protected ScaleBarLengthAndValue calculateScaleBarLengthAndValue ( DistanceUnitAdapter unitAdapter ) { this . prevMapPosition = this . mapViewPosition . getMapPosition ( ) ; double groundResolution = MercatorProjection . calculateGroundResolution ( this . prevMapPosition . latLong . latitude , MercatorProjection . getMapSize ( this . prevMapPosition . zoomLevel , this . displayModel . getTileSize ( ) ) ) ; groundResolution = groundResolution / unitAdapter . getMeterRatio ( ) ; int [ ] scaleBarValues = unitAdapter . getScaleBarValues ( ) ; int scaleBarLength = 0 ; int mapScaleValue = 0 ; for ( int scaleBarValue : scaleBarValues ) { mapScaleValue = scaleBarValue ; scaleBarLength = ( int ) ( mapScaleValue / groundResolution ) ; if ( scaleBarLength < ( this . mapScaleBitmap . getWidth ( ) - 10 ) ) { break ; } } return new ScaleBarLengthAndValue ( scaleBarLength , mapScaleValue ) ; }
Calculates the required length and value of the scalebar