Commit b2edd7de authored by zauberstuhl's avatar zauberstuhl
Browse files

Merge branch 'map_center' into 'master'

Set map center on most common location

See merge request !3
parents 2db5edef 12cce808
......@@ -19,6 +19,7 @@ html, body, #app {
:zoom="zoom"
:minZoom="minZoom"
:options="options"
:center="center"
>
<l-tile-layer :url="url" :attribution="attribution"/>
<l-marker-cluster :options="{}">
......@@ -77,7 +78,8 @@ export default {
options: {
scrollWheelZoom: false,
gestureHandling: true
}
},
center: latLng(0, 0)
}
},
mounted () {
......@@ -138,6 +140,8 @@ export default {
])
)
}
// set new map center
this.updateMapCenter()
} else {
this.failed = true
}
......@@ -157,7 +161,34 @@ export default {
noAutoHide: true,
appendToast: true
})
}
},
updateMapCenter () {
var checkins = this.locations
if (typeof checkins !== 'object' || checkins.length <= 0) {
return
}
var dict = {};
// create data map ranking
for (var index in checkins) {
var name = checkins[index].name
if (typeof dict[name] === 'undefined') {
dict[name] = {
count: 1,
loc: checkins[index]
}
} else {
dict[name].count++
}
}
// sort and find checkin with most common lat/lng
var keys = Object.keys(dict)
var sorted = keys.sort((a, b) => {
return dict[b].count - dict[a].count
})
// set checkin with highest occurrence
var checkin = dict[sorted[0]].loc
this.center = latLng(checkin.lat, checkin.lng)
},
}
}
</script>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment