Creating a map application with APP-6a symbols

The application example given in this section is the JViews Maps for Defense application provided in <installdir> /jviews-maps-defense89/samples/app6a/index.html as part of the Rogue Wave®  JViews Maps for Defense demonstration software.
The application:
  • Creates a map GUI
  • Loads a shape file
  • Creates an APP-6a symbol manager
To create the application:
  1. Import the following Java™ packages and classes:
    import ilog.views.IlvGrapher;
    import ilog.views.IlvManagerView;
    import ilog.views.IlvPoint;
    import ilog.views.maps.*;
    import ilog.views.maps.beans.*;
    import ilog.views.maps.projection.IlvCoordinatePanelFactory;
    import ilog.views.maps.datasource.*;
    import ilog.views.maps.symbology.swing.IlvSymbologyTreeView;
    import ilog.views.maps.graphic.style.IlvPolylineStyle;
    import ilog.views.maps.srs.coordsys.*;
    import ilog.views.sdm.IlvSDMEngine;
    import ilog.views.sdm.IlvSDMModel;
    import ilog.views.sdm.renderer.*;
    import ilog.views.swing.IlvJManagerViewControlBar;
    import ilog.views.swing.IlvJScrollManagerView;
    import java.awt.BorderLayout;
    import java.awt.Color;
    import java.awt.Dimension;
    import java.beans.PropertyChangeEvent;
    import java.beans.PropertyChangeListener;
    import java.net.URL;
    import javax.swing.BorderFactory;
    import javax.swing.JFrame;
    import javax.swing.JTabbedPane;
    import simulation.SimulationController;
    
  2. Declare the public class App6aDemo, which defines the basic building blocks of the Map Builder:
    public class App6aDemo extends JFrame {
       IlvManagerView view;// Map view.
       IlvJScrollManagerView viewScroll;// Scroll around the Map View.
       IlvSymbologyTreeView symbPanel;// Symbology control panel.
       IlvJManagerViewControlBar viewToolbar; // Zoom & selection toolbar.
       IlvJCoordinateSystemEditorPanel csPanel;// Coordinate system choice.
       IlvJMouseCoordinateViewer locator;// Coordinate information.
    
  3. Create a main frame and set it to exit when the Close button is pressed:
    public App6aDemo() {
       super();
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    
  4. Create the main components of the Map Builder and set them up:
    view=new IlvManagerView();
    view.setManager(new IlvGrapher());
    viewScroll=new IlvJScrollManagerView(view);
    viewToolbar = new IlvJManagerViewControlBar();
    csPanel=new IlvJCoordinateSystemEditorPanel();
    viewToolbar.setView(view);
    locator=new IlvJMouseCoordinateViewer();
    locator.setView(view);
    viewToolbar.add(locator);
    view.setKeepingAspectRatio(true);
    view.setBackground(new Color(80, 180, 240));
    view.setAntialiasing(false);
    view.setSize(new Dimension(900, 450));
    viewScroll.setPreferredSize(view.getSize());
    
  5. Create and set up the symbology:
    final IlvSDMEngine symbology = new IlvSDMEngine();
    URL symbolCss = App6aDemo.class.getResource("data/app6.css");
    symbology.setReferenceView(view);
    symbology.setGrapher((IlvGrapher) view.getManager());
       try {
          symbology.setStyleSheets(new String[] { symbolCss.toString()});
           }
       catch (IlvSDMException e) {e.printStackTrace();
           }
    /* show this symbology on the GUI */
    symbPanel = new IlvSymbologyTreeView(symbology);
    IlvApp6aSymbologyTreeViewActions app6Actions = new
       IlvApp6aSymbologyTreeViewActions();
    app6Actions.setLatLonPicker(new IlvCoordinatePanelFactory.
       CoordPointInputPanel(view,IlvDisplayPreferencesProperty.
       GetDisplayPreferences(view.getManager()).getCoordinateFormatter()));
    symbPanel.setSymbologyTreeViewActions(app6Actions);
    
  6. Georeference the view:
    view.getManager().setNamedProperty(new
       IlvCoordinateSystemProperty(IlvGeographicCoordinateSystem.WGS84));
    
  7. Set up the Coordinate System pane to reload symbols:
    csPanel.setCoordinateSystem(IlvCoordinateSystemProperty.
       GetCoordinateSystem(view.getManager()));
    csPanel.addCoordinateSystemChangeListener(new PropertyChangeListener(){
    public void propertyChange(PropertyChangeEvent evt) {
       IlvCoordinateSystem system = (IlvCoordinateSystem) evt.getNewValue();
       view.getManager().setNamedProperty(new
         IlvCoordinateSystemProperty(system));
         symbology.loadData();
       }
    });
    
  8. Show the symbology in the Map Builder:
    symbPanel.setSymbology(symbology);
    
  9. Load the “world” shape file:
    loadInitialData();
    
  10. Configure the Map Builder main window:
    getContentPane().add(viewToolbar,BorderLayout.NORTH);
    getContentPane().add(symbPanel,BorderLayout.LINE_END);
    getContentPane().add(viewScroll,BorderLayout.CENTER);
    JTabbedPane tabPane=new JTabbedPane();
    tabPane.addTab("Coordinate System",csPanel);
    getContentPane().add(tabPane,BorderLayout.LINE_START);
    getContentPane().add(locator,BorderLayout.SOUTH);
    }
    
  11. Load the sample raw data into the application:
    private void loadInitialData() {
       URL shpFile = App6aDemo.class.getResource("data/World_Countries.shp");
       try {
    // Create a data source for the shape file.
    IlvShapeDataSource reader = new IlvShapeDataSource(shpFile.getFile(), true);
    reader.setCoordinateSystem(IlvGeographicCoordinateSystem.WGS84);
    // Insert it in the data source tree of the manager. This optional step is
       necessary to retrieve the data when, for example, a coordinate system
       change occurs.
    IlvMapDataSourceModel dsm =
       IlvMapDataSourceProperty.GetMapDataSourceModel(view.getManager());
    dsm.insert(reader);
    // Get the Map Layer used to display the data source and insert it in the
       Map Layer tree of the manager.
    IlvMapLayer layer = reader.getInsertionLayer();
    layer.setName("World data");
    IlvMapLayerTreeModel ltm =
       IlvMapLayerTreeProperty.GetMapLayerTreeModel(view.getManager());
    ltm.addChild(null, layer);
    // Start reading.
    reader.start();
    // Set up the layer style.
    layer.getStyle().setAttribute(IlvPolylineStyle.FOREGROUND,Color.black);
    layer.getStyle().setAttribute(IlvPolylineStyle.BACKGROUND,new
       Color(1,1,0.8f));
       } catch (Exception e1)
       {e1.printStackTrace();
    }
    
  12. Fit the data source to the size of the Map Builder view:
    view.fitTransformerToContent();
    }
    
  13. Write the main method:
    static public void main(String args[]) {
      javax.swing.SwingUtilities.invokeLater(
        new Runnable() {
          public void run() {
            final JFrame frame = new App6aDemo();
            frame.pack();
            frame.setVisible(true);
        }
      );
    } 
    
Instead of loading raw data (the shape file in the above example), you can build your map and save it as an IVL file using the Map Builder. Refer to Creating a read-only map application for further details.
Refer to the samples provided with Rogue Wave® JViews Maps for Defense for examples of how to create applications that use maps.