diff --git a/backend/src/map_model.rs b/backend/src/map_model.rs index 8ad0353..201d9d5 100644 --- a/backend/src/map_model.rs +++ b/backend/src/map_model.rs @@ -76,6 +76,7 @@ pub struct Road { pub node2: osm_reader::NodeID, pub linestring: LineString, pub tags: Tags, + pub speed_mph: Option, } pub struct Intersection { @@ -571,6 +572,7 @@ impl Road { let mut f = mercator.to_wgs84_gj(&self.linestring); // TODO Most of this is debug only f.set_property("id", self.id.0); + f.set_property("speed_mph", self.speed_mph); f.set_property("way", self.way.to_string()); f.set_property("node1", self.node1.to_string()); f.set_property("node2", self.node2.to_string()); diff --git a/backend/src/scrape.rs b/backend/src/scrape.rs index b762ced..2d0773a 100644 --- a/backend/src/scrape.rs +++ b/backend/src/scrape.rs @@ -114,6 +114,7 @@ pub fn scrape_osm( node1: e.osm_node1, node2: e.osm_node2, linestring: e.linestring, + speed_mph: parse_maxspeed_mph(&e.osm_tags), tags: e.osm_tags, }) .collect(); @@ -287,3 +288,18 @@ fn is_road(tags: &Tags) -> bool { } true } + +// TODO Look at muv for something more rigorous +fn parse_maxspeed_mph(tags: &Tags) -> Option { + let maxspeed = tags.get("maxspeed")?; + if let Ok(kmph) = maxspeed.parse::() { + return Some(kmph * 0.621371); + } + if let Some(mph) = maxspeed + .strip_suffix(" mph") + .and_then(|x| x.parse::().ok()) + { + return Some(mph); + } + None +} diff --git a/web/src/edit/NeighbourhoodMode.svelte b/web/src/edit/NeighbourhoodMode.svelte index 0d5b979..cef1399 100644 --- a/web/src/edit/NeighbourhoodMode.svelte +++ b/web/src/edit/NeighbourhoodMode.svelte @@ -295,6 +295,9 @@

{props.shortcuts} shortcuts through {props.name ?? "unnamed road"} + {#if props.speed_mph} + ({Math.round(props.speed_mph)} mph) + {/if}

{#if action == "filter"}