21

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!

jlengrand
  • 11,230
  • 12
  • 54
  • 80

1 Answers1

47

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();
});
YaFred
  • 9,060
  • 3
  • 27
  • 38