Add way extending by clicking on first/last node
[potlatch2.git] / net / systemeD / potlatch2 / controller / SelectedWayNode.as
index 17be1e8ef4ef359736839c818853700fc7d3c1a7..24dbe484f68bef8c6f8c5c2b93e54fea04a14b11 100644 (file)
@@ -40,14 +40,14 @@ package net.systemeD.potlatch2.controller {
             if ( event.type == MouseEvent.MOUSE_UP ) {
                                if ( entity is Node && event.shiftKey ) {
                                        // start new way
-                    var way:Way = controller.connection.createWay({}, [entity, entity]);
-                    return new DrawWay(way, true);
-                               } else if ( entity is Node ) {
+                    var way:Way = controller.connection.createWay({}, [entity]);
+                    return new DrawWay(way, true, false);
+                               } else if ( entity is Node && focus == selectedWay ) {
                                        // select node within way
-                                       return new SelectedWayNode(selectedWay,Node(entity));
+                                       return selectOrEdit(selectedWay, Node(entity));
                 } else if ( entity is Way ) {
                                        // select way
-                                       return new SelectedWay(selectedWay);
+                                       return new SelectedWay(Way(entity));
                 } else if ( focus == null && map.dragstate!=map.DRAGGING ) {
                     return new NoSelection();
                                }
@@ -78,5 +78,15 @@ package net.systemeD.potlatch2.controller {
             return "SelectedWayNode";
         }
 
+        public static function selectOrEdit(selectedWay:Way, entity:Node):ControllerState {
+               var isFirst:Boolean = false;
+                       var isLast:Boolean = false;
+                       isFirst = selectedWay.getNode(0) == entity;
+                       isLast = selectedWay.getNode(selectedWay.length - 1) == entity;
+                       if ( isFirst == isLast )    // both == looped, none == central node 
+                           return new SelectedWayNode(selectedWay, entity);
+                       else
+                           return new DrawWay(selectedWay, isLast, true);
+        }
     }
 }