[Schmitzm-commits] r536 - branches/1.0-gt2-2.6/src/skrueger/geotools
scm-commit@wald.intevation.org
scm-commit at wald.intevation.org
Fri Nov 20 16:38:35 CET 2009
Author: alfonx
Date: 2009-11-20 16:38:34 +0100 (Fri, 20 Nov 2009)
New Revision: 536
Modified:
branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
Log:
* resetTransforms method in XMapPane changed. Not panning is putting the image where one would expect. BUT on the other hand the left map broder is wrong... still is still work in progress
Modified: branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java
===================================================================
--- branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java 2009-11-20 12:08:55 UTC (rev 535)
+++ branches/1.0-gt2-2.6/src/skrueger/geotools/XMapPane.java 2009-11-20 15:38:34 UTC (rev 536)
@@ -30,6 +30,7 @@
import org.apache.log4j.Logger;
import org.geotools.feature.FeatureCollection;
+import org.geotools.geometry.Envelope2D;
import org.geotools.geometry.jts.JTS;
import org.geotools.geometry.jts.ReferencedEnvelope;
import org.geotools.map.DefaultMapContext;
@@ -1609,44 +1610,81 @@
requestStartRendering = true;
}
+//
+// /**
+// * 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);
+// }
+// }
+
+
- /**
- * Berechnet die Transformation zwischen Fenster- und Karten-Koordinaten
- * neu.
- */
- protected void resetTransforms() {
- if (getMapArea() == null || getWidth() == 0 || getHeight() == 0)
- return;
+ /**
+ * Calculate the affine transforms used to convert between
+ * world and pixel coordinates. The calculations here are very
+ * basic and assume a cartesian reference system.
+ * <p>
+ * Tne transform is calculated such that {@code envelope} will
+ * be centred in the display
+ *
+ * @param envelope the current map extent (world coordinates)
+ * @param paintArea the current map pane extent (screen units)
+ */
+ private void resetTransforms() {
+ ReferencedEnvelope refEnv = new ReferencedEnvelope(mapArea, getContext().getCoordinateReferenceSystem());
- // We store the last Transform
- oldScreenToWorld = screenToWorld;
+ Rectangle paintArea = getBounds();
+
+ double xscale = paintArea.getWidth() / refEnv.getWidth();
+ double yscale = paintArea.getHeight() / refEnv.getHeight();
- 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());
+ double scale = Math.min(xscale, yscale);
- try {
- this.worldToScreen = screenToWorld.createInverse();
- } catch (final NoninvertibleTransformException e) {
- LOGGER.error(e);
- }
- }
+ double xoff = refEnv.getMedian(0) * scale - paintArea.getCenterX();
+ double yoff = refEnv.getMedian(1) * scale + paintArea.getCenterY();
+ worldToScreen = new AffineTransform(scale, 0, 0, -scale, -xoff, yoff);
+ try {
+ screenToWorld = worldToScreen.createInverse();
+
+ } catch (NoninvertibleTransformException ex) {
+ ex.printStackTrace();
+ }
+ }
+
+
+
public void setBgContext(final MapContext context) {
// Remove the default listener from the old context
More information about the Schmitzm-commits
mailing list