skip to main content
Defense > Developing with design tools > Using the Map Builder > Writing an application > Creating a read-only map application
 
Creating a read-only map application
The following application is provided in the directory <installdir> /jviews-maps/samples/loadmap/index.html as part of the JViews Maps for Defense demonstration software. This is a simple case where the application loads a previously saved, read-only map in .ivl format, and displays it in the Map Builder main window. A map of this type can be built using the Map Builder or the JViews Maps for Defense API:
1. Import the required packages and classes:
 
import ilog.views.IlvManagerView;
import ilog.views.maps.IlvCoordinateSystemProperty;
import ilog.views.maps.beans.IlvJMouseCoordinateViewer;
import ilog.views.maps.beans.IlvMapLegend;
import ilog.views.maps.srs.coordsys.IlvGeographicCoordinateSystem;
import ilog.views.swing.IlvJManagerViewControlBar;
import ilog.views.swing.IlvJScrollManagerView;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.io.File;
import javax.swing.JFrame;
2. Create the basic building blocks of the Map Builder: create a frame containing the map beans, set it to exit when the Close button is pressed, set up the beans, and arrange the main window layout:
 
public class LoadMapDemo extends JFrame {
   IlvManagerView view=new IlvManagerView();
   IlvJScrollManagerView viewScroll=new IlvJScrollManagerView(view);
   IlvJManagerViewControlBar viewToolbar = new IlvJManagerViewControlBar();
   IlvJMouseCoordinateViewer locator=new IlvJMouseCoordinateViewer();
   IlvMapLegend legend=new IlvMapLegend();
public LoadMapDemo() {
   super();
   setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   viewToolbar.setView(view);
   locator.setView(view);
   legend.setView(view);
   view.setSize(new Dimension(900, 450));
   view.setKeepingAspectRatio(true);
   viewScroll.setPreferredSize(view.getSize());
   view.getManager().setNamedProperty(new
      IlvCoordinateSystemProperty(IlvGeographicCoordinateSystem.WGS84));
   getContentPane().add(viewToolbar,BorderLayout.NORTH);
   getContentPane().add(viewScroll,BorderLayout.CENTER);
   getContentPane().add(locator,BorderLayout.SOUTH);
   getContentPane().add(legend,BorderLayout.LINE_START);
   loadFile("data/county.ivl"); //$NON-NLS-1$
}
3. Load the file into the manager of the view:
 
public void loadFile(String filename){
   try {
      IlvMapInputStream mapInput = new IlvMapInputStream(filename);
      mapInput.read(view.getManager());
      view.fitTransformerToContent();
      pack();
   } catch(Exception ex){
      ex.printStackTrace();
   }
}
4. Write the main method:
 
static public void main(String args[]) {
  javax.swing.SwingUtilities.invokeLater(
    new Runnable() {
      public void run() {
        final JFrame frame = new LoadMapDemo();
        frame.pack();
        frame.setVisible(true);
    }
  );
}

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