最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

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

programmeradmin0浏览0评论

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.

发布评论

评论列表(0)

  1. 暂无评论