2

I'm quite new in OpenLayers, and I want to act when the map is moved.

So simply listening to the change:center event of the map's view:

map.getView().on('change:center', function(evt){
   console.log(map.getView().getCenter());
}

But I've noticed the event is not fired after we finish the map panning with the mouse - and the map is still moving and slowing down until it stops completely.

Is there another way to know when the map extent is changed?

0

1 Answer 1

1

The moveend event on the Map instance should do what you need: http://openlayers.org/en/v3.4.0/apidoc/ol.MapEvent.html?unstable=true#event:moveend

2
  • :D Don't know how i missed this. After checking it out, it fired only in the end of the change. So i almost covered all cases. While the map panning i have the changed:center of the view. But there is animation between the mouse up till the end of the animation that i don't get trough those events.
    – Raziza O
    Commented Apr 20, 2015 at 11:10
  • Ok, found some workaround. I am listening to the view's change:center event. and to the moveend of the map's. in the center change event i'm start listening to the map's postrender event (only once) and in the moveend i'm stop listening to it. This way i'm getting the map real location at all times.
    – Raziza O
    Commented Apr 20, 2015 at 11:30

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.