MCPcopy Index your code
hub / github.com/dabreegster/route_snapper

github.com/dabreegster/route_snapper @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
138 symbols 317 edges 11 files 15 documented · 11%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

MapLibre route snapper

NPM

This plugin lets you draw routes and polygon areas in MapLibre GL that snap to some network (streets, usually). Unlike similar plugins that send a request to a remote API for routing, this one does the routing client-side. This works by loading a pre-built file covering a fixed area and calculating the routes locally.

Demo

Demo

Usage

See the user guide for full details and examples.

  1. Build a graph file covering some fixed area
  2. npm install route-snapper
  3. Construct the RouteSnapper object, passing in the graph file a MapLibre map
  4. Listen to events to use the drawn routes

Development

route-snapper is written in Rust, compiled to WASM to run in the browser, and has a simple Javascript wrapper library. You need wasm-pack and Python (to run a local server).

cd examples
./serve_locally.sh

Contributing

There are many ideas for improving this plugin, such as customizing the instructions, controls, and route style, and generating graph files on-the-fly from vector tile data. Check out the issues or start your own.

This project follows the Rust code of conduct and is Apache 2.0 licensed.

Related work

This tool started life in fall 2021 through Ungap the Map, for sketching potential cycle lanes along existing roads. It used a custom UI and map rendering library built on top of OpenGL. A year later, the idea was adapted to work in ATIP, using MapLibre GL. The functionality for dragging waypoints is partly inspired by Felt, Google Maps, and similar products.

Other projects with client-side routing: ngraph.path, geojson-path-finder

Extension points exported contracts — how you extend this code

Writable (Interface)
(no doc)
route-snapper-ts/src/index.ts
RouteProps (Interface)
(no doc)
route-snapper-ts/src/index.ts
AreaProps (Interface)
(no doc)
route-snapper-ts/src/index.ts
Waypoint (Interface)
(no doc)
route-snapper-ts/src/index.ts

Core symbols most depended-on inside this repo

on_click
called by 20
route-snapper/src/lib.rs
mouseover_node
called by 11
route-snapper/src/lib.rs
node
called by 11
route-snapper-graph/src/lib.rs
#redraw
called by 10
route-snapper/lib.js
add_waypoint
called by 10
route-snapper/src/lib.rs
redraw
called by 10
route-snapper-ts/src/index.ts
to_pt
called by 8
route-snapper/src/lib.rs
to_path_entry
called by 7
route-snapper/src/lib.rs

Shape

Method 73
Function 37
Class 21
Interface 4
Enum 3

Languages

Rust68%
TypeScript32%

Modules by API surface

route-snapper/src/lib.rs57 symbols
route-snapper-ts/src/index.ts27 symbols
route-snapper/lib.js13 symbols
route-snapper-graph/src/lib.rs12 symbols
route-snapper/src/tests.rs9 symbols
osm-to-route-snapper/src/lib.rs7 symbols
route-snapper-ts/src/split.ts4 symbols
geojson-to-route-snapper/src/lib.rs4 symbols
osm-to-route-snapper/src/main.rs2 symbols
geojson-to-route-snapper/src/main.rs2 symbols
debug-graph/src/main.rs1 symbols

For agents

$ claude mcp add route_snapper \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact