compile fixes
[potlatch2.git] / net / systemeD / potlatch2 / utils / GpxImporter.as
1 package net.systemeD.potlatch2.utils {
2
3         import net.systemeD.halcyon.MapPaint;
4         import net.systemeD.halcyon.Globals;
5         import net.systemeD.halcyon.connection.Node;
6         import net.systemeD.halcyon.connection.Way;
7         import net.systemeD.potlatch2.tools.Simplify;
8
9     /**
10     * Implements parsing and loading of GPX files.
11     * For loading GPX traces from the OSM API, see halcyon/connection/Trace.as
12     */
13         public class GpxImporter extends Importer {
14
15                 public function GpxImporter(container:*, paint:MapPaint, filenames:Array, callback:Function=null, simplify:Boolean=false) {
16                         super(container,paint,filenames,callback,simplify);
17                 }
18
19                 override protected function doImport(): void {
20                         var xmlnsPattern:RegExp = new RegExp("xmlns[^\"]*\"[^\"]*\"", "gi");
21                         var xsiPattern:RegExp = new RegExp("xsi[^\"]*\"[^\"]*\"", "gi");
22                         files[0] = String(files[0]).replace(xmlnsPattern, "").replace(xsiPattern, "");
23                         var file:XML=new XML(files[0]);
24
25                         for each (var trk:XML in file.child("trk")) {
26                                 for each (var trkseg:XML in trk.child("trkseg")) {
27                                         var way:Way;
28                                         var nodestring:Array=[];
29                                         for each (var trkpt:XML in trkseg.child("trkpt")) {
30                                                 nodestring.push(container.createNode({}, trkpt.@lat, trkpt.@lon));
31                                         }
32                                         if (nodestring.length>0) {
33                                                 way=container.createWay({}, nodestring);
34                                                 if (simplify) { Simplify.simplify(way, paint.map, false); }
35                                         }
36                                 }
37                         }
38                         for each (var wpt:XML in file.child("wpt")) {
39                                 var tags:Object={};
40                                 for each (var tag:XML in wpt.children()) {
41                                         tags[tag.name()]=tag.toString();
42                                 }
43                                 var node:Node=container.createNode(tags, wpt.@lat, wpt.@lon);
44                                 container.registerPOI(node);
45                         }
46                 }
47         }
48 }