offscreenBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_3BYTE_BGR);
}
Graphics2D tempG = offscreenBuffer.createGraphics();
tempG.setClip(g.getClip());
Bounds box = getLatLonBounds(g.getClipBounds());
if (!canUseBuffer || nonChangedLayersBuffer == null) {
if (null == nonChangedLayersBuffer || nonChangedLayersBuffer.getWidth() != getWidth() || nonChangedLayersBuffer.getHeight() != getHeight()) {
nonChangedLayersBuffer = new BufferedImage(getWidth(), getHeight(), BufferedImage.TYPE_3BYTE_BGR);
}
Graphics2D g2 = nonChangedLayersBuffer.createGraphics();
g2.setClip(g.getClip());
g2.setColor(PaintColors.getBackgroundColor());
g2.fillRect(0, 0, getWidth(), getHeight());
for (int i=0; i<nonChangedLayersCount; i++) {
paintLayer(visibleLayers.get(i),g2, box);
}
} else {
// Maybe there were more unchanged layers then last time - draw them to buffer
if (nonChangedLayers.size() != nonChangedLayersCount) {
Graphics2D g2 = nonChangedLayersBuffer.createGraphics();
g2.setClip(g.getClip());
for (int i=nonChangedLayers.size(); i<nonChangedLayersCount; i++) {
paintLayer(visibleLayers.get(i),g2, box);
}
}
}
nonChangedLayers.clear();
changedLayer = null;
for (int i=0; i<nonChangedLayersCount; i++) {
nonChangedLayers.add(visibleLayers.get(i));
}
lastViewID = getViewID();
lastClipBounds = g.getClipBounds();
tempG.drawImage(nonChangedLayersBuffer, 0, 0, null);
for (int i=nonChangedLayersCount; i<visibleLayers.size(); i++) {
paintLayer(visibleLayers.get(i),tempG, box);
}
for (MapViewPaintable mvp : temporaryLayers) {
mvp.paint(tempG, this, box);
}
// draw world borders
tempG.setColor(Color.WHITE);
Bounds b = getProjection().getWorldBoundsLatLon();
double lat = b.getMinLat();
double lon = b.getMinLon();
Point p = getPoint(b.getMin());
GeneralPath path = new GeneralPath();
path.moveTo(p.x, p.y);
double max = b.getMax().lat();
for(; lat <= max; lat += 1.0)
{
p = getPoint(new LatLon(lat >= max ? max : lat, lon));
path.lineTo(p.x, p.y);
}
lat = max; max = b.getMax().lon();
for(; lon <= max; lon += 1.0)
{
p = getPoint(new LatLon(lat, lon >= max ? max : lon));
path.lineTo(p.x, p.y);
}
lon = max; max = b.getMinLat();
for(; lat >= max; lat -= 1.0)
{
p = getPoint(new LatLon(lat <= max ? max : lat, lon));
path.lineTo(p.x, p.y);
}
lat = max; max = b.getMinLon();
for(; lon >= max; lon -= 1.0)
{
p = getPoint(new LatLon(lat, lon <= max ? max : lon));
path.lineTo(p.x, p.y);
}