| Programming with JViews Maps > Creating a Map Application Using the API > Manipulating Renderers > Creating a Colored Line Renderer |
Creating a Colored Line Renderer |
INDEX
PREVIOUS
NEXT
|
This section shows how to write a new renderer that displays colored polylines from the numeric value of an attribute whose name is known.
The complete source code example for this renderer can be found in the following file:
<installdir>/jviews-maps81/codefragments/renderer/srchtml/ColorLineRenderer.java
Suppose that you want to display contour lines of different elevations with different colors. A simple solution would consist of indexing a color using the elevation value by means of a java.awt.image.ColorModel. More generally, it would be useful to have a renderer class that applies a color to graphic objects, such as lines, polygons, or text, by using any of the attributes associated with a map feature.
The makeGraphic method in the ColorLineRenderer class builds an IlvPolyline graphic object from the interface IlvMapMultiPointInterface. This interface is common to all geometries composed of a set of points.
The map feature coordinates must be converted to the manager coordinate system. This conversion implies a change of orientation of the y-axis since cartographic data coordinate systems have the positive portion of their y-axis oriented upward, whereas the manager has it oriented downward. It might also imply a coordinate transformation by changing the source coordinate system of the data into a target coordinate system. In our example, the IlvProjectionUtil.ToViews method both transforms the coordinates, if necessary, and corrects the orientation of the y-axis. Note that the IlvCoordinateTransformation can be identity by setting the source (feature.getCoordinateSystem()) and target coordinate systems to null, especially if the source data is not georeferenced (that is, its projection is not known), or does not need to be transformed. For further information about coordinate systems, see Handling Spatial Reference Systems.
Once the graphic object is created, the attribute value for coloring the lines using a color model is retrieved, as shown below:
| Copyright © 1987-2007 ILOG S.A. All rights reserved. Documentation homepage. Legal terms. | PREVIOUS NEXT |