alt-click (for now) to bring ways in from vector background layers
[potlatch2.git] / net / systemeD / halcyon / vectorlayers / VectorLayer.as
index b9e2d1802a5ac288c2cf9cfba986f95fc0ead2d8..3c3c2aa9cb4c6bff4b7bb894c4b7cbefa3135690 100644 (file)
@@ -2,21 +2,22 @@ package net.systemeD.halcyon.vectorlayers {
 
        import net.systemeD.halcyon.Map;
        import net.systemeD.halcyon.MapPaint;
-       import net.systemeD.halcyon.connection.Node;
-       import net.systemeD.halcyon.connection.Way;
-       import net.systemeD.halcyon.connection.Relation;
+       import net.systemeD.halcyon.connection.*;
+       import net.systemeD.halcyon.Globals;
 
        public class VectorLayer extends Object {
 
                public var map:Map;
                public var paint:MapPaint;                                              // sprites
+               public var name:String;
 
                public var ways:Object=new Object();                    // geodata
                public var nodes:Object=new Object();                   //  |
                public var relations:Object=new Object();               //  |
         private var negativeID:Number = -1;
 
-               public function VectorLayer(m:Map) {
+               public function VectorLayer(n:String,m:Map) {
+                       name=n;
                        map=m;
                        paint=new MapPaint(m,0,0);
                }
@@ -36,6 +37,33 @@ package net.systemeD.halcyon.vectorlayers {
                        relations[negativeID]=relation; negativeID--;
             return relation;
                }
+               
+               public function pullThrough(entity:Entity,connection:Connection):Way {
+                       var i:uint=0;
+                       if (entity is Way) {
+                               // copy way through to main layer
+                               // ** shouldn't do this if the nodes are already in the main layer
+                               var oldWay:Way=Way(entity);
+                               var newWay:Way=connection.createWay(oldWay.getTagsCopy(), [], MainUndoStack.getGlobalStack().addAction);
+                               for (i=0; i<oldWay.length; i++) {
+                                       var oldNode:Node = oldWay.getNode(i);
+                                       var newNode:Node = connection.createNode(
+                                               oldNode.getTagsCopy(), oldNode.lat, oldNode.lon, 
+                                               MainUndoStack.getGlobalStack().addAction);
+                                       newWay.appendNode(newNode, MainUndoStack.getGlobalStack().addAction);
+                               }
+                               // delete this way
+                               while (oldWay.length) { 
+                                       var id:int=oldWay.getNode(0).id;
+                                       oldWay.removeNodeByIndex(0,false);
+                                       delete nodes[id];
+                               }
+                               paint.wayuis[oldWay.id].redraw();
+                               ways[oldWay.id]=null;
+                               map.paint.createWayUI(newWay);
+                       }
+                       return newWay;
+               }
 
        }
 }