I'm looking for OpenLayer 3 map event for map move/map pan, something like:

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

Does anyone know how to implement?

有帮助吗?

解决方案 2

UPDATE:

These events are no longer present in recent versions. Please refer to the more recent answer for an up-to-date information.


Names of the events you're looking for are drag and/or dragend (it's probably a better idea to depend on properties names, though: ol.MapBrowserEvent.EventType.DRAG but it didn't work on the demo page):

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

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

Reverse-engineered by looking inside mapbrowserevent.js, the documentation explicitly mentions events are not documented yet.

其他提示

The moveend event might be the one you search for - it detects any move made, even those not invoked by dragging.

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

See http://openlayers.org/en/latest/apidoc/module-ol_Map-Map.html

MoveEnd trigger if u move the map with a script. I have use that in OpenLayers 6:

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

hf gl!

I believe this functionality exists in 2 functions within the View of a map, not the map itself. You can monitor the center property of the View by listening for change:center events. There is also a getInteracting() method in ol.View that will return a boolean if an interaction (zooming or panning) is occurring.

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top