Package org.mapsforge.map.scalebar
Class MapScaleBar
- java.lang.Object
-
- org.mapsforge.map.scalebar.MapScaleBar
-
- Direct Known Subclasses:
DefaultMapScaleBar
public abstract class MapScaleBar extends java.lang.Object
A MapScaleBar displays the ratio of a distance on the map to the corresponding distance on the ground.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static class
MapScaleBar.ScaleBarLengthAndValue
Internal class used by calculateScaleBarLengthAndValuestatic class
MapScaleBar.ScaleBarPosition
-
Field Summary
Fields Modifier and Type Field Description protected DisplayModel
displayModel
protected DistanceUnitAdapter
distanceUnitAdapter
protected org.mapsforge.core.graphics.GraphicFactory
graphicFactory
protected org.mapsforge.core.graphics.Bitmap
mapScaleBitmap
protected org.mapsforge.core.graphics.Canvas
mapScaleCanvas
protected org.mapsforge.core.model.MapPosition
prevMapPosition
protected boolean
redrawNeeded
protected float
scale
protected MapScaleBar.ScaleBarPosition
scaleBarPosition
-
Constructor Summary
Constructors Constructor Description MapScaleBar(IMapViewPosition mapViewPosition, MapViewDimension mapViewDimension, DisplayModel displayModel, org.mapsforge.core.graphics.GraphicFactory graphicFactory, int width, int height, float scale)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected MapScaleBar.ScaleBarLengthAndValue
calculateScaleBarLengthAndValue()
Calculates the required length and value of the scalebar using the currentDistanceUnitAdapter
protected MapScaleBar.ScaleBarLengthAndValue
calculateScaleBarLengthAndValue(DistanceUnitAdapter unitAdapter)
Calculates the required length and value of the scalebarvoid
destroy()
Free all resourcesvoid
draw(org.mapsforge.core.graphics.GraphicContext graphicContext)
Called fromMapView
void
drawScaleBar()
The scalebar is redrawn now.DistanceUnitAdapter
getDistanceUnitAdapter()
int
getMarginHorizontal()
int
getMarginVertical()
MapScaleBar.ScaleBarPosition
getScaleBarPosition()
protected boolean
isRedrawNecessary()
Determines if a redraw is necessary or notboolean
isVisible()
protected abstract void
redraw(org.mapsforge.core.graphics.Canvas canvas)
Redraw the map scale bar.void
redrawScaleBar()
The scalebar will be redrawn on the next draw()void
setDistanceUnitAdapter(DistanceUnitAdapter distanceUnitAdapter)
Set theDistanceUnitAdapter
for the MapScaleBarvoid
setMarginHorizontal(int marginHorizontal)
void
setMarginVertical(int marginVertical)
void
setScaleBarPosition(MapScaleBar.ScaleBarPosition scaleBarPosition)
void
setVisible(boolean visible)
Set the visibility of thisMapScaleBar
-
-
-
Field Detail
-
displayModel
protected final DisplayModel displayModel
-
distanceUnitAdapter
protected DistanceUnitAdapter distanceUnitAdapter
-
graphicFactory
protected final org.mapsforge.core.graphics.GraphicFactory graphicFactory
-
mapScaleBitmap
protected final org.mapsforge.core.graphics.Bitmap mapScaleBitmap
-
mapScaleCanvas
protected final org.mapsforge.core.graphics.Canvas mapScaleCanvas
-
prevMapPosition
protected org.mapsforge.core.model.MapPosition prevMapPosition
-
redrawNeeded
protected boolean redrawNeeded
-
scale
protected final float scale
-
scaleBarPosition
protected MapScaleBar.ScaleBarPosition scaleBarPosition
-
-
Constructor Detail
-
MapScaleBar
public MapScaleBar(IMapViewPosition mapViewPosition, MapViewDimension mapViewDimension, DisplayModel displayModel, org.mapsforge.core.graphics.GraphicFactory graphicFactory, int width, int height, float scale)
-
-
Method Detail
-
destroy
public void destroy()
Free all resources
-
isVisible
public boolean isVisible()
- Returns:
- true if this
MapScaleBar
is visible
-
setVisible
public void setVisible(boolean visible)
Set the visibility of thisMapScaleBar
- Parameters:
visible
- true if the MapScaleBar should be visible, false otherwise
-
getDistanceUnitAdapter
public DistanceUnitAdapter getDistanceUnitAdapter()
- Returns:
- the
DistanceUnitAdapter
in use by this MapScaleBar
-
setDistanceUnitAdapter
public void setDistanceUnitAdapter(DistanceUnitAdapter distanceUnitAdapter)
Set theDistanceUnitAdapter
for the MapScaleBar- Parameters:
distanceUnitAdapter
- TheDistanceUnitAdapter
to be used by thisMapScaleBar
-
getMarginHorizontal
public int getMarginHorizontal()
-
setMarginHorizontal
public void setMarginHorizontal(int marginHorizontal)
-
getMarginVertical
public int getMarginVertical()
-
setMarginVertical
public void setMarginVertical(int marginVertical)
-
getScaleBarPosition
public MapScaleBar.ScaleBarPosition getScaleBarPosition()
-
setScaleBarPosition
public void setScaleBarPosition(MapScaleBar.ScaleBarPosition scaleBarPosition)
-
calculateScaleBarLengthAndValue
protected MapScaleBar.ScaleBarLengthAndValue calculateScaleBarLengthAndValue(DistanceUnitAdapter unitAdapter)
Calculates the required length and value of the scalebar- Parameters:
unitAdapter
- the DistanceUnitAdapter to calculate for- Returns:
- a
MapScaleBar.ScaleBarLengthAndValue
object containing the required scaleBarLength and scaleBarValue
-
calculateScaleBarLengthAndValue
protected MapScaleBar.ScaleBarLengthAndValue calculateScaleBarLengthAndValue()
Calculates the required length and value of the scalebar using the currentDistanceUnitAdapter
- Returns:
- a
MapScaleBar.ScaleBarLengthAndValue
object containing the required scaleBarLength and scaleBarValue
-
draw
public void draw(org.mapsforge.core.graphics.GraphicContext graphicContext)
Called fromMapView
- Parameters:
graphicContext
- The graphicContext to use to draw the MapScaleBar
-
drawScaleBar
public void drawScaleBar()
The scalebar is redrawn now.
-
redrawScaleBar
public void redrawScaleBar()
The scalebar will be redrawn on the next draw()
-
isRedrawNecessary
protected boolean isRedrawNecessary()
Determines if a redraw is necessary or not- Returns:
- true if redraw is necessary, false otherwise
-
redraw
protected abstract void redraw(org.mapsforge.core.graphics.Canvas canvas)
Redraw the map scale bar. Make sure you always apply scale factor to all coordinates and dimensions.- Parameters:
canvas
- The canvas to draw on
-
-