使用getbounds和相关问题居中传单 [英] Centering Leaflet map with getbounds and related issues

查看:78
本文介绍了使用getbounds和相关问题居中传单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了传单问题,但我无法解决。可能有一个我不知道的简单解决方案。

I ran into a leaflet issue but I can't solve it. May be there's a easy solution I don't know.

所以基本上将分组标记的地图居中并不是那么困难,可以像下面这样做:

So basically centering a map of grouped markers isn't so difficult and can be done like the following:

var markerLayer = L.featureGroup(marker)
        .addTo(map);

var bounds = markerLayer.getBounds();
map.fitBounds(bounds);

其中标记是一组标记。但我的问题是我发送给这段代码的标记数组信息是由另一个系统生成的。所以基本上标记可以在地图中相隔很远,或者它们可以非常接近。

where marker is an array of markers. But my problem is that the marker array information I send to this code are generated by another system. So basically the marker can be far apart in the map or they can be really close.

当标记相距很远时,上面的代码可以完美地工作并使地图居中。但是,如果标记非常接近(例如,如果它们来自同一条街道),或者更好,如果只有一个标记出现问题。这是因为getbounds会给我一个如此小的矩形,以致传单中断(这对用户来说也没用)。我的意思是地图基本上试图放大到那个标记。所以我的问题是如何限制缩放。例如,如果地图中只有标记,我希望地图显示标记及其周围的几条街道。

When the markers are far apart the code above works perfectly and centers the map. However if the markers are really close (for example if they are from the same street), or better yet if there is only one marker problems arise. This is because getbounds will give me a rectangle that is so small that leaflet breaks (and this is of no use for the user as well). I mean the map basically tries to zoom in to that marker. So my question is how do I limit the zoom. For example if there is only marker in the map I want the map to show the marker and few streets around it.

推荐答案

你可以给 maxZoom 地图和 fitBounds 不会覆盖它。

You can give a maxZoom to the map and the fitBounds will not override it.

这篇关于使用getbounds和相关问题居中传单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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