public static MapBounds adjustBoundsToScaleAndMapSize(
            final GenericMapAttributeValues mapValues,
            final Rectangle paintArea,
            final MapBounds bounds,
            final double dpi) {
        MapBounds newBounds = bounds;
        if (mapValues.isUseNearestScale()) {
            newBounds = newBounds.adjustBoundsToNearestScale(
                    mapValues.getZoomLevels(),
                    mapValues.getZoomSnapTolerance(),
                    mapValues.getZoomLevelSnapStrategy(),
                    mapValues.getZoomSnapGeodetic(),
                    paintArea, dpi);
        }

        newBounds = new BBoxMapBounds(newBounds.toReferencedEnvelope(paintArea));

        if (mapValues.isUseAdjustBounds()) {
            newBounds = newBounds.adjustedEnvelope(paintArea);
        }
        return newBounds;
    }
public static MapBounds adjustBoundsToScaleAndMapSize ( final GenericMapAttributeValues mapValues , final Rectangle paintArea , final MapBounds bounds , final double dpi ) { MapBounds newBounds = bounds ; if ( mapValues . isUseNearestScale ( ) ) { newBounds = newBounds . adjustBoundsToNearestScale ( mapValues . getZoomLevels ( ) , mapValues . getZoomSnapTolerance ( ) , mapValues . getZoomLevelSnapStrategy ( ) , mapValues . getZoomSnapGeodetic ( ) , paintArea , dpi ) ; } newBounds = new BBoxMapBounds ( newBounds . toReferencedEnvelope ( paintArea ) ) ; if ( mapValues . isUseAdjustBounds ( ) ) { newBounds = newBounds . adjustedEnvelope ( paintArea ) ; } return newBounds ; }
If requested, adjust the bounds to the nearest scale and the map size.

@param mapValues Map parameters.
@param paintArea The size of the painting area.
@param bounds The map bounds.
@param dpi the DPI.