Google RouteBoxer implementation for Leaflet
Switch branches/tags
Nothing to show
Clone or download
Latest commit ae7de42 Apr 17, 2018
Permalink
Failed to load latest commit information.
dist Fixed passing a polyline Dec 8, 2015
example Update index.html Nov 8, 2017
src Fixed passing a polyline Dec 8, 2015
.gitignore Banned .DS_Store Jul 1, 2015
README.md Update README.md Apr 17, 2018
bower.json Adds dependency on leaflet Dec 8, 2015
package.json Bump version Nov 4, 2017

README.md

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

Usage

You need to pass an array of L.Latlng objects (route) to the L.RouteBoxer.

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.

// 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);