delete ways, too
[potlatch2.git] / net / systemeD / potlatch2 / controller / DrawWay.as
index 0e6ff89719ceee9f0d513e2d60e43f6534a2d7c6..29a3f7d9a544349ebad1deb7e4d1656a3bed211b 100644 (file)
@@ -10,11 +10,18 @@ package net.systemeD.potlatch2.controller {
                private var elastic:Elastic;
                private var editEnd:Boolean;
                private var leaveNodeSelected:Boolean;
+               private var lastClick:Entity=null;
+               private var lastClickTime:Date;
                
                public function DrawWay(way:Way, editEnd:Boolean, leaveNodeSelected:Boolean) {
                        super(way);
                        this.editEnd = editEnd;
                        this.leaveNodeSelected = leaveNodeSelected;
+                       if (way.length==1 && way.getNode(0).parentWays.length==1) {
+                               // drawing new way, so keep track of click in case creating a POI
+                               lastClick=way.getNode(0);
+                               lastClickTime=new Date();
+                       }
                }
                
                override public function processMouseEvent(event:MouseEvent, entity:Entity):ControllerState {
@@ -26,16 +33,33 @@ package net.systemeD.potlatch2.controller {
                                if ( entity == null ) {
                                        node = createAndAddNode(event);
                                        resetElastic(node);
+                                       lastClick=node;
                                } else if ( entity is Node ) {
-                                       appendNode(entity as Node);
-                                       controller.map.setHighlight(focus, { showNodesHover: false });
-                                       controller.map.setHighlight(selectedWay, { showNodes: true });
-                                       resetElastic(entity as Node);
+                                       if (entity==lastClick && (new Date().getTime()-lastClickTime.getTime())<1000) {
+                                               if (selectedWay.length==1 && selectedWay.getNode(0).parentWays.length==1) {
+                                                       // double-click to create new POI
+                                                       node=selectedWay.getNode(0);
+                                                       stopDrawing();
+                                                       controller.connection.registerPOI(node);
+                                                       return new SelectedPOINode(node);
+                                               } else {
+                                                       // double-click at end of way
+                                                       return stopDrawing();
+                                               }
+                                       } else {
+                                               appendNode(entity as Node);
+                                               controller.map.setHighlight(focus, { showNodesHover: false });
+                                               controller.map.setHighlight(selectedWay, { showNodes: true });
+                                               resetElastic(entity as Node);
+                                               lastClick=entity;
+                                       }
                                } else if ( entity is Way ) {
                                        node = createAndAddNode(event);
                                        Way(entity).insertNodeAtClosestPosition(node, true);
                                        resetElastic(node);
+                                       lastClick=node;
                                }
+                               lastClickTime=new Date();
                        } else if ( event.type == MouseEvent.MOUSE_MOVE ) {
                                mouse = new Point(
                                                  controller.map.coord2lon(event.localX),
@@ -65,11 +89,20 @@ package net.systemeD.potlatch2.controller {
                }
 
                override public function processKeyboardEvent(event:KeyboardEvent):ControllerState {
-                       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);
+                       if ( event.keyCode == 13 || event.keyCode == 27 ) { return stopDrawing(); }
+                       return this;
+               }
+               
+               protected function stopDrawing():ControllerState {
+                       if ( selectedWay.length<2) {
+                               controller.map.setHighlight(selectedWay, { showNodes: false });
+                               selectedWay.remove();
+                               // delete controller.map.ways[selectedWay.id];
+                               return new NoSelection();
+                       } else if ( leaveNodeSelected ) {
+                           return new SelectedWayNode(selectedWay, selectedWay.getNode(editEnd ? selectedWay.length - 1 : 0));
+                       } else {
+                           return new SelectedWay(selectedWay);
                        }
                        return this;
                }