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-valhalla

v0.1.1

Published

Support for Valhalla by Mapzen in Leaflet Machine

Downloads

32

Readme

Leaflet Routing Machine / Valhalla by Mapzen

 ██▒   █▓ ▄▄▄       ██▓     ██░ ██  ▄▄▄       ██▓     ██▓    ▄▄▄      
▓██░   █▒▒████▄    ▓██▒    ▓██░ ██▒▒████▄    ▓██▒    ▓██▒   ▒████▄    
 ▓██  █▒░▒██  ▀█▄  ▒██░    ▒██▀▀██░▒██  ▀█▄  ▒██░    ▒██░   ▒██  ▀█▄  
  ▒██ █░░░██▄▄▄▄██ ▒██░    ░▓█ ░██ ░██▄▄▄▄██ ▒██░    ▒██░   ░██▄▄▄▄██ 
   ▒▀█░   ▓█   ▓██▒░██████▒░▓█▒░██▓ ▓█   ▓██▒░██████▒░██████▒▓█   ▓██▒
   ░ ▐░   ▒▒   ▓▒█░░ ▒░▓  ░ ▒ ░░▒░▒ ▒▒   ▓▒█░░ ▒░▓  ░░ ▒░▓  ░▒▒   ▓▒█░
   ░ ░░    ▒   ▒▒ ░░ ░ ▒  ░ ▒ ░▒░ ░  ▒   ▒▒ ░░ ░ ▒  ░░ ░ ▒  ░ ▒   ▒▒ ░
     ░░    ░   ▒     ░ ░    ░  ░░ ░  ░   ▒     ░ ░     ░ ░    ░   ▒   
      ░        ░  ░    ░  ░ ░  ░  ░      ░  ░    ░  ░    ░  ░     ░  ░
     ░                                                                    

Extends Leaflet Routing Machine with support for Valhalla.

Valhalla is a free, open-source routing service with dynamic run-time costing that lets you integrate automobile, bicycle, and pedestrian navigation into a web or mobile application. To use Valhalla with the Leaflet Routing Machine, install the lrm-valhalla plug-in with npm and get your free API key from mapzen.com/developers.

How to use

As with the other LRM plug-ins, you can download lrm-valhalla and insert 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-valhalla.js"></script>
/* ... */

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

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

Insert your Valhalla API key and the routing mode (auto, bicycle, or pedestrian). (Note that no options are needed for formatter.)

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

L.Routing.control({
  // [...] See Valhalla API documentation for other options
  router: L.Routing.valhalla('<my api key>', 'auto'),
  formatter: new L.Routing.Valhalla.Formatter()
}).addTo(map);

See the Leaflet Routing Machine documentation and Valhalla API documentation for more information.

If you want to include additional costing options to help define the the route and estimated time along the path, you can pass costing option object as one of router parameter. See the Valhalla API documentation for more information on the available options for each routing mode.

L.Routing.control({
  router: L.Routing.valhalla('<my api key>', 'bicycle', {
        bicycle: {
        bicycle_type: "Road",
        cycling_speed: 17,
        use_roads: "0.1"
      }
    }),
  formatter: new L.Routing.Valhalla.Formatter(),
}).addTo(map);

Using Valhalla with npm and Browserify

Like other plug-ins, the Valhalla plug-in can be installed using npm instead of downloading the script manually:

npm install --save lrm-valhalla

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

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

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

L.Routing.control({
  router: L.Routing.valhalla('<my api key>', 'auto'),
  formatter: new L.Routing.Valhalla.Formatter()
}).addTo(map);

For router, insert your Valhalla API key and the routing mode (such as auto, bicycle, or pedestrian); see the Valhalla API documentation for more information. (Note that no options are needed for formatter.)

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

var rr = L.Routing.valhalla('<my api key>', 'auto');
[...]
bikeButton.onClick: function () {
  rr.route({transitmode: "bicycle"});
}

Running a local example

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

  • Install lrm-valhalla through npm or download the contents of the lrm-valhalla repo
  • get your API key from mapzen.com/developers
  • paste it into the example's index.js and choose the transportation 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 Valhalla are in the /examples folder)