pull through POIs from vector background layers
authorRichard Fairhurst <richard@systemed.net>
Sun, 3 Oct 2010 17:39:06 +0000 (17:39 +0000)
committerRichard Fairhurst <richard@systemed.net>
Sun, 3 Oct 2010 17:39:06 +0000 (17:39 +0000)
net/systemeD/halcyon/Map.as
net/systemeD/halcyon/VectorLayer.as
net/systemeD/halcyon/connection/actions/CreatePOIAction.as
net/systemeD/potlatch2/controller/DrawWay.as

index b9abe28..7b0d2fa 100755 (executable)
@@ -263,8 +263,8 @@ package net.systemeD.halcyon {
                }
 
         public function setHighlight(entity:Entity, settings:Object):void {
-                       if      ( entity is Way  ) { paint.wayuis[entity.id].setHighlight(settings); }
-                       else if ( entity is Node ) { paint.nodeuis[entity.id].setHighlight(settings); }
+                       if      ( entity is Way  && paint.wayuis[entity.id] ) { paint.wayuis[entity.id].setHighlight(settings);  }
+                       else if ( entity is Node && paint.nodeuis[entity.id]) { paint.nodeuis[entity.id].setHighlight(settings); }
         }
 
         public function setHighlightOnNodes(way:Way, settings:Object):void {
index 5648308..b4f6a5c 100644 (file)
@@ -3,6 +3,7 @@ package net.systemeD.halcyon {
        import net.systemeD.halcyon.Map;
        import net.systemeD.halcyon.MapPaint;
        import net.systemeD.halcyon.connection.*;
+    import net.systemeD.halcyon.connection.actions.*;
        import net.systemeD.halcyon.Globals;
        import net.systemeD.halcyon.styleparser.RuleSet;
 
@@ -63,8 +64,9 @@ package net.systemeD.halcyon {
                        return o;
                }
                
-               public function pullThrough(entity:Entity,connection:Connection):Way {
+               public function pullThrough(entity:Entity,connection:Connection):Entity {
                        var i:uint=0;
+                       var oldNode:Node, newNode:Node;
                        if (entity is Way) {
                                // copy way through to main layer
                                // ** shouldn't do this if the nodes are already in the main layer
@@ -72,7 +74,6 @@ package net.systemeD.halcyon {
                                var oldWay:Way=Way(entity);
                                var newWay:Way=connection.createWay(oldWay.getTagsCopy(), [], MainUndoStack.getGlobalStack().addAction);
                                var nodemap:Object={};
-                               var oldNode:Node, newNode:Node;
                                for (i=0; i<oldWay.length; i++) {
                                        oldNode = oldWay.getNode(i);
                                        newNode = nodemap[oldNode.id] ? nodemap[oldNode.id] : connection.createNode(
@@ -90,11 +91,20 @@ package net.systemeD.halcyon {
                                paint.wayuis[oldWay.id].redraw();
                                delete ways[oldWay.id];
                                map.paint.createWayUI(newWay);
-                       } else {
-                               // ** should be able to pull nodes through
-                               trace ("Pulling nodes through isn't supported yet");
+                               return newWay;
+
+                       } else if (entity is Node && !entity.hasParentWays) {
+                               // copy node through to main layer
+                               // ** should be properly undoable
+                               oldNode=Node(entity)
+                               var newPoiAction:CreatePOIAction = new CreatePOIAction(
+                                       oldNode.getTagsCopy(), oldNode.lat, oldNode.lon);
+                               MainUndoStack.getGlobalStack().addAction(newPoiAction);
+                               paint.deleteNodeUI(oldNode);
+                               delete nodes[oldNode.id];
+                               return newPoiAction.getNode();
                        }
-                       return newWay;
+                       return null;
                }
                
                public function blank():void {
index 961a735..99d0b58 100644 (file)
@@ -7,21 +7,20 @@ package net.systemeD.halcyon.connection.actions {
     public class CreatePOIAction extends CompositeUndoableAction {
     
         private var newNode:Node;
-        private var event:MouseEvent;
-        private var map:Map;
+               private var tags:Object;
+               private var lat:Number;
+               private var lon:Number;
         
-        public function CreatePOIAction(event:MouseEvent, map:Map) {
+        public function CreatePOIAction(tags:Object, lat:Number, lon:Number) {
           super("Create POI");
-          this.event = event;
-          this.map = map;
+          this.tags = tags;
+          this.lat = lat;
+          this.lon = lon;
         }
         
         public override function doAction():uint {
           if (newNode == null) {
-            newNode = Connection.getConnection().createNode(
-                {},
-                map.coord2lat(event.localY),
-                map.coord2lon(event.localX), push);
+            newNode = Connection.getConnection().createNode(tags,lat,lon,push);
           }
           super.doAction();
           Connection.getConnection().registerPOI(newNode);
index 886ef56..2d78f8b 100644 (file)
@@ -57,7 +57,10 @@ package net.systemeD.potlatch2.controller {
                             stopDrawing();
                             MainUndoStack.getGlobalStack().undo(); // undo the BeginWayAction that (presumably?) just happened
                             
-                            var newPoiAction:CreatePOIAction = new CreatePOIAction(event, controller.map);
+                            var newPoiAction:CreatePOIAction = new CreatePOIAction(
+                                                               {},
+                                                               controller.map.coord2lat(event.localX),
+                                                               controller.map.coord2lon(event.localY));
                             MainUndoStack.getGlobalStack().addAction(newPoiAction);
                             return new SelectedPOINode(newPoiAction.getNode());
                                                } else {