Please read everything, there are some updates starting from QGIS 3.4 to QGIS 3.18.
In QGIS 3.4, you can build your attribution label automatically, according to layers which are visible.
First, you need to setup metadata for all your layers.
In QGIS 3.4.0 or 3.4.4, you had to use the
QGIS Server panel and fill the
Since QGIS 3.4.5, you can use the
In my project, I have 3 layers, but 2 layers have the same attribution
Then, in your layout, give an
itemID to your map:
Then, in your label, you can create an expression like this:
array_to_string( -- 4 we make the attribution list unique and convert to string
array_foreach( --2 for each layer in the map1
map_get(item_variables('map1'),'map_layers') --1 get the list of layers in the map1
-- 3 we fetch the attribution for the layer
Try to understand the expression by reading comments from 1 to 4.
This will render the correct attribution based on layers which are visible in my map. It will also remove attributions which are the same across layers.
In QGIS 3.6.0, you can add the
array_sort expression to sort alphabetically.
In QGIS 3.18, there is now a
map_credits( 'Main Map' ) expression function which does all the
layer_properties etc ... !