In this article we will look at how polylines can be added to World Wind Java SDK. Polylines are used to represent routes or tracks on your map. A polyline is made up of a list of point coordinates and a line is drawn between each point to create the full polyline. There are actually two different types of Polylines in WWJ. We will take a look at both of them. Note: this tutorial is just to get you pointed in the right direction. There are probably much more efficient ways of handling this. This is just a starting place.

The most simple to use is the SurfacePolyline. This is because it does not require an elevation for each point. It simply draws the line flat against the layer. The surface polyline takes a list of LatLon classes. The LatLon class, as the name implies, is a 2 dimensional point constructed of latitude and longitude. To make a polyline we must first store the points that make up the line.

// Equator line
List<LatLon> latLonList = new ArrayList<LatLon>();
latLonList.add(LatLon.fromRadians(0.0, -180.0));
latLonList.add(LatLon.fromRadians(0.0, 90.0));
latLonList.add(LatLon.fromRadians(0.0, 180.0));
latLonList.add(LatLon.fromRadians(0.0, -90.0));
latLonList.add(LatLon.fromRadians(0.0, -180.0));

After we have a list of LaLon classes we can instantiate the SurfacePolyline class. The constructor accepts the color and stroke color.

// Creating a SurfacePolyline out of our points
SurfacePolyline surfacePolyline1 = new SurfacePolyline(latLonList, Color.CYAN, Color.WHITE);
surfacePolyline1.setAntiAlias(true);

The other type of polyline is the Polyline class. This class is slightly more useful because it accepts a list of Position classes. Position classes are very similar to the LatLon class however it accepts a third parameter for elevation.

//Example of Positions for use with the Polyline class.
List<Position> positionList = new ArrayList<Position>();
positions.add(new Position(Angle.fromRadians(36.0403), Angle.fromRadians(-93.34067), 309.0));
positions.add(new Position(Angle.fromRadians(36.0403), Angle.fromRadians(-93.34067), 309.0));
positions.add(new Position(Angle.fromRadians(36.04019), Angle.fromRadians(-93.34067), 310.0));
positions.add(new Position(Angle.fromRadians(36.04012), Angle.fromRadians(-93.34098), 312.0));
positions.add(new Position(Angle.fromRadians(36.04004), Angle.fromRadians(-93.34106), 316.0));

After we form our polyline we can create a new layer and add it to the layer list.

// Creating a new layer
RenderableLayer polylineLayer = new RenderableLayer();
polylineLayer.addRenderable(surfacePolyline1);

// Add layer to the layer list
LayerList layers = m.getLayers(); //this.worldWindowGLCanvas1.getModel().getLayers();
layers.add(polylineLayer);

Alright, so that is a very basic intriduction to the Polylines in World Wind. If you where following along in the Hello World Wind Article, you can just copy and paste the code below into HelloWorldWindMain() below initComponents();.

Model m = (Model) WorldWind.createConfigurationComponent(AVKey.MODEL_CLASS_NAME);
this.worldWindowGLCanvas1.setModel(m);

// Equator line
List<LatLon> latLonList = new ArrayList<LatLon>();
latLonList.add(LatLon.fromRadians(0.0, -180.0));
latLonList.add(LatLon.fromRadians(0.0, 90.0));
latLonList.add(LatLon.fromRadians(0.0, 180.0));
latLonList.add(LatLon.fromRadians(0.0, -180.0));

// Creating a SurfacePolyline out of our points
SurfacePolyline surfacePolyline = new SurfacePolyline(latLonList1, Color.CYAN, Color.WHITE);
surfacePolyline.setAntiAlias(true);

// Creating a new layer
RenderableLayer polylineLayer = new RenderableLayer();
polylineLayer.addRenderable(surfacePolyline);

// Add layer to the layer list
LayerList layers = m.getLayers();
layers.add(polylineLayer);

Run the project (F6) and see the SurfacePolyline follow the equator.

polyline in world wind