fix horrid merge bug (yay!). Implement suspend/resume events for redrawing, to speed...
[potlatch2.git] / net / systemeD / halcyon / connection / Connection.as
index 4675830..14d48a1 100755 (executable)
@@ -30,6 +30,7 @@ package net.systemeD.halcyon.connection {
         }
 
         public static function getParam(name:String, defaultValue:String):String {
+            trace("Returning param "+name+" as "+(params[name] == null ? defaultValue : params[name]));
             return params[name] == null ? defaultValue : params[name];
         }
 
@@ -58,7 +59,19 @@ package net.systemeD.halcyon.connection {
         public static var NEW_WAY:String = "new_way";
         public static var NEW_RELATION:String = "new_relation";
         public static var NEW_POI:String = "new_poi";
-        public static var TAG_CHANGE:String = "tag_change";
+        public static var TAG_CHANGED:String = "tag_change";
+        public static var NODE_MOVED:String = "node_moved";
+        public static var WAY_NODE_ADDED:String = "way_node_added";
+        public static var WAY_NODE_REMOVED:String = "way_node_removed";
+               public static var NODE_DELETED:String = "node_deleted";
+               public static var WAY_DELETED:String = "way_deleted";
+               public static var RELATION_DELETED:String = "relation_deleted";
+               public static var RELATION_MEMBER_ADDED:String = "relation_member_added";
+               public static var RELATION_MEMBER_REMOVED:String = "relation_member_deleted";
+               public static var ADDED_TO_RELATION:String = "added_to_relation";
+               public static var REMOVED_FROM_RELATION:String = "removed_from_relation";
+               public static var SUSPEND_REDRAW:String = "suspend_redraw";
+               public static var RESUME_REDRAW:String = "resume_redraw";
 
         // store the data we download
         private var negativeID:Number = -1;
@@ -72,25 +85,46 @@ package net.systemeD.halcyon.connection {
             return negativeID--;
         }
 
-        protected function setNode(node:Node):void {
+        protected function setNode(node:Node,queue:Boolean):void {
             nodes[node.id] = node;
-            dispatchEvent(new EntityEvent(NEW_NODE, node));
+            if (node.loaded) { sendEvent(new EntityEvent(NEW_NODE, node),queue); }
         }
 
-        protected function setWay(way:Way):void {
+        protected function setWay(way:Way,queue:Boolean):void {
             ways[way.id] = way;
-            dispatchEvent(new EntityEvent(NEW_WAY, way));
+            if (way.loaded) { sendEvent(new EntityEvent(NEW_WAY, way),queue); }
         }
 
-        protected function setRelation(relation:Relation):void {
+        protected function setRelation(relation:Relation,queue:Boolean):void {
             relations[relation.id] = relation;
-            dispatchEvent(new EntityEvent(NEW_RELATION, relation));
+            if (relation.loaded) { sendEvent(new EntityEvent(NEW_RELATION, relation),queue); }
         }
 
-        protected function registerPOI(node:Node):void {
+        protected function renumberNode(oldID:Number, node:Node):void {
+            nodes[node.id] = node;
+            delete nodes[oldID];
+        }
+
+        protected function renumberWay(oldID:Number, way:Way):void {
+            ways[way.id] = way;
+            delete ways[oldID];
+        }
+
+        protected function renumberRelation(oldID:Number, relation:Relation):void {
+            relations[relation.id] = relation;
+            delete relations[oldID];
+        }
+
+
+               public function sendEvent(e:*,queue:Boolean):void {
+                       // queue is only used for AMFConnection
+                       dispatchEvent(e);
+               }
+
+        public function registerPOI(node:Node):void {
             if ( pois.indexOf(node) < 0 ) {
                 pois.push(node);
-                dispatchEvent(new EntityEvent(NEW_POI, node));
+                sendEvent(new EntityEvent(NEW_POI, node),false);
             }
         }
 
@@ -103,7 +137,7 @@ package net.systemeD.halcyon.connection {
 
         protected function setActiveChangeset(changeset:Changeset):void {
             this.changeset = changeset;
-            dispatchEvent(new EntityEvent(NEW_CHANGESET, changeset));
+            sendEvent(new EntityEvent(NEW_CHANGESET, changeset),false);
         }
         
         public function getNode(id:Number):Node {
@@ -119,20 +153,20 @@ package net.systemeD.halcyon.connection {
         }
 
         public function createNode(tags:Object, lat:Number, lon:Number):Node {
-            var node:Node = new Node(nextNegative, 0, tags, lat, lon);
-            setNode(node);
+            var node:Node = new Node(nextNegative, 0, tags, true, lat, lon);
+            setNode(node,false);
             return node;
         }
 
         public function createWay(tags:Object, nodes:Array):Way {
-            var way:Way = new Way(nextNegative, 0, tags, nodes.concat());
-            setWay(way);
+            var way:Way = new Way(nextNegative, 0, tags, true, nodes.concat());
+            setWay(way,false);
             return way;
         }
 
         public function createRelation(tags:Object, members:Array):Relation {
-            var relation:Relation = new Relation(nextNegative, 0, tags, members.concat());
-            setRelation(relation);
+            var relation:Relation = new Relation(nextNegative, 0, tags, true, members.concat());
+            setRelation(relation,false);
             return relation;
         }