[英]centering map on array of markers bounds [leaflet]
I'm using Leaflet to mark a series of markers. 我正在使用Leaflet标记一系列标记。 I'm using MarkerCluster plugin to create clusters.
我正在使用MarkerCluster插件创建集群。 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,...]
. 我的数组看起来像
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]);
}
Well this was very easy I just needed to read some more. 好吧,这很容易,我只需要阅读更多内容。 All you have to do is
var bounds = markers.getBounds();
您所要做的就是
var bounds = markers.getBounds();
and then map.fitBounds(bounds);
然后
map.fitBounds(bounds);
and voila done. 瞧!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.