Package gov.nasa.worldwind.layers
Class ScalebarLayer
- java.lang.Object
-
- gov.nasa.worldwind.avlist.AVListImpl
-
- gov.nasa.worldwind.WWObjectImpl
-
- gov.nasa.worldwind.layers.AbstractLayer
-
- gov.nasa.worldwind.layers.ScalebarLayer
-
- All Implemented Interfaces:
AVList
,Disposable
,MessageListener
,Layer
,Restorable
,WWObject
,java.beans.PropertyChangeListener
,java.util.EventListener
public class ScalebarLayer extends AbstractLayer
Renders a scalebar graphic in a screen corner.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
ScalebarLayer.OrderedImage
-
Field Summary
Fields Modifier and Type Field Description protected int
borderWidth
protected java.awt.Color
color
protected java.awt.Font
defaultFont
protected long
frameStampForDrawing
protected long
frameStampForPicking
protected Vec4
locationCenter
protected Vec4
locationOffset
protected PickSupport
pickSupport
protected java.lang.String
position
protected java.lang.String
resizeBehavior
protected java.awt.Dimension
size
protected double
toViewportScale
protected java.lang.String
unit
static java.lang.String
UNIT_IMPERIAL
static java.lang.String
UNIT_METRIC
static java.lang.String
UNIT_NAUTICAL
-
Constructor Summary
Constructors Constructor Description ScalebarLayer()
Renders a scalebar graphic in a screen corner
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
addOrderedImage(DrawContext dc)
protected double
computePixelSize(DrawContext dc, Position referencePosition)
void
doPick(DrawContext dc, java.awt.Point pickPoint)
void
doRender(DrawContext dc)
void
draw(DrawContext dc, ScalebarLayer.OrderedImage orderedImage)
int
getBorderWidth()
java.awt.Color
getColor()
Get the scalebar colorjava.awt.Font
getFont()
Get the scalebar legend FonVec4
getLocationCenter()
Returns the current scalebar center location.Vec4
getLocationOffset()
Returns the current location offset.java.lang.String
getPosition()
java.lang.String
getResizeBehavior()
Returns the layer's resize behavior.java.awt.Dimension
getSize()
Get the scalebar graphic Dimension (in pixels)double
getToViewportScale()
Returns the scalebar-to-viewport scale factor.java.lang.String
getUnit()
void
setBorderWidth(int borderWidth)
Sets the scalebar offset from the viewport border.void
setColor(java.awt.Color color)
Set the scalbar Colorvoid
setFont(java.awt.Font font)
Set the scalebar legend Fonvoid
setLocationCenter(Vec4 locationCenter)
Specifies the screen location of the scalebar center.void
setLocationOffset(Vec4 locationOffset)
Specifies a placement offset from the scalebar's position on the screen.void
setPosition(java.lang.String position)
Sets the relative viewport location to display the scalebar.void
setResizeBehavior(java.lang.String resizeBehavior)
Sets the behavior the layer uses to size the scalebar when the viewport size changes, typically when the World Wind window is resized.void
setSize(java.awt.Dimension size)
Set the scalebar graphic Dimenion (in pixels)void
setToViewportScale(double toViewportScale)
Sets the scale factor applied to the viewport size to determine the displayed size of the scalebar.void
setUnit(java.lang.String unit)
Sets the unit the scalebar uses to display distances.java.lang.String
toString()
-
Methods inherited from class gov.nasa.worldwind.layers.AbstractLayer
createLayerConfigElements, dispose, doPreRender, getDataFileStore, getExpiryTime, getLayerConfigParams, getMaxActiveAltitude, getMaxEffectiveAltitude, getMinActiveAltitude, getMinEffectiveAltitude, getName, getOpacity, getRestorableState, getScale, getScreenCredit, isAtMaxResolution, isEnabled, isLayerActive, isLayerConfigDocument, isLayerInView, isMultiResolution, isNetworkRetrievalEnabled, isPickEnabled, pick, preRender, render, restoreState, setDataFileStore, setEnabled, setExpiryTime, setMaxActiveAltitude, setMinActiveAltitude, setName, setNetworkRetrievalEnabled, setOpacity, setPickEnabled, setScreenCredit
-
Methods inherited from class gov.nasa.worldwind.WWObjectImpl
onMessage, propertyChange
-
Methods inherited from class gov.nasa.worldwind.avlist.AVListImpl
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getBooleanValue, getBooleanValue, getChangeSupport, getDoubleValue, getDoubleValue, getEntries, getIntegerValue, getIntegerValue, getLongValue, getLongValue, getRestorableStateForAVPair, getStringValue, getStringValue, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface gov.nasa.worldwind.avlist.AVList
addPropertyChangeListener, addPropertyChangeListener, clearList, copy, firePropertyChange, firePropertyChange, getEntries, getStringValue, getValue, getValues, hasKey, removeKey, removePropertyChangeListener, removePropertyChangeListener, setValue, setValues
-
Methods inherited from interface gov.nasa.worldwind.event.MessageListener
onMessage
-
-
-
-
Field Detail
-
UNIT_METRIC
public static final java.lang.String UNIT_METRIC
- See Also:
- Constant Field Values
-
UNIT_IMPERIAL
public static final java.lang.String UNIT_IMPERIAL
- See Also:
- Constant Field Values
-
UNIT_NAUTICAL
public static final java.lang.String UNIT_NAUTICAL
- See Also:
- Constant Field Values
-
size
protected java.awt.Dimension size
-
color
protected java.awt.Color color
-
borderWidth
protected int borderWidth
-
position
protected java.lang.String position
-
resizeBehavior
protected java.lang.String resizeBehavior
-
unit
protected java.lang.String unit
-
defaultFont
protected java.awt.Font defaultFont
-
toViewportScale
protected double toViewportScale
-
pickSupport
protected PickSupport pickSupport
-
locationCenter
protected Vec4 locationCenter
-
locationOffset
protected Vec4 locationOffset
-
frameStampForPicking
protected long frameStampForPicking
-
frameStampForDrawing
protected long frameStampForDrawing
-
-
Method Detail
-
getSize
public java.awt.Dimension getSize()
Get the scalebar graphic Dimension (in pixels)- Returns:
- the scalebar graphic Dimension
-
setSize
public void setSize(java.awt.Dimension size)
Set the scalebar graphic Dimenion (in pixels)- Parameters:
size
- the scalebar graphic Dimension
-
getColor
public java.awt.Color getColor()
Get the scalebar color- Returns:
- the scalebar Color
-
setColor
public void setColor(java.awt.Color color)
Set the scalbar Color- Parameters:
color
- the scalebar Color
-
getToViewportScale
public double getToViewportScale()
Returns the scalebar-to-viewport scale factor.- Returns:
- the scalebar-to-viewport scale factor
-
setToViewportScale
public void setToViewportScale(double toViewportScale)
Sets the scale factor applied to the viewport size to determine the displayed size of the scalebar. This scale factor is used only when the layer's resize behavior is AVKey.RESIZE_STRETCH or AVKey.RESIZE_SHRINK_ONLY. The scalebar's width is adjusted to occupy the proportion of the viewport's width indicated by this factor. The scalebar's height is adjusted to maintain the scalebar's Dimension aspect ratio.- Parameters:
toViewportScale
- the scalebar to viewport scale factor
-
getPosition
public java.lang.String getPosition()
-
setPosition
public void setPosition(java.lang.String position)
Sets the relative viewport location to display the scalebar. Can be one of AVKey.NORTHEAST, AVKey.NORTHWEST, AVKey.SOUTHEAST (the default), or AVKey.SOUTHWEST. These indicate the corner of the viewport.- Parameters:
position
- the desired scalebar position
-
getLocationCenter
public Vec4 getLocationCenter()
Returns the current scalebar center location.- Returns:
- the current location center. May be null.
-
setLocationCenter
public void setLocationCenter(Vec4 locationCenter)
Specifies the screen location of the scalebar center. May be null. If this value is non-null, it overrides the position specified by #setPosition. The location is specified in pixels. The origin is the window's lower left corner. Positive X values are to the right of the origin, positive Y values are upwards from the origin. The final scalebar location will be affected by the currently specified location offset if a non-null location offset has been specified (see #setLocationOffset).- Parameters:
locationCenter
- the scalebar center. May be null.- See Also:
setPosition(java.lang.String)
,setLocationOffset(gov.nasa.worldwind.geom.Vec4)
-
getLocationOffset
public Vec4 getLocationOffset()
Returns the current location offset. See #setLocationOffset for a description of the offset and its values.- Returns:
- the location offset. Will be null if no offset has been specified.
-
setLocationOffset
public void setLocationOffset(Vec4 locationOffset)
Specifies a placement offset from the scalebar's position on the screen.- Parameters:
locationOffset
- the number of pixels to shift the scalebar from its specified screen position. A positive X value shifts the image to the right. A positive Y value shifts the image up. If null, no offset is applied. The default offset is null.- See Also:
setLocationCenter(gov.nasa.worldwind.geom.Vec4)
,setPosition(java.lang.String)
-
getResizeBehavior
public java.lang.String getResizeBehavior()
Returns the layer's resize behavior.- Returns:
- the layer's resize behavior
-
setResizeBehavior
public void setResizeBehavior(java.lang.String resizeBehavior)
Sets the behavior the layer uses to size the scalebar when the viewport size changes, typically when the World Wind window is resized. If the value is AVKey.RESIZE_KEEP_FIXED_SIZE, the scalebar size is kept to the size specified in its Dimension scaled by the layer's current icon scale. If the value is AVKey.RESIZE_STRETCH, the scalebar is resized to have a constant size relative to the current viewport size. If the viewport shrinks the scalebar size decreases; if it expands then the scalebar enlarges. If the value is AVKey.RESIZE_SHRINK_ONLY (the default), scalebar sizing behaves as for AVKey.RESIZE_STRETCH but it will not grow larger than the size specified in its Dimension.- Parameters:
resizeBehavior
- the desired resize behavior
-
getBorderWidth
public int getBorderWidth()
-
setBorderWidth
public void setBorderWidth(int borderWidth)
Sets the scalebar offset from the viewport border.- Parameters:
borderWidth
- the number of pixels to offset the scalebar from the borders indicated bysetPosition(String)
.
-
getUnit
public java.lang.String getUnit()
-
setUnit
public void setUnit(java.lang.String unit)
Sets the unit the scalebar uses to display distances. Can be one ofUNIT_METRIC
(the default), orUNIT_IMPERIAL
.- Parameters:
unit
- the desired unit
-
getFont
public java.awt.Font getFont()
Get the scalebar legend Fon- Returns:
- the scalebar legend Font
-
setFont
public void setFont(java.awt.Font font)
Set the scalebar legend Fon- Parameters:
font
- the scalebar legend Font
-
doRender
public void doRender(DrawContext dc)
- Specified by:
doRender
in classAbstractLayer
-
doPick
public void doPick(DrawContext dc, java.awt.Point pickPoint)
- Overrides:
doPick
in classAbstractLayer
-
addOrderedImage
protected void addOrderedImage(DrawContext dc)
-
computePixelSize
protected double computePixelSize(DrawContext dc, Position referencePosition)
-
draw
public void draw(DrawContext dc, ScalebarLayer.OrderedImage orderedImage)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classAbstractLayer
-
-