private void applyResolution(double newResolution, Coordinate rescalePoint, ZoomOption zoomOption) { double validResolution = checkResolution(newResolution, zoomOption); if (validResolution != getResolution()) { // Calculate theoretical new bounds. First create a BBOX of correct size: Bbox newBbox = new Bbox(0, 0, getMapWidth() * validResolution, getMapHeight() * validResolution); // Calculate translate vector to assure rescalePoint is on the same position as before. double factor = getResolution() / validResolution; double dX = (rescalePoint.getX() - getPosition().getX()) * (1 - 1 / factor); double dY = (rescalePoint.getY() - getPosition().getY()) * (1 - 1 / factor); // Apply translation to set the BBOX on the correct location: newBbox = BboxService.setCenterPoint(newBbox, getPosition()); newBbox = BboxService.translate(newBbox, dX, dY); // Now apply on this view port: Coordinate tempPosition = checkPosition(BboxService.getCenterPoint(newBbox), validResolution); applyViewNoChecks(new View(tempPosition, validResolution)); } }
private void applyScale(double newScale, Coordinate rescalePoint, boolean dragging) { double limitedScale = zoomStrategy.checkScale(newScale, ZoomOption.LEVEL_CLOSEST); if (limitedScale != scale) { // Calculate theoretical new bounds. First create a BBOX of correct size: Bbox newBbox = new Bbox(0, 0, getMapWidth() / limitedScale, getMapHeight() / limitedScale); // Calculate translate vector to assure rescalePoint is on the same position as before. double factor = limitedScale / scale; double dX = (rescalePoint.getX() - position.getX()) * (1 - 1 / factor); double dY = (rescalePoint.getY() - position.getY()) * (1 - 1 / factor); // Apply translation to set the BBOX on the correct location: newBbox = BboxService.setCenterPoint(newBbox, new Coordinate(position.getX(), position.getY())); newBbox = BboxService.translate(newBbox, dX, dY); // Now apply on this view port: scale = limitedScale; position = checkPosition(BboxService.getCenterPoint(newBbox), scale); if (eventBus != null) { if (dX == 0 && dY == 0) { eventBus.fireEvent(dragging ? new ViewPortScalingEvent(this) : new ViewPortScaledEvent(this)); } else { eventBus.fireEvent(dragging ? new ViewPortChangingEvent(this) : new ViewPortChangedEvent(this)); } } } }