public Response getResponse (
TileRequest tileRequest,
TimeSurface surfA, TimeSurface surfB,
RenderRequest renderRequest) throws Exception {
Tile tile = tileCache.get(tileRequest);
BufferedImage image;
switch (renderRequest.layer) {
case DIFFERENCE :
image = tile.linearCombination(1, surfA, -1, surfB, 0, renderRequest);
break;
case HAGERSTRAND :
long elapsed = Math.abs(surfB.dateTime - surfA.dateTime);
image = tile.linearCombination(-1, surfA, -1, surfB, elapsed/60, renderRequest);
break;
case TRAVELTIME :
default :
image = tile.generateImage(surfA, renderRequest);
}
// add a timestamp to the image if requested.
// of course this will make it useless as a raster for analysis, but it's good for animations.
if (renderRequest.timestamp) {
DateFormat df = DateFormat.getDateTimeInstance();
df.setTimeZone(TimeZone.getTimeZone("America/New_York"));
String ds = df.format(new Date(surfA.dateTime * 1000));
shadowWrite(image, ds, String.format("%f, %f", surfA.lat, surfA.lon));
Graphics2D g2d = image.createGraphics();
g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC));
BufferedImage legend = Tile.getLegend(renderRequest.style, 300, 50);
g2d.drawImage(legend, 0, image.getHeight()-50, null);
g2d.dispose();
}
// geotiff kludge
if (renderRequest.format.toString().equals("image/geotiff")) {
GridCoverage2D gc = tile.getGridCoverage2D(image);
return generateStreamingGeotiffResponse(gc);
} else {
return generateStreamingImageResponse(image, renderRequest.format);
}
}