From e63235e00882b40477637201417eb1c505e69e6a Mon Sep 17 00:00:00 2001 From: Guilhem Moulin Date: Tue, 22 Jul 2025 17:08:21 +0200 Subject: Layer selection: Add ability to collapse children. Don't show children (sublayers) in that case. It is still possible to select individual sublayers by manually editing hash parameters. Use that feature for county and municipality boundaries, which are arguably only useful together. This allows showing separate legend items. --- main.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main.js b/main.js index 6c58c17..af0e874 100644 --- a/main.js +++ b/main.js @@ -750,7 +750,7 @@ const LAYERS = Object.seal({ }), }, kommunyta: { - legend: null, + legend: { zoomLevel: 3, type: 'linestring' }, style: [2, 2, 3, 3, 4, 4, 6, 6, 8, 8, 10, 10].map(function(width) { return new Style({ zIndex: 0, @@ -3278,7 +3278,17 @@ const layerHierarchy = [ { text: 'Administrativa gränser', type: 'switch', - layer: ['adm.lansyta', 'adm.kommunyta'], + collapse_children: true, + children: [ + { + text: 'Länsgränser', + layer: 'adm.lansyta', + }, + { + text: 'Kommungränser', + layer: 'adm.kommunyta', + }, + ], }, ]; @@ -3544,7 +3554,7 @@ const infoMetadataAccordions = []; let layerId = 0; const addAccordionGroup = function(parentNode, children) { const ul = document.createElement('ul'); - parentNode.appendChild(ul); + parentNode?.appendChild?.(ul); ul.classList.add('list-group', 'list-group-flush'); children.forEach(function(child) { @@ -3625,7 +3635,7 @@ const infoMetadataAccordions = []; const text0 = document.createTextNode(x.text); label0.appendChild(text0); - if (x.children == null || x.children.length === 0) { + if (x.children == null || x.children.length === 0 || x.collapse_children) { span0.removeAttribute('data-bs-toggle'); span0.removeAttribute('data-bs-target'); item.replaceChildren(span0); @@ -3633,6 +3643,10 @@ const infoMetadataAccordions = []; span0.classList.add('form-switch'); input0.setAttribute('role', 'switch'); } + if (x.children != null && x.children.length > 0) { + /* create inputs for the hash param logic but don't add them to the panel */ + addAccordionGroup(null, x.children); + } } else { const body = document.createElement('div'); collapse.appendChild(body); -- cgit v1.2.3