@Override
public Scale getScaleDenominator(final Rectangle paintArea, final double dpi) {
final ReferencedEnvelope bboxAdjustedToScreen = toReferencedEnvelope(paintArea, dpi);
DistanceUnit projUnit = DistanceUnit.fromProjection(getProjection());
double geoWidthInInches;
if (projUnit == DistanceUnit.DEGREES) {
GeodeticCalculator calculator = new GeodeticCalculator(getProjection());
final double centerY = bboxAdjustedToScreen.centre().y;
calculator.setStartingGeographicPoint(bboxAdjustedToScreen.getMinX(), centerY);
calculator.setDestinationGeographicPoint(bboxAdjustedToScreen.getMaxX(), centerY);
double geoWidthInEllipsoidUnits = calculator.getOrthodromicDistance();
DistanceUnit ellipsoidUnit = DistanceUnit.fromString(calculator.getEllipsoid().getAxisUnit().toString());
geoWidthInInches = ellipsoidUnit.convertTo(geoWidthInEllipsoidUnits, DistanceUnit.IN);
} else {
// (scale * width ) / dpi = geowidith
geoWidthInInches = projUnit.convertTo(bboxAdjustedToScreen.getWidth(), DistanceUnit.IN);
}