Find the way from A to B on a Leaflet map. The plugin supports multiple backends:
- OSRM - builtin and used by default (version 5)
- Mapbox Directions API - builtin with the class
L.Routing.Mapbox
- GraphHopper - through plugin lrm-graphopper
- Mapzen Valhalla - through plugin lrm-valhalla
- TomTom Online Routing API - through plugin lrm-tomtom by Mathias Rohnstock
- Legacy support for OSRM version 4 through plugin lrm-osrm4
- Esri - through plugin lrm-esri
- Standard Leaflet control, with Leaflet look and feel
- Routing from start to destination, with possibility of via points
- Add, edit and remove waypoints through both address input and using the map
- Multiple language support
- Highly customizable for advanced use
- Customizable look (theming / skins)
- Open Source released under ISC License (more or less equivalent with the MIT license)
Go to the Leaflet Routing Machine site for more information, demos, tutorials and more.
Leaflet Routing Machine is in many ways already a feature complete routing UI. Most likely, your requirements are already covered and require very little adaptation.
For questions and discussions, you might want to look at the Leaflet Routing Machine gitter.
npm install
This requires Node and npm.
via npm/yarn (the preferred way):
npm install --save leaflet-routing-machine
Please Note: If you want to use osrm-text-instructions for routing instructions, you need to add it as a dependency yourself
npm i --save osrm-text-instructions
var L = require('leaflet');
require('leaflet-routing-machine');
// or, if you prefer modern ES6 imports
import * as L from 'leaflet';
import 'leaflet-routing-machine';
...
alternatively, if you do not use a bundler:
Download latest release, or obtain the latest release via unpkg.com.
<link rel="stylesheet" href="https://unpkg.com/[email protected]/dist/leaflet-routing-machine.css" />
<script src="https://unpkg.com/[email protected]/dist/leaflet-routing-machine.js"></script>
Please note: From v4 this will not include osrm-text-instructions anymore so you need to configure your own language mapping or stay on v3
LRM attaches itself onto L
.
Go to the Leaflet Routing Machine site for more information, demos, tutorials and more.