leafletjs setMaxBounds不要放大看看整个世界 [英] leafletjs setMaxBounds wont let zoom out to see whole world
问题描述
我正在使用传单js来显示使用云图的世界地图。当我将 setMaxBounds
添加到地图中,除了向北,边界工作很好。那么这不是我最大的担忧。我关心的是,因为我使用 maxBounds
我无法缩小到任何屏幕尺寸看全世界。
I am using leaflet js to show a world map using cloudmade tiles. When I setMaxBounds
to the map the bounds work great except to north. That is, however, not my biggest concern. My concern is, as I use maxBounds
I can not zoom out to see whole world in any screen size.
我使用的限制从加拿大东北角到澳大利亚西南部一直到达。我可以摇摆到达界限,但不能缩小查看整个地图。我将 minZoom
设置为0.没有 maxBound
,它被缩小太远,你可以看到世界重复三次大屏幕。
The bound I used reaches all the way from north east corner of canada to south west of australia. I can pan to reach the bounds but cant zoom out to see whole map. I set minZoom
to 0. Without maxBound
, it is zoomed out too far you can see the world repeat thrice on big screen.
map = L.map('canvas',{zoomControl: false}).setView([38.82259, -2.8125], 0);
map.setMaxBounds([[84.67351256610522, -174.0234375], [-58.995311187950925, 223.2421875]]);
任何帮助都是合法的。
Anil
Any help is appriciated. Anil
推荐答案
如果我理解正确,你的问题是你想要能够看到整个世界您的观点,但您希望能够限制用户看到包裹的瓷砖。
If I understand correctly, your problem is that you want to be able to see the entire world in your view, but you want to be able to restrict the user from seeing the tiles wrapped around.
首先,传单正在做你正在告诉它做的事情。看看我用你的代码创建的这个JSFiddle。 http://jsfiddle.net/zF6bf/ 我可以缩小查看整个世界,但只有将结果窗格调整到足以显示整个世界,而不违反您的maxBounds规则。这对我来说似乎是正确的行为。
First, Leaflet is doing exactly what you are telling it to do. Check out this JSFiddle I created with your code. http://jsfiddle.net/zF6bf/ I can zoom out to see the entire world, but only if I resize the result pane to be large enough to show the entire world, without violating your maxBounds rule. This appears to be correct behavior to me.
其次,如果你真的不希望世界包装,你还可以设置 noWrap
选项到 true
创建图层。
Second, if you really do not want the world to wrap, you can also set the noWrap
option to true
when creating a layer.
var osmLayer = new L.TileLayer("http://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png", { noWrap: true}).addTo(map);
这将阻止该图层绕过地图。如果这个包装是您首先创建边界,那么也许删除包装将会消除您设置 maxBounds
的需要。然后,地图将能够自由地平移和放大。
This will prevent that layer from wrapping around the map. If this wrapping is what made you create the bounds in the first place, then perhaps removing the wrapping will remove your need to set the maxBounds
. Then the map will be able to be panned and zoomed freely.
这篇关于leafletjs setMaxBounds不要放大看看整个世界的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!