Skip to content

Commit

Permalink
Render perpendicular sidewalk lines
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Mar 15, 2024
1 parent 426f3c0 commit ecad848
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
30 changes: 30 additions & 0 deletions osm2streets/src/render.rs
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,17 @@ impl StreetNetwork {
features.push(f);
}
}

for (lane, center) in road.lane_specs_ltr.iter().zip(lane_centers.iter()) {
if lane.lt != LaneType::Sidewalk {
continue;
}
for polygon in draw_sidewalk_lines(lane, center) {
let mut f = Feature::from(polygon.to_geojson(gps_bounds));
f.set_property("type", "sidewalk line");
features.push(f);
}
}
}

serialize_features(features)
Expand Down Expand Up @@ -611,6 +622,25 @@ fn draw_parking_lines(lane: &LaneSpec, center: &PolyLine, streets: &StreetNetwor
result
}

fn draw_sidewalk_lines(lane: &LaneSpec, center: &PolyLine) -> Vec<Polygon> {
center
.step_along(lane.width, lane.width)
.into_iter()
.map(|(pt, angle)| {
// Project away an arbitrary amount
let pt2 = pt.project_away(Distance::meters(1.0), angle);
perp_line(Line::must_new(pt, pt2), lane.width).make_polygons(Distance::meters(0.25))
})
.collect()
}

// this always does it at pt1
fn perp_line(l: Line, length: Distance) -> Line {
let pt1 = l.shift_right(length / 2.0).pt1();
let pt2 = l.shift_left(length / 2.0).pt1();
Line::must_new(pt1, pt2)
}

fn serialize_features(features: Vec<Feature>) -> Result<String> {
let gj = geojson::GeoJson::from(geojson::FeatureCollection {
bbox: None,
Expand Down
1 change: 1 addition & 0 deletions web/src/common/layers/RenderLaneMarkings.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"buffer stripe": general_road_marking,
"parking hatch": general_road_marking,
"vehicle stop line": general_road_marking,
"sidewalk line": "#BBBBBB",
"bike stop line": "green",
},
"red",
Expand Down

0 comments on commit ecad848

Please sign in to comment.