A IlvMapAttributeFilter object is used to
compute the value of a styling attribute from a value found in an IlvGraphic instance. Typically, this value is
retrieved from the IlvFeatureAttributeProperty named property
attached to a
IlvGraphic
object. To install such a filter, you set it to an IlvMapStyle object.
The following example shows a custom filter
class that defines the foreground of map graphic objects according
to their “VALUE” feature attribute.
/** * Computes the foreground from a graphic's IlvFeatureAttribute */ class ColorAttributeFilter implements IlvMapAttributeFilter { /** * Method that returns the new color computed from the "VALUE" * feature attribute. If DEFAULT_VALUE is returned, the style value on which * the filter is installed will not be affected. */ public Object get(IlvGraphic g, String attributeName) { if(IlvPolylineStyle.FOREGROUND.equals(attributeName)) { IlvAttributeProperty p = (IlvAttributeProperty) g.getNamedProperty(IlvAttributeProperty.NAME); if(p == null) return DEFAULT_VALUE; Object o = p.getValue("VALUE"); Object ret = convertObjectToColor(o); if(ret == null) return DEFAULT_VALUE; return ret; } }
The following code example shows how to
install a custom filter class in a map layer style.
IlvMapAttributeFilter filter = new ColorAttributeFilter(); IlvMapLayer layer = getLayer(); IlvMapStyle style = layer.getStyle(); style.setAttributeFilter(filter);
Once the filter is installed, each request
to retrieve an attribute value is passed to the get method of the
filter.