fix creating ways duplicate node bug, and connecting to existing way-node bug
[potlatch2.git] / net / systemeD / potlatch2 / controller / DrawWay.as
index f5da8ce3ca6af7fbc3d38976dfac13a1608a3541..9932cfb3f286c1c15f21e556c8b418b2b8db2d8c 100644 (file)
@@ -4,6 +4,7 @@ package net.systemeD.potlatch2.controller {
        import net.systemeD.potlatch2.EditController;
        import net.systemeD.halcyon.connection.*;
        import net.systemeD.halcyon.Elastic;
+       import net.systemeD.halcyon.Globals;
 
        public class DrawWay extends SelectedWay {
                private var elastic:Elastic;
@@ -17,16 +18,17 @@ package net.systemeD.potlatch2.controller {
                override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
                        var mouse:Point;
                        var node:Node;
-                       var focus:Entity = NoSelection.getTopLevelFocusEntity(entity);
-                       if ( event.type == MouseEvent.CLICK ) {
-                               if ( focus == null ) {
+
+                       if ( event.type == MouseEvent.MOUSE_UP ) {
+                               if ( entity == null ) {
                                        node = createAndAddNode(event);
                                        resetElastic(node);
-                               } else if ( focus is Node ) {
-                                       appendNode(focus as Node);
-                               } else if ( focus is Way ) {
+                               } else if ( entity is Node ) {
+                                       appendNode(entity as Node);
+                                       resetElastic(entity as Node);
+                               } else if ( entity is Way ) {
                                        node = createAndAddNode(event);
-                                       Way(focus).insertNodeAtClosestPosition(node, true);
+                                       Way(entity).insertNodeAtClosestPosition(node, true);
                                        resetElastic(node);
                                }
                        } else if ( event.type == MouseEvent.MOUSE_MOVE ) {
@@ -72,11 +74,13 @@ package net.systemeD.potlatch2.controller {
                        var node:Node = selectedWay.getNode(editEnd ? selectedWay.length - 1 : 0);
                        var start:Point = new Point(node.lon, node.latp);
                        elastic = new Elastic(controller.map, start, start);
+                       Globals.vars.root.addDebug("**** -> "+this);
                }
                override public function exitState():void {
                        super.exitState();
                        elastic.removeSprites();
                        elastic = null;
+                       Globals.vars.root.addDebug("**** <- "+this);
                }
                override public function toString():String {
                        return "DrawWay";