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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 646 - (show annotations)
Thu Jan 28 16:47:13 2010 UTC (15 years, 1 month ago) by alfonx
File MIME type: text/plain
File size: 2765 byte(s)


1 package skrueger.geotools;
2
3 import java.awt.Point;
4 import java.awt.Rectangle;
5 import java.awt.event.MouseEvent;
6 import java.awt.event.MouseWheelEvent;
7
8 import org.opengis.geometry.DirectPosition;
9
10 import com.vividsolutions.jts.geom.Coordinate;
11 import com.vividsolutions.jts.geom.Envelope;
12
13 public abstract class XMapPaneAction_Zoom implements XMapPaneAction {
14
15 public static class In extends XMapPaneAction_Zoom {
16
17 @Override
18 public void performClick(XMapPane mapPane, MouseEvent ev,
19 DirectPosition coord) {
20
21 mapPane.zoomTo(ev.getPoint(), 1 / 2.);
22 }
23
24 @Override
25 public void performWheel(XMapPane mapPane, MouseWheelEvent wheelEvt,
26 DirectPosition coord) {
27
28 final int units = wheelEvt.getUnitsToScroll();
29 if (units > 0)
30 mapPane.zoomTo(wheelEvt.getPoint(), 1. + .11 * units);
31 else
32 mapPane.zoomTo(wheelEvt.getPoint(), 2. / -units);
33 }
34
35 @Override
36 public void performDragging(XMapPane mapPane, MouseEvent ev,
37 Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
38 DirectPosition endCoord) {
39
40 if (dragLastPos != null)
41 mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, dragLastPos);
42
43 mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev
44 .getPoint());
45 }
46
47 @Override
48 public void performDragged(XMapPane mapPane, MouseEvent ev,
49 Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
50 DirectPosition endCoord) {
51
52 if (dragLastPos != null)
53 mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, dragLastPos );
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 }
90
91 }
92
93 }

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