Most of the time, you do not have to create a totally
new renderer. You can use one of the default renderers that are supplied
in the package and tailor it to your needs.
This section shows how to extend an
IlvDefaultPointRenderer to add text of the type
IlvLabel next to the point of the feature being rendered.
It also shows the use of
IlvMapRenderingStyle which are the classes used by the renderers in order
to customize them. For instance, in this code example, the color of
the labels generated by the renderer is obtained through the
IlvMapPointRenderingStyle of the
IlvDefaultPointRenderer.
The complete source code for the example in this section
can be found in the following file:
The text is stored in an attribute whose name is provided
for the class MarkerTextRenderer
. When
this text exists, it is returned with the marker generated by the
superclass of the renderer; otherwise only the marker is returned.
public IlvGraphic makeGraphic(IlvMapFeature feature,
IlvCoordinateTransformation tr)
throws IlvMapRenderException, IlvCoordinateTransformationException
{
// Let the super class create the marker.
IlvMarker marker = (IlvMarker)super.makeGraphic(feature, tr);
// Create label if needed.
IlvLabel label = null;
IlvFeatureAttributeProperty attributeList = feature.getAttributes();
if (attributeList != null) {
try {
IlvFeatureAttribute attribute = null;
attribute = attributeList.getAttribute(myAttributeName);
if (attribute != null)
label = new IlvLabel(marker.getPoint(), attribute.toString());
} catch (IllegalArgumentException e) {
label = null;
}
}
// Case no label: return marker.
if (label == null) {
return marker;
}
// Else generate a graphic set containing the marker as the label.
else {
// Make this label of the same color than the marker.
label.setForeground(getPointRenderingStyle().getMarkerColor());
IlvGraphicSet set = new IlvGraphicSet();
set.addObject(marker, false);
set.addObject(label, false);
return set;
}
}