Merge pull request #1492 from umap-project/fix-tms-url-preview

Fix preview of TMS TileLayer preview
This commit is contained in:
Yohan Boniface 2023-12-28 20:36:06 +01:00 committed by GitHub
commit 974536debe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 6 deletions

View file

@ -1199,11 +1199,21 @@ L.U.TileLayerControl = L.Control.IconLayers.extend({
if (!layers) { if (!layers) {
layers = [] layers = []
this.map.eachTileLayer((layer) => { this.map.eachTileLayer((layer) => {
try {
// We'd like to use layer.getTileUrl, but this method will only work
// when the tilelayer is actually added to the map (needs this._tileZoom
// to be defined)
// Fixme when https://github.com/Leaflet/Leaflet/pull/9201 is released
const icon = L.Util.template(layer.options.url_template, this.map.demoTileInfos)
layers.push({ layers.push({
title: layer.options.name, title: layer.options.name,
layer: layer, layer: layer,
icon: L.Util.template(layer.options.url_template, this.map.demoTileInfos), icon: icon,
}) })
} catch (e) {
// Skip this tilelayer
console.error(e)
}
}) })
} }
const maxShown = 10 const maxShown = 10

View file

@ -29,7 +29,12 @@ L.Map.mergeOptions({
name: '', name: '',
description: '', description: '',
displayPopupFooter: false, displayPopupFooter: false,
demoTileInfos: { s: 'a', z: 9, x: 265, y: 181, r: '' }, // When a TileLayer is in TMS mode, it needs -y instead of y.
// This is usually handled by the TileLayer instance itself, but
// we cannot rely on this because of the y is overriden by Leaflet
// See https://github.com/Leaflet/Leaflet/pull/9201
// And let's remove this -y when this PR is merged and released.
demoTileInfos: { s: 'a', z: 9, x: 265, y: 181, '-y': 181, r: '' },
licences: [], licences: [],
licence: '', licence: '',
enableMarkerDraw: true, enableMarkerDraw: true,