2092e24da9f12f2fa41e83f078a78742514c2148
[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             default xml namespace = new Namespace("http://www.topografix.com/GPX/1/0");
21                         var file:XML = new XML(files[0]);
22
23                         for each (var trkseg:XML in file..trkseg) {
24                                 var way:Way;
25                 var nodestring:Array = [];
26                 for each (var trkpt:XML in trkseg.trkpt) {
27                                         nodestring.push(container.createNode({}, trkpt.@lat, trkpt.@lon));
28                                 }
29                 if (nodestring.length > 0) {
30                                         way = container.createWay({}, nodestring);
31                                         if (simplify) { Simplify.simplify(way, paint.map, false); }
32                                 }
33                         }
34
35             for each (var wpt:XML in file.wpt) {
36                                 var tags:Object = {};
37                                 for each (var tag:XML in wpt.children()) {
38                                         tags[tag.name()]=tag.toString();
39                                 }
40                                 var node:Node = container.createNode(tags, wpt.@lat, wpt.@lon);
41                                 container.registerPOI(node);
42                         }
43                 }
44         }
45 }