Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add preliminary support for c:geo export GPX (including groundspeak extension) #24

Open
wants to merge 23 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23,481 changes: 11,742 additions & 11,739 deletions dist/gpx-parse-browser.js

Large diffs are not rendered by default.

187 changes: 187 additions & 0 deletions export_test.gpx

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions export_test_oneline.gpx

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = process.env.GPXPARSE_COV ? require('./lib-cov/gpx-parse') : require('./lib/gpx-parse');
module.exports = require('./lib/gpx-parse');
77 changes: 71 additions & 6 deletions lib/gpx-parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ var assert = require("assert"),
GpxRoute = require('./gpxRoute'),
geomUtils = require('./geomUtils');


/**
* Parses the waypoints into an array of waypoints.
* @param {Array<Object>} gpxWaypoints - The array of points from the xml
Expand All @@ -32,6 +31,57 @@ var _getWayPoints = function(gpxWaypoints) {
waypoints.push(point);
});
}
return waypoints;
};


/**
* Parses the waypoints into an array of waypoints.
* @param {Array<Object>} gpxWaypoints - The array of points from the xml
*/
var _getExtendedWayPoints = function(gpxWaypoints) {
var waypoints = [];
if (gpxWaypoints && gpxWaypoints.length) {
gpxWaypoints.forEach(function(wayPoint) {
if( typeof wayPoint["groundspeak:cache"] !== "undefined" ) {
var cache = wayPoint["groundspeak:cache"][0];
var point = new GpxWaypoint(
wayPoint.$.lat, wayPoint.$.lon,
getFloat(wayPoint.ele), wayPoint.time,
null, null,
getString(wayPoint.name), null,
getString(wayPoint.desc), null,
null, getString(wayPoint.sym),
getString(wayPoint.type), getString(wayPoint.url),
getString(wayPoint.urlname), cache.$.id,
cache.$.available, cache.$.archived,
getString(cache["groundspeak:name"]), getString(cache["groundspeak:placed_by"]),
getString(cache["groundspeak:owner"]), getString(cache["groundspeak:type"]),
getString(cache["groundspeak:container"]), getString(cache["groundspeak:country"]),
"false"
);
waypoints.push(point);
} else {
var point = new GpxWaypoint(
wayPoint.$.lat, wayPoint.$.lon,
getFloat(wayPoint.ele), wayPoint.time,
null, null,
getString(wayPoint.name), null,
getString(wayPoint.desc), null,
null, getString(wayPoint.sym),
getString(wayPoint.type), getString(wayPoint.url),
getString(wayPoint.urlname), null,
null , null,
null, null,
null, null,
null, null,
"true"
);
waypoints.push(point);

}
});
}

return waypoints;
};
Expand Down Expand Up @@ -80,6 +130,18 @@ var getString = function(item) {
return value;
};

/**
* Gets a float from an element
var getCache = function(item) {
var value = null;
if (item && Array.isArray(item) && item.length > 0) {
value = (item[0]);
}
return value;
};
**/


/**
* Grabs any tracks contained within the gpx
* @params {Object} gpxTracks - THe gpcx tracks from the file
Expand Down Expand Up @@ -115,21 +177,24 @@ var _getTracks = function(gpxTracks) {
* Parses v1.0 data into data structure
*/
var _ParseV10 = function(gpx) {

var extent = null,
metadata = null;

extent = new GpxExtent();
metadata = new GpxMetaData(gpx.$.creator, gpx.time, extent);

return new GpxResult(metadata, _getWayPoints(gpx.wpt), _getRoutes(gpx.rte), _getTracks(gpx.trk));
metadata = new GpxMetaData(gpx.$.creator, gpx.time, extent);
if(metadata.creator == 'c:geo - http://www.cgeo.org/') {
return new GpxResult(metadata, _getExtendedWayPoints(gpx.wpt), [], [] );
} else {
return new GpxResult(metadata, _getWayPoints(gpx.wpt), _getRoutes(gpx.rte), _getTracks(gpx.trk));
}
};

