added points to gpx track

This commit is contained in:
muerwre 2019-02-18 14:34:01 +07:00
parent 9c46f11a94
commit 1222b8f513
2 changed files with 34 additions and 26 deletions

View file

@ -560,12 +560,14 @@ function* setTitleSaga({ title }: ReturnType<typeof ActionCreators.setTitle>):Sa
}
function* getGPXTrackSaga(): SagaIterator {
const { route } = editor.dumpData();
const { route, stickers } = editor.dumpData();
const { title, address } = yield select(getState);
if (!route || route.length <= 0) return;
const track = getGPXString({ points: route, title: (title || address) });
const track = getGPXString({ route, stickers, title: (title || address) });
console.log({ route, stickers });
return downloadGPXTrack({ track, title });
}
@ -601,8 +603,6 @@ export function* userSaga() {
yield takeLatest(ACTIONS.GOT_VK_USER, gotVkUserSaga);
yield takeLatest(ACTIONS.KEY_PRESSED, keyPressedSaga);
// yield takeLatest(ACTIONS.IFRAME_LOGIN_VK, iframeLoginVkSaga);
yield takeLatest(ACTIONS.SET_TITLE, setTitleSaga);
yield takeLatest([

View file

@ -5,36 +5,44 @@ export interface IRoutePoint {
lng: number,
}
interface IGPXSticker {
latlng: IRoutePoint,
text?: string,
}
interface IGetGPXString {
points: Array<IRoutePoint>,
route: Array<IRoutePoint>,
stickers?: Array<IGPXSticker>
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}
// <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>
<rte>
export const getGPXString = ({ route, title, stickers }: IGetGPXString): string => (`<?xml version="1.0" encoding="UTF-8"?>
<gpx xmlns="http://www.topografix.com/GPX/1/1" version="1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.topografix.com/GPX/1/1 http://www.topografix.com/GPX/1/1/gpx.xsd">
<metadata>
<name>${title || 'GPX Track'}</name>
</metadata>
${
stickers.reduce((cat, { latlng: { lat, lng }, text }, index) => (
`${cat}
<wpt lat="${lat}" lon="${lng}">
<name>${text}</name>
<sym>generic</sym>
<type>Generic</type>
</wpt>`), '')
}
<trk>
<name>${title || 'GPX Track'}</name>
<trkseg>
${
points.reduce((cat, { lat, lng }, index) => (
`${cat}
<rtept lat="${lat}" lon="${lng}"></rtept>`
route.reduce((cat, { lat, lng }, index) => (
` ${cat}
<trkpt lat="${lat}" lon="${lng}"></trkpt>`
), '')
}
</rte>
</trkseg>
</trk>
</gpx>
`);