NASA World Wind

gov.nasa.worldwindx.examples.util
Class LabeledPath

java.lang.Object
  extended by gov.nasa.worldwindx.examples.util.LabeledPath
All Implemented Interfaces:
Renderable

public class LabeledPath
extends Object
implements Renderable

LabeledPath draws a Annotation on a specified path. The path itself is not drawn. Instead, the annotation is drawn at the location that maximizes the annotation's visible area in the viewport. The annotation is not drawn if the location list is null, or if no location in the list is visible.

The caller must specify the screen annotation used to draw the path's label by calling setAnnotation(gov.nasa.worldwind.render.ScreenAnnotation). The path sets the specified annotation's screen point to control the label's location, but otherwise does not modify the annotation.


Field Summary
protected  int altitudeMode
          The altitude mode that defines how to interpret the altitude of locations that have an altitude component.
protected  ScreenAnnotation annotation
          The screen annotation to use as a label.
protected  long frameNumber
          The frame number used to place the label.
protected  int labelLocationIndex
          The index of the label's location in locations, or -1 if the path has no label location.
protected  Iterable<? extends LatLon> locations
          The labeled path's locations as specified by the application.
 
Constructor Summary
LabeledPath()
          Creates a labeled path with no locations and no label annotation.
LabeledPath(Iterable<? extends LatLon> locations)
          Creates a labeled path with specified locations.
LabeledPath(Iterable<? extends LatLon> locations, ScreenAnnotation annotation)
          Creates a labeled path with the specified label annotation and locations.
LabeledPath(ScreenAnnotation annotation)
          Creates a labeled path with the specified label annotation and no locations.
 
Method Summary
protected  Vec4 computePoint(DrawContext dc, LatLon location)
          Computes a model-coordinate point from a LatLon or Position, applying the path's altitude mode.
protected  void determineLabelLocation(DrawContext dc)
          Determines the screen location to place the label at, and stores the the index of the corresponding location in labelLocationIndex.
protected  void drawLabel(DrawContext dc)
          Causes the labeled path to draw its label at the path's current label location.
 int getAltitudeMode()
          Returns the labeled path's altitude mode.
 ScreenAnnotation getAnnotation()
          Returns the ScreenAnnotation used to draw the label, or null if the path doesn't draw a label.
protected  Vec4 getLabelPoint(DrawContext dc)
          Returns the label's model-coordinate point form the path's location iterable, applying the path's altitude mode.
protected  double getLabelVisibleArea(DrawContext dc)
          Returns the approximate number of square pixels that are visible at the label's current location, or 0 if the label is not visible.
 Iterable<? extends LatLon> getLocations()
          Returns the labeled path's locations.
protected  boolean isLabelCompletelyVisible(DrawContext dc)
          Returns true if the label is completely visible at its current location, and false otherwise.
 void render(DrawContext dc)
          Causes the labeled path to draw its label at one of the path locations.
protected  void reset()
          Resets the labeled path's cached location information.
 void setAltitudeMode(int altitudeMode)
          Specifies the labeled path's altitude mode, one of WorldWind.ABSOLUTE, WorldWind.RELATIVE_TO_GROUND or WorldWind.CLAMP_TO_GROUND.
 void setAnnotation(ScreenAnnotation annotation)
          Specifies the ScreenAnnotation to use for drawing the label.
protected  void setLabelLocation(DrawContext dc, Vec4 screenPoint)
          Places the label at the specified screen point.
 void setLocations(Iterable<? extends LatLon> locations)
          Specifies the labeled path's locations, which replace the path's current locations, if any.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

altitudeMode

protected int altitudeMode
The altitude mode that defines how to interpret the altitude of locations that have an altitude component. Defaults to WorldWind.ABSOLUTE.


annotation

protected ScreenAnnotation annotation
The screen annotation to use as a label. null if no annotation has been specified.


frameNumber

protected long frameNumber
The frame number used to place the label.


labelLocationIndex

protected int labelLocationIndex
The index of the label's location in locations, or -1 if the path has no label location.


locations

protected Iterable<? extends LatLon> locations
The labeled path's locations as specified by the application. null if no locations have been specified.

Constructor Detail

LabeledPath

public LabeledPath()
Creates a labeled path with no locations and no label annotation.


LabeledPath

public LabeledPath(Iterable<? extends LatLon> locations)
Creates a labeled path with specified locations.

Parameters:
locations - the labeled path's locations.
Throws:
IllegalArgumentException - if locations is null.

LabeledPath

