Skip to content

Commit

Permalink
Include the full list of nodes in the output GeoJSON
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Sep 19, 2024
1 parent bdb5e99 commit 3743a93
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ changes.
## Unreleased

- The OSM importer can now handle MultiPolygon boundaries for clipping
- The final route feature has a new `full_path` property, with every snapped and freehand node

## 0.4.1

Expand Down
3 changes: 3 additions & 0 deletions route-snapper-ts/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ export interface RouteProps {
waypoints: Waypoint[];
length_meters: number;
route_name: string;
full_path: Node[];
}

export type Node = { snapped: number } | { free: [number, number] };

export interface AreaProps {
waypoints: Waypoint[];
}
Expand Down
34 changes: 34 additions & 0 deletions route-snapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,32 @@ impl JsRouteSnapper {
let to_name = self.name_waypoint(self.route.waypoints.last().as_ref().unwrap());
f.set_property("route_name", format!("Route from {from_name} to {to_name}"));

let mut full_path = Vec::new();
for entry in &self.route.full_path {
match entry {
PathEntry::SnappedPoint(node) => {
full_path.push(
serde_json::to_value(&JsonNode {
snapped: Some(node.0),
free: None,
})
.unwrap(),
);
}
PathEntry::FreePoint(pt) => {
full_path.push(
serde_json::to_value(&JsonNode {
snapped: None,
free: Some([trim_lon_lat(pt.x), trim_lon_lat(pt.y)]),
})
.unwrap(),
);
}
PathEntry::Edge(_) => {}
}
}
f.set_property("full_path", serde_json::Value::Array(full_path));

f
};

Expand Down Expand Up @@ -1158,3 +1184,11 @@ fn unhash_pt(pt: HashedPoint) -> Coord {
y: pt.1 as f64 / 10e6,
}
}

#[derive(Serialize)]
struct JsonNode {
#[serde(skip_serializing_if = "Option::is_none")]
snapped: Option<u32>,
#[serde(skip_serializing_if = "Option::is_none")]
free: Option<[f64; 2]>,
}

0 comments on commit 3743a93

Please sign in to comment.