Update dupes when node is moved / deleted. Needs further refactoring
[potlatch2.git] / net / systemeD / halcyon / connection / Entity.as
index 8fd024c905adabec6970a27906ca52875d917a37..392a890a16d622ac5d7a67b6637ed2953436220c 100644 (file)
@@ -8,6 +8,8 @@ package net.systemeD.halcyon.connection {
     public class Entity extends EventDispatcher {
         private var _id:Number;
         private var _version:uint;
+        private var _uid:Number;
+        private var _timestamp:String;
         private var tags:Object = {};
         private var modified:Boolean = false;
                private var _loaded:Boolean = true;
@@ -15,9 +17,11 @@ package net.systemeD.halcyon.connection {
                private var locked:Boolean = false;
                public var deleted:Boolean = false;
 
-        public function Entity(id:Number, version:uint, tags:Object, loaded:Boolean) {
+        public function Entity(id:Number, version:uint, tags:Object, loaded:Boolean, uid:Number, timestamp:String) {
             this._id = id;
             this._version = version;
+            this._uid = uid;
+            this._timestamp = timestamp;
             this.tags = tags;
                        this._loaded = loaded;
             modified = id < 0;
@@ -31,12 +35,16 @@ package net.systemeD.halcyon.connection {
             return _version;
         }
 
+        public function get uid():Number {
+            return _uid;
+        }
+
         public function get loaded():Boolean {
             return _loaded;
         }
 
-               public function updateEntityProperties(version:uint, tags:Object, loaded:Boolean):void {
-                       _version=version; this.tags=tags; _loaded=loaded;
+               public function updateEntityProperties(version:uint, tags:Object, loaded:Boolean, uid:Number, timestamp:String):void {
+                       _version=version; this.tags=tags; _loaded=loaded; _uid = uid; _timestamp = timestamp;
                }
 
                // Tag-handling methods
@@ -47,7 +55,24 @@ package net.systemeD.halcyon.connection {
             return false;
         }
 
-               // ** we could do with hasInterestingTags - don't bother with source, created_by, any TIGER tags, etc.
+        public function hasInterestingTags():Boolean {
+            for (var key:String in tags) {
+              if (key != "attribution" && key != "created_by" && key != "source" && key.indexOf('tiger:') != 0) {
+                //trace(key);
+                return true;
+              }
+            }
+            return false;
+        }
+
+        public function isUneditedTiger():Boolean {
+            // todo: make this match the rules from the tiger edited map
+            // http://github.com/MapQuest/TIGER-Edited-map/blob/master/inc/layer-tiger.xml.inc
+            if (this is Way && (uid == 7168 || uid == 15169 || uid == 20587)) {//todo fixme etc
+              return true;
+            }
+            return false;
+        }
 
         public function getTag(key:String):String {
             return tags[key];
@@ -118,6 +143,12 @@ package net.systemeD.halcyon.connection {
                
                public function setDeletedState(isDeleted:Boolean):void {
                    deleted = isDeleted;
+            if (this is Node) {
+              var n:Node = Node(this);
+              Connection.getConnection().removeDupe(n);
+            } else if (this is Node) {
+              Connection.getConnection().addDupe(n.id, n.lat, n.lon);
+            }
                }
                
                internal function isEmpty():Boolean {
@@ -188,10 +219,10 @@ package net.systemeD.halcyon.connection {
                        return a;
                }
                
-               public function findParentRelationsOfType(type:String, role:String=""):Array {
+               public function findParentRelationsOfType(type:String, role:String=null):Array {
                        var a:Array=[];
                        for (var o:Object in parents) {
-                               if (o is Relation && Relation(o).tagIs('type',type) && Relation(o).hasMemberInRole(this,role)) { 
+                               if (o is Relation && Relation(o).tagIs('type',type) && (role==null || Relation(o).hasMemberInRole(this,role))) { 
                                        a.push(o);
                                }
                        }