From ed4e61437e030fc98abf3ab3f9896c20dfd7a533 Mon Sep 17 00:00:00 2001 From: David Drury Date: Thu, 24 Mar 2022 10:03:50 +0000 Subject: [PATCH] Simplify code & track upstream --- resources/js/webtrees.js | 37 +++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/resources/js/webtrees.js b/resources/js/webtrees.js index 78098396f1c..419f6636ebd 100644 --- a/resources/js/webtrees.js +++ b/resources/js/webtrees.js @@ -631,9 +631,29 @@ zoomoutTitle: config.i18n.zoomOut, }); + const resetControl = L.Control.extend({ + options: { + position: 'topleft', + }, + onAdd: function (map) { + let container = L.DomUtil.create('div', 'leaflet-bar leaflet-control leaflet-control-custom'); + container.onclick = resetCallback; + let reset = config.i18n.reset; + let anchor = L.DomUtil.create('a', 'leaflet-control-reset', container); + anchor.setAttribute('aria-label', reset); + anchor.href = '#'; + anchor.title = reset; + anchor.role = 'button'; + L.DomEvent.addListener(anchor, 'click', L.DomEvent.preventDefault); + let image = L.DomUtil.create('i', 'fas fa-redo', anchor); + image.alt = reset; + + return container; + }, + }); + const preferredLayer = localStorage.getItem('map_default_layer'); let defaultLayer = null; - let systemDefaultLayer = null; for (let [, provider] of Object.entries(config.mapProviders)) { for (let [, child] of Object.entries(provider.children)) { @@ -644,22 +664,19 @@ } else { child.layer = L.tileLayer(child.url, child); } - if (provider.default && child.default) { - systemDefaultLayer = child.layer; + + if (defaultLayer === null && provider.default && child.default) { + defaultLayer = child.layer; } - if (preferredLayer === child['name']) { + if (preferredLayer === child.name) { defaultLayer = child.layer; } } } if (defaultLayer === null) { - if (systemDefaultLayer === null) { - console.log('No default map layer defined - using the first one.'); - defaultLayer = config.mapProviders[0].children[0].layer; - } else { - defaultLayer = systemDefaultLayer; - } + console.log('No default map layer defined - using the first one.'); + defaultLayer = config.mapProviders[0].children[0].layer; } // Create the map with all controls and layers