Class: QgsLayoutItemMap

class qgis.core.QgsLayoutItemMap(layout: QgsLayout)

Bases: qgis._core.QgsLayoutItem

Constructor for QgsLayoutItemMap, with the specified parent layout.

Layout graphical items for displaying a map.

New in version 3.0: Enums

Methods

accept

addLabelBlockingItem

Sets the specified layout item as a “label blocking item” for this map.

addRenderedFeatureHandler

Adds a rendered feature handler to use while rendering the map.

adjustPointForReferencePosition

applyDataDefinedSize

applyItemSizeConstraint

assignFreeId

Sets the map id() to a number not yet used in the layout.

atlasDriven

Returns whether the map extent is set to follow the current atlas feature.

atlasMargin

Returns the margin size (percentage) used when the map is in atlas mode.

atlasScalingMode

Returns the current atlas scaling mode.

boundingRect

childEvent

connectNotify

containsAdvancedEffects

containsWmsLayer

Returns True if the map contains a WMS layer.

contextMenuEvent

create

Returns a new map item for the specified layout.

createExpressionContext

crs

Returns coordinate reference system used for rendering the map.

customEvent

disconnectNotify

displayName

dragEnterEvent

dragLeaveEvent

dragMoveEvent

draw

drawAnnotations

Returns whether annotations are drawn within the map.

drawBackground

drawDebugRect

drawFrame

dropEvent

exportLayerBehavior

exportLayerDetails

extent

Returns the current map extent.

finalizeRestoreFromXml

focusInEvent

focusOutEvent

followVisibilityPreset

Returns whether the map should follow a map theme.

followVisibilityPresetName

Preset name that decides which layers and layer styles are used for map rendering.

grid

Returns the map item’s first grid.

grids

Returns the map item’s grid stack, which is used to control how grids are drawn over the map’s contents.

hoverEnterEvent

hoverLeaveEvent

hoverMoveEvent

icon

inputMethodEvent

inputMethodQuery

invalidateCache

isDrawing

True if a draw is already in progress

isLabelBlockingItem

Returns True if the specified item is a “label blocking item”.

isSignalConnected

itemChange

itemFlags

keepLayerSet

Returns whether a stored layer set should be used or the current layer set from the project associated with the layout.

keepLayerStyles

Returns whether current styles of layers should be overridden by previously stored styles.

keyPressEvent

keyReleaseEvent

labelMargin

Returns the margin from the map edges in which no labels may be placed.

layerStyleOverrides

Returns stored overrides of styles for layers.

layers

Returns the stored layer set.

layersToRender

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.

mapFlags

Returns the map item’s flags, which control how the map content is drawn.

mapRotation

Returns the rotation used for drawing the map within the layout item, in degrees clockwise.

mapSettings

Returns map settings that will be used for drawing of the map.

mapToItemCoords

Transforms map coordinates to item coordinates (considering rotation and move offset)

mapUnitsToLayoutUnits

Returns the conversion factor from map units to layout units.

mouseDoubleClickEvent

mouseMoveEvent

mousePressEvent

mouseReleaseEvent

moveContent

nextExportPart

numberExportLayers

overview

Returns the map item’s first overview.

overviews

Returns the map item’s overview stack, which is used to control how overviews are drawn over the map’s contents.

paint

positionAtReferencePoint

prepareGeometryChange

presetCrs

Returns the map’s preset coordinate reference system.

readObjectPropertiesFromElement

readPropertiesFromElement

receivers

refresh

refreshBackgroundColor

refreshBlendMode

refreshDataDefinedProperty

refreshFrame

refreshItemPosition

refreshItemRotation

refreshItemSize

refreshOpacity

removeLabelBlockingItem

Removes the specified layout item from the map’s “label blocking items”.

removeRenderedFeatureHandler

Removes a previously added rendered feature handler.

renderingErrors

Returns map rendering errors

requestedExtent

Calculates the extent to request and the yShift of the top-left point in case of rotation.

requiresRasterization

scale

Returns the map scale.

sceneEvent

sceneEventFilter

sender

senderSignalIndex

setAtlasDriven

Sets whether the map extent will follow the current atlas feature.

setAtlasMargin

Sets the margin size (percentage) used when the map is in atlas mode.

setAtlasScalingMode

Sets the current atlas scaling mode.

setCrs

Sets the map’s preset crs (coordinate reference system).

setDrawAnnotations

Sets whether annotations are drawn within the map.

