如何在OpenLayers 3中注册地图移动/地图平移事件

时间:2013-08-12 11:31:42

标签: openlayers-3

我正在寻找地图移动/地图平移的OpenLayer 3地图事件,例如:

map.on('move', function(){
  ...
}

有谁知道如何实施?

4 个答案:

答案 0 :(得分:10)

moveend事件可能是您搜索的事件 - 它会检测所做的任何移动,即使是那些未通过拖动调用的移动。

map.on('moveend', function (e) {
    console.log("moved");
});

请参阅http://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html

答案 1 :(得分:4)

<强>更新

最近版本中不再出现这些事件。请参阅the more recent answer以获取最新信息。


您要查找的事件的名称是drag和/或dragend(但依赖于属性名称可能更好:ol.MapBrowserEvent.EventType.DRAG但它没有在演示页面上工作):

map.on('drag', function() {
  console.log('Dragging...');
});

map.on('dragend', function() {
  console.log('Dragging ended.');
});

通过查看mapbrowserevent.js内部进行反向工程,文档明确提到事件尚未记录。

答案 2 :(得分:0)

我相信这个功能存在于地图视图中的2个功能中,而不是地图本身。您可以通过侦听change:center事件来监视View的center属性。在ol.View中还有一个getInteracting()方法,如果正在进行交互(缩放或平移),它将返回一个布尔值。

https://openlayers.org/en/v4.6.5/apidoc/ol.View.html#getInteracting

答案 3 :(得分:0)

MoveEnd触发器,如果​​您使用脚本移动地图。 我在OpenLayers 6中使用了它:

map.on('pointerdrag', function (event) {
    is_map_center = false;
})

hf gl!