diff --git a/vendor/assets/leaflet/leaflet.osm.js b/vendor/assets/leaflet/leaflet.osm.js index cf574e99c5..192748371a 100644 --- a/vendor/assets/leaflet/leaflet.osm.js +++ b/vendor/assets/leaflet/leaflet.osm.js @@ -56,6 +56,9 @@ L.OSM.colorSchemeWatcher = { text: menuItem.text, callback: function () { watcher.darkFilter = menuItem.filter; + watcher._managedContextMenuElements.forEach(function (menuElement) { + watcher._updateContextMenuElement(menuElement); + }); if (watcher._prefersDarkScheme()) { watcher._watchedLayers.forEach(function (watchedLayer) { watcher._updateLayerDarkScheme(watchedLayer); @@ -63,6 +66,8 @@ L.OSM.colorSchemeWatcher = { } } }); + watcher._decorateContextMenuElement(menuElement, menuItem); + watcher._updateContextMenuElement(menuElement); watcher._managedContextMenuElements.push(menuElement); if (!prefersDarkScheme) { menuElement.hidden = true; @@ -87,6 +92,22 @@ L.OSM.colorSchemeWatcher = { return matchMedia("(prefers-color-scheme: dark)").matches; }, + _decorateContextMenuElement: function (menuElement, menuItem) { + menuElement.dataset.filter = menuItem.filter; + var radio = document.createElement('input'); + radio.type = 'radio'; + radio.tabIndex = -1; + radio.classList.add('leaflet-contextmenu-icon'); + radio.style.pointerEvents = 'none'; + radio.style.transform = 'scale(80%)'; + menuElement.prepend(radio, " "); + }, + _updateContextMenuElement: function (menuElement) { + if ('filter' in menuElement.dataset) { + menuElement.firstChild.checked = menuElement.dataset.filter === this.darkFilter; + } + }, + _switchLayerToDarkScheme: function (layer) { if (layer.options.darkUrl) { layer.setUrl(layer.options.darkUrl);