alt-click (for now) to bring ways in from vector background layers
[potlatch2.git] / net / systemeD / halcyon / vectorlayers / VectorLayer.as
1 package net.systemeD.halcyon.vectorlayers {
2
3         import net.systemeD.halcyon.Map;
4         import net.systemeD.halcyon.MapPaint;
5         import net.systemeD.halcyon.connection.*;
6         import net.systemeD.halcyon.Globals;
7
8         public class VectorLayer extends Object {
9
10                 public var map:Map;
11                 public var paint:MapPaint;                                              // sprites
12                 public var name:String;
13
14                 public var ways:Object=new Object();                    // geodata
15                 public var nodes:Object=new Object();                   //  |
16                 public var relations:Object=new Object();               //  |
17         private var negativeID:Number = -1;
18
19                 public function VectorLayer(n:String,m:Map) {
20                         name=n;
21                         map=m;
22                         paint=new MapPaint(m,0,0);
23                 }
24                 
25                 public function createNode(tags:Object,lat:Number,lon:Number):Node {
26                         var node:Node = new Node(negativeID, 0, tags, true, lat, lon);
27                         nodes[negativeID]=node; negativeID--;
28                         return node;
29                 }
30                 public function createWay(tags:Object,nodes:Array):Way {
31                         var way:Way = new Way(negativeID, 0, tags, true, nodes.concat());
32                         ways[negativeID]=way; negativeID--;
33                         return way;
34                 }
35                 public function createRelation(tags:Object,members:Array):Relation {
36             var relation:Relation = new Relation(negativeID, 0, tags, true, members.concat());
37                         relations[negativeID]=relation; negativeID--;
38             return relation;
39                 }
40                 
41                 public function pullThrough(entity:Entity,connection:Connection):Way {
42                         var i:uint=0;
43                         if (entity is Way) {
44                                 // copy way through to main layer
45                                 // ** shouldn't do this if the nodes are already in the main layer
46                                 var oldWay:Way=Way(entity);
47                                 var newWay:Way=connection.createWay(oldWay.getTagsCopy(), [], MainUndoStack.getGlobalStack().addAction);
48                                 for (i=0; i<oldWay.length; i++) {
49                                         var oldNode:Node = oldWay.getNode(i);
50                                         var newNode:Node = connection.createNode(
51                                                 oldNode.getTagsCopy(), oldNode.lat, oldNode.lon, 
52                                                 MainUndoStack.getGlobalStack().addAction);
53                                         newWay.appendNode(newNode, MainUndoStack.getGlobalStack().addAction);
54                                 }
55                                 // delete this way
56                                 while (oldWay.length) { 
57                                         var id:int=oldWay.getNode(0).id;
58                                         oldWay.removeNodeByIndex(0,false);
59                                         delete nodes[id];
60                                 }
61                                 paint.wayuis[oldWay.id].redraw();
62                                 ways[oldWay.id]=null;
63                                 map.paint.createWayUI(newWay);
64                         }
65                         return newWay;
66                 }
67
68         }
69 }