Backgroundlayer is shown in foreground

Issue #985 resolved
Benjamin Jakimow created an issue

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:

  1. Start QGIS + EnMAP-Box
  2. Type “World” to QGIS coordinate field to open the world example layer
  3. Visualize this layer in the EnMAP-Box
  4. Add Background layer via mapcanvas “Show background layer” menu

Comments (26)

  1. Andreas Janz

    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:

  2. Benjamin Jakimow 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.

  3. Andreas Janz

    Yes yes, I tried both orderings, layer first and layer last. Both resulted in the false ordering.

  4. Benjamin Jakimow 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,

  5. Andreas Janz

    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.

  6. Benjamin Jakimow reporter

    Maybe it’s better to remove these methods that offer direct access to the map canvas layer list because of problem 3.

  7. Andreas Janz

    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 😅

  8. Andreas Janz

    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:

  9. Andreas Janz

    Sorry, really have no idea, what you want to say with your long text block. Maybe we better talk.

  10. Benjamin Jakimow reporter

    Works well in a fresh checkout. Please close this issue if you found out how pull the updates properly.

  11. Log in to comment