3

Is it possible, to get a signal, when something (user or script) changes layer scale visibility?

I tried

layer.configChanged.connect(self.test_2)
layer.flagsChanged.connect(self.test_2)
layer.metadataChanged.connect(self.test_2)
layer.rendererChanged.connect(self.test_2)
layer.styleChanged.connect(self.test_2)

and other signals of QgsMapLayer, QgsVectorLayer, QgsLayerTreeNode.

Maybe I'm missing some signal or class?

1 Answer 1

0

The scale is a function of the canvas. Layers don't have a scale. The layer can be displayed in a canvas at a particular scale.

QgsMapCanvas (which in a plugin can be accessed through iface.mapCanvas()) has a scaleChanged signal.

2
  • You are talking about changing canvas scale, which isn't what I'm looking for. Layers have scale based visibility. Like layer will be visible only on scales from 100:1 to 2000:1. I'm want to know when this parameter changes.
    – Dezmonder
    Commented Jul 20 at 18:18
  • Ah. From looking at the source code for QgsMapLayer, it does not look like setting minimumScale, maximumScale, or hasScaleBasedVisibility properties triggers any signal. But depending on what you are trying to capture that change for, there may be other ways to do what you want to do. E.g., using the canvas scaleChanged signal in combination with the layer’s isInScaleRange method would let you detect when the layer becomes visible or hidden based on the scale.
    – couteau
    Commented Jul 20 at 21:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.