admin管理员组

文章数量:1334663

I'm using Leaflet to mark a series of markers. I'm using MarkerCluster plugin to create clusters. What I'm doing right now I setting the view of the map to the 1st point of my array. What I wand to do is center the map so the user can see all the points/clusters when the map loads.

My array looks like m = [L.Marker, L.Marker,...]. The I add each to my cluster group like:

var markers = L.MarkerClusterGroup();
for(var i = 0; i < m.length; i++){
     markers.addLayer(m[i]);
}

I'm using Leaflet to mark a series of markers. I'm using MarkerCluster plugin to create clusters. What I'm doing right now I setting the view of the map to the 1st point of my array. What I wand to do is center the map so the user can see all the points/clusters when the map loads.

My array looks like m = [L.Marker, L.Marker,...]. The I add each to my cluster group like:

var markers = L.MarkerClusterGroup();
for(var i = 0; i < m.length; i++){
     markers.addLayer(m[i]);
}
Share Improve this question asked Mar 4, 2013 at 17:00 LouieVLouieV 1,0523 gold badges16 silver badges28 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 8

Well this was very easy I just needed to read some more. All you have to do is var bounds = markers.getBounds(); and then map.fitBounds(bounds); and voila done.

本文标签: javascriptcentering map on array of markers bounds leafletStack Overflow