mc.getViewport().setBounds(new ReferencedEnvelope(targetModelSpace, getMap.getCrs()));
mc.setMapWidth(paintAreaSize);
mc.setMapHeight(paintAreaSize);
// and now run the rendering _almost_ like a GetMap
RenderedImageMapOutputFormat rim = new RenderedImageMapOutputFormat(wms) {
private Graphics2D graphics;
@Override
protected RenderedImage prepareImage(int width, int height, IndexColorModel palette,
boolean transparent) {
return image;
}
@Override
protected Graphics2D getGraphics(boolean transparent, Color bgColor,
RenderedImage preparedImage, Map<Key, Object> hintsMap) {
graphics = super.getGraphics(transparent, bgColor, preparedImage,
hintsMap);
return graphics;
}
@Override
protected void onBeforeRender(StreamingRenderer renderer) {
// force the renderer into serial painting mode, as we need to check what
// was painted to decide which features to include in the results
Map hints = renderer.getRendererHints();
hints.put(StreamingRenderer.OPTIMIZE_FTS_RENDERING_KEY, Boolean.FALSE);
// disable antialiasing to speed up rendering
hints.put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
// TODO: should we disable the screenmap as well?
featureInfoListener.setGraphics(graphics);
featureInfoListener.setRenderer(renderer);
renderer.addRenderListener(featureInfoListener);
}
};
rim.produceMap(mc);
List<SimpleFeature> features = featureInfoListener.getFeatures();
return aggregateByFeatureType(features);
} finally {
mc.dispose();