<Trk> component
This commit is contained in:
1 parent
79fb39100f
commit
54f2ab06d9
6 files changed
+65
-10
No files matched your search
+1
-1
@@ -215,7 +215,7 @@ export const getGpxesForViewport = async (params: any) => {
|
||||
);
|
||||
};
|
||||
|
||||
const appendToArray = (target: any, key: string, value: any) => {
|
||||
export const appendToArray = (target: any, key: string, value: any) => {
|
||||
if (!(key in target)) {
|
||||
target[key] = <any>[];
|
||||
}
|
||||
|
||||
+17
-5
@@ -1,5 +1,5 @@
|
||||
import getUri from '../lib/ids';
|
||||
import { putNewGpx } from './gpx';
|
||||
import { appendToArray, putNewGpx } from './gpx';
|
||||
import { getFamily, put } from './lib';
|
||||
|
||||
export const emptyTrk: Trk = {
|
||||
@@ -35,8 +35,20 @@ export const putNewTrk = async (id?: IdTrk | IdGpx) => {
|
||||
export const getTrk = async (params: any) => {
|
||||
const { id } = params;
|
||||
const docs = await getFamily(id, { include_docs: true });
|
||||
console.log(`getTrk, uri: ${id} docs: ${JSON.stringify(docs)}`);
|
||||
return docs.rows.filter(
|
||||
(row: any) => row.doc.type === 'trk' || row.doc.type === 'trkseg'
|
||||
);
|
||||
let target: any[];
|
||||
let trk: Trk | undefined = undefined;
|
||||
docs.rows.forEach((row: any) => {
|
||||
// level 0
|
||||
if (row.doc.type === 'trk') {
|
||||
target = [row.doc.doc];
|
||||
trk = row.doc.doc;
|
||||
}
|
||||
//level 1
|
||||
if (row.doc.type === 'trkseg') {
|
||||
target.splice(1);
|
||||
appendToArray(target.at(-1), row.doc.type, row.doc._id);
|
||||
target.push(row.doc.doc);
|
||||
}
|
||||
});
|
||||
return trk;
|
||||
};
|
||||
Reference in new issue
Block a user