diff --git a/server/src/export/gpx.ts b/server/src/export/gpx.ts index 3bfe8d4d..9afc8c7f 100644 --- a/server/src/export/gpx.ts +++ b/server/src/export/gpx.ts @@ -39,18 +39,24 @@ function dataToText(fields: Field[], data: Record) { return text.join('\n\n'); } -function getMetadataGpx(data: { name: string }, extensions: Record = {}): string { +function getMetadataGpx(data: { name: string; extensions?: Record }, otherExtensions?: Record): string { + const { extensions, ...otherData } = data; return ( `\n` + Object.entries({ time: new Date().toISOString(), - ...data + ...otherData }).map(([k, v]) => `\t<${quoteHtml(k)}>${quoteHtml(v)}\n`).join("") + + (extensions && Object.keys(extensions).length > 0 ? ( + `\t\n` + + Object.entries(extensions).map(([k, v]) => `\t\t<${quoteHtml(k)}>${quoteHtml(v)}\n`).join("") + + `\t\n` + ) : "") + `` + - (Object.keys(extensions).length > 0 ? ( + (otherExtensions && Object.keys(otherExtensions).length > 0 ? ( `\n` + `\n` + - Object.entries(extensions).map(([k, v]) => `\t<${quoteHtml(k)}>${quoteHtml(v)}\n`).join("") + + Object.entries(otherExtensions).map(([k, v]) => `\t<${quoteHtml(k)}>${quoteHtml(v)}\n`).join("") + `` ) : "") ); @@ -218,15 +224,20 @@ export function exportGpxZip(database: Database, padId: PadId, useTracks: boolea type LineForExport = Pick & Partial>; -function getLineMetadataGpx(line: LineForExport): string { +function getLineMetadataGpx(line: LineForExport, type: Type | undefined): string { return getMetadataGpx({ - name: normalizeLineName(line.name) + name: normalizeLineName(line.name), + extensions: { + ...(type ? { + "osmand:desc": dataToText(type.fields, line.data) + } : {}) + } }, { ...(line.colour ? { - color: `#${line.colour}` + "osmand:color": `#${line.colour}` } : {}), ...(line.width ? { - width: `${line.width}` + "osmand:width": `${line.width}` } : {}) }); } @@ -235,7 +246,7 @@ export function exportLineToTrackGpx(line: LineForExport, type: Type | undefined return asyncIteratorToStream((async function*() { yield ( `${gpxHeader}\n` + - `\t${getLineMetadataGpx(line).replaceAll("\n", "\n\t")}\n` + `\t${getLineMetadataGpx(line, type).replaceAll("\n", "\n\t")}\n` ); for await (const chunk of indentStream(getLineTrackGpx(line, type, trackPoints), { indent: "\t", indentFirst: true, addNewline: true })) { @@ -250,7 +261,7 @@ export function exportLineToRouteGpx(line: LineForExport, type: Type | undefined return asyncIteratorToStream((async function*() { yield ( `${gpxHeader}\n` + - `\t${getLineMetadataGpx(line).replaceAll("\n", "\n\t")}\n` + `\t${getLineMetadataGpx(line, type).replaceAll("\n", "\n\t")}\n` ); for await (const chunk of indentStream(getLineRouteGpx(line, type), { indent: "\t", indentFirst: true, addNewline: true })) {