-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
View shortcuts per road... a start. The backend part is trivial to
write, the frontend revisits a bunch of problems. Start with something kind of working but very verbose.
- Loading branch information
1 parent
ceb02e4
commit 08c662a
Showing
8 changed files
with
208 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<script lang="ts"> | ||
import { LTN } from "backend"; | ||
import { GeoJSON, LineLayer } from "svelte-maplibre"; | ||
import { choseRoad, state } from "./stores"; | ||
export let app: LTN; | ||
</script> | ||
|
||
{#if $state.state == "neutral"} | ||
<GeoJSON data={JSON.parse(app.render())}> | ||
<LineLayer | ||
paint={{ | ||
"line-width": 5, | ||
"line-color": "black", | ||
}} | ||
on:click={(e) => choseRoad(app, e.detail.features[0].properties.id)} | ||
hoverCursor="pointer" | ||
/> | ||
</GeoJSON> | ||
{:else if $state.state == "chose-road"} | ||
{#if $state.shortcutIndex == null} | ||
<GeoJSON data={$state.gj}> | ||
<LineLayer | ||
paint={{ | ||
"line-width": 5, | ||
"line-color": "red", | ||
}} | ||
/> | ||
</GeoJSON> | ||
{:else} | ||
<GeoJSON data={$state.gj.features[$state.shortcutIndex]}> | ||
<LineLayer | ||
paint={{ | ||
"line-width": 5, | ||
"line-color": "red", | ||
}} | ||
/> | ||
</GeoJSON> | ||
{/if} | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<script lang="ts"> | ||
import type { Map } from "maplibre-gl"; | ||
import { onDestroy, onMount } from "svelte"; | ||
import { state } from "./stores"; | ||
export let mode: Mode; | ||
export let app: LTN; | ||
export let prevMode: Mode; | ||
export let map: Map; | ||
// Initially set this | ||
$state = { state: "neutral" }; | ||
onMount(() => { | ||
map.keyboard.disable(); | ||
}); | ||
onDestroy(() => { | ||
map.keyboard.enable(); | ||
}); | ||
function onKeyDown(e: KeyboardEvent) { | ||
if ($state.state == "chose-road") { | ||
if (e.key == "ArrowLeft" && $state.shortcutIndex != 0) { | ||
e.stopPropagation(); | ||
$state.shortcutIndex--; | ||
} | ||
if (e.key == "ArrowRight") { | ||
e.stopPropagation(); | ||
if ($state.shortcutIndex == null) { | ||
$state.shortcutIndex = 0; | ||
} else if ($state.shortcutIndex != $state.gj.features.length - 1) { | ||
$state.shortcutIndex++; | ||
} | ||
} | ||
} | ||
} | ||
function back() { | ||
mode = prevMode; | ||
} | ||
</script> | ||
|
||
<svelte:window on:keydown={onKeyDown} /> | ||
|
||
<div><button on:click={back}>Back to editing</button></div> | ||
|
||
{#if $state.state == "neutral"} | ||
<p>Click a road to see shortcuts</p> | ||
{:else if $state.state == "chose-road"} | ||
<div> | ||
<button | ||
disabled={$state.shortcutIndex == null || $state.shortcutIndex == 0} | ||
on:click={() => $state.shortcutIndex--} | ||
> | ||
Prev | ||
</button> | ||
{$state.shortcutIndex} / {$state.gj.features.length} | ||
<button | ||
disabled={$state.shortcutIndex == $state.gj.features.length - 1} | ||
on:click={() => $state.shortcutIndex++} | ||
> | ||
Next | ||
</button> | ||
</div> | ||
{/if} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { LTN } from "backend"; | ||
import { writable, type Writable } from "svelte/store"; | ||
|
||
export type State = | ||
| { | ||
state: "neutral"; | ||
} | ||
| { | ||
state: "chose-road"; | ||
road: number; | ||
gj: FeatureCollection; | ||
shortcutIndex: number | null; | ||
}; | ||
|
||
export let state: Writable<State> = writable({ state: "neutral" }); | ||
|
||
export function choseRoad(app: LTN, road: number) { | ||
let gj = JSON.parse(app.getShortcutsCrossingRoad(road)); | ||
if (gj.features.length == 0) { | ||
window.alert("No shortcuts here"); | ||
return; | ||
} | ||
|
||
state.set({ | ||
state: "chose-road", | ||
road, | ||
gj, | ||
shortcutIndex: null, | ||
}); | ||
} |