Skip to content

Commit bb36aaa

Browse files
committed
Same for one-destination impact mode
1 parent 3aafdca commit bb36aaa

File tree

3 files changed

+44
-23
lines changed

3 files changed

+44
-23
lines changed

backend/src/map_model.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -517,9 +517,9 @@ impl MapModel {
517517
// main_road_penalty doesn't seem relevant for this question
518518
self.rebuild_router(1.0);
519519

520-
// From every road, calculate the time before and after to the one destination
520+
// From every road, calculate the route before and after to the one destination
521521
let mut features = Vec::new();
522-
let mut highest_ratio: f64 = 1.0;
522+
let mut highest_time_ratio: f64 = 1.0;
523523
for r in from {
524524
let road = self.get_r(r);
525525
let pt1 = road.linestring.line_interpolate_point(0.5).unwrap().into();
@@ -529,26 +529,23 @@ impl MapModel {
529529
self.router_before_with_penalty
530530
.as_ref()
531531
.unwrap()
532-
.route(self, pt1, pt2)
533-
.map(|route| route.to_linestring(self)),
534-
self.router_after
535-
.as_ref()
536-
.unwrap()
537-
.route(self, pt1, pt2)
538-
.map(|route| route.to_linestring(self)),
532+
.route(self, pt1, pt2),
533+
self.router_after.as_ref().unwrap().route(self, pt1, pt2),
539534
) {
540535
let from_pt = self.mercator.pt_to_wgs84(pt1);
541-
let distance_before = before.length::<Euclidean>();
542-
let distance_after = after.length::<Euclidean>();
536+
let (distance_before, time_before) = before.get_distance_and_time(self);
537+
let (distance_after, time_after) = after.get_distance_and_time(self);
543538

544539
let mut f = self.mercator.to_wgs84_gj(&road.linestring);
545540
f.set_property("distance_before", distance_before);
546541
f.set_property("distance_after", distance_after);
542+
f.set_property("time_before", time_before);
543+
f.set_property("time_after", time_after);
547544
f.set_property("pt1_x", from_pt.x);
548545
f.set_property("pt1_y", from_pt.y);
549546
features.push(f);
550547

551-
highest_ratio = highest_ratio.max(distance_after / distance_before);
548+
highest_time_ratio = highest_time_ratio.max(time_after / time_before);
552549
}
553550
}
554551

@@ -557,7 +554,7 @@ impl MapModel {
557554
bbox: None,
558555
foreign_members: Some(
559556
serde_json::json!({
560-
"highest_ratio": highest_ratio,
557+
"highest_time_ratio": highest_time_ratio,
561558
})
562559
.as_object()
563560
.unwrap()

web/src/ImpactOneDestinationMode.svelte

+23-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,13 @@
99
} from "svelte-utils/map";
1010
import { SplitComponent } from "svelte-utils/top_bar_layout";
1111
import BackButton from "./BackButton.svelte";
12-
import { DotMarker, layerId, Link } from "./common";
12+
import {
13+
DotMarker,
14+
layerId,
15+
Link,
16+
prettyPrintDistance,
17+
prettyPrintTime,
18+
} from "./common";
1319
import { ModalFilterLayer, RenderNeighbourhood } from "./layers";
1420
import {
1521
backend,
@@ -81,10 +87,9 @@
8187

8288
<p>
8389
This shows the change in driving time to one destination from everywhere
84-
within the neighbourhood. Drag the pin aroun to change that destination.
90+
within the neighbourhood. Drag the pin around to change that destination.
8591
</p>
86-
<p>TODO: It's just distance right now, not time</p>
87-
<p>Highest ratio is {perRoadGj.highest_ratio.toFixed(1)}</p>
92+
<p>Highest ratio is {perRoadGj.highest_time_ratio.toFixed(1)}</p>
8893
</div>
8994

9095
<div slot="map">
@@ -106,10 +111,10 @@
106111
"line-color": [
107112
"interpolate-hcl",
108113
["linear"],
109-
["/", ["get", "distance_after"], ["get", "distance_before"]],
114+
["/", ["get", "time_after"], ["get", "time_before"]],
110115
1,
111116
"white",
112-
Math.max(perRoadGj.highest_ratio, 1.1),
117+
Math.max(perRoadGj.highest_time_ratio, 1.1),
113118
"red",
114119
],
115120
"line-width": 5,
@@ -119,14 +124,25 @@
119124
bind:hovered
120125
>
121126
<Popup openOn="hover" let:props>
122-
Ratio {(props.distance_after / props.distance_before).toFixed(1)}
127+
<p>
128+
{prettyPrintDistance(props.distance_before)}, {prettyPrintTime(
129+
props.time_before,
130+
)} before
131+
</p>
132+
<p>
133+
{prettyPrintDistance(props.distance_after)}, {prettyPrintTime(
134+
props.time_after,
135+
)} after
136+
</p>
137+
<p>Time ratio: {(props.time_after / props.time_before).toFixed(1)}</p>
123138
</Popup>
124139
</LineLayer>
125140
</GeoJSON>
126141

127142
<GeoJSON data={routeGj}>
128143
<LineLayer
129144
{...layerId("compare-route")}
145+
interactive={false}
130146
paint={{
131147
"line-width": 10,
132148
"line-color": constructMatchExpression(

web/src/wasm.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -144,9 +144,17 @@ export class Backend {
144144
);
145145
}
146146

147-
impactToOneDestination(
148-
pt: LngLat,
149-
): FeatureCollection & { highest_ratio: number } {
147+
impactToOneDestination(pt: LngLat): FeatureCollection<
148+
LineString,
149+
{
150+
distance_before: number;
151+
distance_after: number;
152+
time_before: number;
153+
time_after: number;
154+
pt1_x: number;
155+
pt1_y: number;
156+
}
157+
> & { highest_time_ratio: number } {
150158
return JSON.parse(this.inner.impactToOneDestination(pt.lng, pt.lat));
151159
}
152160

0 commit comments

Comments
 (0)