Add way extending by clicking on first/last node
authorDave Stubbs <osm@randomjunk.co.uk>
Sun, 29 Nov 2009 21:11:36 +0000 (21:11 +0000)
committerDave Stubbs <osm@randomjunk.co.uk>
Sun, 29 Nov 2009 21:11:36 +0000 (21:11 +0000)
TODO.txt
net/systemeD/potlatch2/controller/DragWayNode.as
net/systemeD/potlatch2/controller/DrawWay.as
net/systemeD/potlatch2/controller/NoSelection.as
net/systemeD/potlatch2/controller/SelectedWay.as
net/systemeD/potlatch2/controller/SelectedWayNode.as

index 1f071cb00c08cf4c13d8acfe1fd73e6aa51f3842..e5e744be0d919e6875a7a40cec3ddb025495496b 100644 (file)
--- a/TODO.txt
+++ b/TODO.txt
@@ -4,7 +4,6 @@ Potlatch 2: main outstanding issues
 
 == Current issues ==
 
-* Can't extend already-drawn way
 * Drag POI nodes (DragPOINode) and select them
 * Needs some sort of _width attribute so we can draw highlights 2px wider than the largest stroke (difficult because styles are decided before drawing)
 
index 30387b8e0e41677d1c5b65e9d69fe713da4c0049..b2e2668b26e0d16384fa5cb39fd06f4574bb0b3b 100644 (file)
@@ -35,13 +35,13 @@ package net.systemeD.potlatch2.controller {
                                } else if (event.shiftKey && !isNew) {
                                        // start new way
                                        var way:Way = controller.connection.createWay({}, [entity]);
-                                       return new DrawWay(way, true);
+                                       return new DrawWay(way, true, false);
                                } else if (event.shiftKey && isNew) {
                        return new SelectedWayNode(selectedWay,draggingNode);
                                } else {
                                        // select node
                                        dragstate=NOT_DRAGGING;
-                       return new SelectedWayNode(selectedWay,draggingNode);
+                       return SelectedWayNode.selectOrEdit(selectedWay, draggingNode);
                                }
 
                        } else if ( event.type == MouseEvent.MOUSE_MOVE) {
index 6026d099644b83396693bc6bd5923ef4f94f7240..0e6ff89719ceee9f0d513e2d60e43f6534a2d7c6 100644 (file)
@@ -9,10 +9,12 @@ package net.systemeD.potlatch2.controller {
        public class DrawWay extends SelectedWay {
                private var elastic:Elastic;
                private var editEnd:Boolean;
+               private var leaveNodeSelected:Boolean;
                
-               public function DrawWay(way:Way, editEnd:Boolean) {
+               public function DrawWay(way:Way, editEnd:Boolean, leaveNodeSelected:Boolean) {
                        super(way);
                        this.editEnd = editEnd;
+                       this.leaveNodeSelected = leaveNodeSelected;
                }
                
                override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
@@ -63,8 +65,12 @@ package net.systemeD.potlatch2.controller {
                }
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
-                       if ( event.keyCode == 13 || event.keyCode == 27 )
-                               return new SelectedWay(selectedWay);
+                       if ( event.keyCode == 13 || event.keyCode == 27 ) {
+                               if ( leaveNodeSelected ) 
+                                   return new SelectedWayNode(selectedWay, selectedWay.getNode(editEnd ? selectedWay.length - 1 : 0));
+                               else
+                                   return new SelectedWay(selectedWay);
+                       }
                        return this;
                }
 
index d55103b8fcfe7b8589102025dc78566e0213cff5..e2c8bca11043d385184095e7c070e2f4c7861672 100644 (file)
@@ -27,7 +27,7 @@ package net.systemeD.potlatch2.controller {
                                        controller.map.coord2lat(event.localY),
                                        controller.map.coord2lon(event.localX));
                                var way:Way = controller.connection.createWay({}, [startNode]);
-                               return new DrawWay(way, true);
+                               return new DrawWay(way, true, false);
                        } else if ( event.type == MouseEvent.MOUSE_OVER ) {
                                controller.map.setHighlight(focus, { hover: true });
                        } else if ( event.type == MouseEvent.MOUSE_OUT ) {
index cd533231e053e4f9f50fadb504ef6f424c1bc6fd..386daf8d384310fbd5b9ec667e23bd03d31be790 100644 (file)
@@ -39,7 +39,7 @@ package net.systemeD.potlatch2.controller {
                                if ( entity is Node && event.shiftKey ) {
                                        // start new way
                     var way:Way = controller.connection.createWay({}, [entity]);
-                    return new DrawWay(way, true);
+                    return new DrawWay(way, true, false);
                                } else if ( entity is Way ) {
                                        // select way
                     selectWay(entity as Way);
index 114c913be52b359bc262f1b9e1e4c353cfe50527..24dbe484f68bef8c6f8c5c2b93e54fea04a14b11 100644 (file)
@@ -41,10 +41,10 @@ package net.systemeD.potlatch2.controller {
                                if ( entity is Node && event.shiftKey ) {
                                        // start new way
                     var way:Way = controller.connection.createWay({}, [entity]);
-                    return new DrawWay(way, true);
-                               } else if ( entity is Node ) {
+                    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(Way(entity));
@@ -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);
+        }
     }
 }