Contents


Embed the NASA World Wind Java SDK in Eclipse

Develop GIS applications with this open source SDK

Comments

The WWJ SDK is a 3D graphics globe built on top of the Java OpenGL (JOGL) extensions. At the core of the WWJ class hierarchy is the WorldWindowGLCanvas, which is a subclass of GLCanvas. GLCanvas is in turn an Abstract Window Toolkit (AWT) component.

WWJ's dependence on AWT is an obstacle for GIS developers who want to use WWJ in their Eclipse applications. As you probably know, Eclipse uses the Standard Widget Toolkit (SWT), which is incompatible with AWT. Furthermore, AWT and JOGL are tightly integrated, making a port of the AWT interfaces to SWT difficult. This article presents a solution that enables you to use the WWJ SDK with your Eclipse applications.

Enter the SWT/AWT bridge

The SWT is rapidly becoming a top-tier windowing toolkit for quickly building scalable and powerful client applications. Both SWT and AWT/Swing are battling for supremacy of Java user interface development. Given the fact that both have advantages and disadvantages, the Eclipse Foundation recognized the need to build a SWT/AWT bridge that allows you to embed AWT/Swing components into SWT. The bridge has been part of SWT since Eclipse version 3.0. This simple API is located in the org.eclipse.swt.awt package (see Related topics).

The SWT/AWT bridge is the key component you need to embed the AWT-based World Wind 3D Globe into an Eclipse application via SWT.

Eclipse view for WWJ 3D Earth

With the SWT/AWT bridge already in SWT, embedding a WWJ 3D Earth within your view is a snap. Listing 1 demonstrates a basic Eclipse view that performs this task:

Listing 1. Basic Eclipse view for the WWJ 3D Earth
package org.eclipse.plugin.worldwind.views;
_

/**
 * World Wind Eclipse RCP Earth View
 * @author Vladimir Silva
 *
 */
public class EarthView extends ViewPart
{
   private static final Logger logger = Logger.getLogger(EarthView.class);
   
   public static final String ID = EarthView.class.getName(); 
   final WorldWindowGLCanvas world = new WorldWindowGLCanvas();
   

   /**
    * Initialize the default WW layers
    */
   static {
      initWorldWindLayerModel();
   }

   public EarthView() {
      
   }
   
   /**
    * This is a callback that will allow us to create the viewer and initialize
    * it.
    */
   public void createPartControl(Composite parent) 
   {
      // GUI: an SWT composite on top
      Composite top = new Composite(parent, SWT.EMBEDDED);
      top.setLayoutData(new GridData(GridData.FILL_BOTH));
        
      // Swing Frame and Panel
      java.awt.Frame worldFrame = SWT_AWT.new_Frame(top);
      java.awt.Panel panel = new java.awt.Panel(new java.awt.BorderLayout());
      
      worldFrame.add(panel);

      // Add the WWJ 3D OpenGL Canvas to the Swing Panel
      panel.add(world, BorderLayout.CENTER);

      parent.setLayoutData(new GridData(GridData.FILL_BOTH));
        
   }

   /*
    * Initialize WW model with default layers
    */
   static void initWorldWindLayerModel () 
   {
      Model m = (Model) WorldWind.createConfigurationComponent(
            AVKey.MODEL_CLASS_NAME);

      world.setModel(m);
   }

   /**
    * Passing the focus request to the viewer's control.
    */
   public void setFocus() {
   }
   
   public static void repaint() {
      world.repaint();
   }

   @Override
   public void dispose() {
      super.dispose();
   }
   
}

Listing 1 starts by creating a top SWT component that uses the bridge to embed the WWJ swing OpenGL canvas:

Composite top = new Composite(parent, SWT.EMBEDDED);
top.setLayoutData(new GridData(GridData.FILL_BOTH));

Next, a child AWT frame is created within the top SWT component, using the bridge, to host the Swing panel required by the WWJ OpenGL canvas:

java.awt.Frame worldFrame = SWT_AWT.new_Frame(top);
java.awt.Panel panel = new java.awt.Panel(new java.awt.BorderLayout());

Finally, the WWJ GL canvas is added to the Swing panel:

WorldWindowGLCanvas world = new WorldWindowGLCanvas();
panel.add(world, BorderLayout.CENTER);

Figure 1 shows Earth embedded within an Eclipse view as part of a Rich Client Platform (RCP) application:

Figure 1. WWJ Earth as an Eclipse view
Figure 1. WWJ Earth as an Eclipse View
Figure 1. WWJ Earth as an Eclipse View

Flying to a location within a globe

If you want your application to fly to a specific latitude/longitude in a Google Earth style, three objects are required:

  • A View that provides a coordinate transformation from model coordinates to eye coordinates, following the OpenGL convention of a left-handed coordinate system
  • A Globe representing the 3D ellipsoidal sphere of the world you are looking at
  • The latitude/longitude coordinates of the point you wish to fly to

Optional information includes angles for heading and pitch and altitude in meters.

Listing 2 demonstrates how to fly to a location:

Listing 2. Flying to given latitude/longitude coordinates
public void flyTo (LatLon latlon) 
{
   View view       = world.getView();
   Globe globe = world.getModel().getGlobe();
   
   view.applyStateIterator(FlyToOrbitViewStateIterator.createPanToIterator(
           (OrbitView)view
           , globe
           , latlon      // bbox
           , Angle.ZERO   // Heading
           , Angle.ZERO   // Pitch
           , 3e3 )       // Altitude/Zoom (m)
           );
}

The applyStateIterator() method of the View class pans or zooms the globe, producing a smooth fly-to or an instantaneous zoom effect on the globe's target coordinates.

WWJ bundles other globes besides Earth; 3D worlds available as of WWJ version 0.4.1 are:

  • Earth (see Related topics for the included datasets).
  • Moon: 40xx/30xx color/grayscale layers, created using a combination of several spectral bands from the Clementine mission.
  • Mars: Including high-resolution imagery from missions such as Mars Orbital Camera (MOC), Elevation Maps created using data from the NASA Jet Propulsion Laboratory, and data from NASA Mars Odyssey/THEMIS.

Figure 2 shows the Earth, moon, and Mars as three distinct Eclipse views:

Figure 2. Earth, moon, and Mars views within a RCP application
Figure 2. Earth, moon, and Mars views within a Rich Client Application
Figure 2. Earth, moon, and Mars views within a Rich Client Application

Conclusion

The World Wind Java SDK is a 3D interactive world viewer written in Java and OpenGL that allows any user to zoom from outer space into any place on Earth. This article gives you the foundation for embedding the WWJ SDK as an Eclipse view to gain a new set of powerful tools for GIS development within Eclipse.


Downloadable resources


Related topics


Comments

Sign in or register to add and subscribe to comments.

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=Java development, Open source
ArticleID=311635
ArticleTitle=Embed the NASA World Wind Java SDK in Eclipse
publish-date=06032008