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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 643 by alfonx, Thu Jan 28 16:12:04 2010 UTC revision 644 by alfonx, Thu Jan 28 16:28:36 2010 UTC
# Line 1  Line 1 
1  package skrueger.geotools;  package skrueger.geotools;
2    
3  import java.awt.Point;  import java.awt.Point;
4    import java.awt.Rectangle;
5  import java.awt.event.MouseEvent;  import java.awt.event.MouseEvent;
6  import java.awt.event.MouseWheelEvent;  import java.awt.event.MouseWheelEvent;
7    
8  import org.opengis.geometry.DirectPosition;  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 {  public class XMapPaneAction_ZoomIn implements XMapPaneAction {
14            
15          @Override          @Override
16          public void performClick(XMapPane mapPane, MouseEvent ev,          public void performClick(XMapPane mapPane, MouseEvent ev,
17                          DirectPosition coord) {                          DirectPosition coord) {
                   
                 mapPane.zoomTo(ev.getPoint(), 1 / 2.);  
         }  
18    
19          @Override                  mapPane.zoomTo(ev.getPoint(), 1 / 2.);
         public void performDragging(XMapPane mapPane, MouseEvent ev,  
                         Point dragStartPos, Point dragLastPos, DirectPosition startCoord,  
                         DirectPosition endCoord) {  
                   
                 if (dragLastPos != null)  
                         mapPane.drawRectangle(mapPane.getGraphics(), dragLastPos, ev.getPoint());  
                   
                 mapPane.drawRectangle(mapPane.getGraphics(), dragStartPos, ev.getPoint());  
20          }          }
21    
22          @Override          @Override
# Line 38  public class XMapPaneAction_ZoomIn imple Line 31  public class XMapPaneAction_ZoomIn imple
31          }          }
32    
33          @Override          @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,          public void performDragged(XMapPane mapPane, MouseEvent ev,
48                          Point dragStartPos, Point dragLastPos, DirectPosition startCoord,                          Point dragStartPos, Point dragLastPos, DirectPosition startCoord,
49                          DirectPosition endCoord) {                          DirectPosition endCoord) {
50                  // TODO Auto-generated method stub  
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    

Legend:
Removed from v.643  
changed lines
  Added in v.644

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26