30 |
|
|
31 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
32 |
import org.geotools.feature.FeatureCollection; |
import org.geotools.feature.FeatureCollection; |
|
import org.geotools.geometry.Envelope2D; |
|
33 |
import org.geotools.geometry.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
34 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
35 |
import org.geotools.map.DefaultMapContext; |
import org.geotools.map.DefaultMapContext; |
124 |
* regularly and {@link #repaint()}. This {@link Timer} is stopped when all |
* regularly and {@link #repaint()}. This {@link Timer} is stopped when all |
125 |
* renderers have finished. |
* renderers have finished. |
126 |
* |
* |
127 |
* @see #INITIAL_REPAINT_DELAYAL |
* @see INITIAL_REPAINT_DELAYAL |
128 |
* @see #REPEATING_REPAINT_DELAY |
* @see #REPEATING_REPAINT_DELAY |
129 |
*/ |
*/ |
130 |
final private Timer repaintTimer; |
final private Timer repaintTimer; |
140 |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
* the {@link #repaintTimer} is regularly updating the {@link #finalImage} |
141 |
* with previews. |
* with previews. |
142 |
*/ |
*/ |
143 |
public static final long REPEATING_REPAINT_DELAY = 500; |
public static final int REPEATING_REPAINT_DELAY = 500; |
144 |
|
|
145 |
/** |
/** |
146 |
* Default delay (milliseconds) before the map will be redrawn when resizing |
* Default delay (milliseconds) before the map will be redrawn when resizing |
147 |
* the pane. This is to avoid flickering while drag-resizing. |
* the pane. This is to avoid flickering while drag-resizing. |
148 |
|
* |
149 |
|
* @see #resizeTimer |
150 |
*/ |
*/ |
151 |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 600; |
public static final int DEFAULT_RESIZING_PAINT_DELAY = 600; |
152 |
|
|
153 |
|
private final Timer resizeTimer; |
154 |
|
|
155 |
public static final int NONE = -123; |
public static final int NONE = -123; |
156 |
|
|
157 |
/** |
/** |
189 |
public static final Cursor WAIT_CURSOR = Cursor |
public static final Cursor WAIT_CURSOR = Cursor |
190 |
.getPredefinedCursor(Cursor.WAIT_CURSOR); |
.getPredefinedCursor(Cursor.WAIT_CURSOR); |
191 |
|
|
192 |
|
/** |
193 |
|
* {@link Font} used to paint the wait messages into the map |
194 |
|
* |
195 |
|
* @see #addGadgets(Graphics2D, boolean) |
196 |
|
*/ |
197 |
final static Font waitFont = new Font("Arial", Font.BOLD, 30); |
final static Font waitFont = new Font("Arial", Font.BOLD, 30); |
198 |
final String waitMsg = SwingUtil.R("WaitMess"); |
|
199 |
|
/** |
200 |
|
* {@link Font} used to paint error messages into the map |
201 |
|
* |
202 |
|
* @see #addGadgets(Graphics2D, boolean) |
203 |
|
*/ |
204 |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
final static Font errorFont = new Font("Arial", Font.BOLD, 13); |
205 |
|
|
206 |
/** |
/** |
207 |
|
* The wait message painted into the map while rendering is going on on |
208 |
|
* another thread. |
209 |
|
* |
210 |
|
* @see #addGadgets(Graphics2D, boolean) |
211 |
|
*/ |
212 |
|
final String waitMsg = SwingUtil.R("WaitMess"); |
213 |
|
|
214 |
|
/** |
215 |
* Flag fuer Modus "Heran zoomen". |
* Flag fuer Modus "Heran zoomen". |
216 |
* |
* |
217 |
* @see #setState(int) |
* @see #setState(int) |
270 |
|
|
271 |
@Override |
@Override |
272 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
|
|
|
273 |
MapLayer layer = event.getLayer(); |
MapLayer layer = event.getLayer(); |
|
|
|
274 |
layer.addMapLayerListener(bgMapLayerListener); |
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(); |
|
275 |
requestStartRendering(); |
requestStartRendering(); |
276 |
|
|
277 |
} |
} |
278 |
|
|
279 |
@Override |
@Override |
280 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
281 |
requestStartRendering(); |
requestStartRendering(); |
282 |
} |
} |
283 |
|
|
284 |
@Override |
@Override |
285 |
public void layerMoved(final MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
286 |
requestStartRendering(); |
requestStartRendering(); |
287 |
} |
} |
288 |
|
|
290 |
public void layerRemoved(final MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
291 |
if (event.getLayer() != null) |
if (event.getLayer() != null) |
292 |
event.getLayer().removeMapLayerListener(bgMapLayerListener); |
event.getLayer().removeMapLayerListener(bgMapLayerListener); |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
293 |
requestStartRendering(); |
requestStartRendering(); |
294 |
} |
} |
295 |
}; |
}; |
296 |
|
|
297 |
/** |
/** |
298 |
* compass and icon are rendered into this image |
* This {@link RenderingExecutor} manages the creation and cancellation of |
299 |
|
* up to one {@link Thread} for rendering the {@link #localContext}. |
300 |
*/ |
*/ |
301 |
// protected BufferedImage gadgetsImage; |
private final RenderingExecutor localExecuter = new RenderingExecutor(this); |
302 |
|
|
303 |
|
/** |
304 |
|
* This {@link RenderingExecutor} manages the creation and cancellation of |
305 |
|
* up to one {@link Thread} for rendering the {@link #bgContext}. |
306 |
|
*/ |
307 |
protected RenderingExecutor bgExecuter; |
protected RenderingExecutor bgExecuter; |
308 |
|
|
309 |
/** |
/** |
310 |
* The Renderer for the LocalLayers uses this Image. When set to null, |
* The {@link #localRenderer} for the {@link #localContext} uses this |
311 |
* please dispose this {@link Graphics2D} |
* {@link Image}. |
312 |
*/ |
*/ |
313 |
private BufferedImage localImage; |
private BufferedImage localImage; |
314 |
|
|
|
private BufferedImage finalImage; |
|
315 |
/** |
/** |
316 |
* If # {@link #bgExecuter} is using {@link #bgRenderer} for the Background |
* The {@link #bgRenderer} for the {@link #bgContext} uses this |
317 |
* uses this Image. When set to null, please dispose the {@link Graphics2D} |
* {@link Image}. |
318 |
*/ |
*/ |
319 |
private BufferedImage bgImage; |
private BufferedImage bgImage; |
320 |
|
|
321 |
/** |
/** |
322 |
|
* This {@link Image} is a merge of the {@link #bgImage}, |
323 |
|
* {@link #localImage} and {@link #addGadgets(Graphics2D, boolean)}. It is |
324 |
|
* updated with {@link #updateFinalImage()} and used for painting in |
325 |
|
* {@link #paintComponent(Graphics)} |
326 |
|
*/ |
327 |
|
private BufferedImage finalImage; |
328 |
|
|
329 |
|
/** |
330 |
* 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 |
331 |
* corner. |
* corner. |
332 |
* |
* |
343 |
|
|
344 |
@Override |
@Override |
345 |
public void layerChanged(final MapLayerEvent event) { |
public void layerChanged(final MapLayerEvent event) { |
|
// Change of SLD for example |
|
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
346 |
requestStartRendering(); |
requestStartRendering(); |
347 |
} |
} |
348 |
|
|
349 |
@Override |
@Override |
350 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
351 |
requestStartRendering(); |
requestStartRendering(); |
352 |
} |
} |
353 |
|
|
354 |
@Override |
@Override |
355 |
public void layerShown(final MapLayerEvent event) { |
public void layerShown(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
356 |
requestStartRendering(); |
requestStartRendering(); |
357 |
} |
} |
358 |
}; |
}; |
389 |
public void layerAdded(final MapLayerListEvent event) { |
public void layerAdded(final MapLayerListEvent event) { |
390 |
event.getLayer().addMapLayerListener(localMapLayerListener); |
event.getLayer().addMapLayerListener(localMapLayerListener); |
391 |
|
|
392 |
localRenderer.setContext(getContext()); |
localRenderer.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(); |
|
393 |
requestStartRendering(); |
requestStartRendering(); |
394 |
|
|
395 |
} |
} |
396 |
|
|
397 |
@Override |
@Override |
398 |
public void layerChanged(final MapLayerListEvent event) { |
public void layerChanged(final MapLayerListEvent event) { |
399 |
// mapImageInvalid = true; |
localRenderer.setContext(getMapContext()); |
|
// repaint(); |
|
|
localRenderer.setContext(getContext()); |
|
400 |
requestStartRendering(); |
requestStartRendering(); |
401 |
} |
} |
402 |
|
|
403 |
@Override |
@Override |
404 |
public void layerMoved(final MapLayerListEvent event) { |
public void layerMoved(final MapLayerListEvent event) { |
405 |
// mapImageInvalid = true; |
localRenderer.setContext(getMapContext()); |
|
// repaint(); |
|
|
localRenderer.setContext(getContext()); |
|
406 |
requestStartRendering(); |
requestStartRendering(); |
407 |
} |
} |
408 |
|
|
410 |
public void layerRemoved(final MapLayerListEvent event) { |
public void layerRemoved(final MapLayerListEvent event) { |
411 |
if (event.getLayer() != null) |
if (event.getLayer() != null) |
412 |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
event.getLayer().removeMapLayerListener(localMapLayerListener); |
413 |
// mapImageInvalid = true; |
localRenderer.setContext(getMapContext()); |
|
// repaint(); |
|
|
localRenderer.setContext(getContext()); |
|
414 |
requestStartRendering(); |
requestStartRendering(); |
415 |
} |
} |
416 |
}; |
}; |
417 |
|
|
|
private final RenderingExecutor localExecuter = new RenderingExecutor(this); |
|
|
|
|
418 |
/** |
/** |
419 |
* Listens to each layer in the local {@link MapContext} for changes and |
* Listens to each layer in the local {@link MapContext} for changes and |
420 |
* triggers repaints. |
* triggers repaints. |
423 |
|
|
424 |
@Override |
@Override |
425 |
public void layerChanged(final MapLayerEvent event) { |
public void layerChanged(final MapLayerEvent event) { |
426 |
localRenderer.setContext(getContext()); // betters for SLD changes?! |
localRenderer.setContext(getMapContext()); // betters for SLD changes?! |
|
// Change of SLD for example |
|
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
427 |
requestStartRendering(); |
requestStartRendering(); |
428 |
} |
} |
429 |
|
|
430 |
@Override |
@Override |
431 |
public void layerHidden(final MapLayerEvent event) { |
public void layerHidden(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
432 |
requestStartRendering(); |
requestStartRendering(); |
433 |
} |
} |
434 |
|
|
435 |
@Override |
@Override |
436 |
public void layerShown(final MapLayerEvent event) { |
public void layerShown(final MapLayerEvent event) { |
|
// mapImageInvalid = true; |
|
|
// repaint(); |
|
437 |
requestStartRendering(); |
requestStartRendering(); |
438 |
} |
} |
439 |
}; |
}; |
513 |
private Map<Object, Object> rendererHints = GTUtil |
private Map<Object, Object> rendererHints = GTUtil |
514 |
.getDefaultGTRendererHints(localRenderer); |
.getDefaultGTRendererHints(localRenderer); |
515 |
|
|
516 |
|
/** |
517 |
|
* If set to <code>true</code>, the {@link #startRenderThreadsTimer} will |
518 |
|
* start rendering {@link Thread}s |
519 |
|
**/ |
520 |
private volatile Boolean requestStartRendering = false; |
private volatile Boolean requestStartRendering = false; |
521 |
|
|
|
private final Timer resizeTimer; |
|
|
|
|
522 |
/** |
/** |
523 |
* Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten |
* Transformation zwischen Fenster-Koordinaten und Karten-Koordinaten |
524 |
* (lat/lon) |
* (lat/lon) |
555 |
/** Is set if a renderer has an error **/ |
/** Is set if a renderer has an error **/ |
556 |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
protected ArrayList<Exception> renderingErrors = new ArrayList<Exception>(); |
557 |
|
|
558 |
// TODO doku |
// /** If {@link #getVisibleRect()} of this {@link JPanel} is not yet |
559 |
|
// defined, but we are **/ |
560 |
|
// private Envelope mapAreaCondidate = null; |
561 |
|
|
562 |
public XMapPane() { |
public XMapPane() { |
563 |
this(null, null); |
this(null, null); |
564 |
} |
} |
567 |
* full constructor extending JPanel |
* full constructor extending JPanel |
568 |
* |
* |
569 |
* @param rendererHints |
* @param rendererHints |
570 |
|
* may be <code>null</code>. Otherwise a {@link Map<Object, |
571 |
|
* Object>} of {@link RenderingHints} to override the default |
572 |
|
* from {@link GTUtil#getDefaultGTRendererHints(GTRenderer)} |
573 |
* |
* |
|
* @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 |
|
574 |
* @param localContext |
* @param localContext |
575 |
* - {@link MapContext} of layer to render. |
* The main {@link MapContext} to use. If <code>null</code>, an |
576 |
|
* empty {@link DefaultMapContext} will be created. |
577 |
*/ |
*/ |
578 |
public XMapPane(final MapContext localContext_, |
public XMapPane(final MapContext localContext_, |
579 |
final Map<Object, Object> rendererHints) { |
final Map<Object, Object> rendererHints) { |
600 |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
* Using a ComponentListener doesn't work because, unlike a JFrame, the |
601 |
* pane receives a stream of events during drag-resizing. |
* pane receives a stream of events during drag-resizing. |
602 |
*/ |
*/ |
603 |
resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, new ActionListener() { |
resizeTimer = new Timer(DEFAULT_RESIZING_PAINT_DELAY, |
604 |
|
new ActionListener() { |
|
public void actionPerformed(final ActionEvent e) { |
|
|
paneResized = true; |
|
|
|
|
|
if (!isWellDefined()) |
|
|
return; |
|
|
|
|
|
final Rectangle bounds = getVisibleRect(); |
|
605 |
|
|
606 |
final Envelope geoMapArea = tranformWindowToGeo(bounds.x, |
public void actionPerformed(final ActionEvent e) { |
607 |
bounds.y, bounds.x + bounds.width, bounds.y |
if (!isWellDefined()) |
608 |
+ bounds.height); |
return; |
609 |
|
|
610 |
setMapArea(bestAllowedMapArea(geoMapArea)); |
final Rectangle bounds = getVisibleRect(); |
611 |
} |
// |
612 |
}); |
// System.out.println("\n\ntimer performs with bounds = " |
613 |
|
// + bounds); |
614 |
|
|
615 |
|
final Envelope geoMapArea = tranformWindowToGeo( |
616 |
|
bounds.x, bounds.y, bounds.x + bounds.width, |
617 |
|
bounds.y + bounds.height); |
618 |
|
|
619 |
|
if (setMapArea(geoMapArea)) |
620 |
|
paneResized = true; |
621 |
|
// else |
622 |
|
// syso |
623 |
|
} |
624 |
|
}); |
625 |
resizeTimer.setRepeats(false); |
resizeTimer.setRepeats(false); |
626 |
|
|
627 |
this.addComponentListener(new ComponentAdapter() { |
this.addComponentListener(new ComponentAdapter() { |
628 |
|
|
629 |
@Override |
@Override |
630 |
public void componentResized(final ComponentEvent e) { |
public void componentResized(final ComponentEvent e) { |
631 |
|
|
632 |
|
// Already cancel the tasks... |
633 |
if (bgExecuter != null) |
if (bgExecuter != null) |
634 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
635 |
if (localExecuter != null) |
if (localExecuter != null) |
636 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
637 |
|
|
638 |
resizeTimer.restart(); |
resizeTimer.restart(); |
639 |
} |
} |
640 |
|
|
643 |
/* |
/* |
644 |
* Setting up the repaintTimer. Not started automatically. |
* Setting up the repaintTimer. Not started automatically. |
645 |
*/ |
*/ |
646 |
repaintTimer = new Timer((int) REPEATING_REPAINT_DELAY, |
repaintTimer = new Timer(REPEATING_REPAINT_DELAY, new ActionListener() { |
|
new ActionListener() { |
|
647 |
|
|
648 |
@Override |
@Override |
649 |
public void actionPerformed(final ActionEvent e) { |
public void actionPerformed(final ActionEvent e) { |
650 |
updateFinalImage(); |
if ((localExecuter != null && !localExecuter.isRunning()) |
651 |
XMapPane.this.repaint(); |
&& (bgExecuter != null && !bgExecuter.isRunning())) { |
652 |
} |
repaintTimer.stop(); |
653 |
}); |
} else { |
654 |
|
updateFinalImage(); |
655 |
|
XMapPane.this.repaint(100); |
656 |
|
} |
657 |
|
} |
658 |
|
}); |
659 |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
repaintTimer.setInitialDelay(INITIAL_REPAINT_DELAY); |
660 |
repaintTimer.setRepeats(true); |
repaintTimer.setRepeats(true); |
661 |
|
|
673 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
674 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
675 |
} else { |
} else { |
676 |
|
|
677 |
|
// Stupidly, but we have to recheck the |
678 |
|
setMapArea(getMapArea()); |
679 |
requestStartRendering = false; |
requestStartRendering = false; |
680 |
startRendering(); |
startRendering(); |
681 |
} |
} |
708 |
* @author <a href="mailto:[email protected]">Stefan Alfons |
* @author <a href="mailto:[email protected]">Stefan Alfons |
709 |
* Krüger</a> |
* Krüger</a> |
710 |
*/ |
*/ |
711 |
public Envelope bestAllowedMapArea(Envelope env) { |
public ReferencedEnvelope bestAllowedMapArea(ReferencedEnvelope env) { |
712 |
// return env; |
|
713 |
if (getWidth() == 0) |
if (getWidth() == 0) |
714 |
return env; |
return env; |
715 |
|
|
716 |
if (env == null) |
if (env == null) |
717 |
return null; |
return null; |
718 |
|
|
762 |
} |
} |
763 |
|
|
764 |
final Envelope maxAllowedExtend = getMaxExtend(); |
final Envelope maxAllowedExtend = getMaxExtend(); |
765 |
|
|
766 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
767 |
&& newArea != null && !newArea.isNull() |
&& newArea != null && !newArea.isNull() |
768 |
&& !Double.isNaN(newArea.getMinX()) |
&& !Double.isNaN(newArea.getMinX()) |
792 |
|
|
793 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
794 |
|
|
795 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
796 |
false); |
new ReferencedEnvelope(newArea, env |
797 |
|
.getCoordinateReferenceSystem()), false); |
798 |
} |
} |
799 |
} |
} |
800 |
|
|
817 |
|
|
818 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
819 |
|
|
820 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
821 |
false); |
new ReferencedEnvelope(newArea, env |
822 |
|
.getCoordinateReferenceSystem()), false); |
823 |
} |
} |
824 |
} |
} |
825 |
|
|
844 |
|
|
845 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
846 |
|
|
847 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
848 |
false); |
new ReferencedEnvelope(newArea, env |
849 |
|
.getCoordinateReferenceSystem()), false); |
850 |
} |
} |
851 |
} |
} |
852 |
|
|
871 |
|
|
872 |
// LOGGER.debug("and fix aspect ratio"); |
// LOGGER.debug("and fix aspect ratio"); |
873 |
|
|
874 |
newArea = JTSUtil.fixAspectRatio(this.getBounds(), newArea, |
newArea = JTSUtil.fixAspectRatio(getVisibleRect(), |
875 |
false); |
new ReferencedEnvelope(newArea, env |
876 |
|
.getCoordinateReferenceSystem()), false); |
877 |
} |
} |
878 |
} |
} |
879 |
} |
} |
880 |
|
|
881 |
return newArea; |
return new ReferencedEnvelope(newArea, env |
882 |
|
.getCoordinateReferenceSystem()); |
883 |
} |
} |
884 |
|
|
885 |
/** |
/** |
912 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
913 |
while (i++ < 10 && localExecuter.isRunning()) { |
while (i++ < 10 && localExecuter.isRunning()) { |
914 |
try { |
try { |
915 |
Thread.sleep(100); |
Thread.sleep(200); |
916 |
} catch (final InterruptedException e) { |
} catch (final InterruptedException e) { |
917 |
// TODO Auto-generated catch block |
LOGGER |
918 |
e.printStackTrace(); |
.warn( |
919 |
|
"while XMapPane we are waiting for the localExcutor to stop", |
920 |
|
e); |
921 |
} |
} |
922 |
} |
} |
923 |
if (localExecuter.isRunning()) { |
if (localExecuter.isRunning()) { |
924 |
System.out |
LOGGER |
925 |
.println("BAD BAD BAD... still running the thread...."); |
.warn("localExecutor Thread still running after 2s! Continuing anyways..."); |
926 |
} |
} |
927 |
localExecuter.dispose(); |
localExecuter.dispose(); |
928 |
} |
} |
929 |
|
|
930 |
disposeImages(); |
disposeImages(); |
931 |
|
|
932 |
// LangUtil.gcTotal(); |
// Remove all mapPaneListeners that have registered with us |
|
|
|
|
// Alle mapPaneListener entfernen |
|
933 |
mapPaneListeners.clear(); |
mapPaneListeners.clear(); |
934 |
|
|
935 |
removeMouseMotionListener(zoomMapPaneMouseListener); |
removeMouseMotionListener(zoomMapPaneMouseListener); |
936 |
removeMouseListener(zoomMapPaneMouseListener); |
removeMouseListener(zoomMapPaneMouseListener); |
937 |
|
|
938 |
if (localContext != null) |
if (localContext != null) |
939 |
getContext().clearLayerList(); |
getMapContext().clearLayerList(); |
940 |
if (bgContext != null) |
if (bgContext != null) |
941 |
getBgContext().clearLayerList(); |
getBgContext().clearLayerList(); |
942 |
|
|
982 |
*/ |
*/ |
983 |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
protected boolean drawScaledPreviewImage_Zoom(final Graphics2D graphics) { |
984 |
|
|
985 |
if (1 == 1)return false; |
// if (1 == 1)return false; |
986 |
|
|
987 |
if (quickPreviewHint == 0) |
if (quickPreviewHint == 0) |
988 |
return false; |
return false; |
989 |
|
|
1047 |
return bgImage; |
return bgImage; |
1048 |
} |
} |
1049 |
|
|
1050 |
public MapContext getContext() { |
public MapContext getMapContext() { |
1051 |
if (localContext == null) { |
if (localContext == null) { |
1052 |
setLocalContext(new DefaultMapContext()); |
setLocalContext(new DefaultMapContext()); |
1053 |
} |
} |
1058 |
// |
// |
1059 |
if (finalImage == null) { |
if (finalImage == null) { |
1060 |
// Rectangle curPaintArea = getVisibleRect(); |
// Rectangle curPaintArea = getVisibleRect(); |
1061 |
finalImage = new BufferedImage(getBounds().width, |
finalImage = new BufferedImage(getVisibleRect().width, |
1062 |
getBounds().height, IMAGETYPE); |
getVisibleRect().height, IMAGETYPE); |
1063 |
|
|
1064 |
requestStartRendering(); |
requestStartRendering(); |
1065 |
} |
} |
1076 |
private BufferedImage getLocalImage() { |
private BufferedImage getLocalImage() { |
1077 |
|
|
1078 |
if (localImage == null) { |
if (localImage == null) { |
1079 |
localImage = new BufferedImage(getBounds().width, |
localImage = new BufferedImage(getVisibleRect().width, |
1080 |
getBounds().height, IMAGETYPE_withAlpha); |
getVisibleRect().height, IMAGETYPE_withAlpha); |
1081 |
} |
} |
1082 |
|
|
1083 |
return localImage; |
return localImage; |
1094 |
try { |
try { |
1095 |
mapArea_ = localContext.getLayerBounds(); |
mapArea_ = localContext.getLayerBounds(); |
1096 |
} catch (final IOException e) { |
} catch (final IOException e) { |
1097 |
LOGGER.warn("context.getLayerBounds()", e); |
LOGGER.warn("localContext.getLayerBounds()", e); |
1098 |
|
} |
1099 |
|
|
1100 |
|
if (mapArea_ == null && bgContext != null) { |
1101 |
|
try { |
1102 |
|
mapArea_ = bgContext.getLayerBounds(); |
1103 |
|
} catch (final IOException e) { |
1104 |
|
LOGGER.warn("bgContext.getLayerBounds()", e); |
1105 |
|
} |
1106 |
} |
} |
1107 |
|
|
1108 |
if (mapArea_ != null) { |
if (mapArea_ != null) { |
|
mapImageInvalid = true; /* note we need to redraw */ |
|
|
// setMapArea(mapArea_); // results in a loop |
|
1109 |
mapArea = bestAllowedMapArea(mapArea_); |
mapArea = bestAllowedMapArea(mapArea_); |
1110 |
|
requestStartRendering(); |
1111 |
} |
} |
1112 |
} |
} |
1113 |
|
|
1157 |
|
|
1158 |
public Envelope getMaxExtend() { |
public Envelope getMaxExtend() { |
1159 |
if (maxExtend == null) { |
if (maxExtend == null) { |
1160 |
final ReferencedEnvelope layerBounds = GTUtil |
// Commented-out because it takes soo much time! |
1161 |
.getVisibleLayoutBounds(localContext); |
// |
1162 |
if (layerBounds == null) { |
// long start = System.currentTimeMillis(); |
1163 |
// TODO Last fallback could be the CRS valid area |
// final ReferencedEnvelope layerBounds = GTUtil |
1164 |
return null; |
// .getVisibleLayoutBounds(localContext); |
1165 |
} |
// |
1166 |
|
// LOGGER.info( (System.currentTimeMillis()-start)+"m to get maxExtend"); |
1167 |
// Kartenbereich um 10% vergroessern |
// |
1168 |
return JTSUtil.fixAspectRatio(this.getBounds(), JTSUtil |
// if (layerBounds == null) { |
1169 |
.expandEnvelope(layerBounds, 0.1), true); |
// // TODO Last fallback could be the CRS valid area |
1170 |
|
// return null; |
1171 |
|
// } |
1172 |
|
// |
1173 |
|
// // Kartenbereich um 10% vergroessern |
1174 |
|
// return JTSUtil.fixAspectRatio(getVisibleRect(), JTSUtil |
1175 |
|
// .expandEnvelope(layerBounds, 0.1), true); |
1176 |
} |
} |
1177 |
return maxExtend; |
return maxExtend; |
1178 |
} |
} |
1286 |
* {@link XMapPane} is visible and has bounds set. |
* {@link XMapPane} is visible and has bounds set. |
1287 |
*/ |
*/ |
1288 |
public boolean isWellDefined() { |
public boolean isWellDefined() { |
|
|
|
1289 |
try { |
try { |
1290 |
|
if (getMapContext() == null) |
|
if (getContext() == null) |
|
1291 |
return false; |
return false; |
1292 |
if (getContext().getLayerCount() <= 0) |
if (getMapContext().getLayerCount() <= 0) |
1293 |
return false; |
return false; |
1294 |
if (getMapArea() == null) |
if (getVisibleRect().getWidth() == 0) |
1295 |
return false; |
return false; |
1296 |
if (getBounds().getWidth() == 0) |
if (getVisibleRect().getHeight() == 0) |
|
return false; |
|
|
if (getBounds().getHeight() == 0) |
|
1297 |
return false; |
return false; |
1298 |
|
// if (getMapArea() == null) |
1299 |
|
// return false; |
1300 |
} catch (final Exception e) { |
} catch (final Exception e) { |
1301 |
return false; |
return false; |
1302 |
} |
} |
1384 |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
* Called by the {@link RenderingExecutor} when rendering was cancelled. |
1385 |
*/ |
*/ |
1386 |
public void onRenderingCancelled() { |
public void onRenderingCancelled() { |
|
repaintTimer.stop(); |
|
1387 |
LOGGER.debug("Rendering cancelled"); |
LOGGER.debug("Rendering cancelled"); |
1388 |
|
repaintTimer.stop(); |
1389 |
} |
} |
1390 |
|
|
1391 |
/** |
/** |
1429 |
|
|
1430 |
@Override |
@Override |
1431 |
protected void paintComponent(final Graphics g) { |
protected void paintComponent(final Graphics g) { |
1432 |
|
|
1433 |
if (!acceptsRepaintCalls) |
if (!acceptsRepaintCalls) |
1434 |
return; |
return; |
1435 |
|
|
1449 |
// happening. |
// happening. |
1450 |
if (mapAreaChanged && oldMapArea != null |
if (mapAreaChanged && oldMapArea != null |
1451 |
&& getMapArea().intersects(oldMapArea) |
&& getMapArea().intersects(oldMapArea) |
1452 |
& !getMapArea().equals(oldMapArea)) { |
& !getMapArea().equals(oldMapArea) && !paneResized) { |
1453 |
|
|
1454 |
mapAreaChanged = false; |
mapAreaChanged = false; |
1455 |
|
|
1463 |
|
|
1464 |
} |
} |
1465 |
|
|
1466 |
if (paneResized) { |
// if (paneResized) { |
1467 |
paneResized = false; |
// paneResized = false; |
1468 |
disposeImages(); |
// disposeImages(); |
1469 |
} |
// } |
1470 |
|
// |
1471 |
// Start the Threads and Timers to render the image |
// // Start the Threads and Timers to render the image |
1472 |
requestStartRendering(); |
// requestStartRendering(); |
1473 |
|
|
1474 |
} |
} |
1475 |
|
|
1534 |
*/ |
*/ |
1535 |
public void performPan() { |
public void performPan() { |
1536 |
|
|
1537 |
final Rectangle winBounds = getBounds(); |
Rectangle winBounds = getVisibleRect(); |
1538 |
|
|
1539 |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
winBounds.translate(-imageOrigin.x, -imageOrigin.y); |
1540 |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
final Envelope newMapArea = tranformWindowToGeo(winBounds.x, |
1541 |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
winBounds.y, winBounds.x + winBounds.width, winBounds.y |
1600 |
bgExecuter.cancelTask(); |
bgExecuter.cancelTask(); |
1601 |
if (localExecuter != null) |
if (localExecuter != null) |
1602 |
localExecuter.cancelTask(); |
localExecuter.cancelTask(); |
1603 |
|
|
1604 |
|
mapImageInvalid = true; |
1605 |
|
if (paneResized) { |
1606 |
|
paneResized = false; |
1607 |
|
disposeImages(); |
1608 |
|
} |
1609 |
requestStartRendering = true; |
requestStartRendering = true; |
1610 |
|
|
1611 |
} |
} |
1612 |
|
|
|
// |
|
|
// /** |
|
|
// * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten |
|
|
// * neu. |
|
|
// */ |
|
|
// protected void resetTransforms() { |
|
|
// if (getMapArea() == null || getWidth() == 0 || getHeight() == 0) |
|
|
// return; |
|
|
// |
|
|
// // We store the last Transform |
|
|
// oldScreenToWorld = screenToWorld; |
|
|
// |
|
|
// this.screenToWorld = new AffineTransform( |
|
|
// // Genauso wie die Fenster-Koordinaten, werden die Longitude-Koordinaten |
|
|
// // 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()); |
|
|
// |
|
|
// try { |
|
|
// this.worldToScreen = screenToWorld.createInverse(); |
|
|
// } catch (final NoninvertibleTransformException e) { |
|
|
// LOGGER.error(e); |
|
|
// } |
|
|
// } |
|
|
|
|
1613 |
/** |
/** |
1614 |
* Calculate the affine transforms used to convert between world and pixel |
* Calculate the affine transforms used to convert between world and pixel |
1615 |
* coordinates. The calculations here are very basic and assume a cartesian |
* coordinates. The calculations here are very basic and assume a cartesian |
1625 |
*/ |
*/ |
1626 |
private void resetTransforms() { |
private void resetTransforms() { |
1627 |
ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
ReferencedEnvelope refMapEnv = new ReferencedEnvelope(mapArea, |
1628 |
getContext().getCoordinateReferenceSystem()); |
getMapContext().getCoordinateReferenceSystem()); |
1629 |
// |
|
1630 |
Rectangle paintArea = getBounds(); |
// System.out |
1631 |
|
// .println("paintArea in resetTeansofrms = " + getVisibleRect()); |
1632 |
if (!getBounds().equals(getVisibleRect())) { |
if (!isWellDefined()) |
1633 |
System.out.println("did we expect that?"); |
return; |
|
} |
|
|
// |
|
|
// double xscale = paintArea.getWidth() / refEnv.getWidth(); |
|
|
// double yscale = paintArea.getHeight() / refEnv.getHeight(); |
|
|
// |
|
|
// double scale = Math.min(xscale, yscale); |
|
|
// |
|
|
// double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX(); |
|
|
// double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY(); |
|
1634 |
|
|
1635 |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
worldToScreen = RendererUtilities.worldToScreenTransform(refMapEnv, |
1636 |
paintArea); |
getVisibleRect()); |
1637 |
|
|
|
// worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, |
|
|
// yoff); |
|
1638 |
try { |
try { |
1639 |
screenToWorld = worldToScreen.createInverse(); |
screenToWorld = worldToScreen.createInverse(); |
1640 |
|
|
1641 |
} catch (NoninvertibleTransformException ex) { |
} catch (NoninvertibleTransformException ex) { |
1642 |
ex.printStackTrace(); |
LOGGER |
1643 |
|
.error("can't invert worldToScreen to get screenToWorld!", |
1644 |
|
ex); |
1645 |
} |
} |
1646 |
} |
} |
1647 |
|
|
1660 |
this.bgContext = context; |
this.bgContext = context; |
1661 |
|
|
1662 |
if (context != null) { |
if (context != null) { |
1663 |
setMapArea(bgContext.getAreaOfInterest()); |
// setMapArea(bgContext.getAreaOfInterest()); |
1664 |
|
|
1665 |
this.bgContext.addMapLayerListListener(bgContextListener); |
this.bgContext.addMapLayerListListener(bgContextListener); |
1666 |
|
|
1669 |
mapLayer.addMapLayerListener(bgMapLayerListener); |
mapLayer.addMapLayerListener(bgMapLayerListener); |
1670 |
} |
} |
1671 |
} |
} |
1672 |
mapImageInvalid = true; |
|
1673 |
repaint(); |
requestStartRendering(); |
1674 |
} |
} |
1675 |
|
|
1676 |
public void setJava2dHints(final RenderingHints java2dHints) { |
public void setJava2dHints(final RenderingHints java2dHints) { |
1677 |
this.java2dHints = java2dHints; |
this.java2dHints = java2dHints; |
1678 |
} |
} |
1679 |
|
|
|
/** |
|
|
* |
|
|
* @param context |
|
|
*/ |
|
1680 |
public void setLocalContext(final MapContext context) { |
public void setLocalContext(final MapContext context) { |
1681 |
// Remove the default listener from the old context |
// Remove the default listener from the old context |
1682 |
if (this.localContext != null) { |
if (this.localContext != null) { |
1692 |
|
|
1693 |
if (context != null) { |
if (context != null) { |
1694 |
|
|
1695 |
setMapArea(localContext.getAreaOfInterest()); |
// setMapArea(localContext.getAreaOfInterest()); |
1696 |
|
|
1697 |
localRenderer.setContext(localContext); |
localRenderer.setContext(localContext); |
1698 |
|
|
1704 |
} |
} |
1705 |
} |
} |
1706 |
|
|
1707 |
mapImageInvalid = true; |
requestStartRendering(); |
1708 |
repaint(); |
|
1709 |
|
} |
1710 |
|
|
1711 |
|
public boolean setMapArea(final Envelope newMapArea) { |
1712 |
|
return setMapArea(new ReferencedEnvelope(newMapArea, getMapContext() |
1713 |
|
.getCoordinateReferenceSystem())); |
1714 |
} |
} |
1715 |
|
|
1716 |
/** |
/** |
1718 |
* @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 |
1719 |
* has been triggered. |
* has been triggered. |
1720 |
*/ |
*/ |
1721 |
public boolean setMapArea(final Envelope newMapArea) { |
public boolean setMapArea(final ReferencedEnvelope newMapArea) { |
1722 |
|
// |
1723 |
|
// if (getVisibleRect().getWidth() == 0 || (!isVisible()) || |
1724 |
|
// getVisibleRect().getHeight() == 0) { |
1725 |
|
// // The window is not yet defined.. so we can not really determine the |
1726 |
|
// asepect ratio for the mapPane. We store this as a candidate mappane |
1727 |
|
// and handle it when the component resizes or becomes visible) |
1728 |
|
// mapAreaCondidate = newMapArea; |
1729 |
|
// } |
1730 |
|
|
1731 |
if (newMapArea == null |
if (newMapArea == null |
1732 |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
|| bestAllowedMapArea(newMapArea).equals(mapArea)) { |
1781 |
bgContext.setAreaOfInterest(mapArea, localContext |
bgContext.setAreaOfInterest(mapArea, localContext |
1782 |
.getCoordinateReferenceSystem()); |
.getCoordinateReferenceSystem()); |
1783 |
} |
} |
1784 |
mapImageInvalid = true; |
|
1785 |
mapAreaChanged = true; |
mapAreaChanged = true; |
|
repaint(); |
|
1786 |
|
|
1787 |
LOGGER.debug("New maparea = " + mapArea); |
repaint(100); |
1788 |
|
|
1789 |
|
requestStartRendering(); |
1790 |
|
|
1791 |
return true; |
return true; |
1792 |
} |
} |
1793 |
|
|
1937 |
*/ |
*/ |
1938 |
private void startRendering() { |
private void startRendering() { |
1939 |
|
|
1940 |
if (!isWellDefined()) |
if (!isWellDefined() || !acceptsRepaintCalls) { |
1941 |
|
requestStartRendering = true; |
1942 |
return; |
return; |
1943 |
|
} |
1944 |
|
|
1945 |
if (bgExecuter != null) { |
if (bgExecuter != null) { |
1946 |
// Stop all renderers |
// Stop all renderers |
1972 |
// (Graphics2D) getBgImage().getGraphics(), createGTRenderer); |
// (Graphics2D) getBgImage().getGraphics(), createGTRenderer); |
1973 |
} |
} |
1974 |
|
|
1975 |
if (getContext() != null) { |
if (getMapContext() != null) { |
1976 |
// localExecuter = new RenderingExecutor(this, 150l); |
// localExecuter = new RenderingExecutor(this, 150l); |
1977 |
// LOGGER.debug("starting local renderer:"); |
// LOGGER.debug("starting local renderer:"); |
1978 |
|
|
1979 |
localRenderer.setJava2DHints(getJava2dHints()); |
localRenderer.setJava2DHints(getJava2dHints()); |
1980 |
localRenderer.setRendererHints(getRendererHints()); |
localRenderer.setRendererHints(getRendererHints()); |
1981 |
|
|
1982 |
ReferencedEnvelope areaOfInterest = getMapArea(); |
final boolean submitted = localExecuter.submit(getMapArea(), |
|
final boolean submitted = localExecuter.submit(areaOfInterest, |
|
1983 |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
curPaintArea, (Graphics2D) getLocalImage().getGraphics(), |
1984 |
localRenderer, getWorldToScreenTransform()); |
localRenderer |
1985 |
|
// , getWorldToScreenTransform() |
1986 |
|
); |
1987 |
if (submitted) |
if (submitted) |
1988 |
repaintTimer.restart(); |
repaintTimer.restart(); |
1989 |
else |
else |
1990 |
requestStartRendering = true; // Try to start rendering again in |
requestStartRendering = true; // Try to start rendering |
1991 |
|
// again in |
1992 |
// a moment |
// a moment |
1993 |
} |
} |
1994 |
|
|
2041 |
final AffineTransform at = getScreenToWorld(); |
final AffineTransform at = getScreenToWorld(); |
2042 |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
final Point2D geoO = at.transform(new Point2D.Double(ox, oy), null); |
2043 |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
final Point2D geoP = at.transform(new Point2D.Double(px, py), null); |
2044 |
|
|
2045 |
// Mmmmm... don't really understand why its x,x,y,y |
// Mmmmm... don't really understand why its x,x,y,y |
2046 |
// return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), geoP.getY()); |
// return new Envelope(geoO.getX(), geoP.getX(), geoO.getY(), |
2047 |
return new Envelope( new Coordinate(geoO.getX(), geoO.getY()), new Coordinate(geoP.getX(), geoP.getY())); |
// geoP.getY()); |
2048 |
|
return new Envelope(new Coordinate(geoO.getX(), geoO.getY()), |
2049 |
|
new Coordinate(geoP.getX(), geoP.getY())); |
2050 |
} |
} |
2051 |
|
|
2052 |
/** |
/** |
2064 |
} else { |
} else { |
2065 |
// Allow one last rendering |
// Allow one last rendering |
2066 |
if (repaintTimer.isRunning()) { |
if (repaintTimer.isRunning()) { |
2067 |
System.out.println("one last rendering...."); |
// System.out.println("one last rendering...."); |
2068 |
repaintTimer.stop(); |
repaintTimer.stop(); |
2069 |
updateFinalImage(); |
updateFinalImage(); |
2070 |
repaint(); |
repaint(); |
2162 |
|
|
2163 |
// Paint a logo to the bottom right if available |
// Paint a logo to the bottom right if available |
2164 |
if (mapImage != null) { |
if (mapImage != null) { |
2165 |
graphics.drawImage(mapImage, getBounds().width |
Rectangle visibleRect = getVisibleRect(); |
2166 |
- mapImage.getWidth() - 10, getBounds().height |
graphics.drawImage(mapImage, visibleRect.width |
2167 |
|
- mapImage.getWidth() - 10, getVisibleRect().height |
2168 |
- mapImage.getHeight() - 10, null); |
- mapImage.getHeight() - 10, null); |
2169 |
} |
} |
2170 |
|
|
2205 |
|
|
2206 |
String errStr = ex.getLocalizedMessage(); |
String errStr = ex.getLocalizedMessage(); |
2207 |
|
|
2208 |
|
if (errStr == null) |
2209 |
|
errStr = ex.getMessage(); |
2210 |
|
if (errStr == null) |
2211 |
|
errStr = "unknown error: " + ex.getClass().getSimpleName(); |
2212 |
|
|
2213 |
graphics.setColor(Color.WHITE); |
graphics.setColor(Color.WHITE); |
2214 |
graphics.drawString(errStr, 5, y); |
graphics.drawString(errStr, 5, y); |
2215 |
graphics.setColor(Color.RED); |
graphics.setColor(Color.RED); |
2233 |
public void zoomTo( |
public void zoomTo( |
2234 |
final FeatureCollection<SimpleFeatureType, SimpleFeature> features) { |
final FeatureCollection<SimpleFeatureType, SimpleFeature> features) { |
2235 |
|
|
2236 |
final CoordinateReferenceSystem mapCRS = getContext() |
// if (!isWellDefined()) return; |
2237 |
|
|
2238 |
|
final CoordinateReferenceSystem mapCRS = getMapContext() |
2239 |
.getCoordinateReferenceSystem(); |
.getCoordinateReferenceSystem(); |
2240 |
final CoordinateReferenceSystem fCRS = features.getSchema() |
final CoordinateReferenceSystem fCRS = features.getSchema() |
2241 |
.getGeometryDescriptor().getCoordinateReferenceSystem(); |
.getGeometryDescriptor().getCoordinateReferenceSystem(); |
2242 |
|
|
2243 |
double width = mapArea.getWidth(); |
ReferencedEnvelope _mapArea; |
2244 |
double height = mapArea.getHeight(); |
if (mapArea == null) |
2245 |
|
_mapArea = features.getBounds(); |
2246 |
|
else _mapArea = getMapArea(); |
2247 |
|
double width = _mapArea.getWidth(); |
2248 |
|
double height = _mapArea.getHeight(); |
2249 |
final double ratio = height / width; |
final double ratio = height / width; |
2250 |
|
|
2251 |
if (features == null || features.size() == 0) { |
if (features == null || features.size() == 0) { |
2297 |
} else { |
} else { |
2298 |
final ReferencedEnvelope fBounds = features.getBounds(); |
final ReferencedEnvelope fBounds = features.getBounds(); |
2299 |
|
|
2300 |
Envelope bounds; |
ReferencedEnvelope bounds; |
2301 |
if (!mapCRS.equals(fCRS)) { |
if (!mapCRS.equals(fCRS)) { |
2302 |
bounds = JTSUtil.transformEnvelope(fBounds, fCRS, mapCRS); |
bounds = JTSUtil.transformEnvelope(fBounds, mapCRS); |
2303 |
} else { |
} else { |
2304 |
bounds = fBounds; |
bounds = fBounds; |
2305 |
} |
} |
2354 |
newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea |
newMapArea.expandBy((mapArea.getWidth() * zoomFaktor - mapArea |
2355 |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
.getWidth()) / 2., (mapArea.getHeight() * zoomFaktor - mapArea |
2356 |
.getHeight()) / 2.); |
.getHeight()) / 2.); |
2357 |
|
|
2358 |
// TODO we actually want that |
// TODO we actually want that |
2359 |
// // Move the newMapArea above the new center |
// // Move the newMapArea above the new center |
2360 |
// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
// newMapArea.translate(gcenter.getX() - mapArea.centre().x, gcenter |
2361 |
// .getY() |
// .getY() |
2362 |
// - mapArea.centre().y); |
// - mapArea.centre().y); |
2363 |
|
|
2364 |
setMapArea(newMapArea); |
setMapArea(newMapArea); |
2365 |
} |
} |