Class SurfaceText

    • Field Detail

      • DEFAULT_TEXT_SIZE_IN_METERS

        public static final double DEFAULT_TEXT_SIZE_IN_METERS
        Default text size.
        See Also:
        Constant Field Values
      • DEFAULT_FONT

        public static final java.awt.Font DEFAULT_FONT
        Default font.
      • DEFAULT_COLOR

        public static final java.awt.Color DEFAULT_COLOR
        Default text color.
      • DEFAULT_OFFSET

        public static final Offset DEFAULT_OFFSET
        Default offset. The default offset centers the text on its geographic position both horizontally and vertically.
      • text

        protected java.lang.CharSequence text
        The text to draw.
      • location

        protected Position location
        Location at which to draw the text.
      • textSizeInMeters

        protected double textSizeInMeters
        The height of the text in meters.
      • dragEnabled

        protected boolean dragEnabled
        Dragging Support
      • font

        protected java.awt.Font font
        Font to use to draw the text. Defaults to DEFAULT_FONT.
      • color

        protected java.awt.Color color
        Color to use to draw the text. Defaults to DEFAULT_COLOR.
      • bgColor

        protected java.awt.Color bgColor
        Background color for the text. By default color will be generated to contrast with the text color.
      • priority

        protected double priority
        Text priority. Can be used to implement text culling.
      • offset

        protected Offset offset
        Offset that specifies where to place the text in relation to it's geographic position.
      • textBounds

        protected java.awt.geom.Rectangle2D textBounds
        Bounds of the text in pixels.
      • pixelSizeInMeters

        protected double pixelSizeInMeters
        Geographic size of a pixel.
      • scale

        protected double scale
        Scaling factor applied to the text to maintain a constant geographic size.
      • drawLocation

        protected LatLon drawLocation
        The lower-left location of the text box after applying offset.
      • spansAntimeridian

        protected boolean spansAntimeridian
        Indicates whether this text spans the dateline.
    • Constructor Detail

      • SurfaceText

        public SurfaceText​(java.lang.String text,
                           Position position)
        Create a new surface text object.
        Parameters:
        text - Text to draw.
        position - Geographic location at which to draw the text.
      • SurfaceText

        public SurfaceText​(java.lang.String text,
                           Position position,
                           java.awt.Font font,
                           java.awt.Color color)
        Create a new surface text object.
        Parameters:
        text - Text to draw.
        position - Geographic location at which to draw the text.
        font - Font to use when drawing text.
        color - Color to use when drawing text.
    • Method Detail

      • getText

        public java.lang.CharSequence getText()
        Indicates the text contained in this object.
        Specified by:
        getText in interface GeographicText
        Returns:
        The current text.
      • setText

        public void setText​(java.lang.CharSequence text)
        Specifies the text.
        Specified by:
        setText in interface GeographicText
        Parameters:
        text - New text.
      • getPosition

        public Position getPosition()
        Indicates the geographic position of the text.
        Specified by:
        getPosition in interface GeographicText
        Returns:
        The text position.
      • setPosition

        public void setPosition​(Position position)
        Specifies the geographic position of the text.

        The offset determines how the text is placed relative to this position. The default offset centers the text on the position both horizontally and vertically.

        Specified by:
        setPosition in interface GeographicText
        Parameters:
        position - New text position.
        See Also:
        setOffset(Offset)
      • getFont

        public java.awt.Font getFont()
        Indicates the font used to draw the text.
        Specified by:
        getFont in interface GeographicText
        Returns:
        Current font.
      • setFont

        public void setFont​(java.awt.Font font)
        Specifies the font used to draw the text.
        Specified by:
        setFont in interface GeographicText
        Parameters:
        font - New font.
      • getColor

        public java.awt.Color getColor()
        Indicates the color used to draw the text.
        Specified by:
        getColor in interface GeographicText
        Returns:
        Current text color.
      • setColor

        public void setColor​(java.awt.Color color)
        Specifies the color used to draw the text.
        Specified by:
        setColor in interface GeographicText
        Parameters:
        color - New color.
      • getBackgroundColor

        public java.awt.Color getBackgroundColor()
        Indicates the background color used to draw the text.
        Specified by:
        getBackgroundColor in interface GeographicText
        Returns:
        Current background color.
      • setBackgroundColor

        public void setBackgroundColor​(java.awt.Color background)
        Specifies the background color used to draw the text.
        Specified by:
        setBackgroundColor in interface GeographicText
        Parameters:
        background - New background color.
      • setPriority

        public void setPriority​(double priority)
        Specifies the text priority. The priority can be used to implement text culling.
        Specified by:
        setPriority in interface GeographicText
        Parameters:
        priority - New priority.
      • getPriority

        public double getPriority()
        Indicates the text priority. The priority can be used to implement text culling.
        Specified by:
        getPriority in interface GeographicText
        Returns:
        The text priority.
      • getOffset

        public Offset getOffset()
        Returns the text offset. The offset determines how to position the text relative to its geographic position.
        Returns:
        the text offset.
        See Also:
        setOffset(Offset)
      • setOffset

        public void setOffset​(Offset offset)
        Specifies a location relative to the label position at which to align the label. The label text begins at the point indicated by the offset. An offset of (0, 0) aligns the left baseline of the text with the position. An offset of (-0.5, -0.5) fraction aligns the center of the text with the position.

        A pixel based offset is interpreted based on the geographic size of the text. For example, if the text rendered "normally" in two dimensions would be 20 pixels tall, and the geographic text is 100 meters tall, then each pixel of text corresponds to 5 meters. So an offset of 2 pixels would correspond to a geographic offset of 10 meters.

        Parameters:
        offset - Offset that controls where to position the label relative to its geographic location.
      • getTextSize

        public double getTextSize()
      • setTextSize

        public void setTextSize​(double meters)
      • getReferencePosition

        public Position getReferencePosition()
        A position associated with the object that indicates its aggregate geographic position. The chosen position varies among implementers of this interface. For objects defined by a list of positions, the reference position is typically the first position in the list. For symmetric objects the reference position is often the center of the object. In many cases the object's reference position may be explicitly specified by the application.
        Specified by:
        getReferencePosition in interface Movable
        Returns:
        the object's reference position, or null if no reference position is available.
      • move

        public void move​(Position position)
        Shift the shape over the globe's surface while maintaining its original azimuth, its orientation relative to North.
        Specified by:
        move in interface Movable
        Parameters:
        position - the latitude and longitude to add to the shape's reference position.
      • moveTo

        public void moveTo​(Position position)
        Move the shape over the globe's surface while maintaining its original azimuth, its orientation relative to North.
        Specified by:
        moveTo in interface Movable
        Parameters:
        position - the new position of the shape's reference position.
      • isDragEnabled

        public boolean isDragEnabled()
        Description copied from interface: Draggable
        Indicates whether the object is enabled for dragging.
        Specified by:
        isDragEnabled in interface Draggable
        Returns:
        true if the object is enabled, else false.
      • setDragEnabled

        public void setDragEnabled​(boolean enabled)
        Description copied from interface: Draggable
        Controls whether the object is enabled for dragging.
        Specified by:
        setDragEnabled in interface Draggable
        Parameters:
        enabled - true if the object is enabled, else false.
      • doDrag

        protected void doDrag​(DragContext dragContext)
      • getSectors

        public java.util.List<Sector> getSectors​(DrawContext dc)
        Returns a list of sectors indicating the geographic region that bounds this renderable for the specified draw context.

        The returned list typically contains one sector that bounds this renderable in geographic coordinates. When this renderable spans the anti-meridian - the +/- 180 degree meridian - the returned list contains two sectors, one on either side of the anti-meridian.

        Specified by:
        getSectors in interface SurfaceRenderable
        Parameters:
        dc - the draw context for which to determine this renderable's geographic bounds.
        Returns:
        a list of one or two sectors that bound this renderable.
      • drawGeographic

        protected void drawGeographic​(DrawContext dc,
                                      SurfaceTileDrawContext sdc)
        Causes the SurfaceObject to render itself to the specified region in geographic coordinates. The specified viewport denotes the geographic region and its corresponding screen viewport.
        Specified by:
        drawGeographic in class AbstractSurfaceObject
        Parameters:
        dc - the current draw context.
        sdc - the context containing a geographic region and screen viewport corresponding to a surface tile.
      • drawText

        protected void drawText​(DrawContext dc)
        Draw the text.
        Parameters:
        dc - Current draw context.
      • computeGeometry

        protected void computeGeometry​(DrawContext dc,
                                       SurfaceTileDrawContext sdc)
        Compute the text size and position.
        Parameters:
        dc - Current draw context.
        sdc - Current surface tile draw context.
      • applyDrawTransform

        protected void applyDrawTransform​(DrawContext dc,
                                          SurfaceTileDrawContext sdc)
        Apply a transform to the GL state to draw the text at the proper location and scale.
        Parameters:
        dc - Current draw context.
        sdc - Current surface tile draw context.
      • isSmall

        protected boolean isSmall()
        Determine if the text is too small to draw.
        Returns:
        true if the height of the text is less than one pixel.
      • computePixelSize

        protected double computePixelSize​(DrawContext dc,
                                          SurfaceTileDrawContext sdc)
        Compute the size of a pixel in the surface tile.
        Parameters:
        dc - Current draw context.
        sdc - Current surface tile draw context.
        Returns:
        The size of a tile pixel in meters.
      • determineBackgroundColor

        protected java.awt.Color determineBackgroundColor​(java.awt.Color color)
        Determine the text background color. This method returns the user specified background color, or a computed default color if the user has not set a background color.
        Parameters:
        color - text color.
        Returns:
        the user specified background color, or a default color that contrasts with the text color.
      • computeBackgroundColor

        protected java.awt.Color computeBackgroundColor​(java.awt.Color color)
        Compute a background color that contrasts with the text color.
        Parameters:
        color - text color.
        Returns:
        a color that contrasts with the text color.
      • computeSector

        protected Sector[] computeSector​(DrawContext dc)
        Compute the sector covered by this surface text.
        Parameters:
        dc - Current draw context.
        Returns:
        The sector covered by the surface text.
      • getTextRenderer

        protected TextRenderer getTextRenderer​(DrawContext dc)
        Get the text renderer to use to draw text.
        Parameters:
        dc - Current draw context.
        Returns:
        The text renderer that will be used to draw the surface text.
      • updateTextBounds

        protected void updateTextBounds​(DrawContext dc)
        Determine the text bounds.
        Parameters:
        dc - Current draw context.