Class: QgsLayoutItemMap

class qgis.core.QgsLayoutItemMap

Bases: QgsLayoutItem, QgsTemporalRangeObject

Layout graphical items for displaying a map.

QgsLayoutItemMap(layout: Optional[QgsLayout]) Constructor for QgsLayoutItemMap, with the specified parent layout.

Methods

accept

param visitor:

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

Adjusts the specified point at which a reference position of the item sits and returns the top left corner of the item, if reference point were placed at the specified position.

applyDataDefinedSize

Applies any present data defined size overrides to the specified layout size.

applyItemSizeConstraint

Applies any item-specific size constraint handling to a given targetSize in layout units.

assignFreeId

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

atlasClippingSettings

Returns the map's atlas clipping settings.

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

rtype:

QRectF

childEvent

connectNotify

containsAdvancedEffects

rtype:

bool

containsWmsLayer

Returns True if the map contains a WMS layer.

contextMenuEvent

create

Returns a new map item for the specified layout.

createExpressionContext

rtype:

QgsExpressionContext

crs

Returns coordinate reference system used for rendering the map.

customEvent

disconnectNotify

displayName

rtype:

str

dragEnterEvent

dragLeaveEvent

dragMoveEvent

draw

param context:

drawAnnotations

Returns whether annotations are drawn within the map.

drawBackground

Draws the background for the item.

drawDebugRect

Draws a debugging rectangle of the item's current bounds within the specified painter.

drawFrame

Draws the frame around the item.

drawRefreshingOverlay

Draws a "refreshing" overlay icon on the item.

dropEvent

estimatedFrameBleed

rtype:

float

exportLayerBehavior

rtype:

QgsLayoutItem.ExportLayerBehavior

exportLayerDetails

rtype:

QgsLayoutItem.ExportLayerDetail

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.

framePath

rtype:

QPainterPath

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

rtype:

QIcon

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

itemClippingSettings

Returns the map's item based clip path settings.

itemFlags

rtype:

QgsLayoutItem.Flags

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.

layoutToMapCoordsTransform

Creates a transform from layout coordinates to map coordinates.

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

param dx:

nextExportPart

rtype:

bool

numberExportLayers

rtype:

int

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

param painter:

positionAtReferencePoint

Returns the current position (in layout units) of a reference point for the item.

prepareGeometryChange

presetCrs

Returns the map's preset coordinate reference system.

previewLabelingResults

Returns the labeling results of the most recent preview map render.

readObjectPropertiesFromElement

Sets object properties from a DOM element

readPropertiesFromElement

param element:

receivers

refresh

refreshBackgroundColor

Refresh item's background color, considering data defined colors.

refreshBlendMode

Refresh item's blend mode, considering data defined blend mode.

refreshDataDefinedProperty

param property:

refreshFrame

Refresh item's frame, considering data defined colors and frame size.

refreshItemPosition

Refreshes an item's position by rechecking it against any possible overrides such as data defined positioning.

refreshItemRotation

Refreshes an item's rotation by rechecking it against any possible overrides such as data defined rotation.

refreshItemSize

Refreshes an item's size by rechecking it against any possible item fixed or minimum sizes.

refreshOpacity

Refresh item's opacity, considering data defined opacity.

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

rtype:

bool

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

Sets a fixed size for the layout item, which prevents it from being freely resized.

setFollowVisibilityPreset

Sets whether the map should follow a map theme.

setFollowVisibilityPresetName

Sets preset name for map rendering.

setFrameStrokeWidth

param width:

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

Sets the minimum allowed size for the layout item.

setMoveContentPreviewOffset

param dx:

setScale

Sets new map scale and changes only the map extent.

setZRange

Sets the map's z range, which is used to filter the map's content to only display features within the specified z range.

setZRangeEnabled

Sets whether the z range is enabled (i.e. whether the map will be filtered to content within the zRange().).

startLayeredExport

stopLayeredExport

storeCurrentLayerStyles

Stores the current project layer styles into style overrides.

timerEvent

topLeftToReferencePoint

Returns the position for the reference point of the item, if the top-left of the item was placed at the specified point.

