I would like to observe things like maps.on('moveend')
to update zoom level or center values. Currently I have a "construct" made up of computed
params and watcher
functions like this:
export default {
[...],
// Computed values are saved / read from vuex store
computed: {
currentLatLon: {
get () {
const obj = {
lat: this.$store.getters.getCurrentLat,
lon: this.$store.getters.getCurrentLon
}
return obj
}
},
moveEnd: {
get () {
const val = this.olMap !== null
? this.olMap.on('moveend', () => {
console.log('moveEnd; do something... getCenter()...'))
}
: false
return val
}
}
},
watch: {
currentLatLon (value) {
console.log('watcher currentLatLon invoked: value =', value)
// this.zoomToCurrentLocation()
},
moveEnd (value) {
console.log('moveEnd: value =', value)
}
}
}
codesandbox with minimal code: https://codesandbox.io/s/openlayers-getzoom-74gnw?file=/src/components/MapContainer.vue
It works so far. But I am unsure, because it seems to be "double the trouble".
Is there a better way to observe Openlayers events in Vue?