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.ObjectA 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 classMapScaleBar.ScaleBarLengthAndValueInternal class used by calculateScaleBarLengthAndValuestatic classMapScaleBar.ScaleBarPosition
-
Field Summary
Fields Modifier and Type Field Description protected DisplayModeldisplayModelprotected DistanceUnitAdapterdistanceUnitAdapterprotected org.mapsforge.core.graphics.GraphicFactorygraphicFactoryprotected org.mapsforge.core.graphics.BitmapmapScaleBitmapprotected org.mapsforge.core.graphics.CanvasmapScaleCanvasprotected org.mapsforge.core.model.MapPositionprevMapPositionprotected booleanredrawNeededprotected floatscaleprotected MapScaleBar.ScaleBarPositionscaleBarPosition
-
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.ScaleBarLengthAndValuecalculateScaleBarLengthAndValue()Calculates the required length and value of the scalebar using the currentDistanceUnitAdapterprotected MapScaleBar.ScaleBarLengthAndValuecalculateScaleBarLengthAndValue(DistanceUnitAdapter unitAdapter)Calculates the required length and value of the scalebarvoiddestroy()Free all resourcesvoiddraw(org.mapsforge.core.graphics.GraphicContext graphicContext)Called fromMapViewvoiddrawScaleBar()The scalebar is redrawn now.DistanceUnitAdaptergetDistanceUnitAdapter()intgetMarginHorizontal()intgetMarginVertical()MapScaleBar.ScaleBarPositiongetScaleBarPosition()protected booleanisRedrawNecessary()Determines if a redraw is necessary or notbooleanisVisible()protected abstract voidredraw(org.mapsforge.core.graphics.Canvas canvas)Redraw the map scale bar.voidredrawScaleBar()The scalebar will be redrawn on the next draw()voidsetDistanceUnitAdapter(DistanceUnitAdapter distanceUnitAdapter)Set theDistanceUnitAdapterfor the MapScaleBarvoidsetMarginHorizontal(int marginHorizontal)voidsetMarginVertical(int marginVertical)voidsetScaleBarPosition(MapScaleBar.ScaleBarPosition scaleBarPosition)voidsetVisible(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
MapScaleBaris 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
DistanceUnitAdapterin use by this MapScaleBar
-
setDistanceUnitAdapter
public void setDistanceUnitAdapter(DistanceUnitAdapter distanceUnitAdapter)
Set theDistanceUnitAdapterfor the MapScaleBar- Parameters:
distanceUnitAdapter- TheDistanceUnitAdapterto 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.ScaleBarLengthAndValueobject 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.ScaleBarLengthAndValueobject 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
-
-