Skip to content

Commit

Permalink
Allow a callback to modify Roads before building routers
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Aug 25, 2024
1 parent b96adce commit 290eb3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion backend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,9 @@ impl MapModel {
};
let mut timer = Timer::new("build graph", progress_cb);
let mut amenities = Amenities::new();
let modify_roads = |_roads: &mut Vec<graph::Road>| {};
let graph = if is_osm {
Graph::new(input_bytes, gtfs, &mut amenities, &mut timer)
Graph::new(input_bytes, gtfs, &mut amenities, modify_roads, &mut timer)
.await
.map_err(err_to_js)?
} else {
Expand Down
13 changes: 9 additions & 4 deletions graph/src/scrape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,14 @@ use crate::{
};

impl Graph {
/// Call with bytes of an osm.pbf or osm.xml string
pub async fn new<R: utils::osm2graph::OsmReader>(
/// input_bytes: Bytes of an osm.pbf or osm.xml string
/// osm_reader: To scrape OSM elements
/// modify_roads: Runs before any routing structures are calculated. Use to modify access per mode.
pub async fn new<F: FnOnce(&mut Vec<Road>), R: utils::osm2graph::OsmReader>(
input_bytes: &[u8],
gtfs_source: GtfsSource,
reader: &mut R,
osm_reader: &mut R,
modify_roads: F,
timer: &mut Timer,
) -> Result<Graph> {
timer.step("parse OSM and split graph");
Expand All @@ -28,7 +31,7 @@ impl Graph {
|tags| {
tags.has("highway") && !tags.is("highway", "proposed") && !tags.is("area", "yes")
},
reader,
osm_reader,
)?;

timer.step("calculate road attributes");
Expand Down Expand Up @@ -69,6 +72,8 @@ impl Graph {
})
.collect();

modify_roads(&mut roads);

timer.push("build closest_road");
let closest_road = EnumMap::from_fn(|mode| {
timer.step(format!("for {mode:?}"));
Expand Down

0 comments on commit 290eb3d

Please sign in to comment.