Bug report #10980
Can't set new map extent after changed layer visibilty
Status: | Closed | ||
---|---|---|---|
Priority: | Severe/Regression | ||
Assignee: | - | ||
Category: | Python plugins | ||
Affected QGIS version: | master | Regression?: | No |
Operating System: | Ubuntu | Easy fix?: | No |
Pull Request or Patch supplied: | No | Resolution: | invalid |
Crashes QGIS or corrupts data: | No | Copied to github as #: | 19323 |
Description
After adding a layer with python and change its visibility, I cannot change the map extent properly. It seems that the map canvas zooms to full extent (or latest added layer):
- add layer
root = QgsProject.instance().layerTreeRoot() QgsMapLayerRegistry.instance().addMapLayer(my_layer) my_layer_node = root.findLayer(my_layer.id()) my_layer_node.setVisible(Qt.Checked)
- set map extent
rect = another_layer.extent() rect.scale(5) self.iface.mapCanvas().setExtent(rect) self.iface.mapCanvas().refresh()
Map extent is wrong and is set to the extent of the newly added layer. Withoutmy_layer_node.setVisible(Qt.Checked)
it works. The same happens when you add a layer explicit:
- add layer
QgsMapLayerRegistry.instance().addMapLayer(my_layer, False) my_layer_node = root.addLayer(my_layer)
- set map extent
rect = another_layer.extent() rect.scale(5) self.iface.mapCanvas().setExtent(rect) self.iface.mapCanvas().refresh()
-> Wrong map extent (since the layer is visible by default).
History
#1 Updated by Paolo Cavallini over 10 years ago
- Subject changed from Can't set new map pextent after changed layer visibilty to Can't set new map extent after changed layer visibilty
#2 Updated by Giovanni Manghi over 10 years ago
- Status changed from Open to Feedback
what qgis version? was this issue true also on other (older) qgis releases?
#3 Updated by zicke - over 10 years ago
Giovanni Manghi wrote:
what qgis version? was this issue true also on other (older) qgis releases?
Master. (see also affected version combobox).
No, It worked on some 2.1 master so I guess it was introduced with the legend refactoring.
#4 Updated by Giovanni Manghi over 10 years ago
- Priority changed from Normal to Severe/Regression
#5 Updated by Giovanni Manghi about 10 years ago
- Status changed from Feedback to Open
#6 Updated by Martin Dobias about 10 years ago
Could you provide more details regarding how you run these snippets? Setting of canvas extents works for me when used from python console.
Is the other layer "another_layer" also used in the layer tree? In case the "my_layer" layer is the first one to be added to the layer tree, the auto-setup will take effect (deferred) and it will set extent + CRS automatically. Maybe that's why it gives you the impression that the extent is wrong?
#7 Updated by Jürgen Fischer about 10 years ago
- Status changed from Open to Feedback
#8 Updated by Jürgen Fischer almost 10 years ago
- Status changed from Feedback to Closed
- Resolution set to not reproducable
closing for the lack of feedback
#9 Updated by zicke - over 9 years ago
- Status changed from Closed to Reopened
Sorry for not giving some feedback. I used to get some email updates for my tickets but not this time. But I still have some troubles with that one. There is not need for a second layer to reproduce it. Am adding some vector layer within a python plugin:
root = QgsProject.instance().layerTreeRoot() QgsMapLayerRegistry.instance().addMapLayer(my_layer, False) my_layer_node = root.addLayer(my_layer) rect = my_layer.extent() rect.scale(5) self.iface.mapCanvas().setExtent(rect) self.iface.mapCanvas().refresh()
Setting extent works.
root = QgsProject.instance().layerTreeRoot() QgsMapLayerRegistry.instance().addMapLayer(my_layer) my_layer_node = root.findLayer(my_layer.id()) my_layer_node.setVisible(Qt.Checked) rect = my_layer.extent() rect.scale(5) self.iface.mapCanvas().setExtent(rect) self.iface.mapCanvas().refresh()
Setting extent does not work when using .setVisible() method.
#10 Updated by Giovanni Manghi over 9 years ago
- Resolution deleted (
not reproducable)
#11 Updated by Nathan Woodrow over 9 years ago
I can't see anything wrong here. It sets the extent for me.
#12 Updated by Giovanni Manghi over 9 years ago
- Status changed from Reopened to Feedback
#13 Updated by Anita Graser about 9 years ago
Cannot reproduce on OSGeo4W nightly. Setting extent works just fine.
#14 Updated by Nyall Dawson about 9 years ago
- Resolution set to invalid
- Status changed from Feedback to Closed
Closed due to lack of feedback