From 426297df4f785466312ce6486fe67177a69459b4 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Sat, 16 Dec 2023 18:47:14 +0100 Subject: [PATCH] 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 --- umap/static/umap/js/umap.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/umap/static/umap/js/umap.js b/umap/static/umap/js/umap.js index b055dbf2..c814854e 100644 --- a/umap/static/umap/js/umap.js +++ b/umap/static/umap/js/umap.js @@ -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 () {