Directives¶
A directive is a CSS top level declaration that allows control of some aspects of the stylesheet application or translation to SLD. All directives are declared at the beginning of the CSS sheet and follow the same syntax:
@name value;
For example:
@mode 'Flat';
@styleName 'The name';
@styleTitle 'The title';
@styleAbstract 'This is a longer description';
@autoRuleNames 'true';
* {
stroke: black
}
[cat = 10] {
stroke: yellow; stroke-width: 10
}
autoRuleNames¶
The autoRuleNames directive automatically assigns rule names to individual rules in thematic styles. This is useful for instance when creating legends in an application where it is possible to toggle visibility of individual symbols of a theme style. The workflow might look like so:
The application fetches the symbology of the theme layer as JSON ( GetLegendGraphic&FORMAT=application/json) to determine which symbols are available
The application examines the JSON document and fetches the symbol for each rule by rule name (GetLegendGraphic&rule=rulename) and creates a legend displaying all symbols, including their title, with an accompanying radio button for toggling that particular symbol. Letting the client render the title instead of asking Geoserver to do it as part of a composite legend image can allow the legend to look nicer.
When a symbol is toggled, the associated filter from the JSON response is applied to the layer source so that the layer is updated in the map.
Here the name of the rule is not important, there just needs to be a rule name in addition to a title for each rule so that its symbology can be fetched, just like is possible when styling with SLD.
Supported directives¶
Directive |
Type |
Meaning |
Accepts Expression? |
---|---|---|---|
|
String, |
Controls how the CSS is translated to SLD. |
false |
|
String |
The generated SLD style name |
No |
|
String |
The generated SLD style title |
No |
|
String |
The generated SLD style abstract/description |
No |
|
Boolean |
If set to ‘true’, Instructs the translator to give each generated SLD rule a unique name, as a progressive number starting from zero |
No |