diff options
author | Guilhem Moulin <guilhem@fripost.org> | 2025-07-22 17:08:21 +0200 |
---|---|---|
committer | Guilhem Moulin <guilhem@fripost.org> | 2025-07-22 17:36:23 +0200 |
commit | e63235e00882b40477637201417eb1c505e69e6a (patch) | |
tree | 0b24fe83b6304fd837e5daaa5b5f2f3f0130bb18 | |
parent | 5675a32a1aa381bf2ebb21f51aee26b8d4c6ffdb (diff) |
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.
-rw-r--r-- | main.js | 22 |
1 files changed, 18 insertions, 4 deletions
@@ -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); |