Backgroundlayer is shown in foreground
Problem:
The background layer created from the MapCanvas context menu → “Show background layer” is added into the foreground and thus might overlay other layers. A background layer should be placed in the background an not overlay existing layers.
How to reproduce:
- Start QGIS + EnMAP-Box
- Type “World” to QGIS coordinate field to open the world example layer
- Visualize this layer in the EnMAP-Box
- Add Background layer via mapcanvas “Show background layer” menu
Comments (26)
-
-
- changed milestone to 3.10 (Hotfix)
-
assigned issue to
-
reporter Mmmh. Actually it’s obvious that the background layer is set on top to the layer stack. But after fixing this there seems indeed another problem which changes the layer order for reasons I don’t know.
-
Yes yes, I tried both orderings, layer first and layer last. Both resulted in the false ordering.
-
reporter Strange things happen. I want to set the layers as ordered in L:
-
reporter Overall, there are 3 Problems:
1. the background layer is set on top of the layer stack so that other layers will not be shown. You can replicate this with a normal QgsMapCanvas.
2. you add the new map layer to the MapCanvas(QgsMapCanvas) instance. This is generally recommended, because it is unclear where this new layer should be positioned in the Layer Tree.Let our layer tree have 5 layers A - E. Layers with x are checked: xA, B, xC, D, E.
In this situation the map canvas should have the layer list = [A, B].If you are in QGIS and add new layer F to iface.mapCanvas(), it will simply not show-up in the QGIS layer tree list. therefore, new layers should be added using the layer tree list, not the QgsMapCanvas.
The EnMAP-Box is slightly different, as it tries to handle this case. By now it simply adds the new layer to the top of the layer tree. Probably my rational for this was to show new added layer on top of the layer tree. This brings us to Problem 3: Where to put the new layer F? This might become even more problematic if the new canvas layer list is set to a very different layer order compared to the layer tree order.
3. Where to put the new layer F?
a) xA, B, xC, xF, D, E
b) xA, B, xC, D, xF, E
c) xA, B, xC, D, E, xF,
-
@Benjamin Jakimow , I think I also tried this method. But it also failed:
-
Overall, there are 3 Problems:
the background layer is set on top of the layer stack so that other layers will not be shown. You can replicate this with a normal QgsMapCanvas.
you add the new map layer to the MapCanvas(QgsMapCanvas) instance. This is generally recommended, because it is unclear where this new layer should be positioned in the Layer Tree.
Let our layer tree have 5 layers A - E. Layers with x are checked: xA, B, xC, D, E.
In this situation the map canvas should have the layer list = [A, B].If you are in QGIS and add new layer F to iface.mapCanvas(), it will simply not show-up in the QGIS layer tree list. therefore, new layers should be added using the layer tree list, not the QgsMapCanvas.
The EnMAP-Box is slightly different, as it tries to handle this case. By now it simply adds the new layer to the top of the layer tree. Probably my rational for this was to show new added layer on top of the layer tree. This brings us to Problem 3: Where to put the new layer F? This might become even more problematic if the new canvas layer list is set to a very different layer order compared to the layer tree order.
Where to put the new layer F?
a) xA, B, xC, xF, D, E
b) xA, B, xC, D, xF, E
c) xA, B, xC, D, E, xF,Is this a question for me or just self talk?
Sorry, don’t really understand what you want to say or ask here.
-
reporter Maybe it’s better to remove these methods that offer direct access to the map canvas layer list because of problem 3.
-
We just want to add a layer here at the red arrow? Or not?
-
Maybe it’s better to remove these methods that offer direct access to the map canvas layer list because of problem 3.
I don’t understand problem 3 I guess
-
Maybe we better talk in the next meeting about it - I create a Trello card.
-
Look what I’ve found
https://bitbucket.org/hu-geomatics/enmap-box/issues/881/mapdockinsertlayer-is-broken -
reporter So what exactly don’t you understand?
-
I don’t understand what your question is.
If this is your question: “Where to put the new layer F?”
My answer would be: place the layer here:
-
Sorry, really have no idea, what you want to say with your long text block. Maybe we better talk.
-
reporter Thinking a bit more about this problem and with regard to
#649my conclusion is:
Never set the canvas layer list directly. Instead, do it like QGIS and manipulate the layertree (https://docs.qgis.org/3.22/en/docs/pyqgis_developer_cookbook/legend.html# ).I will add some convenient functions to
MapCanvas
andMapCanvasDock
access theMapDockTreeNode
-
reporter - changed status to resolved
removed hiddenlayer group change syncHiddenLayers() to syncProjects() resolves
#985addresses#649refactoring to apply for flake8 / PEP rules→ <<cset 67db906f5d25>>
-
Still not working:
-
- changed status to open
-
reporter Have you really pulled the latest commits from develop?
-
-
reporter Works well in a fresh checkout. Please close this issue if you found out how pull the updates properly.
-
Yes, you are right. I guess I testet in the wrong version.
-
- changed status to resolved
-
reporter resolves
#985→ <<cset 64f78f1ec451>>
- Log in to comment
Yes, I’m aware of that .
Actually, I think it is a bug in your enmapbox.gui.mapcanvas.MapCanvas.setLayers() methode.
I noticed that a while ago and noted it in the code, but forgot to create an issue for you: