Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

Thanks in advance

share|improve this question
up vote 10 down vote accepted

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

share|improve this answer
    
Brilliant! Thanks for your help. – CatchingMonkey Jun 1 '12 at 10:10
    
you're welcome. – Aragon Jun 1 '12 at 10:22
    
Very odd that Map has a movestart event, but Layer doesn't... – ach Sep 19 '13 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 '15 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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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