change relation.appendMember to use the undo system, and update various places as...
[potlatch2.git] / net / systemeD / halcyon / connection / actions / MoveWayAction.as
1 package net.systemeD.halcyon.connection.actions {
2
3     import net.systemeD.halcyon.connection.*;
4     import net.systemeD.halcyon.Map;
5     
6     public class MoveWayAction extends CompositeUndoableAction {
7     
8         private var way:Way;
9         private var downX:Number;
10         private var downY:Number;
11         private var x:Number;
12         private var y:Number;
13         private var map:Map;
14     
15         public function MoveWayAction(way:Way, downX:Number, downY:Number, x:Number, y:Number, map:Map) {
16             super("Drag way "+way.id);
17             this.way = way;
18             this.downX = downX;
19             this.downY = downY;
20             this.x = x;
21             this.y = y;
22             this.map = map;
23         }
24     
25         public override function doAction():uint {
26             var lonDelta:Number = map.coord2lon(downX)-map.coord2lon(x);
27             var latDelta:Number = map.coord2lat(downY)-map.coord2lat(y);
28             var moved:Object = {};
29             way.suspend();
30             way.dispatchEvent(new WayDraggedEvent(Connection.WAY_DRAGGED, way, 0, 0));
31             for (var i:uint=0; i<way.length; i++) {
32                 var n:Node=way.getNode(i);
33                 if (!moved[n.id]) {
34                     n.setLatLon(n.lat-latDelta, n.lon-lonDelta, push);
35                     moved[n.id]=true;
36                 }
37             }
38             super.doAction();
39             way.resume();
40             return SUCCESS;
41         }
42         
43         public override function undoAction():uint {
44             way.suspend();
45             super.undoAction();
46             way.resume();
47             return SUCCESS;
48         }
49         
50     }
51 }