Skip to content

Commit 55d1f9d

Browse files
committed
first commit
1 parent c5bd446 commit 55d1f9d

File tree

3 files changed

+63
-0
lines changed

3 files changed

+63
-0
lines changed

files/.DS_Store

6 KB
Binary file not shown.

files/gpx_config.json

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"JUMP_DELAY": "10",
3+
"ALTERNATE_DELAYS": false,
4+
"ALT_DELAY": "5",
5+
"coordinates": [
6+
"coord,coord",
7+
"coord,coord",
8+
"coord,coord",
9+
"coord,coord"
10+
],
11+
"names": [
12+
"name",
13+
"name",
14+
"name",
15+
"name"
16+
]
17+
}

gpxcreate.js

+46
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
'use strict';
2+
const config=require('./files/gpx_config.json')
3+
const fs=require('fs');
4+
const moment=require('moment');
5+
const coordinates=config.coordinates;
6+
const names=config.names;
7+
8+
var divider=5, multiplier=10, gpx, newCoord, coord, coordLat, coordLon, nextCoordLat, nextCoordTime, jumpCoord;
9+
10+
function createGPX(coordinates, multiplier, divider){
11+
var coordTime=moment('2018-06-01T00:00:00').format('YYYY-MM-DD[T]HH:mm:ss'), jump=0;
12+
for(let x=0;x<coordinates.length;x++){
13+
nextCoordLat=''; coord=coordinates[x].split(',');
14+
coordLat=coord[0]; coordLon=coord[1]; jump++
15+
if(coord[0].length<8){for(let c=coord[0].length; c<8; c++){coord[0]=coord[0]+'0';}}
16+
nextCoordLat=((coordLat*multiplier)-divider)/multiplier;
17+
jumpCoord=moment(coordTime).format('YYYY-MM-DD[T]HH:mm:ss');
18+
nextCoordTime=moment(coordTime).add(config.JUMP_DELAY, 'seconds').format('YYYY-MM-DD[T]HH:mm:ss');
19+
newCoord='<!-- '+names[x]+' -->\n<wpt lat=\"'+coordLat+'\" lon=\"'+coordLon+'\">\n<time>'+jumpCoord+'Z</time>\n</wpt>\n<wpt lat=\"'+nextCoordLat+'\" lon=\"'+coordLon+'\">\n<time>'+nextCoordTime+'Z</time>\n</wpt>\n';
20+
if(gpx==undefined){gpx='<?xml version=\"1.0\"?>\n<gpx version=\"1.1\" creator=\"russellg89\">\n';}else{gpx+=newCoord;}
21+
coordTime=nextCoordTime;
22+
}
23+
if(config.ALTERNATE_DELAYS==true){
24+
for(let x=0;x<coordinates.length;x++){
25+
nextCoordLat=''; coord=coordinates[x].split(',');
26+
coordLat=coord[0]; coordLon=coord[1]; jump++
27+
if(!names[x]){names[x]='Jump '+x;}
28+
nextCoordLat=((coordLat*multiplier)-divider)/multiplier;
29+
jumpCoord=moment(coordTime).format('YYYY-MM-DD[T]HH:mm:ss');
30+
nextCoordTime=moment(coordTime).add(config.ALT_DELAY, 'seconds').format('YYYY-MM-DD[T]HH:mm:ss');
31+
newCoord='<!-- '+names[x]+' -->\n<wpt lat=\"'+coordLat+'\" lon=\"'+coordLon+'\">\n<time>'+jumpCoord+'Z</time>\n</wpt>\n<wpt lat=\"'+nextCoordLat+'\" lon=\"'+coordLon+'\">\n<time>'+nextCoordTime+'Z</time>\n</wpt>\n';
32+
gpx+=newCoord; coordTime=nextCoordTime;
33+
}
34+
}
35+
gpx=gpx+'</gpx>';
36+
return gpx;
37+
}
38+
39+
async function postGPX(coordinates, coordTime){
40+
for(let l=4; l<coordinates[0].length; l++){multiplier=multiplier*10;}
41+
for(let l=8; l<coordinates[0].length; l++){divider=divider*10;}
42+
var result = await createGPX(coordinates, multiplier, divider);
43+
console.log(result);
44+
}
45+
46+
postGPX(coordinates);

0 commit comments

Comments
 (0)