GC gc = g.getGraphics(GC.class);
if (gc != null ) {
// SWT, draw all the tiles
Set<ReferencedEnvelope> keySet = tiles.keySet();
for (ReferencedEnvelope env : keySet) {
Tile tile = tiles.get(env);
//System.out.println("SWTImage: "+tile.getSWTImage());
ViewportModel viewportModelInternal = tile.getRenderExecutor().getRenderer().getContext().getViewportModelInternal();
java.awt.Point a = viewportModelInternal.worldToPixel(new Coordinate(env.getMinX(), env.getMinY()));
java.awt.Point b = viewportModelInternal.worldToPixel(new Coordinate(env.getMaxX(), env.getMaxY()));
int width = b.x - a.x;
int height = a.y - b.y;
synchronized (tile) {
//an exception can be thrown here if the image has been disposed of
//since it was retrieved or something else bad happens while drawing
//this is OK in our case because another paint event should be coming soon
//which will fix the issue; so for now we just catch the errors
//and don't worry about them.
try{
org.eclipse.swt.graphics.Image im = tile.getSWTImage();
gc.drawImage(im, 0, 0, im.getBounds().width, im.getBounds().height, a.x, b.y, width, height);
}catch (Exception ex){
}
}
if( TESTING ){
g.setColor(Color.BLUE);
g.drawLine(a.x, a.y, a.x, b.y);
g.drawLine(a.x, b.y, b.x, b.y);
g.drawLine(b.x, b.y, b.x, a.y);
g.drawLine(b.x, a.y, a.x, a.y);
}
}
}
else {
// AWT, draw all the tiles
Set<ReferencedEnvelope> keySet = tiles.keySet();
for (ReferencedEnvelope env : keySet) {
Tile tile = tiles.get(env);
//System.out.println("BufferedImage: "+tile.getBufferedImage());
ViewportModel viewportModelInternal = tile.getRenderExecutor().getRenderer().getContext().getViewportModelInternal();
java.awt.Point a = viewportModelInternal.worldToPixel(new Coordinate(env.getMinX(), env.getMinY()));
java.awt.Point b = viewportModelInternal.worldToPixel(new Coordinate(env.getMaxX(), env.getMaxY()));
g.drawImage((RenderedImage)tile.getBufferedImage(), a.x, b.y);
g.setColor(Color.BLUE);
g.drawLine(a.x, a.y, a.x, b.y);
g.drawLine(a.x, b.y, b.x, b.y);
g.drawLine(b.x, b.y, b.x, a.y);
g.drawLine(b.x, a.y, a.x, a.y);