skip to main content
Defense > Programmer's documentation > Programming with JViews Maps for Defense > Using the GUI beans > The Fly Through action
 
The Fly Through action
Describes the Fly Through action and how to use it.
*Overview
*Describes the Fly Through action.
*Integrating the Fly Through action into an application
*Explains how to integrate a Fly Through action into your application.
Overview
The Fly Through action is represented by the IlvFlyThroughAction class. This action is usually created and updated by the Fly Through interactor. The Fly Through interactor also creates a graphic object displayed in one of the layers of a view and is represented by the IlvMake3DFlyThroughInteractor class, see Fly Through interactor.
To create the Fly Through Action, you can either use the Fly Through interactor, see Creating and installing the Fly Through interactor, or, for more precise control, write the lines of code given in this section.
The following figure shows an example of a Fly Through Action.
The Fly Through action
The source code for the Map Builder demonstration, which contains all of the code described in this section, can be found at <installdir> /jviews-maps-defense/samples/3dview/index.html.
Integrating the Fly Through action into an application
When integrating a Fly Through into your application, if you need to show a graphical 2D representation (Fly Through graphics), you first need to create a data source and a map layer, and then link them with the manager properties.
Creating a data source and map layer
1. Retrieve the following global properties of the manager:
 
IlvMapDataSourceModel dsm =
   IlvMapDataSourceProperty.GetMapDataSourceModel(view.getManager());
 
IlvMapLayerTreeModel ltm =
   IlvMapLayerTreeProperty.GetMapLayerTreeModel(view.getManager());
2. Create a data source to store the Fly Through polygon:
 
IlvGraphicLayerDataSource ds = new IlvGraphicLayerDataSource();
ds.setManager(view.getManager());
3. Insert the data source into the data source tree of the manager:
 
dsm.insert(ds);
4. Set up the layer:
 
final IlvMapLayer layer = ds.getInsertionLayer();
layer.setAllowingMoveObjects(true);
layer.setName("Fly Through");
layer.setStyle(new IlvFlyThroughStyle());
5. Insert the layer into the layer tree of the manager:
 
ltm.addChild(null, layer);
Creating a Fly Through in graphical 2D representation
1. You can now create the Fly Through object in your program and add it to the data source so that it can be managed by the data source (for example, to change the representation when the coordinate system changes):
 
IlvPoint points[]= {
   new IlvPoint((float)Math.toRadians(10.2), -(float)Math.toRadians(45.8)),
   new IlvPoint((float)Math.toRadians(10.8), -(float)Math.toRadians(45.2)),
};
IlvMapTerrainFlyThrough flyThroughGraphics = new
   IlvMapTerrainFlyThrough(points);
flyThroughGraphics.setStyle(layer.getStyle());
2. Since the Fly Through is created using KERNEL coordinates in the example above (hence the negative values for the latitude coordinates, because the JViews Y axis is opposed to the latitude direction), you only need to call:
 
ds.add(flyThroughGraphics,IlvGeographicCoordinateSystem.KERNEL);
3. Now start the data source to (potentially) transform the polygon and display it in the 3D View.
 
ds.start();
Registering a Fly Through action
What is created above is a polygonal representation of the Fly Through in the 2D View. You now need to create an action that will Start/Stop the Fly Through in the 3D View.
1. Using the example above, retrieve the Fly Through coordinates and style parameters:
 
IlvCoordinate []coords=flyThroughGraphics.getLatLongs();
IlvFlyThroughStyle
ftstyle=(IlvFlyThroughStyle)flyThroughGraphics.getStyle();
2. With these coordinates and parameters create a Fly Through trajectory:
 
Ilv3DTrajectory.Point [] trajPoints=new
Ilv3DTrajectory.Point[coords.length];
for (int i = 0; i < coords.length; i++) {
   trajPoints[i]=new Ilv3DTrajectory.Point(ftstyle.getSpeed(),coords[i].x,
      coords[i].y,ftstyle.getAltitude());
   }
Ilv3DTrajectory traj= new Ilv3DTrajectory(trajPoints);
3. Create the Fly Through action and register it:
 
IlvFlyThroughAction action = new IlvFlyThroughAction(layer.getName(),
   traj,view3D);
4. Register the action in the 3D View:
 
view3D.registerFlyThrough(layer,action);
Recomputing the Fly Through action
When the Fly Through graphic polygon is moved or resized, you will probably want the action on the 3D view to be updated too. To update the action on the 3D view.
*Add a listener to the Fly Through graphic:
 
flyThroughGraphics.addChangeListener(new
   IlvMapControllingPolyline.ComputeListener() {
      public void computationDone(IlvMapControllingPolyline tc) {
// Retrieve the fly through coordinates.
   IlvCoordinate []coords=flyThroughGraphics.getLatLongs();
// Retrieve other parameters in the object style.
   IlvFlyThroughStyle
      ftstyle=(IlvFlyThroughStyle)flyThroughGraphics.getStyle();
 
// Create a fly through trajectory.
   Ilv3DTrajectory.Point [] trajPoints=new
      Ilv3DTrajectory.Point[coords.length];
   for (int i = 0; i < coords.length; i++) {
      Ilv3DTrajectory.Point lookat = new Ilv3DTrajectory.Point(...);
      }
   Ilv3DTrajectory traj= new Ilv3DTrajectory(trajPoints);
 
// Create the fly through action and register it.
   IlvFlyThroughAction action = new IlvFlyThroughAction(layer.getName(),
      traj,view3D);
   view3D.registerFlyThrough(layer,action);
 
   }
});

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