diff --git a/vendor/assets/leaflet/leaflet.osm.js b/vendor/assets/leaflet/leaflet.osm.js index f0d7ae6c69..2bcfd269a4 100644 --- a/vendor/assets/leaflet/leaflet.osm.js +++ b/vendor/assets/leaflet/leaflet.osm.js @@ -113,8 +113,16 @@ L.OSM.DarkMode = L.Class.extend({ }, this); var updateContextMenuElements = function () { + var numberOfLayersWithApplicableFilter = 0; + map.eachLayer(function (layer) { + if (layer instanceof L.OSM.TileLayer) { + if (!layer.options.darkUrl) { + numberOfLayersWithApplicableFilter++; + } + } + }); contextMenuElements.forEach(function (menuElement) { - menuElement.hidden = !this._enabled; + menuElement.hidden = !this._enabled || numberOfLayersWithApplicableFilter == 0; if ('filter' in menuElement.dataset) { menuElement.firstChild.checked = menuElement.dataset.filter === this._darkFilter; } @@ -122,6 +130,8 @@ L.OSM.DarkMode = L.Class.extend({ }.bind(this); updateContextMenuElements(); this._contextMenuUpdateHandlers.push(updateContextMenuElements); + map.on("layeradd", updateContextMenuElements); + map.on("layerremove", updateContextMenuElements); return this; },