Class: QgsLayoutItemMap¶
Layout graphical items for displaying a map.
Class Hierarchy¶
Base classes¶
Base class for graphical items within a |
|
A base class for objects which belong to a layout. |
|
Abstract interface for generating an expression context. |
|
Interface for layout objects which support undo/redo commands. |
|
Base class for objects with an associated (optional) temporal range. |
Methods
Sets the specified layout item as a "label blocking item" for this map. |
|
Adds a rendered feature handler to use while rendering the map. |
|
Sets the map |
|
Returns the map's atlas clipping settings. |
|
Returns whether the map extent is set to follow the current atlas feature. |
|
Returns the margin size (percentage) used when the map is in atlas mode. |
|
Returns the current atlas scaling mode. |
|
Returns |
|
Returns coordinate reference system used for rendering the map. |
|
Returns whether annotations are drawn within the map. |
|
Returns the current map extent. |
|
Returns whether the map should follow a map theme. |
|
Preset name that decides which layers and layer styles are used for map rendering. |
|
Returns the map item's first grid. |
|
Returns the map item's grid stack, which is used to control how grids are drawn over the map's contents. |
|
True if a draw is already in progress |
|
Returns |
|
Returns the map's item based clip path settings. |
|
Returns whether a stored layer set should be used or the current layer set from the project associated with the layout. |
|
Returns whether current styles of layers should be overridden by previously stored styles. |
|
Returns the margin from the map edges in which no labels may be placed. |
|
Returns stored overrides of styles for layers. |
|
Returns the stored layer set. |
|
Returns a list of the layers which will be rendered within this map item, considering any locked layers, linked map theme, and data defined settings. |
|
Creates a transform from layout coordinates to map coordinates. |
|
Returns the map item's flags, which control how the map content is drawn. |
|
Returns the rotation used for drawing the map within the layout item, in degrees clockwise. |
|
Returns map settings that will be used for drawing of the map. |
|
Transforms map coordinates to item coordinates (considering rotation and move offset) |
|
Returns the conversion factor from map units to layout units. |
|
Returns the map item's first overview. |
|
Returns the map item's overview stack, which is used to control how overviews are drawn over the map's contents. |
|
Returns the map's preset coordinate reference system. |
|
Returns the labeling results of the most recent preview map render. |
|
Removes the specified layout item from the map's "label blocking items". |
|
Removes a previously added rendered feature handler. |
|
Returns map rendering errors |
|
Calculates the extent to request and the yShift of the top-left point in case of rotation. |
|
Returns the map scale. |
|
Sets whether the map extent will follow the current atlas feature. |
|
Sets the margin size (percentage) used when the map is in atlas mode. |
|
Sets the current atlas scaling mode. |
|
Sets the map's preset crs (coordinate reference system). |
|
Sets whether annotations are drawn within the map. |
|
Sets a new extent for the map. |
|
Sets whether the map should follow a map theme. |
|
Sets preset name for map rendering. |
|
Sets whether the stored layer set should be used or the current layer set of the associated project. |
|
Sets whether current styles of layers should be overridden by previously stored styles. |
|
Sets the margin from the map edges in which no labels may be placed. |
|
Sets the stored overrides of styles for layers. |
|
Sets the stored layers set. |
|
Sets the map item's flags, which control how the map content is drawn. |
|
Sets the rotation for the map - this does not affect the layout item shape, only the way the map is drawn within the item. |
|
Sets new map scale and changes only the map extent. |
|
Sets the map's z range, which is used to filter the map's content to only display features within the specified z range. |
|
Sets whether the z range is enabled (i.e. whether the map will be filtered to content within the |
|
Stores the current project layer styles into style overrides. |
|
Returns extent that considers rotation and shift with mOffsetX / mOffsetY |
|
Updates the bounding rect of this item. |
|
Returns a polygon representing the current visible map extent, considering map extents and rotation. |
|
Returns the map's z range, which is used to filter the map's content to only display features within the specified z range. |
|
Returns whether the z range is enabled (i.e. whether the map will be filtered to content within the |
|
Zooms the map so that the specified extent is fully visible within the map item. |
Virtual Methods
In PyQGIS, only methods marked as virtual
can be safely overridden in a Python subclass of QgsLayoutItemMap. See the FAQ for more details.
Static Methods
Returns a new map item for the specified layout. |
Signals
Emitted when the map's coordinate reference system is changed. |
|
Emitted when the map's extent changes. |
|
Emitted when layer style overrides are changed. |
|
Emitted when the map's rotation changes. |
|
Emitted when the map has been prepared for atlas rendering, just before actual rendering |
|
Emitted whenever the item's map preview has been refreshed. |
|
Emitted when the map's associated theme is changed. |
Attributes
- class qgis.core.QgsLayoutItemMap[source]¶
Bases:
QgsLayoutItem
,QgsTemporalRangeObject
- __init__(layout: QgsLayout | None)
Constructor for QgsLayoutItemMap, with the specified parent
layout
.- Parameters:
layout (Optional[QgsLayout])
- class AtlasScalingMode¶
Bases:
int
- Auto = 2¶
- Fixed = 0¶
- class MapItemFlag¶
Bases:
int
- class MapItemFlags¶
- class MapItemFlags(f: QgsLayoutItemMap.MapItemFlags | QgsLayoutItemMap.MapItemFlag)
- class MapItemFlags(a0: QgsLayoutItemMap.MapItemFlags)
Bases:
object
- Predefined = 1¶
- ShowPartialLabels = 1¶
- ShowUnplacedLabels = 2¶
- addLabelBlockingItem(self, item: QgsLayoutItem | None)[source]¶
Sets the specified layout
item
as a “label blocking item” for this map.Items which are marked as label blocking items prevent any map labels from being placed in the area of the map item covered by the
item
.See also
See also
Added in version 3.6.
- Parameters:
item (Optional[QgsLayoutItem])
- addRenderedFeatureHandler(self, handler: QgsRenderedFeatureHandlerInterface | None)[source]¶
Adds a rendered feature
handler
to use while rendering the map.Ownership of
handler
is NOT transferred, and it is the caller’s responsibility to ensure that the handler exists for as long as it is registered with the map item.Callers should call
removeRenderedFeatureHandler()
to remove the handler before destroying thehandler
.See also
Added in version 3.10.
- Parameters:
handler (Optional[QgsRenderedFeatureHandlerInterface])
- assignFreeId(self)[source]¶
Sets the map
id()
to a number not yet used in the layout. The existingid()
is kept if it is not in use.
- atlasClippingSettings(self) QgsLayoutItemMapAtlasClippingSettings | None [source]¶
Returns the map’s atlas clipping settings.
Added in version 3.16.
- Return type:
Optional[QgsLayoutItemMapAtlasClippingSettings]
- atlasDriven(self) bool [source]¶
Returns whether the map extent is set to follow the current atlas feature.
- Return type:
bool
- Returns:
True
if map will follow the current atlas feature.
See also
See also
- atlasMargin(self, valueType: QgsLayoutObject.PropertyValueType = QgsLayoutObject.EvaluatedValue) float [source]¶
Returns the margin size (percentage) used when the map is in atlas mode.
- Parameters:
valueType (QgsLayoutObject.PropertyValueType = QgsLayoutObject.EvaluatedValue) – controls whether the returned value is the user specified atlas margin, or the current evaluated atlas margin (which may be affected by data driven atlas margin settings).
- Return type:
float
- Returns:
margin size in percentage to leave around the atlas feature’s extent
Note
this is only used if
atlasScalingMode()
is Auto.See also
See also
- atlasScalingMode(self) QgsLayoutItemMap.AtlasScalingMode [source]¶
Returns the current atlas scaling mode. This controls how the map’s extents are calculated for the current atlas feature when an atlas composition is enabled.
- Return type:
- Returns:
the current scaling mode
Note
this parameter is only used if
atlasDriven()
isTrue
See also
See also
- containsWmsLayer(self) bool [source]¶
Returns
True
if the map contains a WMS layer.- Return type:
bool
- static create(layout: QgsLayout | None) QgsLayoutItemMap | None [source]¶
Returns a new map item for the specified
layout
.The caller takes responsibility for deleting the returned object.
- Parameters:
layout (Optional[QgsLayout])
- Return type:
Optional[QgsLayoutItemMap]
- crs(self) QgsCoordinateReferenceSystem [source]¶
Returns coordinate reference system used for rendering the map. This will match the
presetCrs()
if that is set, or if a preset CRS is not set then the map’s CRS will follow the composition’s project’s CRS.See also
See also
- Return type:
- signal crsChanged[source]¶
Emitted when the map’s coordinate reference system is changed.
Added in version 3.18.
- drawAnnotations(self) bool [source]¶
Returns whether annotations are drawn within the map.
See also
- Return type:
bool
- extent(self) QgsRectangle [source]¶
Returns the current map extent.
See also
See also
- Return type:
- followVisibilityPreset(self) bool [source]¶
Returns whether the map should follow a map theme. If
True
, the layers and layer styles will be used from given preset name (configured withsetFollowVisibilityPresetName()
method). This means when preset’s settings are changed, the new settings are automatically picked up next time when rendering, without having to explicitly update them. At most one of the flagskeepLayerSet()
andfollowVisibilityPreset()
should be enabled at any time since they are alternative approaches - if both are enabled, following map theme has higher priority. If neither is enabled (or if preset name is not set), map will use the same configuration as the map canvas uses.- Return type:
bool
- followVisibilityPresetName(self) str [source]¶
Preset name that decides which layers and layer styles are used for map rendering. It is only used when
followVisibilityPreset()
returnsTrue
.See also
See also
- Return type:
str
- grid(self) QgsLayoutItemMapGrid | None [source]¶
Returns the map item’s first grid. This is a convenience function.
See also
- Return type:
Optional[QgsLayoutItemMapGrid]
- grids(self) QgsLayoutItemMapGridStack | None [source]¶
Returns the map item’s grid stack, which is used to control how grids are drawn over the map’s contents.
See also
- Return type:
Optional[QgsLayoutItemMapGridStack]
- isLabelBlockingItem(self, item: QgsLayoutItem | None) bool [source]¶
Returns
True
if the specifieditem
is a “label blocking item”.Items which are marked as label blocking items prevent any map labels from being placed in the area of the map item covered by the item.
See also
See also
Added in version 3.6.
- Parameters:
item (Optional[QgsLayoutItem])
- Return type:
bool
- itemClippingSettings(self) QgsLayoutItemMapItemClipPathSettings | None [source]¶
Returns the map’s item based clip path settings.
Added in version 3.16.
- Return type:
Optional[QgsLayoutItemMapItemClipPathSettings]
- keepLayerSet(self) bool [source]¶
Returns whether a stored layer set should be used or the current layer set from the project associated with the layout. This is just a GUI flag, and itself does not change which layers are rendered in the map. Instead, use
setLayers()
to control which layers are rendered.See also
See also
- Return type:
bool
- keepLayerStyles(self) bool [source]¶
Returns whether current styles of layers should be overridden by previously stored styles.
See also
- Return type:
bool
- labelMargin(self) QgsLayoutMeasurement [source]¶
Returns the margin from the map edges in which no labels may be placed.
If the margin is 0 then labels can be placed right up to the edge (and possibly overlapping the edge) of the map.
See also
Added in version 3.6.
- Return type:
- layerStyleOverrides(self) Dict[str, str] ¶
Returns stored overrides of styles for layers.
See also
- Return type:
Dict[str, str]
- signal layerStyleOverridesChanged[source]¶
Emitted when layer style overrides are changed… a means to let associated legend items know they should update
- layers(self) List[QgsMapLayer] ¶
Returns the stored layer set. If empty, the current project layers will be used instead.
See also
See also
- Return type:
List[QgsMapLayer]
- layersToRender(self, context: QgsExpressionContext | None = None) List[QgsMapLayer] ¶
Returns a list of the layers which will be rendered within this map item, considering any locked layers, linked map theme, and data defined settings.
- Parameters:
context (Optional[QgsExpressionContext] = None)
- Return type:
List[QgsMapLayer]
- layoutToMapCoordsTransform(self) QTransform [source]¶
Creates a transform from layout coordinates to map coordinates.
- Return type:
QTransform
- mapFlags(self) QgsLayoutItemMap.MapItemFlags [source]¶
Returns the map item’s flags, which control how the map content is drawn.
See also
Added in version 3.6.
- Return type:
- mapRotation(self, valueType: QgsLayoutObject.PropertyValueType = QgsLayoutObject.EvaluatedValue) float [source]¶
Returns the rotation used for drawing the map within the layout item, in degrees clockwise.
- Parameters:
valueType (QgsLayoutObject.PropertyValueType = QgsLayoutObject.EvaluatedValue) – controls whether the returned value is the user specified rotation, or the current evaluated rotation (which may be affected by data driven rotation settings).
See also
See also
- Return type:
float
- signal mapRotationChanged(newRotation: float)[source]¶
Emitted when the map’s rotation changes.
See also
See also
- Parameters:
newRotation (float)
- mapSettings(self, extent: QgsRectangle, size: QSizeF, dpi: float, includeLayerSettings: bool) QgsMapSettings [source]¶
Returns map settings that will be used for drawing of the map.
If
includeLayerSettings
isTrue
, than settings specifically relating to map layers and map layer styles will be calculated. This can be expensive to calculate, so if they are not required in the map settings (e.g. for map settings which are used for scale related calculations only) thenincludeLayerSettings
should beFalse
.- Parameters:
extent (QgsRectangle)
size (QSizeF)
dpi (float)
includeLayerSettings (bool)
- Return type:
- mapToItemCoords(self, mapCoords: QPointF | QPoint) QPointF [source]¶
Transforms map coordinates to item coordinates (considering rotation and move offset)
- Parameters:
mapCoords (Union[QPointF, QPoint])
- Return type:
QPointF
- mapUnitsToLayoutUnits(self) float [source]¶
Returns the conversion factor from map units to layout units. This is calculated using the width of the map item and the width of the current visible map extent.
- Return type:
float
- overview(self) QgsLayoutItemMapOverview | None [source]¶
Returns the map item’s first overview. This is a convenience function.
- Return type:
Optional[QgsLayoutItemMapOverview]
- Returns:
pointer to first overview for map item
See also
- overviews(self) QgsLayoutItemMapOverviewStack | None [source]¶
Returns the map item’s overview stack, which is used to control how overviews are drawn over the map’s contents.
- Return type:
Optional[QgsLayoutItemMapOverviewStack]
- Returns:
pointer to overview stack
See also
- signal preparedForAtlas[source]¶
Emitted when the map has been prepared for atlas rendering, just before actual rendering
- presetCrs(self) QgsCoordinateReferenceSystem [source]¶
Returns the map’s preset coordinate reference system. If set, this CRS will be used to render the map regardless of any project CRS setting. If the returned CRS is not valid then the project CRS will be used to render the map.
See also
See also
- Return type:
- previewLabelingResults(self) QgsLabelingResults | None [source]¶
Returns the labeling results of the most recent preview map render. May be
None
if no map preview has been rendered in the item.The map item retains ownership of the returned results.
Added in version 3.20.
- Return type:
Optional[QgsLabelingResults]
- signal previewRefreshed[source]¶
Emitted whenever the item’s map preview has been refreshed.
Added in version 3.20.
- removeLabelBlockingItem(self, item: QgsLayoutItem | None)[source]¶
Removes the specified layout
item
from the map’s “label blocking items”.Items which are marked as label blocking items prevent any map labels from being placed in the area of the map item covered by the item.
See also
See also
Added in version 3.6.
- Parameters:
item (Optional[QgsLayoutItem])
- removeRenderedFeatureHandler(self, handler: QgsRenderedFeatureHandlerInterface | None)[source]¶
Removes a previously added rendered feature
handler
.See also
Added in version 3.10.
- Parameters:
handler (Optional[QgsRenderedFeatureHandlerInterface])
- renderingErrors(self) List[QgsMapRendererJob.Error] [source]¶
Returns map rendering errors
- Return type:
List[QgsMapRendererJob.Error]
- Returns:
list of errors
- requestedExtent(self) QgsRectangle [source]¶
Calculates the extent to request and the yShift of the top-left point in case of rotation.
- Return type:
- scale(self) float [source]¶
Returns the map scale. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.
See also
- Return type:
float
- setAtlasDriven(self, enabled: bool)[source]¶
Sets whether the map extent will follow the current atlas feature.
- Parameters:
enabled (bool) – set to
True
if the map extents should be set by the current atlas feature.
See also
See also
- setAtlasMargin(self, margin: float)[source]¶
Sets the margin size (percentage) used when the map is in atlas mode.
- Parameters:
margin (float) – size in percentage to leave around the atlas feature’s extent
Note
this is only used if
atlasScalingMode()
is Auto.See also
See also
- setAtlasScalingMode(self, mode: QgsLayoutItemMap.AtlasScalingMode)[source]¶
Sets the current atlas scaling mode. This controls how the map’s extents are calculated for the current atlas feature when an atlas composition is enabled.
- Parameters:
mode (QgsLayoutItemMap.AtlasScalingMode) – atlas scaling mode to set
Note
this parameter is only used if
atlasDriven()
isTrue
See also
See also
- setCrs(self, crs: QgsCoordinateReferenceSystem)[source]¶
Sets the map’s preset
crs
(coordinate reference system). If a valid CRS is set, this CRS will be used to render the map regardless of any project CRS setting. If the CRS is not valid then the project CRS will be used to render the map.See also
See also
- Parameters:
- setDrawAnnotations(self, draw: bool)[source]¶
Sets whether annotations are drawn within the map.
See also
- Parameters:
draw (bool)
- setExtent(self, extent: QgsRectangle)[source]¶
Sets a new
extent
for the map. This method may change the width or height of the map item to ensure that the extent exactly matches the specified extent, with no overlap or margin. This method implicitly alters the map scale.See also
See also
- Parameters:
extent (QgsRectangle)
- setFollowVisibilityPreset(self, follow: bool)[source]¶
Sets whether the map should follow a map theme. See
followVisibilityPreset()
for more details.- Parameters:
follow (bool)
- setFollowVisibilityPresetName(self, name: str | None)[source]¶
Sets preset name for map rendering. See
followVisibilityPresetName()
for more details.See also
See also
- Parameters:
name (Optional[str])
- setKeepLayerSet(self, enabled: bool)[source]¶
Sets whether the stored layer set should be used or the current layer set of the associated project. This is just a GUI flag, and itself does not change which layers are rendered in the map. Instead, use
setLayers()
to control which layers are rendered.See also
See also
- Parameters:
enabled (bool)
- setKeepLayerStyles(self, enabled: bool)[source]¶
Sets whether current styles of layers should be overridden by previously stored styles.
See also
- Parameters:
enabled (bool)
- setLabelMargin(self, margin: QgsLayoutMeasurement)[source]¶
Sets the
margin
from the map edges in which no labels may be placed.If the margin is 0 then labels can be placed right up to the edge (and possibly overlapping the edge) of the map.
See also
Added in version 3.6.
- Parameters:
margin (QgsLayoutMeasurement)
- setLayerStyleOverrides(self, overrides: Dict[str | None, str | None])[source]¶
Sets the stored overrides of styles for layers.
See also
- Parameters:
overrides (Dict[Optional[str], Optional[str]])
- setLayers(self, layers: Iterable[QgsMapLayer])[source]¶
Sets the stored
layers
set. If empty, the current project layers will be used. If the map item is set to follow a map theme (viafollowVisibilityPreset()
andfollowVisibilityPresetName()
), then this method will have no effect and the layers rendered in the map will always follow the map theme.See also
See also
See also
See also
- Parameters:
layers (Iterable[QgsMapLayer])
- setMapFlags(self, flags: QgsLayoutItemMap.MapItemFlags | QgsLayoutItemMap.MapItemFlag)[source]¶
Sets the map item’s
flags
, which control how the map content is drawn.See also
Added in version 3.6.
- Parameters:
flags (Union[QgsLayoutItemMap.MapItemFlags, QgsLayoutItemMap.MapItemFlag])
- setMapRotation(self, rotation: float)[source]¶
Sets the
rotation
for the map - this does not affect the layout item shape, only the way the map is drawn within the item. Rotation is in degrees, clockwise.See also
See also
- Parameters:
rotation (float)
- setScale(self, scale: float, forceUpdate: bool = True)[source]¶
Sets new map
scale
and changes only the map extent.The
scale
value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.See also
- Parameters:
scale (float)
forceUpdate (bool = True)
- setZRange(self, range: QgsDoubleRange)[source]¶
Sets the map’s z
range
, which is used to filter the map’s content to only display features within the specified z range.Note
This is only considered when
zRangeEnabled()
isTrue
.See also
See also
Added in version 3.38.
- Parameters:
range (QgsDoubleRange)
- setZRangeEnabled(self, enabled: bool)[source]¶
Sets whether the z range is
enabled
(i.e. whether the map will be filtered to content within thezRange()
.)See also
Added in version 3.38.
- Parameters:
enabled (bool)
- storeCurrentLayerStyles(self)[source]¶
Stores the current project layer styles into style overrides.
- signal themeChanged(theme: str)[source]¶
Emitted when the map’s associated
theme
is changed.Note
This signal is not emitted when the definition of the theme changes, only the map is linked to a different theme then it previously was.
Added in version 3.14.
- Parameters:
theme (str)
- transformedMapPolygon(self) QPolygonF [source]¶
Returns extent that considers rotation and shift with mOffsetX / mOffsetY
- Return type:
QPolygonF
- updateBoundingRect(self)[source]¶
Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle
- visibleExtentPolygon(self) QPolygonF [source]¶
Returns a polygon representing the current visible map extent, considering map extents and rotation. If the map rotation is 0, the result is the same as currentMapExtent
- Return type:
QPolygonF
- Returns:
polygon with the four corner points representing the visible map extent. The points are clockwise, starting at the top-left point
See also
- zRange(self) QgsDoubleRange [source]¶
Returns the map’s z range, which is used to filter the map’s content to only display features within the specified z range.
Note
This is only considered when
zRangeEnabled()
isTrue
.See also
See also
Added in version 3.38.
- Return type:
- zRangeEnabled(self) bool [source]¶
Returns whether the z range is enabled (i.e. whether the map will be filtered to content within the
zRange()
.)See also
See also
Added in version 3.38.
- Return type:
bool
- zoomToExtent(self, extent: QgsRectangle)[source]¶
Zooms the map so that the specified
extent
is fully visible within the map item. This method will not change the width or height of the map, and may result in an overlap or margin from the specified extent. This method implicitly alters the map scale.See also
- Parameters:
extent (QgsRectangle)