Rohan
Rohan

Reputation: 13811

Zoom in on maker group in leaflet mapbox?

I have a layerGroup in my map which has a lot of markers and another layerGroup which has a lot of circles. I need to zoom in on these layer groups but I cannot find the exact API method to do so.

I have tried:

var myLayerGroup = L.layerGroup().addTo(map);
myLayerGroup.fitBounds(); // tried this
myLayerGroup.setBounds(); // and this too

I am not sure which method in the API will work for me. How to zoom in on a layer of markers?

Upvotes: 1

Views: 249

Answers (1)

snkashis
snkashis

Reputation: 2991

Switch from using layerGroup to featureGroup, theb you can use getBounds() on a feature group to retrieve its bounds, then use map.fitBounds(result) to zoom to that view.

Upvotes: 2

Related Questions