I was wondering if it is possible in QGIS 3.2 to cycle through different layers.

For example, I have a workspace open with 3 raster layers (A, B and C). I would like to create 3 maps:

  • Map A with Layer A and Legend A
  • Map B with Layer B and Legend B
  • Map C with Layer C and Legend C

The only difference in all these maps is the switching of the raster layer and the legend of the layer. Everything else is the same.

I found a similar question before but it appears to be unanswered.

Creating atlas of different layers on the same place (QGIS)

  • Hmmm, I re-read your question and I am now wondering how your project structure is setup. Are your grids actual layers in the project or are they map composer grids. This would make my answer change completely.
    – Gabriel
    Jun 20, 2018 at 1:20
  • @GabrielC. The grids are actual layers in the project. Jun 20, 2018 at 22:58
  • Okay. I'll edit my answer with a second method for layers. The principle is really similar though.
    – Gabriel
    Jun 21, 2018 at 3:47

2 Answers 2


You can set layer visibility (in the layer symbology) based on an atlas variable. Your options for atlas variables are: @atlas_feature, @atlas_featureid, @atlas_geometry and @atlas_pagename.

In QGIS 3.0, use the atlas variable to control whether the layer is enabled.

For example, if your atlas pages are named Map A, Map B and Map C, set the visibility of the grid for Map A like so:

enter image description here

In QGIS 2.18 and earlier, "Enable layer" is not an option. Instead, use a similar method to control the layer transparency. Use this expression for data-defined transparency for Map A:

if(@atlas_pagename = 'Map A', 0, 100)

You can also write your own expressions to control layer visibility within the print composer. enter image description here

Write an expression that outputs a list of map layer names separated by the | character. For example:

  when @atlas_pagename = 'Map A' then 'layerone | layertwo | layerthree'
  when @atlas_pagename = 'Map B' then 'layerone | layertwo | layerfour'
  when @atlas_pagename = 'Map C' then 'layerone | layertwo | layerfive'
  else ''

enter image description here This is how I knew how to format the list of map layer names.

  • Well, I hadn't seen/had to use that enable layer option in 3.x. It sure makes it more straightforward! I would accept this answer.
    – Gabriel
    Jun 27, 2018 at 20:42
  • 1
    Hi, thank you both for taking the time to answer my question. I really appreciate it. I am a bit new to QGIS and print composing, especially in the new QGIS. I am running QGIS 3.2 and I cant seem to find the "Enable Layer" option. I am not sure how to label Atlas Page names. I apologise for being so clueless and I hope my question isnt too confusing. I have updated my question so hopefully it is a bit clearer. Jul 5, 2018 at 6:54
  • @csk: I did not know about the expression that can list an output of map layers. Is it documented somewhere?
    – PieterB
    Jul 5, 2018 at 7:31
  • @PieterB You would have to write it yourself. Follow the example I provided. Substitute your atlas page names where it says 'Map A', 'Map B', etc. Substitute your layer names where it says 'layerone', 'layertwo', etc.
    – csk
    Jul 5, 2018 at 15:57
  • 1
    I edited my answer to show how to figure out the expected input for data-defined layer lock. You can also find one paragraph of documentation on this feature in the user manual, at the end of the section The Map Item > Layers.
    – csk
    Jul 5, 2018 at 20:22

There is a relatively simple solution that I used to show or hide inset maps on different pages of an atlas. Just create the number of grids you need on your map item in the composer and then navigate to the rendering tab for each grid. Then you can go to the expression editor for the opacity parameter and use the following conditional to make the grid either 100% opaque or 100% transparent:

100.0 - (CASE 
   WHEN  @atlas_pagename = 'first atlas page' THEN 0 
   WHEN  @atlas_pagename = 'second atlas page' THEN 100
   WHEN  @atlas_pagename = 'third atlas page' THEN 100

The previous code example shows the map item on the first atlas page and hides it on the second and third. Just change the values accordingly.

There is probably a more elegant way to make this work when you have multiple map items to show or hide but since I only had two insets to deal with, it wasn't long to just copy/paste it to the second item.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.