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 aAnnotationon 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 intaltitudeModeThe altitude mode that defines how to interpret the altitude of locations that have an altitude component.protected ScreenAnnotationannotationThe screen annotation to use as a label.protected longframeNumberThe frame number used to place the label.protected intlabelLocationIndexThe index of the label's location inlocations, or -1 if the path has no label location.protected java.lang.Iterable<? extends LatLon>locationsThe 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 Vec4computePoint(DrawContext dc, LatLon location)Computes a model-coordinate point from a LatLon or Position, applying the path's altitude mode.protected voiddetermineLabelLocation(DrawContext dc)Determines the screen location to place the label at, and stores the the index of the corresponding location inlabelLocationIndex.protected voiddrawLabel(DrawContext dc)Causes the labeled path to draw its label at the path's current label location.intgetAltitudeMode()Returns the labeled path's altitude mode.ScreenAnnotationgetAnnotation()Returns theScreenAnnotationused to draw the label, ornullif the path doesn't draw a label.protected Vec4getLabelPoint(DrawContext dc)Returns the label's model-coordinate point form the path's location iterable, applying the path's altitude mode.protected doublegetLabelVisibleArea(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 booleanisLabelCompletelyVisible(DrawContext dc)Returnstrueif the label is completely visible at its current location, andfalseotherwise.voidrender(DrawContext dc)Causes the labeled path to draw its label at one of the path locations.protected voidreset()Resets the labeled path's cached location information.voidsetAltitudeMode(int altitudeMode)Specifies the labeled path's altitude mode, one ofWorldWind.ABSOLUTE,WorldWind.RELATIVE_TO_GROUNDorWorldWind.CLAMP_TO_GROUND.voidsetAnnotation(ScreenAnnotation annotation)Specifies theScreenAnnotationto use for drawing the label.protected voidsetLabelLocation(DrawContext dc, Vec4 screenPoint)Places the label at the specified screen point.voidsetLocations(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.nullif 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.nullif 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, ornullif 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, ornullif 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
nullif 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_GROUNDorWorldWind.CLAMP_TO_GROUND.Note: If the altitude mode is unrecognized,
WorldWind.ABSOLUTEis used.- Parameters:
altitudeMode- the altitude mode. The default value isWorldWind.ABSOLUTE.
-
getAnnotation
public ScreenAnnotation getAnnotation()
Returns theScreenAnnotationused to draw the label, ornullif the path doesn't draw a label.- Returns:
- the screen annotation used for drawing the label, or
nullif no label is drawn.
-
setAnnotation
public void setAnnotation(ScreenAnnotation annotation)
Specifies theScreenAnnotationto 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, ornullif 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:
renderin interfaceRenderable- Parameters:
dc- theDrawContextto 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 assignslabelLocationIndextonullif 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)
Returnstrueif the label is completely visible at its current location, andfalseotherwise.- Parameters:
dc- the current draw context.- Returns:
trueif the label is completely visible at its current location, andfalseotherwise.
-
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 returnsnullif 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.
-
-