Embed the NASA World Wind Java SDK in Eclipse

Develop GIS applications with this open source SDK

The open source World Wind Java (WWJ) SDK by NASA creates new possibilities for the open Geographic Information Systems (GIS) community. World Wind, a 3D interactive world viewer written in the Java™ language and OpenGL, lets users zoom from outer space into any place on Earth. This article explains how GIS developers who want to enhance their Eclipse-based applications can embed the WWJ SDK as an Eclipse plug-in.

Vladimir Silva (vladimir_silva@hotmail.com), Consultant

  Vladimir SilvaVladimir Silva is a former IBM software engineer who worked for the IBM WebAhead technology think tank on projects such as the IBM Grid Toolbox. Some of his work on server-side security has been incorporated into Globus Toolkit. He is the author of Grid Computing for Developers (Charles River Media, 2005). His other interests include neural nets and artificial intelligence. Vladimir holds numerous IT certifications.



03 June 2008

Also available in Chinese Japanese Vietnamese

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.

Datasets bundled with WWJ

WWJ bundles the following low-, medium-, and high-resolution datasets (see Resources for links to them):

  • Blue Marble (1-km/pixel resolution)
  • i-cubed Landsat 7 (15-meter/pixel resolution) from the Global Land Cover Facility of the University of Maryland Institute for Advanced Computer Studies
  • Elevation data (SRTM30Plus/SRTMv2/USGS NED derived dataset) from the NASA Jet Propulsion Laboratory
  • USGS Topographic, B&W Ortho, and Color Urban Area USGS and Microsoft® Research
  • U.S. placenames from the USGS Geographic Names Information System
  • World placenames from the National Geospatial-Intelligence Agency

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 Resources).

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

WWJ vs. Google Earth and Virtual Earth

Google Earth and Virtual Earth are popular 3D globes that are also available. They too are 3D Earths that let users zoom in and view locations. But despite their similarities to WWJ, these tools have fundamentally different philosophies. Google Earth and Virtual Earth are commercial products, not SDKs, so developers cannot enhance the client to fit their needs. For example, scientists can't add support for scientific data formats or interfaces to mapping services such as OpenGIS Web Map Services (WMS) or Web Feature Services (WFS). WWJ's open source nature allows you to embed the globe in virtually any type of client, as you've seen in this article. WWJ can also be modified to access any type of data service. This is a huge advantage over its commercial counterparts.

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 Resources 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

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.

Resources

Learn

Get products and technologies

Discuss

Comments

developerWorks: Sign in

Required fields are indicated with an asterisk (*).


Need an IBM ID?
Forgot your IBM ID?


Forgot your password?
Change your password

By clicking Submit, you agree to the developerWorks terms of use.

 


The first time you sign into developerWorks, a profile is created for you. Information in your profile (your name, country/region, and company name) is displayed to the public and will accompany any content you post, unless you opt to hide your company name. You may update your IBM account at any time.

All information submitted is secure.

Choose your display name



The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerWorks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

Required fields are indicated with an asterisk (*).

(Must be between 3 – 31 characters.)

By clicking Submit, you agree to the developerWorks terms of use.

 


All information submitted is secure.

Dig deeper into Java technology on developerWorks


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