/[schmitzm]/branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java
ViewVC logotype

Annotation of /branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_Zoom.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 650 - (hide annotations)
Thu Jan 28 17:43:54 2010 UTC (15 years, 1 month ago) by mojays
File MIME type: text/plain
File size: 8277 byte(s)


1 alfonx 639 package skrueger.geotools;
2    
3     import java.awt.Point;
4 alfonx 644 import java.awt.Rectangle;
5 alfonx 639 import java.awt.event.MouseEvent;
6     import java.awt.event.MouseWheelEvent;
7 mojays 650 import java.awt.geom.Point2D;
8 alfonx 639
9     import org.opengis.geometry.DirectPosition;
10    
11 alfonx 644 import com.vividsolutions.jts.geom.Coordinate;
12     import com.vividsolutions.jts.geom.Envelope;
13    
14 alfonx 646 public abstract class XMapPaneAction_Zoom implements XMapPaneAction {
15 alfonx 644
16 alfonx 649 @Override
17     public void performDragging(XMapPane mapPane, MouseEvent ev,
18     Point dragStartPos, Point dragLastPos,
19     DirectPosition startCoord, DirectPosition endCoord) {
20    
21     if (dragLastPos != null)
22     mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
23     dragLastPos);
24    
25     mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev
26     .getPoint());
27     }
28    
29 alfonx 648 public static class In extends XMapPaneAction_Zoom {
30 alfonx 646
31 alfonx 648 @Override
32     public void performClick(XMapPane mapPane, MouseEvent ev,
33     DirectPosition coord) {
34 alfonx 644
35 alfonx 648 mapPane.zoomTo(ev.getPoint(), 1 / 2.);
36     }
37 alfonx 639
38 alfonx 648 @Override
39     public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
40     DirectPosition coord) {
41 alfonx 639
42 mojays 650 int units = wheelEvt.getUnitsToScroll();
43     // Positiver Wert --> Zoom in --> Faktor < 1
44     // Negativer Wert --> Zoom out --> Faktir > 1
45    
46     // SK: 9.9.2007 zoom jetzt wie bei GoogleEarth
47     double zFactor = units > 0 ? 1.3 : 1 / 1.3;
48     // vorher double zFactor = units > 0 ? 1/1.2 : 1.2;
49    
50     // Fenster-Koordinaten zu Karten-Koordinaten transformieren
51     Point2D mapCoord = XMapPane.getMapCoordinatesFromEvent(wheelEvt);
52     // Relative Position des Mauszeigers zum Kartenausschnitt
53     // -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
54     // erscheinen, wie vor dem Zoom
55     double relX = (mapCoord.getX() - mapPane.getMapArea().getMinX())
56     / mapPane.getMapArea().getWidth();
57     double relY = (mapCoord.getY() - mapPane.getMapArea().getMinY())
58     / mapPane.getMapArea().getHeight();
59    
60     // Neuen Karten-Ausschnitt berechnen
61     Coordinate ll = new Coordinate(mapCoord.getX()
62     - mapPane.getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
63     - mapPane.getMapArea().getHeight() * relY * zFactor);
64     Coordinate ur = new Coordinate(mapCoord.getX()
65     + mapPane.getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
66     .getY()
67     + mapPane.getMapArea().getHeight() * (1 - relY) * zFactor);
68     mapPane.setMapArea(new Envelope(ll, ur));
69 alfonx 648 }
70 alfonx 639
71 alfonx 648 @Override
72     public void performDragged(XMapPane mapPane, MouseEvent ev,
73     Point dragStartPos, Point dragLastPos,
74     DirectPosition startCoord, DirectPosition endCoord) {
75    
76     if (dragLastPos != null)
77     mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
78     dragLastPos);
79    
80     // If this is similar to a click, let mouseClicked handle it!
81     if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
82     .getPoint().y
83     - dragStartPos.y)) < 160) {
84     // performClick(mapPane, ev, coord)
85     return;
86     }
87    
88     final Rectangle bounds = mapPane.getBounds();
89    
90     Envelope mapArea = mapPane.getMapArea();
91    
92     // Replace with transform and translate
93     final double mapWidth = mapArea.getWidth();
94     final double mapHeight = mapArea.getHeight();
95    
96     final double startX = ((dragStartPos.x * mapWidth) / (double) bounds.width)
97     + mapArea.getMinX();
98     final double startY = (((bounds.getHeight() - dragStartPos.y) * mapHeight) / (double) bounds.height)
99     + mapArea.getMinY();
100     final double endX = ((ev.getPoint().x * mapWidth) / (double) bounds.width)
101     + mapArea.getMinX();
102     final double endY = (((bounds.getHeight() - ev.getPoint().y) * mapHeight) / (double) bounds.height)
103     + mapArea.getMinY();
104    
105     final double left = Math.min(startX, endX);
106     final double right = Math.max(startX, endX);
107     final double bottom = Math.min(startY, endY);
108     final double top = Math.max(startY, endY);
109     final Coordinate ll = new Coordinate(left, bottom);
110     final Coordinate ur = new Coordinate(right, top);
111    
112     mapPane.setMapArea(new Envelope(ll, ur));
113    
114     }
115 alfonx 644 }
116    
117 alfonx 648 public static class Out extends XMapPaneAction_Zoom {
118 alfonx 639
119 alfonx 648 @Override
120     public void performClick(XMapPane mapPane, MouseEvent ev,
121     DirectPosition coord) {
122 alfonx 644
123 alfonx 648 mapPane.zoomTo(ev.getPoint(), 2.);
124 alfonx 644 }
125    
126 alfonx 648 @Override
127     public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
128     DirectPosition coord) {
129 mojays 650 int units = wheelEvt.getUnitsToScroll();
130     // Positiver Wert --> Zoom in --> Faktor < 1
131     // Negativer Wert --> Zoom out --> Faktir > 1
132 alfonx 644
133 mojays 650 // SK: 9.9.2007 zoom jetzt wie bei GoogleEarth
134     double zFactor = units > 0 ? 1.3 : 1 / 1.3;
135     // vorher double zFactor = units > 0 ? 1/1.2 : 1.2;
136    
137     // Fenster-Koordinaten zu Karten-Koordinaten transformieren
138     Point2D mapCoord = XMapPane.getMapCoordinatesFromEvent(wheelEvt);
139     // Relative Position des Mauszeigers zum Kartenausschnitt
140     // -> Nach Zoom soll dieselbe Kartenposition unterhalb des Mauszeigers
141     // erscheinen, wie vor dem Zoom
142     double relX = (mapCoord.getX() - mapPane.getMapArea().getMinX())
143     / mapPane.getMapArea().getWidth();
144     double relY = (mapCoord.getY() - mapPane.getMapArea().getMinY())
145     / mapPane.getMapArea().getHeight();
146    
147     // Neuen Karten-Ausschnitt berechnen
148     Coordinate ll = new Coordinate(mapCoord.getX()
149     - mapPane.getMapArea().getWidth() * relX * zFactor, mapCoord.getY()
150     - mapPane.getMapArea().getHeight() * relY * zFactor);
151     Coordinate ur = new Coordinate(mapCoord.getX()
152     + mapPane.getMapArea().getWidth() * (1 - relX) * zFactor, mapCoord
153     .getY()
154     + mapPane.getMapArea().getHeight() * (1 - relY) * zFactor);
155     mapPane.setMapArea(new Envelope(ll, ur));
156 alfonx 648 }
157 alfonx 644
158    
159 alfonx 648 @Override
160     public void performDragged(XMapPane mapPane, MouseEvent ev,
161     Point dragStartPos, Point dragLastPos,
162     DirectPosition startCoord, DirectPosition endCoord) {
163 alfonx 644
164 alfonx 648 if (dragLastPos != null)
165     mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos,
166     dragLastPos);
167 alfonx 639
168 alfonx 648 // If this is similar to a click, let mouseClicked handle it!
169     if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev
170     .getPoint().y
171     - dragStartPos.y)) < 160) {
172     // performClick(mapPane, ev, coord)
173     return;
174     }
175 alfonx 646
176 alfonx 648 final Rectangle bounds = mapPane.getBounds();
177    
178     Envelope mapArea = mapPane.getMapArea();
179    
180     // Replace with transform and translate
181     final double mapWidth = mapArea.getWidth();
182     final double mapHeight = mapArea.getHeight();
183    
184     final double startX = ((dragStartPos.x * mapWidth) / (double) bounds.width)
185     + mapArea.getMinX();
186     final double startY = (((bounds.getHeight() - dragStartPos.y) * mapHeight) / (double) bounds.height)
187     + mapArea.getMinY();
188     final double endX = ((ev.getPoint().x * mapWidth) / (double) bounds.width)
189     + mapArea.getMinX();
190     final double endY = (((bounds.getHeight() - ev.getPoint().y) * mapHeight) / (double) bounds.height)
191     + mapArea.getMinY();
192    
193     // make the dragged rectangle in screen coords the new map size?
194     final double left = Math.min(startX, endX);
195     final double right = Math.max(startX, endX);
196     final double bottom = Math.min(startY, endY);
197     final double top = Math.max(startY, endY);
198     final double nWidth = (mapWidth * mapWidth) / (right - left);
199     final double nHeight = (mapHeight * mapHeight) / (top - bottom);
200     final double deltaX1 = left - mapArea.getMinX();
201     final double nDeltaX1 = (deltaX1 * nWidth) / mapWidth;
202     final double deltaY1 = bottom - mapArea.getMinY();
203     final double nDeltaY1 = (deltaY1 * nHeight) / mapHeight;
204     final Coordinate ll = new Coordinate(mapArea.getMinX() - nDeltaX1,
205     mapArea.getMinY() - nDeltaY1);
206     final double deltaX2 = mapArea.getMaxX() - right;
207     final double nDeltaX2 = (deltaX2 * nWidth) / mapWidth;
208     final double deltaY2 = mapArea.getMaxY() - top;
209     final double nDeltaY2 = (deltaY2 * nHeight) / mapHeight;
210     final Coordinate ur = new Coordinate(mapArea.getMaxX() + nDeltaX2,
211     mapArea.getMaxY() + nDeltaY2);
212    
213     mapPane.setMapArea(new Envelope(ll, ur));
214    
215     }
216     }
217 alfonx 646 }

Properties

Name Value
svn:eol-style native
svn:keywords Id URL
svn:mime-type text/plain

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26