setExtent

Sets a new extent for the map.

setFixedSize

setFollowVisibilityPreset

Sets whether the map should follow a map theme.

setFollowVisibilityPresetName

Sets preset name for map rendering.

setFrameStrokeWidth

setKeepLayerSet

Sets whether the stored layer set should be used or the current layer set of the associated project.

setKeepLayerStyles

Sets whether current styles of layers should be overridden by previously stored styles.

setLabelMargin

Sets the margin from the map edges in which no labels may be placed.

setLayerStyleOverrides

Sets the stored overrides of styles for layers.

setLayers

Sets the stored layers set.

setMapFlags

Sets the map item’s flags, which control how the map content is drawn.

setMapRotation

Sets the rotation for the map - this does not affect the layout item shape, only the way the map is drawn within the item.

setMinimumSize

setMoveContentPreviewOffset

setScale

Sets new map scale and changes only the map extent.

startLayeredExport

stopLayeredExport

storeCurrentLayerStyles

Stores the current project layer styles into style overrides.

timerEvent

topLeftToReferencePoint

transformedMapPolygon

Returns extent that considers rotation and shift with mOffsetX / mOffsetY

type

updateBoundingRect

Updates the bounding rect of this item.

updateMicroFocus

visibleExtentPolygon

Returns a polygon representing the current visible map extent, considering map extents and rotation.

wheelEvent

writeObjectPropertiesToElement

writePropertiesToElement

zoomContent

zoomToExtent

Zooms the map so that the specified extent is fully visible within the map item.

Signals

extentChanged

Emitted when the map’s extent changes.

layerStyleOverridesChanged

Emitted when layer style overrides are changed…

mapRotationChanged

Emitted when the map’s rotation changes.

preparedForAtlas

Emitted when the map has been prepared for atlas rendering, just before actual rendering [signal]

Attributes

Auto

Fixed

Predefined

ShowPartialLabels

ShowUnplacedLabels

class AtlasScalingMode

Bases: int

Auto = 2
Fixed = 0
class MapItemFlag

Bases: int

class MapItemFlags

Bases: sip.wrapper

QgsLayoutItemMap.MapItemFlags(Union[QgsLayoutItemMap.MapItemFlags, QgsLayoutItemMap.MapItemFlag]) QgsLayoutItemMap.MapItemFlags(QgsLayoutItemMap.MapItemFlags)

Predefined = 1
ShowPartialLabels = 1
ShowUnplacedLabels = 2
accept(self, visitor: QgsStyleEntityVisitorInterface) → bool
addLabelBlockingItem(self, item: QgsLayoutItem)

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.

New in version 3.6.

addRenderedFeatureHandler(self, handler: QgsRenderedFeatureHandlerInterface)

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 the handler.

New in version 3.10.

adjustPointForReferencePosition()
applyDataDefinedSize()
applyItemSizeConstraint()
assignFreeId(self)

Sets the map id() to a number not yet used in the layout. The existing id() is kept if it is not in use.

atlasDriven(self) → bool

Returns whether the map extent is set to follow the current atlas feature.

Returns

True if map will follow the current atlas feature.

See also

setAtlasDriven()

atlasMargin(self, valueType: QgsLayoutObject.PropertyValueType = QgsLayoutObject.EvaluatedValue) → float

Returns the margin size (percentage) used when the map is in atlas mode.

Parameters

valueType – 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).

Returns

margin size in percentage to leave around the atlas feature’s extent

Note

this is only used if atlasScalingMode() is Auto.

See also

setAtlasMargin()

atlasScalingMode(self) → QgsLayoutItemMap.AtlasScalingMode

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.

Returns

the current scaling mode

Note

this parameter is only used if atlasDriven() is True

See also

atlasDriven()

boundingRect(self) → QRectF
childEvent()
connectNotify()
containsAdvancedEffects(self) → bool
containsWmsLayer(self) → bool

Returns True if the map contains a WMS layer.

contextMenuEvent()
create(layout: QgsLayout) → QgsLayoutItemMap

Returns a new map item for the specified layout.

The caller takes responsibility for deleting the returned object.

createExpressionContext(self) → QgsExpressionContext
crs(self) → QgsCoordinateReferenceSystem

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

presetCrs()

See also

setCrs()

customEvent()
disconnectNotify()
displayName(self) → str
dragEnterEvent()
dragLeaveEvent()
dragMoveEvent()
draw(self, context: QgsLayoutItemRenderContext)
drawAnnotations(self) → bool

