if (future.isDone()) {
try {
ImageResult result;
result = future.get();
// create a rendered image
RenderedImage image = JAI.create("stream", new ByteArraySeekableStream(result
.getImage()));
// convert to common direct colormodel (some images have their own indexed color model)
RenderedImage colored = toDirectColorModel(image);
// translate to the correct position in the tile grid
double xOffset = result.getRasterImage().getCode().getX() * imageWidth
- pixelBounds.getX();
double yOffset = 0;
// TODO: in some cases, the y-index is up (e.g. WMS), should be down for
// all layers !!!!
if (isYIndexUp(tiles)) {
yOffset = result.getRasterImage().getCode().getY() * imageHeight
- pixelBounds.getY();
} else {
yOffset = (float) (pixelBounds.getMaxY() - (result.getRasterImage().getCode()
.getY() + 1)
* imageHeight);
}
log.debug("adding to(" + xOffset + "," + yOffset + "), url = "
+ result.getRasterImage().getUrl());
RenderedImage translated = TranslateDescriptor.create(colored, (float) xOffset,
(float) yOffset, new InterpolationNearest(), null);
images.add(translated);
} catch (ExecutionException e) {
addLoadError(context, (ImageException) (e.getCause()));
} catch (InterruptedException e) {