private void calculateBestFit(double scale) {
		double unitLength = mapPresenter.getConfiguration().getUnitLength();
		int len = 0;
		long px = 0;
		if (UnitType.ENGLISH.equals(unitType)) {
			// try miles.
			for (int i = lengths.length - 1; i > -1; i--) {
				len = this.lengths[i];
				px = Math.round((len * scale / unitLength) * METERS_IN_MILE);
				if (px < MAX_SIZE_IN_PIXELS) {
					break;
				}
			}
			// try yards.
			if (px > MAX_SIZE_IN_PIXELS) {
				for (int i = YARD_STARTING_POINT; i > -1; i--) {
					len = this.lengths[i];
					px = Math.round((len * scale / unitLength) * METERS_IN_YARD);
					if (px < MAX_SIZE_IN_PIXELS) {
						break;
					}
				}
				widthInUnitsIsMiles = false;
			} else {
				widthInUnitsIsMiles = true;
			}
		} else if (UnitType.ENGLISH_FOOT.equals(unitType)) {
			// try miles.
			for (int i = lengths.length - 1; i > -1; i--) {
				len = this.lengths[i];
				px = Math.round((len * scale / unitLength) * METERS_IN_MILE);
				if (px < MAX_SIZE_IN_PIXELS) {
					break;
				}
			}
			// try feet.
			if (px > MAX_SIZE_IN_PIXELS) {
				for (int i = YARD_STARTING_POINT; i > -1; i--) {
					len = this.lengths[i];
					px = Math.round((len * scale / unitLength) / FEET_IN_METER);
					if (px < MAX_SIZE_IN_PIXELS) {
						break;
					}
				}
				widthInUnitsIsMiles = false;
			} else {
				widthInUnitsIsMiles = true;
			}
		} else {
			for (int i = lengths.length - 1; i > -1; i--) {
				len = this.lengths[i];
				px = Math.round(len * scale / unitLength);
				if (px < MAX_SIZE_IN_PIXELS) {
					break;
				}
			}
		}

		widthInUnits = len;
		widthInPixels = (int) px;
	}
private void calculateBestFit ( double scale ) { double unitLength = mapPresenter . getConfiguration ( ) . getUnitLength ( ) ; int len = 0 ; long px = 0 ; if ( UnitType . ENGLISH . equals ( unitType ) ) { for ( int i = lengths . length - 1 ; i > - 1 ; i -- ) { len = this . lengths [ i ] ; px = Math . round ( ( len * scale / unitLength ) * METERS_IN_MILE ) ; if ( px < MAX_SIZE_IN_PIXELS ) { break ; } } if ( px > MAX_SIZE_IN_PIXELS ) { for ( int i = YARD_STARTING_POINT ; i > - 1 ; i -- ) { len = this . lengths [ i ] ; px = Math . round ( ( len * scale / unitLength ) * METERS_IN_YARD ) ; if ( px < MAX_SIZE_IN_PIXELS ) { break ; } } widthInUnitsIsMiles = false ; } else { widthInUnitsIsMiles = true ; } } else if ( UnitType . ENGLISH_FOOT . equals ( unitType ) ) { for ( int i = lengths . length - 1 ; i > - 1 ; i -- ) { len = this . lengths [ i ] ; px = Math . round ( ( len * scale / unitLength ) * METERS_IN_MILE ) ; if ( px < MAX_SIZE_IN_PIXELS ) { break ; } } if ( px > MAX_SIZE_IN_PIXELS ) { for ( int i = YARD_STARTING_POINT ; i > - 1 ; i -- ) { len = this . lengths [ i ] ; px = Math . round ( ( len * scale / unitLength ) / FEET_IN_METER ) ; if ( px < MAX_SIZE_IN_PIXELS ) { break ; } } widthInUnitsIsMiles = false ; } else { widthInUnitsIsMiles = true ; } } else { for ( int i = lengths . length - 1 ; i > - 1 ; i -- ) { len = this . lengths [ i ] ; px = Math . round ( len * scale / unitLength ) ; if ( px < MAX_SIZE_IN_PIXELS ) { break ; } } } widthInUnits = len ; widthInPixels = ( int ) px ; }
Find the rounded value (from the lengths array) which fits the closest into the maxSizeInPixels for the given
scale.

@param scale
@return closest fit in units (will be miles or yards for English, m for metric, unit for CRS)