色付き線のレンダラーの作成

このレンダラーのサンプル・ソース・コード一式は、以下のファイルにあります。
異なる標高の等高線を色別表示すると仮定します。単純な方法は、java.awt.image.ColorModel で標高値を使用して色をインデックス付けする方法です。より一般的には、地図機能に関連付けられたいずれかの属性を使用して、線、多角形またはテキストなどのグラフィック・オブジェクトに色を適用するレンダラー・クラスがあると役に立ちます。
ColorLineRenderer クラスの makeGraphic メソッドは、 IlvMapMultiPointInterface. このインターフェースは、ポイント・セットで構成されるすべてのジオメトリーに共通です。
public IlvGraphic makeGraphic(IlvMapFeature feature,
                              IlvCoordinateTransformation tr)
    throws IlvMapRenderException, IlvCoordinateTransformationException 
  {
    // Check that this geometry can be processed.
    IlvMapMultiPointInterface multiPoint;
    try {
      multiPoint = (IlvMapMultiPointInterface)feature.getGeometry();
    } catch (Exception e) {
      throw new IlvMapRenderException("not a multipoint geometry");
    }

    // Check that something has to be done.
    int pointCount = multiPoint.getPointCount();
    if (pointCount == 0)
      return null;

    // Allocate polyline point array.
    IlvPoint p[] = new IlvPoint[pointCount];
    
    // Convert points.
    for (int i = 0; i < pointCount ; i++) {
      p[i] = new IlvPoint();
      IlvProjectionUtil.ToViews(tr,
                                multiPoint.getPoint(i),
                                p[i]);
    }
    // Create the graphic object, without duplicating the p[] array.
    IlvPolyline poly = new IlvPolyline(p, false);
   [...]
地図機能の座標は、マネージャーの座標系に変換する必要があります。この変換により、マネージャーでは下向きになるのに対し、地図作成データ座標系には下向きの y 軸の正の部分があるため、y 軸の方向が変更されます。また、データのソース座標系をターゲット座標系に変更することで、座標変換も行われます。この例では、 ToViews メソッドは、両方の座標を変換し、必要に応じて y 軸の方向を変更します。特にソース・データが地理参照されていない場合 (つまり、投影図法が不明な場合)、または変換を必要としない場合、ソース座標系 (feature.getCoordinateSystem()) およびターゲット座標系を null に設定することで、IlvCoordinateTransformationidentity になります。座標系の詳細は、「空間参照システムの処理」を参照してください。
グラフィック・オブジェクトを作成すると、下記のように、色モデルを使用して線を着色するための属性値を取得します。
int colorIndex = 0;
   // Get attribute list.
   IlvFeatureAttributeProperty attributeList = feature.getAttributes();
   if (attributeList != null) {
     try {
       IlvFeatureAttribute attribute = null;
       attribute = attributeList.getAttribute(myAttributeName);
       if (attribute instanceof IlvIntegerAttribute)
         colorIndex = ((IlvIntegerAttribute)attribute).getValue();
       else if (attribute instanceof IlvDoubleAttribute)
         colorIndex = (int)((IlvDoubleAttribute)attribute).getValue();
     } catch (IllegalArgumentException e) {
       // No attribute found.
       colorIndex = 0;
     }
   }
   Color color = new Color(myColorModel.getRed(colorIndex),
                           myColorModel.getGreen(colorIndex),
                           myColorModel.getBlue(colorIndex));
   // Sets the color of graphic.
   poly.setForeground(color);