transformedMapPolygon

Returns extent that considers rotation and shift with mOffsetX / mOffsetY

type

rtype:

int

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

Stores object properties within an XML DOM element.

writePropertiesToElement

param element:

zRange

Returns the map's z range, which is used to filter the map's content to only display features within the specified z range.

zRangeEnabled

Returns whether the z range is enabled (i.e. whether the map will be filtered to content within the zRange().).

zoomContent

param factor:

zoomToExtent

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

Signals

crsChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

extentChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

layerStyleOverridesChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

mapRotationChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

preparedForAtlas

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

previewRefreshed

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

themeChanged

pyqtSignal(*types, name: str = ..., revision: int = ..., arguments: Sequence = ...) -> PYQT_SIGNAL

Attributes

Auto

Fixed

Predefined

ShowPartialLabels

ShowUnplacedLabels

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: sip.wrapper

Predefined = 1
ShowPartialLabels = 1
ShowUnplacedLabels = 2
accept(self, visitor: QgsStyleEntityVisitorInterface | None) bool
Parameters:

visitor (Optional[QgsStyleEntityVisitorInterface])

Return type:

bool

addLabelBlockingItem(self, item: QgsLayoutItem | None)

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.

Added in version 3.6.

Parameters:

item (Optional[QgsLayoutItem])

addRenderedFeatureHandler(self, handler: QgsRenderedFeatureHandlerInterface | None)

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.

Added in version 3.10.

Parameters:

handler (Optional[QgsRenderedFeatureHandlerInterface])

adjustPointForReferencePosition(self, point: QPointF | QPoint, size: QSizeF, reference: QgsLayoutItem.ReferencePoint) QPointF

Adjusts the specified point at which a reference position of the item sits and returns the top left corner of the item, if reference point were placed at the specified position.

applyDataDefinedSize(self, size: QgsLayoutSize) QgsLayoutSize

Applies any present data defined size overrides to the specified layout size.

applyItemSizeConstraint(self, targetSize: QSizeF) QSizeF

Applies any item-specific size constraint handling to a given targetSize in layout units. Subclasses can override this method if they need to apply advanced logic regarding item sizes, which cannot be covered by setFixedSize() or setMinimumSize(). Item size constraints are applied after fixed, minimum and data defined size constraints.

See also

setFixedSize()

See also

setMinimumSize()

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.

atlasClippingSettings(self) QgsLayoutItemMapAtlasClippingSettings | None

Returns the map’s atlas clipping settings.

Added in version 3.16.

Return type:

Optional[QgsLayoutItemMapAtlasClippingSettings]

atlasDriven(self) bool

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

setAtlasDriven()

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

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

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.

Return type:

QgsLayoutItemMap.AtlasScalingMode

Returns:

the current scaling mode

Note

this parameter is only used if atlasDriven() is True

See also

atlasDriven()

boundingRect(self) QRectF
Return type:

QRectF

childEvent(self, a0: QChildEvent | None)
connectNotify(self, signal: QMetaMethod)
containsAdvancedEffects(self) bool
Return type:

bool

containsWmsLayer(self) bool

Returns True if the map contains a WMS layer.

Return type:

bool

contextMenuEvent(self, event: QGraphicsSceneContextMenuEvent | None)
create(layout: QgsLayout | None) QgsLayoutItemMap | None

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]

createExpressionContext(self) QgsExpressionContext
Return type:

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()

Return type:

QgsCoordinateReferenceSystem

crsChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

customEvent(self, a0: QEvent | None)
disconnectNotify(self, signal: QMetaMethod)
displayName(self) str
Return type:

str

dragEnterEvent(self, event: QGraphicsSceneDragDropEvent | None)
dragLeaveEvent(self, event: QGraphicsSceneDragDropEvent | None)
dragMoveEvent(self, event: QGraphicsSceneDragDropEvent | None)
draw(self, context: QgsLayoutItemRenderContext)
Parameters:

context (QgsLayoutItemRenderContext)

drawAnnotations(self) bool

Returns whether annotations are drawn within the map.

Return type:

bool

