Graphics Reference
In-Depth Information
Filtering the landmarks
The reason our labels are unreadable is because there are too many landmarks being dis-
played. However, not all landmarks are relevant at all zoom levels—we want to hide land-
marks that are too small to be useful when the map is zoomed out, while still showing these
landmarks when the user zooms in. To do this, we'll use a QgsRuleBasedRendererV2
object and make use of the SCALERANK attribute to selectively hide features that are too
small for the current zoom level.
Add the following code to your loadMap() method, before the call to
self.showVisibleMapLayers() :
symbol =
QgsSymbolV2.defaultSymbol(self.landmark_layer.geometryType())
renderer = QgsRuleBasedRendererV2(symbol)
root_rule = renderer.rootRule()
default_rule = root_rule.children()[0]
rule = default_rule.clone()
rule.setFilterExpression("(SCALERANK >= 0) and
(SCALERANK <= 1)")
rule.setScaleMinDenom(0)
rule.setScaleMaxDenom(99999999)
root_rule.appendChild(rule)
rule = default_rule.clone()
rule.setFilterExpression("(SCALERANK >= 2) and
(SCALERANK <= 4)")
rule.setScaleMinDenom(0)
rule.setScaleMaxDenom(10000000)
root_rule.appendChild(rule)
rule = default_rule.clone()
rule.setFilterExpression("(SCALERANK >= 5) and
(SCALERANK <= 7)")
rule.setScaleMinDenom(0)
rule.setScaleMaxDenom(5000000)
root_rule.appendChild(rule)
Search WWH ::




Custom Search