public LabeledPath(Iterable<? extends LatLon> locations,
                   ScreenAnnotation annotation)
Creates a labeled path with the specified label annotation and locations.

Parameters:
locations - the labeled path's locations.
annotation - the screen annotation to use for drawing the label, or null if no label should be drawn.
Throws:
IllegalArgumentException - if locations is null.

LabeledPath

public LabeledPath(ScreenAnnotation annotation)
Creates a labeled path with the specified label annotation and no locations.

Parameters:
annotation - the screen annotation to use for drawing the label, or null if no label should be drawn.
Method Detail

computePoint

protected Vec4 computePoint(DrawContext dc,
                            LatLon location)
Computes a model-coordinate point from a LatLon or Position, applying the path's altitude mode. If the location is a LatLon it's assumed to have an elevation of 0.

Parameters:
dc - the current draw context.
location - the location to compute a point for.
Returns:
the model-coordinate point corresponding to the position and the path's path type.

determineLabelLocation

protected void determineLabelLocation(DrawContext dc)
Determines the screen location to place the label at, and stores the the index of the corresponding location in labelLocationIndex. This assigns labelLocationIndex to null if the label cannot be placed at any screen location corresponding to the path.

Parameters:
dc - the current draw context.

drawLabel

protected void drawLabel(DrawContext dc)
Causes the labeled path to draw its label at the path's current label location.

Parameters:
dc - the current draw context.

getAltitudeMode

public int getAltitudeMode()
Returns the labeled path's altitude mode.

Returns:
the labeled path's altitude mode.
See Also:
setAltitudeMode(int)

getAnnotation

public ScreenAnnotation getAnnotation()
Returns the ScreenAnnotation used to draw the label, or null if the path doesn't draw a label.

Returns:
the screen annotation used for drawing the label, or null if no label is drawn.

getLabelPoint

protected Vec4 getLabelPoint(DrawContext dc)
Returns the label's model-coordinate point form the path's location iterable, applying the path's altitude mode. If the location is a LatLon it's assumed to have an elevation of 0. This returns null if the path has no label location, or if the path's locations have changed and no longer contain a value at the cached location index.

Parameters:
dc - the current draw context.
Returns:
a model-coordinate point corresponding to the label's position and the path's path type.

getLabelVisibleArea

protected double getLabelVisibleArea(DrawContext dc)
Returns the approximate number of square pixels that are visible at the label's current location, or 0 if the label is not visible.

Parameters:
dc - the current draw context.
Returns:
the number of square pixels visible.

getLocations

public Iterable<? extends LatLon> getLocations()
Returns the labeled path's locations.

Returns:
the labeled path's locations. Will be null if no locations have been specified.

isLabelCompletelyVisible

protected boolean isLabelCompletelyVisible(DrawContext dc)
Returns true if the label is completely visible at its current location, and false otherwise.

Parameters:
dc - the current draw context.
Returns:
true if the label is completely visible at its current location, and false otherwise.

render

public void render(DrawContext dc)
Causes the labeled path to draw its label at one of the path locations.

Specified by:
render in interface Renderable
Parameters:
dc - the DrawContext to be used.
Throws:
IllegalArgumentException - if dc is null.
See Also:
DrawContext

reset

protected void reset()
Resets the labeled path's cached location information.


setAltitudeMode

public void setAltitudeMode(int altitudeMode)
Specifies the labeled path's altitude mode, one of WorldWind.ABSOLUTE, WorldWind.RELATIVE_TO_GROUND or WorldWind.CLAMP_TO_GROUND.

Note: If the altitude mode is unrecognized, WorldWind.ABSOLUTE is used.

Parameters:
altitudeMode - the altitude mode. The default value is WorldWind.ABSOLUTE.

setAnnotation

public void setAnnotation(ScreenAnnotation annotation)
Specifies the ScreenAnnotation to use for drawing the label. The specified screen annotation's screen point is controlled by the labled path. Otherwise the screen annotation's attributes are not modified.

Parameters:
annotation - the screen annotation to use for drawing the label, or null if no label should be drawn.

setLabelLocation

protected void setLabelLocation(DrawContext dc,
                                Vec4 screenPoint)
Places the label at the specified screen point.

Parameters:
dc - the current draw context.
screenPoint - the screen point to use.

setLocations

public void setLocations(Iterable<? extends LatLon> locations)
Specifies the labeled path's locations, which replace the path's current locations, if any.

Parameters:
locations - the labeled path's locations.
Throws:
IllegalArgumentException - if locations is null.

NASA World Wind