Package 

Class ScaleBarOverlay

  • 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.

    • Constructor Detail

      • ScaleBarOverlay

        ScaleBarOverlay(MapView mapView)
      • ScaleBarOverlay

        ScaleBarOverlay(Context pContext, int pMapWidth, int pMapHeight)
    • Method Detail

      • setMinZoom

         void setMinZoom(double zoom)

        Sets the minimum zoom level for the scale bar to be drawn.

        Parameters:
        zoom - minimum zoom level
      • setBarPaint

         void setBarPaint(Paint pBarPaint)

        Sets the paint for drawing the bar

        Parameters:
        pBarPaint - bar drawing paint
      • 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 offset
        y - 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.

      • onDetach

         void onDetach(MapView mapView)

        Override to perform clean up of resources before shutdown. By default does nothing.