Comparing version 0.3.0 to 0.4.0
51
API.md
@@ -22,3 +22,4 @@ ## `MapboxClient` | ||
Search for a location with a string. | ||
Search for a location with a string, using the | ||
[Mapbox Geocoding API](https://www.mapbox.com/developers/api/geocoding/). | ||
@@ -52,3 +53,3 @@ ### Parameters | ||
Given a location, determine what geographical features are located | ||
there. | ||
there. This uses the [Mapbox Geocoding API](https://www.mapbox.com/developers/api/geocoding/). | ||
@@ -116,1 +117,47 @@ ### Parameters | ||
## `matching` | ||
Snap recorded location traces to roads and paths from OpenStreetMap. | ||
Consult the [Map Matching API](https://www.mapbox.com/developers/api/map-matching/) | ||
for more documentation. | ||
### Parameters | ||
* `trace` **`Object`** a single [GeoJSON](http://geojson.org/) Feature with a LineString geometry, containing up to 100 positions. | ||
* `options` **`[Object]`** additional options meant to tune the request (optional, default `{}`) | ||
* `callback` **`Function`** called with (err, results) | ||
### Examples | ||
```js | ||
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 | ||
}); | ||
``` | ||
Returns nothing, calls callback | ||
@@ -5,2 +5,3 @@ 'use strict'; | ||
resolveToString = require('es6-template-strings/resolve-to-string'), | ||
geojsonhint = require('geojsonhint'), | ||
qs = require('querystring'), | ||
@@ -31,3 +32,4 @@ request = require('superagent'), | ||
/** | ||
* Search for a location with a string. | ||
* Search for a location with a string, using the | ||
* [Mapbox Geocoding API](https://www.mapbox.com/developers/api/geocoding/). | ||
* | ||
@@ -98,3 +100,3 @@ * @param {string} query desired location | ||
* Given a location, determine what geographical features are located | ||
* there. | ||
* there. This uses the [Mapbox Geocoding API](https://www.mapbox.com/developers/api/geocoding/). | ||
* | ||
@@ -260,2 +262,106 @@ * @param {Object} location the geographical point to search | ||
/** | ||
* Snap recorded location traces to roads and paths from OpenStreetMap. | ||
* Consult the [Map Matching API](https://www.mapbox.com/developers/api/map-matching/) | ||
* for more documentation. | ||
* | ||
* @param {Object} trace a single [GeoJSON](http://geojson.org/) | ||
* Feature with a LineString geometry, containing up to 100 positions. | ||
* @param {Object} [options={}] additional options meant to tune | ||
* the request | ||
* @param {string} [options.profile=mapbox.driving] the directions | ||
* profile, which determines how to prioritize different routes. | ||
* Options are `'mapbox.driving'`, which assumes transportation via an | ||
* automobile and will use highways, `'mapbox.walking'`, which avoids | ||
* streets without sidewalks, and `'mapbox.cycling'`, which prefers streets | ||
* with bicycle lanes and lower speed limits for transportation via | ||
* bicycle. | ||
* @param {string} [options.geometry=geojson] format for the returned | ||
* route. Options are `'geojson'`, `'polyline'`, or `false`: `polyline` | ||
* yields more compact responses which can be decoded on the client side. | ||
* [GeoJSON](http://geojson.org/), the default, is compatible with libraries | ||
* like [Mapbox GL](https://www.mapbox.com/mapbox-gl/), | ||
* Leaflet and [Mapbox.js](https://www.mapbox.com/mapbox.js/). `false` | ||
* omits the geometry entirely and only returns matched points. | ||
* @param {number} [options.gps_precision=4] An integer in meters indicating | ||
* the assumed precision of the used tracking device. Use higher | ||
* numbers (5-10) for noisy traces and lower numbers (1-3) for clean | ||
* traces. The default value is 4. | ||
* @param {Function} callback called with (err, results) | ||
* @returns {undefined} nothing, calls callback | ||
* @example | ||
* var mapboxClient = new MapboxClient('ACCESSTOKEN'); | ||
* mapboxClient.matching({ | ||
* "type": "Feature", | ||
* "properties": { | ||
* "coordTimes": [ | ||
* "2015-04-21T06:00:00Z", | ||
* "2015-04-21T06:00:05Z", | ||
* "2015-04-21T06:00:10Z", | ||
* "2015-04-21T06:00:15Z", | ||
* "2015-04-21T06:00:20Z" | ||
* ] | ||
* }, | ||
* "geometry": { | ||
* "type": "LineString", | ||
* "coordinates": [ | ||
* [ 13.418946862220764, 52.50055852688439 ], | ||
* [ 13.419011235237122, 52.50113000479732 ], | ||
* [ 13.419756889343262, 52.50171780290061 ], | ||
* [ 13.419885635375975, 52.50237416816131 ], | ||
* [ 13.420631289482117, 52.50294888790448 ] | ||
* ] | ||
* } | ||
* }, | ||
* function(err, res) { | ||
* // res is a document with directions | ||
* }); | ||
*/ | ||
MapboxClient.prototype.matching = function(trace, options, callback) { | ||
// permit the options argument to be omitted | ||
if (callback === undefined && typeof options === 'function') { | ||
callback = options; | ||
options = {}; | ||
} | ||
// typecheck arguments | ||
assert(geojsonhint.hint(trace).length === 0, 'trace must be valid GeoJSON'); | ||
assert(typeof options === 'object', 'options must be an object'); | ||
assert(typeof callback === 'function', 'callback must be a function'); | ||
var profile = 'mapbox.driving', | ||
gps_precision = 4, | ||
geometry = 'geojson'; | ||
if (options.gps_precision !== undefined) { | ||
assert(typeof options.gps_precision === 'number', 'gps_precision must be a number'); | ||
gps_precision = options.gps_precision; | ||
} | ||
if (options.profile) { | ||
assert(typeof options.profile === 'string', 'profile option must be string'); | ||
profile = options.profile; | ||
} | ||
if (options.geometry) { | ||
assert(typeof options.geometry === 'string', 'geometry option must be string'); | ||
geometry = options.geometry; | ||
} | ||
var url = resolveToString(constants.API_MATCHING, { | ||
profile: profile | ||
}) + this.q({ | ||
geometry: geometry, | ||
gps_precision: gps_precision | ||
}); | ||
request.post(url) | ||
.send(trace) | ||
.end(function(err, res) { | ||
callback(err, res.body); | ||
}); | ||
}; | ||
module.exports = MapboxClient; |
var compile = require('es6-template-strings/compile'); | ||
var API = 'http://api.tiles.mapbox.com/v4/'; | ||
var API = 'https://api.tiles.mapbox.com/'; | ||
var APIV4 = API + 'v4/'; | ||
module.exports.API = API; | ||
module.exports.API_GEOCODER_FORWARD = compile(API + 'geocode/${dataset}/${encodeURIComponent(query)}.json'); | ||
module.exports.API_GEOCODER_REVERSE = compile(API + 'geocode/${dataset}/${location.longitude},${location.latitude}.json'); | ||
module.exports.API_DIRECTIONS = compile(API + 'directions/${profile}/${encodedWaypoints}.json'); | ||
module.exports.API_GEOCODER_FORWARD = compile(APIV4 + 'geocode/${dataset}/${encodeURIComponent(query)}.json'); | ||
module.exports.API_GEOCODER_REVERSE = compile(APIV4 + 'geocode/${dataset}/${location.longitude},${location.latitude}.json'); | ||
module.exports.API_DIRECTIONS = compile(APIV4 + 'directions/${profile}/${encodedWaypoints}.json'); | ||
module.exports.API_MATCHING = compile(API + 'matching/v4/${profile}.json'); |
{ | ||
"name": "mapbox", | ||
"version": "0.3.0", | ||
"version": "0.4.0", | ||
"description": "interface to mapbox services", | ||
@@ -34,4 +34,5 @@ "main": "lib/client.js", | ||
"es6-template-strings": "^1.0.0", | ||
"geojsonhint": "^1.0.1", | ||
"superagent": "^1.2.0" | ||
} | ||
} |
@@ -12,5 +12,12 @@ # node-mapbox | ||
* Geocoding | ||
* [Geocoding](https://www.mapbox.com/developers/api/geocoding/) | ||
* Forward (place names ⇢ longitude, latitude) | ||
* Reverse (longitude, latitude ⇢ place names) | ||
* [Directions](https://www.mapbox.com/developers/api/directions/) | ||
* Profiles for driving, walking, and cycling | ||
* GeoJSON & Polyline formatting | ||
* Instructions as text or HTML | ||
* [Map Matching](https://www.mapbox.com/developers/api/map-matching/) | ||
* Aligns GPS trace data to roads and paths from | ||
[OpenStreetMap](https://www.openstreetmap.org/) data | ||
@@ -17,0 +24,0 @@ ## Installation |
@@ -135,3 +135,3 @@ /* eslint no-shadow: 0 */ | ||
test('MapboxClient#directions', function(t) { | ||
test('MapboxClient#getDirections', function(t) { | ||
t.test('typecheck', function(t) { | ||
@@ -188,1 +188,70 @@ var client = new MapboxClient(process.env.MapboxAccessToken); | ||
}); | ||
test('MapboxClient#matching', function(t) { | ||
t.test('typecheck', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
t.throws(function() { | ||
client.matching(null); | ||
}); | ||
t.throws(function() { | ||
client.matching(1, function() {}); | ||
}); | ||
t.throws(function() { | ||
client.matching('foo', 1, function() {}); | ||
}); | ||
t.throws(function() { | ||
client.matching('foo', 1); | ||
}); | ||
t.end(); | ||
}); | ||
var sample = { | ||
'type': 'Feature', | ||
'properties': { | ||
'coordTimes': [ | ||
'2015-04-21T06:00:00Z', | ||
'2015-04-21T06:00:05Z', | ||
'2015-04-21T06:00:10Z', | ||
'2015-04-21T06:00:15Z', | ||
'2015-04-21T06:00:20Z' | ||
] | ||
}, | ||
'geometry': { | ||
'type': 'LineString', | ||
'coordinates': [ | ||
[ 13.418946862220764, 52.50055852688439 ], | ||
[ 13.419011235237122, 52.50113000479732 ], | ||
[ 13.419756889343262, 52.50171780290061 ], | ||
[ 13.419885635375975, 52.50237416816131 ], | ||
[ 13.420631289482117, 52.50294888790448 ] | ||
] | ||
} | ||
}; | ||
t.test('no options', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.matching(sample, function(err, results) { | ||
t.ifError(err); | ||
t.deepEqual(geojsonhint.hint(results), [], 'results are valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.test('all options', function(t) { | ||
var client = new MapboxClient(process.env.MapboxAccessToken); | ||
t.ok(client); | ||
client.matching(sample, { | ||
gps_precision: 8, | ||
profile: 'mapbox.walking', | ||
geometry: 'polyline' | ||
}, function(err, results) { | ||
t.ifError(err); | ||
t.ok(results, 'results are valid'); | ||
t.end(); | ||
}); | ||
}); | ||
t.end(); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
40886
12
566
30
0
3
14
+ Addedgeojsonhint@^1.0.1
+ AddedJSV@4.0.2(transitive)
+ Addedansi-regex@2.1.1(transitive)
+ Addedansi-styles@1.0.02.2.1(transitive)
+ Addedchalk@0.4.01.1.3(transitive)
+ Addedconcat-stream@1.4.11(transitive)
+ Addedescape-string-regexp@1.0.5(transitive)
+ Addedgeojsonhint@1.2.1(transitive)
+ Addedhas-ansi@2.0.0(transitive)
+ Addedhas-color@0.1.7(transitive)
+ Addedjsonlint-lines@1.7.1(transitive)
+ Addedminimist@1.1.1(transitive)
+ Addednomnom@1.8.1(transitive)
+ Addedreadable-stream@1.1.14(transitive)
+ Addedstrip-ansi@0.1.13.0.1(transitive)
+ Addedsupports-color@2.0.0(transitive)
+ Addedtext-table@0.2.0(transitive)
+ Addedtypedarray@0.0.7(transitive)
+ Addedunderscore@1.6.0(transitive)