36 |
import org.geotools.geometry.jts.JTS; |
import org.geotools.geometry.jts.JTS; |
37 |
import org.geotools.geometry.jts.ReferencedEnvelope; |
import org.geotools.geometry.jts.ReferencedEnvelope; |
38 |
import org.geotools.map.DefaultMapContext; |
import org.geotools.map.DefaultMapContext; |
39 |
|
import org.geotools.map.DefaultMapLayer; |
40 |
import org.geotools.map.MapContext; |
import org.geotools.map.MapContext; |
41 |
import org.geotools.map.MapLayer; |
import org.geotools.map.MapLayer; |
42 |
import org.geotools.map.event.MapLayerEvent; |
import org.geotools.map.event.MapLayerEvent; |
50 |
import org.geotools.renderer.lite.RendererUtilities; |
import org.geotools.renderer.lite.RendererUtilities; |
51 |
import org.geotools.renderer.lite.StreamingRenderer; |
import org.geotools.renderer.lite.StreamingRenderer; |
52 |
import org.geotools.resources.image.ImageUtilities; |
import org.geotools.resources.image.ImageUtilities; |
53 |
|
import org.geotools.styling.Style; |
54 |
import org.geotools.swing.JMapPane; |
import org.geotools.swing.JMapPane; |
55 |
import org.geotools.swing.event.MapMouseEvent; |
import org.geotools.swing.event.MapMouseEvent; |
56 |
import org.geotools.swing.event.MapPaneEvent; |
import org.geotools.swing.event.MapPaneEvent; |
68 |
import schmitzm.geotools.io.GeoImportUtil; |
import schmitzm.geotools.io.GeoImportUtil; |
69 |
import schmitzm.geotools.map.event.JMapPaneListener; |
import schmitzm.geotools.map.event.JMapPaneListener; |
70 |
import schmitzm.geotools.map.event.MapLayerAdapter; |
import schmitzm.geotools.map.event.MapLayerAdapter; |
71 |
|
import schmitzm.geotools.styling.StylingUtil; |
72 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
73 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
74 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
613 |
*/ |
*/ |
614 |
public XMapPane(final MapContext localContext_, |
public XMapPane(final MapContext localContext_, |
615 |
final Map<Object, Object> rendererHints) { |
final Map<Object, Object> rendererHints) { |
616 |
|
|
617 |
super(true); |
super(true); |
618 |
|
|
619 |
|
blinkTimer = initBlinkTimer(); |
620 |
|
|
621 |
// A default setting |
// A default setting |
622 |
RenderingHints hintsJava2d = ImageUtilities.NN_INTERPOLATION_HINT; |
RenderingHints hintsJava2d = ImageUtilities.NN_INTERPOLATION_HINT; |
747 |
|
|
748 |
} |
} |
749 |
|
|
750 |
|
|
751 |
/** |
/** |
752 |
* Fuegt der Map einen Listener hinzu. |
* Fuegt der Map einen Listener hinzu. |
753 |
* |
* |
824 |
|
|
825 |
final Envelope maxAllowedExtend = getMaxExtend(); |
final Envelope maxAllowedExtend = getMaxExtend(); |
826 |
|
|
827 |
|
// This variable is used to break the loop if it runs forever... |
828 |
|
Envelope lastCalculatedArea = null; |
829 |
/* |
/* |
830 |
* If a maxAllowedExtend is set, we have to honour that... |
* If a maxAllowedExtend is set, we have to honour that... |
831 |
*/ |
*/ |
|
Envelope lastCalculatedArea = null; |
|
832 |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
while (maxAllowedExtend != null && !maxAllowedExtend.contains(newArea) |
833 |
&& newArea != null && !newArea.isNull() |
&& newArea != null && !newArea.isNull() |
834 |
&& !Double.isNaN(newArea.getMinX()) |
&& !Double.isNaN(newArea.getMinX()) |
835 |
&& !Double.isNaN(newArea.getMaxX()) |
&& !Double.isNaN(newArea.getMaxX()) |
836 |
&& !Double.isNaN(newArea.getMinY()) |
&& !Double.isNaN(newArea.getMinY()) |
837 |
&& !Double.isNaN(newArea.getMaxY()) |
&& !Double.isNaN(newArea.getMaxY())) // Due to Double precision |
838 |
) // Due to Double precision problems, this may iterate for ever |
// problems, this may |
839 |
|
// iterate for ever |
840 |
{ |
{ |
841 |
|
|
842 |
if (newArea.equals(lastCalculatedArea)) |
if (newArea.equals(lastCalculatedArea)) |
843 |
break; |
break; |
844 |
// Check that we are not iterating for ever due to double precision rounding errors |
// Check that we are not iterating for ever due to double precision |
845 |
|
// rounding errors |
846 |
lastCalculatedArea = newArea; |
lastCalculatedArea = newArea; |
847 |
|
|
848 |
// Exceeds top? Move down and maybe cut |
// Exceeds top? Move down and maybe cut |
849 |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
if (newArea.getMaxY() > maxAllowedExtend.getMaxY()) { |
850 |
final double divY = newArea.getMaxY() |
final double divY = newArea.getMaxY() |
948 |
.getCoordinateReferenceSystem()), false); |
.getCoordinateReferenceSystem()), false); |
949 |
} |
} |
950 |
} |
} |
951 |
|
|
|
|
|
952 |
} |
} |
953 |
|
|
954 |
return new ReferencedEnvelope(newArea, env |
return new ReferencedEnvelope(newArea, env |
1264 |
return null; |
return null; |
1265 |
} |
} |
1266 |
|
|
1267 |
return JTSUtil |
return JTSUtil.fixAspectRatio(getVisibleRect(), |
1268 |
.fixAspectRatio(getVisibleRect(), addDefaultMargin(layerBounds), true); |
addDefaultMargin(layerBounds), true); |
1269 |
|
|
1270 |
} |
} |
1271 |
return maxExtend; |
return maxExtend; |
1966 |
private long lastRenderingDuration = 1000; |
private long lastRenderingDuration = 1000; |
1967 |
private XMapPaneTool tool = null; |
private XMapPaneTool tool = null; |
1968 |
|
|
1969 |
|
private Timer blinkTimer ; |
1970 |
|
|
1971 |
/** |
/** |
1972 |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
* Set the minimum (nearest) allowed zoom scale. This is the bigger number |
1973 |
* value of the two. If <code>null</code> is passed, Double.MAXVALUE are |
* value of the two. If <code>null</code> is passed, Double.MAXVALUE are |
2120 |
* X-Koordinate der BIS-Position |
* X-Koordinate der BIS-Position |
2121 |
* @param py |
* @param py |
2122 |
* Y-Koordinate der BIS-Position |
* Y-Koordinate der BIS-Position |
|
* @param winToGeotransform |
|
|
* Eine Window to Geo transform. If <code>null</code>, |
|
|
* {@link #getScreenToWorld()} is used. |
|
2123 |
*/ |
*/ |
2124 |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
public Envelope tranformGeoToWindow(final double ox, final double oy, |
2125 |
final double px, final double py) { |
final double px, final double py) { |
2136 |
} |
} |
2137 |
|
|
2138 |
/** |
/** |
2139 |
|
* Transformiert einen Geo-Koordinate in eine Fenster-Koordinaten. |
2140 |
|
* |
2141 |
|
* @param x |
2142 |
|
* X-Koordinate der VON-Position |
2143 |
|
* @param y |
2144 |
|
* Y-Koordinate der VON-Position |
2145 |
|
*/ |
2146 |
|
public Point2D tranformGeoToWindow(final double x, final double y) { |
2147 |
|
return getWorldToScreenTransform().transform(new Point2D.Double(x, y), |
2148 |
|
null); |
2149 |
|
} |
2150 |
|
|
2151 |
|
/** |
2152 |
* Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten. |
* Transformiert einen Fenster-Koordinaten-Bereich in Geo-Koordinaten. |
2153 |
* |
* |
2154 |
* @param ox |
* @param ox |
2271 |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
SwingUtil.clearAround(finalG, painedArea, getVisibleRect(), |
2272 |
getMapBackgroundColor()); |
getMapBackgroundColor()); |
2273 |
|
|
2274 |
addGadgets(finalG, false); |
addGadgets(finalG, false); |
2275 |
|
|
2276 |
finalG.dispose(); |
finalG.dispose(); |
2277 |
|
|
2707 |
public double getDefaultMaxMapExtendMode() { |
public double getDefaultMaxMapExtendMode() { |
2708 |
return defaultMaxMapExtendMode; |
return defaultMaxMapExtendMode; |
2709 |
} |
} |
2710 |
|
|
2711 |
|
|
2712 |
|
final static int BLINK_TIMER_DEPLAY = 800; |
2713 |
|
|
2714 |
|
private Timer initBlinkTimer() { |
2715 |
|
Timer timer = new Timer(BLINK_TIMER_DEPLAY, new ActionListener() { |
2716 |
|
|
2717 |
|
@Override |
2718 |
|
public void actionPerformed(ActionEvent e) { |
2719 |
|
XMapPane.this.repaint(300); |
2720 |
|
} |
2721 |
|
}); |
2722 |
|
timer.setDelay(BLINK_TIMER_DEPLAY); |
2723 |
|
timer.setRepeats(false); |
2724 |
|
return timer; |
2725 |
|
} |
2726 |
|
|
2727 |
|
/** |
2728 |
|
* Makes the given {@link FeatureCollection} bink in the map for a moment |
2729 |
|
*/ |
2730 |
|
public void blink( |
2731 |
|
FeatureCollection<SimpleFeatureType, SimpleFeature> features) { |
2732 |
|
{ |
2733 |
|
blinkTimer.stop(); |
2734 |
|
repaint(); |
2735 |
|
blinkTimer = initBlinkTimer(); |
2736 |
|
|
2737 |
|
DefaultMapContext mc = new DefaultMapContext(getMapContext() |
2738 |
|
.getCoordinateReferenceSystem()); |
2739 |
|
|
2740 |
|
Style style = StylingUtil.STYLE_FACTORY.createStyle(); |
2741 |
|
style.featureTypeStyles().add( |
2742 |
|
StylingUtil.createBlinkFeatureTypeStyle(features)); |
2743 |
|
|
2744 |
|
// style = StylingUtil.createStyleSimple(features, Color.pink, |
2745 |
|
// Color.WHITE); |
2746 |
|
|
2747 |
|
DefaultMapLayer dml = new DefaultMapLayer(features, style); |
2748 |
|
mc.addLayer(dml); |
2749 |
|
|
2750 |
|
GTRenderer renderer = new StreamingRenderer(); |
2751 |
|
|
2752 |
|
renderer.setJava2DHints(getJava2dHints()); |
2753 |
|
|
2754 |
|
renderer.setContext(mc); |
2755 |
|
|
2756 |
|
Graphics2D g2d = (Graphics2D) getGraphics(); |
2757 |
|
renderer.paint(g2d, getVisibleRect(), getMapArea()); |
2758 |
|
|
2759 |
|
blinkTimer.start(); |
2760 |
|
|
2761 |
|
} |
2762 |
|
|
2763 |
|
} |
2764 |
|
|
2765 |
} |
} |