Returns whether annotations are drawn within the map.

drawBackground()
drawDebugRect()
drawFrame()
dropEvent()
exportLayerBehavior(self) → QgsLayoutItem.ExportLayerBehavior
exportLayerDetails(self) → QgsLayoutItem.ExportLayerDetail
extent(self) → QgsRectangle

Returns the current map extent.

See also

extentChanged()

extentChanged

Emitted when the map’s extent changes.

See also

setExtent()

See also

extent() [signal]

finalizeRestoreFromXml(self)
focusInEvent()
focusOutEvent()
followVisibilityPreset(self) → bool

Returns whether the map should follow a map theme. If True, the layers and layer styles will be used from given preset name (configured with setFollowVisibilityPresetName() 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 flags keepLayerSet() and followVisibilityPreset() 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.

followVisibilityPresetName(self) → str

Preset name that decides which layers and layer styles are used for map rendering. It is only used when followVisibilityPreset() returns True.

grid(self) → QgsLayoutItemMapGrid

Returns the map item’s first grid. This is a convenience function.

See also

grids()

grids(self) → QgsLayoutItemMapGridStack

Returns the map item’s grid stack, which is used to control how grids are drawn over the map’s contents.

See also

grid()

hoverEnterEvent()
hoverLeaveEvent()
hoverMoveEvent()
icon(self) → QIcon
inputMethodEvent()
inputMethodQuery()
invalidateCache(self)
isDrawing(self) → bool

True if a draw is already in progress

isLabelBlockingItem(self, item: QgsLayoutItem) → bool

Returns True if the specified item 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.

New in version 3.6.

isSignalConnected()
itemChange()
itemFlags(self) → QgsLayoutItem.Flags
keepLayerSet(self) → bool

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

layers()

keepLayerStyles(self) → bool

Returns whether current styles of layers should be overridden by previously stored styles.

keyPressEvent()
keyReleaseEvent()
labelMargin(self) → QgsLayoutMeasurement

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

setLabelMargin()

New in version 3.6.

layerStyleOverrides(self) → Dict[str, str]

Returns stored overrides of styles for layers.

layerStyleOverridesChanged

Emitted when layer style overrides are changed… a means to let associated legend items know they should update [signal]

layers(self) → List[QgsMapLayer]

Returns the stored layer set. If empty, the current project layers will be used instead.

See also

setLayers()

See also

keepLayerSet()

layersToRender(self, context: QgsExpressionContext = 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.

mapFlags(self) → QgsLayoutItemMap.MapItemFlags

Returns the map item’s flags, which control how the map content is drawn.

See also

setMapFlags()

New in version 3.6.

mapRotation(self, valueType: QgsLayoutObject.PropertyValueType = QgsLayoutObject.EvaluatedValue) → float

Returns the rotation used for drawing the map within the layout item, in degrees clockwise.

Parameters

valueType – 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

setMapRotation()

mapRotationChanged

Emitted when the map’s rotation changes.

See also

setMapRotation()

See also

mapRotation() [signal]

mapSettings(self, extent: QgsRectangle, size: QSizeF, dpi: float, includeLayerSettings: bool) → QgsMapSettings

Returns map settings that will be used for drawing of the map.

If includeLayerSettings is True, 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) then includeLayerSettings should be False.

mapToItemCoords(self, mapCoords: Union[QPointF, QPoint]) → QPointF

Transforms map coordinates to item coordinates (considering rotation and move offset)

mapUnitsToLayoutUnits(self) → float

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.

mouseDoubleClickEvent()
mouseMoveEvent()
mousePressEvent()
mouseReleaseEvent()
moveContent(self, dx: float, dy: float)
nextExportPart(self) → bool
numberExportLayers(self) → int
overview(self) → QgsLayoutItemMapOverview

Returns the map item’s first overview. This is a convenience function.

Returns

pointer to first overview for map item

See also

overviews()

overviews(self) → QgsLayoutItemMapOverviewStack

Returns the map item’s overview stack, which is used to control how overviews are drawn over the map’s contents.

Returns

pointer to overview stack

See also

overview()

paint(self, painter: QPainter, itemStyle: QStyleOptionGraphicsItem, pWidget: QWidget)
positionAtReferencePoint()
prepareGeometryChange()
preparedForAtlas

Emitted when the map has been prepared for atlas rendering, just before actual rendering [signal]

presetCrs(self) → QgsCoordinateReferenceSystem

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

crs()

See also

setCrs()

readObjectPropertiesFromElement()
readPropertiesFromElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool
receivers()
refresh(self)
refreshBackgroundColor()
refreshBlendMode()
refreshDataDefinedProperty(self, property: QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties)
refreshFrame()
refreshItemPosition()
refreshItemRotation()
refreshItemSize()
refreshOpacity()
removeLabelBlockingItem(self, item: QgsLayoutItem)

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.

New in version 3.6.

removeRenderedFeatureHandler(self, handler: QgsRenderedFeatureHandlerInterface)

Removes a previously added rendered feature handler.

New in version 3.10.

renderingErrors(self) → List[QgsMapRendererJob.Error]

Returns map rendering errors

Returns

list of errors

requestedExtent(self) → QgsRectangle

Calculates the extent to request and the yShift of the top-left point in case of rotation.

requiresRasterization(self) → bool
scale(self) → float

Returns the map scale. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

See also

setScale()

sceneEvent()
sceneEventFilter()
sender()
senderSignalIndex()
setAtlasDriven(self, enabled: bool)

Sets whether the map extent will follow the current atlas feature.

Parameters

enabled – set to True if the map extents should be set by the current atlas feature.

See also

atlasDriven()

setAtlasMargin(self, margin: float)

Sets the margin size (percentage) used when the map is in atlas mode.

Parameters

margin – size in percentage to leave around the atlas feature’s extent

Note

this is only used if atlasScalingMode() is Auto.

See also

atlasMargin()

setAtlasScalingMode(self, mode: QgsLayoutItemMap.AtlasScalingMode)

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 – atlas scaling mode to set

Note

this parameter is only used if atlasDriven() is True

See also

atlasDriven()

setCrs(self, crs: QgsCoordinateReferenceSystem)

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

crs()

See also

presetCrs()

setDrawAnnotations(self, draw: bool)

Sets whether annotations are drawn within the map.

setExtent(self, extent: QgsRectangle)

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

zoomToExtent()

See also

extentChanged()

setFixedSize()
setFollowVisibilityPreset(self, follow: bool)

Sets whether the map should follow a map theme. See followVisibilityPreset() for more details.

setFollowVisibilityPresetName(self, name: str)

Sets preset name for map rendering. See followVisibilityPresetName() for more details.

setFrameStrokeWidth(self, width: QgsLayoutMeasurement)
setKeepLayerSet(self, enabled: bool)

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

keepLayerSet()

See also

layers()

setKeepLayerStyles(self, enabled: bool)

Sets whether current styles of layers should be overridden by previously stored styles.

setLabelMargin(self, margin: QgsLayoutMeasurement)

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

labelMargin()

New in version 3.6.

setLayerStyleOverrides(self, overrides: Dict[str, str])

Sets the stored overrides of styles for layers.

setLayers(self, layers: Iterable[QgsMapLayer])

Sets the stored layers set. If empty, the current project layers will be used instead.

See also

layers()

See also

keepLayerSet()

setMapFlags(self, flags: Union[QgsLayoutItemMap.MapItemFlags, QgsLayoutItemMap.MapItemFlag])

Sets the map item’s flags, which control how the map content is drawn.

See also

mapFlags()

New in version 3.6.

setMapRotation(self, rotation: float)

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

mapRotation()

setMinimumSize()
setMoveContentPreviewOffset(self, dx: float, dy: float)
setScale(self, scale: float, forceUpdate: bool = True)

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

scale()

startLayeredExport(self)
stopLayeredExport(self)
storeCurrentLayerStyles(self)

Stores the current project layer styles into style overrides.

timerEvent()
topLeftToReferencePoint()
transformedMapPolygon(self) → QPolygonF

Returns extent that considers rotation and shift with mOffsetX / mOffsetY

type(self) → int
updateBoundingRect(self)

Updates the bounding rect of this item. Call this function before doing any changes related to annotation out of the map rectangle

updateMicroFocus()
visibleExtentPolygon(self) → QPolygonF

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

Returns

polygon with the four corner points representing the visible map extent. The points are clockwise, starting at the top-left point

See also

extent()

wheelEvent()
writeObjectPropertiesToElement()
writePropertiesToElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool
zoomContent(self, factor: float, point: Union[QPointF, QPoint])
zoomToExtent(self, extent: QgsRectangle)

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

setExtent()