Style element
The style element is the building block for affecting the appearance of rendered geometry, such as color, opacity, texturing, and so on.
Style formats
osgEarth supports two ways to define style information: CSS (cascading style sheet) and SLD (OGC styled layer decriptors).
CSS styling
CSS styling is based on the OGC SLD specification for CSS style parameters. For example, this style definition will color lines yellow, make them 2.0 units with, and give them 50% transparency:
<style type="text/css">
element {
stroke: #FF0000;
stroke-width: 2.0;
stroke-opacity: 0.5;
}
</style>
Polygons require use of the "fill" CSS parameters, like so:
<style type="text/css">
element {
fill: #FF0000;
fill-opacity: 0.5;
}
</style>
SLD/XML styling
SLD/XML is a verbose XML description for styling feature data. Support for this is still under development.
Styling Approaches
When styling a model layer, you can either a) apply one style to the entire layer (general styling), or you can break down feature data into "classes" and style each one separately.
General styling
To apply a general style to the entire layer, just include a <style> block that references the feature source name. Example:
<model ...>
<features name="world" driver="ogr">
<url>data/world.shp</url>
<ogr_driver>ESRI Shapefile</ogr_driver>
</features>
<style type="text/css">
world {
fill: #FF0000;
fill-opacity: 0.5;
}
</style>
</model>
Note that the CSS tag "world" matches the name of the feature source that it is styling. Why do this? Because you can also include that style in an external .css file, along with the rest of your stylesheet. Inlining in the .earth file is just a shortcut.
Styling by feature class
If the feature source supports it (see the OGR driver) you can break down your features into categories and style each one separately. This is a nice way to apply attribute-dependent symbology to your vector data.
This example draws French-speaking countries in yellow, and non-French-speaking countries in red:
<model ...>
<features name="world" driver="ogr">
<url>data/world.shp</url>
<ogr_driver>ESRI Shapefile</ogr_driver>
</features>
<class name="french-speaking">
<query>
<expr> french="true" </expr>
</query>
<style type="text/css">
world {
fill: #FFFF00;
fill-opacity: 0.5;
}
</style>
</class>
<class name="non-french-speaking">
<query>
<expr> french="false" </expr>
</query>
<style type="text/css">
world {
fill: #FF0000;
fill-opacity: 0.5;
}
</style>
</class>
</model>
The <expr>? tag is an SQL expression that gets evaluated by the feature data source. In this example, we are simply testing the value of one feature attribute and categorizing the data based on its value.
Type the repo sample feature_stencil_polygon_draping.earth to see it in action.
