Skip to content

Commit

Permalink
options.proximity as array
Browse files Browse the repository at this point in the history
Match mapbox-gl-js by setting `options.proximity` as [lng, lat] coordinates.

- Fixes #29
  • Loading branch information
tristen committed Dec 6, 2015
1 parent 858087b commit f4235a4
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 1 addition & 4 deletions example/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ var directions = mapboxgl.Directions({
unit: 'metric',
profile: 'walking',
container: 'directions',
proximity: {
latitude: 66.1,
longitude: 45.3
}
proximity: [-79.45, 43.65]
});

var button = document.createElement('button');
Expand Down
2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @param {String} [options.profile="driving"] Routing profile to use. Options: `driving`, `walking`, `cycling`
* @param {String} [options.unit="imperial"] Measurement system to be used in navigation instructions. Options: `imperial`, `metric`
* @param {string|Element} options.container HTML element to initialize the map in (or element id as string). If no container is passed map.getContainer() is used instead.
* @param {Object} [options.proximity=false] Object a proximity argument: this is a geographical point given as an object with latitude and longitude properties. Search results closer to this point will be given higher priority.
* @param {Array<Array<number>>} options.proximity If set, search results closer to these coordinates will be given higher priority.
* @example
* var directions = Directions(document.getElementById('directions'), {
* unit: 'metric',
Expand Down
8 changes: 7 additions & 1 deletion src/actions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,13 @@ function setHoverMarker(feature) {
function geocode(query, callback) {
return (dispatch, getState) => {
const { proximity } = getState();
const options = proximity ? { proximity } : {};
const options = proximity ? {
proximity: {
longitude: proximity[0],
latitude: proximity[1]
}
} : {};

return mapbox.geocodeForward(query.trim(), options, (err, res) => {
if (err) throw err;
return dispatch(callback(res.features));
Expand Down

0 comments on commit f4235a4

Please sign in to comment.