dyomedea/src/components/wpt/Wpt.tsx

79 lines
1.7 KiB
TypeScript
Raw Normal View History

2022-12-06 13:36:50 +00:00
import {
Component,
createEffect,
createResource,
createSignal,
} from 'solid-js';
2022-11-28 10:52:50 +00:00
import dispatch from '../../workers/dispatcher-main';
import VectorSource from 'ol/source/Vector';
import GeoJSON from 'ol/format/GeoJSON';
2022-11-29 14:06:39 +00:00
import { setBranch, tree } from '../map';
import { Feature } from 'ol';
2022-11-28 10:52:50 +00:00
interface Props {
wptId: string;
vectorSource: VectorSource;
}
export const Wpt: Component<Props> = ({ vectorSource, wptId: wptId }) => {
2022-12-06 13:36:50 +00:00
const [wpt, setWpt] = createSignal<Wpt>();
const wptCallBack = (error: any, result: any) => {
if (error) {
console.error({ caller: 'wptCallBack', error });
} else {
console.log({ caller: 'wptCallBack', result });
setWpt(result);
}
};
dispatch(
{
action: 'getAndWatch',
params: {
id: wptId,
method: 'getWpt',
},
},
wptCallBack,
true
2022-11-28 10:52:50 +00:00
);
createEffect(() => {
console.log({ caller: 'Wpt', vectorSource, wptId, wpt: wpt() });
2022-11-29 14:06:39 +00:00
if (wpt() && !tree[wptId]) {
2022-11-28 10:52:50 +00:00
let geo: any = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [wpt().$.lon, wpt().$.lat],
},
properties: { type: 'wpt', ...wpt(), id: wptId },
2022-11-28 10:52:50 +00:00
},
],
};
const features = new GeoJSON().readFeatures(geo);
console.log({ caller: 'Wpt', features });
vectorSource.addFeatures(features);
2022-11-29 14:06:39 +00:00
setBranch(wptId, { features, updateHandler });
2022-11-28 10:52:50 +00:00
}
});
2022-11-29 14:06:39 +00:00
const updateHandler = (feature: Feature) => {
console.log({
caller: 'Wpt / updateHandler / clicked',
feature,
});
};
2022-11-28 10:52:50 +00:00
return <></>;
};
export default Wpt;