dyomedea/src/components/gpx/Gpx.tsx

42 lines
868 B
TypeScript
Raw Normal View History

2022-11-27 15:09:08 +00:00
import { Component, createEffect, createResource, For } from 'solid-js';
2022-11-27 14:50:08 +00:00
import OlMap from 'ol/Map';
import dispatch from '../../workers/dispatcher-main';
2022-11-27 15:09:08 +00:00
import Trk from '../trk';
2022-11-27 14:50:08 +00:00
import getUri from '../../lib/ids';
interface Props {
gpxId: string;
map: () => OlMap | null;
}
export const Gpx: Component<Props> = ({ map, gpxId }) => {
const [gpx] = createResource(
gpxId,
async () =>
await dispatch({
action: 'getGpx',
params: {
id: gpxId,
},
})
);
createEffect(() => {
console.log({ caller: 'Gpx', map: map(), gpxId, gpx: gpx() });
});
2022-11-27 15:09:08 +00:00
return (
// @ts-ignore
<For each={gpx() ? gpx().trk || [] : []}>
{(trkId: string) => {
console.log({ caller: 'Gpx / loop', trkId });
return <Trk map={map} trkId={trkId} />;
}}
</For>
);
2022-11-27 14:50:08 +00:00
};
export default Gpx;