|
| 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