When I add osm service in a mapContent
mapContent.addLayer(new AsyncTileLayer(new OSMService("Mapnik", "http://tile.openstreetmap.org/")));
Then when I use the paint method of StreamingRenderer class, there is an infinite run. More precisely the infinite run occurs in the line 563 of the StreamingRenderer class file with :
painterFuture.get();
I call paint method to paint what I add to the mapContent, i.e. here the featureLayer and the osm map.
MapContent mapContent = new MapContent();
mapContent.addLayer(new AsyncTileLayer(new OSMService("Mapnik", "http://tile.openstreetmap.org/")));
CoordinateReferenceSystem crs = CRS.decode("EPSG:4326", true);
ReferencedEnvelope envelope = new ReferencedEnvelope(566516.1128181651, 571832.3519307065, 5275726.889218023, 5281104.067690026, crs);
mapContent.getViewport().setBounds(envelope);
GTRenderer renderer = new StreamingRenderer();
renderer.setMapContent(mapContent);
Rectangle imageBounds;
ReferencedEnvelope mapBounds;
try {
mapBounds = mapContent.getMaxBounds();
double heightToWidth = mapBounds.getSpan(1) / mapBounds.getSpan(0);
imageBounds = new Rectangle(5, 5, 1000, (int) Math.round(1000 * heightToWidth));
} catch (Exception e) {
throw new RuntimeException(e);
}
BufferedImage mapBufferedImage = new BufferedImage(imageBounds.width, imageBounds.height, BufferedImage.TYPE_INT_ARGB);
Graphics2D gr = mapBufferedImage.createGraphics();
renderer.paint(gr, imageBounds, mapBounds);
Here is the content of the painterFuture object : state = 0, callable = java.util.concurrent.Executors$RunnableAdapter@3533df16[Wrapped task = org.geotools.renderer.lite.StreamingRenderer$PainterThread@15d0849], outcome = null, runner = "Thread[pool-1-thread-1,5,main]", waiters = null
When there is just the featureLayer and not the osm service, the painterFuture object is marked as Completed normally and contains : state = 2, callable = null, outcome = null, runner = null, waiters = null.
With this following code I get an image but that doesn't seems to be the good projection.
ReferencedEnvelope re = layer.getBounds();
mapContent.addLayer(new AsyncTileLayer(new OSMService("Mapnik", "http://tile.openstreetmap.org/")));
CoordinateReferenceSystem source = CRS.decode("EPSG:25832");
CoordinateReferenceSystem target = CRS.decode("EPSG:4326");
MathTransform transform = CRS.findMathTransform(source, target, true);
Envelope targetGeometry = JTS.transform(re, transform);
ReferencedEnvelope envelope = new ReferencedEnvelope(targetGeometry, target);
mapContent.getViewport().setBounds(envelope);