@Override public void update(Bbox mapBounds) { // Only update the mapBounds if it's outside the region we already fetched. if (this.mapBounds == null || !BboxService.contains(this.mapBounds, mapBounds)) { this.mapBounds = BboxService.buffer(mapBounds, mapBounds.getWidth() / 2); fetch = true; } else { fetch = false; } } }
Bbox clippedBounds = BboxService.intersection(bounds, layerBounds); if (clippedBounds == null) {
public Bbox getBounds() { if (bounds == null && !features.isEmpty()) { for (Feature feature : features) { org.geomajas.geometry.Geometry geom = feature.getGeometry(); if (geom != null) { Bbox b = GeometryService.getBounds(geom); if (bounds == null) { bounds = b; } else { bounds = BboxService.union(bounds, b); } } } } return bounds; }
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)); } }
double w = mapWidth * newResolution / 2; double h = mapHeight * newResolution / 2; Coordinate minCoordinate = BboxService.getOrigin(maxBounds); Coordinate maxCoordinate = BboxService.getEndPoint(maxBounds); xCenter = BboxService.getCenterPoint(maxBounds).getX(); } else { if ((xCenter - w) < minCoordinate.getX()) { yCenter = BboxService.getCenterPoint(maxBounds).getY(); } else { if ((yCenter - h) < minCoordinate.getY()) {
private Bbox screenToWorld(Bbox bbox) { if (bbox != null) { Coordinate c1 = screenToWorld(BboxService.getOrigin(bbox)); Coordinate c2 = screenToWorld(BboxService.getEndPoint(bbox)); double x = (c1.getX() < c2.getX()) ? c1.getX() : c2.getX(); double y = (c1.getY() < c2.getY()) ? c1.getY() : c2.getY(); return new Bbox(x, y, Math.abs(c1.getX() - c2.getX()), Math.abs(c1.getY() - c2.getY())); } return null; } }
@Override public void render(final Bbox bounds) { if (rasterLayer.isShowing()) { // First we check whether or not the requested bounds is already rendered: if (currentTileBounds != null && BboxService.contains(currentTileBounds, bounds)) { onScaleRendered(container, scale); return; // Bounds already rendered, nothing to do here. } // Scale the bounds to fetch tiles for (we want a bigger area than the map bounds): currentTileBounds = BboxService.scale(bounds, mapExtentScaleAtFetch); // Create the command: GetRasterTilesRequest request = new GetRasterTilesRequest(); request.setBbox(new org.geomajas.geometry.Bbox(currentTileBounds.getX(), currentTileBounds.getY(), currentTileBounds.getWidth(), currentTileBounds.getHeight())); request.setCrs(crs); request.setLayerId(rasterLayer.getServerLayerId()); request.setScale(scale); GwtCommand command = new GwtCommand(GetRasterTilesRequest.COMMAND); command.setCommandRequest(request); // Execute the fetch, and render on success: deferred = commandService.execute(command, new AbstractCommandCallback<GetRasterTilesResponse>() { public void execute(GetRasterTilesResponse response) { addTiles(response.getRasterData()); } }); } }
@Override public void setTranslation(double deltaX, double deltaY) { matrix = new Matrix(matrix.getXx(), 0.0, 0.0, matrix.getYy(), deltaX, deltaY); updateTransform(); if (!BboxService.contains(bufferBounds, canvasBounds)) { repaintBuffer(); } copyBufferToCanvas(); }
@Override public void initialize(ClientMapInfo mapInfo, MapEventBus eventBus) { this.mapInfo = mapInfo; this.eventBus = eventBus; crs = mapInfo.getCrs(); // Calculate maximum bounds: maxBounds = new Bbox(mapInfo.getMaxBounds().getX(), mapInfo.getMaxBounds().getY(), mapInfo.getMaxBounds() .getWidth(), mapInfo.getMaxBounds().getHeight()); // if the max bounds was not configured, take the union of initial and layer bounds if (BboxService.equals(maxBounds, Bbox.ALL, 1e-10)) { maxBounds = new Bbox(mapInfo.getInitialBounds().getX(), mapInfo.getInitialBounds().getY(), mapInfo .getInitialBounds().getWidth(), mapInfo.getInitialBounds().getHeight()); if (mapInfo.getLayers() != null && mapInfo.getLayers().size() > 0) { for (ClientLayerInfo layerInfo : mapInfo.getLayers()) { if (layerInfo.getMaxExtent() != null) { maxBounds = BboxService.union(maxBounds, layerInfo.getMaxExtent()); } } } } // Set the best zoom strategy given the map info: if (mapInfo.getScaleConfiguration().getZoomLevels() != null && mapInfo.getScaleConfiguration().getZoomLevels().size() > 0) { zoomStrategy = new FixedStepZoomStrategy(mapInfo, maxBounds); } else { zoomStrategy = new FreeForAllZoomStrategy(mapInfo, maxBounds); } zoomStrategy.setMapSize(mapWidth, mapHeight); initialized = true; }
@Override public View asView(Bbox bounds, ZoomOption zoomOption) { double tempResolution = getResolutionForBounds(bounds, zoomOption); Coordinate tempPosition = checkPosition(BboxService.getCenterPoint(bounds), tempResolution); return new View(tempPosition, tempResolution); }
@Override public List<RasterTile> getTiles(Bbox worldBounds) { List<RasterTile> result = new ArrayList<RasterTile>(); for (RasterTile rasterTile : tiles.values()) { Bbox screenBounds = getScreenBounds(worldBounds); if (BboxService.intersects(screenBounds, rasterTile.getBounds())) { result.add(rasterTile); } } return result; }
protected Bbox asBounds(View view) { double deltaScale = view.getResolution() / resolution; Bbox bounds = viewPort.asBounds(view); return BboxService.scale(bounds, deltaScale); }
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)); } } } }
double w = mapWidth / (newScale * 2); double h = mapHeight / (newScale * 2); Coordinate minCoordinate = BboxService.getOrigin(maxBounds); Coordinate maxCoordinate = BboxService.getEndPoint(maxBounds); xCenter = BboxService.getCenterPoint(maxBounds).getX(); } else { if ((xCenter - w) < minCoordinate.getX()) { yCenter = BboxService.getCenterPoint(maxBounds).getY(); } else { if ((yCenter - h) < minCoordinate.getY()) {
private Bbox screenToWorld(Bbox bbox) { if (bbox != null) { Coordinate c1 = screenToWorld(BboxService.getOrigin(bbox)); Coordinate c2 = screenToWorld(BboxService.getEndPoint(bbox)); double x = (c1.getX() < c2.getX()) ? c1.getX() : c2.getX(); double y = (c1.getY() < c2.getY()) ? c1.getY() : c2.getY(); return new Bbox(x, y, Math.abs(c1.getX() - c2.getX()), Math.abs(c1.getY() - c2.getY())); } return null; } }
@Override public void setTranslation(double deltaX, double deltaY) { matrix = new Matrix(matrix.getXx(), 0.0, 0.0, matrix.getYy(), deltaX, deltaY); updateTransform(); if (!BboxService.contains(bufferBounds, canvasBounds)) { repaintBuffer(); } copyBufferToCanvas(); }
@Override public void applyBounds(Bbox bounds, ZoomOption zoomOption) { double tempResolution = getResolutionForBounds(bounds, zoomOption); Coordinate tempPosition = checkPosition(BboxService.getCenterPoint(bounds), tempResolution); View copy = copy(view, tempPosition, tempResolution); applyViewNoChecks(copy); }
@Override public void render(Bbox bbox) { // Only fetch when inside the layer bounds: if (BboxService.intersects(bbox, layerBounds) && vectorLayer.isShowing()) { // Find needed tile codes: List<TileCode> tempCodes = calcCodesForBounds(bbox); for (TileCode tileCode : tempCodes) { VectorTilePresenter tilePresenter = tiles.get(tileCode.toString()); if (tilePresenter == null) { // New tile tilePresenter = addTile(tileCode); tilePresenter.render(); } else if (tilePresenter.getSiblingStatus() == VectorTilePresenter.STATUS.EMPTY) { // Tile already exists, but the siblings have not yet been loaded: tilePresenter.renderSiblings(); } } } }
private Bbox worldToScreen(Bbox bbox) { if (bbox != null) { Coordinate c1 = worldToScreen(BboxService.getOrigin(bbox)); Coordinate c2 = worldToScreen(BboxService.getEndPoint(bbox)); double x = (c1.getX() < c2.getX()) ? c1.getX() : c2.getX(); double y = (c1.getY() < c2.getY()) ? c1.getY() : c2.getY(); return new Bbox(x, y, Math.abs(c1.getX() - c2.getX()), Math.abs(c1.getY() - c2.getY())); } return null; }
protected Bbox calcBounds() { Bbox result = calcBounds(coordinates); for (SubPath s : subPaths) { result = BboxService.union(result, calcBounds(s.getCoordinates())); } return result; }