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); } } } }