Merge branch 'master' of github.com:systemed/potlatch2
[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 lonDelta:Number;
10         private var latDelta:Number;
11                 private var moved:Object;
12     
13         public function MoveWayAction(way:Way, latDelta:Number, lonDelta:Number, moved:Object) {
14             super("Drag way "+way.id);
15             this.way = way;
16             this.lonDelta = lonDelta;
17             this.latDelta = latDelta;
18                         this.moved = moved;
19         }
20     
21         public override function doAction():uint {
22             way.suspend();
23             way.dispatchEvent(new EntityDraggedEvent(Connection.ENTITY_DRAGGED, way, 0, 0));
24             for (var i:uint=0; i<way.length; i++) {
25                 var n:Node=way.getNode(i);
26                 if (!moved[n.id]) {
27                     n.setLatLon(n.lat-latDelta, n.lon-lonDelta, push);
28                     moved[n.id]=true;
29                 }
30             }
31             super.doAction();
32             way.resume();
33             return SUCCESS;
34         }
35         
36         public override function undoAction():uint {
37             way.suspend();
38             super.undoAction();
39             way.resume();
40             return SUCCESS;
41         }
42         
43     }
44 }