Skip to content

Commit e99bfc0

Browse files
committed
Start a mode to debug movements per intersection. No logic yet.
1 parent bb36aaa commit e99bfc0

File tree

8 files changed

+124
-0
lines changed

8 files changed

+124
-0
lines changed

backend/src/lib.rs

+20
Original file line numberDiff line numberDiff line change
@@ -320,6 +320,26 @@ impl LTN {
320320
.map_err(err_to_js)?)
321321
}
322322

323+
#[wasm_bindgen(js_name = getAllIntersections)]
324+
pub fn get_all_intersections(&self) -> Result<String, JsValue> {
325+
Ok(serde_json::to_string(&GeoJson::from(
326+
self.map
327+
.intersections
328+
.iter()
329+
.map(|i| self.map.mercator.to_wgs84_gj(&i.point))
330+
.collect::<Vec<_>>(),
331+
))
332+
.map_err(err_to_js)?)
333+
}
334+
335+
#[wasm_bindgen(js_name = getMovements)]
336+
pub fn get_movements(&self, intersection: usize) -> Result<String, JsValue> {
337+
Ok(
338+
serde_json::to_string(&self.map.get_movements(IntersectionID(intersection)))
339+
.map_err(err_to_js)?,
340+
)
341+
}
342+
323343
// TODO This is also internal to MapModel. But not sure who should own Neighbourhood or how to
324344
// plumb, so duplicting here.
325345
fn after_edit(&mut self) {

backend/src/map_model.rs

+11
Original file line numberDiff line numberDiff line change
@@ -581,6 +581,17 @@ impl MapModel {
581581
}
582582
directions
583583
}
584+
585+
pub fn get_movements(&self, i: IntersectionID) -> GeoJson {
586+
let mut features = Vec::new();
587+
588+
// TODO Temporary
589+
for r in &self.get_i(i).roads {
590+
features.push(self.mercator.to_wgs84_gj(&self.get_r(*r).linestring));
591+
}
592+
593+
GeoJson::from(features)
594+
}
584595
}
585596

586597
impl Road {

web/src/App.svelte

+3
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
} from "svelte-utils/top_bar_layout";
2525
import AutoBoundariesMode from "./AutoBoundariesMode.svelte";
2626
import { DisableInteractiveLayers, layerId, StreetView } from "./common";
27+
import DebugIntersectionsMode from "./DebugIntersectionsMode.svelte";
2728
import DebugMode from "./DebugMode.svelte";
2829
import NeighbourhoodMode from "./edit/NeighbourhoodMode.svelte";
2930
import ImpactDetailMode from "./ImpactDetailMode.svelte";
@@ -177,6 +178,8 @@
177178
<ImpactDetailMode road={$mode.road} />
178179
{:else if $mode.mode == "debug"}
179180
<DebugMode />
181+
{:else if $mode.mode == "debug-intersections"}
182+
<DebugIntersectionsMode />
180183
{/if}
181184
{/if}
182185
<DisableInteractiveLayers />

web/src/DebugIntersectionsMode.svelte

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<script lang="ts">
2+
import {
3+
CircleLayer,
4+
GeoJSON,
5+
LineLayer,
6+
type LayerClickInfo,
7+
} from "svelte-maplibre";
8+
import { notNull } from "svelte-utils";
9+
import { emptyGeojson } from "svelte-utils/map";
10+
import { SplitComponent } from "svelte-utils/top_bar_layout";
11+
import BackButton from "./BackButton.svelte";
12+
import { layerId, Link } from "./common";
13+
import { backend, mode } from "./stores";
14+
15+
let movements = emptyGeojson();
16+
17+
function pickIntersection(e: CustomEvent<LayerClickInfo>) {
18+
movements = $backend!.getMovements(e.detail.features[0].id as number);
19+
}
20+
</script>
21+
22+
<SplitComponent>
23+
<div slot="top">
24+
<nav aria-label="breadcrumb">
25+
<ul>
26+
<li>
27+
<Link on:click={() => ($mode = { mode: "title", firstLoad: false })}>
28+
Choose project
29+
</Link>
30+
</li>
31+
<li>Debug intersections</li>
32+
</ul>
33+
</nav>
34+
</div>
35+
36+
<div slot="sidebar">
37+
<BackButton on:click={() => ($mode = { mode: "network" })} />
38+
39+
{#if movements.features.length > 0}
40+
<button class="secondary" on:click={() => (movements = emptyGeojson())}>
41+
Pick another intersection
42+
</button>
43+
<p>{movements.features.length} movements</p>
44+
{/if}
45+
</div>
46+
47+
<div slot="map">
48+
<GeoJSON data={notNull($backend).getAllIntersections()} generateId>
49+
<CircleLayer
50+
{...layerId("debug-intersections")}
51+
paint={{
52+
"circle-radius": 15,
53+
"circle-color": "black",
54+
}}
55+
manageHoverState
56+
hoverCursor="pointer"
57+
on:click={pickIntersection}
58+
/>
59+
</GeoJSON>
60+
61+
<GeoJSON data={movements} generateId>
62+
<LineLayer
63+
{...layerId("debug-movements")}
64+
paint={{
65+
"line-width": 2,
66+
"line-color": "red",
67+
}}
68+
/>
69+
</GeoJSON>
70+
</div>
71+
</SplitComponent>

web/src/NetworkMode.svelte

+5
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@
123123
Predict impact
124124
</Link>
125125
</li>
126+
<li>
127+
<Link on:click={() => ($mode = { mode: "debug-intersections" })}>
128+
Debug intersections
129+
</Link>
130+
</li>
126131
</ul>
127132
</nav>
128133
</div>

web/src/common/zorder.ts

+3
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ const layerZorder = [
8686
"debug-crosses",
8787
"debug-filters",
8888

89+
"debug-intersections",
90+
"debug-movements",
91+
8992
"cells",
9093
"interior-roads-outlines",
9194
"interior-roads",

web/src/stores.ts

+3
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ export type Mode =
4545
mode: "impact-detail";
4646
road: Feature;
4747
}
48+
| {
49+
mode: "debug-intersections";
50+
}
4851
| {
4952
mode: "debug";
5053
};

web/src/wasm.ts

+8
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,14 @@ export class Backend {
175175
> {
176176
return JSON.parse(this.inner.getImpactsOnRoad(road));
177177
}
178+
179+
getAllIntersections(): FeatureCollection<Point> {
180+
return JSON.parse(this.inner.getAllIntersections());
181+
}
182+
183+
getMovements(intersection: number): FeatureCollection<LineString> {
184+
return JSON.parse(this.inner.getMovements(intersection));
185+
}
178186
}
179187

180188
export interface RenderNeighbourhoodOutput {

0 commit comments

Comments
 (0)