javascript - centering map on array of markers bounds [leaflet] - Stack Overflow

I'm using Leaflet to mark a series of markers. I'm using MarkerCluster plugin to create clust

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742378243a4432622.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信