Add a tool to export a road to streetmix. Untested, because still having trouble making manual API calls.

This commit is contained in:
Dustin Carlino 2020-10-22 16:29:42 -07:00
parent 058103b84f
commit 4a3ea8b5c7
4 changed files with 81 additions and 1 deletions

View File

@ -23,6 +23,7 @@ mod objects;
pub mod path_counter; pub mod path_counter;
mod polygons; mod polygons;
pub mod shared_row; pub mod shared_row;
pub mod streetmix;
pub struct DebugMode { pub struct DebugMode {
panel: Panel, panel: Panel,

View File

@ -3,7 +3,7 @@ use geojson::{Feature, FeatureCollection, GeoJson, Geometry, Value};
use map_model::{Direction, Lane, LaneType, Map, RoadID}; use map_model::{Direction, Lane, LaneType, Map, RoadID};
// Exports to https://github.com/d-wasserman/shared-row/, returns the filename /// Exports to https://github.com/d-wasserman/shared-row/, returns the filename
pub fn export(roads: Vec<RoadID>, map: &Map) -> String { pub fn export(roads: Vec<RoadID>, map: &Map) -> String {
let path = format!( let path = format!(
"shared_row_export_{}.json", "shared_row_export_{}.json",

View File

@ -0,0 +1,63 @@
use map_model::{Direction, Lane, LaneType, Map, RoadID};
/// Exports a single road to Streetmix's format, returns the filename
pub fn export(r: RoadID, map: &Map) -> String {
let path = format!("streetmix_export_{}.json", r.0);
let street = road(r, map);
abstutil::write_json(path.clone(), &street);
path
}
fn road(id: RoadID, map: &Map) -> serde_json::Map<String, serde_json::value::Value> {
let r = map.get_r(id);
let mut street = serde_json::Map::new();
street.insert("schemaVersion".to_string(), 24.into());
// TODO Many more fields
let mut segments = Vec::new();
for (l, dir, _) in r.lanes_ltr() {
segments.push(serde_json::value::Value::Object(lane(map.get_l(l), dir)));
}
street.insert(
"segments".to_string(),
serde_json::value::Value::Array(segments),
);
street
}
fn lane(lane: &Lane, dir: Direction) -> serde_json::Map<String, serde_json::value::Value> {
let mut segment = serde_json::Map::new();
segment.insert("id".to_string(), lane.id.to_string().into());
segment.insert("width".to_string(), lane.width.inner_meters().into());
// TODO I'm taking wild stabs at these values for now. Once I can visualize the results, will
// iterate on these.
let (segment_type, variant) = match lane.lane_type {
LaneType::Driving => match dir {
Direction::Fwd => ("drive-lane", "inbound|car"),
Direction::Back => ("drive-lane", "outbound|car"),
},
LaneType::Parking => match dir {
Direction::Fwd => ("parking-lane", "inbound|left"),
Direction::Back => ("parking-lane", "outbound|right"),
},
LaneType::Sidewalk => ("sidewalk", "dense"),
LaneType::Shoulder => ("sidewalk", "dense"),
LaneType::Biking => match dir {
Direction::Fwd => ("bike-lane", "inbound|green|road"),
Direction::Back => ("bike-lane", "outbound|green|road"),
},
LaneType::Bus => match dir {
Direction::Fwd => ("bus-lane", "inbound|shared"),
Direction::Back => ("bus-lane", "outbound|shared"),
},
LaneType::SharedLeftTurn => ("TODO", "TODO"),
LaneType::Construction => ("TODO", "TODO"),
LaneType::LightRail => ("TODO", "TODO"),
};
segment.insert("type".to_string(), segment_type.into());
segment.insert("variant".to_string(), variant.into());
segment
}

View File

@ -44,6 +44,7 @@ fn make_select_panel(ctx: &mut EventCtx, selector: &RoadSelector) -> Panel {
selector.roads.len() selector.roads.len()
)) ))
.build(ctx, "export roads to shared-row", None), .build(ctx, "export roads to shared-row", None),
Btn::text_fg("export one road to Streetmix").build_def(ctx, None),
Btn::text_fg("Cancel").build_def(ctx, Key::Escape), Btn::text_fg("Cancel").build_def(ctx, Key::Escape),
]) ])
.evenly_spaced(), .evenly_spaced(),
@ -77,6 +78,21 @@ impl State for BulkSelect {
vec![format!("Roads exported to shared-row format at {}", path)], vec![format!("Roads exported to shared-row format at {}", path)],
)); ));
} }
"export one road to Streetmix" => {
let path = crate::debug::streetmix::export(
*self.selector.roads.iter().next().unwrap(),
&app.primary.map,
);
return Transition::Push(PopupMsg::new(
ctx,
"One road exported",
vec![format!(
"One arbitrary road from your selection exported to Streetmix format \
at {}",
path
)],
));
}
x => { x => {
if self.selector.event(ctx, app, Some(x)) { if self.selector.event(ctx, app, Some(x)) {
self.panel = make_select_panel(ctx, &self.selector); self.panel = make_select_panel(ctx, &self.selector);