[Schmitzm-commits] r650 - branches/2.0-RC2/src/skrueger/geotools

scm-commit@wald.intevation.org scm-commit at wald.intevation.org
Thu Jan 28 18:43:55 CET 2010


Author: mojays
Date: 2010-01-28 18:43:54 +0100 (Thu, 28 Jan 2010)
New Revision: 650

Modified:
   branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java
Log:


Modified: branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java
===================================================================
--- branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java	2010-01-28 17:24:15 UTC (rev 649)
+++ branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java	2010-01-28 17:43:54 UTC (rev 650)
@@ -4,6 +4,7 @@
 import java.awt.Rectangle;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseWheelEvent;
+import java.awt.geom.Point2D;
 
 import org.opengis.geometry.DirectPosition;
 
@@ -38,11 +39,33 @@
 		public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
 				DirectPosition coord) {
 
-			final int units = wheelEvt.getUnitsToScroll();
-			if (units > 0)
-				mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units);
-			else
-				mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units);
+	        int units = wheelEvt.getUnitsToScroll();
+	        // Positiver Wert --> Zoom in --> Faktor < 1
+	        // Negativer Wert --> Zoom out --> Faktir > 1
+
+	        // SK: 9.9.2007 zoom jetzt wie bei GoogleEarth
+	        double zFactor = units > 0 ? 1.3 : 1 / 1.3;
+	        // vorher double zFactor = units > 0 ? 1/1.2 : 1.2;
+
+	        // Fenster-Koordinaten zu Karten-Koordinaten transformieren
+	        Point2D mapCoord = XMapPane.getMapCoordinatesFromEvent(wheelEvt);
+	        // Relative Position des Mauszeigers zum Kartenausschnitt
+	        // -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
+	        // erscheinen, wie vor dem Zoom
+	        double relX = (mapCoord.getX() - mapPane.getMapArea().getMinX())
+	                / mapPane.getMapArea().getWidth();
+	        double relY = (mapCoord.getY() - mapPane.getMapArea().getMinY())
+	                / mapPane.getMapArea().getHeight();
+
+	        // Neuen Karten-Ausschnitt berechnen
+	        Coordinate ll = new Coordinate(mapCoord.getX()
+	                - mapPane.getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
+	                - mapPane.getMapArea().getHeight() * relY * zFactor);
+	        Coordinate ur = new Coordinate(mapCoord.getX()
+	                + mapPane.getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
+	                .getY()
+	                + mapPane.getMapArea().getHeight() * (1 - relY) * zFactor);
+	        mapPane.setMapArea(new Envelope(ll, ur));
 		}
 
 		@Override
@@ -103,12 +126,33 @@
 		@Override
 		public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
 				DirectPosition coord) {
+          int units = wheelEvt.getUnitsToScroll();
+          // Positiver Wert --> Zoom in --> Faktor < 1
+          // Negativer Wert --> Zoom out --> Faktir > 1
 
-			final int units = wheelEvt.getUnitsToScroll();
-			if (units <= 0)
-				mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units);
-			else
-				mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units);
+          // SK: 9.9.2007 zoom jetzt wie bei GoogleEarth
+          double zFactor = units > 0 ? 1.3 : 1 / 1.3;
+          // vorher double zFactor = units > 0 ? 1/1.2 : 1.2;
+
+          // Fenster-Koordinaten zu Karten-Koordinaten transformieren
+          Point2D mapCoord = XMapPane.getMapCoordinatesFromEvent(wheelEvt);
+          // Relative Position des Mauszeigers zum Kartenausschnitt
+          // -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
+          // erscheinen, wie vor dem Zoom
+          double relX = (mapCoord.getX() - mapPane.getMapArea().getMinX())
+                  / mapPane.getMapArea().getWidth();
+          double relY = (mapCoord.getY() - mapPane.getMapArea().getMinY())
+                  / mapPane.getMapArea().getHeight();
+
+          // Neuen Karten-Ausschnitt berechnen
+          Coordinate ll = new Coordinate(mapCoord.getX()
+                  - mapPane.getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
+                  - mapPane.getMapArea().getHeight() * relY * zFactor);
+          Coordinate ur = new Coordinate(mapCoord.getX()
+                  + mapPane.getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
+                  .getY()
+                  + mapPane.getMapArea().getHeight() * (1 - relY) * zFactor);
+          mapPane.setMapArea(new Envelope(ll, ur));
 		}
 
 



More information about the Schmitzm-commits mailing list