checkNotNull(metaTileMap, "webMap is not set");
if (!(metaTileMap instanceof RenderedImageMap)) {
throw new IllegalArgumentException("Only RenderedImageMaps are supported so far: "
+ metaTileMap.getClass().getName());
}
final RenderedImageMapResponse mapEncoder;
{
final GWC mediator = GWC.get();
final Response responseEncoder = mediator.getResponseEncoder(responseFormat,
metaTileMap);
mapEncoder = (RenderedImageMapResponse) responseEncoder;
}
RenderedImage tile = metaTileMap.getImage();
WMSMapContent tileContext = metaTileMap.getMapContext();
if (this.tiles.length > 1 || (this.tiles.length == 1 && metaHasGutter())) {
final Rectangle tileDim = this.tiles[tileIdx];
tile = createTile(tileDim.x, tileDim.y, tileDim.width, tileDim.height);
disposeLater(tile);
{
final WMSMapContent metaTileContext = metaTileMap.getMapContext();
// do not create tileContext with metaTileContext.getLayers() as the layer list.
// It is not needed at this stage and the constructor would force a
// MapLayer.getBounds() that might fail
tileContext = new WMSMapContent();
tileContext.setRequest(metaTileContext.getRequest());
tileContext.setBgColor(metaTileContext.getBgColor());
tileContext.setMapWidth(tileDim.width);
tileContext.setMapHeight(tileDim.height);
tileContext.setPalette(metaTileContext.getPalette());
tileContext.setTransparent(tileContext.isTransparent());
long[][] tileIndexes = getTilesGridPositions();
BoundingBox tileBounds = gridSubset.boundsFromIndex(tileIndexes[tileIdx]);
ReferencedEnvelope tilebbox = new ReferencedEnvelope(
metaTileContext.getCoordinateReferenceSystem());
tilebbox.init(tileBounds.getMinX(), tileBounds.getMaxX(), tileBounds.getMinY(),
tileBounds.getMaxY());
tileContext.getViewport().setBounds(tilebbox);
}
}
OutputStream outStream = target.getOutputStream();
try {
// call formatImageOuputStream instead of write to avoid disposition of rendered images
// when processing a tile from a metatile and instead defer it to this class' dispose()
// method
mapEncoder.formatImageOutputStream(tile, outStream, tileContext);
return true;
} finally {
outStream.close();
}
}