fix(routes): store routing graph/pois as plain vars (not $state proxies) so they structured-clone into the Web Worker
All checks were successful
CI / test-and-build (push) Successful in 42s
All checks were successful
CI / test-and-build (push) Successful in 42s
This commit is contained in:
parent
4de3e31708
commit
c3e3617794
@ -79,8 +79,13 @@
|
|||||||
let computingRoute = $state(false);
|
let computingRoute = $state(false);
|
||||||
savedPoints.subscribe((pts) => { savedPointsList = pts; });
|
savedPoints.subscribe((pts) => { savedPointsList = pts; });
|
||||||
// --- route graph + POIs loaded from a dump layer (for directions) ---
|
// --- route graph + POIs loaded from a dump layer (for directions) ---
|
||||||
let routeGraph = $state<RouteGraph | null>(null);
|
// NOTE: keep the graph/POI data as PLAIN (non-$state) variables. $state wraps
|
||||||
let routePois = $state<GeoJSON.Feature[]>([]);
|
// values in Svelte 5 proxies, which cannot be structured-cloned into a Web
|
||||||
|
// Worker ("Proxy object could not be cloned"). These are read-only inputs to
|
||||||
|
// the worker; `hasRouteGraph` drives the UI instead.
|
||||||
|
let routeGraph: RouteGraph | null = null;
|
||||||
|
let routePois: GeoJSON.Feature[] = [];
|
||||||
|
let hasRouteGraph = $state(false);
|
||||||
let routeLoading = $state(false);
|
let routeLoading = $state(false);
|
||||||
let routeProgress = $state(0);
|
let routeProgress = $state(0);
|
||||||
let graphLabel = $derived(dumpLayers[0]?.label ?? '');
|
let graphLabel = $derived(dumpLayers[0]?.label ?? '');
|
||||||
@ -176,7 +181,7 @@
|
|||||||
async function loadRouteGraph(fresh = false) {
|
async function loadRouteGraph(fresh = false) {
|
||||||
if ((routeGraph && !fresh) || routeLoading) return;
|
if ((routeGraph && !fresh) || routeLoading) return;
|
||||||
const layer = dumpLayers[0];
|
const layer = dumpLayers[0];
|
||||||
if (!layer || !layer.graphPath || !layer.poiPath) { routeGraph = null; return; }
|
if (!layer || !layer.graphPath || !layer.poiPath) { routeGraph = null; hasRouteGraph = false; return; }
|
||||||
routeLoading = true;
|
routeLoading = true;
|
||||||
try {
|
try {
|
||||||
const [g, p] = await Promise.all([fetch(layer.graphPath), fetch(layer.poiPath)]);
|
const [g, p] = await Promise.all([fetch(layer.graphPath), fetch(layer.poiPath)]);
|
||||||
@ -185,8 +190,10 @@
|
|||||||
routeGraph = await g.json();
|
routeGraph = await g.json();
|
||||||
const pc: { features: GeoJSON.Feature[] } = await p.json();
|
const pc: { features: GeoJSON.Feature[] } = await p.json();
|
||||||
routePois = pc.features;
|
routePois = pc.features;
|
||||||
|
hasRouteGraph = true;
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
routeGraph = null;
|
routeGraph = null;
|
||||||
|
hasRouteGraph = false;
|
||||||
console.warn('route graph load failed:', e);
|
console.warn('route graph load failed:', e);
|
||||||
} finally {
|
} finally {
|
||||||
routeLoading = false;
|
routeLoading = false;
|
||||||
@ -620,7 +627,7 @@
|
|||||||
<DirectionsPanel
|
<DirectionsPanel
|
||||||
{map}
|
{map}
|
||||||
origin={origin}
|
origin={origin}
|
||||||
hasGraph={!!routeGraph}
|
hasGraph={hasRouteGraph}
|
||||||
graphLabel={graphLabel}
|
graphLabel={graphLabel}
|
||||||
onLoadGraph={() => loadRouteGraph(true)}
|
onLoadGraph={() => loadRouteGraph(true)}
|
||||||
graphLoading={routeLoading}
|
graphLoading={routeLoading}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user