传单-防止在MaxBounds外部加载图块 [英] Leaflet - Prevent loading tiles outside of MaxBounds

查看:58
本文介绍了传单-防止在MaxBounds外部加载图块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在尝试加载不存在且不在我的MaxBounds范围内的图块的传单时遇到问题.

I'm having issues with leaflet trying to load tiles that dont exist and that are outside of my MaxBounds.

我的磁贴集的jsfiddle复制问题 最后还尝试了以下方法:

jsfiddle replicating issue with my tileset Also tried with the following at the end:

map.setBounds(new L.LatLngBounds(southWest, northEast));

但这似乎只是打破了弹出窗口,标记和其他所有内容,而没有解决我的问题.

but that seems to just break popups and markers and everything else without solving my issue.

地图的完整大小为4096x4096

The full size of the map is 4096x4096

不相关的问题,是否有可能将坐标系更改为始终使用未投影的像素坐标,而不必在放置每个标记时都使用unproject或获取常规坐标?

Unrelated question, is it possible to change the coord system to always use unprojected pixel coords without having to either use unproject while placing every marker or getting regular coords?

推荐答案

要告诉Leaflet您的图块层没有任何图块可以服务于预定义范围之外,只需使用

To tell Leaflet that your Tile Layers does not have any tile to serve outside predefined bounds, simply use the bounds option.

在您的情况下,我想它会与地图的最大范围相同.

In your case, I guess it would be the same as your map's max bounds.

我看到您正在尝试显示游戏地图,这就是为什么您需要将CRS更改为L.CRS.Simple的原因.请小心,因为您将 crs 选项错误地应用于了图块图层而不是地图,所以它没有任何作用,除了您的计算边界然后与地图CRS不匹配,并且您的map.setMaxBounds()将导航限制到您可能不希望的地方.

I see that you are trying to display a game map, that is why you need to change the CRS to L.CRS.Simple. Be careful as you incorrectly applied the crs option to your Tile Layer instead of the map, so it had no effect, except that your computed bounds then mismatch the map CRS, and your map.setMaxBounds() restrain navigation to where you may not wish.

请注意,您应该提出其他问题.

Please note that you should make separate questions.

顺便说一句,不确定为什么要在图块图层上使用tms选项.与以前的缩放级别相比,缩放级别为4的图块似乎完全不匹配.更新的JSFiddle: https://jsfiddle.net/f2Ljzpbh/2/

By the way, not sure why you use tms option on your Tile Layer. And your tiles at zoom level 4 seem to be totally mismatched compared to previous zoom levels. Updated JSFiddle: https://jsfiddle.net/f2Ljzpbh/2/

这篇关于传单-防止在MaxBounds外部加载图块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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