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 () {