@Test public void testAdjustedEnvelope() { final BBoxMapBounds bboxMapBounds = new BBoxMapBounds(WGS84, -10, -90, 10, 90); final MapBounds mapBounds = bboxMapBounds.adjustedEnvelope(new Rectangle(5, 5)); final ReferencedEnvelope envelope = mapBounds.toReferencedEnvelope(new Rectangle(5, 5)); assertEquals(-90, envelope.getMinX(), 0.001); assertEquals(90, envelope.getMaxX(), 0.001); assertEquals(-90, envelope.getMinY(), 0.001); assertEquals(90, envelope.getMaxY(), 0.001); assertEquals(WGS84, envelope.getCoordinateReferenceSystem()); }
@Override public MapBounds adjustedEnvelope(final Rectangle paintArea) { final double paintAreaAspectRatio = paintArea.getWidth() / paintArea.getHeight(); final double bboxAspectRatio = this.bbox.getWidth() / this.bbox.getHeight(); if (paintAreaAspectRatio > bboxAspectRatio) { double centerX = (this.bbox.getMinX() + this.bbox.getMaxX()) / 2; double factor = paintAreaAspectRatio / bboxAspectRatio; double finalDiff = (this.bbox.getMaxX() - centerX) * factor; return new BBoxMapBounds(getProjection(), centerX - finalDiff, this.bbox.getMinY(), centerX + finalDiff, this.bbox.getMaxY()); } else { double centerY = (this.bbox.getMinY() + this.bbox.getMaxY()) / 2; double factor = bboxAspectRatio / paintAreaAspectRatio; double finalDiff = (this.bbox.getMaxY() - centerY) * factor; return new BBoxMapBounds(getProjection(), this.bbox.getMinX(), centerY - finalDiff, this.bbox.getMaxX(), centerY + finalDiff); } }
BBoxMapBounds extends MapBounds { @Override public MapBounds adjustedEnvelope(final Rectangle paintArea) { final double paintAreaAspectRatio = paintArea.getWidth() / paintArea.getHeight(); final double bboxAspectRatio = this.bbox.getWidth() / this.bbox.getHeight(); if (paintAreaAspectRatio > bboxAspectRatio) { double centerX = (this.bbox.getMinX() + this.bbox.getMaxX()) / 2; double factor = paintAreaAspectRatio / bboxAspectRatio; double finalDiff = (this.bbox.getMaxX() - centerX) * factor; return new BBoxMapBounds(getProjection(), centerX - finalDiff, this.bbox.getMinY(), centerX + finalDiff, this.bbox.getMaxY()); } else { double centerY = (this.bbox.getMinY() + this.bbox.getMaxY()) / 2; double factor = bboxAspectRatio / paintAreaAspectRatio; double finalDiff = (this.bbox.getMaxY() - centerY) * factor; return new BBoxMapBounds(getProjection(), this.bbox.getMinX(), centerY - finalDiff, this.bbox.getMaxX(), centerY + finalDiff); } } }
BBoxMapBounds extends MapBounds { @Override public MapBounds adjustedEnvelope(final Rectangle paintArea) { final double paintAreaAspectRatio = paintArea.getWidth() / paintArea.getHeight(); final double bboxAspectRatio = this.bbox.getWidth() / this.bbox.getHeight(); if (paintAreaAspectRatio > bboxAspectRatio) { double centerX = (this.bbox.getMinX() + this.bbox.getMaxX()) / 2; double factor = paintAreaAspectRatio / bboxAspectRatio; double finalDiff = (this.bbox.getMaxX() - centerX) * factor; return new BBoxMapBounds(getProjection(), centerX - finalDiff, this.bbox.getMinY(), centerX + finalDiff, this.bbox.getMaxY()); } else { double centerY = (this.bbox.getMinY() + this.bbox.getMaxY()) / 2; double factor = bboxAspectRatio / paintAreaAspectRatio; double finalDiff = (this.bbox.getMaxY() - centerY) * factor; return new BBoxMapBounds(getProjection(), this.bbox.getMinX(), centerY - finalDiff, this.bbox.getMaxX(), centerY + finalDiff); } } BBoxMapBounds(final CoordinateReferenceSystem projection, final Envelope envelope);  BBoxMapBounds(
            final CoordinateReferenceSystem projection, final double minX, final double minY,
            final double maxX, final double maxY);  BBoxMapBounds(final ReferencedEnvelope bbox); }
