Skip to content

Commit

Permalink
Fix preview of TMS TileLayer preview
Browse files Browse the repository at this point in the history
This is not the ideal fix, instead we'd prefer to use
`TileLayer.getTileUrl`, but this is not possible yet.

cf Leaflet/Leaflet#9201

cf https://lists.openstreetmap.org/pipermail/umap/2023-December/000557.html
  • Loading branch information
yohanboniface committed Dec 28, 2023
1 parent f034477 commit 50bee2b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions umap/static/umap/js/umap.controls.js
Original file line number Diff line number Diff line change
Expand Up @@ -1199,11 +1199,21 @@ L.U.TileLayerControl = L.Control.IconLayers.extend({
if (!layers) {
layers = []
this.map.eachTileLayer((layer) => {
layers.push({
title: layer.options.name,
layer: layer,
icon: L.Util.template(layer.options.url_template, this.map.demoTileInfos),
})
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({
title: layer.options.name,
layer: layer,
icon: icon,
})
} catch (e) {
// Skip this tilelayer
console.error(e)
}
})
}
const maxShown = 10
Expand Down
2 changes: 1 addition & 1 deletion umap/static/umap/js/umap.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ L.Map.mergeOptions({
name: '',
description: '',
displayPopupFooter: false,
demoTileInfos: { s: 'a', z: 9, x: 265, y: 181, r: '' },
demoTileInfos: { s: 'a', z: 9, x: 265, y: 181, '-y': 181, r: '' },
licences: [],
licence: '',
enableMarkerDraw: true,
Expand Down

0 comments on commit 50bee2b

Please sign in to comment.