Class LabeledPath

  • All Implemented Interfaces:
    Renderable

    public class LabeledPath
    extends java.lang.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 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 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.
    • 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 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.
      • 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, or null if no label should be drawn.
        Throws:
        java.lang.IllegalArgumentException - if locations is null.
    • 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 is null.
      • 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.
      • 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.
      • 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:
        java.lang.IllegalArgumentException - if dc is null.
        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 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.
      • 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)
        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.
      • 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.
      • 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.