Skip to content

Commit

Permalink
Show the scores. Results are pretty meaningless, need to make the
Browse files Browse the repository at this point in the history
requests intelligently.
  • Loading branch information
dabreegster committed Dec 6, 2023
1 parent 95bf7d3 commit c8f55cc
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 21 deletions.
11 changes: 7 additions & 4 deletions backend/src/heatmap.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use geo::{Rect, GeometryCollection, BoundingRect, Geometry, LineString};
use geo::{BoundingRect, Geometry, GeometryCollection, LineString, Rect};
use geojson::{Feature, FeatureCollection};
use rand::{Rng, SeedableRng};
use rand_xorshift::XorShiftRng;
use geojson::{Feature, FeatureCollection};

use crate::{CompareRouteRequest, MapModel};

Expand All @@ -15,7 +15,7 @@ pub fn measure_randomly(map: &mut MapModel, n: usize) -> FeatureCollection {
.bounding_rect()
.unwrap();
// TODO Do this in the right coordinate space
let dist_away = 0.1;
let dist_away = 0.01;

let mut rng = XorShiftRng::seed_from_u64(42);
let mut samples = Vec::new();
Expand All @@ -42,7 +42,10 @@ pub fn measure_randomly(map: &mut MapModel, n: usize) -> FeatureCollection {
.as_f64()
.unwrap();
let score = route / direct;
let mut f = Feature::from(geojson::Geometry::from(&LineString::new(vec![(x1, y1).into(), (x2, y2).into()])));
let mut f = Feature::from(geojson::Geometry::from(&LineString::new(vec![
(x1, y1).into(),
(x2, y2).into(),
])));
f.set_property("score", score);
samples.push(f);
}
Expand Down
51 changes: 34 additions & 17 deletions web/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
import Loading from "./Loading.svelte";
import NetworkLayer from "./NetworkLayer.svelte";
import RouteLayer from "./RouteLayer.svelte";
import ScoreLayer from "./ScoreLayer.svelte";
let model: MapModel | undefined = undefined;
let map;
let loading = false;
let mode = "route";
let route_a = null;
let route_b = null;
let route_gj = null;
Expand Down Expand Up @@ -93,21 +96,31 @@
<input bind:this={fileInput} on:change={loadFile} type="file" />
</label>
<div><button on:click={zoomToFit}>Zoom to fit</button></div>
<Legend
rows={[
["Footway (ground, outdoors)", "red"],
["Indoors footway", "blue"],
["Footway not on the ground", "purple"],
["Street with sidewalk (or pedestrian street)", "black"],
["Crossing", "green"],
["Severance", "orange"],
]}
/>
{#if route_err}
<p>{route_err}</p>
{/if}
{#if route_gj}
<Directions {route_gj} />

<label>
<input bind:group={mode} type="radio" value="route" />Route
</label>
<label>
<input bind:group={mode} type="radio" value="score" />Score
</label>

{#if mode == "route"}
<Legend
rows={[
["Footway (ground, outdoors)", "red"],
["Indoors footway", "blue"],
["Footway not on the ground", "purple"],
["Street with sidewalk (or pedestrian street)", "black"],
["Crossing", "green"],
["Severance", "orange"],
]}
/>
{#if route_err}
<p>{route_err}</p>
{/if}
{#if route_gj}
<Directions {route_gj} />
{/if}
{/if}
</div>
<div slot="main" style="position:relative; width: 100%; height: 100vh;">
Expand All @@ -118,8 +131,12 @@
bind:map
>
{#if model}
<NetworkLayer {model} />
<RouteLayer bind:route_a bind:route_b {route_gj} />
{#if mode == "route"}
<NetworkLayer {model} />
<RouteLayer bind:route_a bind:route_b {route_gj} />
{:else if mode == "score"}
<ScoreLayer {model} />
{/if}
{/if}
</MapLibre>
</div>
Expand Down
19 changes: 19 additions & 0 deletions web/src/ScoreLayer.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<script lang="ts">
import { GeoJSON, LineLayer, Popup } from "svelte-maplibre";
export let model;
</script>

<GeoJSON data={JSON.parse(model.makeHeatmap())}>
<LineLayer
id="scores"
paint={{
"line-width": 5,
"line-color": "red",
}}
>
<Popup openOn="hover" let:data
>{@html JSON.stringify(data.properties, null, "<br />")}</Popup
>
</LineLayer>
</GeoJSON>

0 comments on commit c8f55cc

Please sign in to comment.