diff --git a/app/assets/javascripts/leaflet.map.js b/app/assets/javascripts/leaflet.map.js index f478f4351b..84640b7903 100644 --- a/app/assets/javascripts/leaflet.map.js +++ b/app/assets/javascripts/leaflet.map.js @@ -106,19 +106,24 @@ L.OSM.Map = L.Map.extend({ }, updateLayers: function (layerParam) { - var layers = layerParam || "M", - layersAdded = ""; + var layerCodes = layerParam || "M", + addedLayer; for (var i = this.baseLayers.length - 1; i >= 0; i--) { - if (layers.indexOf(this.baseLayers[i].options.code) >= 0) { + if (layerCodes.indexOf(this.baseLayers[i].options.code) >= 0 && !addedLayer) { this.addLayer(this.baseLayers[i]); - layersAdded = layersAdded + this.baseLayers[i].options.code; - } else if (i === 0 && layersAdded === "") { + addedLayer = this.baseLayers[i]; + } else if (i === 0 && !addedLayer) { this.addLayer(this.baseLayers[i]); + addedLayer = this.baseLayers[i]; } else { this.removeLayer(this.baseLayers[i]); } } + + if (addedLayer) { + $("body").css("--dark-mode-map-filter", addedLayer.options.darkFilter); + } }, getLayersCode: function () {