Skip to content

Commit d328af5

Browse files
committed
Don't reload route snapper when loading a savefile
1 parent ef8cb8f commit d328af5

File tree

5 files changed

+26
-35
lines changed

5 files changed

+26
-35
lines changed

web/src/App.svelte

+2-23
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<script lang="ts">
2-
import initLtn, { LTN } from "backend";
2+
import initLtn from "backend";
33
import type { Map } from "maplibre-gl";
44
import initRouteSnapper from "route-snapper";
55
import { onMount } from "svelte";
66
import { FillLayer, GeoJSON, MapLibre } from "svelte-maplibre";
77
import { Layout } from "./common";
8-
import { RouteTool } from "./common/snapper/route_tool";
98
import DebugMode from "./DebugMode.svelte";
109
import NeighbourhoodMode from "./edit/NeighbourhoodMode.svelte";
1110
import NetworkMode from "./NetworkMode.svelte";
@@ -42,29 +41,13 @@
4241
mapStore.set(map);
4342
}
4443
45-
// TODO Move stuff like this out...
46-
let route_tool: RouteTool | undefined = undefined;
4744
function zoomToFit() {
4845
$mapStore!.fitBounds(
4946
Array.from($app!.getBounds()) as [number, number, number, number],
5047
{ animate: false }
5148
);
5249
}
5350
54-
// TODO Can we make the title screen mode do this?
55-
function gotApp(_x: LTN | null) {
56-
if (!$app) {
57-
return;
58-
}
59-
console.log("New map model loaded");
60-
zoomToFit();
61-
$mode = {
62-
mode: "network",
63-
};
64-
route_tool = new RouteTool($mapStore!, $app.toRouteSnapper());
65-
}
66-
$: gotApp($app);
67-
6851
let sidebarDiv: HTMLDivElement;
6952
let mapDiv: HTMLDivElement;
7053
$: if (sidebarDiv && $sidebarContents) {
@@ -114,11 +97,7 @@
11497
{#if $mode.mode == "network"}
11598
<NetworkMode />
11699
{:else if $mode.mode == "set-boundary"}
117-
<SetBoundaryMode
118-
{route_tool}
119-
name={$mode.name}
120-
existing={$mode.existing}
121-
/>
100+
<SetBoundaryMode name={$mode.name} existing={$mode.existing} />
122101
{:else if $mode.mode == "neighbourhood"}
123102
<NeighbourhoodMode />
124103
{:else if $mode.mode == "view-shortcuts"}

web/src/NetworkMode.svelte

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
function resetTitle() {
1717
$mode = { mode: "title" };
1818
$app = null;
19+
// TODO If we were being paranoid, route_tool as well
1920
}
2021
2122
function pickNeighbourhood(name: string) {

web/src/SetBoundaryMode.svelte

+10-11
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,54 @@
11
<script lang="ts">
22
import type { Feature, Polygon } from "geojson";
3-
import { RouteTool } from "./common/snapper/route_tool";
3+
import { notNull } from "./common";
44
import RouteSnapperLayer from "./common/snapper/RouteSnapperLayer.svelte";
55
import SnapPolygonControls from "./common/snapper/SnapPolygonControls.svelte";
66
import SplitComponent from "./SplitComponent.svelte";
7-
import { app, mode } from "./stores";
7+
import { app, mode, route_tool } from "./stores";
88
9-
export let route_tool: RouteTool;
109
export let name: string;
1110
export let existing: Feature<Polygon> | null;
1211
1312
if (existing) {
14-
route_tool.editExistingArea(existing);
13+
$route_tool!.editExistingArea(existing);
1514
} else {
16-
route_tool.startArea();
15+
$route_tool!.startArea();
1716
}
1817
1918
function onFailure() {
2019
$mode = {
2120
mode: "network",
2221
};
23-
route_tool.clearEventListeners();
22+
$route_tool!.clearEventListeners();
2423
}
2524
26-
route_tool.addEventListenerSuccess((feature) => {
25+
$route_tool!.addEventListenerSuccess((feature) => {
2726
try {
2827
$app!.setNeighbourhoodBoundary(name, feature);
2928
$app!.setCurrentNeighbourhood(name);
3029
$mode = {
3130
mode: "neighbourhood",
3231
};
33-
route_tool.clearEventListeners();
32+
$route_tool!.clearEventListeners();
3433
} catch (err) {
3534
window.alert(
3635
"Known georust bug hit, sorry. You may need to just refresh the page now."
3736
);
3837
onFailure();
3938
}
4039
});
41-
route_tool.addEventListenerFailure(onFailure);
40+
$route_tool!.addEventListenerFailure(onFailure);
4241
</script>
4342

4443
<SplitComponent>
4544
<div slot="sidebar">
4645
<h1>Draw your neighbourhood boundary for {name}</h1>
4746
<p>TODO: maybe move the instructions from the previous screen to here...</p>
4847

49-
<SnapPolygonControls {route_tool} />
48+
<SnapPolygonControls route_tool={notNull($route_tool)} />
5049

5150
<div>
52-
<button on:click={() => route_tool.finish()}>Finish</button>
51+
<button on:click={() => notNull($route_tool).finish()}>Finish</button>
5352
<button on:click={onFailure}>Cancel</button>
5453
</div>
5554
</div>

web/src/stores.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { LTN } from "backend";
22
import type { Feature, Polygon } from "geojson";
33
import type { Map } from "maplibre-gl";
44
import { writable, type Writable } from "svelte/store";
5+
import { RouteTool } from "./common/snapper/route_tool";
56

67
export type Mode =
78
| {
@@ -35,6 +36,7 @@ export let mutationCounter: Writable<number> = writable(1);
3536
export let mode: Writable<Mode> = writable({ mode: "title" });
3637
export let showBasemap: Writable<boolean> = writable(true);
3738
export let map: Writable<Map | null> = writable(null);
39+
export let route_tool: Writable<RouteTool | null> = writable(null);
3840

3941
export let example: Writable<string> = writable("");
4042

web/src/title/MapLoader.svelte

+11-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import { LTN } from "backend";
33
import { onMount } from "svelte";
44
import { Loading, OverpassSelector } from "../common";
5-
import { app, example, map } from "../stores";
5+
import { RouteTool } from "../common/snapper/route_tool";
6+
import { app, example, map, mode, route_tool } from "../stores";
67
78
let msg: string | null = null;
89
let useLocalVite = false;
@@ -35,6 +36,15 @@
3536
console.time("load");
3637
$app = new LTN(new Uint8Array(buffer));
3738
console.timeEnd("load");
39+
40+
$mode = {
41+
mode: "network",
42+
};
43+
$route_tool = new RouteTool($map!, $app.toRouteSnapper());
44+
$map!.fitBounds(
45+
Array.from($app.getBounds()) as [number, number, number, number],
46+
{ animate: false }
47+
);
3848
}
3949
4050
function gotXml(e: CustomEvent<string>) {

0 commit comments

Comments
 (0)