qgis-js icon indicating copy to clipboard operation
qgis-js copied to clipboard

QGIS layers within layer groups with visibility=false cannot be displayed

Open amuedespacher opened this issue 1 year ago • 2 comments

If a QGIS project has a layer group set to visible==false, setting the visibility of the individual layers to true in QGIS-js does not render the layers on the map.

Steps to reproduce:

  • Create a QGIS project
  • Create a layer group with at least one layer, and set it to invisible (via the checkbox in the layer list)
  • Open the QGIS project with QGIS-js (e.g. on demo site)
  • Try to switch on the layer that is in the group

Actual result:

  • Layer is not displayed on the map

Expected result:

  • Layer is displayed on the map

Example: (last two layers should render a choropleth map) qgis-js-invisible_layers

amuedespacher avatar Jan 17 '24 12:01 amuedespacher

I did some more testing, and the issue can be narrowed down to more specific cases, where layer groups are used. I updated the description of the issue accordingly.

amuedespacher avatar Jan 18 '24 08:01 amuedespacher

The problem is that itemVisibilityChecked() and setItemVisibilityChecked() in MapLayer.hpp will only effect the layer but not it's parent elements, see https://api.qgis.org/api/classQgsLayerTreeNode.html

I did a quick test switching to isVisible() and setItemVisibilityCheckedParentRecursive() which helps to actually show the layer as not visible and to be able to set the invisible group to visible. But will then also make the whole group invisible when just one layer should be set to invisible.

The whole MapLayer implementation was just a quick shot to get a basic example working (without thinking about groups at that point). IMHO the only sane solution is to actually expose the QGIS internals: QgsLayerTree, QgsLayerTreeModel, QgsLayerTreeNode, QgsLayerTreeGroup, QgsLayerTreeLayer. And then build a hierarchical layer widget on top of that.

I've created a new issue for that, see https://github.com/qgis/qgis-js/issues/25

boardend avatar Jan 20 '24 08:01 boardend