Leaflet.js fitBounds 与填充? [英] Leaflet.js fitBounds with padding?

查看:33
本文介绍了Leaflet.js fitBounds 与填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在传单地图中设置 fitBounds 选项,如下所示:

I'm trying to set the fitBounds option in a leaflet map like this:

var bounds = new L.LatLngBounds([[Math.max(lat, borneLat), Math.max(lng, borneLng)], [Math.min(lat, borneLat), Math.min(lng, borneLng)]]);
map.fitBounds(bounds, { padding: [20, 20] });

但是这似乎没有添加任何填充?至少地图缩放级别"没有改变,它总是显示边缘的两个点(即一个在最右边,另一个在最左边).对于某些标记集,它可以正常工作,缩放处于适当的水平,您可以很好地看到一切.然而,当这些项目彼此非常接近时,它似乎放大了一点,除非我可以用一些填充"来适应它.

However this doesn't seem to add any padding ? at least the map "zoom level" doesn't change, and it's always showing the two points in the edges (i.e. one is top far right and the other is bottom far left). For some marker sets, it works ok, the zoom is at a decent level away and you can see everything nicely. However when the items are quite close to each other, it seems it zooms in a bit too much unless I can fit it with some "padding."

我也不确定这样的界限是否正确?我应该改用:

Also I'm unsure if the bounds would be correct like that? Should I use instead just:

var bounds = [[Math.max(lat, borneLat), Math.max(lng, borneLng)], [Math.min(lat, borneLat), Math.min(lng, borneLng)]];

推荐答案

map.fitBounds(bounds, {padding: []}) 应该可以工作.我建议您将填充更改为例如.[50, 50],可能你的padding值太小了.

map.fitBounds(bounds, {padding: []}) should work. I suggest you to change padding to eg. [50, 50], maybe your padding values are too small.

查看这个 JSFiddle 示例.

这篇关于Leaflet.js fitBounds 与填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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