Reputation: 1068
In a Mapnik XML Style element, is there any way to set defaults for a given symbolizer? In the following example, I want the first rule to be the default and the second to change only the polygon color, i.e., use my default opacity of 0.5:
<Style name="MyStyle">
<Rule>
<PolygonSymbolizer fill="gray" fill-opacity="0.5"/>
</Rule>
<Rule>
<Filter>([some_field] < 2)</Filter>
<PolygonSymbolizer fill="red"/>
</Rule>
</Style>
What actually happens is that features matching the filter turn red AND have their opacity set to 1. Is there any way to get what I want without repeating the fill opacity in every rule?
Upvotes: 1
Views: 452
Reputation: 1068
Both what I originally thought was happening and Sergey's answer are only partially correct, so I'll post a fuller explanation here.
In Mapnik, all matching rules are applied in the order matched (given the default value for filter-mode
). The examples in my question and Sergey's answer will render both polygon symbolizers, one on top of the other. In other words, a symbolizer in one rule really has nothing to do with a symbolizer in other rules, except that they all get stacked on top of each other unless filters are mutually exclusive. I can't think of a use for this behavior, but that's how it appears to work.
Summary: alternate versions of the same symbolizer must be placed in mutually exclusive rules and must explicitly set all desired options. There is no way to set a default symbolizer and partially override it.
Upvotes: 1
Reputation: 21
As I know, you can not do that with rules. But you can use rgba colors for fill polygons with opacity.
Try this:
<Style name="MyStyle">
<Rule>
<PolygonSymbolizer fill="rgba(204, 204, 204, 0.5)" />
</Rule>
<Rule>
<Filter>([some_field] < 2)</Filter>
<PolygonSymbolizer fill="rgba(255, 0, 0, 0.5)" />
</Rule>
</Style>
Upvotes: 1