Class LabeledPath
- java.lang.Object
-
- gov.nasa.worldwindx.examples.util.LabeledPath
-
- All Implemented Interfaces:
Renderable
public class LabeledPath extends java.lang.Object implements Renderable
LabeledPath draws aAnnotation
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 isnull
, 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
Fields Modifier and Type Field Description 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 inlocations
, or -1 if the path has no label location.protected java.lang.Iterable<? extends LatLon>
locations
The labeled path's locations as specified by the application.
-
Constructor Summary
Constructors Constructor Description LabeledPath()
Creates a labeled path with no locations and no label annotation.LabeledPath(ScreenAnnotation annotation)
Creates a labeled path with the specified label annotation and no locations.LabeledPath(java.lang.Iterable<? extends LatLon> locations)
Creates a labeled path with specified locations.LabeledPath(java.lang.Iterable<? extends LatLon> locations, ScreenAnnotation annotation)
Creates a labeled path with the specified label annotation and locations.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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 inlabelLocationIndex
.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 theScreenAnnotation
used to draw the label, ornull
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.java.lang.Iterable<? extends LatLon>
getLocations()
Returns the labeled path's locations.protected boolean
isLabelCompletelyVisible(DrawContext dc)
Returnstrue
if the label is completely visible at its current location, andfalse
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 ofWorldWind.ABSOLUTE
,WorldWind.RELATIVE_TO_GROUND
orWorldWind.CLAMP_TO_GROUND
.void
setAnnotation(ScreenAnnotation annotation)
Specifies theScreenAnnotation
to use for drawing the label.protected void
setLabelLocation(DrawContext dc, Vec4 screenPoint)
Places the label at the specified screen point.void
setLocations(java.lang.Iterable<? extends LatLon> locations)
Specifies the labeled path's locations, which replace the path's current locations, if any.
-
-
-
Field Detail
-
locations
protected java.lang.Iterable<? extends LatLon> locations
The labeled path's locations as specified by the application.null
if no locations have been specified.
-
altitudeMode
protected int altitudeMode
The altitude mode that defines how to interpret the altitude of locations that have an altitude component. Defaults toWorldWind.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 inlocations
, or -1 if the path has no label location.
-
-
Constructor Detail
-
LabeledPath
public LabeledPath()
Creates a labeled path with no locations and no label annotation.
-
LabeledPath
public LabeledPath(java.lang.Iterable<? extends LatLon> locations)
Creates a labeled path with specified locations.- Parameters:
locations
- the labeled path's locations.- Throws:
java.lang.IllegalArgumentException
- if locations isnull
.
-
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, ornull
if no label should be drawn.
-
LabeledPath
public LabeledPath(java.lang.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, ornull
if no label should be drawn.- Throws:
java.lang.IllegalArgumentException
- if locations isnull
.
-
-
Method Detail
-
getLocations
public java.lang.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.
-
setLocations
public void setLocations(java.lang.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:
java.lang.IllegalArgumentException
- if locations isnull
.
-
getAltitudeMode
public int getAltitudeMode()
Returns the labeled path's altitude mode.- Returns:
- the labeled path's altitude mode.
- See Also:
setAltitudeMode(int)
-
setAltitudeMode
public void setAltitudeMode(int altitudeMode)
Specifies the labeled path's altitude mode, one ofWorldWind.ABSOLUTE
,WorldWind.RELATIVE_TO_GROUND
orWorldWind.CLAMP_TO_GROUND
.Note: If the altitude mode is unrecognized,
WorldWind.ABSOLUTE
is used.- Parameters:
altitudeMode
- the altitude mode. The default value isWorldWind.ABSOLUTE
.
-
getAnnotation
public ScreenAnnotation getAnnotation()
Returns theScreenAnnotation
used to draw the label, ornull
if the path doesn't draw a label.- Returns:
- the screen annotation used for drawing the label, or
null
if no label is drawn.
-
setAnnotation
public void setAnnotation(ScreenAnnotation annotation)
Specifies theScreenAnnotation
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, ornull
if no label should be drawn.
-
render
public void render(DrawContext dc)
Causes the labeled path to draw its label at one of the path locations.- Specified by:
render
in interfaceRenderable
- Parameters:
dc
- theDrawContext
to be used.- Throws:
java.lang.IllegalArgumentException
- if dc isnull
.- See Also:
DrawContext
-
reset
protected void reset()
Resets the labeled path's cached location information.
-
determineLabelLocation
protected void determineLabelLocation(DrawContext dc)
Determines the screen location to place the label at, and stores the the index of the corresponding location inlabelLocationIndex
. This assignslabelLocationIndex
tonull
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.
-
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.
-
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.
-
isLabelCompletelyVisible
protected boolean isLabelCompletelyVisible(DrawContext dc)
Returnstrue
if the label is completely visible at its current location, andfalse
otherwise.- Parameters:
dc
- the current draw context.- Returns:
true
if the label is completely visible at its current location, andfalse
otherwise.
-
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 returnsnull
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.
-
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.
-
-