World Wind Java SDK - Hello World

Home


World Wind Java SDK with Eclipse

1. Download World Wind Java SDK at http://worldwind.arc.nasa.gov/java/
   Click "Download World Wind Java SDK" and follow instructions

2. Decompress archive in a specific directiory

3. Create new project in Eclipse

4. Go to properties of your project and add "worldwind.jar" and "jogl.jar" to "Java build path/libraries"/
   You should find worldwind.jar and jogl.jar files in the "specific" directory you use to decompress WWJ
   SDK archive.

5. If you are under Windows, put files "jogl.dll" and "jogl_awt.dll" in the root driectory of your Eclipse
   project.

6. Try running this java code:

import java.awt.Color;
import java.util.LinkedList;
import gov.nasa.worldwind.BasicModel;
import gov.nasa.worldwind.awt.WorldWindowGLCanvas;
import gov.nasa.worldwind.geom.Position;
import gov.nasa.worldwind.layers.RenderableLayer;
import gov.nasa.worldwind.render.Polyline;
import javax.swing.JFrame;

public class Test {

	public static void main(String[] args) {

		//create a WorldWind main object
		WorldWindowGLCanvas worldWindCanvas = new WorldWindowGLCanvas();
		worldWindCanvas.setModel(new BasicModel());

		//build Java swing interface
		JFrame frame = new JFrame("World Wind");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.add(worldWindCanvas);
		frame.setSize(800,600);
		frame.setVisible(true);

		//create some "Position" to build a polyline
		LinkedList list = new LinkedList();
		for(int i = 0 ; i < 90 ; i++) {
			//in this case, points are in geographic coordinates.
			//If you are using cartesian coordinates, you have to convert them to geographic coordinates.
			//Maybe, there are some functions doing that in WWJ API...
			list.add(Position.fromDegrees(i,0.0,i*20000));
		}

		//create "Polyline" with list of "Position" and set color / thickness
		Polyline polyline = new Polyline(list);
		polyline.setColor(Color.RED);
		polyline.setLineWidth(3.0);

		//create a layer and add Polyline
		RenderableLayer layer = new RenderableLayer();
		layer.addRenderable(polyline);

		//add layer to WorldWind
		worldWindCanvas.getModel().getLayers().add(layer);
	}

}