/[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 644 - (show annotations)
Thu Jan 28 16:28:36 2010 UTC (15 years, 1 month ago) by alfonx
Original Path: branches/2.0-RC2/src/skrueger/geotools/XMapPaneAction_ZoomIn.java
File MIME type: text/plain
File size: 2715 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 class XMapPaneAction_ZoomIn implements XMapPaneAction {
14
15 @Override
16 public void performClick(XMapPane mapPane, MouseEvent ev,
17 DirectPosition coord) {
18
19 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 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 public void performDragged(XMapPane mapPane, MouseEvent ev,
48 Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
49 DirectPosition endCoord) {
50
51 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 }
90
91 }

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