Leaflet.js fitBounds是否带有填充? [英] Leaflet.js fitBounds with padding?

查看:488
本文介绍了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],也许您的填充值太小.

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天全站免登陆