Skip to content

Commit

Permalink
Parse road speed limits. Display in popups for now. #51
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Dec 28, 2024
1 parent 368be23 commit 86d9446
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions backend/src/map_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ pub struct Road {
pub node2: osm_reader::NodeID,
pub linestring: LineString,
pub tags: Tags,
pub speed_mph: Option<f64>,
}

pub struct Intersection {
Expand Down Expand Up @@ -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());
Expand Down
16 changes: 16 additions & 0 deletions backend/src/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<f64> {
let maxspeed = tags.get("maxspeed")?;
if let Ok(kmph) = maxspeed.parse::<f64>() {
return Some(kmph * 0.621371);
}
if let Some(mph) = maxspeed
.strip_suffix(" mph")
.and_then(|x| x.parse::<f64>().ok())
{
return Some(mph);
}
None
}
3 changes: 3 additions & 0 deletions web/src/edit/NeighbourhoodMode.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,9 @@
<Popup openOn="hover" let:props>
<p>
{props.shortcuts} shortcuts through {props.name ?? "unnamed road"}
{#if props.speed_mph}
({Math.round(props.speed_mph)} mph)
{/if}
</p>
{#if action == "filter"}
<div>
Expand Down

0 comments on commit 86d9446

Please sign in to comment.