public static String asMapArea ( MapWidget map , double area ) { double unitLength = map . getUnitLength ( ) ; double distance = area * unitLength * unitLength ; String unit = "m" ; if ( map . getMapModel ( ) . getMapInfo ( ) . getDisplayUnitType ( ) == UnitType . METRIC ) { // Right now, the distance is expressed in meter. Switch to km? if ( distance > ( METERS_IN_KM * METERS_IN_KM ) ) { distance /= ( METERS_IN_KM * METERS_IN_KM ) ; unit = "km" ; } } else if ( map . getMapModel ( ) . getMapInfo ( ) . getDisplayUnitType ( ) == UnitType . ENGLISH ) { if ( distance > ( METERS_IN_MILE * METERS_IN_MILE ) ) { // Switch to mile: distance = distance / ( METERS_IN_MILE * METERS_IN_MILE ) ; unit = "mi" ; } else { distance /= ( METERS_IN_YARD * METERS_IN_YARD ) ; // use yards. unit = "yd" ; } } else if ( map . getMapModel ( ) . getMapInfo ( ) . getDisplayUnitType ( ) == UnitType . CRS ) { unit = "u" ; } String formatted = NumberFormat . getDecimalFormat ( ) . format ( distance ) ; return formatted + unit + "&sup2;" ; }
Area formatting method . Requires an area as parameter expressed in the CRS units of the given map .