I registered a 'moveend' event listener on my ol.Map. It's firing when the map is moved around by user input, but also when I call ol.View.setCenter and ol.View.setResolution.
Is it possible to check the 'moveend' ol.MapEvent to determine if the event was triggered by user input or from manually changing the map view's properties?
I ended up doing the following.
map.on('moveend', function(event) {
var mapView = map.getView(),
moveInitiatedProgrammatically = mapView.get('moveInitiatedProgrammatically') || false;
mapView.unset('moveInitiatedProgrammatically');
// evaluate moveInitiatedProgrammatically's value and behave accordingly...
});
map.getView().set('moveInitiatedProgrammatically', true);
map.getView().setCenter(coord);
It's not ideal for the following reasons:
- Introduces additional state information in the map's view.
- Carelessly replacing the map view will lose that state information.
- Requires setting a property before changing the view state and may be too easily forgotten.
However, it adresses my issue in the meantime.