BBoxMapBounds extends MapBounds { @Override public MapBounds adjustedEnvelope(final Rectangle paintArea) { final double paintAreaAspectRatio = paintArea.getWidth() / paintArea.getHeight(); final double bboxAspectRatio = this.bbox.getWidth() / this.bbox.getHeight(); if (paintAreaAspectRatio > bboxAspectRatio) { double centerX = (this.bbox.getMinX() + this.bbox.getMaxX()) / 2; double factor = paintAreaAspectRatio / bboxAspectRatio; double finalDiff = (this.bbox.getMaxX() - centerX) * factor; return new BBoxMapBounds(getProjection(), centerX - finalDiff, this.bbox.getMinY(), centerX + finalDiff, this.bbox.getMaxY()); } else { double centerY = (this.bbox.getMinY() + this.bbox.getMaxY()) / 2; double factor = bboxAspectRatio / paintAreaAspectRatio; double finalDiff = (this.bbox.getMaxY() - centerY) * factor; return new BBoxMapBounds(getProjection(), this.bbox.getMinX(), centerY - finalDiff, this.bbox.getMaxX(), centerY + finalDiff); } } BBoxMapBounds(final CoordinateReferenceSystem projection, final Envelope envelope);  BBoxMapBounds(
            final CoordinateReferenceSystem projection, final double minX, final double minY,
            final double maxX, final double maxY);  BBoxMapBounds(final ReferencedEnvelope bbox); @Override ReferencedEnvelope toReferencedEnvelope(final Rectangle paintArea); @Override MapBounds adjustedEnvelope(final Rectangle paintArea); @Override MapBounds adjustBoundsToNearestScale(
            final ZoomLevels zoomLevels, final double tolerance,
            final ZoomLevelSnapStrategy zoomLevelSnapStrategy,
            final boolean geodetic,
            final Rectangle paintArea,
            final double dpi); @Override Scale getScale(final Rectangle paintArea, final double dpi); @Override MapBounds adjustBoundsToRotation(final double rotation); @Override MapBounds zoomOut(final double factor); @Override MapBounds zoomToScale(final Scale scale); @Override Coordinate getCenter(); MapBounds expand(final int margin, final Rectangle paintArea); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); }
BBoxMapBounds extends MapBounds { @Override public MapBounds adjustedEnvelope(final Rectangle paintArea) { final double paintAreaAspectRatio = paintArea.getWidth() / paintArea.getHeight(); final double bboxAspectRatio = this.bbox.getWidth() / this.bbox.getHeight(); if (paintAreaAspectRatio > bboxAspectRatio) { double centerX = (this.bbox.getMinX() + this.bbox.getMaxX()) / 2; double factor = paintAreaAspectRatio / bboxAspectRatio; double finalDiff = (this.bbox.getMaxX() - centerX) * factor; return new BBoxMapBounds(getProjection(), centerX - finalDiff, this.bbox.getMinY(), centerX + finalDiff, this.bbox.getMaxY()); } else { double centerY = (this.bbox.getMinY() + this.bbox.getMaxY()) / 2; double factor = bboxAspectRatio / paintAreaAspectRatio; double finalDiff = (this.bbox.getMaxY() - centerY) * factor; return new BBoxMapBounds(getProjection(), this.bbox.getMinX(), centerY - finalDiff, this.bbox.getMaxX(), centerY + finalDiff); } } BBoxMapBounds(final CoordinateReferenceSystem projection, final Envelope envelope);  BBoxMapBounds(
            final CoordinateReferenceSystem projection, final double minX, final double minY,
            final double maxX, final double maxY);  BBoxMapBounds(final ReferencedEnvelope bbox); @Override ReferencedEnvelope toReferencedEnvelope(final Rectangle paintArea); @Override MapBounds adjustedEnvelope(final Rectangle paintArea); @Override MapBounds adjustBoundsToNearestScale(
            final ZoomLevels zoomLevels, final double tolerance,
            final ZoomLevelSnapStrategy zoomLevelSnapStrategy,
            final boolean geodetic,
            final Rectangle paintArea,
            final double dpi); @Override Scale getScale(final Rectangle paintArea, final double dpi); @Override MapBounds adjustBoundsToRotation(final double rotation); @Override MapBounds zoomOut(final double factor); @Override MapBounds zoomToScale(final Scale scale); @Override Coordinate getCenter(); MapBounds expand(final int margin, final Rectangle paintArea); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }