skip to main content
Defense > Programmer's documentation > Programming with JViews Maps > Creating a map application using the API > Generic code sample for creating a map
 
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
1. 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");
}
2. Retrieve the feature renderer from the reader.dted.
 
IlvFeatureRenderer renderer =
featureIterator.getDefaultFeatureRenderer();
3. Create coordinate transformation.
 
IlvCoordinateTransformation identity = IlvCoordinateTransformation.CreateTransformation(null, null);
4. 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 {
5. Create the graphic object representing the map feature.
 
IlvGraphic graphic = renderer.makeGraphic(feature, identity);
6. Add the graphic object to the manager.
 
manager.addObject(graphic, layerIndex, false);
7. 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());
}
}

Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.