Skip to content


Implement $map variable, which returns the current composer map item …
Browse files Browse the repository at this point in the history
…id where the map is being drawn, or 'canvas' if the map is being drawn in the main QGIS window. Partly implements #9288.
  • Loading branch information
nyalldawson committed Jan 5, 2014
1 parent 9a58828 commit c45bf50
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
16 changes: 16 additions & 0 deletions resources/function_help/$map
@@ -0,0 +1,16 @@
<h3>$map function</h3>
Returns the id of the current map item if the map is being drawn in a composition, or "canvas" if the map is being
drawn within the main QGIS window.



<!-- Show example of function.-->
<pre>$map &rarr; "overview_map" (within a composer item)<br />
$map &rarr; "canvas" (within the main QGIS main canvas)</pre>

4 changes: 4 additions & 0 deletions src/core/composer/qgscomposermap.cpp
Expand Up @@ -28,6 +28,7 @@
#include "qgsscalecalculator.h"
#include "qgsvectorlayer.h"
#include "qgspallabeling.h"
#include "qgsexpression.h"

#include "qgslabel.h"
#include "qgslabelattributes.h"
Expand Down Expand Up @@ -226,6 +227,9 @@ void QgsComposerMap::draw( QPainter *painter, const QgsRectangle& extent, const
bool bkLayerCaching = s.value( "/qgis/enable_render_caching", false ).toBool();
s.setValue( "/qgis/enable_render_caching", false );

//update $map variable. Use QgsComposerItem's id since that is user-definable
QgsExpression::setSpecialColumn( "$map", QgsComposerItem::id() );

if ( forceWidthScale ) //force wysiwyg line widths / marker sizes
theMapRenderer.render( painter, forceWidthScale );
Expand Down
3 changes: 3 additions & 0 deletions src/gui/qgsmapcanvas.cpp
Expand Up @@ -417,6 +417,9 @@ void QgsMapCanvas::refresh()

mDrawing = true;

//update $map variable to canvas
QgsExpression::setSpecialColumn( "$map", tr( "canvas" ) );

if ( mRenderFlag && !mFrozen )
Expand Down

0 comments on commit c45bf50

Please sign in to comment.