This commit is contained in:
muerwre 2019-02-18 12:21:29 +07:00
parent bcc357ca98
commit 9c46f11a94

View file

@ -9,37 +9,35 @@ interface IGetGPXString {
points: Array<IRoutePoint>, points: Array<IRoutePoint>,
title?: string, title?: string,
} }
//
export const getGPXString = ({ points, title }: IGetGPXString): string => (` // export const getGPXString = ({ points, title }: IGetGPXString): string => (`<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<gpx>
<rte>
<name>${title || 'GPX Track'}</name>
${
points.reduce((cat, { lat, lng }, index) => (
` ${cat}
<wpt lat="${lat.toFixed(6)}" lon="${lng.toFixed(6)}"></wpt>`
), '')
}
</rte>
</gpx>
`);
// export const getGPXString = ({ points, title }: IGetGPXString): string => (`
// <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
// <gpx> // <gpx>
// <rte> // <rte>
// <name>${title || 'GPX Track'}</name> // <name>${title || 'GPX Track'}</name>
// ${ // ${
// points.reduce((cat, { lat, lng }, index) => ( // points.reduce((cat, { lat, lng }, index) => (
// `${cat} // ` ${cat}
// <rtept lat="${lat}" lon="${lng}"></rtept>` // <wpt lat="${lat.toFixed(6)}" lon="${lng.toFixed(6)}"></wpt>`
// ), '') // ), '')
// } // }
// </rte> // </rte>
// </gpx> // </gpx>
// `); // `);
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 }) => ( export const downloadGPXTrack = ({ track, title }: { track: string, title?: string }) => (
saveAs( saveAs(
new Blob([track], { type: 'application/gpx+xml;charset=utf-8' }), new Blob([track], { type: 'application/gpx+xml;charset=utf-8' }),