Dirty hack to store the app state and restore it at app startup.
This commit is contained in:
1 parent
acc1d7cc1e
commit
040122189c
4 files changed
+52
-4
No files matched your search
@@ -36,6 +36,8 @@ import DragZoom from 'ol/interaction/DragZoom';
|
||||
import Infos, { clickHandler } from '../infos';
|
||||
import GpxDialog from '../gpx-dialog';
|
||||
import GpxRecord from '../gpx-record';
|
||||
import dispatch from '../../workers/dispatcher-main';
|
||||
import { isEqual } from 'lodash';
|
||||
|
||||
const [getState, setState] = createSignal({
|
||||
lon: 0,
|
||||
@@ -52,12 +54,29 @@ const [getMap, setMap] = createSignal<OlMap | null>(null);
|
||||
export { getMap };
|
||||
|
||||
const Map: Component = () => {
|
||||
const params = useParams();
|
||||
const navigate = useNavigate();
|
||||
const params = useParams();
|
||||
|
||||
if (
|
||||
params.lat === '0' &&
|
||||
params.lon === '0' &&
|
||||
params.provider === 'osm' &&
|
||||
params.rotation === '0' &&
|
||||
params.zoom === '2'
|
||||
) {
|
||||
dispatch({ action: 'getState' }, (error, state) => {
|
||||
if (state !== null) {
|
||||
console;
|
||||
navigate(
|
||||
`/map/${state.provider}/${state.lon}/${state.lat}/${state.zoom}/${state.rotation}`
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
let target: HTMLDivElement;
|
||||
|
||||
createEffect(() => {
|
||||
createEffect(async () => {
|
||||
console.log({
|
||||
caller: 'Map / setState',
|
||||
params: {
|
||||
@@ -71,6 +90,7 @@ const Map: Component = () => {
|
||||
rotation: +params.rotation,
|
||||
zoom: +params.zoom,
|
||||
});
|
||||
await dispatch({ action: 'setState', params: getState() });
|
||||
const map = getMap();
|
||||
|
||||
const layers = map?.getLayers();
|
||||
@@ -131,7 +151,7 @@ const Map: Component = () => {
|
||||
}
|
||||
});
|
||||
|
||||
onMount(() => {
|
||||
onMount(async () => {
|
||||
olUseGeographic();
|
||||
|
||||
const changeListener = (event: any) => {
|
||||
|
||||
Reference in new issue
Block a user