public void fit() throws Exception { MapContent generalMapContext = getGeneralMapContext(); Dimension size = getSize(); Envelope projectedBounds = generalMapContext.getMaxBounds(); double destWidth = projectedBounds.getWidth(); double destHeight = projectedBounds.getHeight(); Coordinate centre = projectedBounds.centre(); Point2D.Double screenLT = awtScreen2Cartesian(new Point(0, 0)); Point2D.Double screenBR = awtScreen2Cartesian(new Point(size.width, size.height)); double srcWidth = screenBR.x - screenLT.x; double srcHeight = screenBR.y - screenLT.y; double sx = srcWidth / destWidth; double sy = srcHeight / destHeight; double coef = Math.min(sx, sy); coef = snapScale(coef); scaleView(coef, coef, false); Point2D.Double projectedScreenCenter = screen2Cartesian(new Point(0, 0)); translateView(projectedScreenCenter.x - centre.x, projectedScreenCenter.y - centre.y, true); repaint(); }