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:
parent
cbb02f9890
commit
426297df4f
1 changed files with 12 additions and 2 deletions
|
@ -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 () {
|
||||
|
|
Loading…
Reference in a new issue