https://github.com/stephangeorg/leaflet-routeboxer
Google RouteBoxer implementation for Leaflet
https://github.com/stephangeorg/leaflet-routeboxer
leaflet polyline routeboxer
Last synced: 11 months ago
JSON representation
Google RouteBoxer implementation for Leaflet
- Host: GitHub
- URL: https://github.com/stephangeorg/leaflet-routeboxer
- Owner: StephanGeorg
- Created: 2015-06-30T16:06:26.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2021-01-11T08:01:09.000Z (over 5 years ago)
- Last Synced: 2025-07-08T22:16:21.701Z (12 months ago)
- Topics: leaflet, polyline, routeboxer
- Language: JavaScript
- Homepage: https://stephangeorg.github.io/leaflet-routeboxer/example/
- Size: 41 KB
- Stars: 46
- Watchers: 3
- Forks: 10
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Leaflet RouteBoxer
This is a Leaflet implementation of Google's RouteBoxer class.
The RouteBoxer class generates a set of L.LatLngBounds objects that are guaranteed
to cover every point within a specified distance of a path, such as that generated
for a route by an OSRM directions service.
## Example
Check out the example [demo](https://stephangeorg.github.io/leaflet-routeboxer/example/)
## Usage
You need to pass an array of L.Latlng objects (route) to the L.RouteBoxer.
```javascript
var route = [
[50.5, 30.5],
[50.4, 30.6],
[50.3, 30.7]
];
var distance = 10; // Distance in km
var boxes = L.RouteBoxer.box(route, distance);
```
### Using w/ OSRM service
OSRM uses polyline encoding to save bandwith. To decode the polyline you can use
[Leaflet.encoded](https://github.com/jieter/Leaflet.encoded).
```javascript
// data.route_geometry is the result from a OSRM endpoint
var route = new L.Polyline(L.PolylineUtil.decode(data.route[0].geometry));
var distance = 10; // Distance in km
var boxes = L.RouteBoxer.box(route, distance);
```