11

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 3

12

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...

2
  • Very odd that Map has a movestart event, but Layer doesn't...
    – ach
    Sep 19, 2013 at 20:18
  • 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)
    – pietro909
    Oct 14, 2015 at 8:26
8

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.

0

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.