Skip to content

Commit 5d52ae1

Browse files
committed
Improve shortcut mode: show chosen road, pick different, get rid of
confusing spider map
1 parent 07b653a commit 5d52ae1

File tree

1 file changed

+39
-39
lines changed

1 file changed

+39
-39
lines changed

web/src/ViewShortcutsMode.svelte

+39-39
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<script lang="ts">
2-
import type { FeatureCollection } from "geojson";
2+
import type { Feature, FeatureCollection } from "geojson";
33
import { onDestroy, onMount } from "svelte";
44
import { GeoJSON, LineLayer } from "svelte-maplibre";
55
import { notNull, Popup } from "./common";
@@ -14,24 +14,24 @@
1414
}
1515
| {
1616
state: "chose-road";
17-
road: number;
17+
roadGj: Feature;
1818
gj: FeatureCollection;
19-
shortcutIndex: number | null;
19+
shortcutIndex: number;
2020
};
2121
let state: State = { state: "neutral" };
2222
23-
function choseRoad(road: number) {
24-
let gj = JSON.parse($app!.getShortcutsCrossingRoad(road));
23+
function choseRoad(roadGj: Feature) {
24+
let gj = JSON.parse($app!.getShortcutsCrossingRoad(roadGj.properties!.id));
2525
if (gj.features.length == 0) {
2626
window.alert("No shortcuts here");
2727
return;
2828
}
2929
3030
state = {
3131
state: "chose-road",
32-
road,
32+
roadGj,
3333
gj,
34-
shortcutIndex: null,
34+
shortcutIndex: 0,
3535
};
3636
}
3737
@@ -44,15 +44,13 @@
4444
4545
function onKeyDown(e: KeyboardEvent) {
4646
if (state.state == "chose-road") {
47-
if (e.key == "ArrowLeft" && state.shortcutIndex) {
47+
if (e.key == "ArrowLeft" && state.shortcutIndex > 0) {
4848
e.stopPropagation();
4949
state.shortcutIndex--;
5050
}
5151
if (e.key == "ArrowRight") {
5252
e.stopPropagation();
53-
if (state.shortcutIndex == null) {
54-
state.shortcutIndex = 0;
55-
} else if (state.shortcutIndex != state.gj.features.length - 1) {
53+
if (state.shortcutIndex != state.gj.features.length - 1) {
5654
state.shortcutIndex++;
5755
}
5856
}
@@ -69,14 +67,13 @@
6967
7068
function prev() {
7169
if (state.state == "chose-road") {
72-
state.shortcutIndex!--;
70+
state.shortcutIndex--;
7371
}
7472
}
7573
7674
function next() {
7775
if (state.state == "chose-road") {
78-
state.shortcutIndex =
79-
state.shortcutIndex == null ? 0 : state.shortcutIndex + 1;
76+
state.shortcutIndex++;
8077
}
8178
}
8279
</script>
@@ -91,13 +88,15 @@
9188
<p>Click a road to see shortcuts</p>
9289
{:else if state.state == "chose-road"}
9390
<div>
94-
<button
95-
disabled={state.shortcutIndex == null || state.shortcutIndex == 0}
96-
on:click={prev}
91+
<button on:click={() => (state = { state: "neutral" })}
92+
>Pick a different road</button
9793
>
94+
</div>
95+
<div>
96+
<button disabled={state.shortcutIndex == 0} on:click={prev}>
9897
Prev
9998
</button>
100-
{state.shortcutIndex} / {state.gj.features.length}
99+
{state.shortcutIndex + 1} / {state.gj.features.length}
101100
<button
102101
disabled={state.shortcutIndex == state.gj.features.length - 1}
103102
on:click={next}
@@ -112,32 +111,33 @@
112111
{#if state.state == "neutral"}
113112
<RenderNeighbourhood
114113
gjInput={JSON.parse(notNull($app).renderNeighbourhood())}
115-
onClickLine={(f) => choseRoad(notNull(f.properties).id)}
114+
onClickLine={choseRoad}
116115
>
117116
<div slot="line-popup">
118-
<Popup openOn="hover" let:props>{props.shortcuts}</Popup>
117+
<Popup openOn="hover" let:props>
118+
<p>
119+
{props.shortcuts} shortcuts through {props.name ?? "unnamed road"}
120+
</p>
121+
</Popup>
119122
</div>
120123
</RenderNeighbourhood>
121124
{:else if state.state == "chose-road"}
122-
{#if state.shortcutIndex == null}
123-
<GeoJSON data={state.gj}>
124-
<LineLayer
125-
paint={{
126-
"line-width": 5,
127-
"line-color": "red",
128-
}}
129-
/>
130-
</GeoJSON>
131-
{:else}
132-
<GeoJSON data={state.gj.features[state.shortcutIndex]}>
133-
<LineLayer
134-
paint={{
135-
"line-width": 5,
136-
"line-color": "red",
137-
}}
138-
/>
139-
</GeoJSON>
140-
{/if}
125+
<GeoJSON data={state.gj.features[state.shortcutIndex]}>
126+
<LineLayer
127+
paint={{
128+
"line-width": 5,
129+
"line-color": "red",
130+
}}
131+
/>
132+
</GeoJSON>
133+
<GeoJSON data={state.roadGj}>
134+
<LineLayer
135+
paint={{
136+
"line-width": 5,
137+
"line-color": "blue",
138+
}}
139+
/>
140+
</GeoJSON>
141141
{/if}
142142
<ModalFilterLayer />
143143
</div>

0 commit comments

Comments
 (0)