Dear Sir/ Madam,
I have a Geotools developed Web application, especially I have a ControllerServlet.java [servlet]
which is responsible for converting the mapContext to Image and bring it on browser., the major part of the code in doing this as given below.,
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
public void renderMap() {
StreamingRenderer streamingRenderer = new StreamingRenderer();
MapHelper mapHelper = MapHelper.getMapHelper(session, getServletConfig().getServletContext());
MapContext mapContext = mapHelper.getMapContext ();
streamingRenderer.setContext(mapContext);
BufferedImage bufferedImage = null;
bufferedImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics2D graphics2D = (Graphics2D)bufferedImage.getGraphics();
graphics2D.setRenderingHints(new RenderingHints(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED));
graphics2D.setColor(Color.WHITE);
graphics2D.fillRect(0, 0, width, height);
RenderingHints hints = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON );
streamingRenderer.setJava2DHints(hints);
Map rendererParams = new HashMap();
rendererParams.put(“optimizedDataLoadingEnabled”,new Boolean(true));
Envelope env = mapHelper.getEnvelope();
streamingRenderer.setRendererHints(rendererParams);
try
{
streamingRenderer.paint(graphics2D, new Rectangle(width, height), mapHelper.setAffineTransform());
} catch(Exception ex) {
ex.printStackTrace();
}
if (graphics2D!=null) graphics2D.dispose();
ServletOutputStream sos = res.getOutputStream();
ImageIO.write(bufferedImage,“jpg”,sos);
sos.close();
}// end rendermap
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
This code is working good, but when two user try to click on the map at the same time, then ImageIO.write, being a static method, throws client abort exception.
In order to really make this more robust, I am think to move to GeoServer., but the question is we cannot invest all time to do so, from scratch.
Is there anyway where can I replace the above method inside my ControllerServlet, and get connected to the Geoserver [wms] request., and which will
give me a image back., then my application can work as it is.,
In the above code, my mapcontext object will get required layers and other operation from MapHelper. [I dont want to touch this class file].
Please let me know how to go about this., waiting for earliest reply.
Thanks
Gov