Skip to content

Commit

Permalink
Treeview: handle item selected state
Browse files Browse the repository at this point in the history
  • Loading branch information
nboisteault committed Jul 25, 2023
1 parent f6d7c4a commit a1f9d5e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 10 deletions.
25 changes: 17 additions & 8 deletions assets/src/components/Treeview.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { when } from 'lit-html/directives/when.js';
export default class Treeview extends HTMLElement {
constructor() {
super();
this._itemNameSelected;
}

connectedCallback() {
Expand Down Expand Up @@ -43,7 +44,7 @@ export default class Treeview extends HTMLElement {
? html`<div class="expandable ${item.expanded ? 'expanded' : ''}" @click=${() => item.expanded = !item.expanded}></div>`
: ''
}
<div class="${item.checked ? 'checked' : ''} ${item.type}">
<div class="${item.checked ? 'checked' : ''} ${item.type} ${item.name === this._itemNameSelected ? 'selected' : ''}">
<div class="loading ${item.loading ? 'spinner' : ''}"></div>
<input class="${layerTreeGroupState.mutuallyExclusive ? 'rounded-checkbox' : ''}" type="checkbox" id="node-${item.name}" .checked=${item.checked} @click=${() => item.checked = !item.checked} >
<div class="node ${item.isFiltered ? 'filtered' : ''}">
Expand All @@ -63,7 +64,7 @@ export default class Treeview extends HTMLElement {
</a>`
: ''
}
<i class="icon-info-sign" @click=${() => this._toggleMetadata(item.name, item.type)}></i>
<i class="icon-info-sign" @click=${() => this.itemNameSelected = item.name}></i>
</div>
</div>
</div>
Expand Down Expand Up @@ -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;

Expand All @@ -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}
)
}
}
2 changes: 1 addition & 1 deletion assets/src/legacy/switcher-layers-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var lizLayerActionButtons = function() {
{ 'name': itemName, 'type': itemType, 'selected': false}
);

$('#switcher tr.selected').removeClass('selected');
document.querySelector('lizmap-treeview').itemNameSelected = undefined;
});
}

Expand Down
2 changes: 1 addition & 1 deletion assets/src/modules/BaseLayersMap.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions lizmap/www/assets/css/map.css
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit a1f9d5e

Please sign in to comment.