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 |
|
|
|
8 |
|
|
import org.opengis.geometry.DirectPosition; |
9 |
|
|
|
10 |
alfonx |
644 |
import com.vividsolutions.jts.geom.Coordinate; |
11 |
|
|
import com.vividsolutions.jts.geom.Envelope; |
12 |
|
|
|
13 |
alfonx |
639 |
public class XMapPaneAction_ZoomIn implements XMapPaneAction { |
14 |
alfonx |
644 |
|
15 |
alfonx |
639 |
@Override |
16 |
|
|
public void performClick(XMapPane mapPane, MouseEvent ev, |
17 |
|
|
DirectPosition coord) { |
18 |
alfonx |
644 |
|
19 |
alfonx |
639 |
mapPane.zoomTo(ev.getPoint(), 1 / 2.); |
20 |
|
|
} |
21 |
|
|
|
22 |
|
|
@Override |
23 |
|
|
public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt, |
24 |
|
|
DirectPosition coord) { |
25 |
|
|
|
26 |
|
|
final int units = wheelEvt.getUnitsToScroll(); |
27 |
|
|
if (units > 0) |
28 |
|
|
mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units); |
29 |
|
|
else |
30 |
|
|
mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units); |
31 |
|
|
} |
32 |
|
|
|
33 |
|
|
@Override |
34 |
alfonx |
644 |
public void performDragging(XMapPane mapPane, MouseEvent ev, |
35 |
|
|
Point dragStartPos, Point dragLastPos, DirectPosition startCoord, |
36 |
|
|
DirectPosition endCoord) { |
37 |
|
|
|
38 |
|
|
if (dragLastPos != null) |
39 |
|
|
mapPane.drawRectangle(mapPane.getGraphics(), dragLastPos, ev |
40 |
|
|
.getPoint()); |
41 |
|
|
|
42 |
|
|
mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev |
43 |
|
|
.getPoint()); |
44 |
|
|
} |
45 |
|
|
|
46 |
|
|
@Override |
47 |
alfonx |
639 |
public void performDragged(XMapPane mapPane, MouseEvent ev, |
48 |
alfonx |
640 |
Point dragStartPos, Point dragLastPos, DirectPosition startCoord, |
49 |
alfonx |
639 |
DirectPosition endCoord) { |
50 |
|
|
|
51 |
alfonx |
644 |
if (dragLastPos != null) |
52 |
|
|
mapPane.drawRectangle(mapPane.getGraphics(), dragLastPos, ev |
53 |
|
|
.getPoint()); |
54 |
|
|
|
55 |
|
|
// If this is similar to a click, let mouseClicked handle it! |
56 |
|
|
if ((Math.abs(dragStartPos.x - ev.getPoint().x) * Math.abs(ev |
57 |
|
|
.getPoint().y |
58 |
|
|
- dragStartPos.y)) < 160) { |
59 |
|
|
// performClick(mapPane, ev, coord) |
60 |
|
|
return; |
61 |
|
|
} |
62 |
|
|
|
63 |
|
|
final Rectangle bounds = mapPane.getBounds(); |
64 |
|
|
|
65 |
|
|
Envelope mapArea = mapPane.getMapArea(); |
66 |
|
|
|
67 |
|
|
// Replace with transform and translate |
68 |
|
|
final double mapWidth = mapArea.getWidth(); |
69 |
|
|
final double mapHeight = mapArea.getHeight(); |
70 |
|
|
|
71 |
|
|
final double startX = ((dragStartPos.x * mapWidth) / (double) bounds.width) |
72 |
|
|
+ mapArea.getMinX(); |
73 |
|
|
final double startY = (((bounds.getHeight() - dragStartPos.y) * mapHeight) / (double) bounds.height) |
74 |
|
|
+ mapArea.getMinY(); |
75 |
|
|
final double endX = ((ev.getPoint().x * mapWidth) / (double) bounds.width) |
76 |
|
|
+ mapArea.getMinX(); |
77 |
|
|
final double endY = (((bounds.getHeight() - ev.getPoint().y) * mapHeight) / (double) bounds.height) |
78 |
|
|
+ mapArea.getMinY(); |
79 |
|
|
|
80 |
|
|
final double left = Math.min(startX, endX); |
81 |
|
|
final double right = Math.max(startX, endX); |
82 |
|
|
final double bottom = Math.min(startY, endY); |
83 |
|
|
final double top = Math.max(startY, endY); |
84 |
|
|
final Coordinate ll = new Coordinate(left, bottom); |
85 |
|
|
final Coordinate ur = new Coordinate(right, top); |
86 |
|
|
|
87 |
|
|
mapPane.setMapArea(new Envelope(ll, ur)); |
88 |
|
|
|
89 |
alfonx |
639 |
} |
90 |
|
|
|
91 |
|
|
} |