How do I style different elements of a layer differently, depending on the value of an attribute?
For example, I have time zone data which includes an attribute associating an integer from 1 to 8 to each time zone, for the purposes of colouring the time zones on a map. How can I associate a style to each value of the attribute, and use it to colour the time zones in different colours?
This answer is for Geotools 9.2
Below is an example which you can adopt, see below for some ideas how to apply it to your requirements.
The example is about polygons. It has different styles for selected and visible features and for small and large scales:
Of course optimizations are possible and welcome.
For your requirement the following may help:
FilterFactory.equals(Expression, Expression)
where first expression is of typeAttributeExpressionImpl
and second of typeLiteralExpressionImpl
equal
(without s) in FilterFactory2