From ae32dac12429ee5b1496df48ea414306855eadd2 Mon Sep 17 00:00:00 2001 From: Dustin Carlino Date: Fri, 5 Jan 2024 16:01:30 +0000 Subject: [PATCH] Start the skeleton route mode, but actually, just do some refactoring first --- web/src/App.svelte | 32 +++++++++++++++------- web/src/MapLoader.svelte | 7 ++--- web/src/NeighbourhoodMode.svelte | 32 +++++++++++----------- web/src/RenderNeighbourhood.svelte | 6 ++--- web/src/RouteMode.svelte | 43 ++++++++++++++++++++++++++++++ web/src/SetBoundaryMode.svelte | 18 +++++++++---- web/src/ViewShortcutsMode.svelte | 14 +++------- web/src/stores.ts | 7 ++++- 8 files changed, 109 insertions(+), 50 deletions(-) create mode 100644 web/src/RouteMode.svelte diff --git a/web/src/App.svelte b/web/src/App.svelte index d22d023..5475c18 100644 --- a/web/src/App.svelte +++ b/web/src/App.svelte @@ -7,12 +7,19 @@ import MapLoader from "./MapLoader.svelte"; import NeighbourhoodMode from "./NeighbourhoodMode.svelte"; import NetworkMode from "./NetworkMode.svelte"; + import RouteMode from "./RouteMode.svelte"; import SetBoundaryMode from "./SetBoundaryMode.svelte"; - import { app, mapContents, mode, sidebarContents } from "./stores"; + import { + app, + mapContents, + map as mapStore, + mode, + showBasemap, + sidebarContents, + } from "./stores"; import ViewShortcutsMode from "./ViewShortcutsMode.svelte"; - let showBasemap = false; - $: mapStyle = showBasemap + $: mapStyle = $showBasemap ? "https://api.maptiler.com/maps/dataviz/style.json?key=MZEJTanw3WpxRvt7qDfo" : { version: 8 as const, @@ -22,10 +29,13 @@ let route_tool: RouteTool | undefined = undefined; let map: Map; + $: if (map) { + mapStore.set(map); + } function zoomToFit() { // TODO wasteful - map.fitBounds(bbox(JSON.parse($app!.render())), { animate: false }); + $mapStore!.fitBounds(bbox(JSON.parse($app!.render())), { animate: false }); } function gotApp(_x: LTN | null) { @@ -37,7 +47,7 @@ $mode = { mode: "network", }; - route_tool = new RouteTool(map, $app.toRouteSnapper()); + route_tool = new RouteTool($mapStore!, $app.toRouteSnapper()); } $: gotApp($app); @@ -55,15 +65,15 @@
- {#if map} - + {#if $mapStore} + {#if $app}
{/if} {/if}
Show basemap

@@ -85,9 +95,11 @@ {:else if $mode.mode == "set-boundary"} {:else if $mode.mode == "neighbourhood"} - + {:else if $mode.mode == "view-shortcuts"} - + + {:else if $mode.mode == "route"} + {/if} {/if} diff --git a/web/src/MapLoader.svelte b/web/src/MapLoader.svelte index fa9c552..59e5d47 100644 --- a/web/src/MapLoader.svelte +++ b/web/src/MapLoader.svelte @@ -1,13 +1,10 @@ + + + + +
+
+ +

Drag markers for a route

+
+ +
+ +
+
diff --git a/web/src/SetBoundaryMode.svelte b/web/src/SetBoundaryMode.svelte index 8389adc..c3dae32 100644 --- a/web/src/SetBoundaryMode.svelte +++ b/web/src/SetBoundaryMode.svelte @@ -15,11 +15,19 @@ } route_tool.addEventListenerSuccess((feature) => { - $app!.setNeighbourhood(feature); - $mode = { - mode: "neighbourhood", - }; - route_tool.clearEventListeners(); + try { + $app!.setNeighbourhood(feature); + $mode = { + mode: "neighbourhood", + }; + route_tool.clearEventListeners(); + } catch (err) { + window.alert("Known georust bug hit, sorry"); + $mode = { + mode: "network", + }; + route_tool.clearEventListeners(); + } }); route_tool.addEventListenerFailure(() => { $mode = { diff --git a/web/src/ViewShortcutsMode.svelte b/web/src/ViewShortcutsMode.svelte index 8b5d2a1..c879959 100644 --- a/web/src/ViewShortcutsMode.svelte +++ b/web/src/ViewShortcutsMode.svelte @@ -1,15 +1,10 @@ @@ -102,7 +97,6 @@ {#if state.state == "neutral"} choseRoad(f.properties.id)} >
diff --git a/web/src/stores.ts b/web/src/stores.ts index 52670e7..d299e51 100644 --- a/web/src/stores.ts +++ b/web/src/stores.ts @@ -1,5 +1,6 @@ import { LTN } from "backend"; import type { Feature, Polygon } from "geojson"; +import type { Map } from "maplibre-gl"; import { writable, type Writable } from "svelte/store"; export type Mode = @@ -15,11 +16,15 @@ export type Mode = } | { mode: "view-shortcuts"; - prevMode: Mode; + } + | { + mode: "route"; }; export let app: Writable = writable(null); export let mode: Writable = writable({ mode: "network" }); +export let showBasemap: Writable = writable(false); +export let map: Writable = writable(null); export let sidebarContents: Writable = writable(null); export let mapContents: Writable = writable(null);