From 52a27698a00fce3cea8b2da65f47f889a41cf51b 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 9a9db0a82f..59eb1e2a25 100644 --- a/vendor/assets/leaflet/leaflet.osm.js +++ b/vendor/assets/leaflet/leaflet.osm.js @@ -140,8 +140,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; } @@ -149,6 +157,8 @@ L.OSM.DarkMode = L.Class.extend({ }.bind(this); updateContextMenuElements(); this._contextMenuUpdateHandlers.push(updateContextMenuElements); + map.on("layeradd", updateContextMenuElements); + map.on("layerremove", updateContextMenuElements); return this; },