drawBackground(self, context: QgsRenderContext)

Draws the background for the item.

See also

framePath()

drawDebugRect(self, painter: QPainter | None)

Draws a debugging rectangle of the item’s current bounds within the specified painter.

Parameters:

painter – destination QPainter

drawFrame(self, context: QgsRenderContext)

Draws the frame around the item.

See also

framePath()

drawRefreshingOverlay(self, painter: QPainter | None, itemStyle: QStyleOptionGraphicsItem | None)

Draws a “refreshing” overlay icon on the item.

Added in version 3.32.

dropEvent(self, event: QGraphicsSceneDragDropEvent | None)
estimatedFrameBleed(self) float
Return type:

float

exportLayerBehavior(self) QgsLayoutItem.ExportLayerBehavior
Return type:

QgsLayoutItem.ExportLayerBehavior

exportLayerDetails(self) QgsLayoutItem.ExportLayerDetail
Return type:

QgsLayoutItem.ExportLayerDetail

extent(self) QgsRectangle

Returns the current map extent.

See also

extentChanged()

Return type:

QgsRectangle

extentChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

finalizeRestoreFromXml(self)
focusInEvent(self, event: QFocusEvent | None)
focusOutEvent(self, event: QFocusEvent | None)
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.

Return type:

bool

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.

See also

themeChanged()

Return type:

str

framePath(self) QPainterPath
Return type:

QPainterPath

grid(self) QgsLayoutItemMapGrid | None

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

See also

grids()

Return type:

Optional[QgsLayoutItemMapGrid]

grids(self) QgsLayoutItemMapGridStack | None

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

See also

grid()

Return type:

Optional[QgsLayoutItemMapGridStack]

hoverEnterEvent(self, event: QGraphicsSceneHoverEvent | None)
hoverLeaveEvent(self, event: QGraphicsSceneHoverEvent | None)
hoverMoveEvent(self, event: QGraphicsSceneHoverEvent | None)
icon(self) QIcon
Return type:

QIcon

inputMethodEvent(self, event: QInputMethodEvent | None)
inputMethodQuery(self, query: Qt.InputMethodQuery) Any
invalidateCache(self)
isDrawing(self) bool

True if a draw is already in progress

Return type:

bool

isLabelBlockingItem(self, item: QgsLayoutItem | None) 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.

Added in version 3.6.

Parameters:

item (Optional[QgsLayoutItem])

Return type:

bool

isSignalConnected(self, signal: QMetaMethod) bool
itemChange(self, change: QGraphicsItem.GraphicsItemChange, value: Any) Any
itemClippingSettings(self) QgsLayoutItemMapItemClipPathSettings | None

Returns the map’s item based clip path settings.

Added in version 3.16.

Return type:

Optional[QgsLayoutItemMapItemClipPathSettings]

itemFlags(self) QgsLayoutItem.Flags
Return type:

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()

Return type:

bool

keepLayerStyles(self) bool

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

Return type:

bool

keyPressEvent(self, event: QKeyEvent | None)
keyReleaseEvent(self, event: QKeyEvent | None)
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()

Added in version 3.6.

Return type:

QgsLayoutMeasurement

layerStyleOverrides(self) Dict[str, str]

Returns stored overrides of styles for layers.

Return type:

Dict[str, str]

layerStyleOverridesChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_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()

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

Creates a transform from layout coordinates to map coordinates.

Return type:

QTransform

mapFlags(self) QgsLayoutItemMap.MapItemFlags

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

See also

setMapFlags()

Added in version 3.6.

Return type:

