add todo
[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         public class GpxImporter extends Importer {
10
11                 public function GpxImporter(container:*, paint:MapPaint, filenames:Array, callback:Function=null, simplify:Boolean=false) {
12                         super(container,paint,filenames,callback,simplify);
13                 }
14
15                 override protected function doImport(): void {
16                         var xmlnsPattern:RegExp = new RegExp("xmlns[^\"]*\"[^\"]*\"", "gi");
17                         var xsiPattern:RegExp = new RegExp("xsi[^\"]*\"[^\"]*\"", "gi");
18                         files[0] = String(files[0]).replace(xmlnsPattern, "").replace(xsiPattern, "");
19                         var file:XML=new XML(files[0]);
20
21                         for each (var trk:XML in file.child("trk")) {
22                                 for each (var trkseg:XML in trk.child("trkseg")) {
23                                         var way:Way;
24                                         var nodestring:Array=[];
25                                         for each (var trkpt:XML in trkseg.child("trkpt")) {
26                                                 nodestring.push(container.createNode({}, trkpt.@lat, trkpt.@lon));
27                                         }
28                                         if (nodestring.length>0) {
29                                                 way=container.createWay({}, nodestring);
30                                                 if (simplify) { Simplify.simplify(way, paint.map, false); }
31                                         }
32                                 }
33                         }
34                         for each (var wpt:XML in file.child("wpt")) {
35                                 // ** could potentially get the children and add them as gpx:tags
36                                 container.createNode({}, wpt.lat, wpt.lon);
37                         }
38                 }
39         }
40 }