1 |
package gtmig.org.geotools.swing; |
package skrueger.geotools; |
2 |
|
|
3 |
import java.awt.Color; |
import java.awt.Color; |
4 |
import java.awt.Cursor; |
import java.awt.Cursor; |
21 |
import java.awt.geom.Point2D; |
import java.awt.geom.Point2D; |
22 |
import java.awt.image.BufferedImage; |
import java.awt.image.BufferedImage; |
23 |
import java.io.IOException; |
import java.io.IOException; |
24 |
|
import java.util.ArrayList; |
25 |
import java.util.HashMap; |
import java.util.HashMap; |
26 |
import java.util.Map; |
import java.util.Map; |
27 |
import java.util.Vector; |
import java.util.Vector; |
28 |
|
|
29 |
|
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.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
37 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
46 |
import org.geotools.renderer.GTRenderer; |
import org.geotools.renderer.GTRenderer; |
47 |
import org.geotools.renderer.label.LabelCacheImpl; |
import org.geotools.renderer.label.LabelCacheImpl; |
48 |
import org.geotools.renderer.lite.LabelCache; |
import org.geotools.renderer.lite.LabelCache; |
49 |
|
import org.geotools.renderer.lite.RendererUtilities; |
50 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
51 |
import org.geotools.swing.JMapPane; |
import org.geotools.swing.JMapPane; |
52 |
import org.geotools.swing.event.MapMouseEvent; |
import org.geotools.swing.event.MapMouseEvent; |
62 |
import schmitzm.geotools.GTUtil; |
import schmitzm.geotools.GTUtil; |
63 |
import schmitzm.geotools.JTSUtil; |
import schmitzm.geotools.JTSUtil; |
64 |
import schmitzm.geotools.gui.SelectableXMapPane; |
import schmitzm.geotools.gui.SelectableXMapPane; |
65 |
|
import schmitzm.geotools.io.GeoImportUtil; |
66 |
import schmitzm.geotools.map.event.JMapPaneListener; |
import schmitzm.geotools.map.event.JMapPaneListener; |
67 |
import schmitzm.geotools.map.event.MapLayerAdapter; |
import schmitzm.geotools.map.event.MapLayerAdapter; |
68 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
69 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
70 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
|
import skrueger.geotools.RenderingExecutor; |
|
71 |
|
|
72 |
import com.vividsolutions.jts.geom.Coordinate; |
import com.vividsolutions.jts.geom.Coordinate; |
73 |
import com.vividsolutions.jts.geom.Envelope; |
import com.vividsolutions.jts.geom.Envelope; |
98 |
*/ |
*/ |
99 |
public class XMapPane extends JPanel { |
public class XMapPane extends JPanel { |
100 |
|
|
101 |
private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
// private static final int IMAGETYPE = BufferedImage.TYPE_INT_RGB; |
102 |
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_INT_ARGB; |
// private static final int IMAGETYPE_withAlpha = |
103 |
|
// BufferedImage.TYPE_INT_ARGB; |
104 |
|
private static final int IMAGETYPE = BufferedImage.TYPE_3BYTE_BGR; |
105 |
|
private static final int IMAGETYPE_withAlpha = BufferedImage.TYPE_4BYTE_ABGR; |
106 |
|
|
107 |
private static Logger LOGGER = Logger.getLogger(XMapPane.class); |
private final static Logger LOGGER = Logger.getLogger(XMapPane.class); |
108 |
|
|
109 |
private boolean acceptsRepaintCalls = true; |
private boolean acceptsRepaintCalls = true; |
110 |
|
|
130 |
* regularly and {@link #repaint()}. This {@link Timer} is stopped when all |
* regularly and {@link #repaint()}. This {@link Timer} is stopped when all |
131 |
* renderers have finished. |
* renderers have finished. |
132 |
* |
* |
133 |
* @see #INITIAL_REPAINT_DELAYAL |
* @see INITIAL_REPAINT_DELAYAL |
134 |
* @see #REPEATING_REPAINT_DELAY |
* @see #REPEATING_REPAINT_DELAY |
135 |
*/ |
*/ |
136 |
final private Timer repaintTimer; |
final private Timer repaintTimer; |
139 |
* The initial delay in milliseconds until the {@link #finalImage} is |
* The initial delay in milliseconds until the {@link #finalImage} is |
140 |
* updated the first time. |
* updated the first time. |
141 |
*/ |
*/ |
142 |
public static final int INITIAL_REPAINT_DELAY = 1000; |
public static final int INITIAL_REPAINT_DELAY = 900; |
143 |
|
|
144 |
/** |
/** |
145 |
* While the {@link #bgExecuter} and {@link #localExecuter} are rendering, |
* While the {@link #bgExecuter} and {@link #localExecuter} are rendering, |
146 |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
147 |
* with previews. |
* with previews. |
148 |
*/ |
*/ |
149 |
public static final long REPEATING_REPAINT_DELAY = 500; |
public static final int REPEATING_REPAINT_DELAY = 500; |
150 |
|
|
151 |
/** |
/** |
152 |
* Default delay (milliseconds) before the map will be redrawn when resizing |
* Default delay (milliseconds) before the map will be redrawn when resizing |
153 |
* the pane. This is to avoid flickering while drag-resizing. |
* the pane. This is to avoid flickering while drag-resizing. |
154 |
|
* |
155 |
|
* @see #resizeTimer |
156 |
|
*/ |
157 |
|
public static final int DEFAULT_RESIZING_PAINT_DELAY = 600; |
158 |
|
|
159 |
|
/** |
160 |
|
* This not-repeating {@link Timer} is re-started whenever the component is |
161 |
|
* resized. That means => only if the component is not resizing for |
162 |
|
* {@link #DEFAULT_RESIZING_PAINT_DELAY} milliseconds, does the |
163 |
|
* {@link XMapPane} react. |
164 |
*/ |
*/ |
165 |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 500; |
private final Timer resizeTimer; |
166 |
|
|
167 |
|
/** |
168 |
|
* Flag for no-tool. |
169 |
|
*/ |
170 |
public static final int NONE = -123; |
public static final int NONE = -123; |
171 |
|
|
172 |
/** |
/** |
178 |
public static final int PAN = 1; |
public static final int PAN = 1; |
179 |
|
|
180 |
/** |
/** |
181 |
|
* Flag fuer Modus "Heran zoomen". |
182 |
|
* |
183 |
|
* @see #setState(int) |
184 |
|
* @see #setState(int) |
185 |
|
*/ |
186 |
|
public static final int ZOOM_IN = 2; |
187 |
|
|
188 |
|
/** |
189 |
|
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
190 |
|
* |
191 |
|
* @see #setState(int) |
192 |
|
*/ |
193 |
|
public static final int ZOOM_OUT = 3; |
194 |
|
|
195 |
|
/** |
196 |
* Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern". |
* Flag fuer Modus "SimpleFeature-Auswahl auf allen (sichtbaren) Layern". |
197 |
* |
* |
198 |
* @see #setState(int) |
* @see #setState(int) |
216 |
*/ |
*/ |
217 |
public static final int SELECT_TOP = 4; |
public static final int SELECT_TOP = 4; |
218 |
|
|
219 |
public static final Cursor WAIT_CURSOR = Cursor |
/** |
220 |
.getPredefinedCursor(Cursor.WAIT_CURSOR); |
* {@link Font} used to paint the wait messages into the map |
221 |
|
* |
222 |
final static Font waitFont = new Font("Arial", Font.BOLD, 30); |
* @see #addGadgets(Graphics2D, boolean) |
223 |
|
*/ |
224 |
|
final static Font waitFont = new Font("Arial", Font.BOLD, 28); |
225 |
|
|
226 |
/** |
/** |
227 |
* Flag fuer Modus "Heran zoomen". |
* {@link Font} used to paint error messages into the map |
228 |
* |
* |
229 |
* @see #setState(int) |
* @see #addGadgets(Graphics2D, boolean) |
|
* @see #setState(int) |
|
230 |
*/ |
*/ |
231 |
public static final int ZOOM_IN = 2; |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
232 |
|
|
233 |
/** |
/** |
234 |
* Flag fuer Modus "Heraus zoomen". Nicht fuer Window-Auswahl moeglich! |
* If last average last two renderings took more than that many ms, show the |
235 |
|
* user a scaled preview |
236 |
|
**/ |
237 |
|
private static final long PRESCALE_MINTIME = 230; |
238 |
|
|
239 |
|
/** |
240 |
|
* The wait message painted into the map while rendering is going on on |
241 |
|
* another thread. |
242 |
* |
* |
243 |
* @see #setState(int) |
* @see #addGadgets(Graphics2D, boolean) |
244 |
*/ |
*/ |
245 |
public static final int ZOOM_OUT = 3; |
final String waitMsg = SwingUtil.R("WaitMess"); |
246 |
|
|
247 |
/** |
/** |
248 |
* Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in |
* Konvertiert die Maus-Koordinaten (relativ zum <code>JMapPane</code>) in |
288 |
|
|
289 |
@Override |
@Override |
290 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
291 |
event.getLayer().addMapLayerListener(bgMapLayerListener); |
final MapLayer layer = event.getLayer(); |
292 |
|
layer.addMapLayerListener(bgMapLayerListener); |
|
if (localContext.getLayers().length == 0 |
|
|
&& bgContext.getLayers().length == 1) { // the first one and |
|
|
// localContext is |
|
|
// empty |
|
|
if (!setMapArea(localContext.getAreaOfInterest())) |
|
|
requestStartRendering(); |
|
|
return; |
|
|
} |
|
|
|
|
|
// We need to redraw, even in case that the mapArea didn't change |
|
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
293 |
requestStartRendering(); |
requestStartRendering(); |
294 |
|
|
295 |
} |
} |
296 |
|
|
297 |
@Override |
@Override |
298 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
299 |
requestStartRendering(); |
requestStartRendering(); |
300 |
} |
} |
301 |
|
|
302 |
@Override |
@Override |
303 |
public void layerMoved(final MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
304 |
requestStartRendering(); |
requestStartRendering(); |
305 |
} |
} |
306 |
|
|
308 |
public void layerRemoved(final MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
309 |
if (event.getLayer() != null) |
if (event.getLayer() != null) |
310 |
event.getLayer().removeMapLayerListener(bgMapLayerListener); |
event.getLayer().removeMapLayerListener(bgMapLayerListener); |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
311 |
requestStartRendering(); |
requestStartRendering(); |
312 |
} |
} |
313 |
}; |
}; |
314 |
|
|
315 |
/** |
/** |
316 |
* compass and icon are rendered into this image |
* This {@link RenderingExecutor} manages the creation and cancellation of |
317 |
|
* up to one {@link Thread} for rendering the {@link #localContext}. |
318 |
*/ |
*/ |
319 |
// protected BufferedImage gadgetsImage; |
private final RenderingExecutor localExecuter = new RenderingExecutor(this); |
320 |
|
|
321 |
|
/** |
322 |
|
* This {@link RenderingExecutor} manages the creation and cancellation of |
323 |
|
* up to one {@link Thread} for rendering the {@link #bgContext}. |
324 |
|
*/ |
325 |
protected RenderingExecutor bgExecuter; |
protected RenderingExecutor bgExecuter; |
326 |
|
|
327 |
/** |
/** |
328 |
* The Renderer for the LocalLayers uses this Image. When set to null, |
* The {@link #localRenderer} for the {@link #localContext} uses this |
329 |
* please dispose this {@link Graphics2D} |
* {@link Image}. |
330 |
*/ |
*/ |
331 |
private BufferedImage localImage; |
private BufferedImage localImage; |
332 |
|
|
|
private BufferedImage finalImage; |
|
333 |
/** |
/** |
334 |
* If # {@link #bgExecuter} is using {@link #bgRenderer} for the Background |
* The {@link #bgRenderer} for the {@link #bgContext} uses this |
335 |
* uses this Image. When set to null, please dispose the {@link Graphics2D} |
* {@link Image}. |
336 |
*/ |
*/ |
337 |
private BufferedImage bgImage; |
private BufferedImage bgImage; |
338 |
|
|
339 |
/** |
/** |
340 |
|
* This {@link Image} is a merge of the {@link #bgImage}, |
341 |
|
* {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is |
342 |
|
* updated with {@link #updateFinalImage()} and used for painting in |
343 |
|
* {@link #paintComponent(Graphics)} |
344 |
|
*/ |
345 |
|
private BufferedImage finalImage; |
346 |
|
|
347 |
|
/** |
348 |
* Optionally a transparent image to paint over the map in the lower right |
* Optionally a transparent image to paint over the map in the lower right |
349 |
* corner. |
* corner. |
350 |
* |
* |
361 |
|
|
362 |
@Override |
@Override |
363 |
public void layerChanged(final MapLayerEvent event) { |
public void layerChanged(final MapLayerEvent event) { |
|
// Change of SLD for example |
|
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
364 |
requestStartRendering(); |
requestStartRendering(); |
365 |
} |
} |
366 |
|
|
367 |
@Override |
@Override |
368 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
369 |
requestStartRendering(); |
requestStartRendering(); |
370 |
} |
} |
371 |
|
|
372 |
@Override |
@Override |
373 |
public void layerShown(final MapLayerEvent event) { |
public void layerShown(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
374 |
requestStartRendering(); |
requestStartRendering(); |
375 |
} |
} |
376 |
}; |
}; |
407 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
408 |
event.getLayer().addMapLayerListener(localMapLayerListener); |
event.getLayer().addMapLayerListener(localMapLayerListener); |
409 |
|
|
410 |
localRenderer.setContext(getContext()); |
getLocalRenderer().setContext(getMapContext()); |
|
|
|
|
if (localContext.getLayers().length == 1) { // the first one |
|
|
// if the Area of Interest is unset, the LayerBounds are used |
|
|
if (!setMapArea(localContext.getAreaOfInterest())) |
|
|
repaint(); |
|
|
|
|
|
return; |
|
|
} |
|
|
|
|
|
// We need to redraw, even in case that the mapArea didn't change |
|
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
411 |
requestStartRendering(); |
requestStartRendering(); |
412 |
|
|
413 |
} |
} |
414 |
|
|
415 |
@Override |
@Override |
416 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
417 |
// mapImageInvalid = true; |
// getLocalRenderer().setContext(getMapContext()); geht doch auch ohne?!?!? wow... |
|
// repaint(); |
|
|
localRenderer.setContext(getContext()); |
|
418 |
requestStartRendering(); |
requestStartRendering(); |
419 |
} |
} |
420 |
|
|
421 |
@Override |
@Override |
422 |
public void layerMoved(final MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
423 |
// mapImageInvalid = true; |
getLocalRenderer().setContext(getMapContext()); |
|
// repaint(); |
|
|
localRenderer.setContext(getContext()); |
|
424 |
requestStartRendering(); |
requestStartRendering(); |
425 |
} |
} |
426 |
|
|
428 |
public void layerRemoved(final MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
429 |
if (event.getLayer() != null) |
if (event.getLayer() != null) |
430 |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
431 |
// mapImageInvalid = true; |
getLocalRenderer().setContext(getMapContext()); |
|
// repaint(); |
|
|
localRenderer.setContext(getContext()); |
|
432 |
requestStartRendering(); |
requestStartRendering(); |
433 |
} |
} |
434 |
}; |
}; |
435 |
|
|
|
private final RenderingExecutor localExecuter = new RenderingExecutor(this); |
|
|
|
|
436 |
/** |
/** |
437 |
* Listens to each layer in the local {@link MapContext} for changes and |
* Listens to each layer in the local {@link MapContext} for changes and |
438 |
* triggers repaints. |
* triggers repaints. We don't have to listen layerChanged, because that is |
439 |
|
* already done in {@link #localContextListener} |
440 |
*/ |
*/ |
441 |
protected MapLayerListener localMapLayerListener = new MapLayerAdapter() { |
protected MapLayerListener localMapLayerListener = new MapLayerAdapter() { |
442 |
|
|
443 |
@Override |
// @Override |
444 |
public void layerChanged(final MapLayerEvent event) { |
// public void layerChanged(final MapLayerEvent event) { |
445 |
localRenderer.setContext(getContext()); // betters for SLD changes?! |
// // getLocalRenderer().setContext(getMapContext()); // betters for SLD |
446 |
// Change of SLD for example |
// // // changes?! |
447 |
// mapImageInvalid = true; |
// // requestStartRendering(); |
448 |
// repaint(); |
// } |
|
requestStartRendering(); |
|
|
} |
|
449 |
|
|
450 |
@Override |
@Override |
451 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
452 |
requestStartRendering(); |
requestStartRendering(); |
453 |
} |
} |
454 |
|
|
455 |
@Override |
@Override |
456 |
public void layerShown(final MapLayerEvent event) { |
public void layerShown(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
457 |
requestStartRendering(); |
requestStartRendering(); |
458 |
} |
} |
459 |
}; |
}; |
460 |
|
|
461 |
private final GTRenderer localRenderer = GTUtil.createGTRenderer(); |
final private GTRenderer localRenderer = GTUtil.createGTRenderer(); |
462 |
|
|
463 |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
private final GTRenderer bgRenderer = GTUtil.createGTRenderer(); |
464 |
|
|
465 |
/** |
/** |
479 |
/** |
/** |
480 |
* This color is used as the default background color when painting a map. |
* This color is used as the default background color when painting a map. |
481 |
*/ |
*/ |
482 |
private Color mapBackgroundColor = Color.WHITE; |
private Color mapBackgroundColor = null; |
483 |
|
|
484 |
/** |
/** |
485 |
* A flag indicating that the shown image is invalid and needs to be |
* A flag indicating that the shown image is invalid and needs to be |
523 |
* A flag indicating, that the image size has changed and the buffered |
* A flag indicating, that the image size has changed and the buffered |
524 |
* images are not big enough any more |
* images are not big enough any more |
525 |
**/ |
**/ |
526 |
protected boolean paneResized = false; |
protected boolean paneResized = true; |
527 |
|
|
528 |
private BufferedImage preFinalImage; |
private BufferedImage preFinalImage; |
529 |
|
|
530 |
// if null, no quick preview will be shown |
// ** if 0, no quick preview will be shown **/ |
531 |
private int quickPreviewHint = 0; |
// private int quickPreviewHint = 0; |
532 |
|
|
533 |
private Map<Object, Object> rendererHints; |
private Map<Object, Object> rendererHints = GTUtil |
534 |
|
.getDefaultGTRendererHints(getLocalRenderer()); |
535 |
|
|
536 |
|
/** |
537 |
|
* If set to <code>true</code>, the {@link #startRenderThreadsTimer} will |
538 |
|
* start rendering {@link Thread}s |
539 |
|
**/ |
540 |
private volatile Boolean requestStartRendering = false; |
private volatile Boolean requestStartRendering = false; |
541 |
|
|
|
private final Timer resizeTimer; |
|
|
|
|
|
private final int resizingPaintDelay; |
|
|
|
|
542 |
/** |
/** |
543 |
* Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten |
* Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten |
544 |
* (lat/lon) |
* (lat/lon) |
572 |
public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener( |
public final ZoomXMapPaneMouseListener zoomMapPaneMouseListener = new ZoomXMapPaneMouseListener( |
573 |
this); |
this); |
574 |
|
|
575 |
// TODO doku |
/** Is set if a renderer has an error **/ |
576 |
|
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
577 |
|
|
578 |
|
/** |
579 |
|
* If <code>true</code>, then rendering exceptions are rendererd into the |
580 |
|
* map pane |
581 |
|
**/ |
582 |
|
private boolean showExceptions = false; |
583 |
|
|
584 |
public XMapPane() { |
public XMapPane() { |
585 |
this(null, null); |
this(null, null); |
586 |
} |
} |
589 |
* full constructor extending JPanel |
* full constructor extending JPanel |
590 |
* |
* |
591 |
* @param rendererHints |
* @param rendererHints |
592 |
|
* may be <code>null</code>. Otherwise a {@link Map<Object, |
593 |
|
* Object>} of {@link RenderingHints} to override the default |
594 |
|
* from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)} |
595 |
* |
* |
|
* @param layout |
|
|
* - layout (probably shouldn't be set) |
|
|
* @param isDoubleBuffered |
|
|
* - a Swing thing I don't really understand |
|
|
* @param render |
|
|
* - what to draw the map with |
|
596 |
* @param localContext |
* @param localContext |
597 |
* - {@link MapContext} of layer to render. |
* The main {@link MapContext} to use. If <code>null</code>, an |
598 |
|
* empty {@link DefaultMapContext} will be created. |
599 |
*/ |
*/ |
600 |
public XMapPane(final MapContext localContext_, |
public XMapPane(final MapContext localContext_, |
601 |
final Map<Object, Object> rendererHints) { |
final Map<Object, Object> rendererHints) { |
605 |
|
|
606 |
setOpaque(true); |
setOpaque(true); |
607 |
|
|
|
localRenderer.setJava2DHints(getJava2dHints()); |
|
|
|
|
608 |
if (localContext_ != null) |
if (localContext_ != null) |
609 |
setLocalContext(localContext_); |
setLocalContext(localContext_); |
610 |
|
|
622 |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
623 |
* pane receives a stream of events during drag-resizing. |
* pane receives a stream of events during drag-resizing. |
624 |
*/ |
*/ |
625 |
resizingPaintDelay = DEFAULT_RESIZING_PAINT_DELAY; |
resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, |
626 |
resizeTimer = new Timer(resizingPaintDelay, new ActionListener() { |
new ActionListener() { |
|
|
|
|
public void actionPerformed(final ActionEvent e) { |
|
|
paneResized = true; |
|
627 |
|
|
628 |
if (!isWellDefined()) |
public void actionPerformed(final ActionEvent e) { |
629 |
return; |
if (!isWellDefined()) |
630 |
|
return; |
631 |
|
|
632 |
final Rectangle bounds = getVisibleRect(); |
// LOGGER.debug("resizeTimer performed"); |
633 |
|
|
634 |
final Envelope geoMapArea = tranformWindowToGeo(bounds.x, |
// final Rectangle bounds = getVisibleRect(); |
635 |
bounds.y, bounds.x + bounds.width, bounds.y |
// |
636 |
+ bounds.height); |
// System.out.println("\n\ntimer performs with bounds = " |
637 |
|
// + bounds); |
638 |
|
|
639 |
|
// final Envelope geoMapArea = tranformWindowToGeo( |
640 |
|
// bounds.x, bounds.y, bounds.x + bounds.width, |
641 |
|
// bounds.y + bounds.height); |
642 |
|
|
643 |
|
paneResized = true; |
644 |
|
if (!setMapArea(getMapArea())) { |
645 |
|
// It's important to request new rendering here. |
646 |
|
// setMapArea only returns true and only calls |
647 |
|
// requestStartRendering if the maparea has changed. |
648 |
|
// But if the component is resized, the maparea |
649 |
|
// doesn't have to change. |
650 |
|
requestStartRendering(); |
651 |
|
} |
652 |
|
|
653 |
setMapArea(bestAllowedMapArea(geoMapArea)); |
} |
654 |
} |
}); |
|
}); |
|
655 |
resizeTimer.setRepeats(false); |
resizeTimer.setRepeats(false); |
656 |
|
|
657 |
this.addComponentListener(new ComponentAdapter() { |
this.addComponentListener(new ComponentAdapter() { |
658 |
|
|
659 |
|
private Rectangle oldVisibleRect; |
660 |
|
|
661 |
@Override |
@Override |
662 |
public void componentResized(final ComponentEvent e) { |
public void componentResized(final ComponentEvent e) { |
663 |
if (bgExecuter != null) |
|
664 |
bgExecuter.cancelTask(); |
// Seems to be called twice with the same size.. |
665 |
if (localExecuter != null) |
if (oldVisibleRect != null |
666 |
localExecuter.cancelTask(); |
&& oldVisibleRect.equals(getVisibleRect())) { |
667 |
|
// LOGGER.debug("skipping resize."); |
668 |
|
return; |
669 |
|
} |
670 |
|
|
671 |
|
// LOGGER.debug("resized: " + getVisibleRect()); |
672 |
resizeTimer.restart(); |
resizeTimer.restart(); |
673 |
|
oldVisibleRect = getVisibleRect(); |
674 |
} |
} |
675 |
|
|
676 |
}); |
}); |
678 |
/* |
/* |
679 |
* Setting up the repaintTimer. Not started automatically. |
* Setting up the repaintTimer. Not started automatically. |
680 |
*/ |
*/ |
681 |
repaintTimer = new Timer((int) REPEATING_REPAINT_DELAY, |
repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() { |
682 |
new ActionListener() { |
|
683 |
|
@Override |
684 |
|
public void actionPerformed(final ActionEvent e) { |
685 |
|
if ((!localExecuter.isRunning()) |
686 |
|
&& (bgExecuter != null && !bgExecuter.isRunning())) { |
687 |
|
repaintTimer.stop(); |
688 |
|
} else { |
689 |
|
updateFinalImage(); |
690 |
|
XMapPane.this.repaint(100); |
691 |
|
|
692 |
|
} |
693 |
|
} |
694 |
|
}); |
695 |
|
|
|
@Override |
|
|
public void actionPerformed(final ActionEvent e) { |
|
|
updateFinalImage(); |
|
|
XMapPane.this.repaint(); |
|
|
} |
|
|
}); |
|
696 |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
697 |
repaintTimer.setRepeats(true); |
repaintTimer.setRepeats(true); |
698 |
|
|
710 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
711 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
712 |
} else { |
} else { |
713 |
|
// Stupidly, but we have to recheck the |
714 |
|
setMapArea(getMapArea()); |
715 |
requestStartRendering = false; |
requestStartRendering = false; |
716 |
startRendering(); |
startRendering(); |
717 |
} |
} |
744 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
745 |
* Krüger</a> |
* Krüger</a> |
746 |
*/ |
*/ |
747 |
public Envelope bestAllowedMapArea(Envelope env) { |
public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) { |
748 |
|
|
749 |
if (getWidth() == 0) |
if (getWidth() == 0) |
750 |
return env; |
return env; |
751 |
|
|
752 |
if (env == null) |
if (env == null) |
753 |
return null; |
return null; |
754 |
|
|
798 |
} |
} |
799 |
|
|
800 |
final Envelope maxAllowedExtend = getMaxExtend(); |
final Envelope maxAllowedExtend = getMaxExtend(); |
801 |
|
|
802 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
803 |
&& newArea != null && !newArea.isNull() |
&& newArea != null && !newArea.isNull() |
804 |
&& !Double.isNaN(newArea.getMinX()) |
&& !Double.isNaN(newArea.getMinX()) |
828 |
|
|
829 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
830 |
|
|
831 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
832 |
false); |
new ReferencedEnvelope(newArea, env |
833 |
|
.getCoordinateReferenceSystem()), false); |
834 |
} |
} |
835 |
} |
} |
836 |
|
|
853 |
|
|
854 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
855 |
|
|
856 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
857 |
false); |
new ReferencedEnvelope(newArea, env |
858 |
|
.getCoordinateReferenceSystem()), false); |
859 |
} |
} |
860 |
} |
} |
861 |
|
|
880 |
|
|
881 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
882 |
|
|
883 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
884 |
false); |
new ReferencedEnvelope(newArea, env |
885 |
|
.getCoordinateReferenceSystem()), false); |
886 |
} |
} |
887 |
} |
} |
888 |
|
|
907 |
|
|
908 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
909 |
|
|
910 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
911 |
false); |
new ReferencedEnvelope(newArea, env |
912 |
|
.getCoordinateReferenceSystem()), false); |
913 |
} |
} |
914 |
} |
} |
915 |
} |
} |
916 |
|
|
917 |
return newArea; |
return new ReferencedEnvelope(newArea, env |
918 |
|
.getCoordinateReferenceSystem()); |
919 |
} |
} |
920 |
|
|
921 |
/** |
/** |
943 |
bgExecuter.dispose(); |
bgExecuter.dispose(); |
944 |
} |
} |
945 |
|
|
946 |
if (localExecuter != null) { |
if (localExecuter.isRunning()) { |
947 |
int i = 0; |
int i = 0; |
948 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
949 |
while (i++ < 10 && localExecuter.isRunning()) { |
while (i++ < 10 && localExecuter.isRunning()) { |
950 |
try { |
try { |
951 |
Thread.sleep(200); |
Thread.sleep(200); |
952 |
} catch (final InterruptedException e) { |
} catch (final InterruptedException e) { |
953 |
// TODO Auto-generated catch block |
LOGGER |
954 |
e.printStackTrace(); |
.warn( |
955 |
|
"while XMapPane we are waiting for the localExcutor to stop", |
956 |
|
e); |
957 |
} |
} |
958 |
} |
} |
959 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
960 |
System.out |
LOGGER |
961 |
.println("BAD BAD BAD... still running the thread...."); |
.warn("localExecutor Thread still running after 2s! Continuing anyways..."); |
962 |
} |
} |
963 |
localExecuter.dispose(); |
localExecuter.dispose(); |
964 |
} |
} |
|
// |
|
|
// if (bgImage != null) { |
|
|
// bgImage = dispose(bgImage); |
|
|
// bgImage = null; |
|
|
// // LangUtil.gcTotal(); |
|
|
// } |
|
|
// |
|
|
// if (localImage != null) { |
|
|
// localImage = dispose(localImage); |
|
|
// localImage = null; |
|
|
// // LangUtil.gcTotal(); |
|
|
// } |
|
|
// |
|
|
// if (finalImage != null) { |
|
|
// finalImage = dispose(finalImage); |
|
|
// finalImage = null; |
|
|
// // LangUtil.gcTotal(); |
|
|
// } |
|
|
// |
|
|
// if (preFinalImage != null) { |
|
|
// preFinalImage = dispose(preFinalImage); |
|
|
// preFinalImage = null; |
|
|
// } |
|
|
disposeImages(); |
|
965 |
|
|
966 |
// LangUtil.gcTotal(); |
disposeImages(); |
967 |
|
|
968 |
// Alle mapPaneListener entfernen |
// Remove all mapPaneListeners that have registered with us |
969 |
mapPaneListeners.clear(); |
mapPaneListeners.clear(); |
970 |
|
|
971 |
removeMouseMotionListener(zoomMapPaneMouseListener); |
removeMouseMotionListener(zoomMapPaneMouseListener); |
972 |
removeMouseListener(zoomMapPaneMouseListener); |
removeMouseListener(zoomMapPaneMouseListener); |
973 |
|
|
974 |
if (localContext != null) |
if (localContext != null) |
975 |
getContext().clearLayerList(); |
getMapContext().clearLayerList(); |
976 |
if (bgContext != null) |
if (bgContext != null) |
977 |
getBgContext().clearLayerList(); |
getBgContext().clearLayerList(); |
978 |
|
|
1012 |
* |
* |
1013 |
* @param g |
* @param g |
1014 |
* Graphics2D to paint the preview into |
* Graphics2D to paint the preview into |
|
* |
|
|
* @param state |
|
|
* Max be {@link #ZOOM_IN} or {@link #ZOOM_OUT} |
|
1015 |
*/ |
*/ |
1016 |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
1017 |
|
|
1018 |
if (quickPreviewHint == 0) |
// if (1 == 1)return false; |
1019 |
return false; |
// if (quickPreviewHint == 0) |
1020 |
|
// return false; |
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
|
|
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
|
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
|
|
RenderingHints.VALUE_ANTIALIAS_OFF); |
|
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
|
|
RenderingHints.VALUE_RENDER_SPEED); |
|
1021 |
|
|
1022 |
if (oldMapArea == null) |
if (oldMapArea == null) |
1023 |
return false; |
return false; |
1024 |
|
|
1025 |
|
if (getPreFinalImage() == null) |
1026 |
|
return false; |
1027 |
|
|
1028 |
final Rectangle visibleArea = getVisibleRect(); |
final Rectangle visibleArea = getVisibleRect(); |
1029 |
|
|
1030 |
// Calculate the oldMapArea in the current WindowCoordinates: |
// Calculate the oldMapArea in the current WindowCoordinates: |
1031 |
final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(), |
final Envelope oldMapWindow = tranformGeoToWindow(oldMapArea.getMinX(), |
1032 |
oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea |
oldMapArea.getMinY(), oldMapArea.getMaxX(), oldMapArea |
1033 |
.getMaxY(), null); |
.getMaxY()); |
1034 |
|
|
1035 |
final int xx1 = (int) Math.round(oldMapWindow.getMinX()); |
final int xx1 = (int) Math.round(oldMapWindow.getMinX()); |
1036 |
final int yy1 = (int) Math.round(oldMapWindow.getMinY()); |
final int yy1 = (int) Math.round(oldMapWindow.getMinY()); |
1037 |
final int xx2 = (int) Math.round(oldMapWindow.getMaxX()); |
final int xx2 = (int) Math.round(oldMapWindow.getMaxX()); |
1038 |
final int yy2 = (int) Math.round(oldMapWindow.getMaxY()); |
final int yy2 = (int) Math.round(oldMapWindow.getMaxY()); |
1039 |
|
|
1040 |
|
graphics.setRenderingHint(RenderingHints.KEY_INTERPOLATION, |
1041 |
|
RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR); |
1042 |
|
graphics.setRenderingHint(RenderingHints.KEY_ANTIALIASING, |
1043 |
|
RenderingHints.VALUE_ANTIALIAS_OFF); |
1044 |
|
graphics.setRenderingHint(RenderingHints.KEY_RENDERING, |
1045 |
|
RenderingHints.VALUE_RENDER_SPEED); |
1046 |
|
|
1047 |
graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2, |
graphics.drawImage(getPreFinalImage(), xx1, yy1, xx2, yy2, |
1048 |
(int) visibleArea.getMinX(), (int) visibleArea.getMinY(), |
(int) visibleArea.getMinX(), (int) visibleArea.getMinY(), |
1049 |
(int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(), |
(int) visibleArea.getMaxX(), (int) visibleArea.getMaxY(), |
1052 |
final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 |
final Rectangle painedArea = new Rectangle(xx1, yy1, xx2 - xx1, yy2 |
1053 |
- yy1); |
- yy1); |
1054 |
|
|
1055 |
SwingUtil.clearAround(graphics, painedArea, visibleArea); |
SwingUtil.clearAround(graphics, painedArea, visibleArea, |
1056 |
|
getMapBackgroundColor()); |
1057 |
|
|
1058 |
addGadgets(graphics); |
addGadgets(graphics, true); |
1059 |
|
|
1060 |
quickPreviewHint = 0; |
// quickPreviewHint = 0; |
1061 |
|
|
1062 |
graphics.dispose(); |
repaintTimer.restart(); |
1063 |
|
|
1064 |
// Something has been drawn |
// Something has been drawn |
1065 |
return true; |
return true; |
1073 |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
1074 |
*/ |
*/ |
1075 |
private Image getBgImage() { |
private Image getBgImage() { |
1076 |
// |
if (bgImage == null) { |
1077 |
// if (bgImage == null) { |
bgImage = new BufferedImage(getVisibleRect().width, |
1078 |
// bgImage = createImage(getBounds().width, getBounds().height); |
getVisibleRect().height, IMAGETYPE); |
1079 |
// } |
SwingUtil.clearImage(finalImage, getMapBackgroundColor()); |
1080 |
|
} |
1081 |
|
|
1082 |
return bgImage; |
return bgImage; |
1083 |
} |
} |
1084 |
|
|
1085 |
public MapContext getContext() { |
public MapContext getMapContext() { |
1086 |
if (localContext == null) { |
if (localContext == null) { |
1087 |
setLocalContext(new DefaultMapContext()); |
setLocalContext(new DefaultMapContext()); |
1088 |
} |
} |
1093 |
// |
// |
1094 |
if (finalImage == null) { |
if (finalImage == null) { |
1095 |
// Rectangle curPaintArea = getVisibleRect(); |
// Rectangle curPaintArea = getVisibleRect(); |
1096 |
finalImage = new BufferedImage(getBounds().width, |
finalImage = new BufferedImage(getVisibleRect().width, |
1097 |
getBounds().height, IMAGETYPE); |
getVisibleRect().height, IMAGETYPE); |
1098 |
|
SwingUtil.clearImage(finalImage, getMapBackgroundColor()); |
1099 |
|
|
1100 |
requestStartRendering(); |
// requestStartRendering(); |
1101 |
} |
} |
1102 |
return finalImage; |
return finalImage; |
1103 |
} |
} |
1104 |
|
|
|
public RenderingHints getJava2dHints() { |
|
|
return java2dHints; |
|
|
} |
|
|
|
|
1105 |
/** |
/** |
1106 |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
* Lazyly initializes a {@link BufferedImage} for the background renderer. |
1107 |
*/ |
*/ |
1108 |
private BufferedImage getLocalImage() { |
private BufferedImage getLocalImage() { |
1109 |
|
|
1110 |
if (localImage == null) { |
if (localImage == null) { |
1111 |
localImage = new BufferedImage(getBounds().width, |
localImage = new BufferedImage(getVisibleRect().width, |
1112 |
getBounds().height, IMAGETYPE_withAlpha); |
getVisibleRect().height, IMAGETYPE_withAlpha); |
1113 |
|
SwingUtil.clearImage(localImage, getMapBackgroundColor()); |
1114 |
} |
} |
1115 |
|
|
1116 |
return localImage; |
return localImage; |
1121 |
* |
* |
1122 |
* @return |
* @return |
1123 |
*/ |
*/ |
1124 |
public Envelope getMapArea() { |
public ReferencedEnvelope getMapArea() { |
1125 |
if (mapArea == null) { |
if (mapArea == null) { |
1126 |
ReferencedEnvelope mapArea_ = null; |
ReferencedEnvelope mapArea_ = null; |
1127 |
try { |
try { |
1128 |
mapArea_ = localContext.getLayerBounds(); |
mapArea_ = localContext.getLayerBounds(); |
1129 |
} catch (final IOException e) { |
} catch (final IOException e) { |
1130 |
LOGGER.warn("context.getLayerBounds()", e); |
LOGGER.warn("localContext.getLayerBounds()", e); |
1131 |
|
} |
1132 |
|
|
1133 |
|
if (mapArea_ == null && bgContext != null) { |
1134 |
|
try { |
1135 |
|
mapArea_ = bgContext.getLayerBounds(); |
1136 |
|
} catch (final IOException e) { |
1137 |
|
LOGGER.warn("bgContext.getLayerBounds()", e); |
1138 |
|
} |
1139 |
} |
} |
1140 |
|
|
1141 |
if (mapArea_ != null) { |
if (mapArea_ != null) { |
|
mapImageInvalid = true; /* note we need to redraw */ |
|
|
// setMapArea(mapArea_); // results in a loop |
|
1142 |
mapArea = bestAllowedMapArea(mapArea_); |
mapArea = bestAllowedMapArea(mapArea_); |
1143 |
|
requestStartRendering(); |
1144 |
} |
} |
1145 |
} |
} |
1146 |
|
|
1147 |
if (mapArea == null) |
if (mapArea == null) |
1148 |
return null; |
return null; |
1149 |
|
|
1150 |
return new Envelope(mapArea); |
// TODO is needed at all, this should go to setMapArea maybe |
1151 |
|
if (localContext.getCoordinateReferenceSystem() == null) |
1152 |
|
try { |
1153 |
|
localContext.setCoordinateReferenceSystem(GeoImportUtil |
1154 |
|
.getDefaultCRS()); |
1155 |
|
} catch (final Exception e) { |
1156 |
|
throw new RuntimeException("setting context CRS:", e); |
1157 |
|
} |
1158 |
|
|
1159 |
|
return new ReferencedEnvelope(mapArea, localContext |
1160 |
|
.getCoordinateReferenceSystem()); |
1161 |
} |
} |
1162 |
|
|
1163 |
/** |
/** |
1164 |
* Returns the background {@link Color} of the map pane. Default is white. |
* Returns the background {@link Color} of the map pane. If not set, the |
1165 |
|
* methods looks for a parent component and will use its background color. |
1166 |
|
* If no parent component is available, WHITE is returned. |
1167 |
**/ |
**/ |
1168 |
public Color getMapBackgroundColor() { |
public Color getMapBackgroundColor() { |
1169 |
|
if (mapBackgroundColor == null) { |
1170 |
|
if (getParent() != null) |
1171 |
|
return getParent().getBackground(); |
1172 |
|
else |
1173 |
|
return Color.WHITE; |
1174 |
|
} |
1175 |
return mapBackgroundColor; |
return mapBackgroundColor; |
1176 |
} |
} |
1177 |
|
|
1198 |
|
|
1199 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1200 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1201 |
|
|
1202 |
|
// The next command may take long time! |
1203 |
|
// long start = System.currentTimeMillis(); |
1204 |
final ReferencedEnvelope layerBounds = GTUtil |
final ReferencedEnvelope layerBounds = GTUtil |
1205 |
.getVisibleLayoutBounds(localContext); |
.getVisibleLayoutBounds(localContext); |
1206 |
|
// |
1207 |
|
// LOGGER.info( |
1208 |
|
// (System.currentTimeMillis()-start)+"m to get maxExtend"); |
1209 |
|
// |
1210 |
if (layerBounds == null) { |
if (layerBounds == null) { |
1211 |
// TODO Last fallback could be the CRS valid area |
// // TODO Last fallback could be the CRS valid area |
1212 |
return null; |
return null; |
1213 |
} |
} |
1214 |
|
|
1215 |
// Kartenbereich um 10% vergroessern |
// Vergrößerung um 10% nochmal rausgenommen |
1216 |
return JTSUtil.fixAspectRatio(this.getBounds(), JTSUtil |
// // // Kartenbereich um 10% vergroessern |
1217 |
.expandEnvelope(layerBounds, 0.1), true); |
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
1218 |
|
// .expandEnvelope(layerBounds, 0.1), true); |
1219 |
|
|
1220 |
|
return JTSUtil.fixAspectRatio(getVisibleRect(), layerBounds, true); |
1221 |
} |
} |
1222 |
return maxExtend; |
return maxExtend; |
1223 |
} |
} |
1245 |
} |
} |
1246 |
|
|
1247 |
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(); |
|
|
// } |
|
1248 |
return preFinalImage; |
return preFinalImage; |
1249 |
} |
} |
1250 |
|
|
1251 |
public Map<Object, Object> getRendererHints() { |
public Map<Object, Object> getRendererHints() { |
1252 |
|
// Clear label cache |
1253 |
|
labelCache.clear(); |
1254 |
|
rendererHints.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
1255 |
|
|
1256 |
return rendererHints; |
return rendererHints; |
1257 |
} |
} |
1258 |
|
|
1321 |
* {@link XMapPane} is visible and has bounds set. |
* {@link XMapPane} is visible and has bounds set. |
1322 |
*/ |
*/ |
1323 |
public boolean isWellDefined() { |
public boolean isWellDefined() { |
|
|
|
1324 |
try { |
try { |
1325 |
|
if (getMapContext() == null) |
|
if (getContext() == null) |
|
|
return false; |
|
|
if (getContext().getLayerCount() <= 0) |
|
1326 |
return false; |
return false; |
1327 |
if (getMapArea() == null) |
if (getMapContext().getLayerCount() <= 0) |
1328 |
return false; |
return false; |
1329 |
if (getBounds().getWidth() == 0) |
if (getVisibleRect().getWidth() == 0) |
1330 |
return false; |
return false; |
1331 |
if (getBounds().getHeight() == 0) |
if (getVisibleRect().getHeight() == 0) |
1332 |
return false; |
return false; |
1333 |
|
// if (getMapArea() == null) |
1334 |
|
// return false; |
1335 |
} catch (final Exception e) { |
} catch (final Exception e) { |
1336 |
return false; |
return false; |
1337 |
} |
} |
1338 |
return true; |
return true; |
1339 |
} |
} |
1340 |
|
|
1341 |
|
/** |
1342 |
|
* Called from the listeners while the mouse is dragging, this method either |
1343 |
|
* paints a translated (moved/panned) version of the image, or a rectangle. |
1344 |
|
* |
1345 |
|
* @param startPos |
1346 |
|
* in screen coordinates |
1347 |
|
* @param lastPos |
1348 |
|
* in screen coordinates |
1349 |
|
* @param event |
1350 |
|
* the {@link MouseEvent} to read the mouse buttons from |
1351 |
|
*/ |
1352 |
public void mouseDragged(final Point startPos, final Point lastPos, |
public void mouseDragged(final Point startPos, final Point lastPos, |
1353 |
final MouseEvent event) { |
final MouseEvent event) { |
1354 |
|
|
1355 |
if ((getState() == XMapPane.PAN) |
if ((getState() == XMapPane.PAN) |
1356 |
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
|| ((event.getModifiersEx() & InputEvent.BUTTON3_DOWN_MASK) != 0)) { |
1357 |
|
|
1358 |
|
// Panning needs a panning coursor |
1359 |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
if (getCursor() != SwingUtil.PANNING_CURSOR) { |
1360 |
setCursor(SwingUtil.PANNING_CURSOR); |
setCursor(SwingUtil.PANNING_CURSOR); |
1361 |
|
|
1362 |
// While panning, we deactivate the rendering. So the tasts are |
// While panning, we deactivate the rendering. So the tasks are |
1363 |
// ready to start when the panning os done. |
// ready to start when the panning is finished. |
1364 |
if (bgExecuter != null) |
if (bgExecuter != null && bgExecuter.isRunning()) |
1365 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1366 |
if (localExecuter != null) |
if (localExecuter.isRunning()) |
1367 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1368 |
} |
} |
1369 |
|
|
1410 |
} else if ((getState() == XMapPane.ZOOM_IN) |
} else if ((getState() == XMapPane.ZOOM_IN) |
1411 |
|| (getState() == XMapPane.ZOOM_OUT) |
|| (getState() == XMapPane.ZOOM_OUT) |
1412 |
|| (getState() == XMapPane.SELECT_ALL) |
|| (getState() == XMapPane.SELECT_ALL) |
1413 |
|| (getState() == XMapPane.SELECT_TOP) |
|| (getState() == XMapPane.SELECT_TOP)) { |
|
// || (getState() == XMapPane.SELECT_ONE_FROM_TOP) |
|
|
) { |
|
|
final Graphics graphics = getGraphics(); |
|
1414 |
|
|
1415 |
|
// Draws a rectangle |
1416 |
|
final Graphics2D graphics = (Graphics2D) getGraphics(); |
1417 |
drawRectangle(graphics, startPos, event.getPoint()); |
drawRectangle(graphics, startPos, event.getPoint()); |
1418 |
|
if ((lastPos.x > 0) && (lastPos.y > 0)) |
|
if ((lastPos.x > 0) && (lastPos.y > 0)) { |
|
1419 |
drawRectangle(graphics, startPos, lastPos); |
drawRectangle(graphics, startPos, lastPos); |
|
} |
|
|
|
|
1420 |
graphics.dispose(); |
graphics.dispose(); |
|
|
|
1421 |
} |
} |
|
|
|
1422 |
} |
} |
1423 |
|
|
1424 |
/** |
/** |
1425 |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
1426 |
*/ |
*/ |
1427 |
public void onRenderingCancelled() { |
public void onRenderingCancelled() { |
1428 |
|
// LOGGER.debug("Rendering cancelled"); |
1429 |
repaintTimer.stop(); |
repaintTimer.stop(); |
|
LOGGER.debug("Rendering cancelled"); |
|
1430 |
} |
} |
1431 |
|
|
1432 |
/** |
/** |
1433 |
* Called by the {@link RenderingExecutor} when rendering has been |
* Called by the {@link RenderingExecutor} when rendering has been |
1434 |
* completed. |
* completed. |
1435 |
|
* |
1436 |
|
* @param l |
1437 |
|
* long ms the rendering took |
1438 |
*/ |
*/ |
1439 |
public void onRenderingCompleted() { |
public void onRenderingCompleted(final long l) { |
1440 |
|
lastRenderingDuration = (lastRenderingDuration + l) / 2; |
1441 |
|
LOGGER |
1442 |
|
.debug("complete rendering after " + lastRenderingDuration |
1443 |
|
+ "ms"); |
1444 |
|
|
1445 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1446 |
|
|
1447 |
|
// We "forget" about an exception every time we complete a rendering |
1448 |
|
// thread successfully |
1449 |
|
if (renderingErrors.size() > 0) |
1450 |
|
renderingErrors.remove(0); |
1451 |
|
|
1452 |
updateFinalImage(); |
updateFinalImage(); |
1453 |
repaint(); |
repaint(); |
1454 |
} |
} |
1464 |
* @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent) |
* @see MapPaneListener#onRenderingStopped(org.geotools.swing.event.MapPaneEvent) |
1465 |
*/ |
*/ |
1466 |
public void onRenderingFailed(final Exception renderingError) { |
public void onRenderingFailed(final Exception renderingError) { |
1467 |
|
|
1468 |
|
// Store the exceptions so we can show it to the user: |
1469 |
|
if (!(renderingError instanceof java.lang.IllegalArgumentException && renderingError |
1470 |
|
.getMessage().equals( |
1471 |
|
"Argument \"sourceCRS\" should not be null."))) |
1472 |
|
this.renderingErrors.add(renderingError); |
1473 |
|
if (renderingErrors.size() > 3) |
1474 |
|
renderingErrors.remove(0); |
1475 |
|
|
1476 |
repaintTimer.stop(); |
repaintTimer.stop(); |
1477 |
|
|
1478 |
LOGGER.warn("Rendering failed", renderingError); |
LOGGER.warn("Rendering failed", renderingError); |
1479 |
updateFinalImage(); |
updateFinalImage(); |
1480 |
repaint(); |
repaint(); |
1481 |
|
|
1482 |
} |
} |
1483 |
|
|
|
public void onRenderingPending() { |
|
|
// LOGGER.debug("Pending rendering updates the preview..."); |
|
|
updateFinalImage(); |
|
|
repaint(); |
|
|
} |
|
|
|
|
1484 |
@Override |
@Override |
1485 |
protected void paintComponent(final Graphics g) { |
protected void paintComponent(final Graphics g) { |
|
if (!acceptsRepaintCalls) |
|
|
return; |
|
1486 |
|
|
1487 |
// Maybe update the cursor and maybe stop the repainting timer |
// Maybe update the cursor and maybe stop the repainting timer |
1488 |
updateCursor(); |
updateCursor(); |
1489 |
|
|
1490 |
super.paintComponent(g); // candidate for removal |
if (!acceptsRepaintCalls) |
1491 |
|
return; |
1492 |
|
|
1493 |
|
if (!isWellDefined()) |
1494 |
|
return; |
1495 |
|
// |
1496 |
|
// if (paneResized) { |
1497 |
|
// // ((Graphics2D) g).setBackground(getMapBackgroundColor()); |
1498 |
|
// // g.clearRect(0, 0, getVisibleRect().width, |
1499 |
|
// getVisibleRect().height); |
1500 |
|
// return; |
1501 |
|
// } |
1502 |
|
|
1503 |
|
// super.paintComponent(g); // candidate for removal |
1504 |
|
|
1505 |
boolean paintedSomething = false; |
boolean paintedSomething = false; |
1506 |
|
|
1511 |
// If the new mapArea and the oldMapArea intersect, we can draw some |
// If the new mapArea and the oldMapArea intersect, we can draw some |
1512 |
// quick scaled preview to make the user feel that something is |
// quick scaled preview to make the user feel that something is |
1513 |
// happening. |
// happening. |
1514 |
if (mapAreaChanged && oldMapArea != null |
if (lastRenderingDuration > PRESCALE_MINTIME && mapAreaChanged |
1515 |
|
&& oldMapArea != null |
1516 |
&& getMapArea().intersects(oldMapArea) |
&& getMapArea().intersects(oldMapArea) |
1517 |
& !getMapArea().equals(oldMapArea)) { |
&& !getMapArea().equals(oldMapArea) && !paneResized) { |
1518 |
|
|
1519 |
mapAreaChanged = false; |
mapAreaChanged = false; |
1520 |
|
|
1521 |
if (getMapArea().covers(oldMapArea)) { |
// if (getMapArea().covers(oldMapArea)) { |
1522 |
setQuickPreviewHint(ZOOM_OUT); |
// // quickPreviewHint = ZOOM_OUT; |
1523 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
// paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) |
1524 |
} else if (oldMapArea.covers(getMapArea())) { |
// g); |
1525 |
setQuickPreviewHint(ZOOM_IN); |
// } else if (oldMapArea.covers(getMapArea())) { |
1526 |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
// quickPreviewHint = ZOOM_IN; |
1527 |
} |
paintedSomething = drawScaledPreviewImage_Zoom((Graphics2D) g); |
1528 |
|
// } |
|
} |
|
|
|
|
|
if (paneResized) { |
|
|
paneResized = false; |
|
|
disposeImages(); |
|
1529 |
} |
} |
|
|
|
|
// Start the Threads and Timers to render the image |
|
|
requestStartRendering(); |
|
|
|
|
1530 |
} |
} |
1531 |
|
|
1532 |
if (!paintedSomething) { |
if (!paintedSomething) { |
1533 |
|
|
1534 |
g.drawImage(getFinalImage(), 0, 0, null); |
g.drawImage(getFinalImage(), 0, 0, null); |
1535 |
|
|
|
g.dispose(); // cand. for removal |
|
|
|
|
1536 |
paintedSomething = true; // cand. for removal |
paintedSomething = true; // cand. for removal |
1537 |
} |
} |
1538 |
|
|
1588 |
*/ |
*/ |
1589 |
public void performPan() { |
public void performPan() { |
1590 |
|
|
1591 |
final Rectangle winBounds = getBounds(); |
final Rectangle winBounds = getVisibleRect(); |
1592 |
|
|
1593 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1594 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1595 |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
1612 |
setCursor(SwingUtil.PAN_CURSOR); |
setCursor(SwingUtil.PAN_CURSOR); |
1613 |
} |
} |
1614 |
|
|
|
// |
|
|
// /** |
|
|
// * Nuetzlich wenn die Componente gedruckt (z.B. wenn ein Screenshot |
|
|
// gemacht |
|
|
// * wird) wird. Dann werden wird der Hintergrund auf WEISS gesetzt. |
|
|
// * |
|
|
// * @author <a href="mailto:[email protected]">Stefan Alfons |
|
|
// * Krüger</a> |
|
|
// */ |
|
|
// @Override |
|
|
// public void print(final Graphics g) { |
|
|
// final Color orig = getBackground(); |
|
|
// setBackground(Color.WHITE); |
|
|
// |
|
|
// // wrap in try/finally so that we always restore the state |
|
|
// try { |
|
|
// super.print(g); |
|
|
// } finally { |
|
|
// setBackground(orig); |
|
|
// } |
|
|
// } |
|
|
|
|
1615 |
/** |
/** |
1616 |
* Entfernt einen Listener von der Map. |
* Entfernt einen Listener von der Map. |
1617 |
* |
* |
1630 |
private void requestStartRendering() { |
private void requestStartRendering() { |
1631 |
if (bgExecuter != null) |
if (bgExecuter != null) |
1632 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1633 |
if (localExecuter != null) |
|
1634 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1635 |
|
|
1636 |
|
mapImageInvalid = true; |
1637 |
|
if (paneResized) { |
1638 |
|
paneResized = false; |
1639 |
|
disposeImages(); |
1640 |
|
} |
1641 |
requestStartRendering = true; |
requestStartRendering = true; |
1642 |
|
|
1643 |
} |
} |
1644 |
|
|
1645 |
/** |
/** |
1646 |
* Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten |
* Calculate the affine transforms used to convert between world and pixel |
1647 |
* neu. |
* coordinates. The calculations here are very basic and assume a cartesian |
1648 |
*/ |
* reference system. |
1649 |
protected void resetTransforms() { |
* <p> |
1650 |
if (getMapArea() == null || getWidth() == 0 || getHeight() == 0) |
* Tne transform is calculated such that {@code envelope} will be centred in |
1651 |
return; |
* the display |
1652 |
|
* |
1653 |
|
* @param envelope |
1654 |
|
* the current map extent (world coordinates) |
1655 |
|
* @param paintArea |
1656 |
|
* the current map pane extent (screen units) |
1657 |
|
*/ |
1658 |
|
private void resetTransforms() { |
1659 |
|
final ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1660 |
|
getMapContext().getCoordinateReferenceSystem()); |
1661 |
|
|
1662 |
// We store the last Transform |
// System.out |
1663 |
oldScreenToWorld = screenToWorld; |
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
1664 |
|
if (!isWellDefined()) |
1665 |
|
return; |
1666 |
|
|
1667 |
this.screenToWorld = new AffineTransform( |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1668 |
// Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten |
getVisibleRect()); |
|
// nach rechts (Osten) hin groesser |
|
|
// --> positive Verschiebung |
|
|
getMapArea().getWidth() / getWidth(), |
|
|
// keine Verzerrung |
|
|
0.0, 0.0, |
|
|
// Waehrend die Fenster-Koordinaten nach unten hin groesser |
|
|
// werden, |
|
|
// werden Latitude-Koordinaten nach Sueden hin keiner |
|
|
// --> negative Verschiebung |
|
|
-getMapArea().getHeight() / getHeight(), |
|
|
// Die Longitude-Koordinaten werden nach Osten hin groesser |
|
|
// --> obere linke Ecke des Fensters hat also den Minimalwert |
|
|
getMapArea().getMinX(), |
|
|
// Die Latitude-Koordinaten werden nach Norden hin groesser |
|
|
// --> obere linke Ecke des Fensters hat also den Maximalwert |
|
|
getMapArea().getMaxY()); |
|
1669 |
|
|
1670 |
try { |
try { |
1671 |
this.worldToScreen = screenToWorld.createInverse(); |
screenToWorld = worldToScreen.createInverse(); |
1672 |
} catch (final NoninvertibleTransformException e) { |
|
1673 |
LOGGER.error(e); |
} catch (final NoninvertibleTransformException ex) { |
1674 |
|
LOGGER |
1675 |
|
.error("can't invert worldToScreen to get screenToWorld!", |
1676 |
|
ex); |
1677 |
} |
} |
1678 |
} |
} |
1679 |
|
|
1692 |
this.bgContext = context; |
this.bgContext = context; |
1693 |
|
|
1694 |
if (context != null) { |
if (context != null) { |
1695 |
setMapArea(bgContext.getAreaOfInterest()); |
// setMapArea(bgContext.getAreaOfInterest()); |
1696 |
|
|
1697 |
this.bgContext.addMapLayerListListener(bgContextListener); |
this.bgContext.addMapLayerListListener(bgContextListener); |
1698 |
|
|
1701 |
mapLayer.addMapLayerListener(bgMapLayerListener); |
mapLayer.addMapLayerListener(bgMapLayerListener); |
1702 |
} |
} |
1703 |
} |
} |
1704 |
mapImageInvalid = true; |
|
1705 |
repaint(); |
requestStartRendering(); |
1706 |
} |
} |
1707 |
|
|
1708 |
public void setJava2dHints(final RenderingHints java2dHints) { |
public void setJava2dHints(final RenderingHints java2dHints) { |
1709 |
this.java2dHints = java2dHints; |
this.java2dHints = java2dHints; |
1710 |
} |
} |
1711 |
|
|
|
/** |
|
|
* |
|
|
* @param context |
|
|
*/ |
|
1712 |
public void setLocalContext(final MapContext context) { |
public void setLocalContext(final MapContext context) { |
1713 |
// Remove the default listener from the old context |
// Remove the default listener from the old context |
1714 |
if (this.localContext != null) { |
if (this.localContext != null) { |
1724 |
|
|
1725 |
if (context != null) { |
if (context != null) { |
1726 |
|
|
1727 |
setMapArea(localContext.getAreaOfInterest()); |
// setMapArea(localContext.getAreaOfInterest()); |
1728 |
|
|
1729 |
localRenderer.setContext(localContext); |
getLocalRenderer().setContext(localContext); |
1730 |
|
|
1731 |
this.localContext.addMapLayerListListener(localContextListener); |
this.localContext.addMapLayerListListener(localContextListener); |
1732 |
|
|
1736 |
} |
} |
1737 |
} |
} |
1738 |
|
|
1739 |
|
requestStartRendering(); |
1740 |
|
|
1741 |
|
} |
1742 |
|
|
1743 |
|
public void setBorder(final Border b) { |
1744 |
|
super.setBorder(b); |
1745 |
|
} |
1746 |
|
|
1747 |
|
/** |
1748 |
|
* Triggers to repaint (fast) and re-render (slow) the JMapPane. |
1749 |
|
*/ |
1750 |
|
public void refresh() { |
1751 |
mapImageInvalid = true; |
mapImageInvalid = true; |
1752 |
repaint(); |
repaint(); |
1753 |
} |
} |
1754 |
|
|
1755 |
|
// /** |
1756 |
|
// * Triggers to use new {@link GTRenderer} and refresh the map. Should be |
1757 |
|
// * called after {@link Style}s have been changed because GTRenderer is |
1758 |
|
// * otherwise not working well. |
1759 |
|
// */ |
1760 |
|
// public void refreshRenderers() { |
1761 |
|
// localRenderer = GTUtil.createGTRenderer(); |
1762 |
|
// setLocalContext(getMapContext()); |
1763 |
|
// mapImageInvalid = true; |
1764 |
|
// repaint(); |
1765 |
|
// } |
1766 |
|
|
1767 |
/** |
/** |
1768 |
|
* Set the new map area. |
1769 |
|
* |
1770 |
* @param newMapArea |
* @param newMapArea |
1771 |
* @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 |
1772 |
* has been triggered. |
* has been triggered. |
1773 |
*/ |
*/ |
1774 |
public boolean setMapArea(final Envelope newMapArea) { |
public boolean setMapArea(final Envelope newMapArea) { |
1775 |
|
if (newMapArea == null) |
1776 |
|
return false; |
1777 |
|
if (getMapContext().getCoordinateReferenceSystem() == null) |
1778 |
|
return false; |
1779 |
|
return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext() |
1780 |
|
.getCoordinateReferenceSystem())); |
1781 |
|
} |
1782 |
|
|
1783 |
|
/** |
1784 |
|
* Set the new map area. |
1785 |
|
* |
1786 |
|
* @param newMapArea |
1787 |
|
* @return <code>true</code> if the mapArea has been changed and a repaint |
1788 |
|
* has been triggered. |
1789 |
|
*/ |
1790 |
|
public boolean setMapArea(final ReferencedEnvelope newMapArea) { |
1791 |
|
|
1792 |
if (newMapArea == null |
if (newMapArea == null |
1793 |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
1806 |
return false; |
return false; |
1807 |
} |
} |
1808 |
|
|
1809 |
|
final Envelope candNew = bestAllowedMapArea(newMapArea); |
1810 |
|
|
1811 |
// Testing, whether the difference if just minimal |
// Testing, whether the difference if just minimal |
1812 |
if (mapArea != null) { |
if (mapArea != null) { |
|
final Envelope candNew = bestAllowedMapArea(newMapArea); |
|
1813 |
final double tolX = mapArea.getWidth() / 1000.; |
final double tolX = mapArea.getWidth() / 1000.; |
1814 |
final double tolY = mapArea.getHeight() / 1000.; |
final double tolY = mapArea.getHeight() / 1000.; |
1815 |
if ((candNew.getMinX() - tolX < mapArea.getMinX()) |
if ((candNew.getMinX() - tolX < mapArea.getMinX()) |
1829 |
} |
} |
1830 |
} |
} |
1831 |
|
|
1832 |
|
// New map are is accepted: |
1833 |
oldMapArea = mapArea; |
oldMapArea = mapArea; |
1834 |
|
mapArea = candNew; |
1835 |
this.mapArea = bestAllowedMapArea(newMapArea); |
resetTransforms(); |
1836 |
|
|
1837 |
if (localContext != null) { |
if (localContext != null) { |
1838 |
localContext.setAreaOfInterest(mapArea, localContext |
localContext.setAreaOfInterest(mapArea, localContext |
1842 |
bgContext.setAreaOfInterest(mapArea, localContext |
bgContext.setAreaOfInterest(mapArea, localContext |
1843 |
.getCoordinateReferenceSystem()); |
.getCoordinateReferenceSystem()); |
1844 |
} |
} |
1845 |
resetTransforms(); |
|
|
mapImageInvalid = true; |
|
1846 |
mapAreaChanged = true; |
mapAreaChanged = true; |
|
repaint(); |
|
1847 |
|
|
1848 |
// LOGGER.debug("New maparea = " + mapArea); |
repaint(200); // Do not remove it! |
1849 |
|
|
1850 |
|
requestStartRendering(); |
1851 |
|
|
1852 |
return true; |
return true; |
1853 |
} |
} |
1854 |
|
|
1857 |
* |
* |
1858 |
* @param if <code>null</code>, white is used. |
* @param if <code>null</code>, white is used. |
1859 |
*/ |
*/ |
1860 |
public void setMapBackgroundColor(Color bgColor) { |
public void setMapBackgroundColor(final Color bgColor) { |
|
if (bgColor == null) |
|
|
bgColor = Color.WHITE; |
|
1861 |
this.mapBackgroundColor = bgColor; |
this.mapBackgroundColor = bgColor; |
1862 |
} |
} |
1863 |
|
|
1915 |
} |
} |
1916 |
|
|
1917 |
// /** Stored the time used for the last real rendering in ms. **/ |
// /** Stored the time used for the last real rendering in ms. **/ |
1918 |
// private long lastRenderingDuration = Long.MAX_VALUE; |
private long lastRenderingDuration = 1000; |
1919 |
|
|
1920 |
/** |
/** |
1921 |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
1932 |
} |
} |
1933 |
|
|
1934 |
/** |
/** |
1935 |
* |
* If <code>true</code>, allow the {@link XMapPane} to process #repaint() |
1936 |
* @param b |
* requests. Otherwise the map will not paint anything and not start any |
1937 |
|
* rendering {@link Thread}s. |
1938 |
*/ |
*/ |
1939 |
public void setPainting(final boolean b) { |
public void setPainting(final boolean b) { |
1940 |
acceptsRepaintCalls = b; |
acceptsRepaintCalls = b; |
1941 |
} |
if (acceptsRepaintCalls == true) |
1942 |
|
repaint(); |
|
// /** |
|
|
// * Returns in milli seconds the time the last rending of the |
|
|
// * {@link SelectableXMapPane} took. #Long.MAX_VALUE if the JMapPane has |
|
|
// not |
|
|
// * been rendered yet. |
|
|
// */ |
|
|
// public long getLastRenderingDuration() { |
|
|
// return lastRenderingDuration; |
|
|
// } |
|
|
|
|
|
public void setQuickPreviewHint(final int quickPreviewHint) { |
|
|
this.quickPreviewHint = quickPreviewHint; |
|
|
|
|
1943 |
} |
} |
1944 |
|
|
1945 |
private void setRendererHints(final Map<Object, Object> rendererHints) { |
private void setRendererHints(final Map<Object, Object> rendererHints) { |
1946 |
this.rendererHints = rendererHints; |
if (rendererHints != null) |
1947 |
|
this.rendererHints = rendererHints; |
1948 |
} |
} |
1949 |
|
|
1950 |
/** |
/** |
1984 |
*/ |
*/ |
1985 |
private void startRendering() { |
private void startRendering() { |
1986 |
|
|
1987 |
if (!isWellDefined()) |
if (!isWellDefined() || !acceptsRepaintCalls) { |
1988 |
|
// if we are not ready to start rendering, try it again the next |
1989 |
|
// time the timer is chacking the flag. |
1990 |
|
requestStartRendering = true; |
1991 |
return; |
return; |
1992 |
|
} |
1993 |
|
|
1994 |
if (bgExecuter != null) { |
if (bgExecuter != null) { |
1995 |
// Stop all renderers |
// Stop all renderers |
1996 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1997 |
} |
} |
1998 |
|
|
1999 |
if (localExecuter != null) { |
localExecuter.cancelTask(); |
|
localExecuter.cancelTask(); |
|
|
} |
|
2000 |
|
|
2001 |
final Rectangle curPaintArea = getVisibleRect(); |
final Rectangle curPaintArea = getVisibleRect(); |
2002 |
|
|
2005 |
*/ |
*/ |
2006 |
|
|
2007 |
if (getBgContext() != null) { |
if (getBgContext() != null) { |
2008 |
|
bgRenderer.setJava2DHints(getJava2dHints()); |
2009 |
|
bgRenderer.setRendererHints(getRendererHints()); |
2010 |
|
|
2011 |
// bgExecuter = new RenderingExecutor(); |
// bgExecuter = new RenderingExecutor(); |
2012 |
// LOGGER.debug("starting bg renderer:"); |
// LOGGER.debug("starting bg renderer:"); |
2013 |
// // /* System.out.println("rendering"); */ |
// // /* System.out.println("rendering"); */ |
2019 |
// (Graphics2D) getBgImage().getGraphics(), createGTRenderer); |
// (Graphics2D) getBgImage().getGraphics(), createGTRenderer); |
2020 |
} |
} |
2021 |
|
|
2022 |
if (getContext() != null) { |
if (getMapContext() != null) { |
2023 |
// localExecuter = new RenderingExecutor(this, 150l); |
// localExecuter = new RenderingExecutor(this, 150l); |
2024 |
// LOGGER.debug("starting local renderer:"); |
// LOGGER.debug("starting local renderer:"); |
2025 |
|
|
2026 |
// Clear label cache |
getLocalRenderer().setJava2DHints(getJava2dHints()); |
2027 |
labelCache.clear(); |
getLocalRenderer().setRendererHints(getRendererHints()); |
2028 |
final Map<Object, Object> rh = localRenderer.getRendererHints(); |
|
2029 |
rh.put(StreamingRenderer.LABEL_CACHE_KEY, labelCache); |
final boolean submitted = localExecuter.submit(getMapArea(), |
2030 |
localRenderer.setRendererHints(rh); |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
2031 |
|
getLocalRenderer()); |
|
final boolean submitted = localExecuter.submit(getContext() |
|
|
.getAreaOfInterest(), curPaintArea, |
|
|
(Graphics2D) getLocalImage().getGraphics(), localRenderer, |
|
|
getWorldToScreenTransform()); |
|
2032 |
if (submitted) |
if (submitted) |
2033 |
repaintTimer.restart(); |
repaintTimer.restart(); |
2034 |
else |
else |
2035 |
requestStartRendering = true; // Try to start rendering again in |
requestStartRendering = true; // Try to start rendering |
2036 |
|
// again in |
2037 |
// a moment |
// a moment |
2038 |
} |
} |
2039 |
|
|
2040 |
updateCursor(); |
updateCursor(); |
2041 |
} |
} |
2042 |
|
|
2043 |
|
private RenderingHints getJava2dHints() { |
2044 |
|
return java2dHints; |
2045 |
|
} |
2046 |
|
|
2047 |
/** |
/** |
2048 |
* Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten. |
* Transformiert einen Geo-Koordinaten-Bereich in Fenster-Koordinaten. |
2049 |
* |
* |
2060 |
* {@link #getScreenToWorld()} is used. |
* {@link #getScreenToWorld()} is used. |
2061 |
*/ |
*/ |
2062 |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
2063 |
final double px, final double py, |
final double px, final double py) { |
2064 |
final AffineTransform winToGeotransform) { |
final AffineTransform at = getWorldToScreenTransform(); |
|
final AffineTransform at = winToGeotransform == null ? getScreenToWorld() |
|
|
: winToGeotransform; |
|
2065 |
Point2D geoO; |
Point2D geoO; |
2066 |
try { |
// try { |
2067 |
geoO = at.inverseTransform(new Point2D.Double(ox, oy), null); |
geoO = at.transform(new Point2D.Double(ox, oy), null); |
2068 |
final Point2D geoP = at.inverseTransform( |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
2069 |
new Point2D.Double(px, py), null); |
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY()); |
2070 |
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP |
// } catch (final NoninvertibleTransformException e) { |
2071 |
.getY()); |
// LOGGER.error(e); |
2072 |
} catch (final NoninvertibleTransformException e) { |
// return new Envelope(ox, oy, px, py); |
2073 |
LOGGER.error(e); |
// } |
|
return new Envelope(ox, oy, px, py); |
|
|
} |
|
2074 |
} |
} |
2075 |
|
|
2076 |
/** |
/** |
2090 |
final AffineTransform at = getScreenToWorld(); |
final AffineTransform at = getScreenToWorld(); |
2091 |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
2092 |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
2093 |
return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY()); |
|
2094 |
|
// Mmmmm... don't really understand why its x,x,y,y |
2095 |
|
// return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), |
2096 |
|
// geoP.getY()); |
2097 |
|
return new Envelope(new Coordinate(geoO.getX(), geoO.getY()), |
2098 |
|
new Coordinate(geoP.getX(), geoP.getY())); |
2099 |
} |
} |
2100 |
|
|
2101 |
/** |
/** |
2107 |
// if the renderers have stopped, also stop the timer that is updating |
// if the renderers have stopped, also stop the timer that is updating |
2108 |
// the final image |
// the final image |
2109 |
if (bgExecuter != null && bgExecuter.isRunning() |
if (bgExecuter != null && bgExecuter.isRunning() |
2110 |
|| localExecuter != null && localExecuter.isRunning()) { |
|| localExecuter.isRunning()) { |
2111 |
setCursor(WAIT_CURSOR); |
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR)); |
2112 |
return; |
return; |
2113 |
} else { |
} else { |
2114 |
// Allow one last rendering |
// Allow one last rendering |
2115 |
if (repaintTimer.isRunning()) { |
if (repaintTimer.isRunning()) { |
2116 |
|
// System.out.println("one last rendering...."); |
2117 |
repaintTimer.stop(); |
repaintTimer.stop(); |
2118 |
updateFinalImage(); |
updateFinalImage(); |
2119 |
repaint(); |
repaint(); |
2183 |
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y, |
finalG.drawImage(getPreFinalImage(), imageOrigin.x, imageOrigin.y, |
2184 |
getMapBackgroundColor(), null); |
getMapBackgroundColor(), null); |
2185 |
|
|
2186 |
final int finalImageHeight = getFinalImage().getHeight(null); |
// When panning, we have to clear the area around the image |
|
final int finalImageWidth = getFinalImage().getWidth(null); |
|
|
|
|
2187 |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
final Rectangle painedArea = new Rectangle(imageOrigin.x, |
2188 |
imageOrigin.y, finalImageWidth, finalImageHeight); |
imageOrigin.y, getFinalImage().getWidth(), getFinalImage() |
2189 |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect()); |
.getHeight()); |
2190 |
|
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
2191 |
|
getMapBackgroundColor()); |
2192 |
|
|
2193 |
addGadgets(finalG); |
addGadgets(finalG, false); |
2194 |
|
|
2195 |
finalG.dispose(); |
finalG.dispose(); |
2196 |
|
|
2200 |
/** |
/** |
2201 |
* Paints some optional stuff into the given {@link Graphics2D}. Usually |
* Paints some optional stuff into the given {@link Graphics2D}. Usually |
2202 |
* called as the last layer when {@link #updateFinalImage()} |
* called as the last layer when {@link #updateFinalImage()} |
2203 |
|
* |
2204 |
|
* @param forceWait |
2205 |
|
* if <code>true</code>, a Wait-message will be painted even |
2206 |
|
* though the rendering threads may not yet have started. If |
2207 |
|
* <code>false</code>, it will only depend on |
2208 |
|
* {@link #localExecuter.isRunning} and #bgExecuter.isRunning |
2209 |
*/ |
*/ |
2210 |
private void addGadgets(final Graphics2D graphics) { |
private void addGadgets(final Graphics2D graphics, final boolean forceWait) { |
2211 |
|
|
2212 |
// Paint a logo to the bottom right if available |
// Paint a logo to the bottom right if available |
2213 |
if (mapImage != null) { |
if (mapImage != null) { |
2214 |
graphics.drawImage(mapImage, getBounds().width |
final Rectangle visibleRect = getVisibleRect(); |
2215 |
- mapImage.getWidth() - 10, getBounds().height |
graphics.drawImage(mapImage, visibleRect.width |
2216 |
|
- mapImage.getWidth() - 10, getVisibleRect().height |
2217 |
- mapImage.getHeight() - 10, null); |
- mapImage.getHeight() - 10, null); |
2218 |
} |
} |
2219 |
|
|
2220 |
|
int y = 17; |
2221 |
|
|
2222 |
// If the rendering process is still running, indicate this is the image |
// If the rendering process is still running, indicate this is the image |
2223 |
if (bgExecuter != null && bgExecuter.isRunning() |
if (forceWait || bgExecuter != null && bgExecuter.isRunning() |
2224 |
|| localExecuter != null && localExecuter.isRunning()) { |
|| localExecuter.isRunning()) { |
2225 |
|
|
2226 |
|
y += 8; |
2227 |
|
|
2228 |
final Color c = graphics.getColor(); |
final Color c = graphics.getColor(); |
2229 |
graphics.setFont(waitFont); |
graphics.setFont(waitFont); |
2230 |
String waitStr = "Wait..."; //i8n |
|
2231 |
|
graphics.setColor(getMapBackgroundColor()); |
2232 |
graphics.setColor(Color.WHITE); |
graphics.drawString(waitMsg, 5, y); |
2233 |
graphics.drawString(waitStr, 39, 69); |
graphics.setColor(getMapBackgroundColor()); |
2234 |
|
graphics.drawString(waitMsg, 7, y + 2); |
2235 |
graphics.setColor(Color.BLACK); |
graphics.setColor(Color.BLACK); |
2236 |
graphics.drawString(waitStr, 40, 70); |
graphics.drawString(waitMsg, 6, y + 1); |
2237 |
|
|
2238 |
|
graphics.setColor(c); |
2239 |
|
|
2240 |
|
y += 21; |
2241 |
|
} |
2242 |
|
|
2243 |
|
if (!renderingErrors.isEmpty() && isShowExceptions()) { |
2244 |
|
|
2245 |
|
final Color c = graphics.getColor(); |
2246 |
|
graphics.setFont(errorFont); |
2247 |
|
|
2248 |
|
for (final Exception ex : renderingErrors) { |
2249 |
|
|
2250 |
|
String errStr = ex.getLocalizedMessage(); |
2251 |
|
|
2252 |
|
if (errStr == null) |
2253 |
|
errStr = ex.getMessage(); |
2254 |
|
if (errStr == null) |
2255 |
|
errStr = "unknown error: " + ex.getClass().getSimpleName(); |
2256 |
|
|
2257 |
|
graphics.setColor(getMapBackgroundColor()); |
2258 |
|
graphics.drawString(errStr, 5, y); |
2259 |
|
graphics.setColor(Color.RED); |
2260 |
|
graphics.drawString(errStr, 6, y + 1); |
2261 |
|
|
2262 |
|
y += 19; |
2263 |
|
} |
2264 |
|
|
2265 |
graphics.setColor(c); |
graphics.setColor(c); |
2266 |
} |
} |
2268 |
} |
} |
2269 |
|
|
2270 |
/** |
/** |
2271 |
* Sets the {@link #mapArea} to best possibly present the given features. If only one |
* Sets the {@link #mapArea} to best possibly present the given features. If |
2272 |
* single point is given, the window is moved over the point. |
* only one single point is given, the window is moved over the point. |
2273 |
* |
* |
2274 |
* @param features |
* @param features |
2275 |
* if <code>null</code> or size==0, the function doesn nothing. |
* if <code>null</code> or size==0, the function doesn nothing. |
2277 |
public void zoomTo( |
public void zoomTo( |
2278 |
final FeatureCollection<SimpleFeatureType, SimpleFeature> features) { |
final FeatureCollection<SimpleFeatureType, SimpleFeature> features) { |
2279 |
|
|
2280 |
final CoordinateReferenceSystem mapCRS = getContext() |
// if (!isWellDefined()) return; |
2281 |
|
|
2282 |
|
final CoordinateReferenceSystem mapCRS = getMapContext() |
2283 |
.getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2284 |
final CoordinateReferenceSystem fCRS = features.getSchema() |
final CoordinateReferenceSystem fCRS = features.getSchema() |
2285 |
.getGeometryDescriptor().getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2286 |
|
|
2287 |
double width = mapArea.getWidth(); |
ReferencedEnvelope _mapArea; |
2288 |
double height = mapArea.getHeight(); |
if (mapArea == null) |
2289 |
|
_mapArea = features.getBounds(); |
2290 |
|
else |
2291 |
|
_mapArea = getMapArea(); |
2292 |
|
double width = _mapArea.getWidth(); |
2293 |
|
double height = _mapArea.getHeight(); |
2294 |
final double ratio = height / width; |
final double ratio = height / width; |
2295 |
|
|
2296 |
if (features == null || features.size() == 0) { |
if (features == null || features.size() == 0) { |
2342 |
} else { |
} else { |
2343 |
final ReferencedEnvelope fBounds = features.getBounds(); |
final ReferencedEnvelope fBounds = features.getBounds(); |
2344 |
|
|
2345 |
Envelope bounds; |
ReferencedEnvelope bounds; |
2346 |
if (!mapCRS.equals(fCRS)) { |
if (!mapCRS.equals(fCRS)) { |
2347 |
bounds = JTSUtil.transformEnvelope(fBounds, fCRS, mapCRS); |
bounds = JTSUtil.transformEnvelope(fBounds, mapCRS); |
2348 |
} else { |
} else { |
2349 |
bounds = fBounds; |
bounds = fBounds; |
2350 |
} |
} |
2400 |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
2401 |
.getHeight()) / 2.); |
.getHeight()) / 2.); |
2402 |
|
|
2403 |
// Move the newMapArea above the new center |
// // Move the newMapArea above the new center if we zoom in: |
2404 |
newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
if (zoomFaktor >= 1) { |
2405 |
.getY() |
newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
2406 |
- mapArea.centre().y); |
.getY() |
2407 |
|
- mapArea.centre().y); |
2408 |
|
} |
2409 |
|
|
2410 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2411 |
} |
} |
2412 |
|
|
2413 |
|
/** |
2414 |
|
* Shall non-fatal rendering exceptions be reported in the mappane or be |
2415 |
|
* dropped quitely. |
2416 |
|
*/ |
2417 |
|
public void setShowExceptions(final boolean showExceptions) { |
2418 |
|
this.showExceptions = showExceptions; |
2419 |
|
} |
2420 |
|
|
2421 |
|
/** |
2422 |
|
* Shall exceptions be reported in the mappane? |
2423 |
|
*/ |
2424 |
|
public boolean isShowExceptions() { |
2425 |
|
return showExceptions; |
2426 |
|
} |
2427 |
|
|
2428 |
|
public GTRenderer getLocalRenderer() { |
2429 |
|
return localRenderer; |
2430 |
|
} |
2431 |
|
|
2432 |
|
|
2433 |
|
|
2434 |
|
/** |
2435 |
|
* Setzt den Kartenausschnitt auf die Ausdehnung eines bestimmten Layers. |
2436 |
|
* Macht nichts, wenn {@code null} uebergeben wird. |
2437 |
|
* |
2438 |
|
* <br> |
2439 |
|
* |
2440 |
|
* @param layer |
2441 |
|
* ein Layer |
2442 |
|
*/ |
2443 |
|
public void zoomToLayer(MapLayer layer) { |
2444 |
|
if (layer == null) |
2445 |
|
return; |
2446 |
|
try { |
2447 |
|
|
2448 |
|
// BB umrechnen von Layer-CRS in Map-CRS |
2449 |
|
final CoordinateReferenceSystem targetCRS = getMapContext() |
2450 |
|
.getCoordinateReferenceSystem(); |
2451 |
|
final CoordinateReferenceSystem sourceCRS = layer |
2452 |
|
.getFeatureSource().getSchema() |
2453 |
|
.getCoordinateReferenceSystem(); |
2454 |
|
|
2455 |
|
Envelope mapAreaNew; |
2456 |
|
if (!CRS.equalsIgnoreMetadata(sourceCRS, targetCRS)) { |
2457 |
|
mapAreaNew = JTSUtil.transformEnvelope(layer.getFeatureSource() |
2458 |
|
.getBounds(), sourceCRS, targetCRS); |
2459 |
|
} else { |
2460 |
|
try { |
2461 |
|
mapAreaNew = layer.getFeatureSource().getBounds(); |
2462 |
|
} catch (java.lang.IllegalArgumentException e) { |
2463 |
|
LOGGER.error("Can't calc layers bounds...", e); |
2464 |
|
mapAreaNew = null; |
2465 |
|
|
2466 |
|
/** |
2467 |
|
* |
2468 |
|
23.10.2009 11:20:50 |
2469 |
|
* org.geotools.data.shapefile.shp.PolygonHandler read |
2470 |
|
* WARNUNG: only one hole in this polygon record ERROR |
2471 |
|
* JMapPane zoomToLayer Zoom to layer did not terminate |
2472 |
|
* correctly java.lang.IllegalArgumentException: Points of |
2473 |
|
* LinearRing do not form a closed linestring at |
2474 |
|
* com.vividsolutions |
2475 |
|
* .jts.geom.LinearRing.validateConstruction |
2476 |
|
* (LinearRing.java:105) at |
2477 |
|
* com.vividsolutions.jts.geom.LinearRing |
2478 |
|
* .<init>(LinearRing.java:100) at |
2479 |
|
* com.vividsolutions.jts.geom |
2480 |
|
* .GeometryFactory.createLinearRing |
2481 |
|
* (GeometryFactory.java:339) at |
2482 |
|
* org.geotools.data.shapefile. |
2483 |
|
* shp.PolygonHandler.read(PolygonHandler.java:188) at |
2484 |
|
* org.geotools |
2485 |
|
* .data.shapefile.shp.ShapefileReader$Record.shape |
2486 |
|
* (ShapefileReader.java:106) at |
2487 |
|
* org.geotools.data.shapefile. |
2488 |
|
* ShapefileAttributeReader.next( |
2489 |
|
* ShapefileAttributeReader.java:157) at |
2490 |
|
* org.geotools.data.shapefile |
2491 |
|
* .indexed.IndexedShapefileAttributeReader |
2492 |
|
* .next(IndexedShapefileAttributeReader.java:122) at |
2493 |
|
* org.geotools |
2494 |
|
* .data.FIDFeatureReader.next(FIDFeatureReader.java:96) at |
2495 |
|
* org.geotools.data.FIDFeatureReader.next(FIDFeatureReader. |
2496 |
|
* java:55) at org.geotools.data.MaxFeatureReader.next( |
2497 |
|
* MaxFeatureReader.java:61) at |
2498 |
|
* org.geotools.data.MaxFeatureReader |
2499 |
|
* .next(MaxFeatureReader.java:61) |
2500 |
|
**/ |
2501 |
|
} |
2502 |
|
} |
2503 |
|
|
2504 |
|
// Kartenbereich um 10% vergroessern, damit z.B. auch ein |
2505 |
|
// Punkt-Layer, |
2506 |
|
// welches nur aus 2 Punnkten besteht, sichtbar ist (Punkte liegen |
2507 |
|
// sonst |
2508 |
|
// genau auf dem Rand der angezeigten Flaeche) |
2509 |
|
|
2510 |
|
if (mapAreaNew != null) { |
2511 |
|
mapAreaNew.expandBy(mapAreaNew.getWidth() * 0.1, mapAreaNew |
2512 |
|
.getHeight() * 0.1); |
2513 |
|
setMapArea(mapAreaNew); |
2514 |
|
} else { |
2515 |
|
LOGGER |
2516 |
|
.warn("Couldn't transformEnvelope when zooming to the layer"); |
2517 |
|
} |
2518 |
|
} catch (Exception err) { |
2519 |
|
LOGGER.error("Zoom to layer did not terminate correctly", err); |
2520 |
|
} |
2521 |
|
} |
2522 |
|
|
2523 |
|
/** |
2524 |
|
* Zooms the {@link SelectableXMapPane} to the {@link Envelope} of a layer. |
2525 |
|
* |
2526 |
|
* <br> |
2527 |
|
* A refresh of the map is not done automatically |
2528 |
|
* |
2529 |
|
* @param index |
2530 |
|
* Index of the {@link MapLayer} in the {@link MapContext} (from |
2531 |
|
* back to top) |
2532 |
|
* |
2533 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2534 |
|
* Krüger</a> |
2535 |
|
*/ |
2536 |
|
public void zoomToLayer(int index) { |
2537 |
|
final MapContext context = getMapContext(); |
2538 |
|
if (context != null) |
2539 |
|
zoomToLayer(context.getLayer(index)); |
2540 |
|
} |
2541 |
|
|
2542 |
|
/** |
2543 |
|
* Zooms the {@link SelectableXMapPane} to the {@link Envelope} of the |
2544 |
|
* selected layer. The layer is selected by the idx, counting from front to |
2545 |
|
* back, like humans would expect in a {@link JList} |
2546 |
|
* |
2547 |
|
* <br> |
2548 |
|
* A refresh of the map is not done automatically |
2549 |
|
* |
2550 |
|
* |
2551 |
|
* |
2552 |
|
* @param index |
2553 |
|
* Reverse index of the {@link MapLayer} in the |
2554 |
|
* {@link MapContext} |
2555 |
|
* |
2556 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2557 |
|
* Krüger</a> |
2558 |
|
*/ |
2559 |
|
public void zoomToLayerIdxReverse(int index) { |
2560 |
|
zoomToLayer(getMapContext().getLayerCount() - 1 - index); |
2561 |
|
} |
2562 |
|
|
2563 |
|
|
2564 |
|
|
2565 |
|
|
2566 |
|
|
2567 |
|
/** |
2568 |
|
* Aktiviert oder deaktiviert das AntiAliasing for diese |
2569 |
|
* {@link SelectableXMapPane}. AntiALiasing ist besonders fuer |
2570 |
|
* Textbeschriftung sehr schoen, verbraucht aber auch mehr Performance. |
2571 |
|
* |
2572 |
|
* @author <a href="mailto:[email protected]">Stefan Alfons |
2573 |
|
* Krüger</a> |
2574 |
|
*/ |
2575 |
|
public void setAntiAliasing(final boolean aa) { |
2576 |
|
// LOGGER.info("Setting AntiAliasing for this JMapPane to " + aa); |
2577 |
|
RenderingHints java2DHints = java2dHints; |
2578 |
|
if (java2DHints == null) { |
2579 |
|
java2DHints = GeoTools.getDefaultHints(); |
2580 |
|
} |
2581 |
|
|
2582 |
|
java2DHints.put(RenderingHints.KEY_ANTIALIASING, |
2583 |
|
aa ? RenderingHints.VALUE_ANTIALIAS_ON |
2584 |
|
: RenderingHints.VALUE_ANTIALIAS_OFF); |
2585 |
|
java2DHints.put(RenderingHints.KEY_TEXT_ANTIALIASING, |
2586 |
|
aa ? RenderingHints.VALUE_TEXT_ANTIALIAS_ON |
2587 |
|
: RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); |
2588 |
|
java2DHints.put(RenderingHints.KEY_RENDERING, |
2589 |
|
aa ? RenderingHints.VALUE_RENDER_QUALITY |
2590 |
|
: RenderingHints.VALUE_RENDER_SPEED); |
2591 |
|
|
2592 |
|
} |
2593 |
|
|
2594 |
} |
} |