From 54abed48fc475f1b38d9a30ae75239cf92fa3b4f Mon Sep 17 00:00:00 2001 From: Anton Khorev Date: Fri, 10 May 2024 18:40:59 +0300 Subject: [PATCH] Hide dark mode context menu items when not applicable --- vendor/assets/leaflet/leaflet.osm.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) 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; },