【问题标题】:Leaflet with Customs Tiles seems to not be working带有海关瓷砖的传单似乎不起作用
【发布时间】:2020-04-02 19:30:49
【问题描述】:

我正在尝试将 Leaflet 与自定义瓷砖结合使用来制作一个虚构的地图,但即使我将错误瓷砖 URL 设置为完全不同的图像,它似乎也无法正常工作,它甚至没有显示出来。

我的 JS 代码如下所示:

axios.get("https://crugg.de/udumap/map1/tiles/tiles.json").then((result) => {
    let tilesData = JSON.parse(result.data.replace(/(\/\/)[A-Z a-z,:'()\/.#0-9]*/gm, ""));
    console.log(tilesData.center);
    let map = L.map('map', {
        center: [tilesData.center[0], tilesData.center[1]],
        zoom: tilesData.center[2]
    }).setView([tilesData.center[0], tilesData.center[1]], tilesData.center[2]);
    L.tileLayer('https://crugg.de/udumap/map1/tiles/{z}/{x}/{y}.png', {
        attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">UD:RP Map</a> contributors',
        minZoom: tilesData.minzoom,
        maxZoom: tilesData.maxzoom,
        zoomOffset: -1,
        bounds: L.latLngBounds(L.latLng(tilesData.bounds[0], tilesData.bounds[1]), L.latLng(tilesData.bounds[2], tilesData.bounds[3])),
        errorTileUrl: "https://crugg.de/udumap/map1/tiles/17/107729/82841.png"
    }).addTo(map);
});

JSFiddle:https://jsfiddle.net/5xprc6n3/1/
这是我第一次使用 Leaflet,我不知道为什么这不起作用。

【问题讨论】:

  • 我认为这是confusing lat-long with long-lat 的又一个案例。仔细检查您的虚构数据的 lat-lng 坐标是否在您期望的位置(并记住纬度不能超出 -90,90 范围)。

标签: javascript html web leaflet


【解决方案1】:

您必须删除 bounds 属性。

L.tileLayer('https://crugg.de/udumap/map1/tiles/{z}/{x}/{y}.png', {
        attribution: 'Map data &copy; <a href="https://www.openstreetmap.org/">UD:RP Map</a> contributors',
        minZoom: tilesData.minzoom,
        maxZoom: tilesData.maxzoom,
        zoomOffset: -1,
        errorTileUrl: "https://crugg.de/udumap/map1/tiles/17/107729/82841.png"
    }).addTo(map);

【讨论】:

  • 但是现在我唯一看到的是错误瓷砖和灰色之间的分裂,但是我的道路和一切都无处可见(即使它们可以清楚地在我的服务器上的瓷砖中看到)
  • 看网络分析,想取这样的瓦片:crugg.de/udumap/map1/tiles/12/3122/0.png但是这条路径上没有瓦片
  • 因为 Zoom 12 不存在。我已将 minZoom 设置为 13...但即使我放大它仍然不起作用
猜你喜欢
  • 2015-11-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-11-03
  • 1970-01-01
  • 2016-12-14
相关资源
最近更新 更多