diff --git a/CHANGES.md b/CHANGES.md index 3253cd1..7c35196 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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 diff --git a/route-snapper-ts/src/index.ts b/route-snapper-ts/src/index.ts index 4702398..e3fdbbd 100644 --- a/route-snapper-ts/src/index.ts +++ b/route-snapper-ts/src/index.ts @@ -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[]; } diff --git a/route-snapper/src/lib.rs b/route-snapper/src/lib.rs index a0164bc..8cf6326 100644 --- a/route-snapper/src/lib.rs +++ b/route-snapper/src/lib.rs @@ -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 }; @@ -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, + #[serde(skip_serializing_if = "Option::is_none")] + free: Option<[f64; 2]>, +}