npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

lrm-mapzen

v1.3.5

Published

Support for Turn By Turn by Mapzen in Leaflet Machine

Downloads

224

Readme

Mapzen is shutting down its services including Turn-by-turn. Read more at https://mapzen.com/blog/shutdown/

npm version

Add support for Mapzen Turn-by-Turn routing in Leaflet Routing Machine

Mapzen Turn-by-Turn is an open-source routing service with dynamic run-time costing that lets you integrate automobile, bicycle, pedestrian, or multimodal navigation into a web or mobile application.

Use this plug-in to create a Leaflet map that has a route line between map locations (also known as waypoints), a text narrative of maneuvers to perform on the route, distances along your route and estimated travel times, and the ability to drag the route start and endpoints to get a different path.

With lrm-mapzen, Mapzen Turn-by-Turn is substituted for the default routing service used in Leaflet Routing Machine. You need to install the lrm-mapzen plug-in and obtain an API key from mapzen.com/developers.

Get started with lrm-mapzen

Follow along with this tutorial to build a map with lrm-mapzen.

Download lrm-mapzen and insert a reference to the JavaScript file into your page right after the line where it loads Leaflet Routing Machine:

[...]
<script src="leaflet-routing-machine.js"></script>
<script src="lrm-mapzen.js"></script>
[...]

Also, include the stylesheet. This can replace the default leaflet-routing-machine.css provided by LRM, since the Mapzen plug-in includes its own styles and icons.

<link rel="stylesheet" href="leaflet.routing.mapzen.css">

Insert your Mapzen API key for the placeholder text (mapzen-xxxxxx) and a routing options object to at least include the costing mode (auto, bicycle, pedestrian, or multimodal). Note that no additional options are needed for formatter.

var map = L.map('map');

L.Routing.control({
  // [...] See MapzenTurn-by-Turn API documentation for other options
  router: L.Routing.mapzen('mapzen-xxxxxx', {
    costing:'auto'
  }),
  formatter: new L.Routing.mapzenFormatter()
}).addTo(map);

If you want to include additional costing options to help define the the route and estimated time along the path, you can pass a costing option object as one of router parameters. You can also include options for directions in order to change the language, distance units or narrative guidance production. See the Mapzen Turn-by-Turn API documentation for more information on the available options.

L.Routing.control({
  router: L.Routing.mapzen('mapzen-xxxxxx', {
    costing: "bicycle",
    costing_options: {
      bicycle: {
        bicycle_type: "Road",
        cycling_speed: "17.0",
        use_roads: "0.1"
      },
    },
    directions_options: {
      language: 'en-US'
    }
  }),
  formatter: new L.Routing.mapzenFormatter(),
}).addTo(map);

With themultimodal costing mode, you can set costing options for preferences for taking buses or rail lines or having to make transfers. If you include a date_time, you can request a transit route departing at a certain time, for example. See the Mapzen Turn-by-Turn API documentation for more information on the available options.

L.Routing.control({
  router: L.Routing.mapzen('mapzen-xxxxxx', {
    // you need to pass mapzenLine as routeLine to router to see subroutes of transit routing.
    // you can skip routeLine if you don't want to use subroutes.
    routeLine: function (route, options) { return L.Routing.mapzenLine(route, options); },
    costing: "multimodal",
    date_time: {
      type: 1,
      value: "2016-05-10T08:00"
    }
  }),
  formatter: new L.Routing.mapzenFormatter(),
}).addTo(map);

See the Leaflet Routing Machine documentation and Mapzen Turn-by-Turn API documentation for more information.

Use lrm-mapzen with npm and Browserify

The Mapzen plug-in can be installed using npm instead of downloading the script manually:

npm install --save lrm-mapzen

Once the Mapzen plug-in is installed, update the router and formatter instances to tell the Leaflet Routing Machine to use Mapzen’s engine.

var L = require('leaflet');
require('leaflet-routing-machine');
require('lrm-mapzen');

var map = L.map('map');

L.Routing.control({
  router: L.Routing.mapzen('mapzen-xxxxxx', {costing:'auto'}),
  formatter: new L.Routing.mapzenFormatter()
}).addTo(map);

For router, insert your Mapzen Turn-by-Turn API key and a routing options object to at least include the routing mode (such as auto, bicycle, pedestrian, or multimodal); see the Mapzen Turn-by-Turn API documentation for more information. (Note that no additional options are needed for formatter.)

You can also change the route costing mode after the router is created. Say you had different transportation options on your map and wanted to change costing to bicycle when that button is clicked:

var rr = L.Routing.mapzen('mapzen-xxxxxx', {costing:'auto'});
[...]
bikeButton.onClick: function () {
  rr.route({costing: "bicycle"});
}

Run a local example

If you want to run your lrm-mapzen plug-in locally for testing and development purposes:

  • Install lrm-mapzen through npm or download the contents of the lrm-mapzen repo
  • Get your API key from mapzen.com/developers
  • Paste it into the example's index.js and choose the transportation/costing mode (auto, bicycle, or pedestrian)
  • Start a local web server (such as python -m SimpleHTTPServer or the local server you prefer)
  • Go to http://localhost:8000/examples in your browser (all assets needed to run Mapzen are in the /examples folder)