以标记范围阵列为中心的地图[传单] [英] centering map on array of markers bounds [leaflet]

查看:76
本文介绍了以标记范围阵列为中心的地图[传单]的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Leaflet标记一系列标记.我正在使用MarkerCluster插件来创建集群.我现在正在做的事情是将地图的视图设置为数组的第一点.我要执行的操作是将地图居中,以便用户在加载地图时可以看到所有点/群集.

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.

我的数组看起来像m = [L.Marker, L.Marker,...].我将每个都添加到我的群集组中,例如:

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]);
}

推荐答案

这很容易,我只需要阅读更多内容.您所要做的就是var bounds = markers.getBounds();,然后完成map.fitBounds(bounds);,瞧瞧.

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.

这篇关于以标记范围阵列为中心的地图[传单]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