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.
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.
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
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
Viewthat provides a coordinate transformation from model coordinates to eye coordinates, following the OpenGL convention of a left-handed coordinate system
- A
Globerepresenting 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
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.
Learn
-
World Wind Central: Official knowledge base and support site for NASA World Wind SDK.
-
WWJ bundles these low-, medium-, and high-resolution datasets:
-
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's SRTM Project.
- USGS Topographic, B&W Ortho, and Color Urban Area USGS and Microsoft Research, available from TerraServer.
- U.S. placenames from the USGS Geographic Names Information System.
- World placenames from the National Geospatial-Intelligence Agency.
-
Blue Marble
(1-km/pixel resolution).
-
SWT/AWT bridge: Javadoc for the
SWT_AWTclass. -
"Swing/SWT Integration" (Gordon Hirsch, eclipse.org, 2007): This article focuses on using the SWT/AWT bridge to embed existing Swing components into an SWT-based RCP application.
-
"Find your way
around open source GIS" (Frank Pohlmann, developerWorks, May 2005): Read about some
GIS tools for UNIX® and Linux® users.
-
Eclipse project resources: Resources galore for Eclipse developers.
-
Browse the
technology bookstore for books on these and other technical topics.
-
developerWorks Java technology zone: Find hundreds of articles about every aspect of Java programming.
Get products and technologies
-
NASA World Wind SDK: Download the World Wind Java SDK.
-
Europa Simultaneous Release project: Download free Eclipse Europa bundles.
Discuss
-
Check out developerWorks blogs and get involved in the developerWorks community.

Vladimir 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.



