Each map feature can also have attributes. If the map
feature is a town, its attributes can be its name, or the number of
inhabitants. Attributes can be used, for example, for graphical rendering.
In the section
Creating a colored line renderer,
the color of polylines representing contour lines on a map is defined
by the elevation attribute.
Attributes belong to the class
IlvFeatureAttribute
.
They are stored in the following two classes of the
ilog.views.maps package:
IlvAttributeInfoProperty,
which defines the attribute properties, such as name, type, mandatory,
or optional characters.
-
The following code example lists the attributes of an
IlvMapFeature object and displays them on the screen:
public void dumpAttributes(IlvMapFeature feature)
{
IlvAttributeInfoProperty info = feature.getAttributeInfo();
IlvFeatureAttributeProperty attributes = feature.getAttributes();
// Attributes are not mandatory in a feature.
if ((info == null) || (attributes == null)) {
System.out.println("This feature has no attribute");
return;
}
for (int i = 0; i < info.getAttributesCount(); i++) {
String name = info.getAttributeName(i);
IlvFeatureAttribute attribute = attributes.getAttribute(i);
System.out.println("The attribute " + name +
" takes the value " + attribute.toString());
}
}
The attributes are of different types, according to whether
they represent whole numbers, floating-point values, character strings,
and so on. The predefined attributes, all of the
IlvFeatureAttribute class, are in the
ilog.views.maps.attribute package.