-
- All Implemented Interfaces:
-
org.osmdroid.util.constants.GeoConstants,org.osmdroid.views.util.constants.OverlayConstants
public class ScaleBarOverlay extends Overlay implements GeoConstants
ScaleBarOverlay.java
Puts a scale bar in the top-left corner of the screen, offset by a configurable number of pixels. The bar is scaled to 1-inch length by querying for the physical DPI of the screen. The size of the bar is printed between the tick marks. A vertical (longitude) scale can be enabled. Scale is printed in metric (kilometers, meters), imperial (miles, feet) and nautical (nautical miles, feet).
Author: Erik Burrows, Griffin Systems LLC erik@griffinsystems.org
Change Log: 2010-10-08: Inclusion to osmdroid trunk 2015-12-17: Allow for top, bottom, left or right placement by W. Strickling
Usage:
MapView map = new MapView(...); ScaleBarOverlay scaleBar = new ScaleBarOverlay(map); // Thiw is an important change of calling!map.getOverlays().add(scaleBar);To Do List: 1. Allow for top, bottom, left or right placement. // done in this changement 2. Scale bar to precise displayed scale text after rounding.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public enumScaleBarOverlay.UnitsOfMeasure
-
Field Summary
Fields Modifier and Type Field Description doubleminZoomScaleBarOverlay.UnitsOfMeasureunitsOfMeasureprotected booleanalignBottomprotected booleanalignRightpublic floatxdpipublic floatydpipublic intscreenWidthpublic intscreenHeightprivate PaintbarPaintprivate PainttextPaintprivate booleancentredprivate floatmaxLength
-
Constructor Summary
Constructors Constructor Description ScaleBarOverlay(MapView mapView)ScaleBarOverlay(Context pContext, int pMapWidth, int pMapHeight)
-
Method Summary
Modifier and Type Method Description voidsetMinZoom(double zoom)Sets the minimum zoom level for the scale bar to be drawn. ScaleBarOverlay.UnitsOfMeasuregetUnitsOfMeasure()Gets the units of measure to be shown in the scale bar voidsetUnitsOfMeasure(ScaleBarOverlay.UnitsOfMeasure unitsOfMeasure)Sets the units of measure to be shown in the scale bar voidsetAlignBottom(boolean alignBottom)voidsetAlignRight(boolean alignRight)PaintgetBarPaint()Return's the paint used to draw the bar voidsetBarPaint(Paint pBarPaint)Sets the paint for drawing the bar PaintgetTextPaint()Returns the paint used to draw the text voidsetTextPaint(Paint pTextPaint)Sets the paint for drawing the text voidsetCentred(boolean centred)Flag to draw the bar centered around the set offset coordinates or to the right/bottom of thecoordinates (default) voidsetMaxLength(float pMaxLengthInCm)Sets the maximum bar length. voidsetScaleBarOffset(int x, int y)Sets the scale bar screen offset for the bar. voidsetLineWidth(float width)Sets the bar's line width. voidsetTextSize(float size)Sets the text size. voiddrawLatitudeScale(boolean latitude)Latitudinal / horizontal scale bar flag voiddrawLongitudeScale(boolean longitude)Longitudinal / vertical scale bar flag voidsetBackgroundPaint(Paint pBgPaint)Sets the background paint. voidsetEnableAdjustLength(boolean adjustLength)If enabled, the bar will automatically adjust the length to reflect a round number (startingwith 1, 2 or 5). voiddraw(Canvas c, Projection projection)voiddisableScaleBar()voidenableScaleBar()voidonDetach(MapView mapView)Override to perform clean up of resources before shutdown. static StringgetScaleString(Context pContext, String pValue, GeoConstants.UnitOfMeasure pUnitOfMeasure)-
Methods inherited from class org.osmdroid.views.overlay.Overlay
draw, draw, getBounds, isEnabled, onDetach, onDoubleTap, onDoubleTapEvent, onDown, onFling, onKeyDown, onKeyUp, onLongPress, onPause, onResume, onScroll, onShowPress, onSingleTapConfirmed, onSingleTapUp, onTouchEvent, onTrackballEvent, setEnabled -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Method Detail
-
setMinZoom
void setMinZoom(double zoom)
Sets the minimum zoom level for the scale bar to be drawn.
- Parameters:
zoom- minimum zoom level
-
getUnitsOfMeasure
ScaleBarOverlay.UnitsOfMeasure getUnitsOfMeasure()
Gets the units of measure to be shown in the scale bar
-
setUnitsOfMeasure
void setUnitsOfMeasure(ScaleBarOverlay.UnitsOfMeasure unitsOfMeasure)
Sets the units of measure to be shown in the scale bar
-
setAlignBottom
void setAlignBottom(boolean alignBottom)
-
setAlignRight
void setAlignRight(boolean alignRight)
-
getBarPaint
Paint getBarPaint()
Return's the paint used to draw the bar
-
setBarPaint
void setBarPaint(Paint pBarPaint)
Sets the paint for drawing the bar
- Parameters:
pBarPaint- bar drawing paint
-
getTextPaint
Paint getTextPaint()
Returns the paint used to draw the text
-
setTextPaint
void setTextPaint(Paint pTextPaint)
Sets the paint for drawing the text
- Parameters:
pTextPaint- text drawing paint
-
setCentred
void setCentred(boolean centred)
Flag to draw the bar centered around the set offset coordinates or to the right/bottom of thecoordinates (default)
- Parameters:
centred- set true to centre the bar around the given screen coordinates
-
setMaxLength
void setMaxLength(float pMaxLengthInCm)
Sets the maximum bar length. If adjustLength is disabled this will match exactly the lengthof the bar. If adjustLength is enabled, the bar will be shortened to reflect a round numberin length.
- Parameters:
pMaxLengthInCm- maximum length of the bar in the screen in cm.
-
setScaleBarOffset
void setScaleBarOffset(int x, int y)
Sets the scale bar screen offset for the bar. Note: if the bar is set to be drawn centered,this will be the middle of the bar, otherwise the top left corner.
- Parameters:
x- x screen offsety- z screen offset
-
setLineWidth
void setLineWidth(float width)
Sets the bar's line width. (the default is 2)
- Parameters:
width- the new line width
-
setTextSize
void setTextSize(float size)
Sets the text size. (the default is 12)
- Parameters:
size- the new text size
-
drawLatitudeScale
void drawLatitudeScale(boolean latitude)
Latitudinal / horizontal scale bar flag
-
drawLongitudeScale
void drawLongitudeScale(boolean longitude)
Longitudinal / vertical scale bar flag
-
setBackgroundPaint
void setBackgroundPaint(Paint pBgPaint)
Sets the background paint. Set to null to disable drawing of background (default)
- Parameters:
pBgPaint- the paint for colouring the bar background
-
setEnableAdjustLength
void setEnableAdjustLength(boolean adjustLength)
If enabled, the bar will automatically adjust the length to reflect a round number (startingwith 1, 2 or 5). If disabled, the bar will always be drawn in full length representing afractional distance.
-
draw
void draw(Canvas c, Projection projection)
-
disableScaleBar
void disableScaleBar()
-
enableScaleBar
void enableScaleBar()
-
onDetach
void onDetach(MapView mapView)
Override to perform clean up of resources before shutdown. By default does nothing.
-
getScaleString
static String getScaleString(Context pContext, String pValue, GeoConstants.UnitOfMeasure pUnitOfMeasure)
-
-
-
-