Saving and reloading a map

In JViews Maps 8.1, maps can be saved in the proprietary .ivl file format. This is basically the regular Rogue Wave® JViews format slightly modified to improve the loading performance of maps containing large amounts of raster data.
To save a map:
  1. Create an IlvMapOutputStream object from a filename. This class extends the IlvOutputStream (see Input/output operations in The Essential JViews Framework) and provides the option of not saving the layers (and hence the graphic objects) contained in an IlvManager. You can choose to write the file in binary format, which is more compact, or in ASCII format, which is more readable.
    String mapFilename = "myMap.ivl";
    boolean binary = false;
    IlvMapOutputStream mapOutput = new IlvMapOutputStream(mapFilename, binary);
    
    Note that when using the above IlvMapOutputStream constructor, the name of the image file (see The .img File) is inferred from the specified map filename, by adding the .img extension or by replacing the ivl extension by .img . You can also create the IlvMapOutputStream with a different constructor, specifying a java.io.OutputStream to save the map contents to, and a different filename for the .img file. In this case, you must use the appropriate matching constructor of IlvMapInputStream when loading the map, see the reloading a map procedure below for more information.
  2. Optionally:
    Save only the map theme. When reloading a theme file only, all IlvMapDataSource instances of the model are started again so that they can read data from their original files and reconstruct the map. This is useful if the original data sources (ESRI Shape, DTED® and so on) are available when reloading the .ivl file (when working on the same machine for example, or on the same network if data formats are stored on a networked resource). The file produced is small, typically only a few tens of KB:
    mapOutput.setWritingObjects(false);
    
    Conversely, if you plan on distributing the map without the original data sources, or if you want to achieve higher reload performance, you should consider saving all the data in the file:
    mapOutput.setWritingObjects(true);
    
  3. Write the manager to the IlvMapOutputStream and clean up the remaining resources:
    try {
      mapOutput.write(manager);
    } catch (IOException ex) {
      // handle I/O exception here...…
    }
    
To reload a map:
  1. First, it is best is to clear the current manager, see Clearing map data.
  2. Create an IlvMapInputStream and use it to read the map file. This takes care of reconnecting read data with the corresponding read map model (data sources, map layers and so on).
    String mapFilename = "myMap.ivl";
    IlvMapInputStream mapInputStream = new IlvMapInputStream (mapFilename);
    try {
       mapInputStream.read(manager);
    }  catch (Exception ex) {
       // handle reading exceptions here
    }
    
    Note that when using the above IlvMapInputStream constructor, the .img file that goes with the .ivl file (passed to IlvMapInputStream ) must be in the same directory as the .ivl file or the stream will not be able to find it, leading to missing images on the map.
    If you choose to specify a different name for the .img file when saving the map (see Saving and reloading a map), you must also specify the filename to the IlvMapInputStream using the appropriate constructor as follows:
    String ivlFilename = "myMap.ivl";
    String imgFilename = "myImgFilename.img";
    
    //Create the input stream for the .ivl file.
    FileInputStream fis = new FileInputStream(ivlFilename);
    
    //Create the IlvMapInputstream and specify the image file name.
    IlvMapInputStream mapInputStream = new IlvMapInputStream(fis, imgFilename);
    
    //Read the map as described previously.
       try {
         mapInputStream.read(manager);
         } catch (Exception ex) {
    // Handle reading exceptions here.
    }