2022-12-06 13:36:50 +00:00
|
|
|
import {
|
|
|
|
Component,
|
|
|
|
createEffect,
|
|
|
|
createResource,
|
|
|
|
createSignal,
|
2022-12-06 13:54:59 +00:00
|
|
|
onCleanup,
|
2022-12-06 13:36:50 +00:00
|
|
|
} from 'solid-js';
|
2022-11-28 10:52:50 +00:00
|
|
|
|
2022-12-06 13:54:59 +00:00
|
|
|
import dispatch, { cancelDispatch } from '../../workers/dispatcher-main';
|
2022-11-28 10:52:50 +00:00
|
|
|
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>();
|
2022-12-06 13:54:59 +00:00
|
|
|
const [dispatchId, setDispatchId] = createSignal<number>(-1);
|
2022-12-06 13:36:50 +00:00
|
|
|
|
2022-12-06 13:54:59 +00:00
|
|
|
const wptCallBack = (error: any, result: any, id?: number) => {
|
2022-12-06 13:36:50 +00:00
|
|
|
if (error) {
|
|
|
|
console.error({ caller: 'wptCallBack', error });
|
|
|
|
} else {
|
|
|
|
console.log({ caller: 'wptCallBack', result });
|
|
|
|
setWpt(result);
|
|
|
|
}
|
2022-12-06 13:54:59 +00:00
|
|
|
if (id) {
|
|
|
|
setDispatchId(id);
|
|
|
|
}
|
2022-12-06 13:36:50 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
dispatch(
|
|
|
|
{
|
|
|
|
action: 'getAndWatch',
|
|
|
|
params: {
|
|
|
|
id: wptId,
|
|
|
|
method: 'getWpt',
|
|
|
|
},
|
|
|
|
},
|
|
|
|
wptCallBack,
|
|
|
|
true
|
2022-11-28 10:52:50 +00:00
|
|
|
);
|
|
|
|
|
2022-12-06 13:54:59 +00:00
|
|
|
onCleanup(() => {
|
|
|
|
dispatch({
|
|
|
|
action: 'cancelWatch',
|
|
|
|
params: {
|
|
|
|
id: wptId,
|
|
|
|
method: 'getWpt',
|
|
|
|
},
|
|
|
|
});
|
|
|
|
cancelDispatch(dispatchId());
|
|
|
|
});
|
|
|
|
|
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],
|
|
|
|
},
|
2022-11-28 20:36:12 +00:00
|
|
|
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;
|