gpx generation

This commit is contained in:
muerwre 2019-02-18 12:02:06 +07:00
parent b28e695fe7
commit 99f76dbe2c
6 changed files with 72 additions and 4 deletions

33
src/utils/gpx.ts Normal file
View file

@ -0,0 +1,33 @@
import * as saveAs from 'file-saver';
export interface IRoutePoint {
lat: number,
lng: number,
}
interface IGetGPXString {
points: Array<IRoutePoint>,
title?: string,
}
export const getGPXString = ({ points, title }: IGetGPXString): string => (`
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gpx>
<rte>
<name>${title || 'GPX Track'}</name>
${
points.reduce((cat, { lat, lng }, index) => (
`${cat}
<rtept lat="${lat}" lon="${lng}"></rtept>`
), '')
}
</rte>
</gpx>
`);
export const downloadGPXTrack = ({ track, title }: { track: string, title?: string }) => (
saveAs(
new Blob([track], { type: 'application/gpx+xml;charset=utf-8' }),
`${title || 'track'}.gpx`
)
);