Skip to content

Commit

Permalink
Let users override the traffic direction. #268
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jun 7, 2024
1 parent 04cd198 commit c7c34d5
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions osm2lanes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,8 @@ pub struct MapConfig {
/// Note this is calculated by osm2streets! The value passed in is ignored; don't do any work
/// to set it.
pub driving_side: DrivingSide,
/// If set, will override the automatic calculation
pub override_driving_side: Option<DrivingSide>,
/// The [two-letter ISO country code](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) where
/// this network exists. Note osm2streets doesn't support areas that cross country boundaries.
///
Expand Down Expand Up @@ -580,6 +582,7 @@ impl MapConfig {
Self {
// Just a dummy value that'll be set later
driving_side: DrivingSide::Right,
override_driving_side: None,
country_code: String::new(),
bikes_can_use_bus_lanes: true,
inferred_sidewalks: false,
Expand Down
15 changes: 13 additions & 2 deletions osm2streets-js/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ use serde::{Deserialize, Serialize};
use wasm_bindgen::prelude::*;

use osm2streets::{
osm, DebugStreets, Filter, IntersectionID, LaneID, MapConfig, Placement, RoadID, RoadSideID,
SideOfRoad, Sidepath, StreetNetwork, Transformation,
osm, DebugStreets, DrivingSide, Filter, IntersectionID, LaneID, MapConfig, Placement, RoadID,
RoadSideID, SideOfRoad, Sidepath, StreetNetwork, Transformation,
};

static SETUP_LOGGER: Once = Once::new();
Expand All @@ -22,6 +22,7 @@ pub struct ImportOptions {
inferred_sidewalks: bool,
inferred_kerbs: bool,
date_time: Option<NaiveDateTime>,
override_driving_side: String,
}

#[wasm_bindgen]
Expand Down Expand Up @@ -62,6 +63,16 @@ impl JsStreetNetwork {
cfg.inferred_sidewalks = input.inferred_sidewalks;
cfg.inferred_kerbs = input.inferred_kerbs;
cfg.date_time = input.date_time;
cfg.override_driving_side = match input.override_driving_side.as_str() {
"" => None,
"Left" => Some(DrivingSide::Left),
"Right" => Some(DrivingSide::Right),
x => {
return Err(JsValue::from_str(&format!(
"Unknown override_driving_side = {x}"
)))
}
};

let mut timer = Timer::throwaway();
let (mut street_network, doc) =
Expand Down
6 changes: 6 additions & 0 deletions streets_reader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ pub fn osm_to_street_network(
/// Set up country code and driving side, using an arbitrary point. This must be called after
/// `gps_bounds` is set.
pub fn detect_country_code(streets: &mut StreetNetwork) {
if let Some(dir) = streets.config.override_driving_side {
info!("Ignoring country for driving side; using override {dir:?}");
streets.config.driving_side = dir;
return;
}

let geocoder = country_geocoder::CountryGeocoder::new();
let pt = streets.gps_bounds.get_rectangle()[0].into();

Expand Down
1 change: 1 addition & 0 deletions web/src/common/import/ImportControls.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
inferred_sidewalks: boolean;
inferred_kerbs: boolean;
date_time: string | undefined;
override_driving_side: string;
}
type Imported =
Expand Down
16 changes: 16 additions & 0 deletions web/src/common/import/Osm2streetsSettings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
inferred_sidewalks: false,
inferred_kerbs: true,
date_time: undefined as string | undefined,
override_driving_side: "",
};
let date_time: string;
Expand All @@ -14,24 +15,28 @@

<details>
<summary>Processing Options</summary>

<label>
<input type="checkbox" bind:checked={settings.debug_each_step} />
Debug each transformation step
</label>

<label>
<input
type="checkbox"
bind:checked={settings.dual_carriageway_experiment}
/>
Enable dual carriageway experiment
</label>

<label>
<input
type="checkbox"
bind:checked={settings.sidepath_zipping_experiment}
/>
Enable sidepath zipping experiment
</label>

<div>
Sidewalks:
<label>
Expand All @@ -51,16 +56,27 @@
infer on roads
</label>
</div>

<label>
<input type="checkbox" bind:checked={settings.inferred_kerbs} />
Infer kerbs
</label>

<div>
Change the time and date:
<label>
<input type="datetime-local" bind:value={date_time} />
</label>
</div>

<div>
Override the driving side:
<select bind:value={settings.override_driving_side}>
<option value="">Auto-detect based on country</option>
<option value="Left">Left</option>
<option value="Right">Right</option>
</select>
</div>
</details>

<style>
Expand Down

0 comments on commit c7c34d5

Please sign in to comment.