Mapbox.js-在要求的缩放级别中缺失时,较低缩放级别的后备图块图像 [英] Mapbox.js - Fallback tile image from lower zoom level, when missing in requested zoom level
问题描述
我从磁盘上提供地图png文件,并且在缩放级别15中具有整个城市的图块png.我在缩放级别16-18中也具有图块,但仅适用于某些区域.
I serve map png files from disk and I have tile pngs for whole city in zoom level 15. I have also tiles in zoom levels 16-18 but only for certain areas.
我想设置图块图层,以便当用户处于缩放级别18时,地图将显示级别15的缩放图块作为后备.
I would like to set up the tile Layer, so that when the user is in zoom level 18 the map will display scaled tiles from level 15 as a fallback.
我尝试设置选项maxNativeZoom
,但对我不起作用.
I tried setting option maxNativeZoom
, but didn't work for me.
这是我的代码:
offlineLayer = L.mapbox.tileLayer(tileJSON, {
minZoom: 8,
maxZoom: 18,
maxNativeZoom: 15
});
map.addLayer(offlineLayer, 'Offline', 1);
我可以使用某些选项使它工作吗,还是需要以某种方式修改它?还是有一些示例代码?
Can I make it work, that way using some options or do I need to hack it some way? Or is there some example code for that?
推荐答案
Just to let people know that I wrote Leaflet.TileLayer.Fallback plugin some time ago to address this exact use case:
通过缩放的较低缩放图块替换丢失的图块(404错误).
Replaces missing Tiles (404 error) by scaled lower zoom Tiles.
在OP的情况下,您只需照常指定maxZoom
Tile Layer选项,每当发现当前缩放级别的图块丢失时,插件将尝试用上一个父"图块替换它缩放级别(适当缩放和裁剪,使其适合丢失的图块),依此类推,直到找到图块或达到minZoom
.
In OP's situation, you would just specify the maxZoom
Tile Layer option as usual, and whenever a tile is found missing at the current zoom level, the plugin will try to replace it by the "parent" tile at the previous zoom level (scaled and clipped appropriately so that it fits the missing tile), and so on until a tile is found or minZoom
is reached.
L.tileLayer.fallback(urlTemplate, {
minZoom: 8,
maxZoom: 18
});
免责声明:我是该插件的作者.
Disclaimer: I am the author of that plugin.
这篇关于Mapbox.js-在要求的缩放级别中缺失时,较低缩放级别的后备图块图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!