`<Trkseg>` component

This commit is contained in:
Eric van der Vlist 2022-11-27 16:18:50 +01:00
parent 54f2ab06d9
commit ab7374f360
4 changed files with 61 additions and 5 deletions

View File

@ -1,11 +1,11 @@
import { Component, createEffect, createResource } from 'solid-js'; import { Component, createEffect, createResource, For } from 'solid-js';
import OlMap from 'ol/Map'; import OlMap from 'ol/Map';
import dispatch from '../../workers/dispatcher-main'; import dispatch from '../../workers/dispatcher-main';
import getUri from '../../lib/ids'; import getUri from '../../lib/ids';
//import Trkseg from './Trkseg'; import Trkseg from '../trkseg';
interface Props { interface Props {
trkId: string; trkId: string;
@ -27,7 +27,15 @@ export const Trk: Component<Props> = ({ map, trkId }) => {
console.log({ caller: 'Trk', map: map(), trkId, trk: trk() }); console.log({ caller: 'Trk', map: map(), trkId, trk: trk() });
}); });
return <></>; return (
// @ts-ignore
<For each={trk() ? trk().trkseg || [] : []}>
{(trksegId: string) => {
console.log({ caller: 'Trk / loop', trksegId });
return <Trkseg map={map} trksegId={trksegId} />;
}}
</For>
);
}; };
export default Trk; export default Trk;

View File

@ -0,0 +1,32 @@
import { Component, createEffect, createResource } from 'solid-js';
import OlMap from 'ol/Map';
import dispatch from '../../workers/dispatcher-main';
import getUri from '../../lib/ids';
interface Props {
trksegId: string;
map: () => OlMap | null;
}
export const Trkseg: Component<Props> = ({ map, trksegId }) => {
const [trkseg] = createResource(
trksegId,
async () =>
await dispatch({
action: 'getTrkseg',
params: {
id: trksegId,
},
})
);
createEffect(() => {
console.log({ caller: 'Trkseg', map: map(), trksegId, trkseg: trkseg() });
});
return <></>;
};
export default Trkseg;

View File

@ -0,0 +1 @@
export { default } from './Trkseg';

View File

@ -1,4 +1,5 @@
import getUri from '../lib/ids'; import getUri from '../lib/ids';
import { appendToArray } from './gpx';
import { getFamily, put } from './lib'; import { getFamily, put } from './lib';
import { putNewTrk } from './trk'; import { putNewTrk } from './trk';
@ -28,6 +29,20 @@ export const putNewTrkseg = async (id?: IdTrk | IdGpx | IdTrkseg) => {
export const getTrkseg = async (params: any) => { export const getTrkseg = async (params: any) => {
const { id } = params; const { id } = params;
const docs = await getFamily(id, { include_docs: true }); const docs = await getFamily(id, { include_docs: true });
console.log(`getTrkseg, uri: ${id} docs: ${JSON.stringify(docs)}`); let target: any[];
return docs.rows; 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;
}; };