UNPKG

npmap.js

Version:

A JavaScript web mapping library, built as a Leaflet plugin, for the National Park Service.

43 lines (35 loc) 971 B
/* globals L */ /* jshint camelcase: false */ 'use strict'; var reqwest = require('reqwest'); module.exports = ({ mapbox: (function() { return { route: function(latLngs, callback) { var locations = ''; for (var i = 0; i < latLngs.length; i++) { var latLng = latLngs[i]; if (i) { locations += ';'; } locations += latLng.lng + ',' + latLng.lat; } reqwest({ crossOrigin: true, error: function() { callback({ message: 'The route failed. Please check your network connection.', success: false }); }, success: function(response) { //console.log(response); callback(response); }, type: 'json', url: 'http://api.tiles.mapbox.com/v3/nps.map-06dnxzq5/directions/driving/' + locations + '.json' }); } }; })() });