The SVG reader

There are two ways of reading SVG files:
  • Use an IlvMapSVGReader instance directly. When you use IlvMapSVGReader, you must write all of the code required to render the SVG features into graphic objects, and to add them to the manager.
    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.
  • Use an IlvSVGDataSource. This is a convenient way of performing all of the above operations at once. Using IlvSVGDataSource is better integrated with the data model of the map.
    The IlvSVGDataSource class provides a convenient way to create a set of layers containing SVG data in a manager.
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps89/samples/mapbuilder/index.html.
To read SVG features and create vector data:
  1. Create a new IlvMapSVGReader instance using the path to the SVG catalog.
  2. Set the transformation to use to render the SVG data. The following code example shows an specimen transformation:
  3. retrieve the default SVG renderer.
  4. Iterate over the features, render them, and assign them to a manager:
    String SVGpath = " C:/maps/SVG/map.svg";
    IlvMapSVGReader reader = new IlvMapSVGReader(SVGpath);
    reader.setDestinationBounds(lonMinRad,latMinRad,lonMaxRad,latMaxRad);
    IlvFeatureRenderer renderer = reader.getDefaultFeatureRenderer();
    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();
    }
    
To read SVG features and create vector data:
  1. Create a new IlvSVGDataSource instance.
  2. Connect this data source with the manager of the view.
  3. Set the transformation to render the SVG data into geo-referenced objects.
  4. Start the SVG data source.