Make sure we do not display twice the same background layer in selector

At this stage, uMap does not distinguish between a custom background
and the default background, both are saved in map.options.tilelayer.

Given we want a custom background (so not in the list) to appear in
the selector, we need this check to be sure we are not adding again
one layer from the list
This commit is contained in:
Yohan Boniface 2023-12-16 18:47:14 +01:00
parent cbb02f9890
commit 426297df4f

View file

@ -651,8 +651,18 @@ L.U.Map.include({
},
eachTileLayer: function (callback, context) {
if (this.customTilelayer) callback.call(context, this.customTilelayer)
this.tilelayers.forEach((layer) => callback.call(context, layer))
const urls = []
const callOne = (layer) => {
// Prevent adding a duplicate background,
// while adding selected/custom on top of the list
const url = layer.options.url_template
if (urls.indexOf(url) !== -1) return
callback.call(context, layer)
urls.push(url)
}
if (this.selected_tilelayer) callOne(this.selected_tilelayer)
if (this.customTilelayer) callOne(this.customTilelayer)
this.tilelayers.forEach(callOne)
},
setOverlay: function () {