Identifying if a map moveend event was user initiated

一个人想着一个人 提交于 2019-12-11 09:42:32

问题


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?


回答1:


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:

  1. Introduces additional state information in the map's view.
  2. Carelessly replacing the map view will lose that state information.
  3. Requires setting a property before changing the view state and may be too easily forgotten.

However, it adresses my issue in the meantime.



来源:https://stackoverflow.com/questions/35163355/identifying-if-a-map-moveend-event-was-user-initiated

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!