Bug report #19736

Unable to get list of map layers from a map item in the layout

Added by Harrissou Santanna about 6 years ago. Updated about 6 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Expressions
Affected QGIS version:3.3(master) Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:27561

Description

If I write in a label item of the layout an expression like map_get(item_variables('Map 1'), 'map_scale') it returns the current scale of the "Map 1" item.
If I write map_get(item_variables('Map 1'), 'map_layers'), I get an empty label. Same thing with map_layer_ids.

History

#1 Updated by Nyall Dawson about 6 years ago

That's because the values aren't strings or numbers - you need to format them by converting the list to a string, etc. It's the same behaviour with geometries, dates, intervals, etc.

#2 Updated by Harrissou Santanna about 6 years ago

Ok I get it using something like array_to_string( array_foreach( map_get( item_variables( 'Map 1' ), 'map_layers'), layer_property(@element, 'name'))).
Just awesome!!! Thanks.

Then I remark that I get all the layers checked in the Layers panel and not only the layers whose features are visible in the map item. Likewise, when I lock the map item with a map_theme i get the map theme layers (regardless what is displayed in the main canvas, which is great).
BUT I wonder if there should not be a method to filter list of layers by map item content (like the legend item option).

#3 Updated by Nyall Dawson about 6 years ago

Ok, but that's a feature request ;)

#4 Updated by Harrissou Santanna about 6 years ago

  • Status changed from Open to Closed

Done in #19745

#5 Updated by Giovanni Manghi about 6 years ago

  • Resolution set to invalid

Also available in: Atom PDF