Comparing version 0.4.0 to 0.5.0
46
API.md
@@ -8,2 +8,4 @@ ## `MapboxClient` | ||
* `accessToken` **`string`** a private or public access token | ||
* `options` **`Object`** additional options provided for configuration | ||
* `options.endpoint` **`[string]`** location of the Mapbox API pointed-to. This can be customized to point to a Mapbox Atlas Server instance, or a different service, a mock, or a staging endpoint. Usually you don't need to customize this. (optional, default `https://api.mapbox.com`) | ||
@@ -30,2 +32,4 @@ | ||
* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`) | ||
* `options.proximity` **`Object`** a proximity argument: this is a geographical point given as an object with latitude and longitude properties. Search results closer to this point will be given higher priority. | ||
* `options.dataset` **`[string]`** the desired data to be geocoded against. The default, mapbox.places, does not permit unlimited caching. `mapbox.places-permanent` is available on request and does permit permanent caching. (optional, default `mapbox.places`) | ||
* `callback` **`Function`** called with (err, results) | ||
@@ -59,3 +63,6 @@ | ||
* `location` **`Object`** the geographical point to search | ||
* `location.latitude` **`number`** decimal degrees latitude, in range -90 to 90 | ||
* `location.longitude` **`number`** decimal degrees longitude, in range -180 to 180 | ||
* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`) | ||
* `options.dataset` **`[string]`** the desired data to be geocoded against. The default, mapbox.places, does not permit unlimited caching. `mapbox.places-permanent` is available on request and does permit permanent caching. (optional, default `mapbox.places`) | ||
* `callback` **`Function`** called with (err, results) | ||
@@ -67,3 +74,3 @@ | ||
```js | ||
var mapboxClient = new MapboxClient('ACCESSTOKEN'); | ||
var mapboxClient = new MapboxGeocoder('ACCESSTOKEN'); | ||
mapboxClient.geocodeReverse( | ||
@@ -88,2 +95,6 @@ { latitude: 33.6875431, longitude: -95.4431142 }, | ||
* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`) | ||
* `options.profile` **`[string]`** the directions profile, which determines how to prioritize different routes. Options are `'mapbox.driving'`, which assumes transportation via an automobile and will use highways, `'mapbox.walking'`, which avoids streets without sidewalks, and `'mapbox.cycling'`, which prefers streets with bicycle lanes and lower speed limits for transportation via bicycle. (optional, default `mapbox.driving`) | ||
* `options.alternatives` **`[string]`** whether to generate alternative routes along with the preferred route. (optional, default `true`) | ||
* `options.instructions` **`[string]`** format for turn-by-turn instructions along the route. (optional, default `text`) | ||
* `options.geometry` **`[string]`** format for the returned route. Options are `'geojson'`, `'polyline'`, or `false`: `polyline` yields more compact responses which can be decoded on the client side. [GeoJSON](http://geojson.org/), the default, is compatible with libraries like [Mapbox GL](https://www.mapbox.com/mapbox-gl/), Leaflet and [Mapbox.js](https://www.mapbox.com/mapbox.js/). `false` omits the geometry entirely and only returns instructions. (optional, default `geojson`) | ||
* `callback` **`Function`** called with (err, results) | ||
@@ -130,2 +141,5 @@ | ||
* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`) | ||
* `options.profile` **`[string]`** the directions profile, which determines how to prioritize different routes. Options are `'mapbox.driving'`, which assumes transportation via an automobile and will use highways, `'mapbox.walking'`, which avoids streets without sidewalks, and `'mapbox.cycling'`, which prefers streets with bicycle lanes and lower speed limits for transportation via bicycle. (optional, default `mapbox.driving`) | ||
* `options.geometry` **`[string]`** format for the returned route. Options are `'geojson'`, `'polyline'`, or `false`: `polyline` yields more compact responses which can be decoded on the client side. [GeoJSON](http://geojson.org/), the default, is compatible with libraries like [Mapbox GL](https://www.mapbox.com/mapbox-gl/), Leaflet and [Mapbox.js](https://www.mapbox.com/mapbox.js/). `false` omits the geometry entirely and only returns matched points. (optional, default `geojson`) | ||
* `options.gps_precision` **`[number]`** An integer in meters indicating the assumed precision of the used tracking device. Use higher numbers (5-10) for noisy traces and lower numbers (1-3) for clean traces. The default value is 4. (optional, default `4`) | ||
* `callback` **`Function`** called with (err, results) | ||
@@ -167,1 +181,31 @@ | ||
## `surface` | ||
Given a list of locations, retrieve vector tiles, find the nearest | ||
spatial features, extract their data values, and then absolute values and | ||
optionally interpolated values in-between, if the interpolate option is specified. | ||
Consult the [Surface API](https://www.mapbox.com/developers/api/surface/) | ||
for more documentation. | ||
### Parameters | ||
* `mapid` **`string`** a Mapbox mapid containing vector tiles against which we'll query | ||
* `layer` **`string`** layer within the given `mapid` for which to pull data | ||
* `fields` **`Array<string>`** layer within the given `mapid` for which to pull data | ||
* `path` **`Array<Object> or string`** either an encoded polyline, provided as a string, or an array of objects with longitude and latitude properties, similar to waypoints. | ||
* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`) | ||
* `options.geojson` **`[string]`** whether to return data as a GeoJSON point (optional, default `false`) | ||
* `options.zoom` **`[string]`** zoom level at which features are queried (optional, default `maximum`) | ||
* `options.interpolate` **`[boolean]`** Whether to interpolate between matches in the feature collection. (optional, default `true`) | ||
* `callback` **`Function`** called with (err, results) | ||
### Examples | ||
```js | ||
var mapboxClient = new MapboxClient('ACCESSTOKEN'); | ||
``` | ||
Returns nothing, calls callback | ||
@@ -0,1 +1,10 @@ | ||
## 0.6.0 | ||
* Allows endpoint to be customized | ||
* Support for sub-requiring individual services | ||
## 0.5.0 | ||
* Added `surface` method that connects to [Mapbox Surface API](https://www.mapbox.com/developers/api/surface/) | ||
## 0.4.0 | ||
@@ -2,0 +11,0 @@ |
'use strict'; | ||
var assert = require('assert'), | ||
resolveToString = require('es6-template-strings/resolve-to-string'), | ||
geojsonhint = require('geojsonhint'), | ||
qs = require('querystring'), | ||
request = require('superagent'), | ||
constants = require('./constants'); | ||
var makeClient = require('./make_service'); | ||
var xtend = require('xtend/mutable'); | ||
var MapboxGeocoder = require('./services/geocoder'); | ||
var MapboxSurface = require('./services/surface'); | ||
var MapboxDirections = require('./services/directions'); | ||
var MapboxMatching = require('./services/matching'); | ||
@@ -16,349 +16,18 @@ /** | ||
* @param {string} accessToken a private or public access token | ||
* @param {Object} options additional options provided for configuration | ||
* @param {string} [options.endpoint=https://api.mapbox.com] location | ||
* of the Mapbox API pointed-to. This can be customized to point to a | ||
* Mapbox Atlas Server instance, or a different service, a mock, | ||
* or a staging endpoint. Usually you don't need to customize this. | ||
* @example | ||
* var client = new MapboxClient('ACCESSTOKEN'); | ||
*/ | ||
function MapboxClient(accessToken) { | ||
assert(typeof accessToken === 'string', | ||
'accessToken required to instantiate MapboxClient'); | ||
this.accessToken = accessToken; | ||
} | ||
var MapboxClient = makeClient('MapboxClient'); | ||
MapboxClient.prototype.q = function(options) { | ||
options.access_token = this.accessToken; | ||
return '?' + qs.stringify(options); | ||
}; | ||
xtend(MapboxClient.prototype, | ||
MapboxGeocoder.prototype, | ||
MapboxSurface.prototype, | ||
MapboxDirections.prototype, | ||
MapboxMatching.prototype); | ||
/** | ||
* Search for a location with a string, using the | ||
* [Mapbox Geocoding API](https://www.mapbox.com/developers/api/geocoding/). | ||
* | ||
* @param {string} query desired location | ||
* @param {Object} [options={}] additional options meant to tune | ||
* the request | ||
* @param {Object} options.proximity a proximity argument: this is | ||
* a geographical point given as an object with latitude and longitude | ||
* properties. Search results closer to this point will be given | ||
* higher priority. | ||
* @param {string} [options.dataset=mapbox.places] the desired data to be | ||
* geocoded against. The default, mapbox.places, does not permit unlimited | ||
* caching. `mapbox.places-permanent` is available on request and does | ||
* permit permanent caching. | ||
* @param {Function} callback called with (err, results) | ||
* @returns {undefined} nothing, calls callback | ||
* @example | ||
* var mapboxClient = new MapboxClient('ACCESSTOKEN'); | ||
* mapboxClient.geocodeForward('Paris, France', function(err, res) { | ||
* // res is a GeoJSON document with geocoding matches | ||
* }); | ||
* // using the proximity option to weight results closer to texas | ||
* mapboxClient.geocodeForward('Paris, France', { | ||
* proximity: { latitude: 33.6875431, longitude: -95.4431142 } | ||
* }, function(err, res) { | ||
* // res is a GeoJSON document with geocoding matches | ||
* }); | ||
*/ | ||
MapboxClient.prototype.geocodeForward = function(query, options, callback) { | ||
// permit the options argument to be omitted | ||
if (callback === undefined && typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
// typecheck arguments | ||
assert(typeof query === 'string', 'query must be a string'); | ||
assert(typeof options === 'object', 'options must be an object'); | ||
assert(typeof callback === 'function', 'callback must be a function'); | ||
var queryOptions = {}; | ||
if (options.proximity) { | ||
assert(typeof options.proximity.latitude === 'number' && | ||
typeof options.proximity.longitude === 'number', | ||
'proximity must be an object with numeric latitude & longitude properties'); | ||
queryOptions.proximity = options.proximity.longitude + ',' + options.proximity.latitude; | ||
} | ||
var dataset = 'mapbox.places'; | ||
if (options.dataset) { | ||
assert(typeof options.dataset === 'string', 'dataset option must be string'); | ||
dataset = options.dataset; | ||
} | ||
var url = resolveToString(constants.API_GEOCODER_FORWARD, { | ||
query: query, | ||
dataset: dataset | ||
}) + this.q(queryOptions); | ||
request(url, function(err, res) { | ||
callback(err, res.body); | ||
}); | ||
}; | ||
/** | ||
* Given a location, determine what geographical features are located | ||
* there. This uses the [Mapbox Geocoding API](https://www.mapbox.com/developers/api/geocoding/). | ||
* | ||
* @param {Object} location the geographical point to search | ||
* @param {number} location.latitude decimal degrees latitude, in range -90 to 90 | ||
* @param {number} location.longitude decimal degrees longitude, in range -180 to 180 | ||
* @param {Object} [options={}] additional options meant to tune | ||
* the request | ||
* @param {string} [options.dataset=mapbox.places] the desired data to be | ||
* geocoded against. The default, mapbox.places, does not permit unlimited | ||
* caching. `mapbox.places-permanent` is available on request and does | ||
* permit permanent caching. | ||
* @param {Function} callback called with (err, results) | ||
* @returns {undefined} nothing, calls callback | ||
* @example | ||
* var mapboxClient = new MapboxClient('ACCESSTOKEN'); | ||
* mapboxClient.geocodeReverse( | ||
* { latitude: 33.6875431, longitude: -95.4431142 }, | ||
* function(err, res) { | ||
* // res is a GeoJSON document with geocoding matches | ||
* }); | ||
*/ | ||
MapboxClient.prototype.geocodeReverse = function(location, options, callback) { | ||
// permit the options argument to be omitted | ||
if (callback === undefined && typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
// typecheck arguments | ||
assert(typeof location === 'object', 'location must be an object'); | ||
assert(typeof options === 'object', 'options must be an object'); | ||
assert(typeof callback === 'function', 'callback must be a function'); | ||
assert(typeof location.latitude === 'number' && | ||
typeof location.longitude === 'number', | ||
'location must be an object with numeric latitude & longitude properties'); | ||
var dataset = 'mapbox.places'; | ||
if (options.dataset) { | ||
assert(typeof options.dataset === 'string', 'dataset option must be string'); | ||
dataset = options.dataset; | ||
} | ||
var url = resolveToString(constants.API_GEOCODER_REVERSE, { | ||
location: location, | ||
dataset: dataset | ||
}) + this.q({}); | ||
request(url, function(err, res) { | ||
callback(err, res.body); | ||
}); | ||
}; | ||
/** | ||
* Find directions from A to B, or between any number of locations. | ||
* Consult the [Mapbox Directions API](https://www.mapbox.com/developers/api/directions/) | ||
* for more documentation. | ||
* | ||
* @param {Array<Object>} waypoints an array of objects with `latitude` | ||
* and `longitude` properties that represent waypoints in order. Up to | ||
* 25 waypoints can be specified. | ||
* @param {Object} [options={}] additional options meant to tune | ||
* the request | ||
* @param {string} [options.profile=mapbox.driving] the directions | ||
* profile, which determines how to prioritize different routes. | ||
* Options are `'mapbox.driving'`, which assumes transportation via an | ||
* automobile and will use highways, `'mapbox.walking'`, which avoids | ||
* streets without sidewalks, and `'mapbox.cycling'`, which prefers streets | ||
* with bicycle lanes and lower speed limits for transportation via | ||
* bicycle. | ||
* @param {string} [options.alternatives=true] whether to generate | ||
* alternative routes along with the preferred route. | ||
* @param {string} [options.instructions=text] format for turn-by-turn | ||
* instructions along the route. | ||
* @param {string} [options.geometry=geojson] format for the returned | ||
* route. Options are `'geojson'`, `'polyline'`, or `false`: `polyline` | ||
* yields more compact responses which can be decoded on the client side. | ||
* [GeoJSON](http://geojson.org/), the default, is compatible with libraries | ||
* like [Mapbox GL](https://www.mapbox.com/mapbox-gl/), | ||
* Leaflet and [Mapbox.js](https://www.mapbox.com/mapbox.js/). `false` | ||
* omits the geometry entirely and only returns instructions. | ||
* @param {Function} callback called with (err, results) | ||
* @returns {undefined} nothing, calls callback | ||
* @example | ||
* var mapboxClient = new MapboxClient('ACCESSTOKEN'); | ||
* mapboxClient.directions( | ||
* [ | ||
* { latitude: 33.6, longitude: -95.4431 }, | ||
* { latitude: 33.2, longitude: -95.4431 } ], | ||
* function(err, res) { | ||
* // res is a document with directions | ||
* }); | ||
* | ||
* // With options | ||
* mapboxClient.getDirections([ | ||
* { latitude: 33.6875431, longitude: -95.4431142 }, | ||
* { latitude: 33.6875431, longitude: -95.4831142 } | ||
* ], { | ||
* profile: 'mapbox.walking', | ||
* instructions: 'html', | ||
* alternatives: false, | ||
* geometry: 'polyline' | ||
* }, function(err, results) { | ||
* console.log(results.origin); | ||
* }); | ||
*/ | ||
MapboxClient.prototype.getDirections = function(waypoints, options, callback) { | ||
// permit the options argument to be omitted | ||
if (callback === undefined && typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
// typecheck arguments | ||
assert(Array.isArray(waypoints), 'waypoints must be an array'); | ||
assert(typeof options === 'object', 'options must be an object'); | ||
assert(typeof callback === 'function', 'callback must be a function'); | ||
var encodedWaypoints = waypoints.map(function(location) { | ||
assert(typeof location.latitude === 'number' && | ||
typeof location.longitude === 'number', | ||
'location must be an object with numeric latitude & longitude properties'); | ||
return location.longitude + ',' + location.latitude; | ||
}).join(';'); | ||
var profile = 'mapbox.driving', | ||
alternatives = true, | ||
geometry = 'geojson', | ||
instructions = 'text'; | ||
if (options.profile) { | ||
assert(typeof options.profile === 'string', 'profile option must be string'); | ||
profile = options.profile; | ||
} | ||
if (options.instructions) { | ||
assert(typeof options.instructions === 'string', 'instructions option must be string'); | ||
instructions = options.instructions; | ||
} | ||
if (options.geometry) { | ||
assert(typeof options.geometry === 'string', 'geometry option must be string'); | ||
geometry = options.geometry; | ||
} | ||
var url = resolveToString(constants.API_DIRECTIONS, { | ||
encodedWaypoints: encodedWaypoints, | ||
profile: profile | ||
}) + this.q({ | ||
instructions: instructions, | ||
geometry: geometry, | ||
alternatives: alternatives | ||
}); | ||
request(url, function(err, res) { | ||
callback(err, res.body); | ||
}); | ||
}; | ||
/** | ||
* Snap recorded location traces to roads and paths from OpenStreetMap. | ||
* Consult the [Map Matching API](https://www.mapbox.com/developers/api/map-matching/) | ||
* for more documentation. | ||
* | ||
* @param {Object} trace a single [GeoJSON](http://geojson.org/) | ||
* Feature with a LineString geometry, containing up to 100 positions. | ||
* @param {Object} [options={}] additional options meant to tune | ||
* the request | ||
* @param {string} [options.profile=mapbox.driving] the directions | ||
* profile, which determines how to prioritize different routes. | ||
* Options are `'mapbox.driving'`, which assumes transportation via an | ||
* automobile and will use highways, `'mapbox.walking'`, which avoids | ||
* streets without sidewalks, and `'mapbox.cycling'`, which prefers streets | ||
* with bicycle lanes and lower speed limits for transportation via | ||
* bicycle. | ||
* @param {string} [options.geometry=geojson] format for the returned | ||
* route. Options are `'geojson'`, `'polyline'`, or `false`: `polyline` | ||
* yields more compact responses which can be decoded on the client side. | ||
* [GeoJSON](http://geojson.org/), the default, is compatible with libraries | ||
* like [Mapbox GL](https://www.mapbox.com/mapbox-gl/), | ||
* Leaflet and [Mapbox.js](https://www.mapbox.com/mapbox.js/). `false` | ||
* omits the geometry entirely and only returns matched points. | ||
* @param {number} [options.gps_precision=4] An integer in meters indicating | ||
* the assumed precision of the used tracking device. Use higher | ||
* numbers (5-10) for noisy traces and lower numbers (1-3) for clean | ||
* traces. The default value is 4. | ||
* @param {Function} callback called with (err, results) | ||
* @returns {undefined} nothing, calls callback | ||
* @example | ||
* var mapboxClient = new MapboxClient('ACCESSTOKEN'); | ||
* mapboxClient.matching({ | ||
* "type": "Feature", | ||
* "properties": { | ||
* "coordTimes": [ | ||
* "2015-04-21T06:00:00Z", | ||
* "2015-04-21T06:00:05Z", | ||
* "2015-04-21T06:00:10Z", | ||
* "2015-04-21T06:00:15Z", | ||
* "2015-04-21T06:00:20Z" | ||
* ] | ||
* }, | ||
* "geometry": { | ||
* "type": "LineString", | ||
* "coordinates": [ | ||
* [ 13.418946862220764, 52.50055852688439 ], | ||
* [ 13.419011235237122, 52.50113000479732 ], | ||
* [ 13.419756889343262, 52.50171780290061 ], | ||
* [ 13.419885635375975, 52.50237416816131 ], | ||
* [ 13.420631289482117, 52.50294888790448 ] | ||
* ] | ||
* } | ||
* }, | ||
* function(err, res) { | ||
* // res is a document with directions | ||
* }); | ||
*/ | ||
MapboxClient.prototype.matching = function(trace, options, callback) { | ||
// permit the options argument to be omitted | ||
if (callback === undefined && typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
// typecheck arguments | ||
assert(geojsonhint.hint(trace).length === 0, 'trace must be valid GeoJSON'); | ||
assert(typeof options === 'object', 'options must be an object'); | ||
assert(typeof callback === 'function', 'callback must be a function'); | ||
var profile = 'mapbox.driving', | ||
gps_precision = 4, | ||
geometry = 'geojson'; | ||
if (options.gps_precision !== undefined) { | ||
assert(typeof options.gps_precision === 'number', 'gps_precision must be a number'); | ||
gps_precision = options.gps_precision; | ||
} | ||
if (options.profile) { | ||
assert(typeof options.profile === 'string', 'profile option must be string'); | ||
profile = options.profile; | ||
} | ||
if (options.geometry) { | ||
assert(typeof options.geometry === 'string', 'geometry option must be string'); | ||
geometry = options.geometry; | ||
} | ||
var url = resolveToString(constants.API_MATCHING, { | ||
profile: profile | ||
}) + this.q({ | ||
geometry: geometry, | ||
gps_precision: gps_precision | ||
}); | ||
request.post(url) | ||
.send(trace) | ||
.end(function(err, res) { | ||
callback(err, res.body); | ||
}); | ||
}; | ||
module.exports = MapboxClient; |
var compile = require('es6-template-strings/compile'); | ||
var API = 'https://api.tiles.mapbox.com/'; | ||
var APIV4 = API + 'v4/'; | ||
module.exports.API = API; | ||
module.exports.API_GEOCODER_FORWARD = compile(APIV4 + 'geocode/${dataset}/${encodeURIComponent(query)}.json'); | ||
module.exports.API_GEOCODER_REVERSE = compile(APIV4 + 'geocode/${dataset}/${location.longitude},${location.latitude}.json'); | ||
module.exports.API_DIRECTIONS = compile(APIV4 + 'directions/${profile}/${encodedWaypoints}.json'); | ||
module.exports.API_MATCHING = compile(API + 'matching/v4/${profile}.json'); | ||
module.exports.DEFAULT_ENDPOINT = 'https://api.mapbox.com'; | ||
module.exports.API_GEOCODER_FORWARD = compile('${endpoint}/v4/geocode/${dataset}/${encodeURIComponent(query)}.json?${query}'); | ||
module.exports.API_GEOCODER_REVERSE = compile('${endpoint}/v4/geocode/${dataset}/${location.longitude},${location.latitude}.json?${query}'); | ||
module.exports.API_DIRECTIONS = compile('${endpoint}/v4/directions/${profile}/${encodedWaypoints}.json?${query}'); | ||
module.exports.API_SURFACE = compile('${endpoint}/v4/surface/${mapid}.json?${query}'); | ||
module.exports.API_MATCHING = compile('${endpoint}/matching/v4/${profile}.json?${query}'); |
{ | ||
"name": "mapbox", | ||
"version": "0.4.0", | ||
"version": "0.5.0", | ||
"description": "interface to mapbox services", | ||
"main": "lib/client.js", | ||
"scripts": { | ||
"lint": "eslint --no-eslintrc -c .eslintrc lib test/*.js", | ||
"test": "tap --coverage test/*.js", | ||
"docs": "documentation . --format=md > API.md" | ||
"docs": "documentation . --format=md > API.md", | ||
"build": "browserify -s MapboxClient lib/client.js > dist/mapbox-sdk.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/mapbox/node-mapbox.git" | ||
"url": "https://github.com/mapbox/mapbox-sdk-js.git" | ||
}, | ||
@@ -23,10 +25,13 @@ "keywords": [ | ||
"bugs": { | ||
"url": "https://github.com/mapbox/node-mapbox/issues" | ||
"url": "https://github.com/mapbox/mapbox-sdk-js/issues" | ||
}, | ||
"homepage": "https://github.com/mapbox/node-mapbox", | ||
"homepage": "https://github.com/mapbox/mapbox-sdk-js", | ||
"devDependencies": { | ||
"documentation": "^2.1.0-alpha1", | ||
"browserify": "^11.0.0", | ||
"documentation": "^2.1.0-alpha2", | ||
"eslint": "^0.24.1", | ||
"geojsonhint": "^1.0.1", | ||
"tap": "^1.3.1" | ||
"geojsonhint": "^1.1.0", | ||
"polyline": "^0.1.0", | ||
"tap": "^1.3.1", | ||
"uglifyjs": "^2.4.10" | ||
}, | ||
@@ -36,4 +41,6 @@ "dependencies": { | ||
"geojsonhint": "^1.0.1", | ||
"superagent": "^1.2.0" | ||
"invariant": "^2.1.0", | ||
"superagent": "^1.2.0", | ||
"xtend": "^4.0.0" | ||
} | ||
} |
@@ -1,6 +0,6 @@ | ||
# node-mapbox | ||
# mapbox-sdk-js | ||
[![npm version](https://badge.fury.io/js/mapbox.svg)](http://badge.fury.io/js/mapbox) | ||
[![Build Status](https://travis-ci.org/mapbox/node-mapbox.svg?branch=master)](https://travis-ci.org/mapbox/node-mapbox) | ||
[![Coverage Status](https://coveralls.io/repos/mapbox/node-mapbox/badge.svg?branch=master&service=github)](https://coveralls.io/github/mapbox/node-mapbox?branch=master) | ||
[![Build Status](https://travis-ci.org/mapbox/mapbox-sdk-js.svg?branch=master)](https://travis-ci.org/mapbox/mapbox-sdk-js) | ||
[![Coverage Status](https://coveralls.io/repos/mapbox/mapbox-sdk-js/badge.svg?branch=master&service=github)](https://coveralls.io/github/mapbox/mapbox-sdk-js?branch=master) | ||
@@ -22,2 +22,4 @@ A [node.js](https://nodejs.org/) and browser JavaScript client | ||
[OpenStreetMap](https://www.openstreetmap.org/) data | ||
* [Surface API](https://www.mapbox.com/developers/api/surface/) | ||
* Interpolates values along lines. Useful for elevation traces. | ||
@@ -30,2 +32,28 @@ ## Installation | ||
## Usage | ||
Basic usage of the geocoder: | ||
```js | ||
var MapboxClient = require('mapbox'); | ||
var client = new MapboxClient('YOUR_ACCESS_TOKEN'); | ||
client.geocodeForward('Chester, NJ', function(err, res) { | ||
// res is the geocoding result as parsed JSON | ||
}); | ||
``` | ||
### 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: | ||
* geocoder: `require('mapbox/lib/services/geocoder')` | ||
* surface: `require('mapbox/lib/services/surface')` | ||
* matching: `require('mapbox/lib/services/matching')` | ||
* directions: `require('mapbox/lib/services/directions')` | ||
## [API](API.md) |
232
test/test.js
@@ -7,3 +7,2 @@ /* eslint no-shadow: 0 */ | ||
// path = require('path'), | ||
geojsonhint = require('geojsonhint'), | ||
MapboxClient = require('../'); | ||
@@ -35,223 +34,14 @@ | ||
test('MapboxClient#geocodeForward', function(t) { | ||
t.test('typecheck', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
t.throws(function() { | ||
client.geocodeForward(null); | ||
}, /query/); | ||
t.throws(function() { | ||
client.geocodeForward(1, function() {}); | ||
}, /query/); | ||
t.throws(function() { | ||
client.geocodeForward('foo', 1, function() {}); | ||
}, /options/); | ||
t.throws(function() { | ||
client.geocodeForward('foo', 1); | ||
}, /callback/); | ||
t.end(); | ||
}); | ||
t.test('no options', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.geocodeForward('Chester, New Jersey', function(err, results) { | ||
t.ifError(err); | ||
t.deepEqual(geojsonhint.hint(results), [], 'results are valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.test('dataset option', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.geocodeForward( | ||
'Chester, New Jersey', { dataset: 'mapbox.places' }, | ||
function(err, results) { | ||
t.ifError(err); | ||
t.deepEqual(geojsonhint.hint(results), [], 'results are valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.test('options.proximity', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.geocodeForward('Paris', { | ||
proximity: { latitude: 33.6875431, longitude: -95.4431142 } | ||
}, function(err, results) { | ||
t.ifError(err); | ||
t.deepEqual(geojsonhint.hint(results), [], 'results are valid'); | ||
t.end(); | ||
}); | ||
}); | ||
test('MapboxClient - custom endpoint', function(t) { | ||
t.throws(function() { | ||
var client = new MapboxClient('foo', 1); | ||
t.notOk(client); | ||
}, /options/); | ||
t.throws(function() { | ||
var client = new MapboxClient('foo', { endpoint: 1 }); | ||
t.notOk(client); | ||
}, /endpoint/); | ||
var customClient = new MapboxClient('foo', { endpoint: 'foo.bar' }); | ||
t.equal(customClient.endpoint, 'foo.bar', 'receives an endpoint from options'); | ||
t.end(); | ||
}); | ||
test('MapboxClient#geocodeReverse', function(t) { | ||
t.test('typecheck', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
t.throws(function() { | ||
client.geocodeReverse(null); | ||
}, /location/); | ||
t.throws(function() { | ||
client.geocodeReverse(1, function() {}); | ||
}, /location/); | ||
t.throws(function() { | ||
client.geocodeReverse('foo', 1, function() {}); | ||
}, /options/); | ||
t.throws(function() { | ||
client.geocodeReverse('foo', 1); | ||
}, /callback/); | ||
t.end(); | ||
}); | ||
t.test('no options', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.geocodeReverse({ latitude: 33.6875431, longitude: -95.4431142 }, function(err, results) { | ||
t.ifError(err); | ||
t.deepEqual(geojsonhint.hint(results), [], 'results are valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.test('dataset option', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.geocodeReverse( | ||
{ latitude: 33.6875431, longitude: -95.4431142 }, | ||
{ dataset: 'mapbox.places' }, | ||
function(err, results) { | ||
t.ifError(err); | ||
t.deepEqual(geojsonhint.hint(results), [], 'results are valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.end(); | ||
}); | ||
test('MapboxClient#getDirections', function(t) { | ||
t.test('typecheck', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
t.throws(function() { | ||
client.getDirections(null); | ||
}); | ||
t.throws(function() { | ||
client.getDirections(1, function() {}); | ||
}); | ||
t.throws(function() { | ||
client.getDirections('foo', 1, function() {}); | ||
}); | ||
t.throws(function() { | ||
client.getDirections('foo', 1); | ||
}); | ||
t.end(); | ||
}); | ||
t.test('no options', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.getDirections([ | ||
{ latitude: 33.6875431, longitude: -95.4431142 }, | ||
{ latitude: 33.6875431, longitude: -95.4831142 } | ||
], function(err, results) { | ||
t.ifError(err); | ||
t.deepEqual(geojsonhint.hint(results.origin), [], 'origin is valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.test('all options', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.getDirections([ | ||
{ latitude: 33.6875431, longitude: -95.4431142 }, | ||
{ latitude: 33.6875431, longitude: -95.4831142 } | ||
], { | ||
profile: 'mapbox.walking', | ||
instructions: 'html', | ||
alternatives: false, | ||
geometry: 'polyline' | ||
}, function(err, results) { | ||
t.ifError(err); | ||
t.deepEqual(geojsonhint.hint(results.origin), [], 'origin is valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.end(); | ||
}); | ||
test('MapboxClient#matching', function(t) { | ||
t.test('typecheck', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
t.throws(function() { | ||
client.matching(null); | ||
}); | ||
t.throws(function() { | ||
client.matching(1, function() {}); | ||
}); | ||
t.throws(function() { | ||
client.matching('foo', 1, function() {}); | ||
}); | ||
t.throws(function() { | ||
client.matching('foo', 1); | ||
}); | ||
t.end(); | ||
}); | ||
var sample = { | ||
'type': 'Feature', | ||
'properties': { | ||
'coordTimes': [ | ||
'2015-04-21T06:00:00Z', | ||
'2015-04-21T06:00:05Z', | ||
'2015-04-21T06:00:10Z', | ||
'2015-04-21T06:00:15Z', | ||
'2015-04-21T06:00:20Z' | ||
] | ||
}, | ||
'geometry': { | ||
'type': 'LineString', | ||
'coordinates': [ | ||
[ 13.418946862220764, 52.50055852688439 ], | ||
[ 13.419011235237122, 52.50113000479732 ], | ||
[ 13.419756889343262, 52.50171780290061 ], | ||
[ 13.419885635375975, 52.50237416816131 ], | ||
[ 13.420631289482117, 52.50294888790448 ] | ||
] | ||
} | ||
}; | ||
t.test('no options', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.matching(sample, function(err, results) { | ||
t.ifError(err); | ||
t.deepEqual(geojsonhint.hint(results), [], 'results are valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.test('all options', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.matching(sample, { | ||
gps_precision: 8, | ||
profile: 'mapbox.walking', | ||
geometry: 'polyline' | ||
}, function(err, results) { | ||
t.ifError(err); | ||
t.ok(results, 'results are valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.end(); | ||
}); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Uses eval
Supply chain riskPackage uses eval() which is a dangerous function. This prevents the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Environment variable access
Supply chain riskPackage accesses environment variables, which may be a sign of credential stuffing or data theft.
Found 2 instances in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
162155
30
3098
58
5
7
22
3
+ Addedinvariant@^2.1.0
+ Addedxtend@^4.0.0
+ Addedinvariant@2.2.4(transitive)
+ Addedjs-tokens@4.0.0(transitive)
+ Addedloose-envify@1.4.0(transitive)
+ Addedxtend@4.0.2(transitive)