mirror of
https://github.com/muerwre/orchidmap-front.git
synced 2025-04-25 19:16:41 +07:00
gpx generation
This commit is contained in:
parent
b28e695fe7
commit
99f76dbe2c
6 changed files with 72 additions and 4 deletions
33
src/utils/gpx.ts
Normal file
33
src/utils/gpx.ts
Normal 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`
|
||||
)
|
||||
);
|
Loading…
Add table
Add a link
Reference in a new issue