From 1222b8f5137372b1669739db179e84857a3dfedd Mon Sep 17 00:00:00 2001 From: muerwre Date: Mon, 18 Feb 2019 14:34:01 +0700 Subject: [PATCH] added points to gpx track --- src/redux/user/sagas.ts | 8 +++---- src/utils/gpx.ts | 52 ++++++++++++++++++++++++----------------- 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/src/redux/user/sagas.ts b/src/redux/user/sagas.ts index 88dcfaf..512e5f8 100644 --- a/src/redux/user/sagas.ts +++ b/src/redux/user/sagas.ts @@ -560,12 +560,14 @@ function* setTitleSaga({ title }: ReturnType):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([ diff --git a/src/utils/gpx.ts b/src/utils/gpx.ts index 413f112..412e6a4 100644 --- a/src/utils/gpx.ts +++ b/src/utils/gpx.ts @@ -5,36 +5,44 @@ export interface IRoutePoint { lng: number, } + +interface IGPXSticker { + latlng: IRoutePoint, + text?: string, +} + interface IGetGPXString { - points: Array, + route: Array, + stickers?: Array title?: string, } -// -// export const getGPXString = ({ points, title }: IGetGPXString): string => (` -// -// -// ${title || 'GPX Track'} -// ${ -// points.reduce((cat, { lat, lng }, index) => ( -// ` ${cat} -// ` -// ), '') -// } -// -// -// `); -export const getGPXString = ({ points, title }: IGetGPXString): string => (` - - + +export const getGPXString = ({ route, title, stickers }: IGetGPXString): string => (` + + + ${title || 'GPX Track'} + + ${ + stickers.reduce((cat, { latlng: { lat, lng }, text }, index) => ( + `${cat} + + ${text} + generic + Generic + `), '') + } + ${title || 'GPX Track'} + ${ - points.reduce((cat, { lat, lng }, index) => ( - `${cat} -` + route.reduce((cat, { lat, lng }, index) => ( + ` ${cat} + ` ), '') } - + + `);