识别地图Moveend事件是否由用户启动 [英] Identifying if a map moveend event was user initiated

查看:103
本文介绍了识别地图Moveend事件是否由用户启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 ol.Map .当通过用户输入来移动地图时,以及当我调用 ol.View .setResolution .

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.

是否可以检查'moveend' ol .MapEvent 确定事件是由用户输入触发还是由手动更改地图视图的属性触发的?

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?

推荐答案

我最终做了以下事情.

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. 在地图视图中引入其他状态信息.
  2. 不小心更换地图视图将丢失该状态信息.
  3. 需要在更改视图状态之前设置属性,否则可能会很容易忘记.

但是,它同时解决了我的问题.

However, it adresses my issue in the meantime.

这篇关于识别地图Moveend事件是否由用户启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