Class: QgsLayoutItemMap¶
-
class
qgis.core.
QgsLayoutItemMap
(layout: QgsLayout)¶ Bases:
QgsLayoutItem
Constructor for
QgsLayoutItemMap
, with the specified parentlayout
.Layout graphical items for displaying a map.
New in version 3.0.
- Parameters
layout –
-
class
AtlasScalingMode
¶ Bases:
int
-
Auto
= 2¶
-
Fixed
= 0¶
-
Predefined
= 1¶
-
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.
- 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¶ 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¶ 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() is true
See also
See also
-
boundingRect
(self) → QRectF¶ - Return type
QRectF
-
childEvent
()¶
-
connectNotify
()¶
-
containsAdvancedEffects
(self) → bool¶ - Return type
bool
-
containsWmsLayer
(self) → bool¶ Returns true if the map contains a WMS layer.
- Return type
bool
-
contextMenuEvent
()¶
-
create
(layout: QgsLayout) → QgsLayoutItemMap¶ Returns a new map item for the specified
layout
.The caller takes responsibility for deleting the returned object.
- Parameters
layout (QgsLayout) –
- Return type
-
createExpressionContext
(self) → QgsExpressionContext¶ - Return type
-
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
See also
- Return type
-
customEvent
()¶
-
disconnectNotify
()¶
-
displayName
(self) → str¶ - Return type
str
-
dragEnterEvent
()¶
-
dragLeaveEvent
()¶
-
dragMoveEvent
()¶
-
draw
(self, context: QgsLayoutItemRenderContext)¶ - Parameters
context (QgsLayoutItemRenderContext) –
-
drawAnnotations
(self) → bool¶ Returns whether annotations are drawn within the map.
See also
- Return type
bool
-
drawBackground
()¶
-
drawDebugRect
()¶
-
drawFrame
()¶
-
dropEvent
()¶
-
extent
(self) → QgsRectangle¶ Returns the current map extent.
See also
See also
- Return type
-
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.
- 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
- Return type
str
-
grid
(self) → QgsLayoutItemMapGrid¶ Returns the map item’s first grid. This is a convenience function.
See also
- Return type
-
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
- Return type
-
hoverEnterEvent
()¶
-
hoverLeaveEvent
()¶
-
hoverMoveEvent
()¶
-
icon
(self) → QIcon¶ - Return type
QIcon
-
inputMethodEvent
()¶
-
inputMethodQuery
()¶
-
invalidateCache
(self)¶
-
isDrawing
(self) → bool¶ True if a draw is already in progress
- Return type
bool
-
isSignalConnected
()¶
-
itemChange
()¶
-
itemFlags
(self) → QgsLayoutItem.Flags¶ - Return type
-
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
See also
- Return type
bool
-
keepLayerStyles
(self) → bool¶ Returns whether current styles of layers should be overridden by previously stored styles.
See also
- Return type
bool
-
keyPressEvent
()¶
-
keyReleaseEvent
()¶
-
layerStyleOverrides
(self) → Dict[str, str]¶ Returns stored overrides of styles for layers.
See also
- Return type
Dict[str, str]
-
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
See also
- Return type
List[QgsMapLayer]
-
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.
- Parameters
context (
QgsExpressionContext
= None) –- Return type
List[QgsMapLayer]
-
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
See also
- Return type
float
-
mapRotationChanged
¶ Is emitted when the map’s rotation changes.
See also
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) thenincludeLayerSettings
should be false.- Parameters
extent (QgsRectangle) –
size (QSizeF) –
dpi (float) –
includeLayerSettings (bool) –
- Return type
-
mapToItemCoords
(self, mapCoords: Union[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
()¶
-
mouseMoveEvent
()¶
-
mousePressEvent
()¶
-
mouseReleaseEvent
()¶
-
moveContent
(self, dx: float, dy: float)¶ - Parameters
dx (float) –
dy (float) –
-
numberExportLayers
(self) → int¶ - Return type
int
-
overview
(self) → QgsLayoutItemMapOverview¶ Returns the map item’s first overview. This is a convenience function.
- Return type
- Returns
pointer to first overview for map item
See also
-
overviews
(self) → QgsLayoutItemMapOverviewStack¶ Returns the map item’s overview stack, which is used to control how overviews are drawn over the map’s contents.
- Return type
- Returns
pointer to overview stack
See also
-
paint
(self, painter: QPainter, itemStyle: QStyleOptionGraphicsItem, pWidget: QWidget)¶ - Parameters
painter (QPainter) –
itemStyle (QStyleOptionGraphicsItem) –
pWidget (QWidget) –
-
positionAtReferencePoint
()¶
-
prepareGeometryChange
()¶
-
preparedForAtlas
¶ Is 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
See also
- Return type
-
readObjectPropertiesFromElement
()¶
-
readPropertiesFromElement
(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool¶ - Parameters
element (QDomElement) –
document (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool
-
receivers
()¶
-
refresh
(self)¶
-
refreshBackgroundColor
()¶
-
refreshBlendMode
()¶
-
refreshDataDefinedProperty
(self, property: QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties)¶ - Parameters
property (QgsLayoutObject.DataDefinedProperty = QgsLayoutObject.AllProperties) –
-
refreshFrame
()¶
-
refreshItemPosition
()¶
-
refreshItemRotation
()¶
-
refreshItemSize
()¶
-
refreshOpacity
()¶
-
requestedExtent
(self) → QgsRectangle¶ Calculates the extent to request and the yShift of the top-left point in case of rotation.
- Return type
-
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
- Return type
float
-
sceneEvent
()¶
-
sceneEventFilter
()¶
-
sender
()¶
-
senderSignalIndex
()¶
-
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
See also
-
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
See also
-
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
See also
-
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
See also
- Parameters
crs (QgsCoordinateReferenceSystem) –
-
setDrawAnnotations
(self, draw: bool)¶ Sets whether annotations are drawn within the map.
See also
- 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
See also
- Parameters
extent (QgsRectangle) –
-
setFixedSize
()¶
-
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)¶ Sets preset name for map rendering. See followVisibilityPresetName() for more details.
See also
- Parameters
name (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
See also
- Parameters
enabled (bool) –
-
setKeepLayerStyles
(self, enabled: bool)¶ Sets whether current styles of layers should be overridden by previously stored styles.
See also
- Parameters
enabled (bool) –
-
setLayerStyleOverrides
(self, overrides: Dict[str, str])¶ Sets the stored overrides of styles for layers.
See also
- Parameters
overrides (Dict[str) –
-
setLayers
(self, layers: Iterable[QgsMapLayer])¶ Sets the stored
layers
set. If empty, the current project layers will be used instead.See also
See also
- Parameters
layers (Iterable[QgsMapLayer]) –
-
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
See also
- Parameters
rotation (float) –
-
setMinimumSize
()¶
-
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
- Parameters
scale (float) –
forceUpdate (bool = True) –
-
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
- 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
()¶
-
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
-
wheelEvent
()¶
-
writeObjectPropertiesToElement
()¶
-
writePropertiesToElement
(self, element: QDomElement, document: QDomDocument, context: QgsReadWriteContext) → bool¶ - Parameters
element (QDomElement) –
document (QDomDocument) –
context (QgsReadWriteContext) –
- Return type
bool
-
zoomContent
(self, factor: float, point: Union[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
- Parameters
extent (QgsRectangle) –