<Trkseg> component

This commit is contained in:
vdv committed 2022-11-27 16:18:50 +01:00
1 parent 54f2ab06d9
commit ab7374f360
4 files changed
+61 -5

No files matched your search

+17 -2
View File
@@ -1,4 +1,5 @@
import getUri from '../lib/ids';
import { appendToArray } from './gpx';
import { getFamily, put } from './lib';
import { putNewTrk } from './trk';
@@ -28,6 +29,20 @@ export const putNewTrkseg = async (id?: IdTrk | IdGpx | IdTrkseg) => {
export const getTrkseg = async (params: any) => {
const { id } = params;
const docs = await getFamily(id, { include_docs: true });
console.log(`getTrkseg, uri: ${id} docs: ${JSON.stringify(docs)}`);
return docs.rows;
let target: any[];
let trkseg: Trkseg | undefined = undefined;
docs.rows.forEach((row: any) => {
// level 0
if (row.doc.type === 'trkseg') {
target = [row.doc.doc];
trkseg = row.doc.doc;
}
//level 1
if (row.doc.type === 'trkpt') {
target.splice(1);
appendToArray(target.at(-1), row.doc.type, row.doc._id);
target.push(row.doc.doc);
}
});
return trkseg;
};