QgsLayoutItemMap.MapItemFlags

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 (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

setMapRotation()

Return type:

float

mapRotationChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_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.

Parameters:
  • extent (QgsRectangle)

  • size (QSizeF)

  • dpi (float)

  • includeLayerSettings (bool)

Return type:

QgsMapSettings

mapToItemCoords(self, mapCoords: QPointF | QPoint) QPointF

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

Parameters:

mapCoords (Union[QPointF)

Return type:

QPointF

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.

Return type:

float

mouseDoubleClickEvent(self, event: QGraphicsSceneMouseEvent | None)
mouseMoveEvent(self, event: QGraphicsSceneMouseEvent | None)
mousePressEvent(self, event: QGraphicsSceneMouseEvent | None)
mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent | None)
moveContent(self, dx: float, dy: float)
Parameters:
  • dx (float)

  • dy (float)

nextExportPart(self) bool
Return type:

bool

numberExportLayers(self) int
Return type:

int

overview(self) QgsLayoutItemMapOverview | None

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()

overviews(self) QgsLayoutItemMapOverviewStack | None

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

overview()

paint(self, painter: QPainter | None, itemStyle: QStyleOptionGraphicsItem | None, pWidget: QWidget | None)
Parameters:
  • painter (Optional[QPainter])

  • itemStyle (Optional[QStyleOptionGraphicsItem])

  • pWidget (Optional[QWidget])

positionAtReferencePoint(self, reference: QgsLayoutItem.ReferencePoint) QPointF

Returns the current position (in layout units) of a reference point for the item.

prepareGeometryChange(self)
preparedForAtlas

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_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()

Return type:

QgsCoordinateReferenceSystem

previewLabelingResults(self) QgsLabelingResults | None

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]

previewRefreshed

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

readObjectPropertiesFromElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool

Sets object properties from a DOM element

Parameters:
  • parentElement – is the parent DOM element for the object

  • document – DOM document

  • context – read write context

Returns:

True if read was successful

readPropertiesFromElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool
Parameters:
Return type:

bool

receivers(self, signal: PYQT_SIGNAL) int
refresh(self)
refreshBackgroundColor(self, updateItem: bool = True)

Refresh item’s background color, considering data defined colors. If updateItem is set to False, the item will not be automatically updated after the frame color is set and a later call to update() must be made.

refreshBlendMode(self)

Refresh item’s blend mode, considering data defined blend mode.

refreshDataDefinedProperty(self, property: QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.DataDefinedProperty.AllProperties)
Parameters:

property (QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.DataDefinedProperty.AllProperties)

refreshFrame(self, updateItem: bool = True)

Refresh item’s frame, considering data defined colors and frame size. If updateItem is set to False, the item will not be automatically updated after the frame is set and a later call to update() must be made.

refreshItemPosition(self)

Refreshes an item’s position by rechecking it against any possible overrides such as data defined positioning.

refreshItemRotation(self, origin: QPointF | QPoint | None = None)

Refreshes an item’s rotation by rechecking it against any possible overrides such as data defined rotation.

The optional origin point specifies the origin (in item coordinates) around which the rotation should be applied.

refreshItemSize(self)

Refreshes an item’s size by rechecking it against any possible item fixed or minimum sizes.

See also

setFixedSize()

See also

setMinimumSize()

refreshOpacity(self, updateItem: bool = True)

Refresh item’s opacity, considering data defined opacity. If updateItem is set to False the item will not be automatically updated after the opacity is set and a later call to update() must be made.

removeLabelBlockingItem(self, item: QgsLayoutItem | None)

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.

Added in version 3.6.

Parameters:

item (Optional[QgsLayoutItem])

removeRenderedFeatureHandler(self, handler: QgsRenderedFeatureHandlerInterface | None)

Removes a previously added rendered feature handler.

Added in version 3.10.

Parameters:

handler (Optional[QgsRenderedFeatureHandlerInterface])

renderingErrors(self) List[QgsMapRendererJob.Error]

Returns map rendering errors

Return type:

List[QgsMapRendererJob.Error]

Returns:

list of errors

requestedExtent(self) QgsRectangle

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

Return type:

QgsRectangle

requiresRasterization(self) bool
Return type:

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()

Return type:

float

sceneEvent(self, event: QEvent | None) bool
sceneEventFilter(self, watched: QGraphicsItem | None, event: QEvent | None) bool
sender(self) QObject | None
senderSignalIndex(self) int
setAtlasDriven(self, enabled: bool)

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

atlasDriven()

setAtlasMargin(self, margin: float)

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

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 (QgsLayoutItemMap.AtlasScalingMode) – 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()

