Drop xmlbuilder from gps-to-gpx dep

This commit is contained in:
Lucas Verney 2018-09-04 13:39:25 +02:00
parent 7557d3b64c
commit f5fdb2aeb0
4 changed files with 29 additions and 13 deletions

View File

@ -15,7 +15,7 @@
"dependencies": {
"@babel/polyfill": "^7.0.0",
"file-saver": "^1.3.8",
"gps-to-gpx": "^1.4.0",
"gps-to-gpx": "git://github.com/phyks/gps-to-gpx.git#2c9da24ca98ecd520ee75276714d4df337696475",
"howler": "^2.0.15",
"material-icons": "^0.2.3",
"nosleep.js": "^0.7.0",

View File

@ -5,31 +5,47 @@ import { VERSION } from '@/constants';
import { formatDate } from '@/tools/date';
export default function (activityName, locationGPX) {
const courseKey = 'heading';
const eleKey = 'elevation';
const hdopKey = 'hdop';
const speedKey = 'speed';
const vdopKey = 'vdop';
// Extensions
const extKey = 'extensions';
const extensionsKeys = {
heading: 'course',
speed: 'speed',
};
const waypoints = [];
locationGPX.forEach((item) => {
const waypoint = Object.assign({}, item, { timestamp: new Date(item.timestamp) });
[courseKey, eleKey, hdopKey, speedKey, vdopKey].forEach((key) => {
// Omit keys with empty values
[eleKey, hdopKey, vdopKey].forEach((key) => {
if (waypoint[key] === null || waypoint[key] === undefined) {
delete waypoint[key];
}
});
// Handle extensions
waypoint[extKey] = {};
Object.keys(extensionsKeys).forEach((key) => {
if (waypoint[key] !== null && waypoint[key] !== undefined) {
waypoint[extKey][extensionsKeys[key]] = waypoint[key];
delete waypoint[key];
}
});
waypoints.push(waypoint);
});
const gpx = createGPX(waypoints, {
activityName,
creator: `Cycl'Assist v${VERSION}`,
courseKey,
eleKey,
extKey,
hdopKey,
latKey: 'latitude',
lonKey: 'longitude',
speedKey,
startTime: waypoints[0].timestamp,
timeKey: 'timestamp',
vdopKey,

View File

@ -36,6 +36,10 @@ export function mockLocationRandom() {
if (Math.random() > 0.25) {
heading = Math.random() * 360;
}
let speed = null;
if (Math.random() > 0.25) {
speed = Math.random() * 20;
}
const newLocation = {
coords: {
accuracy: Math.random() * 100, // In meters
@ -48,6 +52,7 @@ export function mockLocationRandom() {
+ MOCK_LOCATION_LNG_MIN
),
heading,
speed,
},
timestamp: new Date().getTime(),
};

View File

@ -3711,13 +3711,12 @@ got@^7.0.0:
url-parse-lax "^1.0.0"
url-to-options "^1.0.1"
gps-to-gpx@^1.4.0:
"gps-to-gpx@git://github.com/phyks/gps-to-gpx.git#2c9da24ca98ecd520ee75276714d4df337696475":
version "1.4.0"
resolved "https://registry.yarnpkg.com/gps-to-gpx/-/gps-to-gpx-1.4.0.tgz#9cf4e5ae630189e0058dd01897111a55168009bc"
resolved "git://github.com/phyks/gps-to-gpx.git#2c9da24ca98ecd520ee75276714d4df337696475"
dependencies:
babel-runtime "6.18.0"
loose-envify "1.3.0"
xmlbuilder "8.2.2"
graceful-fs@^4.0.0, graceful-fs@^4.1.10, graceful-fs@^4.1.11, graceful-fs@^4.1.2, graceful-fs@^4.1.6, graceful-fs@^4.1.9:
version "4.1.11"
@ -8817,10 +8816,6 @@ xml2js@^0.4.5:
sax ">=0.6.0"
xmlbuilder "~9.0.1"
xmlbuilder@8.2.2:
version "8.2.2"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-8.2.2.tgz#69248673410b4ba42e1a6136551d2922335aa773"
xmlbuilder@~9.0.1:
version "9.0.7"
resolved "https://registry.yarnpkg.com/xmlbuilder/-/xmlbuilder-9.0.7.tgz#132ee63d2ec5565c557e20f4c22df9aca686b10d"