Hi,
I want to write a map created by Geotools to a SVG image using Apache Batik, as
suggested here
http://docs.geotools.org/latest/userguide.old/library/render/gtrenderer.html#svg
and here
http://xmlgraphics.apache.org/batik/using/svg-generator.html
I set both the dependencies for gt-svg and the batik library.
Unfortunately, the renderer freezes when calling renderer.paint(svgGenerator,
imageBounds, mapBounds); see code below.
When I step into the method, an exception is thrown at
java.util.concurrent.FutureTask:innerRunandReset()
after labelCache.end(graphics, paintArea); is called at StreamingRenderer:854
and the thread freezes at java.util.concurrent.ThreadPoolExecutor:1130.
Does anyone know why this happens, and does anyone know a solution for this?
(I'm using gt 9.4)
I really need this feature...
Cheers, Philipp
PS: Here's my code:
protected synchronized void saveSVG(String fileName) throws
InterruptedException{
writingSVG = true;
System.out.println("Rendering image...");
GTRenderer renderer = new StreamingRenderer();
MapContent map = mapFrame.getMapContent();
renderer.setMapContent(map);
Rectangle imageBounds = null;
ReferencedEnvelope mapBounds = null;
try {
mapBounds = mapFrame.getMapPane().getDisplayArea();
double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0);
imageBounds = new Rectangle(
0, 0, width, (int) Math.round(width * heightToWidth));
} catch (Exception e) {
// failed to access map layers
e.printStackTrace();
throw new RuntimeException(e);
}
// Get a DOMImplementation.
DOMImplementation domImpl =
GenericDOMImplementation.getDOMImplementation();
// Create an instance of org.w3c.dom.Document.
String svgNS = "http://www.w3.org/2000/svg";
Document document = domImpl.createDocument(svgNS, "svg", null);
// Create an instance of the SVG Generator.
SVGGeneratorContext svggencon =
SVGGeneratorContext.createDefault(document);
SVGGraphics2D svgGenerator = new SVGGraphics2D(svggencon, true);
svggencon.setComment("Generated by GeoTools2 with Batik SVG Generator");
svgGenerator.setPaint(Color.WHITE);
svgGenerator.fill(imageBounds);
try {
renderer.paint(svgGenerator, imageBounds, mapBounds);
System.out.println("Writing " + fileName + "...");
File fileToSave = new File(fileName);
fileToSave.mkdirs();
// Finally, stream out SVG to the standard output using
// UTF-8 encoding.
boolean useCSS = true; // we want to use CSS style attributes
FileWriter out = new FileWriter(fileToSave);
svgGenerator.stream(out, useCSS);
System.out.println("...done!");
writingSVG = false;
notifyAll();
} catch (IOException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
------------------------------------------------------------------------------
Android is increasing in popularity, but the open development platform that
developers love is also attractive to malware creators. Download this white
paper to learn more about secure code signing practices that can help keep
Android apps secure.
http://pubads.g.doubleclick.net/gampad/clk?id=65839951&iu=/4140/ostg.clktrk
_______________________________________________
GeoTools-GT2-Users mailing list
GeoTools-GT2-Users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-gt2-users