placeholders for second half of the code (will need a small API update before this...
[potlatch2.git] / net / systemeD / halcyon / connection / XMLBaseConnection.as
index c65d6d8..16cbeb2 100644 (file)
@@ -27,10 +27,19 @@ package net.systemeD.halcyon.connection {
             var uid:Number;
             var timestamp:String;
             var tags:Object;
+            var node:Node, newNode:Node;
+            var unusedNodes:Object={};
+
+                       var minlon:Number=map.bounds.@minlon;
+                       var maxlon:Number=map.bounds.@maxlon;
+                       var minlat:Number=map.bounds.@minlat;
+                       var maxlat:Number=map.bounds.@maxlat;
 
             for each(var relData:XML in map.relation) {
                 id = Number(relData.@id);
                 version = uint(relData.@version);
+                uid = Number(relData.@uid);
+                timestamp = relData.@timestamp;
                 
                 var rel:Relation = getRelation(id);
                 if ( rel == null || !rel.loaded ) {
@@ -46,6 +55,8 @@ package net.systemeD.halcyon.connection {
                             if ( member == null ) {
                                 member = new Node(memberID,0,{},false,0,0);
                                 setNode(Node(member),true);
+                            } else if (member.isDeleted()) {
+                                member.setDeletedState(false);
                             }
                         } else if ( type == "way" ) {
                             member = getWay(memberID);
@@ -66,34 +77,37 @@ package net.systemeD.halcyon.connection {
                     }
                     
                     if ( rel == null )
-                        setRelation(new Relation(id, version, tags, true, members), false);
+                        setRelation(new Relation(id, version, tags, true, members, uid, timestamp), false);
                     else {
-                        rel.update(version,tags,true,members);
+                        rel.update(version, tags, true, members, uid, timestamp);
                         sendEvent(new EntityEvent(NEW_RELATION, rel), false);
                     }
                 }
             }
-            
-            for each(var nodeData:XML in map.node) {
-                id = Number(nodeData.@id);
-                version = uint(nodeData.@version);
-                uid = Number(nodeData.@uid);
-                timestamp = nodeData.@timestamp;
-
-                var node:Node = getNode(id);
-                if ( node == null || !node.loaded ) {
-                    var lat:Number = Number(nodeData.@lat);
-                    var lon:Number = Number(nodeData.@lon);
-                    tags = parseTags(nodeData.tag);
-                    if ( node == null )
-                        setNode(new Node(id, version, tags, true, lat, lon, uid, timestamp),false);
-                    else {
-                        node.update(version, tags, true, lat, lon, uid, timestamp);
-                        sendEvent(new EntityEvent(NEW_NODE, node), false);
-                    }
-                }
-            }
 
+            for each(var nodeData:XML in map.node) {
+                               id = Number(nodeData.@id);
+                               node = getNode(id);
+                               newNode = new Node(id, 
+                                                  uint(nodeData.@version), 
+                                                  parseTags(nodeData.tag),
+                                                  true, 
+                                                  Number(nodeData.@lat),
+                                                  Number(nodeData.@lon),
+                                                  Number(nodeData.@uid),
+                                                  nodeData.@timestamp);
+                               
+                               if ( node == null || !node.loaded) {
+//                                     newNode.parentsLoaded=newNode.within(minlon,maxlon,minlat,maxlat);
+//                                     ** updateEntityProperties will need to do parentsLoaded as well
+                                       setOrUpdateNode(newNode, true);
+                               } else {
+                                       // the node's already in memory, but store it in case one of the new ways needs it
+//                                     if (newNode.within(minlon,maxlon,minlat,maxlat)) newNode.parentsLoaded=true;
+                                       unusedNodes[id]=newNode;
+                               }
+                       }
+            
             for each(var data:XML in map.way) {
                 id = Number(data.@id);
                 version = uint(data.@version);
@@ -103,12 +117,18 @@ package net.systemeD.halcyon.connection {
                 var way:Way = getWay(id);
                 if ( way == null || !way.loaded ) {
                     var nodes:Array = [];
-                    for each(var nd:XML in data.nd)
-                        nodes.push(getNode(Number(nd.@ref)));
+                    for each(var nd:XML in data.nd) {
+                                               var nodeid:Number=Number(nd.@ref)
+                                               if (getNode(nodeid).isDeleted() && unusedNodes[nodeid]) { 
+                                                       setOrUpdateNode(unusedNodes[nodeid], true); 
+                                               }
+                        nodes.push(getNode(nodeid));
+                                       }
                     tags = parseTags(data.tag);
-                    if ( way == null )
+                    if ( way == null ) {
                         setWay(new Way(id, version, tags, true, nodes, uid, timestamp),false);
-                    else {
+                    } else {
+                                               waycount++;
                         way.update(version, tags, true, nodes, uid, timestamp);
                         sendEvent(new EntityEvent(NEW_WAY, way), false);
                     }