[QGIS-Developer] PyQGIS zoom to layer not working
Frank Broniewski
broniewski at a-a.lu
Tue Jun 20 03:59:50 PDT 2023
Hi,
I am writing a plugin, in which I am loading a bunch of layers, and I want to zoom on one of them. Layers are loaded through an action (click).
def load_layer(self):
self.project.addMapLayers(
[
self.addresses_layer.layer,
self.adminunits_layer.layer,
self.georecord_layer,
],
addToLegend=False,
)
self.project.addMapLayers(
[
self.geolocation_point_layer.layer,
self.geolocation_line_layer.layer,
self.geolocation_poly_layer.layer,
self.ortho_layer
]
)
self.iface.mapCanvas().setExtent(self.georecord_layer.layer.extent())
self.iface.mapCanvas().refresh()
but unfortunately, that does not work as expected. QGIS zooms just on the ortho_layer in the end. I have the suspicion, that the extent I set, gets overwritten by another layer that loads in in a later stage. Layers are from a PostGIS, and the ortho_layer is a WMS layer.
I tried googleing, mapCanvas().waitWhileRendering() and whatnot, it just will not zoom. I am completely clueless now, so any hints are greatly appreciated.
This is on OSGeo4W, QGIS 3.28 and Python , for explanation, the .layer attribute is the actual QGIS layer …
Many thanks,
Frank
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20230620/3e735e5b/attachment-0001.htm>
More information about the QGIS-Developer
mailing list