from qgis.gui import QgsMapCanvas from qgis.core import QgsRectangle canvas = QgsMapCanvas() extent = QgsRectangle(10, 10, 20, 20) # define the extent with xmin, ymin, xmax, ymax values canvas.setExtent(extent)
from qgis.gui import QgsMapCanvas canvas = QgsMapCanvas() current_extent = canvas.extent()
from qgis.gui import QgsMapCanvas from qgis.core import QgsRectangle canvas = QgsMapCanvas() layer = iface.activeLayer() # get the currently active layer layer_extent = layer.extent() # get the extent of the layer canvas.setExtent(layer_extent) # set the extent of the canvas to the extent of the layer canvas.zoomToFullExtent() # zoom to the full extent of the layerThis example demonstrates how to zoom the QgsMapCanvas to the full extent of a map layer. Firstly, we get the extent of the currently active layer and use it to set the extent of the canvas. Then, we use the zoomToFullExtent() method to zoom the canvas to the full extent of the layer. Package library: qgis.gui