@Override public void accept(PainterVisitor visitor, Object group, Bbox bounds, boolean recursive) { if (googleMap != null) { String sourceCrs = map.getMapModel().getCrs(); if (isGoogleProjection(sourceCrs)) { int zoomLevel = calcZoomLevel(map.getMapModel().getMapView().getCurrentScale()); Coordinate latLon = convertToLatLon(bounds.getCenterPoint()); fitGoogleMapBounds(googleMap, latLon, zoomLevel); } else { // transform on server TransformGeometryRequest request = new TransformGeometryRequest(); request.setBounds( new org.geomajas.geometry.Bbox( bounds.getX(), bounds.getY(), bounds.getWidth(), bounds.getHeight())); request.setSourceCrs(map.getMapModel().getCrs()); request.setTargetCrs(EPSG_3857); GwtCommand command = new GwtCommand(TransformGeometryRequest.COMMAND); command.setCommandRequest(request); GwtCommandDispatcher.getInstance() .execute( command, new AbstractCommandCallback<TransformGeometryResponse>() { public void execute(TransformGeometryResponse response) { Bbox google = new Bbox(response.getBounds()); int zoomLevel = calcZoomLevelFromBounds(google); fitGoogleMapBounds( googleMap, convertToLatLon(google.getCenterPoint()), zoomLevel); } }); } } }
/** Method based on WmsTileServiceImpl in GWT2 client. */ private List<org.geomajas.layer.tile.RasterTile> calculateTilesForBounds(Bbox bounds) { List<org.geomajas.layer.tile.RasterTile> tiles = new ArrayList<org.geomajas.layer.tile.RasterTile>(); if (bounds.getHeight() == 0 || bounds.getWidth() == 0) { return tiles; } return tiles; }
private void addTiles(List<org.geomajas.layer.tile.RasterTile> images) { Matrix t = rasterLayer.getMapModel().getMapView().getWorldToPanTranslation(); Bbox cacheBounds = null; // flag and reference tile to realign the grid when new tiles come in (transformation shift!) boolean newTiles = false; RasterTile referenceTile = null; for (org.geomajas.layer.tile.RasterTile image : images) { TileCode code = image.getCode().clone(); if (!tiles.containsKey(code)) { Bbox panBounds = new Bbox(image.getBounds()); panBounds.translate(Math.round(t.getDx()), Math.round(t.getDy())); if (cacheBounds == null) { cacheBounds = panBounds; } else { cacheBounds = cacheBounds.union(panBounds); } RasterTile tile = new RasterTile(code, panBounds, image.getUrl(), this); tiles.put(code, tile); newTiles = true; referenceTile = tile; } } // This realigns the grid of tiles based on their code if (newTiles) { for (RasterTile tile : tiles.values()) { if (!tile.getCode().equals(referenceTile.getCode())) { Bbox aligned = new Bbox(referenceTile.getBounds()); aligned.setX( referenceTile.getBounds().getX() + (tile.getCode().getX() - referenceTile.getCode().getX()) * aligned.getWidth()); if (tile.getCode().getY() != referenceTile.getCode().getY()) { aligned.setY( referenceTile.getBounds().getY() + getOrientedJDiff(referenceTile, tile) * aligned.getHeight()); } tile.setBounds(aligned); } } } }
private int calcZoomLevelFromBounds(Bbox google) { return calcZoomLevel(map.getWidth() / google.getWidth()); }