最佳答案
要阻止图 block 重复,请使用 L.TileLayer
的 noWrap
选项
If set to true, the tiles just won't load outside the world width (-180 to 180 longitude) instead of repeating.
http://leafletjs.com/reference.html#tilelayer-nowrap
如果您想停止平移超出定义的边界,请使用 L.Map
的 maxBounds
选项或调用 setMaxBounds
方法:
Restricts the view to the given geographical bounds, bouncing the user back when he tries to pan outside the view.
- http://leafletjs.com/reference.html#map-maxbounds
- http://leafletjs.com/reference.html#map-setmaxbounds
如果您想禁用超过特定级别的缩放,请使用 L.Map
的 minZoom
和 maxZoom
选项。您要做的是设置最小缩放级别并将其用作初始缩放。什么因素取决于 map 的元素大小和 tilelayer 的 tilesize。大多数 tileproviders 使用 256px²。在缩放 0 时,世界是 1 个图 block ,在缩放 1 时,2x2 图 block ,在 3 时,它是 4x4 等等。因此,如果您的 map 元素是 512px²,您的 minZoom
将是 1。
这是关于 Plunker 的演示:http://embed.plnkr.co/rP5NLQ/preview
关于javascript - 防止重复 map 并在世界范围内继续拖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33105258/