Generic code sample for creating a map
The complete source code for this example can be found in the following file:
<installdir> /jviews-maps/codefragments/readers/src/GenericReader.java
-
Instantiate the reader. In this example, you are using the IlvShapeReader.
try
{
featureIterator = new IlvShapeFileReader(shapeFileName, dbfFileName);
}
catch (IOException e)
{
System.err.println("IOError while instantiating reader");
}
-
Retrieve the feature renderer from the reader.dted.
IlvFeatureRenderer renderer =
featureIterator.getDefaultFeatureRenderer();
-
Create coordinate transformation.
IlvCoordinateTransformation identity = IlvCoordinateTransformation.CreateTransformation(null, null);
-
Retrieve the first map feature.
IlvMapFeature feature = null;
try
{
feature = featureIterator.getNextFeature();
}
catch (IOException io)
{
System.err.println("IOExeption while getting next feature"
+io.getMessage());
}
// Loop on all the available map features.
while (feature != null)
{
try {
-
Create the graphic object representing the map feature.
IlvGraphic graphic = renderer.makeGraphic(feature, identity);
-
Add the graphic object to the manager.
manager.addObject(graphic, layerIndex, false);
-
Handle exceptions.
} catch (IlvMapRenderException e)
{
// Should not occur: renderer provided by the feature iterator.
System.out.println("Rendering Exception " + e.getMessage());
} catch (IlvCoordinateTransformationException cte) {
System.err.println("Coordinate transformation exception " + cte.getMessage());
}
}