Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mapbox

Package Overview
Dependencies
Maintainers
44
Versions
28
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mapbox - npm Package Compare versions

Comparing version 1.0.0-beta1 to 1.0.0-beta10

dist/mapbox-sdk.js

52

CHANGELOG.md

@@ -0,1 +1,53 @@

## 1.0.0-beta10
- **Bug** Fix bug preventing Geocoding service being used without an `options` parameter when using promise syntax. [#197](https://github.com/mapbox/mapbox-sdk-js/pull/197)
- **Feature** Geocoding `language`, `country` and `types` parameters can be passed as arrays as an alternative to comma separated strings. [#208](https://github.com/mapbox/mapbox-sdk-js/pull/208)
## 1.0.0-beta9
- **Feature** Add language parameter to geocoding API. [#174](https://github.com/mapbox/mapbox-sdk-js/issues/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](https://github.com/mapbox/mapbox-sdk-js/pull/177)
## 1.0.0-beta7
- **Deprecation** Renamed .getStaticURL() method to .getStaticClassicURL() [#152](https://github.com/mapbox/mapbox-sdk-js/pull/152)
- **Feature** Add Styles Static API [#152](https://github.com/mapbox/mapbox-sdk-js/pull/152)
- **Feature** Add Tilesets API [#165](https://github.com/mapbox/mapbox-sdk-js/pull/165)
- **Feature** Add Tokens API [#155](https://github.com/mapbox/mapbox-sdk-js/pull/155)
- **Feature** Add response.nextPage() method for pagination of list resources [#159](https://github.com/mapbox/mapbox-sdk-js/pull/159)
- **Bug** Avoid double URL encoding of geojson static overlays [#156](https://github.com/mapbox/mapbox-sdk-js/pull/156)
- **Update** Remove start and reverse opts for datasets listings
- **Update** Clarify account/profile property for Directions API [#150](https://github.com/mapbox/mapbox-sdk-js/pull/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](https://github.com/mapbox/mapbox-sdk-js/pull/126)
- **Bug** Install Promise polyfill only when needed. [#122](https://github.com/mapbox/mapbox-sdk-js/pull/122)
- **Update** Update Map Matching to `v5`. [#128](https://github.com/mapbox/mapbox-sdk-js/pull/128)
- **Update** Update Directions to `v5`. [#68](https://github.com/mapbox/mapbox-sdk-js/pull/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

@@ -2,0 +54,0 @@

11

lib/callbackify.js
'use strict';
// install ES6 Promise polyfill
require('./promise');
var interceptor = require('rest/interceptor');

@@ -7,7 +10,6 @@

success: function (response) {
var request = response && response.request;
var callback = request && request.callback;
var callback = response && response.callback;
if (typeof callback === 'function') {
callback(null, response.entity);
callback(null, response.entity, response);
}

@@ -18,4 +20,3 @@

error: function (response) {
var request = response && response.request;
var callback = request && request.callback;
var callback = response && response.callback;

@@ -22,0 +23,0 @@ if (typeof callback === 'function') {

'use strict';
// install ES6 Promise polyfill
require('./promise');
var rest = require('rest');
var callbackify = require('./callbackify');

@@ -12,7 +14,9 @@ // rest.js client with MIME support

.wrap(require('rest/interceptor/mime'), { mime: 'application/json' })
.wrap(require('rest/interceptor/template'))
.wrap(require('rest/interceptor/defaultRequest'), {
params: { access_token: config.accessToken }
})
.wrap(require('rest/interceptor/template'))
.wrap(callbackify);
.wrap(require('./paginator'), { access_token: config.accessToken })
.wrap(require('./standard_response'))
.wrap(require('./callbackify'));
};

@@ -1,43 +0,2 @@

// We keep all of the constants that declare endpoints in one
// place, so that we could concievably update this for API layout
// revisions.
module.exports.DEFAULT_ENDPOINT = 'https://api.mapbox.com';
module.exports.API_GEOCODING_FORWARD = '/geocoding/v5/{dataset}/{query}.json{?proximity,country,types,bbox}';
module.exports.API_GEOCODING_REVERSE = '/geocoding/v5/{dataset}/{longitude},{latitude}.json{?types}';
module.exports.API_DIRECTIONS = '/v4/directions/{profile}/{encodedWaypoints}.json{?alternatives,instructions,geometry,steps}';
module.exports.API_DISTANCE = '/distances/v1/mapbox/{profile}';
module.exports.API_SURFACE = '/v4/surface/{mapid}.json{?layer,fields,points,geojson,interpolate,encoded_polyline}';
module.exports.API_UPLOADS = '/uploads/v1/{owner}';
module.exports.API_UPLOAD = '/uploads/v1/{owner}/{upload}';
module.exports.API_UPLOAD_CREDENTIALS = '/uploads/v1/{owner}/credentials';
module.exports.API_MATCHING = '/matching/v4/{profile}.json';
module.exports.API_DATASET_DATASETS = '/datasets/v1/{owner}';
module.exports.API_DATASET_DATASET = '/datasets/v1/{owner}/{dataset}';
module.exports.API_DATASET_FEATURES = '/datasets/v1/{owner}/{dataset}/features{?reverse,limit,start}';
module.exports.API_DATASET_FEATURE = '/datasets/v1/{owner}/{dataset}/features/{id}';
module.exports.API_TILESTATS_STATISTICS = '/tilestats/v1/{owner}/{tileset}';
module.exports.API_TILESTATS_LAYER = '/tilestats/v1/{owner}/{tileset}/{layer}';
module.exports.API_TILESTATS_ATTRIBUTE = '/tilestats/v1/{owner}/{tileset}/{layer}/{attribute}';
module.exports.API_STATIC = '/v4/{mapid}{+overlay}/{+xyz}/{width}x{height}{+retina}{.format}{?api_token}';
module.exports.API_STYLES_LIST = '/styles/v1/{owner}';
module.exports.API_STYLES_CREATE = '/styles/v1/{owner}';
module.exports.API_STYLES_READ = '/styles/v1/{owner}/{styleid}';
module.exports.API_STYLES_UPDATE = '/styles/v1/{owner}/{styleid}';
module.exports.API_STYLES_DELETE = '/styles/v1/{owner}/{styleid}';
module.exports.API_STYLES_EMBED = '/styles/v1/{owner}/{styleid}.html{?zoomwheel,title,access_token}';
module.exports.API_STYLES_SPRITE = '/styles/v1/{owner}/{styleid}/sprite{+retina}{.format}';
module.exports.API_STYLES_SPRITE_ADD_ICON = '/styles/v1/{owner}/{styleid}/sprite/{iconName}';
module.exports.API_STYLES_SPRITE_DELETE_ICON = '/styles/v1/{owner}/{styleid}/sprite/{iconName}';
module.exports.API_STYLES_FONT_GLYPH_RANGES = '/fonts/v1/{owner}/{font}/{start}-{end}.pbf'
module.exports.API_STYLES_SPRITE_DELETE_ICON = '/styles/v1/{owner}/{styleid}/sprite/{iconName}';

@@ -54,3 +54,3 @@ 'use strict';

function encodeGeoJSON(geojson) {
var encoded = encodeURIComponent(JSON.stringify(geojson));
var encoded = JSON.stringify(geojson);
invariant(encoded.length < 4096, 'encoded GeoJSON must be shorter than 4096 characters long');

@@ -57,0 +57,0 @@ return 'geojson(' + encoded + ')';

@@ -12,5 +12,10 @@ 'use strict';

var MapboxDatasets = require('./services/datasets');
var MapboxDistance = require('./services/distance');
var MapboxMatrix = require('./services/matrix');
var MapboxTilestats = require('./services/tilestats');
var MapboxStyles = require('./services/styles');
var MapboxStatic = require('./services/static');
var MapboxTilesets = require('./services/tilesets');
var MapboxTokens = require('./services/tokens');
/**

@@ -42,7 +47,11 @@ * The JavaScript API to Mapbox services

MapboxDirections.prototype,
MapboxDistance.prototype,
MapboxMatrix.prototype,
MapboxMatching.prototype,
MapboxDatasets.prototype,
MapboxUploads.prototype,
MapboxTilestats.prototype
MapboxTilestats.prototype,
MapboxStyles.prototype,
MapboxStatic.prototype,
MapboxTilesets.prototype,
MapboxTokens.prototype
);

@@ -49,0 +58,0 @@

'use strict';
var invariant = require('../../vendor/invariant'),
hat = require('../../vendor/hat'),
makeService = require('../make_service'),
constants = require('../constants');
var invariant = require('../../vendor/invariant');
var hat = require('../../vendor/hat');
var makeService = require('../make_service');
var Datasets = module.exports = makeService('MapboxDatasets');
/**
* @class MapboxDatasets
*/
var MapboxDatasets = module.exports = makeService('MapboxDatasets');
var API_DATASET_DATASETS = '/datasets/v1/{owner}{?access_token,limit,fresh}';
var API_DATASET_DATASET = '/datasets/v1/{owner}/{dataset}{?access_token}';
var API_DATASET_FEATURES = '/datasets/v1/{owner}/{dataset}/features{?access_token,limit}';
var API_DATASET_FEATURE = '/datasets/v1/{owner}/{dataset}/features/{id}{?access_token}';
/**

@@ -14,4 +21,7 @@ * To retrieve a listing of datasets for a particular account.

*
* @param {Object} [opts={}] list options
* @param {number} opts.limit limit, for paging
* @param {boolean} opts.fresh whether to request fresh data
* @param {Function} callback called with (err, datasets)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -42,10 +52,16 @@ * var MapboxClient = require('mapbox');

*/
Datasets.prototype.listDatasets = function(callback) {
MapboxDatasets.prototype.listDatasets = function(opts, callback) {
if (typeof opts === 'function') {
callback = opts;
opts = {};
}
return this.client({
path: constants.API_DATASET_DATASETS,
path: API_DATASET_DATASETS,
params: {
limit: opts.limit,
fresh: opts.fresh,
owner: this.owner
},
callback: callback
}).entity();
});
};

@@ -61,3 +77,3 @@

* @param {Function} callback called with (err, dataset)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -78,3 +94,3 @@ * var MapboxClient = require('mapbox');

*/
Datasets.prototype.createDataset = function(options, callback) {
MapboxDatasets.prototype.createDataset = function(options, callback) {
// permit the options argument to be omitted

@@ -89,3 +105,3 @@ if (callback === undefined && typeof options === 'function') {

return this.client({
path: constants.API_DATASET_DATASETS,
path: API_DATASET_DATASETS,
params: {

@@ -96,3 +112,3 @@ owner: this.owner

callback: callback
}).entity();
});
};

@@ -106,3 +122,3 @@

* @param {Function} callback called with (err, dataset)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -123,7 +139,7 @@ * var MapboxClient = require('mapbox');

*/
Datasets.prototype.readDataset = function(dataset, callback) {
MapboxDatasets.prototype.readDataset = function(dataset, callback) {
invariant(typeof dataset === 'string', 'dataset must be a string');
return this.client({
path: constants.API_DATASET_DATASET,
path: API_DATASET_DATASET,
params: {

@@ -134,3 +150,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -147,3 +163,3 @@

* @param {Function} callback called with (err, dataset)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -165,3 +181,3 @@ * var MapboxClient = require('mapbox');

*/
Datasets.prototype.updateDataset = function(dataset, options, callback) {
MapboxDatasets.prototype.updateDataset = function(dataset, options, callback) {
invariant(typeof dataset === 'string', 'dataset must be a string');

@@ -172,3 +188,3 @@ invariant(typeof options === 'object', 'options must be an object');

return this.client({
path: constants.API_DATASET_DATASET,
path: API_DATASET_DATASET,
params: {

@@ -181,3 +197,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -191,3 +207,3 @@

* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -200,7 +216,7 @@ * var MapboxClient = require('mapbox');

*/
Datasets.prototype.deleteDataset = function(dataset, callback) {
MapboxDatasets.prototype.deleteDataset = function(dataset, callback) {
invariant(typeof dataset === 'string', 'dataset must be a string');
return this.client({
path: constants.API_DATASET_DATASET,
path: API_DATASET_DATASET,
params: {

@@ -212,3 +228,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -222,7 +238,5 @@

* @param {object} [options] an object for passing pagination arguments
* @param {boolean} [options.reverse] Set to `true` to reverse the default sort order of the listing.
* @param {number} [options.limit] The maximum number of objects to return. This value must be between 1 and 100. The API will attempt to return the requested number of objects, but receiving fewer objects does not necessarily signal the end of the collection. Receiving an empty page of results is the only way to determine when you are at the end of a collection.
* @param {string} [options.start] The object id that acts as the cursor for pagination and defines your location in the collection. This argument is exclusive so the object associated with the id provided to the start argument will not be included in the response.
* @param {Function} callback called with (err, collection)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -252,3 +266,3 @@ * var MapboxClient = require('mapbox');

*/
Datasets.prototype.listFeatures = function(dataset, options, callback) {
MapboxDatasets.prototype.listFeatures = function(dataset, options, callback) {
// permit the options argument to be omitted

@@ -268,7 +282,2 @@ if (callback === undefined && typeof options === 'function') {

if (options.reverse) {
invariant(typeof options.reverse === 'boolean', 'reverse option must be a boolean');
params.reverse = options.reverse;
}
if (options.limit) {

@@ -279,12 +288,7 @@ invariant(typeof options.limit === 'number', 'limit option must be a number');

if (options.start) {
invariant(typeof options.start === 'string', 'start option must be a string');
params.start = options.start;
}
return this.client({
path: constants.API_DATASET_FEATURES,
path: API_DATASET_FEATURES,
params: params,
callback: callback
}).entity();
});
};

@@ -307,3 +311,3 @@

* @param {Function} callback called with (err, feature)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -367,3 +371,3 @@ * // Insert a brand new feature without an id

*/
Datasets.prototype.insertFeature = function(feature, dataset, callback) {
MapboxDatasets.prototype.insertFeature = function(feature, dataset, callback) {
invariant(typeof dataset === 'string', 'dataset must be a string');

@@ -375,3 +379,3 @@

return this.client({
path: constants.API_DATASET_FEATURE,
path: API_DATASET_FEATURE,
params: {

@@ -385,3 +389,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -396,3 +400,3 @@

* @param {Function} callback called with (err, feature)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -416,3 +420,3 @@ * var MapboxClient = require('mapbox');

*/
Datasets.prototype.readFeature = function(id, dataset, callback) {
MapboxDatasets.prototype.readFeature = function(id, dataset, callback) {
invariant(typeof id === 'string', 'id must be a string');

@@ -422,3 +426,3 @@ invariant(typeof dataset === 'string', 'dataset must be a string');

return this.client({
path: constants.API_DATASET_FEATURE,
path: API_DATASET_FEATURE,
params: {

@@ -430,3 +434,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -438,6 +442,6 @@

*
* @param {string} id the `id` of the feature to read
* @param {string} id the `id` of the feature to delete
* @param {string} dataset the id for an existing dataset
* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -450,3 +454,3 @@ * var MapboxClient = require('mapbox');

*/
Datasets.prototype.deleteFeature = function(id, dataset, callback) {
MapboxDatasets.prototype.deleteFeature = function(id, dataset, callback) {
invariant(typeof id === 'string', 'id must be a string');

@@ -456,3 +460,3 @@ invariant(typeof dataset === 'string', 'dataset must be a string');

return this.client({
path: constants.API_DATASET_FEATURE,
path: API_DATASET_FEATURE,
params: {

@@ -465,112 +469,2 @@ owner: this.owner,

callback: callback
}).entity();
};
/**
* Perform a batch of inserts, updates, and deletes to a dataset in a single combined request.
* This request requires an access token with the datasets:write scope.
* There are a number of limits to consider when making this request:
* - you can send a total of 100 changes (sum of puts + deletes) in a single request
* - any single feature cannot be larger than 500 KB
* - the dataset must not exceed 2000 total features
* - the dataset must not exceed a total of 5 MB
*
* @param {object} update an object describing features in insert and/or delete
* @param {Array<object>} [update.put] features to insert. Each feature must be a valid GeoJSON feature per http://geojson.org/geojson-spec.html#feature-objects
* @param {Array<string>} [update.delete] ids of features to delete
* @param {string} dataset the id for an existing dataset
* @param {Function} callback called with (err, results)
* @returns {undefined} nothing, calls callback
* @example
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* var inserts = [
* {
* "id": "1",
* "type": "Feature",
* "properties": {
* "name": "Null Island"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [0, 0]
* }
* },
* {
* "id": "2",
* "type": "Feature",
* "properties": {
* "name": "Offshore from Null Island"
* },
* "geometry": {
* "type": "Point",
* "coordinates": [0.01, 0.01]
* }
* }
* ];
* var deletes =[
* 'feature-id-1',
* 'feature-id-2'
* ];
* client.batchFeatureUpdate({ put: inserts, delete: deletes }, dataset, function(err, results) {
* console.log(results);
* // {
* // "put": [
* // {
* // "id": {feature-id},
* // "type": "Feature",
* // "properties": {
* // "name": "Null Island"
* // },
* // "geometry": {
* // "type": "Point",
* // "coordinates": [0, 0]
* // }
* // },
* // {
* // "id": {feature-id},
* // "type": "Feature",
* // "properties": {
* // "name": "Offshore from Null Island"
* // },
* // "geometry": {
* // "type": "Point",
* // "coordinates": [0.01, 0.01]
* // }
* // }
* // ],
* // "delete": [
* // "feature-id-1",
* // "feature-id-2"
* // ]
* // }
* });
*/
Datasets.prototype.batchFeatureUpdate = function(update, dataset, callback) {
invariant(typeof update === 'object', 'update must be an object');
invariant(typeof dataset === 'string', 'dataset must be a string');
var inserts = update.put || [];
var deletes = update.delete || [];
invariant(
inserts.every(function(feature) { return feature.id; }),
'inserted GeoJSON features must include ids'
);
invariant(
deletes.every(function(id) { return typeof id === 'string'; }),
'update.delete must be an array of strings'
);
return this.client({
path: constants.API_DATASET_FEATURES,
params: {
owner: this.owner,
dataset: dataset
},
method: 'post',
entity: { put: inserts, delete: deletes },
callback: callback
}).entity();
};
})};
'use strict';
var invariant = require('../../vendor/invariant'),
formatPoints = require('../format_points'),
makeService = require('../make_service'),
constants = require('../constants');
var invariant = require('../../vendor/invariant');
var formatPoints = require('../format_points');
var makeService = require('../make_service');
/**
* @class MapboxDirections
*/
var MapboxDirections = makeService('MapboxDirections');
var API_DIRECTIONS = '/directions/v5/{account}/{profile}/{encodedWaypoints}.json{?access_token,alternatives,geometries,overview,radiuses,steps,continue_straight,bearings}';
/**
* Find directions from A to B, or between any number of locations.
* Consult the [Mapbox Directions API](https://www.mapbox.com/developers/api/directions/)
* Consult the [Mapbox Directions API](https://www.mapbox.com/api-documentation/#directions)
* for more documentation.

@@ -20,14 +24,15 @@ *

* the request
* @param {string} [options.profile=mapbox.driving] the directions
* @param {string} [options.profile=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
* Options are `'driving-traffic'` for automotive routing which factors
* in current and historic traffic conditions to avoid slowdowns,
* `'driving'`, which assumes transportation via an
* automobile and will use highways, `'walking'`, which avoids
* streets without sidewalks, and `'cycling'`, which prefers streets
* with bicycle lanes and lower speed limits for transportation via
* bicycle.
* @param {string} [options.account=mapbox] Account for the profile.
* @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
* @param {string} [options.geometries=geojson] format for the returned
* route. Options are `'geojson'`, `'polyline'`, or `false`: `polyline`

@@ -39,5 +44,33 @@ * yields more compact responses which can be decoded on the client side.

* omits the geometry entirely and only returns instructions.
* @param {string} [options.overview=simplified] type of returned overview
* geometry. Can be `full` (the most detailed geometry available), `simplified`
* (a simplified version of the full geometry), or `false`.
* @param {Array<number|string>} [options.radiuses] an array of integers in meters
* indicating the maximum distance each coordinate is allowed to move when
* snapped to a nearby road segment. There must be as many radiuses as there
* are coordinates in the request. Values can be any number greater than `0` or
* they can be the string `unlimited`. If no routable road is found within the
* radius, a `NoSegment` error is returned.
* @param {boolean} [options.steps=false] whether to return steps and
* turn-by-turn instructions. Can be `true` or `false`.
* @param {boolean} [options.continue_straight] sets allowed direction of travel
* when departing intermediate waypoints. If `true` the route will continue in
* the same direction of travel. If `false` the route may continue in the
* opposite direction of travel. Defaults to `true` for the `driving` profile
* and `false` for the `walking` and `cycling` profiles.
* @param {Array<Array>} [options.bearings] used to filter the road
* segment the waypoint will be placed on by direction and dictates the angle
* of approach. This option should always be used in conjunction with the
* `radiuses` option. The parameter takes two values per waypoint: the first is
* an angle clockwise from true north between `0` and `360`. The second is the
* range of degrees the angle can deviate by. We recommend a value of `45` or
* `90` for the range, as bearing measurements tend to be inaccurate. This is
* useful for making sure we reroute vehicles on new routes that continue
* traveling in their current direction. A request that does this would provide
* bearing and radius values for the first waypoint and leave the remaining
* values empty.If provided, the list of bearings must be the same length as
* the list of waypoints, but you can skip a coordinate and show its position
* by providing an empty array.
* @param {Function} callback called with (err, results)
* @returns {undefined} nothing, calls callback
* @memberof MapboxClient
* @returns {Promise} response
* @example

@@ -58,8 +91,7 @@ * var mapboxClient = new MapboxClient('ACCESSTOKEN');

* ], {
* profile: 'mapbox.walking',
* instructions: 'html',
* profile: 'walking',
* alternatives: false,
* geometry: 'polyline'
* }, function(err, results) {
* console.log(results.origin);
* console.log(results);
* });

@@ -83,47 +115,67 @@ */

var profile = 'mapbox.driving',
alternatives = true,
steps = true,
geometry = 'geojson',
instructions = 'text';
var params = {
encodedWaypoints: encodedWaypoints,
profile: 'driving',
account: 'mapbox',
alternatives: true,
steps: true,
geometries: 'geojson'
};
if (options.profile) {
invariant(typeof options.profile === 'string', 'profile option must be string');
profile = options.profile;
params.profile = options.profile;
}
if (options.account) {
invariant(typeof options.account === 'string', 'account option must be string');
params.account = options.account;
}
if (typeof options.alternatives !== 'undefined') {
invariant(typeof options.alternatives === 'boolean', 'alternatives option must be boolean');
alternatives = options.alternatives;
params.alternatives = options.alternatives;
}
if (options.radiuses) {
invariant(Array.isArray(options.radiuses), 'radiuses must be an array');
invariant(options.radiuses.length === waypoints.length, 'There must be as many radiuses as there are waypoints in the request');
params.radiuses = options.radiuses.join(';');
}
if (typeof options.steps !== 'undefined') {
invariant(typeof options.steps === 'boolean', 'steps option must be boolean');
steps = options.steps;
params.steps = options.steps;
}
if (options.geometry) {
invariant(typeof options.geometry === 'string', 'geometry option must be string');
geometry = options.geometry;
var allowedGeometries = ['polyline', 'geojson'];
if (options.geometries) {
invariant(allowedGeometries.indexOf(options.geometries) !== -1, 'geometries option must be ' + allowedGeometries);
params.geometries = options.geometries;
}
if (options.instructions) {
invariant(typeof options.instructions === 'string', 'instructions option must be string');
instructions = options.instructions;
var allowedOverviews = ['simplified', 'full'];
if (options.overview) {
invariant(allowedOverviews.indexOf(options.overview) !== -1, 'overview option must be ' + allowedOverviews);
params.overview = options.overview;
}
if (typeof options.continue_straight !== 'undefined') {
invariant(typeof options.continue_straight === 'boolean', 'continue_straight option must be boolean');
params.continue_straight = options.continue_straight;
}
if (options.bearings) {
invariant(Array.isArray(options.radiuses), 'bearings must be an array');
invariant(options.bearings.length === waypoints.length, 'There must be as many bearings as there are waypoints in the request');
params.bearings = options.bearings.join(';');
}
return this.client({
path: constants.API_DIRECTIONS,
params: {
encodedWaypoints: encodedWaypoints,
profile: profile,
instructions: instructions,
geometry: geometry,
alternatives: alternatives,
steps: steps
},
path: API_DIRECTIONS,
params: params,
callback: callback
}).entity();
});
};
module.exports = MapboxDirections;
'use strict';
var invariant = require('../../vendor/invariant'),
makeService = require('../make_service'),
constants = require('../constants');
var invariant = require('../../vendor/invariant');
var makeService = require('../make_service');
/**
* @class MapboxGeocoding
*/
var MapboxGeocoding = makeService('MapboxGeocoding');
var API_GEOCODING_FORWARD = '/geocoding/v5/{dataset}/{query}.json{?access_token,proximity,country,types,bbox,limit,autocomplete,language}';
var API_GEOCODING_REVERSE = '/geocoding/v5/{dataset}/{longitude},{latitude}.json{?access_token,types,limit,language}';
var REVERSE_GEOCODING_PRECISION = 5;

@@ -34,8 +39,11 @@ var FORWARD_GEOCODING_PROXIMITY_PRECISION = 3;

* Search results will be limited to the bounding box.
* @param {string} options.types a comma seperated list of types that filter
* @param {Array<string>|string} options.language Specify the language to use for response text and, for forward geocoding, query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, as an array or separated by commas.
* @param {Array<string>|string} options.types an array or comma seperated list of types that filter
* results to match those specified. See https://www.mapbox.com/developers/api/geocoding/#filter-type
* for available types.
* @param {string} options.country a comma separated list of country codes to
* @param {number} [options.limit=5] is the maximum number of results to return, between 1 and 10 inclusive.
* Some very specific queries may return fewer results than the limit.
* @param {Array<string>|string} options.country an array or comma separated list of country codes to
* limit results to specified country or countries.
* @param {boolean=true} options.autocomplete whether to include results that include
* @param {boolean} [options.autocomplete=true] whether to include results that include
* the query only as a prefix. This is useful for UIs where users type

@@ -48,4 +56,3 @@ * values, but if you have complete addresses as input, you'll want to turn it off

* @param {Function} callback called with (err, results)
* @returns {undefined} nothing, calls callback
* @memberof MapboxClient
* @returns {Promise} response
* @example

@@ -70,5 +77,4 @@ * var mapboxClient = new MapboxClient('ACCESSTOKEN');

MapboxGeocoding.prototype.geocodeForward = function(query, options, callback) {
// permit the options argument to be omitted
if (callback === undefined && typeof options === 'function') {
// permit the options argument to be omitted, or the options + callback args to be omitted if using promise syntax
if (callback === undefined && (options === undefined || typeof options === 'function')) {
callback = options;

@@ -81,3 +87,3 @@ options = {};

if (options.dataset !== 'mapbox.places-permanent') {
throw new Error('Batch geocoding is only available with the mapbox.places-permanent endpoint. See https://mapbox.com/api-documentation/#batch-requests for details')
throw new Error('Batch geocoding is only available with the mapbox.places-permanent endpoint. See https://mapbox.com/api-documentation/#batch-requests for details');
} else {

@@ -95,3 +101,2 @@ query = query.join(';');

var autocomplete = true;
var precision = FORWARD_GEOCODING_PROXIMITY_PRECISION;

@@ -117,5 +122,11 @@ if (options.precision) {

'bbox must be an array with numeric values in the form [minX, minY, maxX, maxY]');
queryOptions.bbox = options.bbox[0] + "," + options.bbox[1] + "," + options.bbox[2] + "," + options.bbox[3];
queryOptions.bbox = options.bbox[0] + ',' + options.bbox[1] + ',' + options.bbox[2] + ',' + options.bbox[3];
}
if (options.limit) {
invariant(typeof options.limit === 'number',
'limit must be a number');
queryOptions.limit = options.limit;
}
if (options.dataset) {

@@ -127,9 +138,26 @@ invariant(typeof options.dataset === 'string', 'dataset option must be string');

if (options.country) {
invariant(typeof options.country === 'string', 'country option must be string');
queryOptions.country = options.country;
if (Array.isArray(options.country)) {
queryOptions.country = options.country.join(',');
} else {
invariant(typeof options.country === 'string', 'country option must be an array or string');
queryOptions.country = options.country;
}
}
if (options.language) {
if (Array.isArray(options.language)) {
queryOptions.language = options.language.join(',');
} else {
invariant(typeof options.language === 'string', 'language option must be an array or string');
queryOptions.language = options.language;
}
}
if (options.types) {
invariant(typeof options.types === 'string', 'types option must be string');
queryOptions.types = options.types;
if (Array.isArray(options.types)) {
queryOptions.types = options.types.join(',');
} else {
invariant(typeof options.types === 'string', 'types option must be an array or string');
queryOptions.types = options.types;
}
}

@@ -143,6 +171,6 @@

return this.client({
path: constants.API_GEOCODING_FORWARD,
path: API_GEOCODING_FORWARD,
params: queryOptions,
callback: callback
}).entity();
});
};

@@ -152,3 +180,3 @@

* Given a location, determine what geographical features are located
* there. This uses the [Mapbox Geocoding API](https://www.mapbox.com/developers/api/geocoding/).
* there. This uses the [Mapbox Geocoding API](https://www.mapbox.com/api-documentation/#geocoding).
*

@@ -160,5 +188,9 @@ * @param {Object} location the geographical point to search

* the request.
* @param {string} options.types a comma seperated list of types that filter
* results to match those specified. See https://www.mapbox.com/developers/api/geocoding/#filter-type
* @param {Array<string>|string} options.language Specify the language to use for response text and, for forward geocoding, query result weighting. Options are IETF language tags comprised of a mandatory ISO 639-1 language code and optionally one or more IETF subtags for country or script. More than one value can also be specified, separated by commas or as an array.
* @param {Array<string>|string} options.types an array or comma seperated list of types that filter
* results to match those specified. See
* https://www.mapbox.com/api-documentation/#retrieve-places-near-a-location
* for available types.
* @param {number} [options.limit=1] is the maximum number of results to return, between 1 and 5
* inclusive. Requires a single options.types to be specified (see example).
* @param {string} [options.dataset=mapbox.places] the desired data to be

@@ -169,5 +201,5 @@ * geocoded against. The default, mapbox.places, does not permit unlimited

* @param {Function} callback called with (err, results)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example
* var mapboxClient = new MapboxGeocoding('ACCESSTOKEN');
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.geocodeReverse(

@@ -178,7 +210,13 @@ * { latitude: 33.6875431, longitude: -95.4431142 },

* });
* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* mapboxClient.geocodeReverse(
* { latitude: 33.6875431, longitude: -95.4431142, options: { types: 'address', limit: 3 } },
* function(err, res) {
* // res is a GeoJSON document with up to 3 geocoding matches
* });
*/
MapboxGeocoding.prototype.geocodeReverse = function(location, options, callback) {
// permit the options argument to be omitted
if (callback === undefined && typeof options === 'function') {
// permit the options argument to be omitted, or the options + callback args to be omitted if using promise syntax
if (callback === undefined && (options === undefined || typeof options === 'function')) {
callback = options;

@@ -189,3 +227,3 @@ options = {};

// typecheck arguments
invariant(typeof location === 'object', 'location must be an object');
invariant((typeof location === 'object' && location !== null), 'location must be an object');
invariant(typeof options === 'object', 'options must be an object');

@@ -212,7 +250,26 @@

if (options.language) {
if (Array.isArray(options.language)) {
queryOptions.language = options.language.join(',');
} else {
invariant(typeof options.language === 'string', 'language option must be an array or string');
queryOptions.language = options.language;
}
}
if (options.types) {
invariant(typeof options.types === 'string', 'types option must be string');
queryOptions.types = options.types;
if (Array.isArray(options.types)) {
queryOptions.types = options.types.join(',');
} else {
invariant(typeof options.types === 'string', 'types option must be an array or string');
queryOptions.types = options.types;
}
}
if (options.limit) {
invariant(typeof options.limit === 'number', 'limit option must be a number');
invariant(options.types.split(',').length === 1, 'a single type must be specified to use the limit option');
queryOptions.limit = options.limit;
}
queryOptions.longitude = roundTo(location.longitude, precision);

@@ -222,8 +279,8 @@ queryOptions.latitude = roundTo(location.latitude, precision);

return this.client({
path: constants.API_GEOCODING_REVERSE,
path: API_GEOCODING_REVERSE,
params: queryOptions,
callback: callback
}).entity();
});
};
module.exports = MapboxGeocoding;
'use strict';
var invariant = require('../../vendor/invariant'),
makeService = require('../make_service'),
constants = require('../constants');
var invariant = require('../../vendor/invariant');
var makeService = require('../make_service');
/**
* @class MapboxMatching
*/
var MapboxMatching = makeService('MapboxMatching');
var API_MATCHING = '/matching/v5/{account}/{profile}/{coordinates}.json{?access_token,geometries,radiuses,steps,overview,timestamps,annotations}';
/**
* Snap recorded location traces to roads and paths from OpenStreetMap.
* Consult the [Map Matching API](https://www.mapbox.com/developers/api/map-matching/)
* Consult the [Map Matching API](https://www.mapbox.com/api-documentation/#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 {Array<Array<number>>} coordinates an array of coordinate pairs
* in [longitude, latitude] order. Up to 100 coordinates can be specified.
* @param {Object} [options={}] additional options meant to tune
* the request
* @param {string} [options.profile=mapbox.driving] the directions
* @param {string} [options.profile=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
* Options are `'driving'`, which assumes transportation via an
* automobile and will use highways, `'walking'`, which avoids
* streets without sidewalks, and `'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 {string} [options.geometries=geojson] format of the returned geometry.
* Allowed values are: `'geojson'` (as LineString), `'polyline'` with
* precision 5, `'polyline6'`. `'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/).
* @param {Array<number>} [options.radiuses] an array of integers in meters
* indicating the assumed precision of the used tracking device. There must be
* as many radiuses as there are coordinates in the request. Values can be a
* number between 0 and 30. Use higher numbers (20-30) for noisy traces and
* lower numbers (1-10) for clean traces. The default value is 5.
* @param {boolean} [options.steps=false] Whether to return steps and
* turn-by-turn instructions. Can be `true` or `false`.
* @param {string|boolean} [options.overview=simplified] type of returned
* overview geometry. Can be `'full'` (the most detailed geometry available),
* `'simplified'` (a simplified version of the full geometry), or `false`.
* @param {Array<number>} [options.timestamps] an array of timestamps
* corresponding to each coordinate provided in the request; must be numbers in
* [Unix time](https://en.wikipedia.org/wiki/Unix_time)
* (seconds since the Unix epoch). There must be as many timestamps as there
* are coordinates in the request.
* @param {Array<string>} [options.annotations] an array of fields that return
* additional metadata for each coordinate along the match geometry. Can be any
* of `'duration'`, `'distance'`, or `'nodes'`.
* @param {Function} callback called with (err, results)
* @returns {undefined} nothing, calls callback
* @memberof MapboxClient
* @returns {Promise} response
* @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.matching([
* [-95.4431142, 33.6875431],
* [-95.0431142, 33.6875431],
* [-95.0431142, 33.0875431],
* [-95.0431142, 33.0175431],
* [-95.4831142, 33.6875431]
* ], {
* overview: 'full'
* }, function(err, res) {
* // res is a match response object
* });
*/
MapboxMatching.prototype.matching = function(trace, options, callback) {
MapboxMatching.prototype.matching = function(coordinates, options, callback) {

@@ -76,38 +79,58 @@ // permit the options argument to be omitted

// typecheck arguments
invariant(typeof trace === 'object', 'trace must be an object');
invariant(typeof options === 'object', 'options must be an object');
invariant(Array.isArray(coordinates), 'coordinates must be an array');
var profile = 'mapbox.driving',
gps_precision = 4,
geometry = 'geojson';
var params = {
profile: 'driving',
account: 'mapbox',
geometries: 'geojson',
coordinates: coordinates.join(';')
};
if (options.profile) {
invariant(typeof options.profile === 'string', 'profile option must be string');
params.profile = options.profile;
}
if (options.gps_precision !== undefined) {
invariant(typeof options.gps_precision === 'number', 'gps_precision must be a number');
gps_precision = options.gps_precision;
var allowedGeometries = ['polyline', 'geojson'];
if (options.geometries) {
invariant(allowedGeometries.indexOf(options.geometries) !== -1, 'geometries option must be ' + allowedGeometries);
params.geometries = options.geometries;
}
if (options.profile) {
invariant(typeof options.profile === 'string', 'profile option must be string');
profile = options.profile;
if (options.radiuses) {
invariant(Array.isArray(options.radiuses), 'radiuses must be an array');
invariant(options.radiuses.length === coordinates.length, 'There must be as many radiuses as there are coordinates in the request');
params.radiuses = options.radiuses.join(';');
}
if (options.geometry) {
invariant(typeof options.geometry === 'string', 'geometry option must be string');
geometry = options.geometry;
if (typeof options.steps !== 'undefined') {
invariant(typeof options.steps === 'boolean', 'steps option must be boolean');
params.steps = options.steps;
}
var allowedOverview = ['full', 'simplified'];
if (typeof options.overview !== 'undefined') {
invariant(allowedOverview.indexOf(options.overview) !== -1 || options.overview === false, 'overview option must be ' + allowedOverview + ' or false');
params.overview = options.overview;
}
if (options.timestamps) {
invariant(Array.isArray(options.timestamps), 'timestamps must be an array');
invariant(options.timestamps.length === coordinates.length, 'There must be as many timestamps as there are coordinates in the request');
params.timestamps = options.timestamps.join(';');
}
if (options.annotations) {
invariant(Array.isArray(options.annotations), 'annotations must be an array');
params.annotations = options.annotations.join();
}
return this.client({
path: constants.API_MATCHING,
params: {
profile: profile,
geometry: geometry,
gps_precision: gps_precision
},
method: 'post',
entity: trace,
path: API_MATCHING,
params: params,
method: 'get',
callback: callback
}).entity();
});
};
module.exports = MapboxMatching;
'use strict';
var invariant = require('../../vendor/invariant'),
xtend = require('../../vendor/xtend').extend,
uriTemplate = require('rest/util/uriTemplate'),
encodeOverlay = require('../encode_overlay'),
invariantLocation = require('../invariant_location'),
makeService = require('../make_service'),
constants = require('../constants');
var invariant = require('../../vendor/invariant');
var xtend = require('../../vendor/xtend').extend;
var uriTemplate = require('rest/util/uriTemplate');
var encodeOverlay = require('../encode_overlay');
var invariantLocation = require('../invariant_location');
var makeService = require('../make_service');
/**
* @class MapboxStatic
*/
var MapboxStatic = makeService('MapboxStatic');
var API_STATIC = '/styles/v1/{username}/{styleid}/static{+overlay}/{+xyzbp}/{width}x{height}{+retina}{?access_token,attribution,logo,before_layer}';
var API_STATIC_CLASSIC = '/v4/{mapid}{+overlay}/{+xyz}/{width}x{height}{+retina}{.format}{?access_token}';
/**
* Determine a URL for a static map image, using the [Mapbox Static Map API](https://www.mapbox.com/developers/api/static/).
* Determine a URL for a static map image, using the [Mapbox Static Map API](https://www.mapbox.com/api-documentation/#static).
*
* @param {string} username Mapbox username
* @param {string} styleid Mapbox Style ID
* @param {number} width width of the image
* @param {number} height height of the image
*
* @param {Object|string} position either an object with longitude and latitude members, or the string 'auto'
* @param {number} position.longitude east, west bearing
* @param {number} position.latitude north, south bearing
* @param {number} position.zoom map zoom level
* @param {number} position.bearing map bearing in degrees between 0 and 360
* @param {number} position.pitch map pitch in degrees between 0 (straight down, no pitch) and 60 (maximum pitch)
*
* @param {Object} options all map options
* @param {boolean} [options.retina=false] whether to double image pixel density
*
* @param {Array<Object>} [options.markers=[]] an array of simple marker objects as an overlay
* @param {Object} [options.geojson={}] geojson data for the overlay
* @param {Object} [options.path={}] a path and
* @param {Array<Object>} options.path.geojson data for the path as an array of longitude, latitude objects
* @param {Array<Object>} options.path.style optional style definitions for a path
* @param {boolean} options.attribution controlling whether there is attribution on the image; defaults to true
* @param {boolean} options.logo controlling whether there is a Mapbox logo on the image; defaults to true
* @param {string} options.before_layer value for controlling where the overlay is inserted in the style
*
* @returns {string} static map url
* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
* var url = mapboxClient.getStaticURL('mapbox', 'streets-v10', 600, 400, {
* longitude: 151.22,
* latitude: -33.87,
* zoom: 11
* }, {
* markers: [{ longitude: 151.22, latitude: -33.87 }],
* before_layer: 'housenum-label'
* });
* // url = https://api.mapbox.com/styles/v1/mapbox/streets-v10/static/pin-l-circle(151.22,-33.87)/151.22,-33.87,11/600x400?access_token=ACCESS_TOKEN&before_layer=housenum-label
*/
MapboxStatic.prototype.getStaticURL = function(username, styleid, width, height, position, options) {
invariant(typeof username === 'string', 'username option required and must be a string');
invariant(typeof styleid === 'string', 'styleid option required and must be a string');
invariant(typeof width === 'number', 'width option required and must be a number');
invariant(typeof height === 'number', 'height option required and must be a number');
var defaults = {
retina: ''
};
var xyzbp;
if (position === 'auto') {
xyzbp = 'auto';
} else {
invariantLocation(position);
xyzbp = position.longitude + ',' + position.latitude + ',' + position.zoom;
if ('pitch' in position) {
xyzbp += ',' + (position.bearing || 0) + ',' + position.pitch;
} else if ('bearing' in position) {
xyzbp += ',' + position.bearing;
}
}
var userOptions = {};
if (options) {
invariant(typeof options === 'object', 'options must be an object');
if (options.format) {
invariant(typeof options.format === 'string', 'format must be a string');
userOptions.format = options.format;
}
if (options.retina) {
invariant(typeof options.retina === 'boolean', 'retina must be a boolean');
userOptions.retina = options.retina;
}
if (options.markers) {
userOptions.overlay = '/' + encodeOverlay.encodeMarkers(options.markers);
} else if (options.geojson) {
userOptions.overlay = '/' + encodeOverlay.encodeGeoJSON(options.geojson);
} else if (options.path) {
userOptions.overlay = '/' + encodeOverlay.encodePath(options.path);
}
if ('attribution' in options) {
invariant(typeof options.attribution === 'boolean', 'attribution must be a boolean');
userOptions.attribution = options.attribution;
}
if ('logo' in options) {
invariant(typeof options.logo === 'boolean', 'logo must be a boolean');
userOptions.logo = options.logo;
}
if (options.before_layer) {
invariant(typeof options.before_layer === 'string', 'before_layer must be a string');
userOptions.before_layer = options.before_layer;
}
}
var params = xtend(defaults, userOptions, {
username: username,
styleid: styleid,
width: width,
xyzbp: xyzbp,
height: height,
access_token: this.accessToken
});
if (params.retina === true) {
params.retina = '@2x';
}
return this.endpoint + uriTemplate.expand(API_STATIC, params);
};
/**
* Determine a URL for a static classic map image, using the [Mapbox Static (Classic) Map API](https://www.mapbox.com/api-documentation/pages/static_classic.html).
*
* @param {string} mapid a Mapbox map id in username.id form

@@ -35,8 +153,7 @@ * @param {number} width width of the image

*
* @returns {string} static map url
* @memberof MapboxClient
* @returns {string} static classic map url
* @example
* var mapboxClient = new MapboxClient('ACCESSTOKEN');
*/
MapboxStatic.prototype.getStaticURL = function(mapid, width, height, position, options) {
MapboxStatic.prototype.getStaticClassicURL = function(mapid, width, height, position, options) {
invariant(typeof mapid === 'string', 'mapid option required and must be a string');

@@ -93,5 +210,5 @@ invariant(typeof width === 'number', 'width option required and must be a number');

return this.endpoint + uriTemplate.expand(constants.API_STATIC, params);
return this.endpoint + uriTemplate.expand(API_STATIC_CLASSIC, params);
};
module.exports = MapboxStatic;
'use strict';
var invariant = require('../../vendor/invariant'),
hat = require('../../vendor/hat'),
uriTemplate = require('rest/util/uriTemplate'),
makeService = require('../make_service'),
constants = require('../constants');
var invariant = require('../../vendor/invariant');
var uriTemplate = require('rest/util/uriTemplate');
var makeService = require('../make_service');
var Styles = module.exports = makeService('MapboxStyles');
/**
* @class MapboxStyles
*/
var MapboxStyles = module.exports = makeService('MapboxStyles');
var API_STYLES_LIST = '/styles/v1/{owner}{?access_token}';
var API_STYLES_CREATE = '/styles/v1/{owner}{?access_token}';
var API_STYLES_READ = '/styles/v1/{owner}/{styleid}{?access_token}';
var API_STYLES_UPDATE = '/styles/v1/{owner}/{styleid}{?access_token}';
var API_STYLES_DELETE = '/styles/v1/{owner}/{styleid}{?access_token}';
var API_STYLES_EMBED = '/styles/v1/{owner}/{styleid}.html{?access_token,zoomwheel,title}';
var API_STYLES_SPRITE = '/styles/v1/{owner}/{styleid}/sprite{+retina}{.format}{?access_token}';
var API_STYLES_SPRITE_ICON = '/styles/v1/{owner}/{styleid}/sprite/{iconName}{?access_token}';
var API_STYLES_FONT_GLYPH_RANGES = '/fonts/v1/{owner}/{font}/{start}-{end}.pbf{?access_token}';
/**
* To retrieve a listing of styles for a particular account.
*
* @param {Function} callback called with (err, datasets)
* @returns {undefined} nothing, calls callback
* @param {Function} callback called with (err, styles)
* @returns {Promise} response
* @example

@@ -20,3 +31,3 @@ * var MapboxClient = require('mapbox');

* client.listStyles(function(err, styles) {
* console.log(datasets);
* console.log(styles);
* // [{ version: 8,

@@ -40,5 +51,5 @@ * // name: 'Light',

*/
Styles.prototype.listStyles = function(callback) {
MapboxStyles.prototype.listStyles = function(callback) {
return this.client({
path: constants.API_STYLES_LIST,
path: API_STYLES_LIST,
params: {

@@ -48,3 +59,3 @@ owner: this.owner

callback: callback
}).entity();
});
};

@@ -56,4 +67,4 @@

* @param {Object} style Mapbox GL Style Spec object
* @param {Function} callback called with (err, datasets)
* @returns {undefined} nothing, calls callback
* @param {Function} callback called with (err, createdStyle)
* @returns {Promise} response
* @example

@@ -74,5 +85,5 @@ * var MapboxClient = require('mapbox');

*/
Styles.prototype.createStyle = function(style, callback) {
MapboxStyles.prototype.createStyle = function(style, callback) {
return this.client({
path: constants.API_STYLES_CREATE,
path: API_STYLES_CREATE,
params: {

@@ -83,3 +94,3 @@ owner: this.owner

callback: callback
}).entity();
});
};

@@ -91,5 +102,5 @@

* @param {Object} style Mapbox GL Style Spec object
* @param {string} id style id
* @param {Function} callback called with (err, datasets)
* @returns {undefined} nothing, calls callback
* @param {string} styleid style id
* @param {Function} callback called with (err, createdStyle)
* @returns {Promise} response
* @example

@@ -110,6 +121,6 @@ * var MapboxClient = require('mapbox');

*/
Styles.prototype.updateStyle = function(style, styleid, callback) {
MapboxStyles.prototype.updateStyle = function(style, styleid, callback) {
invariant(typeof styleid === 'string', 'style id must be a string');
return this.client({
path: constants.API_STYLES_UPDATE,
path: API_STYLES_UPDATE,
params: {

@@ -122,3 +133,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -135,11 +146,11 @@

* var client = new MapboxClient('ACCESSTOKEN');
* client.readStyle('style-id', function(err, response) {
* if (!err) console.log(response);
* client.deleteStyle('style-id', function(err) {
* if (!err) console.log('deleted!');
* });
*/
Styles.prototype.deleteStyle = function(styleid, callback) {
MapboxStyles.prototype.deleteStyle = function(styleid, callback) {
invariant(typeof styleid === 'string', 'styleid must be a string');
return this.client({
path: constants.API_STYLES_DELETE,
path: API_STYLES_DELETE,
params: {

@@ -151,3 +162,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -159,16 +170,16 @@

* @param {string} styleid the id for an existing style
* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
* @param {Function} callback called with (err, style)
* @returns {Promise} response
* @example
* var MapboxClient = require('mapbox');
* var client = new MapboxClient('ACCESSTOKEN');
* client.deleteStyle('style-id', function(err) {
* if (!err) console.log('deleted!');
* client.readStyle('style-id', function(err, style) {
* if (!err) console.log(style);
* });
*/
Styles.prototype.readStyle = function(styleid, callback) {
MapboxStyles.prototype.readStyle = function(styleid, callback) {
invariant(typeof styleid === 'string', 'styleid must be a string');
return this.client({
path: constants.API_STYLES_READ,
path: API_STYLES_READ,
params: {

@@ -179,3 +190,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -191,3 +202,3 @@

* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -202,3 +213,3 @@ * var MapboxClient = require('mapbox');

*/
Styles.prototype.readSprite = function(styleid, options, callback) {
MapboxStyles.prototype.readSprite = function(styleid, options, callback) {
invariant(typeof styleid === 'string', 'styleid must be a string');

@@ -229,3 +240,3 @@

return this.client({
path: constants.API_STYLES_SPRITE,
path: API_STYLES_SPRITE,
params: {

@@ -238,3 +249,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -250,3 +261,3 @@

* @param {Function} callback called with (err)
* @returns {Promise}
* @returns {Promise} response
* @example

@@ -259,3 +270,3 @@ * var MapboxClient = require('mapbox');

*/
Styles.prototype.readFontGlyphRanges = function(font, start, end, callback) {
MapboxStyles.prototype.readFontGlyphRanges = function(font, start, end, callback) {
invariant(typeof font === 'string', 'font must be a string');

@@ -266,3 +277,3 @@ invariant(typeof start === 'number', 'start must be a number');

return this.client({
path: constants.API_STYLES_FONT_GLYPH_RANGES,
path: API_STYLES_FONT_GLYPH_RANGES,
params: {

@@ -275,3 +286,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -282,7 +293,7 @@

*
* @param {string} style the id for an existing style
* @param {string} styleid the id for an existing style
* @param {string} iconName icon's name
* @param {Buffer} icon icon content as a buffer
* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -296,3 +307,3 @@ * var MapboxClient = require('mapbox');

*/
Styles.prototype.addIcon = function(styleid, iconName, icon, callback) {
MapboxStyles.prototype.addIcon = function(styleid, iconName, icon, callback) {
invariant(typeof styleid === 'string', 'style must be a string');

@@ -303,3 +314,3 @@ invariant(typeof iconName === 'string', 'icon name must be a string');

return this.client({
path: constants.API_STYLES_SPRITE_ADD_ICON,
path: API_STYLES_SPRITE_ICON,
params: {

@@ -316,3 +327,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -323,6 +334,6 @@

*
* @param {string} style the id for an existing style
* @param {string} styleid the id for an existing style
* @param {string} iconName icon's name
* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -335,3 +346,3 @@ * var MapboxClient = require('mapbox');

*/
Styles.prototype.deleteIcon = function(styleid, iconName, callback) {
MapboxStyles.prototype.deleteIcon = function(styleid, iconName, callback) {
invariant(typeof styleid === 'string', 'style must be a string');

@@ -341,3 +352,3 @@ invariant(typeof iconName === 'string', 'icon name must be a string');

return this.client({
path: constants.API_STYLES_SPRITE_ADD_ICON,
path: API_STYLES_SPRITE_ICON,
params: {

@@ -350,3 +361,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -357,7 +368,7 @@

*
* @param {string} style the id for an existing style
* @param {Object} options
* @param {boolean=false} options.title If true, shows a title box in upper right
* corner with map title and owner
* @param {boolean=true} options.zoomwheel Disables zooming with mouse scroll wheel
* @param {string} styleid the id for an existing style
* @param {Object} options optional params
* @param {boolean} [options.title=false] If true, shows a title box in upper right
* corner with map title and owner
* @param {boolean} [options.zoomwheel=true] Disables zooming with mouse scroll wheel
* @returns {string} URL of style embed page

@@ -369,3 +380,3 @@ * @example

*/
Styles.prototype.embedStyle = function(styleid, options) {
MapboxStyles.prototype.embedStyle = function(styleid, options) {
invariant(typeof styleid === 'string', 'style must be a string');

@@ -392,3 +403,3 @@

return this.endpoint + uriTemplate.expand(constants.API_STYLES_EMBED, params);
return this.endpoint + uriTemplate.expand(API_STYLES_EMBED, params);
};
'use strict';
var invariant = require('../../vendor/invariant'),
formatPoints = require('../format_points'),
makeService = require('../make_service'),
constants = require('../constants');
var invariant = require('../../vendor/invariant');
var formatPoints = require('../format_points');
var makeService = require('../make_service');
/**
* @class MapboxSurface
*/
var MapboxSurface = makeService('MapboxSurface');
var API_SURFACE = '/v4/surface/{mapid}.json{?access_token,layer,fields,points,geojson,interpolate,encoded_polyline}';
/**

@@ -36,4 +40,3 @@ * Given a list of locations, retrieve vector tiles, find the nearest

* @param {Function} callback called with (err, results)
* @memberof MapboxClient
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -90,8 +93,8 @@ * var mapboxClient = new MapboxClient('ACCESSTOKEN');

return this.client({
path: constants.API_SURFACE,
path: API_SURFACE,
params: surfaceOptions,
callback: callback
}).entity();
});
};
module.exports = MapboxSurface;
'use strict';
var invariant = require('../../vendor/invariant'),
makeService = require('../make_service'),
constants = require('../constants');
var invariant = require('../../vendor/invariant');
var makeService = require('../make_service');
var Tilestats = module.exports = makeService('MapboxTilestats');
/**
* To create an empty set of tileset statistics.
*
* @private
* @param {String} tileset - the id for the tileset
* @param {Array<string>} layers - an array of layer names in the tileset
* @param {Function} callback called with (err, tilestats)
* @returns {undefined} nothing, calls callback
* @class MapboxTilestats
*/
Tilestats.prototype.createTilestats = function(tileset, layers, callback) {
invariant(typeof tileset === 'string', 'tileset must be a string');
invariant(Array.isArray(layers), 'layers must be an array');
invariant(layers.every(function(layer) {
return typeof layer === 'string';
}), 'layers must be an array of strings');
var MapboxTilestats = module.exports = makeService('MapboxTilestats');
var owner = tileset.split('.')[0];
if (owner === tileset) owner = this.owner;
var API_TILESTATS_STATISTICS = '/tilestats/v1/{owner}/{tileset}{?access_token}';
return this.client({
path: constants.API_TILESTATS_STATISTICS,
params: {
owner: owner,
tileset: tileset
},
entity: { layers: layers },
method: 'post',
callback: callback
}).entity();
};
/**
* To delete a set of tileset statistics.
*
* @private
* @param {String} tileset - the id for the tileset
* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
*/
Tilestats.prototype.deleteTilestats = function(tileset, callback) {
invariant(typeof tileset === 'string', 'tileset must be a string');
var owner = tileset.split('.')[0];
if (owner === tileset) owner = this.owner;
return this.client({
path: constants.API_TILESTATS_STATISTICS,
params: {
owner: owner,
tileset: tileset
},
method: 'delete',
callback: callback
}).entity();
};
/**
* To retrieve statistics about a specific tileset.

@@ -70,3 +18,3 @@ *

* @param {Function} callback called with (err, tilestats)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -77,16 +25,17 @@ * var client = new MapboxClient('ACCESSTOKEN');

* // {
* // "account": {account},
* // "tilesetid": "tileset-id",
* // "layerCount": {layer count},
* // "layers": [
* // {
* // "account": {account},
* // "tilesetid": "tileset-id",
* // "layer": {layername},
* // "count": 10,
* // "layer": {layer name},
* // "geometry": {dominant geometry},
* // "count": {feature count},
* // "attributeCount": {attribute count}
* // "attributes": [
* // {
* // "attribute": {attributename},
* // "min": 0,
* // "max": 10,
* // "values": [0, 10]
* // "attribute": {attribute name},
* // "type": {attribute type},
* // "count": {unique value count},
* // "min": {minimum value if type is number},
* // "max": {maximum value if type is number},
* // "values": [{...unique values}]
* // }

@@ -99,3 +48,3 @@ * // ]

*/
Tilestats.prototype.getTilestats = function(tileset, callback) {
MapboxTilestats.prototype.getTilestats = function(tileset, callback) {
invariant(typeof tileset === 'string', 'tileset must be a string');

@@ -107,3 +56,3 @@

return this.client({
path: constants.API_TILESTATS_STATISTICS,
path: API_TILESTATS_STATISTICS,
params: {

@@ -114,117 +63,25 @@ owner: owner,

callback: callback
}).entity();
});
};
/**
* Add or update information about geometry types present in a tileset layer.
* This request may be made multiple times against a single layer, in order to
* update the total geometry counts across a set of parallel tileset reads.
*
* @private
* @param {String} tileset - the id for the tileset
* @param {String} layer - the name of the layer in the tileset
* @param {Object} geometries - an object indicating the number of features present
* in the layer of various geometry types.
* @param {Number} [geometries.point] - number of Point features
* @param {Number} [geometries.multipoint] - number of MultiPoint features
* @param {Number} [geometries.linestring] - number of LineString features
* @param {Number} [geometries.multilinestring] - number of MultiLineString features
* @param {Number} [geometries.polygon] - number of Polygon features
* @param {Number} [geometries.multipolygon] - number of MultiPolygon features
* @param {Number} [geometries.geometrycollection] - number of GeometryCollection features
* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
*/
Tilestats.prototype.updateTilestatsLayer = function(tileset, layer, geometries, callback) {
invariant(typeof tileset === 'string', 'tileset must be a string');
invariant(typeof layer === 'string', 'layer must be a string');
invariant(typeof geometries === 'object', 'geometries must be an object');
var owner = tileset.split('.')[0];
if (owner === tileset) owner = this.owner;
return this.client({
path: constants.API_TILESTATS_LAYER,
params: {
owner: owner,
tileset: tileset,
layer: layer
},
entity: geometries,
method: 'post',
callback: callback
}).entity();
};
/**
* To add or update statistics about the values of a particular attribute in
* a layer. This request may be made multiple times against a single attribute,
* in order to update the statistics across a set of parallel tileset reads.
* To create or update statistics about a specific tileset.
*
* @private
* @param {String} tileset - the id for the tileset
* @param {String} layer - the name of the layer in the tileset
* @param {String} attribute - the name of the attribute in the layer
* @param {Object} stats - statistics about attribute values in the layer
* @param {Number|String} stats.min - the minimum attribute value
* @param {Number|String} stats.max - the maximum attribute value
* @param {Array<Number|String>} stats.values - an array of unique values for the attribute
* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
*/
Tilestats.prototype.updateTilestatsAttribute = function(tileset, layer, attribute, stats, callback) {
invariant(typeof tileset === 'string', 'tileset must be a string');
invariant(typeof layer === 'string', 'layer must be a string');
invariant(typeof attribute === 'string', 'attribute must be a string');
invariant(typeof stats === 'object', 'stats must be an object');
var owner = tileset.split('.')[0];
if (owner === tileset) owner = this.owner;
return this.client({
path: constants.API_TILESTATS_ATTRIBUTE,
params: {
owner: owner,
tileset: tileset,
layer: layer,
attribute: attribute
},
entity: stats,
method: 'post',
callback: callback
}).entity();
};
/**
* To retrieve statistics about the attribute values of a particular attribute
* within a tileset layer.
*
* @param {String} tileset - the id for the tileset
* @param {String} layer - the name of the layer in the tileset
* @param {String} attribute - the name of the attribute in the layer
* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
* @param {object} statistics - the statistics to upload
* @param {Function} callback called with (err, tilestats)
* @returns {Promise} response
* @example
* var client = new MapboxClient('ACCESSTOKEN');
* client.getTilestatsAttribute('tileset-id', 'layer-name', 'attr-name', function(err, info) {
* console.log(info);
* client.getTilestats('tileset-id', function(err, stats) {
* console.log(stats);
* // {
* // "account": {account},
* // "tilesetid": "tileset-id",
* // "layer": "layer-name",
* // "attribute": "attr-name",
* // "type": "Number",
* // "min": 0,
* // "max": 10,
* // "values": [
* // 0,
* // 10
* // ]
* // "account": {account}
* // ... see stats example above (for Tilestats#getTilestats)
* // }
* });
*/
Tilestats.prototype.getTilestatsAttribute = function(tileset, layer, attribute, callback) {
MapboxTilestats.prototype.putTilestats = function(tileset, statistics, callback) {
invariant(typeof tileset === 'string', 'tileset must be a string');
invariant(typeof layer === 'string', 'layer must be a string');
invariant(typeof attribute === 'string', 'attribute must be a string');

@@ -235,11 +92,11 @@ var owner = tileset.split('.')[0];

return this.client({
path: constants.API_TILESTATS_ATTRIBUTE,
path: API_TILESTATS_STATISTICS,
params: {
owner: owner,
tileset: tileset,
layer: layer,
attribute: attribute
tileset: tileset
},
entity: statistics,
method: 'put',
callback: callback
}).entity();
});
};
'use strict';
var invariant = require('../../vendor/invariant'),
makeService = require('../make_service'),
constants = require('../constants');
var invariant = require('../../vendor/invariant');
var makeService = require('../make_service');
var Uploads = module.exports = makeService('MapboxUploads');
/**
* @class MapboxUploads
*/
var MapboxUploads = module.exports = makeService('MapboxUploads');
var API_UPLOADS = '/uploads/v1/{owner}{?access_token}';
var API_UPLOAD = '/uploads/v1/{owner}/{upload}{?access_token}';
var API_UPLOAD_CREDENTIALS = '/uploads/v1/{owner}/credentials{?access_token}';
/**

@@ -15,3 +21,3 @@ * Retrieve a listing of uploads for a particular account.

* @param {Function} callback called with (err, uploads)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -45,8 +51,8 @@ * var mapboxClient = new MapboxClient('ACCESSTOKEN');

*/
Uploads.prototype.listUploads = function(callback) {
MapboxUploads.prototype.listUploads = function(callback) {
return this.client({
path: constants.API_UPLOADS,
path: API_UPLOADS,
params: { owner: this.owner },
callback: callback
}).entity();
});
};

@@ -62,3 +68,3 @@

* @param {Function} callback called with (err, credentials)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -93,8 +99,9 @@ * var mapboxClient = new MapboxClient('ACCESSTOKEN');

*/
Uploads.prototype.createUploadCredentials = function(callback) {
MapboxUploads.prototype.createUploadCredentials = function(callback) {
return this.client({
path: constants.API_UPLOAD_CREDENTIALS,
path: API_UPLOAD_CREDENTIALS,
params: { owner: this.owner },
method: 'post',
callback: callback
}).entity();
});
};

@@ -115,3 +122,3 @@

* @param {Function} callback called with (err, upload)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -145,11 +152,11 @@ * var mapboxClient = new MapboxClient('ACCESSTOKEN');

*/
Uploads.prototype.createUpload = function(options, callback) {
MapboxUploads.prototype.createUpload = function(options, callback) {
invariant(typeof options === 'object', 'options must be an object');
return this.client({
path: constants.API_UPLOADS,
path: API_UPLOADS,
params: { owner: this.owner },
entity: options,
callback: callback
}).entity();
});
};

@@ -164,3 +171,3 @@

* @param {Function} callback called with (err, upload)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -182,7 +189,7 @@ * var mapboxClient = new MapboxClient('ACCESSTOKEN');

*/
Uploads.prototype.readUpload = function(upload, callback) {
MapboxUploads.prototype.readUpload = function(upload, callback) {
invariant(typeof upload === 'string', 'upload must be a string');
return this.client({
path: constants.API_UPLOAD,
path: API_UPLOAD,
params: {

@@ -193,3 +200,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};

@@ -202,4 +209,5 @@

*
* @param {string} upload upload identifier
* @param {Function} callback called with (err)
* @returns {undefined} nothing, calls callback
* @returns {Promise} response
* @example

@@ -210,3 +218,3 @@ * var mapboxClient = new MapboxClient('ACCESSTOKEN');

*/
Uploads.prototype.deleteUpload = function(upload, callback) {
MapboxUploads.prototype.deleteUpload = function(upload, callback) {
invariant(typeof upload === 'string', 'upload must be a string');

@@ -216,3 +224,3 @@

method: 'delete',
path: constants.API_UPLOAD,
path: API_UPLOAD,
params: {

@@ -223,3 +231,3 @@ owner: this.owner,

callback: callback
}).entity();
});
};
{
"name": "mapbox",
"version": "1.0.0-beta1",
"version": "1.0.0-beta10",
"description": "interface to mapbox services",
"main": "lib/mapbox.js",
"scripts": {
"lint": "eslint --no-eslintrc -c .eslintrc lib test/*.js",
"test": "tap --coverage test/browser.js test/*.js",
"test": "npm run lint && npm run unit-test",
"lint": "eslint lib test/*.js",
"unit-test": "tap --coverage test/browser.js test/*.js",
"browser-test": "browserify -t envify -t brfs test/*.js test/helpers/close.js | smokestack | tap-status",
"browser-test-ff": "browserify -t envify -t brfs test/*.js test/helpers/close.js | smokestack -b firefox | tap-status",
"browser-test-build": "echo '<script>' > test_bundle.html && browserify -t envify -t brfs test/directions.js >> test_bundle.html && echo '</script>' >> test_bundle.html",
"docs": "documentation -f md > API.md",
"browser-test-build": "echo '<script>' > test_bundle.html && browserify -t envify -t brfs test/matching.js >> test_bundle.html && echo '</script>' >> test_bundle.html",
"docs": "documentation build --shallow --config .documentation.yml -f md lib/mapbox.js lib/services/* > API.md",
"prepublish": "npm run build",
"build": "npm run build-dist && npm run build-min",
"build-dist": "browserify -s MapboxClient lib/mapbox.js > dist/mapbox-sdk.js",
"build-dist": "mkdir -p dist && browserify -s MapboxClient lib/mapbox.js > dist/mapbox-sdk.js",
"build-min": "uglifyjs -c -m < dist/mapbox-sdk.js > dist/mapbox-sdk.min.js"

@@ -24,2 +26,7 @@ },

},
"files": [
"lib",
"vendor",
"dist"
],
"keywords": [

@@ -32,2 +39,12 @@ "mapbox",

"author": "Tom MacWright",
"contributors": [
{
"name": "Andrew Harvey",
"email": "andrew@alantgeo.com.au"
},
{
"name": "Scott Andrews",
"email": "scott@mapbox.com"
}
],
"license": "ISC",

@@ -44,16 +61,17 @@ "bugs": {

"browserify": "^11.0.0",
"documentation": "^3.0.0",
"documentation": "^6.1.0",
"envify": "^3.4.0",
"eslint": "^0.24.1",
"eslint": "^3.10.2",
"geojson-random": "^0.2.2",
"geojsonhint": "^1.1.0",
"smokestack": "^3.3.0",
"tap": "^1.3.1",
"tap": "^8.0.1",
"tap-status": "^1.0.1",
"tape": "^4.2.0",
"geojsonhint": "^1.1.0",
"uglifyjs": "^2.4.10"
"uglify-js": "^2.4.10"
},
"dependencies": {
"rest": "^1.3.2"
"es6-promise": "^4.0.5",
"rest": "^2.0.0"
}
}

@@ -14,29 +14,26 @@ # mapbox-sdk-js

* [Geocoding](https://www.mapbox.com/developers/api/geocoding/)
* [Geocoding](https://www.mapbox.com/api-documentation/#geocoding)
* Forward (place names ⇢ longitude, latitude)
* Reverse (longitude, latitude ⇢ place names)
* [Upload API](https://www.mapbox.com/developers/api/uploads/)
* [Upload API](https://www.mapbox.com/api-documentation/#uploads)
* Upload data to be processed and hosted by Mapbox.
* [Directions](https://www.mapbox.com/developers/api/directions/)
* [Directions](https://www.mapbox.com/api-documentation/#directions)
* Profiles for driving, walking, and cycling
* GeoJSON & Polyline formatting
* Instructions as text or HTML
Contact help@mapbox.com for information
* [Distance](https://www.mapbox.com/developers/api/distance/)
* Travel-time tables between up to 100 points
* [Datasets](https://www.mapbox.com/api-documentation/#datasets)
* Retrieve, add, and edit datasets.
* [Styles](https://www.mapbox.com/api-documentation/#styles)
* Retrieve, add and edit styles, fonts and icons.
* [Tilesets](https://www.mapbox.com/api-documentation/#tilesets)
* List tilesets.
* [Tokens](https://www.mapbox.com/api-documentation/#tokens)
* Retrieve, add and edit access tokens.
* [Matrix](https://www.mapbox.com/api-documentation/#matrix)
* Travel-time tables between coordinates up to 25 pairs
* Profiles for driving, walking and cycling
* [Map Matching](https://www.mapbox.com/developers/api/map-matching/)
* [Map Matching](https://www.mapbox.com/api-documentation/#map-matching)
* Aligns GPS trace data to roads and paths from
[OpenStreetMap](https://www.openstreetmap.org/) data
* [Surface API](https://www.mapbox.com/developers/api/surface/)
* Interpolates values along lines. Useful for elevation traces.
Not currently public
* Datasets
* Retrieve, add, and edit datasets.
* **Note: The Mapbox Datasets API is in private beta. Currently, all end user requests to this API from outside of Mapbox will 404.**
## Installation

@@ -50,12 +47,46 @@

Setup via `node`:
```js
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:
```js
var client = new MapboxClient('YOUR_ACCESS_TOKEN');
```
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
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:
```js
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

@@ -74,3 +105,11 @@

* 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](API.md)
/* eslint-disable */
/**
/*
* hat

@@ -4,0 +4,0 @@ * written by James Halliday, licensed under MIT/X11

@@ -1,2 +0,2 @@

/**
/*
* Copyright 2013-2015, Facebook, Inc.

@@ -12,3 +12,3 @@ * All rights reserved.

/**
/*
* Use invariant() to assert state which your program assumes to be true.

@@ -15,0 +15,0 @@ *

'use strict';
/**
/*
* polyline

@@ -12,3 +12,3 @@ *

/**
/*
* Based off of [the offical Google document](https://developers.google.com/maps/documentation/utilities/polylinealgorithm)

@@ -15,0 +15,0 @@ *

@@ -1,2 +0,2 @@

/**
/*
* xtend by Jake Verbaten

@@ -3,0 +3,0 @@ *

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc