Bound a Leaflet map to many layers

1.6k Views Asked by At

I have a leaflet map with many layers and each layer has many objects. Is there a way to fit the map bounds so that all objects in all layers are visible?

2

There are 2 best solutions below

5
iH8 On BEST ANSWER

If you're using or could switch to FeatureGroup, which is extended from LayerGroup, you have the getBounds method which would return the bounds of all the layers/features in your group. Those you could use with fitBounds method of your mapinstance.

0
AudioBubble On
map.addLayer("your layer name");