Programming with JViews Maps > Introducing the Main Classes > Readers and Writers > The SVG Reader

There are two ways of reading SVG files:

This section contains the following topics:

The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir>/jviews-maps81/samples/mapbuilder/index.html

The IlvMapSVGReader Class

This class reads SVG features from a specified SVG file or catalog. It implements the IlvMapFeatureIterator interface to iterate over the features to be read.

Using the IlvMapSVGReader Class to Create Vector Data

To read SVG features by means of the IlvMapSVGReader object, do the following:

  1. Create a new IlvMapSVGReader instance using the path to the SVG catalog.
String SVGpath = " C:/maps/SVG/map.svg";
IlvMapSVGReader reader = new IlvMapSVGReader(SVGpath);
  1. Set the transformation to use to render the SVG data. The following code example shows an specimen transformation:
reader.setDestinationBounds(lonMinRad,latMinRad,lonMaxRad,latMaxRad);
  1. retrieve the default SVG renderer.
IlvFeatureRenderer renderer = reader.getDefaultFeatureRenderer();
  1. Iterate over the features, render them, and assign them to a manager:
IlvMapFeature feature = reader.getNextFeature();
while(feature != null) {
  // Render map feature into a graphic object
  IlvGraphic graphic = renderer.makeGraphic(feature,null);
  // Add this object to the first layer of the manager
  manager.addObject(graphic, 0, false);
  feature = reader.getNextFeature();
}

The IlvSVGDataSource Class

The IlvSVGDataSource class provides a convenient way to create a set of layers containing SVG data in a manager.

Using the IlvSVGDataSource Class to Create Vector Data

Here are the steps required to read SVG features by means of the IlvSVGDataSource:

  1. Create a new IlvSVGDataSource instance.
String SVGpath = "C:/maps/map.svg";
IlvSVGDataSource source = new IlvSVGDataSource(SVGpath); 
  1. Connect this data source with the manager of the view.
source.setManager(getView().getManager());
  1. Set the transformation to render the SVG data into geo-referenced objects.
source.setDestinationBounds(lonMinRad,latMinRad,lonMaxRad,latMaxRad);
Note
Alternatively you can use a tailored transformation by calling IlvSVGDataSource.setInternalTransformation.
  1. Start the SVG data source.
source.start();