26 |
import java.util.Map; |
import java.util.Map; |
27 |
import java.util.Vector; |
import java.util.Vector; |
28 |
|
|
29 |
import javax.jws.soap.SOAPBinding.Style; |
import javax.swing.JList; |
30 |
import javax.swing.Timer; |
import javax.swing.Timer; |
31 |
|
import javax.swing.border.Border; |
32 |
|
|
33 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
34 |
|
import org.geotools.factory.GeoTools; |
35 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
36 |
|
import org.geotools.geometry.DirectPosition2D; |
37 |
import org.geotools.geometry.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
38 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
39 |
import org.geotools.map.DefaultMapContext; |
import org.geotools.map.DefaultMapContext; |
99 |
*/ |
*/ |
100 |
public class XMapPane extends JPanel { |
public class XMapPane extends JPanel { |
101 |
|
|
102 |
private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
// private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
103 |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB; |
// private static final int IMAGETYPE_withAlpha = |
104 |
|
// BufferedImage.TYPE_INT_ARGB; |
105 |
|
private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR; |
106 |
|
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR; |
107 |
|
|
108 |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
109 |
|
|
222 |
* |
* |
223 |
* @see #addGadgets(Graphics2D, boolean) |
* @see #addGadgets(Graphics2D, boolean) |
224 |
*/ |
*/ |
225 |
final static Font waitFont = new Font("Arial", Font.BOLD, 30); |
final static Font waitFont = new Font("Arial", Font.BOLD, 28); |
226 |
|
|
227 |
/** |
/** |
228 |
* {@link Font} used to paint error messages into the map |
* {@link Font} used to paint error messages into the map |
232 |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
233 |
|
|
234 |
/** |
/** |
235 |
|
* If last average last two renderings took more than that many ms, show the |
236 |
|
* user a scaled preview |
237 |
|
**/ |
238 |
|
private static final long PRESCALE_MINTIME = 230; |
239 |
|
|
240 |
|
/** |
241 |
* The wait message painted into the map while rendering is going on on |
* The wait message painted into the map while rendering is going on on |
242 |
* another thread. |
* another thread. |
243 |
* |
* |
252 |
* @param e |
* @param e |
253 |
* Maus-Ereignis |
* Maus-Ereignis |
254 |
*/ |
*/ |
255 |
public static Point2D getMapCoordinatesFromEvent(final MouseEvent e) { |
public static DirectPosition2D getMapCoordinatesFromEvent(final MouseEvent e) { |
256 |
// aktuelle Geo-Position aus GeoMouseEvent ermitteln |
// aktuelle Geo-Position aus GeoMouseEvent ermitteln |
257 |
if (e != null && e instanceof MapMouseEvent) |
if (e != null && e instanceof MapMouseEvent) |
258 |
try { |
try { |
259 |
return ((MapMouseEvent) e).getMapPosition().toPoint2D(); |
return ((MapMouseEvent) e).getMapPosition(); |
260 |
} catch (final Exception err) { |
} catch (final Exception err) { |
261 |
LOGGER |
LOGGER |
262 |
.error( |
.error( |
273 |
return null; |
return null; |
274 |
|
|
275 |
final AffineTransform at = xMapPane.getScreenToWorld(); |
final AffineTransform at = xMapPane.getScreenToWorld(); |
276 |
if (at != null) |
if (at != null) { |
277 |
return at.transform(e.getPoint(), null); |
Point2D transformed = at.transform(e.getPoint(), null); |
278 |
|
return new DirectPosition2D(xMapPane.getMapContext() |
279 |
|
.getCoordinateReferenceSystem(), transformed.getX(), |
280 |
|
transformed.getY()); |
281 |
|
} |
282 |
return null; |
return null; |
283 |
} |
} |
284 |
throw new IllegalArgumentException( |
throw new IllegalArgumentException( |
293 |
|
|
294 |
@Override |
@Override |
295 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
296 |
MapLayer layer = event.getLayer(); |
final MapLayer layer = event.getLayer(); |
297 |
layer.addMapLayerListener(bgMapLayerListener); |
layer.addMapLayerListener(bgMapLayerListener); |
298 |
requestStartRendering(); |
requestStartRendering(); |
299 |
|
|
419 |
|
|
420 |
@Override |
@Override |
421 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
422 |
// localRenderer = GTUtil.createGTRenderer(); |
// getLocalRenderer().setContext(getMapContext()); geht doch auch |
423 |
getLocalRenderer().setContext(getMapContext()); |
// ohne?!?!? wow... |
424 |
requestStartRendering(); |
requestStartRendering(); |
425 |
} |
} |
426 |
|
|
441 |
|
|
442 |
/** |
/** |
443 |
* Listens to each layer in the local {@link MapContext} for changes and |
* Listens to each layer in the local {@link MapContext} for changes and |
444 |
* triggers repaints. |
* triggers repaints. We don't have to listen layerChanged, because that is |
445 |
|
* already done in {@link #localContextListener} |
446 |
*/ |
*/ |
447 |
protected MapLayerListener localMapLayerListener = new MapLayerAdapter() { |
protected MapLayerListener localMapLayerListener = new MapLayerAdapter() { |
448 |
|
|
449 |
@Override |
// @Override |
450 |
public void layerChanged(final MapLayerEvent event) { |
// public void layerChanged(final MapLayerEvent event) { |
451 |
getLocalRenderer().setContext(getMapContext()); // betters for SLD |
// // getLocalRenderer().setContext(getMapContext()); // betters for SLD |
452 |
// changes?! |
// // // changes?! |
453 |
requestStartRendering(); |
// // requestStartRendering(); |
454 |
} |
// } |
455 |
|
|
456 |
@Override |
@Override |
457 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
534 |
private BufferedImage preFinalImage; |
private BufferedImage preFinalImage; |
535 |
|
|
536 |
// ** if 0, no quick preview will be shown **/ |
// ** if 0, no quick preview will be shown **/ |
537 |
private int quickPreviewHint = 0; |
// private int quickPreviewHint = 0; |
538 |
|
|
539 |
private Map<Object, Object> rendererHints = GTUtil |
private Map<Object, Object> rendererHints = GTUtil |
540 |
.getDefaultGTRendererHints(getLocalRenderer()); |
.getDefaultGTRendererHints(getLocalRenderer()); |
635 |
if (!isWellDefined()) |
if (!isWellDefined()) |
636 |
return; |
return; |
637 |
|
|
638 |
LOGGER.debug("resizeTimer performed"); |
// LOGGER.debug("resizeTimer performed"); |
639 |
|
|
640 |
final Rectangle bounds = getVisibleRect(); |
// final Rectangle bounds = getVisibleRect(); |
641 |
// |
// |
642 |
// System.out.println("\n\ntimer performs with bounds = " |
// System.out.println("\n\ntimer performs with bounds = " |
643 |
// + bounds); |
// + bounds); |
644 |
|
|
645 |
final Envelope geoMapArea = tranformWindowToGeo( |
// final Envelope geoMapArea = tranformWindowToGeo( |
646 |
bounds.x, bounds.y, bounds.x + bounds.width, |
// bounds.x, bounds.y, bounds.x + bounds.width, |
647 |
bounds.y + bounds.height); |
// bounds.y + bounds.height); |
648 |
|
|
649 |
if (setMapArea(geoMapArea)) { |
paneResized = true; |
650 |
LOGGER.debug(" maparea changed"); |
if (!setMapArea(getMapArea())) { |
651 |
paneResized = true; |
// It's important to request new rendering here. |
652 |
} else |
// setMapArea only returns true and only calls |
653 |
LOGGER.debug(" maparea NOT changed"); |
// requestStartRendering if the maparea has changed. |
654 |
|
// But if the component is resized, the maparea |
655 |
|
// doesn't have to change. |
656 |
|
requestStartRendering(); |
657 |
|
} |
658 |
|
|
659 |
} |
} |
660 |
}); |
}); |
661 |
resizeTimer.setRepeats(false); |
resizeTimer.setRepeats(false); |
670 |
// Seems to be called twice with the same size.. |
// Seems to be called twice with the same size.. |
671 |
if (oldVisibleRect != null |
if (oldVisibleRect != null |
672 |
&& oldVisibleRect.equals(getVisibleRect())) { |
&& oldVisibleRect.equals(getVisibleRect())) { |
673 |
LOGGER.debug("skipping resize."); |
// LOGGER.debug("skipping resize."); |
674 |
return; |
return; |
675 |
} |
} |
676 |
|
|
677 |
LOGGER.debug("resized: " + getVisibleRect()); |
// LOGGER.debug("resized: " + getVisibleRect()); |
678 |
resizeTimer.restart(); |
resizeTimer.restart(); |
679 |
oldVisibleRect = getVisibleRect(); |
oldVisibleRect = getVisibleRect(); |
680 |
} |
} |
1018 |
* |
* |
1019 |
* @param g |
* @param g |
1020 |
* Graphics2D to paint the preview into |
* Graphics2D to paint the preview into |
|
* |
|
|
* @param state |
|
|
* Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT} |
|
1021 |
*/ |
*/ |
1022 |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
1023 |
|
|
1024 |
// if (1 == 1)return false; |
// if (1 == 1)return false; |
1025 |
|
// if (quickPreviewHint == 0) |
1026 |
|
// return false; |
1027 |
|
|
1028 |
if (quickPreviewHint == 0) |
if (oldMapArea == null) |
1029 |
return false; |
return false; |
1030 |
|
|
1031 |
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
if (getPreFinalImage() == null) |
|
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
|
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
|
|
RenderingHints.VALUE_ANTIALIAS_OFF); |
|
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
|
|
RenderingHints.VALUE_RENDER_SPEED); |
|
|
|
|
|
if (oldMapArea == null) |
|
1032 |
return false; |
return false; |
1033 |
|
|
1034 |
final Rectangle visibleArea = getVisibleRect(); |
final Rectangle visibleArea = getVisibleRect(); |
1043 |
final int xx2 = (int) Math.round(oldMapWindow.getMaxX()); |
final int xx2 = (int) Math.round(oldMapWindow.getMaxX()); |
1044 |
final int yy2 = (int) Math.round(oldMapWindow.getMaxY()); |
final int yy2 = (int) Math.round(oldMapWindow.getMaxY()); |
1045 |
|
|
1046 |
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
1047 |
|
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
1048 |
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
1049 |
|
RenderingHints.VALUE_ANTIALIAS_OFF); |
1050 |
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
1051 |
|
RenderingHints.VALUE_RENDER_SPEED); |
1052 |
|
|
1053 |
graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2, |
graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2, |
1054 |
(int) visibleArea.getMinX(), (int) visibleArea.getMinY(), |
(int) visibleArea.getMinX(), (int) visibleArea.getMinY(), |
1055 |
(int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(), |
(int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(), |
1058 |
final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 |
final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 |
1059 |
- yy1); |
- yy1); |
1060 |
|
|
1061 |
SwingUtil.clearAround(graphics, painedArea, visibleArea); |
SwingUtil.clearAround(graphics, painedArea, visibleArea, |
1062 |
|
getMapBackgroundColor()); |
1063 |
|
|
1064 |
addGadgets(graphics, true); |
addGadgets(graphics, true); |
1065 |
|
|
1066 |
quickPreviewHint = 0; |
// quickPreviewHint = 0; |
1067 |
|
|
1068 |
repaintTimer.restart(); |
repaintTimer.restart(); |
1069 |
|
|
|
graphics.dispose(); |
|
|
|
|
1070 |
// Something has been drawn |
// Something has been drawn |
1071 |
return true; |
return true; |
1072 |
} |
} |
1079 |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
1080 |
*/ |
*/ |
1081 |
private Image getBgImage() { |
private Image getBgImage() { |
1082 |
// |
if (bgImage == null) { |
1083 |
// if (bgImage == null) { |
bgImage = new BufferedImage(getVisibleRect().width, |
1084 |
// bgImage = createImage(getBounds().width, getBounds().height); |
getVisibleRect().height, IMAGETYPE); |
1085 |
// } |
SwingUtil.clearImage(finalImage, getMapBackgroundColor()); |
1086 |
|
} |
1087 |
|
|
1088 |
return bgImage; |
return bgImage; |
1089 |
} |
} |
1101 |
// Rectangle curPaintArea = getVisibleRect(); |
// Rectangle curPaintArea = getVisibleRect(); |
1102 |
finalImage = new BufferedImage(getVisibleRect().width, |
finalImage = new BufferedImage(getVisibleRect().width, |
1103 |
getVisibleRect().height, IMAGETYPE); |
getVisibleRect().height, IMAGETYPE); |
1104 |
|
SwingUtil.clearImage(finalImage, getMapBackgroundColor()); |
1105 |
|
|
1106 |
requestStartRendering(); |
// requestStartRendering(); |
1107 |
} |
} |
1108 |
return finalImage; |
return finalImage; |
1109 |
} |
} |
1110 |
|
|
|
public RenderingHints getJava2dHints() { |
|
|
return java2dHints; |
|
|
} |
|
|
|
|
1111 |
/** |
/** |
1112 |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
1113 |
*/ |
*/ |
1116 |
if (localImage == null) { |
if (localImage == null) { |
1117 |
localImage = new BufferedImage(getVisibleRect().width, |
localImage = new BufferedImage(getVisibleRect().width, |
1118 |
getVisibleRect().height, IMAGETYPE_withAlpha); |
getVisibleRect().height, IMAGETYPE_withAlpha); |
1119 |
|
SwingUtil.clearImage(localImage, getMapBackgroundColor()); |
1120 |
} |
} |
1121 |
|
|
1122 |
return localImage; |
return localImage; |
1132 |
ReferencedEnvelope mapArea_ = null; |
ReferencedEnvelope mapArea_ = null; |
1133 |
try { |
try { |
1134 |
mapArea_ = localContext.getLayerBounds(); |
mapArea_ = localContext.getLayerBounds(); |
1135 |
} catch (final IOException e) { |
} catch (final Exception e) { |
1136 |
LOGGER.warn("localContext.getLayerBounds()", e); |
LOGGER.warn("localContext.getLayerBounds()", e); |
1137 |
} |
} |
1138 |
|
|
1158 |
try { |
try { |
1159 |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
localContext.setCoordinateReferenceSystem(GeoImportUtil |
1160 |
.getDefaultCRS()); |
.getDefaultCRS()); |
1161 |
} catch (Exception e) { |
} catch (final Exception e) { |
1162 |
throw new RuntimeException("setting context CRS:", e); |
throw new RuntimeException("setting context CRS:", e); |
1163 |
} |
} |
1164 |
|
|
1204 |
|
|
1205 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1206 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1207 |
// Commented-out because it takes soo much time! |
|
1208 |
// |
// The next command may take long time! |
1209 |
// long start = System.currentTimeMillis(); |
// long start = System.currentTimeMillis(); |
1210 |
// final ReferencedEnvelope layerBounds = GTUtil |
final ReferencedEnvelope layerBounds = GTUtil |
1211 |
// .getVisibleLayoutBounds(localContext); |
.getVisibleLayoutBounds(localContext); |
1212 |
// |
// |
1213 |
// LOGGER.info( |
// LOGGER.info( |
1214 |
// (System.currentTimeMillis()-start)+"m to get maxExtend"); |
// (System.currentTimeMillis()-start)+"m to get maxExtend"); |
1215 |
// |
// |
1216 |
// if (layerBounds == null) { |
if (layerBounds == null) { |
1217 |
// // TODO Last fallback could be the CRS valid area |
// // TODO Last fallback could be the CRS valid area |
1218 |
// return null; |
return null; |
1219 |
// } |
} |
1220 |
// |
|
1221 |
// // Kartenbereich um 10% vergroessern |
// Vergrößerung um 10% nochmal rausgenommen |
1222 |
|
// // // Kartenbereich um 10% vergroessern |
1223 |
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
1224 |
// .expandEnvelope(layerBounds, 0.1), true); |
// .expandEnvelope(layerBounds, 0.1), true); |
1225 |
|
|
1226 |
|
return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true); |
1227 |
} |
} |
1228 |
return maxExtend; |
return maxExtend; |
1229 |
} |
} |
1251 |
} |
} |
1252 |
|
|
1253 |
private Image getPreFinalImage() { |
private Image getPreFinalImage() { |
|
// if (preFinalImage == null) { |
|
|
// |
|
|
// // Rectangle curPaintArea = getVisibleRect(); |
|
|
// // preFinalImage = new BufferedImage(curPaintArea.width, |
|
|
// // curPaintArea.height, BufferedImage.TYPE_INT_RGB); |
|
|
// |
|
|
// preFinalImage = createImage(getBounds().width, getBounds().height); |
|
|
// |
|
|
// requestStartRendering(); |
|
|
// } |
|
1254 |
return preFinalImage; |
return preFinalImage; |
1255 |
} |
} |
1256 |
|
|
1419 |
|| (getState() == XMapPane.SELECT_TOP)) { |
|| (getState() == XMapPane.SELECT_TOP)) { |
1420 |
|
|
1421 |
// Draws a rectangle |
// Draws a rectangle |
1422 |
final Graphics graphics = getGraphics(); |
final Graphics2D graphics = (Graphics2D) getGraphics(); |
1423 |
drawRectangle(graphics, startPos, event.getPoint()); |
drawRectangle(graphics, startPos, event.getPoint()); |
1424 |
if ((lastPos.x > 0) && (lastPos.y > 0)) |
if ((lastPos.x > 0) && (lastPos.y > 0)) |
1425 |
drawRectangle(graphics, startPos, lastPos); |
drawRectangle(graphics, startPos, lastPos); |
1431 |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
1432 |
*/ |
*/ |
1433 |
public void onRenderingCancelled() { |
public void onRenderingCancelled() { |
1434 |
LOGGER.debug("Rendering cancelled"); |
// LOGGER.debug("Rendering cancelled"); |
1435 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1436 |
} |
} |
1437 |
|
|
1438 |
/** |
/** |
1439 |
* Called by the {@link RenderingExecutor} when rendering has been |
* Called by the {@link RenderingExecutor} when rendering has been |
1440 |
* completed. |
* completed. |
1441 |
|
* |
1442 |
|
* @param l |
1443 |
|
* long ms the rendering took |
1444 |
*/ |
*/ |
1445 |
public void onRenderingCompleted() { |
public void onRenderingCompleted(final long l) { |
1446 |
LOGGER.debug("complete"); |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
1447 |
|
// LOGGER |
1448 |
|
// .debug("complete rendering after " + lastRenderingDuration |
1449 |
|
// + "ms"); |
1450 |
|
|
1451 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1452 |
|
|
1498 |
|
|
1499 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1500 |
return; |
return; |
1501 |
|
// |
1502 |
|
// if (paneResized) { |
1503 |
|
// // ((Graphics2D) g).setBackground(getMapBackgroundColor()); |
1504 |
|
// // g.clearRect(0, 0, getVisibleRect().width, |
1505 |
|
// getVisibleRect().height); |
1506 |
|
// return; |
1507 |
|
// } |
1508 |
|
|
1509 |
// super.paintComponent(g); // candidate for removal |
// super.paintComponent(g); // candidate for removal |
1510 |
|
|
1511 |
boolean paintedSomething = false; |
boolean paintedSomething = false; |
1512 |
|
|
1517 |
// If the new mapArea and the oldMapArea intersect, we can draw some |
// If the new mapArea and the oldMapArea intersect, we can draw some |
1518 |
// quick scaled preview to make the user feel that something is |
// quick scaled preview to make the user feel that something is |
1519 |
// happening. |
// happening. |
1520 |
if (mapAreaChanged && oldMapArea != null |
if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged |
1521 |
|
&& oldMapArea != null |
1522 |
&& getMapArea().intersects(oldMapArea) |
&& getMapArea().intersects(oldMapArea) |
1523 |
& !getMapArea().equals(oldMapArea) && !paneResized) { |
&& !getMapArea().equals(oldMapArea) && !paneResized) { |
1524 |
|
|
1525 |
mapAreaChanged = false; |
mapAreaChanged = false; |
1526 |
|
|
1527 |
if (getMapArea().covers(oldMapArea)) { |
// if (getMapArea().covers(oldMapArea)) { |
1528 |
quickPreviewHint = ZOOM_OUT; |
// // quickPreviewHint = ZOOM_OUT; |
1529 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
// paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) |
1530 |
} else if (oldMapArea.covers(getMapArea())) { |
// g); |
1531 |
quickPreviewHint = ZOOM_IN; |
// } else if (oldMapArea.covers(getMapArea())) { |
1532 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
// quickPreviewHint = ZOOM_IN; |
1533 |
} |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
1534 |
|
// } |
1535 |
} |
} |
1536 |
} |
} |
1537 |
|
|
1539 |
|
|
1540 |
g.drawImage(getFinalImage(), 0, 0, null); |
g.drawImage(getFinalImage(), 0, 0, null); |
1541 |
|
|
|
g.dispose(); // cand. for removal |
|
|
|
|
1542 |
paintedSomething = true; // cand. for removal |
paintedSomething = true; // cand. for removal |
1543 |
} |
} |
1544 |
|
|
1594 |
*/ |
*/ |
1595 |
public void performPan() { |
public void performPan() { |
1596 |
|
|
1597 |
Rectangle winBounds = getVisibleRect(); |
final Rectangle winBounds = getVisibleRect(); |
1598 |
|
|
1599 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1600 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1662 |
* the current map pane extent (screen units) |
* the current map pane extent (screen units) |
1663 |
*/ |
*/ |
1664 |
private void resetTransforms() { |
private void resetTransforms() { |
|
ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
|
|
getMapContext().getCoordinateReferenceSystem()); |
|
|
|
|
1665 |
// System.out |
// System.out |
1666 |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
1667 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1668 |
return; |
return; |
1669 |
|
|
1670 |
|
if (mapArea == null) |
1671 |
|
return; |
1672 |
|
|
1673 |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1674 |
|
getMapContext().getCoordinateReferenceSystem()); |
1675 |
|
|
1676 |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1677 |
getVisibleRect()); |
getVisibleRect()); |
1678 |
|
|
1679 |
try { |
try { |
1680 |
screenToWorld = worldToScreen.createInverse(); |
screenToWorld = worldToScreen.createInverse(); |
1681 |
|
|
1682 |
} catch (NoninvertibleTransformException ex) { |
} catch (final NoninvertibleTransformException ex) { |
1683 |
LOGGER |
LOGGER |
1684 |
.error("can't invert worldToScreen to get screenToWorld!", |
.error("can't invert worldToScreen to get screenToWorld!", |
1685 |
ex); |
ex); |
1749 |
|
|
1750 |
} |
} |
1751 |
|
|
1752 |
|
public void setBorder(final Border b) { |
1753 |
|
super.setBorder(b); |
1754 |
|
} |
1755 |
|
|
1756 |
/** |
/** |
1757 |
* Triggers to repaint (fast) and re-render (slow) the JMapPane. |
* Triggers to repaint (fast) and re-render (slow) the JMapPane. |
1758 |
*/ |
*/ |
1773 |
// repaint(); |
// repaint(); |
1774 |
// } |
// } |
1775 |
|
|
1776 |
|
/** |
1777 |
|
* Set the new map area. |
1778 |
|
* |
1779 |
|
* @param newMapArea |
1780 |
|
* @return <code>true</code> if the mapArea has been changed and a repaint |
1781 |
|
* has been triggered. |
1782 |
|
*/ |
1783 |
public boolean setMapArea(final Envelope newMapArea) { |
public boolean setMapArea(final Envelope newMapArea) { |
1784 |
if (newMapArea == null) |
if (newMapArea == null) |
1785 |
return false; |
return false; |
1790 |
} |
} |
1791 |
|
|
1792 |
/** |
/** |
1793 |
|
* Set the new map area. |
1794 |
|
* |
1795 |
* @param newMapArea |
* @param newMapArea |
1796 |
* @return <code>true</code> if the mapArea has been changed and a repaint |
* @return <code>true</code> if the mapArea has been changed and a repaint |
1797 |
* has been triggered. |
* has been triggered. |
1866 |
* |
* |
1867 |
* @param if <code>null</code>, white is used. |
* @param if <code>null</code>, white is used. |
1868 |
*/ |
*/ |
1869 |
public void setMapBackgroundColor(Color bgColor) { |
public void setMapBackgroundColor(final Color bgColor) { |
1870 |
this.mapBackgroundColor = bgColor; |
this.mapBackgroundColor = bgColor; |
1871 |
} |
} |
1872 |
|
|
1924 |
} |
} |
1925 |
|
|
1926 |
// /** Stored the time used for the last real rendering in ms. **/ |
// /** Stored the time used for the last real rendering in ms. **/ |
1927 |
// private long lastRenderingDuration = Long.MAX_VALUE; |
private long lastRenderingDuration = 1000; |
1928 |
|
|
1929 |
/** |
/** |
1930 |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
2049 |
updateCursor(); |
updateCursor(); |
2050 |
} |
} |
2051 |
|
|
2052 |
|
private RenderingHints getJava2dHints() { |
2053 |
|
return java2dHints; |
2054 |
|
} |
2055 |
|
|
2056 |
/** |
/** |
2057 |
* Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten. |
* Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten. |
2058 |
* |
* |
2192 |
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y, |
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y, |
2193 |
getMapBackgroundColor(), null); |
getMapBackgroundColor(), null); |
2194 |
|
|
2195 |
final int finalImageHeight = getFinalImage().getHeight(null); |
// When panning, we have to clear the area around the image |
|
final int finalImageWidth = getFinalImage().getWidth(null); |
|
|
|
|
2196 |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
2197 |
imageOrigin.y, finalImageWidth, finalImageHeight); |
imageOrigin.y, getFinalImage().getWidth(), getFinalImage() |
2198 |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect()); |
.getHeight()); |
2199 |
|
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
2200 |
|
getMapBackgroundColor()); |
2201 |
|
|
2202 |
addGadgets(finalG, false); |
addGadgets(finalG, false); |
2203 |
|
|
2216 |
* <code>false</code>, it will only depend on |
* <code>false</code>, it will only depend on |
2217 |
* {@link #localExecuter.isRunning} and #bgExecuter.isRunning |
* {@link #localExecuter.isRunning} and #bgExecuter.isRunning |
2218 |
*/ |
*/ |
2219 |
private void addGadgets(final Graphics2D graphics, boolean forceWait) { |
private void addGadgets(final Graphics2D graphics, final boolean forceWait) { |
2220 |
|
|
2221 |
// Paint a logo to the bottom right if available |
// Paint a logo to the bottom right if available |
2222 |
if (mapImage != null) { |
if (mapImage != null) { |
2223 |
Rectangle visibleRect = getVisibleRect(); |
final Rectangle visibleRect = getVisibleRect(); |
2224 |
graphics.drawImage(mapImage, visibleRect.width |
graphics.drawImage(mapImage, visibleRect.width |
2225 |
- mapImage.getWidth() - 10, getVisibleRect().height |
- mapImage.getWidth() - 10, getVisibleRect().height |
2226 |
- mapImage.getHeight() - 10, null); |
- mapImage.getHeight() - 10, null); |
2246 |
|
|
2247 |
graphics.setColor(c); |
graphics.setColor(c); |
2248 |
|
|
2249 |
y += 24; |
y += 21; |
2250 |
} |
} |
2251 |
|
|
2252 |
if (!renderingErrors.isEmpty() && isShowExceptions()) { |
if (!renderingErrors.isEmpty() && isShowExceptions()) { |
2254 |
final Color c = graphics.getColor(); |
final Color c = graphics.getColor(); |
2255 |
graphics.setFont(errorFont); |
graphics.setFont(errorFont); |
2256 |
|
|
2257 |
for (Exception ex : renderingErrors) { |
for (final Exception ex : renderingErrors) { |
2258 |
|
|
2259 |
String errStr = ex.getLocalizedMessage(); |
String errStr = ex.getLocalizedMessage(); |
2260 |
|
|
2291 |
final CoordinateReferenceSystem mapCRS = getMapContext() |
final CoordinateReferenceSystem mapCRS = getMapContext() |
2292 |
.getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2293 |
final CoordinateReferenceSystem fCRS = features.getSchema() |
final CoordinateReferenceSystem fCRS = features.getSchema() |
2294 |
.getGeometryDescriptor().getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2295 |
|
|
2296 |
ReferencedEnvelope _mapArea; |
ReferencedEnvelope _mapArea; |
2297 |
if (mapArea == null) |
if (mapArea == null) |
2384 |
* @param center |
* @param center |
2385 |
* position in window coordinates |
* position in window coordinates |
2386 |
* @param zoomFaktor |
* @param zoomFaktor |
2387 |
* > 1 for zoom in, < 1 for zoom out. Default is 1.33. |
* > 1 for zoom out, < 1 for zoom in. Default is .5 |
2388 |
*/ |
*/ |
2389 |
public void zoomTo(Point center, Double zoomFaktor) { |
public void zoomTo(Point center, Double zoomFaktor) { |
2390 |
if (zoomFaktor == null || zoomFaktor == 0.) |
if (zoomFaktor == null || zoomFaktor == 0.) |
2391 |
zoomFaktor = 2.; |
zoomFaktor = .5; |
2392 |
|
|
2393 |
final Point2D gcenter = getScreenToWorld().transform(center, null); |
final Point2D gcenter = getScreenToWorld().transform(center, null); |
2394 |
center = null; |
center = null; |
2409 |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
2410 |
.getHeight()) / 2.); |
.getHeight()) / 2.); |
2411 |
|
|
2412 |
// TODO we actually want that |
// // Move the newMapArea above the new center if we zoom in: |
2413 |
// // Move the newMapArea above the new center |
newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
2414 |
// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
.getY() |
2415 |
// .getY() |
- mapArea.centre().y); |
|
// - mapArea.centre().y); |
|
2416 |
|
|
2417 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2418 |
} |
} |
2421 |
* Shall non-fatal rendering exceptions be reported in the mappane or be |
* Shall non-fatal rendering exceptions be reported in the mappane or be |
2422 |
* dropped quitely. |
* dropped quitely. |
2423 |
*/ |
*/ |
2424 |
public void setShowExceptions(boolean showExceptions) { |
public void setShowExceptions(final boolean showExceptions) { |
2425 |
this.showExceptions = showExceptions; |
this.showExceptions = showExceptions; |
2426 |
} |
} |
2427 |
|
|
2436 |
return localRenderer; |
return localRenderer; |
2437 |
} |
} |
2438 |
|
|
2439 |
|
/** |
2440 |
|
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
2441 |
|
* Macht nichts, wenn {@code null} uebergeben wird. |
2442 |
|
* |
2443 |
|
* <br> |
2444 |
|
* |
2445 |
|
* @param layer |
2446 |
|
* ein Layer |
2447 |
|
*/ |
2448 |
|
public void zoomToLayer(MapLayer layer) { |
2449 |
|
if (layer == null) |
2450 |
|
return; |
2451 |
|
try { |
2452 |
|
|
2453 |
|
// BB umrechnen von Layer-CRS in Map-CRS |
2454 |
|
final CoordinateReferenceSystem targetCRS = getMapContext() |
2455 |
|
.getCoordinateReferenceSystem(); |
2456 |
|
final CoordinateReferenceSystem sourceCRS = layer |
2457 |
|
.getFeatureSource().getSchema() |
2458 |
|
.getCoordinateReferenceSystem(); |
2459 |
|
|
2460 |
|
Envelope mapAreaNew; |
2461 |
|
if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { |
2462 |
|
mapAreaNew = JTSUtil.transformEnvelope(layer.getFeatureSource() |
2463 |
|
.getBounds(), sourceCRS, targetCRS); |
2464 |
|
} else { |
2465 |
|
try { |
2466 |
|
mapAreaNew = layer.getFeatureSource().getBounds(); |
2467 |
|
} catch (java.lang.IllegalArgumentException e) { |
2468 |
|
LOGGER.error("Can't calc layers bounds...", e); |
2469 |
|
mapAreaNew = null; |
2470 |
|
|
2471 |
|
/** |
2472 |
|
* |
2473 |
|
23.10.2009 11:20:50 |
2474 |
|
* org.geotools.data.shapefile.shp.PolygonHandler read |
2475 |
|
* WARNUNG: only one hole in this polygon record ERROR |
2476 |
|
* JMapPane zoomToLayer Zoom to layer did not terminate |
2477 |
|
* correctly java.lang.IllegalArgumentException: Points of |
2478 |
|
* LinearRing do not form a closed linestring at |
2479 |
|
* com.vividsolutions |
2480 |
|
* .jts.geom.LinearRing.validateConstruction |
2481 |
|
* (LinearRing.java:105) at |
2482 |
|
* com.vividsolutions.jts.geom.LinearRing |
2483 |
|
* .<init>(LinearRing.java:100) at |
2484 |
|
* com.vividsolutions.jts.geom |
2485 |
|
* .GeometryFactory.createLinearRing |
2486 |
|
* (GeometryFactory.java:339) at |
2487 |
|
* org.geotools.data.shapefile. |
2488 |
|
* shp.PolygonHandler.read(PolygonHandler.java:188) at |
2489 |
|
* org.geotools |
2490 |
|
* .data.shapefile.shp.ShapefileReader$Record.shape |
2491 |
|
* (ShapefileReader.java:106) at |
2492 |
|
* org.geotools.data.shapefile. |
2493 |
|
* ShapefileAttributeReader.next( |
2494 |
|
* ShapefileAttributeReader.java:157) at |
2495 |
|
* org.geotools.data.shapefile |
2496 |
|
* .indexed.IndexedShapefileAttributeReader |
2497 |
|
* .next(IndexedShapefileAttributeReader.java:122) at |
2498 |
|
* org.geotools |
2499 |
|
* .data.FIDFeatureReader.next(FIDFeatureReader.java:96) at |
2500 |
|
* org.geotools.data.FIDFeatureReader.next(FIDFeatureReader. |
2501 |
|
* java:55) at org.geotools.data.MaxFeatureReader.next( |
2502 |
|
* MaxFeatureReader.java:61) at |
2503 |
|
* org.geotools.data.MaxFeatureReader |
2504 |
|
* .next(MaxFeatureReader.java:61) |
2505 |
|
**/ |
2506 |
|
} |
2507 |
|
} |
2508 |
|
|
2509 |
|
// Kartenbereich um 10% vergroessern, damit z.B. auch ein |
2510 |
|
// Punkt-Layer, |
2511 |
|
// welches nur aus 2 Punnkten besteht, sichtbar ist (Punkte liegen |
2512 |
|
// sonst |
2513 |
|
// genau auf dem Rand der angezeigten Flaeche) |
2514 |
|
|
2515 |
|
if (mapAreaNew != null) { |
2516 |
|
mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew |
2517 |
|
.getHeight() * 0.1); |
2518 |
|
setMapArea(mapAreaNew); |
2519 |
|
} else { |
2520 |
|
LOGGER |
2521 |
|
.warn("Couldn't transformEnvelope when zooming to the layer"); |
2522 |
|
} |
2523 |
|
} catch (Exception err) { |
2524 |
|
LOGGER.error("Zoom to layer did not terminate correctly", err); |
2525 |
|
} |
2526 |
|
} |
2527 |
|
|
2528 |
|
/** |
2529 |
|
* Zooms the {@link SelectableXMapPane} to the {@link Envelope} of a layer. |
2530 |
|
* |
2531 |
|
* <br> |
2532 |
|
* A refresh of the map is not done automatically |
2533 |
|
* |
2534 |
|
* @param index |
2535 |
|
* Index of the {@link MapLayer} in the {@link MapContext} (from |
2536 |
|
* back to top) |
2537 |
|
* |
2538 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2539 |
|
* Krüger</a> |
2540 |
|
*/ |
2541 |
|
public void zoomToLayer(int index) { |
2542 |
|
final MapContext context = getMapContext(); |
2543 |
|
if (context != null) |
2544 |
|
zoomToLayer(context.getLayer(index)); |
2545 |
|
} |
2546 |
|
|
2547 |
|
/** |
2548 |
|
* Zooms the {@link SelectableXMapPane} to the {@link Envelope} of the |
2549 |
|
* selected layer. The layer is selected by the idx, counting from front to |
2550 |
|
* back, like humans would expect in a {@link JList} |
2551 |
|
* |
2552 |
|
* <br> |
2553 |
|
* A refresh of the map is not done automatically |
2554 |
|
* |
2555 |
|
* |
2556 |
|
* |
2557 |
|
* @param index |
2558 |
|
* Reverse index of the {@link MapLayer} in the |
2559 |
|
* {@link MapContext} |
2560 |
|
* |
2561 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2562 |
|
* Krüger</a> |
2563 |
|
*/ |
2564 |
|
public void zoomToLayerIdxReverse(int index) { |
2565 |
|
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
2566 |
|
} |
2567 |
|
|
2568 |
|
/** |
2569 |
|
* Aktiviert oder deaktiviert das AntiAliasing for diese |
2570 |
|
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
2571 |
|
* Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance. |
2572 |
|
* |
2573 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2574 |
|
* Krüger</a> |
2575 |
|
*/ |
2576 |
|
public void setAntiAliasing(final boolean aa) { |
2577 |
|
// LOGGER.info("Setting AntiAliasing for this JMapPane to " + aa); |
2578 |
|
RenderingHints java2DHints = java2dHints; |
2579 |
|
if (java2DHints == null) { |
2580 |
|
java2DHints = GeoTools.getDefaultHints(); |
2581 |
|
} |
2582 |
|
|
2583 |
|
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
2584 |
|
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
2585 |
|
: RenderingHints.VALUE_ANTIALIAS_OFF); |
2586 |
|
java2DHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, |
2587 |
|
aa ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON |
2588 |
|
: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); |
2589 |
|
java2DHints.put(RenderingHints.KEY_RENDERING, |
2590 |
|
aa ? RenderingHints.VALUE_RENDER_QUALITY |
2591 |
|
: RenderingHints.VALUE_RENDER_SPEED); |
2592 |
|
|
2593 |
|
} |
2594 |
|
|
2595 |
} |
} |