I'm working with 3.22.10-Białowieża and I need to create several maps of the same location, showing a different layer in each (i.e. heatmaps for different years). This is the workflow that I have set, but still needs a final fix:
- Create a layer (years) with no geometries and filled it with the names of the layers I want to use (an easy automated task, since the names are correlative: heatmap_1999, heatmap_2000…);
- Create a new print layout with the map extent I need;
- Create an atlas for that layout, using the
years
layer as coverage; - Set the visibility of the layers in the
Element properties
of the map with the expression@atlas_pagename
. - Create the atlas preview, and it correctly shows each layer in each page.
So far, so good. However, I need to add a baselayer to the view and I've tried the following expression, but it doesn't work as expected:
'Base_map'||'|'||@atlas_pagename
Instead of this (obtained when the atlas preview is switched off):
I get this:
How can it be done?
Edit:
Here is a sample project (hope I've used the Project Packager
complement properly). For the base layer I'm using a WMS and double-clicking on its name when constructing the expression, so misspelling shouldn't be the problem -> Well, it turns out yes: see the answer by @Babel below.
Best Answer
Use this syntax:
'Base_map|'||@atlas_pagename
. However, in this case, the basemap is rendered above the atlas page and will cover it.To see the basemap in the background and the atlas features above it, use the expression in switched order:
@atlas_pagename || '|Base_map'
As became clear when you shared your project, the problem in your case was that your
Base_map
layer was not properlay named. You had:Use the following expression, then it works:
Be aware: To get the correct layer name, do not double click the layer's entry from the middle column (under Map Layers) in expression string builder, as this inserts the
layer ID
(name + sting), but rather uselayer_property( [layer_id], 'name')
, where insted of[layer_id]
, fill in thelayer ID
.