Bug report #20006

When using map_get() in expressions referencing multiple maps in print composer, map does not refresh automatically

Added by Robert Carey over 5 years ago.

Category:Map Composer/Printing
Affected QGIS version:3.2.3 Regression?:No
Operating System:Microsoft Windows 10 Pro Easy fix?:No
Pull Request or Patch supplied:No Resolution:
Crashes QGIS or corrupts data:No Copied to github as #:27828


When exporting from a Layout with inset maps, these is unexpected behaviour concerning the use of the map_get function. The expression functions correctly if the map is refreshed before being exported to PDF, but if exported before this point (such as when using an atlas or the QGIS API), the refresh does not occur. This can be demonstrated in the below scenario (my current issue).

I have a map consisting of a walking routes. A layout has been created with atlas enabled to create maps for each route. I have included an inset map which overlaps the main map area, but which moves to a different position around the map if the inset map intersects the geometry. I was able to do this using map_get location to calculate the map extent of the main map, and move the X and Y positions of the inset map if they overlapped.

A simple example would be as follows (changing the X position of the INSET map):

--checks if the inset map intersect the walking route
--geometry 1: creating a bounding box square from the bottom left corner to 40.5% of the maps width which represents the position of the inset map
point_n( map_get( item_variables( 'FULLMAP' ), 'map_extent' ) ,1)
,make_point(X(point_n(map_get( item_variables( 'FULLMAP' ), 'map_extent' ) ,1))+(0.405*map_get( item_variables( 'FULLMAP' ), 'map_extent_width' ))
,Y(point_n(map_get( item_variables( 'FULLMAP' ), 'map_extent' ) ,1))+ (0.405*map_get( item_variables( 'FULLMAP' ), 'map_extent_width' )))
--intersecting with map geometry which is the same between both maps, controlled by the atlas filter query
, @atlas_geometry ) = 0 --when the route does not intersect the inset map
THEN '100' --map is visible
ELSE '0' --map is not visible

In the above example, viewing the atlas pages individually, I can see the inset map overlapping the geometry of the main map, which is unexpected. However, if I open the position expression for the inset map without changing it, the map refreshes and the map moves outside the map bounds as expected. Similarly, pressing F5 allows the position to change as expected.

My issue is that when exporting an atlas, or using the API to perform this function, there appears to be no way to force this refresh. I have included an example QGZ project and shapefile containing 5 routes. This is the x and y positions of the inset map are dictated by the extent and geometry of the full map. The map is also dynamically landscape/portrait. Preview the atlas and notice the inset map begins overlapping the feature. Refreshing the layout with F5 moves the inset map to its correct position.

Walking_Routes_Example.zip - QGZ files and shapefile of walking routes (14.7 KB) Robert Carey, 2018-10-03 05:08 PM

Also available in: Atom PDF