generic parent object handling
[potlatch2.git] / net / systemeD / halcyon / connection / Way.as
index f26d5b6419acce472440285b7d6838324fde8551..56dad5f6f8066222c25aa42bf334b09c75a12b85 100644 (file)
@@ -2,10 +2,12 @@ package net.systemeD.halcyon.connection {
 
     public class Way extends Entity {
         private var nodes:Array;
+               public static var entity_type:String = 'way';
 
         public function Way(id:Number, version:uint, tags:Object, nodes:Array) {
             super(id, version, tags);
             this.nodes = nodes;
+                       for each (var node:Node in nodes) { node.addParent(this); }
         }
 
         public function get length():uint {
@@ -17,25 +19,32 @@ package net.systemeD.halcyon.connection {
         }
 
         public function insertNode(index:uint, node:Node):void {
+                       node.addParent(this);
             nodes.splice(index, 0, node);
         }
 
         public function appendNode(node:Node):uint {
+                       node.addParent(this);
             nodes.push(node);
             return nodes.length;
         }
 
         public function removeNode(index:uint):void {
-            nodes.splice(index, 1);
+            var removed:Array=nodes.splice(index, 1);
+                       removed[0].removeParent(this);
         }
 
-        public function toString():String {
+        public override function toString():String {
             return "Way("+id+"@"+version+"): "+getTagList()+
                      " "+nodes.map(function(item:Node,index:int, arr:Array):String {return item.id.toString();}).join(",");
         }
 
                public function isArea():Boolean {
-                       return nodes[0]==nodes[nodes.length-1] && nodes.length>2;
+                       return (nodes[0].id==nodes[nodes.length-1].id && nodes.length>2);
+               }
+
+               public override function getType():String {
+                       return 'way';
                }
     }