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; |
36 |
import org.geotools.geometry.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
37 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
38 |
import org.geotools.map.DefaultMapContext; |
import org.geotools.map.DefaultMapContext; |
39 |
|
import org.geotools.map.DefaultMapLayer; |
40 |
import org.geotools.map.MapContext; |
import org.geotools.map.MapContext; |
41 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
42 |
import org.geotools.map.event.MapLayerEvent; |
import org.geotools.map.event.MapLayerEvent; |
49 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
50 |
import org.geotools.renderer.lite.RendererUtilities; |
import org.geotools.renderer.lite.RendererUtilities; |
51 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
52 |
|
import org.geotools.resources.image.ImageUtilities; |
53 |
|
import org.geotools.styling.Style; |
54 |
import org.geotools.swing.JMapPane; |
import org.geotools.swing.JMapPane; |
55 |
import org.geotools.swing.event.MapMouseEvent; |
import org.geotools.swing.event.MapMouseEvent; |
56 |
import org.geotools.swing.event.MapPaneEvent; |
import org.geotools.swing.event.MapPaneEvent; |
68 |
import schmitzm.geotools.io.GeoImportUtil; |
import schmitzm.geotools.io.GeoImportUtil; |
69 |
import schmitzm.geotools.map.event.JMapPaneListener; |
import schmitzm.geotools.map.event.JMapPaneListener; |
70 |
import schmitzm.geotools.map.event.MapLayerAdapter; |
import schmitzm.geotools.map.event.MapLayerAdapter; |
71 |
|
import schmitzm.geotools.styling.StylingUtil; |
72 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
73 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
74 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
75 |
|
import schmitzm.swing.event.MouseInputType; |
76 |
|
|
77 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
78 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
103 |
*/ |
*/ |
104 |
public class XMapPane extends JPanel { |
public class XMapPane extends JPanel { |
105 |
|
|
106 |
|
/** |
107 |
|
* If {@link #maxExtend} is <code>null</code> the following rules are used |
108 |
|
* to create a default maximum. |
109 |
|
* <ul> |
110 |
|
* <li>Values < 0 : don't grow to fit the monitors aspect ratio, no |
111 |
|
* margin</li> |
112 |
|
* <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li> |
113 |
|
* <li>Values > 0 : grow to fit the monitors aspect ratio, and add a |
114 |
|
* relative margin</li> |
115 |
|
* </ul> |
116 |
|
* **/ |
117 |
|
private double defaultMaxMapExtendMode = .05; |
118 |
|
|
119 |
// private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
// private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
120 |
// private static final int IMAGETYPE_withAlpha = |
// private static final int IMAGETYPE_withAlpha = |
121 |
// BufferedImage.TYPE_INT_ARGB; |
// BufferedImage.TYPE_INT_ARGB; |
122 |
private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR; |
private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR; |
123 |
|
|
124 |
|
public XMapPaneTool getTool() { |
125 |
|
return tool; |
126 |
|
} |
127 |
|
|
128 |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR; |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR; |
129 |
|
|
130 |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
131 |
|
|
132 |
|
/** |
133 |
|
* A flag indicating whether the {@link XMapPane} is accepting repaints from |
134 |
|
* the EDT. @see {@link XMapPane#setPainting(boolean)) |
135 |
|
**/ |
136 |
private boolean acceptsRepaintCalls = true; |
private boolean acceptsRepaintCalls = true; |
137 |
|
|
138 |
/** |
/** |
195 |
* Flag for no-tool. |
* Flag for no-tool. |
196 |
*/ |
*/ |
197 |
public static final int NONE = -123; |
public static final int NONE = -123; |
198 |
|
// |
199 |
/** |
// /** |
200 |
* Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
// * Flag fuer Modus "Kartenausschnitt bewegen". Nicht fuer Window-Auswahl |
201 |
* moeglich! |
// * moeglich! |
202 |
* |
// * |
203 |
* @see #setState(int) |
// * @see #setState(int) |
204 |
*/ |
// */ |
205 |
public static final int PAN = 1; |
// public static final int PAN = 1; |
206 |
|
// |
207 |
/** |
// /** |
208 |
* Flag fuer Modus "Heran zoomen". |
// * Flag fuer Modus "Heran zoomen". |
209 |
* |
// * |
210 |
* @see #setState(int) |
// * @see #setState(int) |
211 |
* @see #setState(int) |
// * @see #setState(int) |
212 |
*/ |
// */ |
213 |
public static final int ZOOM_IN = 2; |
// public static final int ZOOM_IN = 2; |
214 |
|
// |
215 |
/** |
// /** |
216 |
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
// * Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
217 |
* |
// * |
218 |
* @see #setState(int) |
// * @see #setState(int) |
219 |
*/ |
// */ |
220 |
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; |
|
221 |
|
|
222 |
/** |
/** |
223 |
* {@link Font} used to paint the wait messages into the map |
* {@link Font} used to paint the wait messages into the map |
277 |
final AffineTransform at = xMapPane.getScreenToWorld(); |
final AffineTransform at = xMapPane.getScreenToWorld(); |
278 |
if (at != null) { |
if (at != null) { |
279 |
Point2D transformed = at.transform(e.getPoint(), null); |
Point2D transformed = at.transform(e.getPoint(), null); |
280 |
return new DirectPosition2D(xMapPane.getMapContext().getCoordinateReferenceSystem(), transformed.getX(), transformed.getY()); |
return new DirectPosition2D(xMapPane.getMapContext() |
281 |
|
.getCoordinateReferenceSystem(), transformed.getX(), |
282 |
|
transformed.getY()); |
283 |
} |
} |
284 |
return null; |
return null; |
285 |
} |
} |
286 |
throw new IllegalArgumentException( |
throw new IllegalArgumentException( |
287 |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
"MouseEvent has to be of instance MapMouseEvent or come from an XMapPane"); |
288 |
} |
} |
|
|
|
|
|
|
289 |
|
|
290 |
/** |
/** |
291 |
* Listens to changes of the "background" {@link MapContext} and triggers |
* Listens to changes of the "background" {@link MapContext} and triggers |
298 |
final MapLayer layer = event.getLayer(); |
final MapLayer layer = event.getLayer(); |
299 |
layer.addMapLayerListener(bgMapLayerListener); |
layer.addMapLayerListener(bgMapLayerListener); |
300 |
requestStartRendering(); |
requestStartRendering(); |
|
|
|
301 |
} |
} |
302 |
|
|
303 |
@Override |
@Override |
391 |
* While dragging, the {@link #updateFinalImage()} method is translating the |
* While dragging, the {@link #updateFinalImage()} method is translating the |
392 |
* cached images while setting it together. |
* cached images while setting it together. |
393 |
**/ |
**/ |
394 |
Point imageOrigin = new Point(0, 0); |
private final Point imageOrigin = new Point(0, 0); |
395 |
/** |
/** |
396 |
* For every rendering thread started, |
* For every rendering thread started, |
397 |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
* {@link GTUtil#createGTRenderer(MapContext)} is called to create a new |
420 |
|
|
421 |
@Override |
@Override |
422 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
423 |
// getLocalRenderer().setContext(getMapContext()); geht doch auch ohne?!?!? wow... |
// getLocalRenderer().setContext(getMapContext()); geht doch auch |
424 |
|
// ohne?!?!? wow... |
425 |
requestStartRendering(); |
requestStartRendering(); |
426 |
} |
} |
427 |
|
|
558 |
* thread. |
* thread. |
559 |
*/ |
*/ |
560 |
final private Timer startRenderThreadsTimer; |
final private Timer startRenderThreadsTimer; |
561 |
|
// |
562 |
/** |
// /** |
563 |
* The default state is ZOOM_IN, hence by default the |
// * The default state is ZOOM_IN, hence by default the |
564 |
* {@link #zoomMapPaneMouseListener} is also enabled. |
// * {@link #xMapPaneMouseListener} is also enabled. |
565 |
**/ |
// **/ |
566 |
private int state = ZOOM_IN; |
// private int state = ZOOM_IN; |
567 |
|
// |
568 |
/** |
// /** |
569 |
* Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen |
// * Manuell gesetzter statischer Cursor, unabhaengig von der aktuellen |
570 |
* MapPane-Funktion |
// * MapPane-Funktion |
571 |
*/ |
// */ |
572 |
protected Cursor staticCursor = null; |
// protected Cursor staticCursor = null; |
573 |
|
|
574 |
private AffineTransform worldToScreen; |
private AffineTransform worldToScreen; |
575 |
|
|
576 |
|
// /** |
577 |
|
// * This {@link MouseListener} is managing all zoom related tasks |
578 |
|
// */ |
579 |
|
// private final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new |
580 |
|
// ZoomXMapPaneMouseListener( |
581 |
|
// this); |
582 |
|
|
583 |
/** |
/** |
584 |
* This {@link MouseListener} is managing all zoom related tasks |
* This {@link MouseListener} is managing all zoom related tasks |
585 |
*/ |
*/ |
586 |
public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener( |
private final XMapPaneMouseListener xMapPaneMouseListener = new XMapPaneMouseListener( |
587 |
this); |
this); |
588 |
|
|
589 |
/** Is set if a renderer has an error **/ |
/** Is set if a renderer has an error **/ |
613 |
*/ |
*/ |
614 |
public XMapPane(final MapContext localContext_, |
public XMapPane(final MapContext localContext_, |
615 |
final Map<Object, Object> rendererHints) { |
final Map<Object, Object> rendererHints) { |
616 |
|
|
617 |
super(true); |
super(true); |
618 |
|
|
619 |
|
blinkTimer = initBlinkTimer(); |
620 |
|
|
621 |
|
// A default setting |
622 |
|
RenderingHints hintsJava2d = ImageUtilities.NN_INTERPOLATION_HINT; |
623 |
|
setJava2dHints(hintsJava2d); |
624 |
|
|
625 |
setRendererHints(rendererHints); |
setRendererHints(rendererHints); |
626 |
|
|
632 |
/** |
/** |
633 |
* Adding the #zoomMapPaneMouseListener |
* Adding the #zoomMapPaneMouseListener |
634 |
*/ |
*/ |
635 |
this.addMouseListener(zoomMapPaneMouseListener); |
this.addMouseListener(xMapPaneMouseListener); |
636 |
this.addMouseMotionListener(zoomMapPaneMouseListener); |
this.addMouseMotionListener(xMapPaneMouseListener); |
637 |
this.addMouseWheelListener(zoomMapPaneMouseListener); |
this.addMouseWheelListener(xMapPaneMouseListener); |
638 |
|
|
639 |
|
// By default the XMapPAne uses the ZOOM_IN tool. |
640 |
|
setTool(XMapPaneTool.ZOOM_IN); |
641 |
|
|
642 |
/* |
/* |
643 |
* We use a Timer object to avoid rendering delays and flickering when |
* We use a Timer object to avoid rendering delays and flickering when |
747 |
|
|
748 |
} |
} |
749 |
|
|
750 |
|
|
751 |
/** |
/** |
752 |
* Fuegt der Map einen Listener hinzu. |
* Fuegt der Map einen Listener hinzu. |
753 |
* |
* |
824 |
|
|
825 |
final Envelope maxAllowedExtend = getMaxExtend(); |
final Envelope maxAllowedExtend = getMaxExtend(); |
826 |
|
|
827 |
|
// This variable is used to break the loop if it runs forever... |
828 |
|
Envelope lastCalculatedArea = null; |
829 |
|
/* |
830 |
|
* If a maxAllowedExtend is set, we have to honour that... |
831 |
|
*/ |
832 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
833 |
&& newArea != null && !newArea.isNull() |
&& newArea != null && !newArea.isNull() |
834 |
&& !Double.isNaN(newArea.getMinX()) |
&& !Double.isNaN(newArea.getMinX()) |
835 |
&& !Double.isNaN(newArea.getMaxX()) |
&& !Double.isNaN(newArea.getMaxX()) |
836 |
&& !Double.isNaN(newArea.getMinY()) |
&& !Double.isNaN(newArea.getMinY()) |
837 |
&& !Double.isNaN(newArea.getMaxY())) { |
&& !Double.isNaN(newArea.getMaxY())) // Due to Double precision |
838 |
/* |
// problems, this may |
839 |
* If a maxExtend is set, we have to honour that... |
// iterate for ever |
840 |
*/ |
{ |
841 |
|
|
842 |
|
if (newArea.equals(lastCalculatedArea)) |
843 |
|
break; |
844 |
|
// Check that we are not iterating for ever due to double precision |
845 |
|
// rounding errors |
846 |
|
lastCalculatedArea = newArea; |
847 |
|
|
848 |
// Exceeds top? Move down and maybe cut |
// Exceeds top? Move down and maybe cut |
849 |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
948 |
.getCoordinateReferenceSystem()), false); |
.getCoordinateReferenceSystem()), false); |
949 |
} |
} |
950 |
} |
} |
951 |
|
|
952 |
} |
} |
953 |
|
|
954 |
return new ReferencedEnvelope(newArea, env |
return new ReferencedEnvelope(newArea, env |
1005 |
// Remove all mapPaneListeners that have registered with us |
// Remove all mapPaneListeners that have registered with us |
1006 |
mapPaneListeners.clear(); |
mapPaneListeners.clear(); |
1007 |
|
|
1008 |
removeMouseMotionListener(zoomMapPaneMouseListener); |
removeMouseMotionListener(xMapPaneMouseListener); |
1009 |
removeMouseListener(zoomMapPaneMouseListener); |
removeMouseListener(xMapPaneMouseListener); |
1010 |
|
|
1011 |
if (localContext != null) |
if (localContext != null) |
1012 |
getMapContext().clearLayerList(); |
getMapContext().clearLayerList(); |
1022 |
*/ |
*/ |
1023 |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
protected void drawRectangle(final Graphics graphics, final Point startPos, |
1024 |
final Point e) { |
final Point e) { |
1025 |
|
drawRectangle(graphics, startPos, e, Color.WHITE, false); |
1026 |
|
} |
1027 |
|
|
1028 |
|
/** |
1029 |
|
* Draws a rectangle in XOR mode from the origin at {@link #startPos} to the |
1030 |
|
* given point. All in screen coordinates. |
1031 |
|
*/ |
1032 |
|
protected void drawRectangle(final Graphics graphics, final Point startPos, |
1033 |
|
final Point e, Color color, boolean fill) { |
1034 |
|
|
1035 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1036 |
return; |
return; |
1046 |
if (width == 0 && height == 0) |
if (width == 0 && height == 0) |
1047 |
return; |
return; |
1048 |
|
|
1049 |
graphics.setXORMode(Color.WHITE); |
graphics.setXORMode(color); |
1050 |
|
|
1051 |
|
if (fill) { |
1052 |
|
graphics.fillRect(left, bottom, width, height); |
1053 |
|
graphics.setXORMode(Color.WHITE); |
1054 |
|
} |
1055 |
|
|
1056 |
graphics.drawRect(left, bottom, width, height); |
graphics.drawRect(left, bottom, width, height); |
1057 |
} |
} |
1058 |
|
|
1178 |
ReferencedEnvelope mapArea_ = null; |
ReferencedEnvelope mapArea_ = null; |
1179 |
try { |
try { |
1180 |
mapArea_ = localContext.getLayerBounds(); |
mapArea_ = localContext.getLayerBounds(); |
1181 |
} catch (final IOException e) { |
} catch (final Exception e) { |
1182 |
LOGGER.warn("localContext.getLayerBounds()", e); |
LOGGER.warn("localContext.getLayerBounds()", e); |
1183 |
} |
} |
1184 |
|
|
1264 |
return null; |
return null; |
1265 |
} |
} |
1266 |
|
|
1267 |
// Vergrößerung um 10% nochmal rausgenommen |
return JTSUtil.fixAspectRatio(getVisibleRect(), |
1268 |
// // // Kartenbereich um 10% vergroessern |
addDefaultMargin(layerBounds), true); |
|
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
|
|
// .expandEnvelope(layerBounds, 0.1), true); |
|
1269 |
|
|
|
return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true); |
|
1270 |
} |
} |
1271 |
return maxExtend; |
return maxExtend; |
1272 |
} |
} |
1321 |
return new AffineTransform(screenToWorld); |
return new AffineTransform(screenToWorld); |
1322 |
} |
} |
1323 |
|
|
1324 |
public int getState() { |
// public int getState() { |
1325 |
return state; |
// return state; |
1326 |
} |
// } |
1327 |
|
// |
1328 |
/** |
// /** |
1329 |
* Liefert den statisch eingestellten Cursor, der unabhaengig von der |
// * Liefert den statisch eingestellten Cursor, der unabhaengig von der |
1330 |
* eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird. |
// * eingestellten MapPane-Aktion (Zoom, Auswahl, ...) verwendet wird. |
1331 |
* |
// * |
1332 |
* @return {@code null}, wenn kein statischer Cursor verwendet, sondern der |
// * @return {@code null}, wenn kein statischer Cursor verwendet, sondern |
1333 |
* Cursor automatisch je nach MapPane-Aktion eingestellt wird. |
// der |
1334 |
*/ |
// * Cursor automatisch je nach MapPane-Aktion eingestellt wird. |
1335 |
public Cursor getStaticCursor() { |
// */ |
1336 |
return this.staticCursor; |
// public Cursor getStaticCursor() { |
1337 |
} |
// return this.staticCursor; |
1338 |
|
// } |
1339 |
|
|
1340 |
public AffineTransform getWorldToScreenTransform() { |
public AffineTransform getWorldToScreenTransform() { |
1341 |
if (worldToScreen == null) { |
if (worldToScreen == null) { |
1389 |
} |
} |
1390 |
|
|
1391 |
/** |
/** |
1392 |
* 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. |
|
1393 |
* |
* |
1394 |
* @param startPos |
* @param startPos |
1395 |
* in screen coordinates |
* in screen coordinates |
1396 |
* @param lastPos |
* @param lastPos |
1397 |
* in screen coordinates |
* in screen coordinates |
|
* @param event |
|
|
* the {@link MouseEvent} to read the mouse buttons from |
|
1398 |
*/ |
*/ |
1399 |
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)) { |
|
1400 |
|
|
1401 |
// Panning needs a panning coursor |
// Panning needs a panning coursor |
1402 |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
1403 |
setCursor(SwingUtil.PANNING_CURSOR); |
setCursor(SwingUtil.PANNING_CURSOR); |
1404 |
|
|
1405 |
// While panning, we deactivate the rendering. So the tasks are |
// While panning, we deactivate the rendering. So the tasks are |
1406 |
// ready to start when the panning is finished. |
// ready to start when the panning is finished. |
1407 |
if (bgExecuter != null && bgExecuter.isRunning()) |
if (bgExecuter != null && bgExecuter.isRunning()) |
1408 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1409 |
if (localExecuter.isRunning()) |
if (localExecuter.isRunning()) |
1410 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1411 |
} |
} |
1412 |
|
// |
1413 |
if (lastPos.x > 0 && lastPos.y > 0) { |
// if (lastPos.x > 0 && lastPos.y > 0) { |
1414 |
final int dx = event.getX() - lastPos.x; |
// final int dx = event.getX() - lastPos.x; |
1415 |
final int dy = event.getY() - lastPos.y; |
// final int dy = event.getY() - lastPos.y; |
1416 |
|
|
1417 |
// TODO Stop dragging when the drag would not be valid... |
// TODO Stop dragging when the drag would not be valid... |
1418 |
// boolean dragValid = true; |
// boolean dragValid = true; |
1419 |
// // check if this panning results in a valid mapArea |
// // check if this panning results in a valid mapArea |
1420 |
// { |
// { |
1421 |
// Rectangle winBounds = xMapPane.getBounds(); |
// Rectangle winBounds = xMapPane.getBounds(); |
1422 |
// winBounds.translate(xMapPane.imageOrigin.x, |
// winBounds.translate(xMapPane.imageOrigin.x, |
1423 |
// -xMapPane.imageOrigin.y); |
// -xMapPane.imageOrigin.y); |
1424 |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaBefore = xMapPane.tranformWindowToGeo( |
1425 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1426 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1427 |
// + winBounds.height); |
// + winBounds.height); |
1428 |
// |
// |
1429 |
// |
// |
1430 |
// winBounds = xMapPane.getBounds(); |
// winBounds = xMapPane.getBounds(); |
1431 |
// Point testIng = new Point(xMapPane.imageOrigin); |
// Point testIng = new Point(xMapPane.imageOrigin); |
1432 |
// testIng.translate(dx, dy); |
// testIng.translate(dx, dy); |
1433 |
// winBounds.translate(testIng.x, -testIng.y); |
// winBounds.translate(testIng.x, -testIng.y); |
1434 |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
// Envelope newMapAreaAfter = xMapPane.tranformWindowToGeo( |
1435 |
// winBounds.x, winBounds.y, winBounds.x |
// winBounds.x, winBounds.y, winBounds.x |
1436 |
// + winBounds.width, winBounds.y |
// + winBounds.width, winBounds.y |
1437 |
// + winBounds.height); |
// + winBounds.height); |
1438 |
// |
// |
1439 |
// // If the last drag doesn't change the MapArea anymore cancel |
// // If the last drag doesn't change the MapArea anymore cancel |
1440 |
// it. |
// it. |
1441 |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
// if (xMapPane.bestAllowedMapArea(newMapAreaAfter).equals( |
1442 |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
// xMapPane.bestAllowedMapArea(newMapAreaBefore))){ |
1443 |
// dragValid = false; |
// dragValid = false; |
1444 |
// return; |
// return; |
1445 |
// } |
// } |
1446 |
// } |
// } |
1447 |
|
|
1448 |
imageOrigin.translate(dx, dy); |
getImageOrigin().translate(dX, dY); |
1449 |
updateFinalImage(); |
updateFinalImage(); |
1450 |
repaint(); |
repaint(); |
1451 |
} |
// } |
1452 |
|
|
1453 |
} else if ((getState() == XMapPane.ZOOM_IN) |
// } else if ((getState() == XMapPane.ZOOM_IN) |
1454 |
|| (getState() == XMapPane.ZOOM_OUT) |
// || (getState() == XMapPane.ZOOM_OUT) |
1455 |
|| (getState() == XMapPane.SELECT_ALL) |
// || (getState() == XMapPane.SELECT_ALL) |
1456 |
|| (getState() == XMapPane.SELECT_TOP)) { |
// || (getState() == XMapPane.SELECT_TOP)) { |
1457 |
|
// |
1458 |
// Draws a rectangle |
// // Draws a rectangle |
1459 |
final Graphics2D graphics = (Graphics2D) getGraphics(); |
// final Graphics2D graphics = (Graphics2D) getGraphics(); |
1460 |
drawRectangle(graphics, startPos, event.getPoint()); |
// drawRectangle(graphics, startPos, event.getPoint()); |
1461 |
if ((lastPos.x > 0) && (lastPos.y > 0)) |
// if ((lastPos.x > 0) && (lastPos.y > 0)) |
1462 |
drawRectangle(graphics, startPos, lastPos); |
// drawRectangle(graphics, startPos, lastPos); |
1463 |
graphics.dispose(); |
// graphics.dispose(); |
1464 |
} |
// } |
1465 |
} |
} |
1466 |
|
|
1467 |
/** |
/** |
1481 |
*/ |
*/ |
1482 |
public void onRenderingCompleted(final long l) { |
public void onRenderingCompleted(final long l) { |
1483 |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
1484 |
// LOGGER |
// LOGGER |
1485 |
// .debug("complete rendering after " + lastRenderingDuration |
// .debug("complete rendering after " + lastRenderingDuration |
1486 |
// + "ms"); |
// + "ms"); |
1487 |
|
|
1488 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1489 |
|
|
1624 |
|
|
1625 |
} |
} |
1626 |
|
|
1627 |
/** |
// |
1628 |
* Performs a {@value #PAN} action. During panning, the displacement is |
// /** |
1629 |
* stored in {@link #imageOrigin} object. Calling {@link #performPan()} will |
// * Performs a {@value #PAN} action. During panning, the displacement is |
1630 |
* reset the offset and call {@link #setMapArea(Envelope)}. |
// * stored in {@link #imageOrigin} object. Calling {@link #performPan()} |
1631 |
*/ |
// will |
1632 |
public void performPan() { |
// * reset the offset and call {@link #setMapArea(Envelope)}. |
1633 |
|
// */ |
1634 |
final Rectangle winBounds = getVisibleRect(); |
// public void performPan() { |
1635 |
|
// |
1636 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
// final Rectangle winBounds = getVisibleRect(); |
1637 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
// |
1638 |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
// winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1639 |
+ winBounds.height); |
// final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1640 |
|
// winBounds.y, winBounds.x + winBounds.width, winBounds.y |
1641 |
imageOrigin.x = 0; |
// + winBounds.height); |
1642 |
imageOrigin.y = 0; |
// |
1643 |
|
// imageOrigin.x = 0; |
1644 |
if (!setMapArea(newMapArea)) { |
// imageOrigin.y = 0; |
1645 |
/** |
// |
1646 |
* If setMapArea returns true, the finalImage is updated anyways. |
// if (!setMapArea(newMapArea)) { |
1647 |
* This if-case exists to ensure that we repaint a correct image |
// /** |
1648 |
* even if the new panning area has been denied. |
// * If setMapArea returns true, the finalImage is updated anyways. |
1649 |
*/ |
// * This if-case exists to ensure that we repaint a correct image |
1650 |
updateFinalImage(); |
// * even if the new panning area has been denied. |
1651 |
repaint(); |
// */ |
1652 |
} |
// updateFinalImage(); |
1653 |
|
// repaint(); |
1654 |
if (getCursor() == SwingUtil.PANNING_CURSOR) |
// } |
1655 |
setCursor(SwingUtil.PAN_CURSOR); |
// |
1656 |
} |
// if (getCursor() == SwingUtil.PANNING_CURSOR) |
1657 |
|
// setCursor(SwingUtil.PAN_CURSOR); |
1658 |
|
// } |
1659 |
|
|
1660 |
/** |
/** |
1661 |
* Entfernt einen Listener von der Map. |
* Entfernt einen Listener von der Map. |
1701 |
* the current map pane extent (screen units) |
* the current map pane extent (screen units) |
1702 |
*/ |
*/ |
1703 |
private void resetTransforms() { |
private void resetTransforms() { |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
|
|
getMapContext().getCoordinateReferenceSystem()); |
|
|
|
|
1704 |
// System.out |
// System.out |
1705 |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
1706 |
if (!isWellDefined()) |
if (!isWellDefined()) |
1707 |
return; |
return; |
1708 |
|
|
1709 |
|
if (mapArea == null) |
1710 |
|
return; |
1711 |
|
|
1712 |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1713 |
|
getMapContext().getCoordinateReferenceSystem()); |
1714 |
|
|
1715 |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1716 |
getVisibleRect()); |
getVisibleRect()); |
1717 |
|
|
1964 |
|
|
1965 |
// /** Stored the time used for the last real rendering in ms. **/ |
// /** Stored the time used for the last real rendering in ms. **/ |
1966 |
private long lastRenderingDuration = 1000; |
private long lastRenderingDuration = 1000; |
1967 |
|
private XMapPaneTool tool = null; |
1968 |
|
|
1969 |
|
private Timer blinkTimer ; |
1970 |
|
|
1971 |
/** |
/** |
1972 |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
1998 |
this.rendererHints = rendererHints; |
this.rendererHints = rendererHints; |
1999 |
} |
} |
2000 |
|
|
2001 |
/** |
// @Deprecated |
2002 |
* Enables/Disables the ZOOM Mouse Listener. Upates the Cursor and stops the |
// public void setState(final int state) { |
2003 |
* repaint Timer if |
// this.state = state; |
2004 |
* |
// |
2005 |
* @param state |
// // throw new RuntimeException("Old concept.. migrate to new concept!"); |
2006 |
*/ |
// |
2007 |
public void setState(final int state) { |
// // xMapPaneMouseListener.setEnabled((state == ZOOM_IN |
2008 |
this.state = state; |
// // || state == ZOOM_OUT || state == PAN)); |
2009 |
|
// |
2010 |
zoomMapPaneMouseListener.setEnabled((state == ZOOM_IN |
// // Je nach Aktion den Cursor umsetzen |
2011 |
|| state == ZOOM_OUT || state == PAN)); |
// updateCursor(); |
2012 |
|
// } |
2013 |
|
|
2014 |
// Je nach Aktion den Cursor umsetzen |
public void configureMouse(MouseInputType type, XMapPaneAction action) { |
2015 |
updateCursor(); |
xMapPaneMouseListener.actions.put(type, action); |
2016 |
} |
} |
2017 |
|
|
2018 |
/** |
/** |
2019 |
* Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion (Zoom, |
* Configure the {@link XMapPaneTool} that active on the map. Passing |
2020 |
* Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
* <code>null</code> will set the NO_ACTION tool. |
2021 |
* gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion |
*/ |
2022 |
* beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann |
public void setTool(XMapPaneTool tool) { |
2023 |
* {@code null} als Parameter uebergeben werden |
if (tool == null) |
2024 |
* |
tool = XMapPaneTool.NO_ACTION; |
2025 |
* @param cursor |
this.tool = tool; |
2026 |
* Cursor |
xMapPaneMouseListener.configure(tool); |
2027 |
*/ |
setCursor(tool.getCursor()); |
|
public void setStaticCursor(final Cursor cursor) { |
|
|
this.staticCursor = cursor; |
|
|
if (cursor != null) |
|
|
super.setCursor(cursor); |
|
2028 |
} |
} |
2029 |
|
|
2030 |
|
// /** |
2031 |
|
// * Standardmaessig wird der Cursor automatisch je nach MapPane-Aktion |
2032 |
|
// (Zoom, |
2033 |
|
// * Auswahl, ...) gesetzt. Mit dieser Methode kann ein statischer Cursor |
2034 |
|
// * gesetzt werden, der unabhaengig von der aktuellen MapPanes-Aktion |
2035 |
|
// * beibehalten wird. Um diesen statischen Cursor wieder zu entfernen, kann |
2036 |
|
// * {@code null} als Parameter uebergeben werden |
2037 |
|
// * |
2038 |
|
// * @param cursor |
2039 |
|
// * Cursor |
2040 |
|
// */ |
2041 |
|
// public void setStaticCursor(final Cursor cursor) { |
2042 |
|
// this.staticCursor = cursor; |
2043 |
|
// if (cursor != null) |
2044 |
|
// super.setCursor(cursor); |
2045 |
|
// } |
2046 |
|
|
2047 |
/** |
/** |
2048 |
* Starts rendering on one or two threads |
* Starts rendering on one or two threads |
2049 |
*/ |
*/ |
2120 |
* X-Koordinate der BIS-Position |
* X-Koordinate der BIS-Position |
2121 |
* @param py |
* @param py |
2122 |
* Y-Koordinate der BIS-Position |
* Y-Koordinate der BIS-Position |
|
* @param winToGeotransform |
|
|
* Eine Window to Geo transform. If <code>null</code>, |
|
|
* {@link #getScreenToWorld()} is used. |
|
2123 |
*/ |
*/ |
2124 |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
2125 |
final double px, final double py) { |
final double px, final double py) { |
2136 |
} |
} |
2137 |
|
|
2138 |
/** |
/** |
2139 |
|
* Transformiert einen Geo-Koordinate in eine Fenster-Koordinaten. |
2140 |
|
* |
2141 |
|
* @param x |
2142 |
|
* X-Koordinate der VON-Position |
2143 |
|
* @param y |
2144 |
|
* Y-Koordinate der VON-Position |
2145 |
|
*/ |
2146 |
|
public Point2D tranformGeoToWindow(final double x, final double y) { |
2147 |
|
return getWorldToScreenTransform().transform(new Point2D.Double(x, y), |
2148 |
|
null); |
2149 |
|
} |
2150 |
|
|
2151 |
|
/** |
2152 |
* Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten. |
* Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten. |
2153 |
* |
* |
2154 |
* @param ox |
* @param ox |
2194 |
repaint(); |
repaint(); |
2195 |
} |
} |
2196 |
} |
} |
2197 |
|
// |
2198 |
// wenn manueller Cursor gesetzt ist, dann diesen verwenden (unabhaengig |
// // |
2199 |
// von der aktuellen Aktion |
// // wenn manueller Cursor gesetzt ist, dann diesen verwenden |
2200 |
if (this.staticCursor != null) { |
// (unabhaengig |
2201 |
setCursor(staticCursor); |
// // von der aktuellen Aktion |
2202 |
return; |
// if (this.staticCursor != null) { |
2203 |
} |
// setCursor(staticCursor); |
2204 |
|
// return; |
2205 |
|
// } |
2206 |
|
// |
2207 |
if (getCursor() == SwingUtil.PANNING_CURSOR) { |
if (getCursor() == SwingUtil.PANNING_CURSOR) { |
2208 |
// This cursor will reset itself |
// This cursor will reset itself |
2209 |
return; |
return; |
2210 |
} |
} |
2211 |
|
|
2212 |
// Set the cursor depending on what tool is in use... |
setCursor(tool.getCursor()); |
2213 |
switch (state) { |
|
2214 |
case SELECT_TOP: |
// |
2215 |
case SELECT_ONE_FROM_TOP: |
// // Set the cursor depending on what tool is in use... |
2216 |
case SELECT_ALL: |
// switch (state) { |
2217 |
setCursor(SwingUtil.CROSSHAIR_CURSOR); |
// case SELECT_TOP: |
2218 |
break; |
// case SELECT_ONE_FROM_TOP: |
2219 |
case ZOOM_IN: |
// case SELECT_ALL: |
2220 |
setCursor(SwingUtil.ZOOMIN_CURSOR); |
// setCursor(SwingUtil.CROSSHAIR_CURSOR); |
2221 |
break; |
// break; |
2222 |
case ZOOM_OUT: |
// case ZOOM_IN: |
2223 |
setCursor(SwingUtil.ZOOMOUT_CURSOR); |
// setCursor(SwingUtil.ZOOMIN_CURSOR); |
2224 |
break; |
// break; |
2225 |
case PAN: |
// case ZOOM_OUT: |
2226 |
setCursor(SwingUtil.PAN_CURSOR); |
// setCursor(SwingUtil.ZOOMOUT_CURSOR); |
2227 |
break; |
// break; |
2228 |
default: |
// case PAN: |
2229 |
setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
// setCursor(SwingUtil.PAN_CURSOR); |
2230 |
break; |
// break; |
2231 |
} |
// default: |
2232 |
|
// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR)); |
2233 |
|
// break; |
2234 |
|
// } |
2235 |
} |
} |
2236 |
|
|
2237 |
/** |
/** |
2261 |
|
|
2262 |
final Graphics2D finalG = getFinalImage().createGraphics(); |
final Graphics2D finalG = getFinalImage().createGraphics(); |
2263 |
finalG.setBackground(getMapBackgroundColor()); |
finalG.setBackground(getMapBackgroundColor()); |
2264 |
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y, |
finalG.drawImage(getPreFinalImage(), getImageOrigin().x, |
2265 |
getMapBackgroundColor(), null); |
getImageOrigin().y, getMapBackgroundColor(), null); |
2266 |
|
|
2267 |
// When panning, we have to clear the area around the image |
// When panning, we have to clear the area around the image |
2268 |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
final Rectangle painedArea = new Rectangle(getImageOrigin().x, |
2269 |
imageOrigin.y, getFinalImage().getWidth(), getFinalImage() |
getImageOrigin().y, getFinalImage().getWidth(), getFinalImage() |
2270 |
.getHeight()); |
.getHeight()); |
2271 |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
2272 |
getMapBackgroundColor()); |
getMapBackgroundColor()); |
2432 |
// BB umrechnen von Layer-CRS in Map-CRS |
// BB umrechnen von Layer-CRS in Map-CRS |
2433 |
|
|
2434 |
// Expand a bit |
// Expand a bit |
2435 |
bounds.expandBy(bounds.getWidth() / 6., bounds.getHeight() / 6.); |
addDefaultMargin(bounds); |
2436 |
|
|
2437 |
setMapArea(bounds); |
setMapArea(bounds); |
2438 |
} |
} |
2439 |
} |
} |
2440 |
|
|
2441 |
|
private ReferencedEnvelope addDefaultMargin(ReferencedEnvelope bounds) { |
2442 |
|
return JTSUtil.expandEnvelope(bounds, Math.max(0, |
2443 |
|
defaultMaxMapExtendMode)); |
2444 |
|
} |
2445 |
|
|
2446 |
|
private Envelope addDefaultMargin(Envelope bounds) { |
2447 |
|
return JTSUtil.expandEnvelope(bounds, Math.max(0, |
2448 |
|
defaultMaxMapExtendMode)); |
2449 |
|
} |
2450 |
|
|
2451 |
/** |
/** |
2452 |
* Zooms towards a point. |
* Zooms towards a point. |
2453 |
* |
* |
2518 |
return localRenderer; |
return localRenderer; |
2519 |
} |
} |
2520 |
|
|
|
|
|
|
|
|
2521 |
/** |
/** |
2522 |
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
2523 |
* Macht nichts, wenn {@code null} uebergeben wird. |
* Macht nichts, wenn {@code null} uebergeben wird. |
2595 |
// genau auf dem Rand der angezeigten Flaeche) |
// genau auf dem Rand der angezeigten Flaeche) |
2596 |
|
|
2597 |
if (mapAreaNew != null) { |
if (mapAreaNew != null) { |
2598 |
mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew |
|
2599 |
.getHeight() * 0.1); |
mapAreaNew = addDefaultMargin(mapAreaNew); |
2600 |
setMapArea(mapAreaNew); |
setMapArea(mapAreaNew); |
2601 |
} else { |
} else { |
2602 |
LOGGER |
LOGGER |
2647 |
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
2648 |
} |
} |
2649 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2650 |
/** |
/** |
2651 |
* Aktiviert oder deaktiviert das AntiAliasing for diese |
* Aktiviert oder deaktiviert das AntiAliasing for diese |
2652 |
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
2661 |
if (java2DHints == null) { |
if (java2DHints == null) { |
2662 |
java2DHints = GeoTools.getDefaultHints(); |
java2DHints = GeoTools.getDefaultHints(); |
2663 |
} |
} |
2664 |
|
|
2665 |
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
2666 |
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
2667 |
: RenderingHints.VALUE_ANTIALIAS_OFF); |
: RenderingHints.VALUE_ANTIALIAS_OFF); |
2671 |
java2DHints.put(RenderingHints.KEY_RENDERING, |
java2DHints.put(RenderingHints.KEY_RENDERING, |
2672 |
aa ? RenderingHints.VALUE_RENDER_QUALITY |
aa ? RenderingHints.VALUE_RENDER_QUALITY |
2673 |
: RenderingHints.VALUE_RENDER_SPEED); |
: RenderingHints.VALUE_RENDER_SPEED); |
2674 |
|
|
2675 |
|
} |
2676 |
|
|
2677 |
|
public Point getImageOrigin() { |
2678 |
|
return imageOrigin; |
2679 |
|
} |
2680 |
|
|
2681 |
|
/** |
2682 |
|
* If {@link #maxExtend} is <code>null</code> the following rules are used |
2683 |
|
* to create a default maximum. |
2684 |
|
* <ul> |
2685 |
|
* <li>Values < 0 : don't grow to fit the monitors aspect ratio, no |
2686 |
|
* margin</li> |
2687 |
|
* <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li> |
2688 |
|
* <li>Values > 0 : grow to fit the monitors aspect ratio, and add a |
2689 |
|
* relative margin</li> |
2690 |
|
* </ul> |
2691 |
|
* **/ |
2692 |
|
public void setDefaultMaxMapExtendMode(double defaultMaxMapExtendMode) { |
2693 |
|
this.defaultMaxMapExtendMode = defaultMaxMapExtendMode; |
2694 |
|
} |
2695 |
|
|
2696 |
|
/** |
2697 |
|
* If {@link #maxExtend} is <code>null</code> the following rules are used |
2698 |
|
* to create a default maximum. |
2699 |
|
* <ul> |
2700 |
|
* <li>Values < 0 : don't grow to fit the monitors aspect ratio, no |
2701 |
|
* margin</li> |
2702 |
|
* <li>Values 0 : grow to fit the monitors aspect ratio, no margin</li> |
2703 |
|
* <li>Values > 0 : grow to fit the monitors aspect ratio, and add a |
2704 |
|
* relative margin</li> |
2705 |
|
* </ul> |
2706 |
|
* **/ |
2707 |
|
public double getDefaultMaxMapExtendMode() { |
2708 |
|
return defaultMaxMapExtendMode; |
2709 |
|
} |
2710 |
|
|
2711 |
|
|
2712 |
|
final static int BLINK_TIMER_DEPLAY = 800; |
2713 |
|
|
2714 |
|
private Timer initBlinkTimer() { |
2715 |
|
Timer timer = new Timer(BLINK_TIMER_DEPLAY, new ActionListener() { |
2716 |
|
|
2717 |
|
@Override |
2718 |
|
public void actionPerformed(ActionEvent e) { |
2719 |
|
XMapPane.this.repaint(300); |
2720 |
|
} |
2721 |
|
}); |
2722 |
|
timer.setDelay(BLINK_TIMER_DEPLAY); |
2723 |
|
timer.setRepeats(false); |
2724 |
|
return timer; |
2725 |
|
} |
2726 |
|
|
2727 |
|
/** |
2728 |
|
* Makes the given {@link FeatureCollection} bink in the map for a moment |
2729 |
|
*/ |
2730 |
|
public void blink( |
2731 |
|
FeatureCollection<SimpleFeatureType, SimpleFeature> features) { |
2732 |
|
{ |
2733 |
|
blinkTimer.stop(); |
2734 |
|
repaint(); |
2735 |
|
blinkTimer = initBlinkTimer(); |
2736 |
|
|
2737 |
|
DefaultMapContext mc = new DefaultMapContext(getMapContext() |
2738 |
|
.getCoordinateReferenceSystem()); |
2739 |
|
|
2740 |
|
Style style = StylingUtil.STYLE_FACTORY.createStyle(); |
2741 |
|
style.featureTypeStyles().add( |
2742 |
|
StylingUtil.createBlinkFeatureTypeStyle(features)); |
2743 |
|
|
2744 |
|
// style = StylingUtil.createStyleSimple(features, Color.pink, |
2745 |
|
// Color.WHITE); |
2746 |
|
|
2747 |
|
DefaultMapLayer dml = new DefaultMapLayer(features, style); |
2748 |
|
mc.addLayer(dml); |
2749 |
|
|
2750 |
|
GTRenderer renderer = new StreamingRenderer(); |
2751 |
|
|
2752 |
|
renderer.setJava2DHints(getJava2dHints()); |
2753 |
|
|
2754 |
|
renderer.setContext(mc); |
2755 |
|
|
2756 |
|
Graphics2D g2d = (Graphics2D) getGraphics(); |
2757 |
|
renderer.paint(g2d, getVisibleRect(), getMapArea()); |
2758 |
|
|
2759 |
|
blinkTimer.start(); |
2760 |
|
|
2761 |
|
} |
2762 |
|
|
2763 |
} |
} |
2764 |
|
|
2765 |
} |
} |