Comparing version 1.0.0-beta6 to 1.0.0-beta7
@@ -0,2 +1,17 @@ | ||
## 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) | ||
@@ -3,0 +18,0 @@ - **Bug** Install Promise polyfill only when needed. [#122](https://github.com/mapbox/mapbox-sdk-js/pull/122) |
@@ -7,4 +7,2 @@ 'use strict'; | ||
var rest = require('rest'); | ||
var standardResponse = require('./standard_response'); | ||
var callbackify = require('./callbackify'); | ||
@@ -17,9 +15,9 @@ // rest.js client with MIME support | ||
.wrap(require('rest/interceptor/mime'), { mime: 'application/json' }) | ||
.wrap(require('rest/interceptor/params')) | ||
.wrap(require('rest/interceptor/template')) | ||
.wrap(require('rest/interceptor/defaultRequest'), { | ||
params: { access_token: config.accessToken } | ||
}) | ||
.wrap(require('rest/interceptor/template')) | ||
.wrap(standardResponse) | ||
.wrap(callbackify); | ||
.wrap(require('./paginator'), { access_token: config.accessToken }) | ||
.wrap(require('./standard_response')) | ||
.wrap(require('./callbackify')); | ||
}; |
@@ -1,41 +0,2 @@ | ||
// We keep all of the constants that declare endpoints in one | ||
// place, so that we could conceivably 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,limit,autocomplete}'; | ||
module.exports.API_GEOCODING_REVERSE = '/geocoding/v5/{dataset}/{longitude},{latitude}.json{?types,limit}'; | ||
module.exports.API_DIRECTIONS = '/directions/v5/{account}/{profile}/{encodedWaypoints}.json{?alternatives,geometries,overview,radiuses,steps,continue_straight,bearings}'; | ||
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/v5/{account}/{profile}/{coordinates}.json{?geometries,radiuses,steps,overview,timestamps,annotations}'; | ||
module.exports.API_DATASET_DATASETS = '/datasets/v1/{owner}{?limit,start,fresh}'; | ||
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}{?access_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'; |
@@ -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 + ')'; |
@@ -14,2 +14,6 @@ 'use strict'; | ||
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'); | ||
@@ -47,3 +51,7 @@ | ||
MapboxUploads.prototype, | ||
MapboxTilestats.prototype | ||
MapboxTilestats.prototype, | ||
MapboxStyles.prototype, | ||
MapboxStatic.prototype, | ||
MapboxTilesets.prototype, | ||
MapboxTokens.prototype | ||
); | ||
@@ -50,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'); | ||
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}'; | ||
/** | ||
@@ -15,3 +19,2 @@ * To retrieve a listing of datasets for a particular account. | ||
* @param {Object} [opts={}] list options | ||
* @param {string} opts.start start location, for paging | ||
* @param {number} opts.limit limit, for paging | ||
@@ -52,6 +55,5 @@ * @param {boolean} opts.fresh whether to request fresh data | ||
return this.client({ | ||
path: constants.API_DATASET_DATASETS, | ||
path: API_DATASET_DATASETS, | ||
params: { | ||
limit: opts.limit, | ||
start: opts.start, | ||
fresh: opts.fresh, | ||
@@ -98,3 +100,3 @@ owner: this.owner | ||
return this.client({ | ||
path: constants.API_DATASET_DATASETS, | ||
path: API_DATASET_DATASETS, | ||
params: { | ||
@@ -134,3 +136,3 @@ owner: this.owner | ||
return this.client({ | ||
path: constants.API_DATASET_DATASET, | ||
path: API_DATASET_DATASET, | ||
params: { | ||
@@ -176,3 +178,3 @@ owner: this.owner, | ||
return this.client({ | ||
path: constants.API_DATASET_DATASET, | ||
path: API_DATASET_DATASET, | ||
params: { | ||
@@ -206,3 +208,3 @@ owner: this.owner, | ||
return this.client({ | ||
path: constants.API_DATASET_DATASET, | ||
path: API_DATASET_DATASET, | ||
params: { | ||
@@ -223,5 +225,3 @@ owner: this.owner, | ||
* @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) | ||
@@ -268,7 +268,2 @@ * @returns {Promise} response | ||
if (options.reverse) { | ||
invariant(typeof options.reverse === 'boolean', 'reverse option must be a boolean'); | ||
params.reverse = options.reverse; | ||
} | ||
if (options.limit) { | ||
@@ -279,9 +274,4 @@ 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, | ||
@@ -373,3 +363,3 @@ callback: callback | ||
return this.client({ | ||
path: constants.API_DATASET_FEATURE, | ||
path: API_DATASET_FEATURE, | ||
params: { | ||
@@ -417,3 +407,3 @@ owner: this.owner, | ||
return this.client({ | ||
path: constants.API_DATASET_FEATURE, | ||
path: API_DATASET_FEATURE, | ||
params: { | ||
@@ -448,3 +438,3 @@ owner: this.owner, | ||
return this.client({ | ||
path: constants.API_DATASET_FEATURE, | ||
path: API_DATASET_FEATURE, | ||
params: { | ||
@@ -458,2 +448,1 @@ owner: this.owner, | ||
})}; | ||
@@ -6,9 +6,10 @@ 'use strict'; | ||
var makeService = require('../make_service'); | ||
var constants = require('../constants'); | ||
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. | ||
@@ -23,7 +24,10 @@ * | ||
* 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 | ||
@@ -85,3 +89,3 @@ * alternative routes along with the preferred route. | ||
* ], { | ||
* profile: 'mapbox.walking', | ||
* profile: 'walking', | ||
* alternatives: false, | ||
@@ -123,2 +127,7 @@ * geometry: 'polyline' | ||
if (options.account) { | ||
invariant(typeof options.account === 'string', 'account option must be string'); | ||
params.account = options.account; | ||
} | ||
if (typeof options.alternatives !== 'undefined') { | ||
@@ -164,3 +173,3 @@ invariant(typeof options.alternatives === 'boolean', 'alternatives option must be boolean'); | ||
return this.client({ | ||
path: constants.API_DIRECTIONS, | ||
path: API_DIRECTIONS, | ||
params: params, | ||
@@ -167,0 +176,0 @@ callback: callback |
'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 MapboxDistance = makeService('MapboxDistance'); | ||
var API_DISTANCE = '/distances/v1/mapbox/{profile}{?access_token}'; | ||
/** | ||
@@ -80,3 +81,3 @@ * Compute a table of travel-time estimates between a set of waypoints. | ||
return this.client({ | ||
path: constants.API_DISTANCE, | ||
path: API_DISTANCE, | ||
params: { | ||
@@ -83,0 +84,0 @@ profile: profile |
'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 MapboxGeocoding = makeService('MapboxGeocoding'); | ||
var API_GEOCODING_FORWARD = '/geocoding/v5/{dataset}/{query}.json{?access_token,proximity,country,types,bbox,limit,autocomplete}'; | ||
var API_GEOCODING_REVERSE = '/geocoding/v5/{dataset}/{longitude},{latitude}.json{?access_token,types,limit}'; | ||
var REVERSE_GEOCODING_PRECISION = 5; | ||
@@ -143,3 +145,3 @@ var FORWARD_GEOCODING_PROXIMITY_PRECISION = 3; | ||
return this.client({ | ||
path: constants.API_GEOCODING_FORWARD, | ||
path: API_GEOCODING_FORWARD, | ||
params: queryOptions, | ||
@@ -160,3 +162,3 @@ callback: callback | ||
* @param {string} options.types a comma seperated list of types that filter | ||
* results to match those specified. See | ||
* results to match those specified. See | ||
* https://www.mapbox.com/api-documentation/#retrieve-places-near-a-location | ||
@@ -233,3 +235,3 @@ * for available types. | ||
return this.client({ | ||
path: constants.API_GEOCODING_REVERSE, | ||
path: API_GEOCODING_REVERSE, | ||
params: queryOptions, | ||
@@ -236,0 +238,0 @@ callback: callback |
@@ -5,6 +5,7 @@ 'use strict'; | ||
var makeService = require('../make_service'); | ||
var constants = require('../constants'); | ||
var MapboxMatching = makeService('MapboxMatching'); | ||
var API_MATCHING = '/matching/v5/{account}/{profile}/{coordinates}.json{?access_token,geometries,radiuses,steps,overview,timestamps,annotations}'; | ||
/** | ||
@@ -126,3 +127,3 @@ * Snap recorded location traces to roads and paths from OpenStreetMap. | ||
return this.client({ | ||
path: constants.API_MATCHING, | ||
path: API_MATCHING, | ||
params: params, | ||
@@ -129,0 +130,0 @@ method: 'get', |
'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'); | ||
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 | ||
* @memberof MapboxClient | ||
* @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,3 +151,3 @@ * @param {number} width width of the image | ||
* | ||
* @returns {string} static map url | ||
* @returns {string} static classic map url | ||
* @memberof MapboxClient | ||
@@ -41,3 +157,3 @@ * @example | ||
*/ | ||
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'); | ||
@@ -94,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'), | ||
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'); | ||
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) | ||
* @param {Function} callback called with (err, styles) | ||
* @returns {Promise} response | ||
@@ -19,3 +28,3 @@ * @example | ||
* client.listStyles(function(err, styles) { | ||
* console.log(datasets); | ||
* console.log(styles); | ||
* // [{ version: 8, | ||
@@ -41,3 +50,3 @@ * // name: 'Light', | ||
return this.client({ | ||
path: constants.API_STYLES_LIST, | ||
path: API_STYLES_LIST, | ||
params: { | ||
@@ -54,3 +63,3 @@ owner: this.owner | ||
* @param {Object} style Mapbox GL Style Spec object | ||
* @param {Function} callback called with (err, datasets) | ||
* @param {Function} callback called with (err, createdStyle) | ||
* @returns {Promise} response | ||
@@ -74,3 +83,3 @@ * @example | ||
return this.client({ | ||
path: constants.API_STYLES_CREATE, | ||
path: API_STYLES_CREATE, | ||
params: { | ||
@@ -89,3 +98,3 @@ owner: this.owner | ||
* @param {string} styleid style id | ||
* @param {Function} callback called with (err, datasets) | ||
* @param {Function} callback called with (err, createdStyle) | ||
* @returns {Promise} response | ||
@@ -110,3 +119,3 @@ * @example | ||
return this.client({ | ||
path: constants.API_STYLES_UPDATE, | ||
path: API_STYLES_UPDATE, | ||
params: { | ||
@@ -131,4 +140,4 @@ owner: this.owner, | ||
* 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!'); | ||
* }); | ||
@@ -140,3 +149,3 @@ */ | ||
return this.client({ | ||
path: constants.API_STYLES_DELETE, | ||
path: API_STYLES_DELETE, | ||
params: { | ||
@@ -155,3 +164,3 @@ owner: this.owner, | ||
* @param {string} styleid the id for an existing style | ||
* @param {Function} callback called with (err) | ||
* @param {Function} callback called with (err, style) | ||
* @returns {Promise} response | ||
@@ -161,4 +170,4 @@ * @example | ||
* 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); | ||
* }); | ||
@@ -170,3 +179,3 @@ */ | ||
return this.client({ | ||
path: constants.API_STYLES_READ, | ||
path: API_STYLES_READ, | ||
params: { | ||
@@ -224,3 +233,3 @@ owner: this.owner, | ||
return this.client({ | ||
path: constants.API_STYLES_SPRITE, | ||
path: API_STYLES_SPRITE, | ||
params: { | ||
@@ -258,3 +267,3 @@ owner: this.owner, | ||
return this.client({ | ||
path: constants.API_STYLES_FONT_GLYPH_RANGES, | ||
path: API_STYLES_FONT_GLYPH_RANGES, | ||
params: { | ||
@@ -292,3 +301,3 @@ owner: this.owner, | ||
return this.client({ | ||
path: constants.API_STYLES_SPRITE_ADD_ICON, | ||
path: API_STYLES_SPRITE_ICON, | ||
params: { | ||
@@ -327,3 +336,3 @@ owner: this.owner, | ||
return this.client({ | ||
path: constants.API_STYLES_SPRITE_ADD_ICON, | ||
path: API_STYLES_SPRITE_ICON, | ||
params: { | ||
@@ -375,3 +384,3 @@ owner: this.owner, | ||
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'); | ||
var MapboxSurface = makeService('MapboxSurface'); | ||
var API_SURFACE = '/v4/surface/{mapid}.json{?access_token,layer,fields,points,geojson,interpolate,encoded_polyline}'; | ||
/** | ||
@@ -89,3 +90,3 @@ * Given a list of locations, retrieve vector tiles, find the nearest | ||
return this.client({ | ||
path: constants.API_SURFACE, | ||
path: API_SURFACE, | ||
params: surfaceOptions, | ||
@@ -92,0 +93,0 @@ callback: callback |
'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'); | ||
var API_TILESTATS_STATISTICS = '/tilestats/v1/{owner}/{tileset}{?access_token}'; | ||
/** | ||
@@ -49,3 +50,3 @@ * To retrieve statistics about a specific tileset. | ||
return this.client({ | ||
path: constants.API_TILESTATS_STATISTICS, | ||
path: API_TILESTATS_STATISTICS, | ||
params: { | ||
@@ -84,3 +85,3 @@ owner: owner, | ||
return this.client({ | ||
path: constants.API_TILESTATS_STATISTICS, | ||
path: API_TILESTATS_STATISTICS, | ||
params: { | ||
@@ -87,0 +88,0 @@ owner: owner, |
'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'); | ||
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}'; | ||
/** | ||
@@ -46,3 +49,3 @@ * Retrieve a listing of uploads for a particular account. | ||
return this.client({ | ||
path: constants.API_UPLOADS, | ||
path: API_UPLOADS, | ||
params: { owner: this.owner }, | ||
@@ -93,4 +96,5 @@ callback: callback | ||
return this.client({ | ||
path: constants.API_UPLOAD_CREDENTIALS, | ||
path: API_UPLOAD_CREDENTIALS, | ||
params: { owner: this.owner }, | ||
method: 'post', | ||
callback: callback | ||
@@ -146,3 +150,3 @@ }); | ||
return this.client({ | ||
path: constants.API_UPLOADS, | ||
path: API_UPLOADS, | ||
params: { owner: this.owner }, | ||
@@ -182,3 +186,3 @@ entity: options, | ||
return this.client({ | ||
path: constants.API_UPLOAD, | ||
path: API_UPLOAD, | ||
params: { | ||
@@ -210,3 +214,3 @@ owner: this.owner, | ||
method: 'delete', | ||
path: constants.API_UPLOAD, | ||
path: API_UPLOAD, | ||
params: { | ||
@@ -213,0 +217,0 @@ owner: this.owner, |
@@ -8,13 +8,10 @@ var interceptor = require('rest/interceptor'); | ||
function transform(response) { | ||
var status = undefined; | ||
if (response.status) { | ||
status = response.status.code; | ||
} | ||
return { | ||
url: response.url, | ||
status: status, | ||
status: response.status && response.status.code, | ||
headers: response.headers, | ||
entity: response.entity, | ||
error: response.error, | ||
callback: response.request.callback | ||
callback: response.request && response.request.callback, | ||
nextPage: response.nextPage | ||
}; | ||
@@ -21,0 +18,0 @@ } |
{ | ||
"name": "mapbox", | ||
"version": "1.0.0-beta6", | ||
"version": "1.0.0-beta7", | ||
"description": "interface to mapbox services", | ||
@@ -38,2 +38,6 @@ "main": "lib/mapbox.js", | ||
"author": "Tom MacWright", | ||
"contributors": [ | ||
{ "name" : "Andrew Harvey", "email": "andrew@alantgeo.com.au" }, | ||
{ "name": "Scott Andrews", "email": "scott@mapbox.com" } | ||
], | ||
"license": "ISC", | ||
@@ -40,0 +44,0 @@ "bugs": { |
@@ -14,8 +14,8 @@ # 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 | ||
@@ -26,2 +26,8 @@ * GeoJSON & Polyline formatting | ||
* 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. | ||
@@ -47,3 +53,3 @@ Contact help@mapbox.com for information | ||
Basic usage of the geocoder: | ||
Setup: | ||
@@ -53,7 +59,33 @@ ```js | ||
var client = new MapboxClient('YOUR_ACCESS_TOKEN'); | ||
client.geocodeForward('Chester, NJ', function(err, res) { | ||
// res is the geocoding result as parsed JSON | ||
``` | ||
Basic usage of the geocoder: | ||
```js | ||
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 | ||
@@ -72,4 +104,11 @@ | ||
* directions: `require('mapbox/lib/services/directions')` | ||
* distance: `require('mapbox/lib/services/distance')` | ||
* 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) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
463963
34
11054
110
3