In my OpenLayers web app I have registered an onmousemove
event which performs certain functions. What I am really after though is a way to register and handle the user panning or zooming the map.
3 Answers
In OpenLayers 2 you can do with the same method:
map.events.register(type, obj, listener);
movestart triggered after the start of a drag, pan, or zoom
move triggered after each drag, pan, or zoom
moveend triggered after a drag, pan, or zoom completes
zoomend triggered after a zoom completes
example code:
map.events.register("move", map, function() {
console.log("panning");
});
i hope it helps you...
-
-
hi there, seems like this answer is out of date: the current map object has a more standard way to add listeners with map.addEventListener(evt, handler) Commented Oct 14, 2015 at 8:26
In OpenLayers 3 you have moveend
, an ol.MapEvent
triggered by the map itselft. Use it this way:
map.on("moveend", function(e){
// event actions
});
This event is triggered in many ways, after click
or dblclick
ol.MapBrowserEvent
events.
Hope it helps.
If the automatic Geolocation is enabled, the event is called either the map moved automatically or the user moved it. So, this is a problem.