I've written a plugin which loads a number of map layers (based on constraints) and I would thenlike to set the canvas extent to a selection of them. Code very similar to that below works perfectly, except when the plugin imports layers into a project with no layers in. If you load a single layer before running the plugin then it performs fine.
I've tried mapCanvas.refresh() and .repaint() within the plugin but none seem to work - what am I missing?
Many thanks!
extent = QgsRectangle() extent.setMinimal() layers = [ iface.mapCanvas().layers()[0], iface.mapCanvas().layers()[1] ] for layer in layers: extent.combineExtentWith( layer.extent() ) extent.scale( 1.1 ) # Increase a bit the extent to make sure all geometries lie inside iface.mapCanvas().setExtent( extent ) iface.mapCanvas().refresh()
أكثر...
I've tried mapCanvas.refresh() and .repaint() within the plugin but none seem to work - what am I missing?
Many thanks!
extent = QgsRectangle() extent.setMinimal() layers = [ iface.mapCanvas().layers()[0], iface.mapCanvas().layers()[1] ] for layer in layers: extent.combineExtentWith( layer.extent() ) extent.scale( 1.1 ) # Increase a bit the extent to make sure all geometries lie inside iface.mapCanvas().setExtent( extent ) iface.mapCanvas().refresh()
أكثر...