POIs, and relations, and stuff :)
[potlatch2.git] / net / systemeD / halcyon / connection / Way.as
1 package net.systemeD.halcyon.connection {
2
3     public class Way extends Entity {
4         private var nodes:Array;
5                 public static var entity_type:String = 'way';
6
7         public function Way(id:Number, version:uint, tags:Object, loaded:Boolean, nodes:Array) {
8             super(id, version, tags, loaded);
9             this.nodes = nodes;
10                         for each (var node:Node in nodes) { node.addParent(this); }
11         }
12
13                 public function update(version:uint, tags:Object, loaded:Boolean, nodes:Array):void {
14                         var node:Node;
15                         for each (node in this.nodes) { node.removeParent(this); }
16                         updateEntityProperties(version,tags,loaded); this.nodes=nodes;
17                         for each (node in nodes) { node.addParent(this); }
18                 }
19
20         public function get length():uint {
21             return nodes.length;
22         }
23         
24         public function getNode(index:uint):Node {
25             return nodes[index];
26         }
27
28         public function insertNode(index:uint, node:Node):void {
29                         node.addParent(this);
30             nodes.splice(index, 0, node);
31         }
32
33         public function appendNode(node:Node):uint {
34                         node.addParent(this);
35             nodes.push(node);
36             return nodes.length;
37         }
38
39         public function removeNode(index:uint):void {
40             var removed:Array=nodes.splice(index, 1);
41                         removed[0].removeParent(this);
42         }
43
44         public override function toString():String {
45             return "Way("+id+"@"+version+"): "+getTagList()+
46                      " "+nodes.map(function(item:Node,index:int, arr:Array):String {return item.id.toString();}).join(",");
47         }
48
49                 public function isArea():Boolean {
50                         return (nodes[0].id==nodes[nodes.length-1].id && nodes.length>2);
51                 }
52
53                 public override function getType():String {
54                         return 'way';
55                 }
56     }
57
58 }