现在我正在尝试做的是根据屏幕大小放大和缩小 map ,这样您就可以基本上看到世界上的每一 block 土地。我不担心重复的世界,但理想情况下我希望它基本上以非洲西海岸为中心,就像一张典型的 map 。
我有如下所示的东西:
function fitMap() {
if ($) {
var height = $(window).height();
var width = $(window).width();
//Put map into full screen
$('#map').css({position: "absolute", top: "0", left: "0", right: "0", bottom:"0"});
if ((height < 586 && width < 1095) || height < 325 || (width < 700 && height > 586)) {
map.setZoom(1);
}
else if (width >= 1500 && height > 900) {
map.setZoom(3);
}
else {
map.setZoom(2);
}
}
};
//Fit the map more appropriately to screen sizes.
window.onload = fitMap;
window.onresize = fitMap;
我发现这真的很 hacky,如果我尝试将它放在 1920x1080 一直到小的 1024x768 上,它就可以工作,但我在 Leaflet 中没有看到任何允许我这样做的东西。我有一个想法是创建一个不可见的功能组,基本上创建从日期线到日期线的周界,并使用 .getBounds()
像这样:Centering Leaflet map with getbounds and related issues
有没有人有更好的解决方案?
最佳答案
传单提供了一个 fitWorld()
method做到这一点。
您可以通过调用 map.fitWorld();
来使用它,这里是一个 full example .
关于javascript - 适合 map 以始终显示世界,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17838577/