既存レンダラーの拡張

ほとんどの場合、レンダラーを最初から記述する必要はありません。パッケージで提供されているいずれかのデフォルトのレンダラーを使用して、必要に応じて変更できます。
このセクションでは、 IlvDefaultPointRenderer を拡張して、レンダリングする機能ポイントの横に、タイプ IlvLabel のテキストを追加する方法について説明します。また、カスタマイズ用にレンダラーで使用するクラスである IlvMapRenderingStyle の使用方法についても説明します。例えば、次のコードン例では、レンダラーで作成するラベルの色は、IlvDefaultPointRenderer.IlvMapPointRenderingStyle を介して取得されます。
このセクションに示す例のソース・コード一式は、以下のファイルにあります。
テキストは、クラス MarkerTextRenderer に名前が提供される属性に格納されます。このテキストがある場合、テキストはレンダラーのスーパークラスで作成するマーカーと一緒に返されるか、またはマーカーのみが返されます。
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;
    }
  }