Parameters:

crs (QgsCoordinateReferenceSystem)

setDrawAnnotations(self, draw: bool)

Sets whether annotations are drawn within the map.

Parameters:

draw (bool)

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()

Parameters:

extent (QgsRectangle)

setFixedSize(self, size: QgsLayoutSize)

Sets a fixed size for the layout item, which prevents it from being freely resized. Set an empty size if item can be freely resized.

See also

fixedSize()

See also

setMinimumSize()

setFollowVisibilityPreset(self, follow: bool)

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

Parameters:

follow (bool)

setFollowVisibilityPresetName(self, name: str | None)

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

See also

themeChanged()

Parameters:

name (Optional[str])

setFrameStrokeWidth(self, width: QgsLayoutMeasurement)
Parameters:

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()

Parameters:

enabled (bool)

setKeepLayerStyles(self, enabled: bool)

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

Parameters:

enabled (bool)

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()

Added in version 3.6.

Parameters:

margin (QgsLayoutMeasurement)

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

Sets the stored overrides of styles for layers.

Parameters:

overrides (Dict[Optional[str])

setLayers(self, layers: Iterable[QgsMapLayer])

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 (via followVisibilityPreset() and followVisibilityPresetName() ), then this method will have no effect and the layers rendered in the map will always follow the map theme.

See also

layers()

See also

keepLayerSet()

Parameters:

layers (Iterable[QgsMapLayer])

setMapFlags(self, flags: QgsLayoutItemMap.MapItemFlags | QgsLayoutItemMap.MapItemFlag)

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

See also

mapFlags()

Added in version 3.6.

Parameters:

flags (Union[QgsLayoutItemMap.MapItemFlags)

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()

Parameters:

rotation (float)

setMinimumSize(self, size: QgsLayoutSize)

Sets the minimum allowed size for the layout item. Set an empty size if item can be freely resized.

See also

minimumSize()

See also

setFixedSize()

setMoveContentPreviewOffset(self, dx: float, dy: float)
Parameters:
  • 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()

Parameters:
  • scale (float)

  • forceUpdate (bool = True)

setZRange(self, range: QgsDoubleRange)

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() is True.

See also

zRange()

Added in version 3.38.

Parameters:

range (QgsDoubleRange)

setZRangeEnabled(self, enabled: bool)

Sets whether the z range is enabled (i.e. whether the map will be filtered to content within the zRange().)

See also

zRangeEnabled()

Added in version 3.38.

Parameters:

enabled (bool)

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

Stores the current project layer styles into style overrides.

themeChanged

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

Parameters:
  • name (str = ...)

  • revision (int = ...)

  • arguments (Sequence = ...)

Return type:

PYQT_SIGNAL

timerEvent(self, a0: QTimerEvent | None)
topLeftToReferencePoint(self, point: QgsLayoutPoint) QgsLayoutPoint

Returns the position for the reference point of the item, if the top-left of the item was placed at the specified point.

transformedMapPolygon(self) QPolygonF

Returns extent that considers rotation and shift with mOffsetX / mOffsetY

Return type:

QPolygonF

type(self) int
Return type:

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(self)
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

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

extent()

wheelEvent(self, event: QGraphicsSceneWheelEvent | None)
writeObjectPropertiesToElement(self, parentElement: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool

Stores object properties within an XML DOM element.

Parameters:
  • parentElement – is the parent DOM element to store the object’s properties in

  • document – DOM document

  • context – read write context

Returns:

True if write was successful

writePropertiesToElement(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) bool
Parameters:
Return type:

bool

zRange(self) QgsDoubleRange

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() is True.

See also

setZRange()

See also

zRangeEnabled()

Added in version 3.38.

Return type:

QgsDoubleRange

zRangeEnabled(self) bool

Returns whether the z range is enabled (i.e. whether the map will be filtered to content within the zRange().)

See also

zRange()

Added in version 3.38.

Return type:

bool

zoomContent(self, factor: float, point: QPointF | QPoint)
Parameters:
  • factor (float)

  • point (Union[QPointF)

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()

Parameters:

extent (QgsRectangle)