13 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
14 |
import java.awt.event.ComponentAdapter; |
import java.awt.event.ComponentAdapter; |
15 |
import java.awt.event.ComponentEvent; |
import java.awt.event.ComponentEvent; |
|
import java.awt.event.InputEvent; |
|
16 |
import java.awt.event.MouseEvent; |
import java.awt.event.MouseEvent; |
17 |
import java.awt.event.MouseListener; |
import java.awt.event.MouseListener; |
18 |
import java.awt.geom.AffineTransform; |
import java.awt.geom.AffineTransform; |
48 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
49 |
import org.geotools.renderer.lite.RendererUtilities; |
import org.geotools.renderer.lite.RendererUtilities; |
50 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
51 |
|
import org.geotools.resources.image.ImageUtilities; |
52 |
import org.geotools.swing.JMapPane; |
import org.geotools.swing.JMapPane; |
53 |
import org.geotools.swing.event.MapMouseEvent; |
import org.geotools.swing.event.MapMouseEvent; |
54 |
import org.geotools.swing.event.MapPaneEvent; |
import org.geotools.swing.event.MapPaneEvent; |
69 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
70 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
71 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
72 |
|
import schmitzm.swing.event.MouseInputType; |
73 |
|
|
74 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
75 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
100 |
*/ |
*/ |
101 |
public class XMapPane extends JPanel { |
public class XMapPane extends JPanel { |
102 |
|
|
103 |
|
/** |
104 |
|
* If {@link #maxExtend} is <code>null</code> the following rules are used |
105 |
|
* to create a default maximum. |
106 |
|
* <ul> |
107 |
|
* <li>Values < 0 : don't grow to fit the monitors aspect ratio, no |
108 |
|
* margin</li> |
109 |
|
* <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li> |
110 |
|
* <li>Values > 0 : grow to fit the monitors aspect ratio, and add a |
111 |
|
* relative margin</li> |
112 |
|
* </ul> |
113 |
|
* **/ |
114 |
|
private double defaultMaxMapExtendMode = .05; |
115 |
|
|
116 |
// private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
// private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
117 |
// private static final int IMAGETYPE_withAlpha = |
// private static final int IMAGETYPE_withAlpha = |
118 |
// BufferedImage.TYPE_INT_ARGB; |
// BufferedImage.TYPE_INT_ARGB; |
119 |
private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR; |
private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR; |
120 |
|
|
121 |
|
public XMapPaneTool getTool() { |
122 |
|
return tool; |
123 |
|
} |
124 |
|
|
125 |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR; |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR; |
126 |
|
|
127 |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
128 |
|
|
129 |
|
/** |
130 |
|
* A flag indicating whether the {@link XMapPane} is accepting repaints from |
131 |
|
* the EDT. @see {@link XMapPane#setPainting(boolean)) |
132 |
|
**/ |
133 |
private boolean acceptsRepaintCalls = true; |
private boolean acceptsRepaintCalls = true; |
134 |
|
|
135 |
/** |
/** |
192 |
* Flag for no-tool. |
* Flag for no-tool. |
193 |
*/ |
*/ |
194 |
public static final int NONE = -123; |
public static final int NONE = -123; |
195 |
|
// |
196 |
/** |
// /** |
197 |
* Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
// * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
198 |
* moeglich! |
// * moeglich! |
199 |
* |
// * |
200 |
* @see #setState(int) |
// * @see #setState(int) |
201 |
*/ |
// */ |
202 |
public static final int PAN = 1; |
// public static final int PAN = 1; |
203 |
|
// |
204 |
/** |
// /** |
205 |
* Flag fuer Modus "Heran zoomen". |
// * Flag fuer Modus "Heran zoomen". |
206 |
* |
// * |
207 |
* @see #setState(int) |
// * @see #setState(int) |
208 |
* @see #setState(int) |
// * @see #setState(int) |
209 |
*/ |
// */ |
210 |
public static final int ZOOM_IN = 2; |
// public static final int ZOOM_IN = 2; |
211 |
|
// |
212 |
/** |
// /** |
213 |
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
// * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
214 |
* |
// * |
215 |
* @see #setState(int) |
// * @see #setState(int) |
216 |
*/ |
// */ |
217 |
public static final int ZOOM_OUT = 3; |
// public static final int ZOOM_OUT = 3; |
|
|
|
|
/** |
|
|
* Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern". |
|
|
* |
|
|
* @see #setState(int) |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int SELECT_ALL = 103; |
|
|
/** |
|
|
* Flag fuer Modus |
|
|
* "Auswahl nur eines Features, das erste sichtbare von Oben". |
|
|
* |
|
|
* @see #setState(int) |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int SELECT_ONE_FROM_TOP = 104; |
|
|
/** |
|
|
* Flag fuer Modus |
|
|
* "SimpleFeature-Auswahl auf dem obersten (sichtbaren) Layer". |
|
|
* |
|
|
* @see #setState(int) |
|
|
* @see #setState(int) |
|
|
*/ |
|
|
public static final int SELECT_TOP = 4; |
|
218 |
|
|
219 |
/** |
/** |
220 |
* {@link Font} used to paint the wait messages into the map |
* {@link Font} used to paint the wait messages into the map |
274 |
final AffineTransform at = xMapPane.getScreenToWorld(); |
final AffineTransform at = xMapPane.getScreenToWorld(); |
275 |
if (at != null) { |
if (at != null) { |
276 |
Point2D transformed = at.transform(e.getPoint(), null); |
Point2D transformed = at.transform(e.getPoint(), null); |
277 |
return new DirectPosition2D(xMapPane.getMapContext().getCoordinateReferenceSystem(), transformed.getX(), transformed.getY()); |
return new DirectPosition2D(xMapPane.getMapContext() |
278 |
|
.getCoordinateReferenceSystem(), transformed.getX(), |
279 |
|
transformed.getY()); |
280 |
} |
} |
281 |
return null; |
return null; |
282 |
} |
} |
283 |
throw new IllegalArgumentException( |
throw new IllegalArgumentException( |
284 |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
285 |
} |
} |
|
|
|
|
|
|
286 |
|
|
287 |
/** |
/** |
288 |
* Listens to changes of the "background" {@link MapContext} and triggers |
* Listens to changes of the "background" {@link MapContext} and triggers |
295 |
final MapLayer layer = event.getLayer(); |
final MapLayer layer = event.getLayer(); |
296 |
layer.addMapLayerListener(bgMapLayerListener); |
layer.addMapLayerListener(bgMapLayerListener); |
297 |
requestStartRendering(); |
requestStartRendering(); |
|
|
|
298 |
} |
} |
299 |
|
|
300 |
@Override |
@Override |
388 |
* While dragging, the {@link #updateFinalImage()} method is translating the |
* While dragging, the {@link #updateFinalImage()} method is translating the |
389 |
* cached images while setting it together. |
* cached images while setting it together. |
390 |
**/ |
**/ |
391 |
Point imageOrigin = new Point(0, 0); |
private final Point imageOrigin = new Point(0, 0); |
392 |
/** |
/** |
393 |
* For every rendering thread started, |
* For every rendering thread started, |
394 |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
417 |
|
|
418 |
@Override |
@Override |
419 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
420 |
// getLocalRenderer().setContext(getMapContext()); geht doch auch ohne?!?!? wow... |
// getLocalRenderer().setContext(getMapContext()); geht doch auch |
421 |
|
// ohne?!?!? wow... |
422 |
requestStartRendering(); |
requestStartRendering(); |
423 |
} |
} |
424 |
|
|
555 |
* thread. |
* thread. |
556 |
*/ |
*/ |
557 |
final private Timer startRenderThreadsTimer; |
final private Timer startRenderThreadsTimer; |
558 |
|
// |
559 |
/** |
// /** |
560 |
* The default state is ZOOM_IN, hence by default the |
// * The default state is ZOOM_IN, hence by default the |
561 |
* {@link #zoomMapPaneMouseListener} is also enabled. |
// * {@link #xMapPaneMouseListener} is also enabled. |
562 |
**/ |
// **/ |
563 |
private int state = ZOOM_IN; |
// private int state = ZOOM_IN; |
564 |
|
// |
565 |
/** |
// /** |
566 |
* Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen |
// * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen |
567 |
* MapPane-Funktion |
// * MapPane-Funktion |
568 |
*/ |
// */ |
569 |
protected Cursor staticCursor = null; |
// protected Cursor staticCursor = null; |
570 |
|
|
571 |
private AffineTransform worldToScreen; |
private AffineTransform worldToScreen; |
572 |
|
|
573 |
|
// /** |
574 |
|
// * This {@link MouseListener} is managing all zoom related tasks |
575 |
|
// */ |
576 |
|
// private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new |
577 |
|
// ZoomXMapPaneMouseListener( |
578 |
|
// this); |
579 |
|
|
580 |
/** |
/** |
581 |
* This {@link MouseListener} is managing all zoom related tasks |
* This {@link MouseListener} is managing all zoom related tasks |
582 |
*/ |
*/ |
583 |
public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener( |
private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener( |
584 |
this); |
this); |
585 |
|
|
586 |
/** Is set if a renderer has an error **/ |
/** Is set if a renderer has an error **/ |
612 |
final Map<Object, Object> rendererHints) { |
final Map<Object, Object> rendererHints) { |
613 |
super(true); |
super(true); |
614 |
|
|
615 |
|
// A default setting |
616 |
|
RenderingHints hintsJava2d = ImageUtilities.NN_INTERPOLATION_HINT; |
617 |
|
setJava2dHints(hintsJava2d); |
618 |
|
|
619 |
setRendererHints(rendererHints); |
setRendererHints(rendererHints); |
620 |
|
|
621 |
setOpaque(true); |
setOpaque(true); |
626 |
/** |
/** |
627 |
* Adding the #zoomMapPaneMouseListener |
* Adding the #zoomMapPaneMouseListener |
628 |
*/ |
*/ |
629 |
this.addMouseListener(zoomMapPaneMouseListener); |
this.addMouseListener(xMapPaneMouseListener); |
630 |
this.addMouseMotionListener(zoomMapPaneMouseListener); |
this.addMouseMotionListener(xMapPaneMouseListener); |
631 |
this.addMouseWheelListener(zoomMapPaneMouseListener); |
this.addMouseWheelListener(xMapPaneMouseListener); |
632 |
|
|
633 |
|
// By default the XMapPAne uses the ZOOM_IN tool. |
634 |
|
setTool(XMapPaneTool.ZOOM_IN); |
635 |
|
|
636 |
/* |
/* |
637 |
* We use a Timer object to avoid rendering delays and flickering when |
* We use a Timer object to avoid rendering delays and flickering when |
817 |
|
|
818 |
final Envelope maxAllowedExtend = getMaxExtend(); |
final Envelope maxAllowedExtend = getMaxExtend(); |
819 |
|
|
820 |
|
/* |
821 |
|
* If a maxAllowedExtend is set, we have to honour that... |
822 |
|
*/ |
823 |
|
Envelope lastCalculatedArea = null; |
824 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
825 |
&& newArea != null && !newArea.isNull() |
&& newArea != null && !newArea.isNull() |
826 |
&& !Double.isNaN(newArea.getMinX()) |
&& !Double.isNaN(newArea.getMinX()) |
827 |
&& !Double.isNaN(newArea.getMaxX()) |
&& !Double.isNaN(newArea.getMaxX()) |
828 |
&& !Double.isNaN(newArea.getMinY()) |
&& !Double.isNaN(newArea.getMinY()) |
829 |
&& !Double.isNaN(newArea.getMaxY())) { |
&& !Double.isNaN(newArea.getMaxY()) |
830 |
/* |
) // Due to Double precision problems, this may iterate for ever |
831 |
* If a maxExtend is set, we have to honour that... |
{ |
832 |
*/ |
|
833 |
|
if (newArea.equals(lastCalculatedArea)) |
834 |
|
break; |
835 |
|
// Check that we are not iterating for ever due to double precision rounding errors |
836 |
|
lastCalculatedArea = newArea; |
837 |
|
|
838 |
// Exceeds top? Move down and maybe cut |
// Exceeds top? Move down and maybe cut |
839 |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
840 |
final double divY = newArea.getMaxY() |
final double divY = newArea.getMaxY() |
938 |
.getCoordinateReferenceSystem()), false); |
.getCoordinateReferenceSystem()), false); |
939 |
} |
} |
940 |
} |
} |
941 |
|
|
942 |
|
|
943 |
} |
} |
944 |
|
|
945 |
return new ReferencedEnvelope(newArea, env |
return new ReferencedEnvelope(newArea, env |
996 |
// Remove all mapPaneListeners that have registered with us |
// Remove all mapPaneListeners that have registered with us |
997 |
mapPaneListeners.clear(); |
mapPaneListeners.clear(); |
998 |
|
|
999 |
removeMouseMotionListener(zoomMapPaneMouseListener); |
removeMouseMotionListener(xMapPaneMouseListener); |
1000 |
removeMouseListener(zoomMapPaneMouseListener); |
removeMouseListener(xMapPaneMouseListener); |
1001 |
|
|
1002 |
if (localContext != null) |
if (localContext != null) |
1003 |
getMapContext().clearLayerList(); |
getMapContext().clearLayerList(); |
1013 |
*/ |
*/ |
1014 |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
1015 |
final Point e) { |
final Point e) { |
1016 |
|
drawRectangle(graphics, startPos, e, Color.WHITE, false); |
1017 |
|
} |
1018 |
|
|
1019 |
|
/** |
1020 |
|
* Draws a rectangle in XOR mode from the origin at {@link #startPos} to the |
1021 |
|
* given point. All in screen coordinates. |
1022 |
|
*/ |
1023 |
|
protected void drawRectangle(final Graphics graphics, final Point startPos, |
1024 |
|
final Point e, Color color, boolean fill) { |
1025 |
|
|
1026 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1027 |
return; |
return; |
1037 |
if (width == 0 && height == 0) |
if (width == 0 && height == 0) |
1038 |
return; |
return; |
1039 |
|
|
1040 |
graphics.setXORMode(Color.WHITE); |
graphics.setXORMode(color); |
1041 |
|
|
1042 |
|
if (fill) { |
1043 |
|
graphics.fillRect(left, bottom, width, height); |
1044 |
|
graphics.setXORMode(Color.WHITE); |
1045 |
|
} |
1046 |
|
|
1047 |
graphics.drawRect(left, bottom, width, height); |
graphics.drawRect(left, bottom, width, height); |
1048 |
} |
} |
1049 |
|
|
1169 |
ReferencedEnvelope mapArea_ = null; |
ReferencedEnvelope mapArea_ = null; |
1170 |
try { |
try { |
1171 |
mapArea_ = localContext.getLayerBounds(); |
mapArea_ = localContext.getLayerBounds(); |
1172 |
} catch (final IOException e) { |
} catch (final Exception e) { |
1173 |
LOGGER.warn("localContext.getLayerBounds()", e); |
LOGGER.warn("localContext.getLayerBounds()", e); |
1174 |
} |
} |
1175 |
|
|
1255 |
return null; |
return null; |
1256 |
} |
} |
1257 |
|
|
1258 |
// Vergrößerung um 10% nochmal rausgenommen |
return JTSUtil |
1259 |
// // // Kartenbereich um 10% vergroessern |
.fixAspectRatio(getVisibleRect(), addDefaultMargin(layerBounds), true); |
|
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
|
|
// .expandEnvelope(layerBounds, 0.1), true); |
|
1260 |
|
|
|
return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true); |
|
1261 |
} |
} |
1262 |
return maxExtend; |
return maxExtend; |
1263 |
} |
} |
1312 |
return new AffineTransform(screenToWorld); |
return new AffineTransform(screenToWorld); |
1313 |
} |
} |
1314 |
|
|
1315 |
public int getState() { |
// public int getState() { |
1316 |
return state; |
// return state; |
1317 |
} |
// } |
1318 |
|
// |
1319 |
/** |
// /** |
1320 |
* Liefert den statisch eingestellten Cursor, der unabhaengig von der |
// * Liefert den statisch eingestellten Cursor, der unabhaengig von der |
1321 |
* eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird. |
// * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird. |
1322 |
* |
// * |
1323 |
* @return {@code null}, wenn kein statischer Cursor verwendet, sondern der |
// * @return {@code null}, wenn kein statischer Cursor verwendet, sondern |
1324 |
* Cursor automatisch je nach MapPane-Aktion eingestellt wird. |
// der |
1325 |
*/ |
// * Cursor automatisch je nach MapPane-Aktion eingestellt wird. |
1326 |
public Cursor getStaticCursor() { |
// */ |
1327 |
return this.staticCursor; |
// public Cursor getStaticCursor() { |
1328 |
} |
// return this.staticCursor; |
1329 |
|
// } |
1330 |
|
|
1331 |
public AffineTransform getWorldToScreenTransform() { |
public AffineTransform getWorldToScreenTransform() { |
1332 |
if (worldToScreen == null) { |
if (worldToScreen == null) { |
1380 |
} |
} |
1381 |
|
|
1382 |
/** |
/** |
1383 |
* Called from the listeners while the mouse is dragging, this method either |
* Usually called from {@link XMapPaneAction_Pan} to pan the image. |
|
* paints a translated (moved/panned) version of the image, or a rectangle. |
|
1384 |
* |
* |
1385 |
* @param startPos |
* @param startPos |
1386 |
* in screen coordinates |
* in screen coordinates |
1387 |
* @param lastPos |
* @param lastPos |
1388 |
* in screen coordinates |
* in screen coordinates |
|
* @param event |
|
|
* the {@link MouseEvent} to read the mouse buttons from |
|
1389 |
*/ |
*/ |
1390 |
public void mouseDragged(final Point startPos, final Point lastPos, |
public void pan(final int dX, final int dY) { |
|
final MouseEvent event) { |
|
|
|
|
|
if ((getState() == XMapPane.PAN) |
|
|
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
|
1391 |
|
|
1392 |
// Panning needs a panning coursor |
// Panning needs a panning coursor |
1393 |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
1394 |
setCursor(SwingUtil.PANNING_CURSOR); |
setCursor(SwingUtil.PANNING_CURSOR); |
1395 |
|
|
1396 |
// While panning, we deactivate the rendering. So the tasks are |
// While panning, we deactivate the rendering. So the tasks are |
1397 |
// ready to start when the panning is finished. |
// ready to start when the panning is finished. |
1398 |
if (bgExecuter != null && bgExecuter.isRunning()) |
if (bgExecuter != null && bgExecuter.isRunning()) |
1399 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1400 |
if (localExecuter.isRunning()) |
if (localExecuter.isRunning()) |
1401 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1402 |
} |
} |
1403 |
|
// |
1404 |
if (lastPos.x > 0 && lastPos.y > 0) { |
// if (lastPos.x > 0 && lastPos.y > 0) { |
1405 |
final int dx = event.getX() - lastPos.x; |
// final int dx = event.getX() - lastPos.x; |
1406 |
final int dy = event.getY() - lastPos.y; |
// final int dy = event.getY() - lastPos.y; |
1407 |
|
|
1408 |
// TODO Stop dragging when the drag would not be valid... |
// TODO Stop dragging when the drag would not be valid... |
1409 |
// boolean dragValid = true; |
// boolean dragValid = true; |
1410 |
// // check if this panning results in a valid mapArea |
// // check if this panning results in a valid mapArea |
1411 |
// { |
// { |
1412 |
// Rectangle winBounds = xMapPane.getBounds(); |
// Rectangle winBounds = xMapPane.getBounds(); |
1413 |
// winBounds.translate(xMapPane.imageOrigin.x, |
// winBounds.translate(xMapPane.imageOrigin.x, |
1414 |
// -xMapPane.imageOrigin.y); |
// -xMapPane.imageOrigin.y); |
1415 |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
1416 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1417 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1418 |
// + winBounds.height); |
// + winBounds.height); |
1419 |
// |
// |
1420 |
// |
// |
1421 |
// winBounds = xMapPane.getBounds(); |
// winBounds = xMapPane.getBounds(); |
1422 |
// Point testIng = new Point(xMapPane.imageOrigin); |
// Point testIng = new Point(xMapPane.imageOrigin); |
1423 |
// testIng.translate(dx, dy); |
// testIng.translate(dx, dy); |
1424 |
// winBounds.translate(testIng.x, -testIng.y); |
// winBounds.translate(testIng.x, -testIng.y); |
1425 |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
1426 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1427 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1428 |
// + winBounds.height); |
// + winBounds.height); |
1429 |
// |
// |
1430 |
// // If the last drag doesn't change the MapArea anymore cancel |
// // If the last drag doesn't change the MapArea anymore cancel |
1431 |
// it. |
// it. |
1432 |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
1433 |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
1434 |
// dragValid = false; |
// dragValid = false; |
1435 |
// return; |
// return; |
1436 |
// } |
// } |
1437 |
// } |
// } |
1438 |
|
|
1439 |
imageOrigin.translate(dx, dy); |
getImageOrigin().translate(dX, dY); |
1440 |
updateFinalImage(); |
updateFinalImage(); |
1441 |
repaint(); |
repaint(); |
1442 |
} |
// } |
1443 |
|
|
1444 |
} else if ((getState() == XMapPane.ZOOM_IN) |
// } else if ((getState() == XMapPane.ZOOM_IN) |
1445 |
|| (getState() == XMapPane.ZOOM_OUT) |
// || (getState() == XMapPane.ZOOM_OUT) |
1446 |
|| (getState() == XMapPane.SELECT_ALL) |
// || (getState() == XMapPane.SELECT_ALL) |
1447 |
|| (getState() == XMapPane.SELECT_TOP)) { |
// || (getState() == XMapPane.SELECT_TOP)) { |
1448 |
|
// |
1449 |
// Draws a rectangle |
// // Draws a rectangle |
1450 |
final Graphics2D graphics = (Graphics2D) getGraphics(); |
// final Graphics2D graphics = (Graphics2D) getGraphics(); |
1451 |
drawRectangle(graphics, startPos, event.getPoint()); |
// drawRectangle(graphics, startPos, event.getPoint()); |
1452 |
if ((lastPos.x > 0) && (lastPos.y > 0)) |
// if ((lastPos.x > 0) && (lastPos.y > 0)) |
1453 |
drawRectangle(graphics, startPos, lastPos); |
// drawRectangle(graphics, startPos, lastPos); |
1454 |
graphics.dispose(); |
// graphics.dispose(); |
1455 |
} |
// } |
1456 |
} |
} |
1457 |
|
|
1458 |
/** |
/** |
1472 |
*/ |
*/ |
1473 |
public void onRenderingCompleted(final long l) { |
public void onRenderingCompleted(final long l) { |
1474 |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
1475 |
// LOGGER |
// LOGGER |
1476 |
// .debug("complete rendering after " + lastRenderingDuration |
// .debug("complete rendering after " + lastRenderingDuration |
1477 |
// + "ms"); |
// + "ms"); |
1478 |
|
|
1479 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1480 |
|
|
1615 |
|
|
1616 |
} |
} |
1617 |
|
|
1618 |
/** |
// |
1619 |
* Performs a {@value #PAN} action. During panning, the displacement is |
// /** |
1620 |
* stored in {@link #imageOrigin} object. Calling {@link #performPan()} will |
// * Performs a {@value #PAN} action. During panning, the displacement is |
1621 |
* reset the offset and call {@link #setMapArea(Envelope)}. |
// * stored in {@link #imageOrigin} object. Calling {@link #performPan()} |
1622 |
*/ |
// will |
1623 |
public void performPan() { |
// * reset the offset and call {@link #setMapArea(Envelope)}. |
1624 |
|
// */ |
1625 |
final Rectangle winBounds = getVisibleRect(); |
// public void performPan() { |
1626 |
|
// |
1627 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
// final Rectangle winBounds = getVisibleRect(); |
1628 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
// |
1629 |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
// winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1630 |
+ winBounds.height); |
// final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1631 |
|
// winBounds.y, winBounds.x + winBounds.width, winBounds.y |
1632 |
imageOrigin.x = 0; |
// + winBounds.height); |
1633 |
imageOrigin.y = 0; |
// |
1634 |
|
// imageOrigin.x = 0; |
1635 |
if (!setMapArea(newMapArea)) { |
// imageOrigin.y = 0; |
1636 |
/** |
// |
1637 |
* If setMapArea returns true, the finalImage is updated anyways. |
// if (!setMapArea(newMapArea)) { |
1638 |
* This if-case exists to ensure that we repaint a correct image |
// /** |
1639 |
* even if the new panning area has been denied. |
// * If setMapArea returns true, the finalImage is updated anyways. |
1640 |
*/ |
// * This if-case exists to ensure that we repaint a correct image |
1641 |
updateFinalImage(); |
// * even if the new panning area has been denied. |
1642 |
repaint(); |
// */ |
1643 |
} |
// updateFinalImage(); |
1644 |
|
// repaint(); |
1645 |
if (getCursor() == SwingUtil.PANNING_CURSOR) |
// } |
1646 |
setCursor(SwingUtil.PAN_CURSOR); |
// |
1647 |
} |
// if (getCursor() == SwingUtil.PANNING_CURSOR) |
1648 |
|
// setCursor(SwingUtil.PAN_CURSOR); |
1649 |
|
// } |
1650 |
|
|
1651 |
/** |
/** |
1652 |
* Entfernt einen Listener von der Map. |
* Entfernt einen Listener von der Map. |
1692 |
* the current map pane extent (screen units) |
* the current map pane extent (screen units) |
1693 |
*/ |
*/ |
1694 |
private void resetTransforms() { |
private void resetTransforms() { |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
|
|
getMapContext().getCoordinateReferenceSystem()); |
|
|
|
|
1695 |
// System.out |
// System.out |
1696 |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
1697 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1698 |
return; |
return; |
1699 |
|
|
1700 |
|
if (mapArea == null) |
1701 |
|
return; |
1702 |
|
|
1703 |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1704 |
|
getMapContext().getCoordinateReferenceSystem()); |
1705 |
|
|
1706 |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1707 |
getVisibleRect()); |
getVisibleRect()); |
1708 |
|
|
1955 |
|
|
1956 |
// /** Stored the time used for the last real rendering in ms. **/ |
// /** Stored the time used for the last real rendering in ms. **/ |
1957 |
private long lastRenderingDuration = 1000; |
private long lastRenderingDuration = 1000; |
1958 |
|
private XMapPaneTool tool = null; |
1959 |
|
|
1960 |
/** |
/** |
1961 |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
1987 |
this.rendererHints = rendererHints; |
this.rendererHints = rendererHints; |
1988 |
} |
} |
1989 |
|
|
1990 |
/** |
// @Deprecated |
1991 |
* Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the |
// public void setState(final int state) { |
1992 |
* repaint Timer if |
// this.state = state; |
1993 |
* |
// |
1994 |
* @param state |
// // throw new RuntimeException("Old concept.. migrate to new concept!"); |
1995 |
*/ |
// |
1996 |
public void setState(final int state) { |
// // xMapPaneMouseListener.setEnabled((state == ZOOM_IN |
1997 |
this.state = state; |
// // || state == ZOOM_OUT || state == PAN)); |
1998 |
|
// |
1999 |
zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN |
// // Je nach Aktion den Cursor umsetzen |
2000 |
|| state == ZOOM_OUT || state == PAN)); |
// updateCursor(); |
2001 |
|
// } |
2002 |
|
|
2003 |
// Je nach Aktion den Cursor umsetzen |
public void configureMouse(MouseInputType type, XMapPaneAction action) { |
2004 |
updateCursor(); |
xMapPaneMouseListener.actions.put(type, action); |
2005 |
} |
} |
2006 |
|
|
2007 |
/** |
/** |
2008 |
* Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom, |
* Configure the {@link XMapPaneTool} that active on the map. Passing |
2009 |
* Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
* <code>null</code> will set the NO_ACTION tool. |
2010 |
* gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion |
*/ |
2011 |
* beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann |
public void setTool(XMapPaneTool tool) { |
2012 |
* {@code null} als Parameter uebergeben werden |
if (tool == null) |
2013 |
* |
tool = XMapPaneTool.NO_ACTION; |
2014 |
* @param cursor |
this.tool = tool; |
2015 |
* Cursor |
xMapPaneMouseListener.configure(tool); |
2016 |
*/ |
setCursor(tool.getCursor()); |
|
public void setStaticCursor(final Cursor cursor) { |
|
|
this.staticCursor = cursor; |
|
|
if (cursor != null) |
|
|
super.setCursor(cursor); |
|
2017 |
} |
} |
2018 |
|
|
2019 |
|
// /** |
2020 |
|
// * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion |
2021 |
|
// (Zoom, |
2022 |
|
// * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
2023 |
|
// * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion |
2024 |
|
// * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann |
2025 |
|
// * {@code null} als Parameter uebergeben werden |
2026 |
|
// * |
2027 |
|
// * @param cursor |
2028 |
|
// * Cursor |
2029 |
|
// */ |
2030 |
|
// public void setStaticCursor(final Cursor cursor) { |
2031 |
|
// this.staticCursor = cursor; |
2032 |
|
// if (cursor != null) |
2033 |
|
// super.setCursor(cursor); |
2034 |
|
// } |
2035 |
|
|
2036 |
/** |
/** |
2037 |
* Starts rendering on one or two threads |
* Starts rendering on one or two threads |
2038 |
*/ |
*/ |
2173 |
repaint(); |
repaint(); |
2174 |
} |
} |
2175 |
} |
} |
2176 |
|
// |
2177 |
// wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig |
// // |
2178 |
// von der aktuellen Aktion |
// // wenn manueller Cursor gesetzt ist, dann diesen verwenden |
2179 |
if (this.staticCursor != null) { |
// (unabhaengig |
2180 |
setCursor(staticCursor); |
// // von der aktuellen Aktion |
2181 |
return; |
// if (this.staticCursor != null) { |
2182 |
} |
// setCursor(staticCursor); |
2183 |
|
// return; |
2184 |
|
// } |
2185 |
|
// |
2186 |
if (getCursor() == SwingUtil.PANNING_CURSOR) { |
if (getCursor() == SwingUtil.PANNING_CURSOR) { |
2187 |
// This cursor will reset itself |
// This cursor will reset itself |
2188 |
return; |
return; |
2189 |
} |
} |
2190 |
|
|
2191 |
// Set the cursor depending on what tool is in use... |
setCursor(tool.getCursor()); |
2192 |
switch (state) { |
|
2193 |
case SELECT_TOP: |
// |
2194 |
case SELECT_ONE_FROM_TOP: |
// // Set the cursor depending on what tool is in use... |
2195 |
case SELECT_ALL: |
// switch (state) { |
2196 |
setCursor(SwingUtil.CROSSHAIR_CURSOR); |
// case SELECT_TOP: |
2197 |
break; |
// case SELECT_ONE_FROM_TOP: |
2198 |
case ZOOM_IN: |
// case SELECT_ALL: |
2199 |
setCursor(SwingUtil.ZOOMIN_CURSOR); |
// setCursor(SwingUtil.CROSSHAIR_CURSOR); |
2200 |
break; |
// break; |
2201 |
case ZOOM_OUT: |
// case ZOOM_IN: |
2202 |
setCursor(SwingUtil.ZOOMOUT_CURSOR); |
// setCursor(SwingUtil.ZOOMIN_CURSOR); |
2203 |
break; |
// break; |
2204 |
case PAN: |
// case ZOOM_OUT: |
2205 |
setCursor(SwingUtil.PAN_CURSOR); |
// setCursor(SwingUtil.ZOOMOUT_CURSOR); |
2206 |
break; |
// break; |
2207 |
default: |
// case PAN: |
2208 |
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
// setCursor(SwingUtil.PAN_CURSOR); |
2209 |
break; |
// break; |
2210 |
} |
// default: |
2211 |
|
// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
2212 |
|
// break; |
2213 |
|
// } |
2214 |
} |
} |
2215 |
|
|
2216 |
/** |
/** |
2240 |
|
|
2241 |
final Graphics2D finalG = getFinalImage().createGraphics(); |
final Graphics2D finalG = getFinalImage().createGraphics(); |
2242 |
finalG.setBackground(getMapBackgroundColor()); |
finalG.setBackground(getMapBackgroundColor()); |
2243 |
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y, |
finalG.drawImage(getPreFinalImage(), getImageOrigin().x, |
2244 |
getMapBackgroundColor(), null); |
getImageOrigin().y, getMapBackgroundColor(), null); |
2245 |
|
|
2246 |
// When panning, we have to clear the area around the image |
// When panning, we have to clear the area around the image |
2247 |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
final Rectangle painedArea = new Rectangle(getImageOrigin().x, |
2248 |
imageOrigin.y, getFinalImage().getWidth(), getFinalImage() |
getImageOrigin().y, getFinalImage().getWidth(), getFinalImage() |
2249 |
.getHeight()); |
.getHeight()); |
2250 |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
2251 |
getMapBackgroundColor()); |
getMapBackgroundColor()); |
2252 |
|
|
2253 |
addGadgets(finalG, false); |
addGadgets(finalG, false); |
2254 |
|
|
2255 |
finalG.dispose(); |
finalG.dispose(); |
2256 |
|
|
2411 |
// BB umrechnen von Layer-CRS in Map-CRS |
// BB umrechnen von Layer-CRS in Map-CRS |
2412 |
|
|
2413 |
// Expand a bit |
// Expand a bit |
2414 |
bounds.expandBy(bounds.getWidth() / 6., bounds.getHeight() / 6.); |
addDefaultMargin(bounds); |
2415 |
|
|
2416 |
setMapArea(bounds); |
setMapArea(bounds); |
2417 |
} |
} |
2418 |
} |
} |
2419 |
|
|
2420 |
|
private ReferencedEnvelope addDefaultMargin(ReferencedEnvelope bounds) { |
2421 |
|
return JTSUtil.expandEnvelope(bounds, Math.max(0, |
2422 |
|
defaultMaxMapExtendMode)); |
2423 |
|
} |
2424 |
|
|
2425 |
|
private Envelope addDefaultMargin(Envelope bounds) { |
2426 |
|
return JTSUtil.expandEnvelope(bounds, Math.max(0, |
2427 |
|
defaultMaxMapExtendMode)); |
2428 |
|
} |
2429 |
|
|
2430 |
/** |
/** |
2431 |
* Zooms towards a point. |
* Zooms towards a point. |
2432 |
* |
* |
2497 |
return localRenderer; |
return localRenderer; |
2498 |
} |
} |
2499 |
|
|
|
|
|
|
|
|
2500 |
/** |
/** |
2501 |
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
2502 |
* Macht nichts, wenn {@code null} uebergeben wird. |
* Macht nichts, wenn {@code null} uebergeben wird. |
2574 |
// genau auf dem Rand der angezeigten Flaeche) |
// genau auf dem Rand der angezeigten Flaeche) |
2575 |
|
|
2576 |
if (mapAreaNew != null) { |
if (mapAreaNew != null) { |
2577 |
mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew |
|
2578 |
.getHeight() * 0.1); |
mapAreaNew = addDefaultMargin(mapAreaNew); |
2579 |
setMapArea(mapAreaNew); |
setMapArea(mapAreaNew); |
2580 |
} else { |
} else { |
2581 |
LOGGER |
LOGGER |
2626 |
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
2627 |
} |
} |
2628 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2629 |
/** |
/** |
2630 |
* Aktiviert oder deaktiviert das AntiAliasing for diese |
* Aktiviert oder deaktiviert das AntiAliasing for diese |
2631 |
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
2640 |
if (java2DHints == null) { |
if (java2DHints == null) { |
2641 |
java2DHints = GeoTools.getDefaultHints(); |
java2DHints = GeoTools.getDefaultHints(); |
2642 |
} |
} |
2643 |
|
|
2644 |
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
2645 |
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
2646 |
: RenderingHints.VALUE_ANTIALIAS_OFF); |
: RenderingHints.VALUE_ANTIALIAS_OFF); |
2650 |
java2DHints.put(RenderingHints.KEY_RENDERING, |
java2DHints.put(RenderingHints.KEY_RENDERING, |
2651 |
aa ? RenderingHints.VALUE_RENDER_QUALITY |
aa ? RenderingHints.VALUE_RENDER_QUALITY |
2652 |
: RenderingHints.VALUE_RENDER_SPEED); |
: RenderingHints.VALUE_RENDER_SPEED); |
2653 |
|
|
2654 |
|
} |
2655 |
|
|
2656 |
|
public Point getImageOrigin() { |
2657 |
|
return imageOrigin; |
2658 |
|
} |
2659 |
|
|
2660 |
|
/** |
2661 |
|
* If {@link #maxExtend} is <code>null</code> the following rules are used |
2662 |
|
* to create a default maximum. |
2663 |
|
* <ul> |
2664 |
|
* <li>Values < 0 : don't grow to fit the monitors aspect ratio, no |
2665 |
|
* margin</li> |
2666 |
|
* <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li> |
2667 |
|
* <li>Values > 0 : grow to fit the monitors aspect ratio, and add a |
2668 |
|
* relative margin</li> |
2669 |
|
* </ul> |
2670 |
|
* **/ |
2671 |
|
public void setDefaultMaxMapExtendMode(double defaultMaxMapExtendMode) { |
2672 |
|
this.defaultMaxMapExtendMode = defaultMaxMapExtendMode; |
2673 |
|
} |
2674 |
|
|
2675 |
|
/** |
2676 |
|
* If {@link #maxExtend} is <code>null</code> the following rules are used |
2677 |
|
* to create a default maximum. |
2678 |
|
* <ul> |
2679 |
|
* <li>Values < 0 : don't grow to fit the monitors aspect ratio, no |
2680 |
|
* margin</li> |
2681 |
|
* <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li> |
2682 |
|
* <li>Values > 0 : grow to fit the monitors aspect ratio, and add a |
2683 |
|
* relative margin</li> |
2684 |
|
* </ul> |
2685 |
|
* **/ |
2686 |
|
public double getDefaultMaxMapExtendMode() { |
2687 |
|
return defaultMaxMapExtendMode; |
2688 |
} |
} |
2689 |
|
|
2690 |
} |
} |