diff --git a/assets/src/components/Treeview.js b/assets/src/components/Treeview.js index c46dd2efb9..22757197dd 100644 --- a/assets/src/components/Treeview.js +++ b/assets/src/components/Treeview.js @@ -6,6 +6,7 @@ import { when } from 'lit-html/directives/when.js'; export default class Treeview extends HTMLElement { constructor() { super(); + this._itemNameSelected; } connectedCallback() { @@ -43,7 +44,7 @@ export default class Treeview extends HTMLElement { ? html`` : '' } -
+
item.checked = !item.checked} >
@@ -63,7 +64,7 @@ export default class Treeview extends HTMLElement { ` : '' } - this._toggleMetadata(item.name, item.type)}> + this.itemNameSelected = item.name}>
@@ -94,6 +95,20 @@ export default class Treeview extends HTMLElement { ); } + set itemNameSelected(itemName) { + if (this._itemNameSelected === itemName) { + this._itemNameSelected = undefined; + } else { + this._itemNameSelected = itemName; + } + + lizMap.events.triggerEvent("lizmapswitcheritemselected", + { 'name': itemName, 'selected': this._itemNameSelected !== undefined } + ); + + this._onChange(); + } + _createDocLink(layerName) { let url = lizMap.config.layers?.[layerName]?.link; @@ -119,10 +134,4 @@ export default class Treeview extends HTMLElement { event.preventDefault(); } } - - _toggleMetadata (layerName, isGroup){ - lizMap.events.triggerEvent("lizmapswitcheritemselected", - { 'name': layerName, 'type': isGroup ? "group" : "layer", 'selected': true} - ) - } } diff --git a/assets/src/legacy/switcher-layers-actions.js b/assets/src/legacy/switcher-layers-actions.js index bfddca65cf..f5727df663 100644 --- a/assets/src/legacy/switcher-layers-actions.js +++ b/assets/src/legacy/switcher-layers-actions.js @@ -46,7 +46,7 @@ var lizLayerActionButtons = function() { { 'name': itemName, 'type': itemType, 'selected': false} ); - $('#switcher tr.selected').removeClass('selected'); + document.querySelector('lizmap-treeview').itemNameSelected = undefined; }); } diff --git a/assets/src/modules/BaseLayersMap.js b/assets/src/modules/BaseLayersMap.js index 02733f1025..57430aa6af 100644 --- a/assets/src/modules/BaseLayersMap.js +++ b/assets/src/modules/BaseLayersMap.js @@ -334,7 +334,7 @@ export default class BaseLayersMap extends olMap { mainLizmap.state.layersAndGroupsCollection.addListener( evt => { const activeBaseLayer = this.getActiveBaseLayer(); - if (activeBaseLayer.get("name") === evt.name) { + if (activeBaseLayer && activeBaseLayer.get("name") === evt.name) { activeBaseLayer.setOpacity(evt.opacity); } else { this.getLayerOrGroupByName(evt.name).setOpacity(evt.opacity); diff --git a/lizmap/www/assets/css/map.css b/lizmap/www/assets/css/map.css index b0de01268e..d05efbd7ab 100644 --- a/lizmap/www/assets/css/map.css +++ b/lizmap/www/assets/css/map.css @@ -3008,6 +3008,12 @@ lizmap-treeview li { lizmap-treeview li > div { display: flex; + border: 1px solid transparent; + padding-left: 4px; +} + +lizmap-treeview li > div.selected { + border-color: #0094D6; } lizmap-treeview div.expandable{