From 265f5e44b368f8fb0dc689b0f56cfc2a6deaa61d Mon Sep 17 00:00:00 2001 From: nboisteault Date: Thu, 1 Jun 2023 17:39:02 +0200 Subject: [PATCH] Trreview: handle layer UI when filtered --- assets/src/components/Treeview.js | 6 +++++- assets/src/legacy/attributeTable.js | 16 +++------------- assets/src/modules/BaseLayersMap.js | 4 ++++ lizmap/www/assets/css/map.css | 7 +++++++ 4 files changed, 19 insertions(+), 14 deletions(-) diff --git a/assets/src/components/Treeview.js b/assets/src/components/Treeview.js index 63c7d620d7..df624ab02e 100644 --- a/assets/src/components/Treeview.js +++ b/assets/src/components/Treeview.js @@ -20,7 +20,7 @@ export default class Treeview extends HTMLElement { ${layerGroup.getLayers().getArray().slice().reverse().map(layer => html`
  • layer.setVisible(!layer.getVisible())} > -
    +
    this._toggleMetadata(layer.get('name'), layer instanceof LayerGroup)}>
    @@ -37,6 +37,10 @@ export default class Treeview extends HTMLElement { disconnectedCallback() { } + _isFiltered(layer) { + return !(layer instanceof LayerGroup) && layer.getSource().getParams()?.['FILTERTOKEN']; + } + _toggleMetadata (layerName, isGroup){ lizMap.events.triggerEvent("lizmapswitcheritemselected", { 'name': layerName, 'type': isGroup ? "group" : "layer", 'selected': true} diff --git a/assets/src/legacy/attributeTable.js b/assets/src/legacy/attributeTable.js index 0b4569d7ad..d1a47eb81a 100644 --- a/assets/src/legacy/attributeTable.js +++ b/assets/src/legacy/attributeTable.js @@ -1976,7 +1976,6 @@ var lizAttributeTable = function() { // Get first elements of the pile and withdraw it from the pile var typeName = typeNamePile.shift(); - var cleanName = lizMap.cleanName(typeName); // Get corresponding filter var aFilter = typeNameFilter[typeName]; @@ -1988,16 +1987,7 @@ var lizAttributeTable = function() { applyEmptyLayerFilter( typeName, typeNamePile, typeNameFilter, typeNameDone, cascade ); } - // Change background in switcher - var trFilteredBgcolor = 'inherit'; - var displayUnFilterSwitcherTool = false; - if( aFilter ){ - trFilteredBgcolor = 'rgba(255, 171, 0, 0.4)'; - displayUnFilterSwitcherTool = true; - } - $('#switcher .treeTable tr#group-' + cleanName).css('background-color', trFilteredBgcolor ); - $('#switcher .treeTable tr#layer-' + cleanName).css('background-color', trFilteredBgcolor ); - $('#layerActionUnfilter' ).toggle( ( lizMap.lizmapLayerFilterActive !== null ) ).css( 'background-color', 'rgba(255, 171, 0, 0.4)'); + $('#layerActionUnfilter').toggle((lizMap.lizmapLayerFilterActive !== null)); } function buildChildParam( relation, typeNameDone ) { @@ -2407,8 +2397,8 @@ var lizAttributeTable = function() { var cFilter = null; var cExpFilter = null; // Get WMS layer name (can be different depending on QGIS Server version) - let layer = lizMap.mainLizmap.baseLayersMap.getLayerByTypeName(lizMap.cleanName(cName)); - var wmsCname = layer.getSource?.().getParams?.()?.['LAYERS'] || cName; + let layer = lizMap.mainLizmap.baseLayersMap.getLayerByName(lizMap.cleanName(cName)); + var wmsCname = layer?.getSource?.().getParams?.()?.['LAYERS'] || cName; // Build filter for children // and add child to the typeNameFilter and typeNamePile objects diff --git a/assets/src/modules/BaseLayersMap.js b/assets/src/modules/BaseLayersMap.js index 5f40e5b6e7..2a2f3cb2c9 100644 --- a/assets/src/modules/BaseLayersMap.js +++ b/assets/src/modules/BaseLayersMap.js @@ -251,6 +251,10 @@ export default class BaseLayersMap extends olMap { const changedLayer = evt.target; const parentGroup = this.getLayerOrGroupByName(changedLayer.get('parentName')); + if(!parentGroup){ + return; + } + if (changedLayer.getVisible()) { parentGroup?.setVisible(true); } diff --git a/lizmap/www/assets/css/map.css b/lizmap/www/assets/css/map.css index 67079eb6a0..f626d1cfb1 100644 --- a/lizmap/www/assets/css/map.css +++ b/lizmap/www/assets/css/map.css @@ -2992,6 +2992,12 @@ lizmap-paste-geom svg { vertical-align: text-top; } +/* Treeview */ + +lizmap-treeview .filtered, button#layerActionUnfilter.btn { + background-color: rgba(255, 171, 0, 0.4); +} + lizmap-treeview ul { list-style: none; } @@ -3000,6 +3006,7 @@ lizmap-treeview .node { display: inline-flex; width: calc(100% - 25px); vertical-align: top; + padding-left: 2px; } lizmap-treeview input[type="checkbox"] {