Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leaflet : Firing an event when bounds change

Tags:

I am using leaflet to develop a new application. You can have an idea of the app here.

I would like to fire an event whenever the bounds of the map change. I looked at the doc but couldn't find anything related to that.

I have found the getBounds() method, and the list of possible event methods, but nothing combining both.

The only other possibility I see to do that is to check for mouse drag and scroll events and check the bounds every time. But I was hoping there would be something better to do.

Would you have a better idea? Thanks!

like image 322
jlengrand Avatar asked Jul 19 '14 21:07

jlengrand


1 Answers

Map bounds are updated each time the map is moved (either by pan or zoom). So you can use moveend event for your purpose

map.on('moveend', function(e) {
   var bounds = map.getBounds();
});
like image 52
YaFred Avatar answered Sep 24 '22 17:09

YaFred