Search code examples
openlayers-3

How to register map move / map pan events in OpenLayers 3


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?


Solution

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