I would like to store map created in JXMapKit in BufferedImage, but without creating GUI.
I tried following code, but, althought I get image with correct size, tiles are with clock symbol. That means that tiles form OSM server aren't ready. So I guess I should wait for them before I copy image to BufferedImage. However this approach hasn't succeeded.
JXMapKit jXMapKit = new org.jxmapviewer.JXMapKit();
OSMTileFactoryInfo info = new OSMTileFactoryInfo();
DefaultTileFactory tileFactory = new DefaultTileFactory(info);
jXMapKit.setTileFactory(tileFactory);
tileFactory.setThreadPoolSize(8);
jXMapKit.setSize(new Dimension(1024, 800));
jXMapKit.setZoom(7);
jXMapKit.setAddressLocation(newGeoPosition(cm.getCoordinateY(),cm.getCoordinateX()));
layoutComponent(jXMapKit);
int pt;
do {
pt = tileFactory.getPendingTiles();
System.out.println(pt);
} while (pt>0);
BufferedImage bi = new BufferedImage(jXMapKit.getWidth(), jXMapKit.getHeight(), BufferedImage.TYPE_INT_RGB);
jXMapKit.paint(bi.getGraphics());
File outputfile = new File("c:/img.jpg");
try {
ImageIO.write(bi, "jpg", outputfile);
} catch (IOException ex) {
//
}
// from the example of user489041
public static void layoutComponent(Component c) {
synchronized (c.getTreeLock()) {
c.doLayout();
if (c instanceof Container)
for (Component child : ((Container) c).getComponents())
layoutComponent(child);
}
}