1 package net.systemeD.potlatch2.utils {
3 import net.systemeD.halcyon.Map;
4 import net.systemeD.halcyon.connection.Connection;
5 import net.systemeD.halcyon.connection.Node;
6 import net.systemeD.halcyon.connection.Way;
7 import net.systemeD.potlatch2.tools.Simplify;
10 * Implements parsing and loading of GPX files.
11 * For loading GPX traces from the OSM API, see halcyon/connection/Trace.as
13 public class GpxImporter extends Importer {
15 public function GpxImporter(connection:Connection, map:Map, filenames:Array, callback:Function=null, simplify:Boolean=false) {
16 super(connection,map,filenames,callback,simplify);
19 override protected function doImport(push:Function): void {
20 var file:XML = new XML(files[0]);
21 for each (var ns:Namespace in file.namespaceDeclarations()) {
22 if (ns.uri.match(/^http:\/\/www\.topografix\.com\/GPX\/1\/[01]$/)) {
23 default xml namespace = ns;
27 for each (var trkseg:XML in file..trkseg) {
29 var nodestring:Array = [];
30 for each (var trkpt:XML in trkseg.trkpt) {
31 nodestring.push(connection.createNode({}, trkpt.@lat, trkpt.@lon, push));
33 if (nodestring.length > 0) {
34 way = connection.createWay({}, nodestring, push);
35 if (simplify) { Simplify.simplify(way, map, false); }
39 for each (var wpt:XML in file.wpt) {
41 for each (var tag:XML in wpt.children()) {
42 tags[tag.name().localName]=tag.toString();
44 var node:Node = connection.createNode(tags, wpt.@lat, wpt.@lon, push);
45 connection.registerPOI(node);
48 default xml namespace = new Namespace("");