Skip to content

Commit

Permalink
Add a new API for showing snappable nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
dabreegster committed Jun 27, 2024
1 parent 7e232a3 commit 940f107
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ changes.

## Unreleased

## 0.4.1

- Removed `fetchWithProgress`, which is a general-purpose utility method that
should come from another library
- Improved the tool that makes graphs from GeoJSON files by splitting
LineStrings that touch at interior points
- Added `debugSnappableNodes` as a faster alternative to `debugRenderGraph`

## 0.4.0

Expand Down
2 changes: 1 addition & 1 deletion route-snapper/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion route-snapper/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "route-snapper"
version = "0.4.0"
version = "0.4.1"
edition = "2021"
description = "Draw routes in MapLibre snapped to a street network using client-side routing"
repository = "https://github.com/dabreegster/route_snapper"
Expand Down
12 changes: 12 additions & 0 deletions route-snapper/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -718,6 +718,18 @@ impl JsRouteSnapper {
serde_json::to_string_pretty(&gj).unwrap()
}

/// Render the graph as GeoJSON points, for helping the user understand the snappable nodes.
#[wasm_bindgen(js_name = debugSnappableNodes)]
pub fn debug_snappable_nodes(&self) -> String {
let mut features = Vec::new();
for pt in &self.router.map.nodes {
features.push(Feature::from(Geometry::from(&Point::from(*pt))));
}
let gj =
geojson::GeoJson::from(features.into_iter().collect::<geojson::FeatureCollection>());
serde_json::to_string(&gj).unwrap()
}

#[wasm_bindgen(js_name = routeNameForWaypoints)]
pub fn route_name_for_waypoints(&self, raw_waypoints: JsValue) -> Result<String, JsValue> {
let waypoints: Vec<RouteWaypoint> = serde_wasm_bindgen::from_value(raw_waypoints)?;
Expand Down
1 change: 1 addition & 0 deletions user_guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ If you're using the WASM API directly, the best reference is currently [the code
- A numeric `undo_length`
- `toggleSnapMode` attempts to switch between snapping and freehand drawing. It may not succeed.
- `addSnappedWaypoint` adds a new waypoint to the end of the route, snapping to the nearest node. It's useful for clients to hook up a geocoder and add a point by address. Unsupported in area mode.
- `debugSnappableNodes` returns a FeatureCollection of Points with no properties, for showing the user all snappable nodes

### MapLibre gotchas

Expand Down

0 comments on commit 940f107

Please sign in to comment.