Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

mapbox

mapbox55.3kISC1.0.0-beta10TypeScript support: definitely-typed

interface to mapbox services

mapbox, interface, api, sdk

readme

mapbox-sdk-js

npm version Build Status Coverage Status

A node.js and browser JavaScript client to Mapbox services.

Services

Generally Available

  • Geocoding
    • Forward (place names ⇢ longitude, latitude)
    • Reverse (longitude, latitude ⇢ place names)
  • Upload API
    • Upload data to be processed and hosted by Mapbox.
  • Directions
    • Profiles for driving, walking, and cycling
    • GeoJSON & Polyline formatting
    • Instructions as text or HTML
  • Datasets
    • Retrieve, add, and edit datasets.
  • Styles
    • Retrieve, add and edit styles, fonts and icons.
  • Tilesets
    • List tilesets.
  • Tokens
    • Retrieve, add and edit access tokens.
  • Matrix
    • Travel-time tables between coordinates up to 25 pairs
    • Profiles for driving, walking and cycling
  • Map Matching
    • Aligns GPS trace data to roads and paths from OpenStreetMap data

Installation

$ npm install --save mapbox

Usage

Setup via node:

var MapboxClient = require('mapbox');

Setup via script tag:

<script src='https://unpkg.com/mapbox@1.0.0-beta9/dist/mapbox-sdk.min.js'></script>

Initializing:

var client = new MapboxClient('YOUR_ACCESS_TOKEN');

Basic usage of the geocoder:

client.geocodeForward('Chester, NJ', function(err, data, res) {
  // data is the geocoding result as parsed JSON
  // res is the http response, including: status, headers and entity properties
});

As an alternative to callbacks, each method also returns a Promise:

client.geocodeForward('Chester, NJ')
  .then(function(res) {
    // res is the http response, including: status, headers and entity properties
    var data = res.entity; // data is the geocoding result as parsed JSON
  })
  .catch(function(err) {
    // handle errors
  });

pagination

Listing resources may return a subset of the entire listing. If more pages are available the res object will contain a .nextPage() method. This method requires no arguments, other than an optional callback function, otherwise a Promise is returned.

sub-requiring individual services

Each service is available as a sub-require if you'd only like to include only its functionality and not the entire bundle. The returned MapboxClient will have the same constructor style but only include functions necessary for that service's support.

Available sub-requires:

  • geocoding: require('mapbox/lib/services/geocoding')
  • surface: require('mapbox/lib/services/surface')
  • matching: require('mapbox/lib/services/matching')
  • directions: require('mapbox/lib/services/directions')
  • matrix: require('mapbox/lib/services/matrix')
  • datasets: require('mapbox/lib/services/datasets')
  • styles: require('mapbox/lib/services/styles')
  • uploads: require('mapbox/lib/services/uploads')
  • tilestats: require('mapbox/lib/services/tilestats')
  • static: require('mapbox/lib/services/static')
  • tilesets: require('mapbox/lib/services/tilesets')
  • tokens: require('mapbox/lib/services/tokens')

API

changelog

1.0.0-beta10

  • Bug Fix bug preventing Geocoding service being used without an options parameter when using promise syntax. #197
  • Feature Geocoding language, country and types parameters can be passed as arrays as an alternative to comma separated strings. #208

1.0.0-beta9

  • Feature Add language parameter to geocoding API. #174

1.0.0-beta8

  • Deprecation Distance API has been deprecated and is now referred to the Matrix API. This renames .getDistances() method to .getMatrix(). #177

1.0.0-beta7

  • Deprecation Renamed .getStaticURL() method to .getStaticClassicURL() #152
  • Feature Add Styles Static API #152
  • Feature Add Tilesets API #165
  • Feature Add Tokens API #155
  • Feature Add response.nextPage() method for pagination of list resources #159
  • Bug Avoid double URL encoding of geojson static overlays #156
  • Update Remove start and reverse opts for datasets listings
  • Update Clarify account/profile property for Directions API #150
  • Update Miscellaneous documentation polish

Special thanks to @andrewharvey for significant contributions to this release

1.0.0-beta6

  • Bug Add autocomplete param to geocoding endpoint. #126
  • Bug Install Promise polyfill only when needed. #122
  • Update Update Map Matching to v5. #128
  • Update Update Directions to v5. #68

1.0.0-beta5

  • Add limit option to geocoder API
  • Add poi.landmark type to geocoder API
  • Fixes a bug where the global Promise object was overwritten by a polyfill

1.0.0-beta4

  • Adds the concept of a reponse object
  • Update all callbacks to provide err, body, response.
  • Change default returned value for promises from body to response.
  • Remove client.batchFeatureUpdate. client.insertFeature or client.destroyFeture should be used now.

1.0.0-beta3

  • Update tilestat service for new API.

1.0.0-beta1

  • Add bbox option to geocoder API

1.0.0-beta

  • Changes a major API! Geocoding is now named geocoding everywhere, so the sub-require is mapbox/lib/services/geocoding, not, like it used to be, mapbox/lib/services/geocoder
  • The DatasetClient#bulkFeatureUpdate method is renamed DatasetClient#batcFeatureUpdate to match the rest of the Mapbox ecosystem.

0.12.0

  • Add types & country options to geocoder #65

0.11.0

  • Allow pagination options if passed in listFeatures #61

0.10.0

  • Support query params for Directions requests #58

0.9.0

  • Adds a precision option to geocodeForward and geocodeReverse methods: this allows you to customize how much decimal precision is provided wth proximity parameters and the location of geocodeReverse requests, potentially increasing cache-friendliness.

0.8.2

  • Fixes geocodeReverse method

0.8.1

  • Include Mapbox Distance in default client

0.8.0

0.7.0

  • Improved error handling
  • Added support for Tileset statistics API (in preview)

0.6.2

  • Added support for Upload API
  • Added support for Datasets API (in preview)

0.6.1

  • Fixed bug in forward geococoding

0.6.0

  • Allows endpoint to be customized
  • Support for sub-requiring individual services

0.5.0

0.4.0

0.3.0

0.2.0