use of org.geotools.renderer.lite.NoThreadStreamingRenderer in project polymap4-core by Polymap4.
the class FeatureRenderProcessor2 method getMapRequest.
@Override
public void getMapRequest(GetMapRequest request, ProcessorContext context) throws Exception {
long start = System.currentTimeMillis();
// result
BufferedImage result = new BufferedImage(request.getWidth(), request.getHeight(), TYPE_4BYTE_ABGR);
result.setAccelerationPriority(1);
final Graphics2D g = result.createGraphics();
// log.info( "IMAGE: accelerated=" + result.getCapabilities( g.getDeviceConfiguration() ).isAccelerated() );
MapContent mapContent = new MapContent();
try {
// MapContent
mapContent.getViewport().setCoordinateReferenceSystem(request.getBoundingBox().getCoordinateReferenceSystem());
mapContent.addLayer(new FeatureLayer(fs.get(), style.get()));
StreamingRenderer renderer = new NoThreadStreamingRenderer();
// error handler
renderer.addRenderListener(new RenderListener() {
@Override
public void featureRenderer(SimpleFeature feature) {
}
@Override
public void errorOccurred(Exception e) {
if (e.getMessage() == null || e.getMessage().contains("Error transforming bbox") || e.getMessage().contains("too close to a pole")) {
log.warn("Renderer: " + e.getMessage());
} else {
log.error("Renderer error: ", e);
drawErrorMsg(g, "Unable to render.", e);
}
}
});
// rendering hints
RenderingHints hints = new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
hints.add(new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON));
hints.add(new RenderingHints(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON));
hints.add(new RenderingHints(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON));
// hints.add( new RenderingHints(
// RenderingHints.KEY_TEXT_ANTIALIASING,
// RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB ) );
// geoserver compatibility to support *env* in SLD functions
double scale = RendererUtilities.calculateOGCScale(request.getBoundingBox(), request.getWidth(), Collections.EMPTY_MAP);
EnvFunction.setLocalValue("wms_scale_denominator", scale);
renderer.setJava2DHints(hints);
g.setRenderingHints(hints);
// render params
Map rendererParams = new HashMap();
rendererParams.put("optimizedDataLoadingEnabled", Boolean.TRUE);
renderer.setRendererHints(rendererParams);
renderer.setMapContent(mapContent);
Rectangle paintArea = new Rectangle(request.getWidth(), request.getHeight());
renderer.paint(g, paintArea, request.getBoundingBox());
} catch (Throwable e) {
log.error("Renderer error: ", e);
drawErrorMsg(g, "Unable to render.", e);
} finally {
mapContent.dispose();
EnvFunction.clearLocalValues();
if (g != null) {
g.dispose();
}
}
log.debug(" ...done: (" + (System.currentTimeMillis() - start) + "ms).");
context.sendResponse(new ImageResponse(result));
}
Aggregations