From: Anton Khorev Date: Wed, 29 Jan 2025 10:35:01 +0000 (+0300) Subject: Don't remove-readd standard layer when layerParam is not empty in map.updateLayers X-Git-Tag: live~213^2 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/4f4808a9fd893fb9a5c109d16b6eb8877749f605 Don't remove-readd standard layer when layerParam is not empty in map.updateLayers --- diff --git a/app/assets/javascripts/leaflet.map.js b/app/assets/javascripts/leaflet.map.js index bdc8532d1..10ce94715 100644 --- a/app/assets/javascripts/leaflet.map.js +++ b/app/assets/javascripts/leaflet.map.js @@ -115,19 +115,18 @@ L.OSM.Map = L.Map.extend({ }, updateLayers: function (layerParam) { - var layers = layerParam || "M"; + const oldBaseLayer = this.getMapBaseLayer(); + let newBaseLayer; - for (let i = this.baseLayers.length - 1; i >= 0; i--) { - if (layers.indexOf(this.baseLayers[i].options.code) === -1) { - this.removeLayer(this.baseLayers[i]); + for (const layer of this.baseLayers) { + if (!newBaseLayer || layerParam.includes(layer.options.code)) { + newBaseLayer = layer; } } - for (let i = this.baseLayers.length - 1; i >= 0; i--) { - if (layers.indexOf(this.baseLayers[i].options.code) >= 0 || i === 0) { - this.addLayer(this.baseLayers[i]); - return; - } + if (newBaseLayer !== oldBaseLayer) { + if (oldBaseLayer) this.removeLayer(oldBaseLayer); + if (newBaseLayer) this.addLayer(newBaseLayer); } },