/**
* Parses v1.1 data into data structure
*/
var _ParseV11 = function(gpx) {
var metadata;
var metadata;

if (gpx.metadata && gpx.metadata.length > 0) {
metadata = new GpxMetaData(gpx.$.creator, getString(gpx.metadata[0].time));
Expand Down
205 changes: 178 additions & 27 deletions lib/gpxWaypoint.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,90 @@
* @param {string[]} links An array of links for the waypoint.
* @param {string} sym The symbol of the waypoint.
* @param {string} type The type of waypoint.
* @param {string} url An url of the waypoint.
* @param {string} urlname The name of url of the waypoint.
* @param {string} cache The cache (groundspeak extension).
* @param {boolean} extraWp T if additional wp (not cache).
*
**/
function GpxWaypoint(lat, lon, elevation, time, magvar, geoidheight, name, cmt, desc, src, links, sym, type) {
function GpxWaypoint(lat, lon, elevation, time,
magvar, geoidheight, name, cmt,
desc, src, links, sym,
type, url, urlname, cacheId,
cacheAvailable, cacheArchived, cacheName, cachePlacedBy,
cacheOwner, cacheType, cacheContainer, cacheCountry,
extraWp) {
lat = parseFloat(lat) || -1;
lon = parseFloat(lon) || -1;
elevation = elevation || -1;
time = time ? new Date(time) : null;
magvar = magvar || -1;
geoidheight = geoidheight || -1;
name = name || null;
cmt = cmt || "";
desc = desc || null;
src = src || "";
type = type || "";
links = links || null;
sym = sym || null;
type = type || null;
url = url || null;
urlname = urlname || null;
cacheId = cacheId || null;
cacheAvailable = cacheAvailable || null;
cacheArchived = cacheArchived || null;
cacheName = cacheName || null;
cachePlacedBy = cachePlacedBy || null;
cacheOwner = cacheOwner || null;
cacheType = cacheType || null;
cacheContainer = cacheContainer || null;
cacheCountry = cacheCountry || null;
extraWp = extraWp || "true";

/**
* Latitude of the Waypoint
* @name lat
* @memberOf GpxWaypoint
* @instance
* @type {Number}
**/
this.__defineGetter__("lat", function() {
return lat;
});

/**
* Longtitude of the Waypoint
* @name lon
* @memberOf GpxWaypoint
* @instance
* @type {Number}
**/
this.__defineGetter__("lon", function() {
return lon;
});


/**
* Elevation at the Waypoint
* @name elevation
* @memberOf GpxWaypoint
* @instance
* @type {Number}
**/
this.__defineGetter__("elevation", function() {
return elevation;
});
/**
* Time associated with the Waypoint
* @name time
* @memberOf GpxWaypoint
* @instance
* @type {Date}
**/
this.__defineGetter__("time", function() {
return time;
});



/**
* Name of the Waypoint
Expand Down Expand Up @@ -61,58 +134,136 @@ function GpxWaypoint(lat, lon, elevation, time, magvar, geoidheight, name, cmt,
get: function() { return desc; }
});


/**
* desc of the Waypoint
* @name desc
* @memberOf GpxWaypoint
* @instance
* @type {string}
**/
this.__defineGetter__("desc", function() {
return desc;
});

this.__defineGetter__("src", function() {
return src;
});

this.__defineGetter__("sym", function() {
return sym;
});

this.__defineGetter__("type", function() {
return type;
});
this.__defineGetter__("url", function() {
return url;
});
this.__defineGetter__("urlname", function() {
return urlname;
});

/**
* Latitude of the Waypoint
* @name lat
* cacheId of the Waypoint
* @name cacheId
* @memberOf GpxWaypoint
* @instance
* @type {Number}
* @type {string}
**/
this.__defineGetter__("lat", function() {
return lat;
this.__defineGetter__("cacheId", function() {
return cacheId;
});

/**
* Longtitude of the Waypoint
* @name lon
* groundspeak extension cacheAvailable of the Waypoint
* @name cacheAvailable
* @memberOf GpxWaypoint
* @instance
* @type {Number}
* @type {string}
**/
this.__defineGetter__("lon", function() {
return lon;
this.__defineGetter__("cacheAvailable", function() {
return cacheAvailable;
});


/**
* Elevation at the Waypoint
* @name elevation
* groundspeak extension cacheArchived of the Waypoint
* @name cacheArchived
* @memberOf GpxWaypoint
* @instance
* @type {Number}
* @type {string}
**/
this.__defineGetter__("elevation", function() {
return elevation;
this.__defineGetter__("cacheArchived", function() {
return cacheArchived;
});


/**
* Time associated with the Waypoint
* @name time
* groundspeak extension cacheName of the Waypoint
* @name cacheName
* @memberOf GpxWaypoint
* @instance
* @type {Date}
* @type {string}
**/
this.__defineGetter__("time", function() {
return time;
this.__defineGetter__("cacheName", function() {
return cacheName;
});
/**
* groundspeak extension cachePlacedBy of the Waypoint
* @name cachePlacedBy
* @memberOf GpxWaypoint
* @instance
* @type {string}
**/
this.__defineGetter__("cachePlacedBy", function() {
return cachePlacedBy;
});
/**
* groundspeak extension cacheOwner of the Waypoint
* @name cacheOwner
* @memberOf GpxWaypoint
* @instance
* @type {string}
**/
this.__defineGetter__("cacheOwner", function() {
return cacheOwner;
});
/**
* groundspeak extension cacheType of the Waypoint
* @name cacheType
* @memberOf GpxWaypoint
* @instance
* @type {string}
**/
this.__defineGetter__("cacheType", function() {
return cacheType;
});
/**
* groundspeak extension cacheContainer of the Waypoint
* @name cacheContainer
* @memberOf GpxWaypoint
* @instance
* @type {string}
**/
this.__defineGetter__("cacheContainer", function() {
return cacheContainer;
});
/**
* groundspeak extension cacheCountry of the Waypoint
* @name cacheCountry
* @memberOf GpxWaypoint
* @instance
* @type {string}
**/
this.__defineGetter__("cacheCountry", function() {
return cacheCountry;
});
/**
* extra Waypoint (t/f)
* @name extraWp
* @memberOf GpxWaypoint
* @instance
* @type {boolean}
**/
this.__defineGetter__("extraWp", function() {
return extraWp;
});
}

Expand Down
Loading