101 lines
2.3 KiB
TypeScript
101 lines
2.3 KiB
TypeScript
import { Component, createEffect, For, onCleanup, Suspense } from 'solid-js';
|
|
|
|
import OlMap from 'ol/Map';
|
|
|
|
import Trk from '../trk';
|
|
import VectorSource from 'ol/source/Vector';
|
|
import VectorLayer from 'ol/layer/Vector';
|
|
|
|
import style from './styles';
|
|
import Wpt from '../wpt';
|
|
import Rte from '../rte';
|
|
import {
|
|
createCachedSignal,
|
|
destroyCachedSignal,
|
|
} from '../../workers/cached-signals';
|
|
|
|
interface Props {
|
|
gpxId: string;
|
|
map: () => OlMap | null;
|
|
}
|
|
|
|
export const Gpx: Component<Props> = ({ map, gpxId }) => {
|
|
const params = {
|
|
id: gpxId,
|
|
method: 'getGpx',
|
|
};
|
|
const gpx = createCachedSignal(params);
|
|
|
|
onCleanup(() => {
|
|
console.log({
|
|
caller: 'Gpx / onCleanup',
|
|
gpxId,
|
|
gpx: gpx(),
|
|
params,
|
|
});
|
|
|
|
destroyCachedSignal(params);
|
|
});
|
|
|
|
const vectorSource = new VectorSource();
|
|
const vectorLayer = new VectorLayer({
|
|
source: vectorSource,
|
|
style,
|
|
declutter: true,
|
|
});
|
|
createEffect(() => map()?.addLayer(vectorLayer));
|
|
|
|
createEffect(() => {
|
|
console.log({ caller: 'Gpx', map: map(), gpxId, gpx: gpx(), vectorLayer });
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<For each={gpx() ? gpx().trk || [] : []}>
|
|
{(trkId: string) => {
|
|
console.log({ caller: 'Gpx / loop', trkId });
|
|
return (
|
|
<Suspense>
|
|
<Trk
|
|
vectorSource={vectorSource}
|
|
trkId={trkId}
|
|
context={{ gpx, gpxId }}
|
|
/>
|
|
</Suspense>
|
|
);
|
|
}}
|
|
</For>
|
|
<For each={gpx() ? gpx().rte || [] : []}>
|
|
{(rteId: string) => {
|
|
console.log({ caller: 'Gpx / loop', rteId });
|
|
return (
|
|
<Suspense>
|
|
<Rte
|
|
vectorSource={vectorSource}
|
|
rteId={rteId}
|
|
context={{ gpx, gpxId }}
|
|
/>
|
|
</Suspense>
|
|
);
|
|
}}
|
|
</For>
|
|
<For each={gpx() ? gpx().wpt || [] : []}>
|
|
{(wptId: string) => {
|
|
console.log({ caller: 'Gpx / loop', wptId });
|
|
return (
|
|
<Suspense>
|
|
<Wpt
|
|
vectorSource={vectorSource}
|
|
wptId={wptId}
|
|
context={{ gpx, gpxId }}
|
|
/>
|
|
</Suspense>
|
|
);
|
|
}}
|
|
</For>
|
|
</>
|
|
);
|
|
};
|
|
|
|
export default Gpx;
|