Allow several .osm files in one imported .zip
authorRichard Fairhurst <richard@systemeD.net>
Mon, 2 Jul 2012 17:32:48 +0000 (18:32 +0100)
committerRichard Fairhurst <richard@systemeD.net>
Mon, 2 Jul 2012 17:32:48 +0000 (18:32 +0100)
(loads to one Connection, so id numbering must be consistent
 - useful for working with CanVec files)

net/systemeD/potlatch2/utils/OsmImporter.as

index 550024f..fac2a27 100644 (file)
@@ -11,46 +11,49 @@ package net.systemeD.potlatch2.utils {
                }
 
                override protected function doImport(push:Function):void {
-                       var map:XML = new XML(files[0]);
-                       if (map.name().localName=='osmChange') { map=map.create[0]; }
-
                        var data:XML;
-            var oldid:Number;
-            var tags:Object;
+                       var oldid:Number;
+                       var tags:Object;
 
                        var nodemap:Object={};
                        var waymap:Object={};
                        var relationmap:Object={};
 
-            for each(data in map.node) {
-                oldid = Number(data.@id);
-                               nodemap[oldid] = connection.createNode(parseTags(data.tag), Number(data.@lat), Number(data.@lon), push);
-            }
+                       for (var f:uint=0; f<files.length; f++) {
+                               var map:XML = new XML(files[f]);
+                               if (map.name().localName=='osmChange') { map=map.create[0]; }
+
+                               for each(data in map.node) {
+                                       oldid = Number(data.@id);
+                                       nodemap[oldid] = connection.createNode(parseTags(data.tag), Number(data.@lat), Number(data.@lon), push);
+                               }
 
-            for each(data in map.way) {
-                oldid = Number(data.@id);
-                var nodes:Array = [];
-                for each(var nd:XML in data.nd) { nodes.push(nodemap[Number(nd.@ref)]); }
-                               waymap[oldid] = connection.createWay(parseTags(data.tag), nodes, push);
-            }
+                               for each(data in map.way) {
+                                       oldid = Number(data.@id);
+                                       var nodes:Array = [];
+                                       for each(var nd:XML in data.nd) { nodes.push(nodemap[Number(nd.@ref)]); }
+                                       waymap[oldid] = connection.createWay(parseTags(data.tag), nodes, push);
+                               }
             
-            for each(data in map.relation) {
-                oldid = Number(data.@id);
-                var members:Array = [];
-                for each(var memberXML:XML in data.member) {
-                    var type:String = memberXML.@type.toLowerCase();
-                    var role:String = memberXML.@role;
-                    var memberID:Number = Number(memberXML.@ref);
-                    var member:Entity = null;
-                                       switch (memberXML.@type.toLowerCase()) {
-                                               case 'node':            member=nodemap[memberID]; break;
-                                               case 'way':                     member=waymap[memberID]; break;
-                                               case 'relation':        break;  // ** TODO - cope with evil nested relations
+                               for each(data in map.relation) {
+                                       oldid = Number(data.@id);
+                                       var members:Array = [];
+                                       for each(var memberXML:XML in data.member) {
+                                               var type:String = memberXML.@type.toLowerCase();
+                                               var role:String = memberXML.@role;
+                                               var memberID:Number = Number(memberXML.@ref);
+                                               var member:Entity = null;
+                                               switch (memberXML.@type.toLowerCase()) {
+                                                       case 'node':            member=nodemap[memberID]; break;
+                                                       case 'way':                     member=waymap[memberID]; break;
+                                                       case 'relation':        break;  // ** TODO - cope with evil nested relations
+                                               }
+                                               if (member!=null) { members.push(new RelationMember(member,role)); }
                                        }
-                                       if (member!=null) { members.push(new RelationMember(member,role)); }
-                }
-                               relationmap[oldid] = connection.createRelation(parseTags(data.tag), members, push);
-            }
+                                       relationmap[oldid] = connection.createRelation(parseTags(data.tag), members, push);
+                               }
+                       }
+                       
         }
 
         private function parseTags(tagElements:XMLList):Object {