Skip to content

Commit

Permalink
Merge pull request #40 from conveyal/add-url-param
Browse files Browse the repository at this point in the history
feat(url-param): add optional url param for overriding Mapzen Search …
  • Loading branch information
Landon Reed authored Jun 8, 2017
2 parents 4646c13 + 8ceebff commit 7bfe973
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ service.
[layer types](https://mapzen.com/documentation/search/autocomplete/#layers)
- `$0.sources` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** (optional, default `'gn,oa,osm,wof'`)
- `$0.text` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** query text
- `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen autocomplete endpoint (optional, default `'https://search.mapzen.com/v1/autocomplete'`)

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with the autocomplete result

Expand All @@ -122,6 +123,7 @@ service.
- `$0.size` **[number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)?** (optional, default `10`)
- `$0.sources` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** (optional, default `'gn,oa,osm,wof'`)
- `$0.text` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The address text to query for
- `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen search endpoint (optional, default `'https://search.mapzen.com/v1/search'`)

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with search result

Expand All @@ -137,5 +139,6 @@ service.
- `$0.apiKey` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)** The Mapzen API key
- `$0.format` **[boolean](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Boolean)**
- `$0.point` **{lat: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number), lon: [number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number)}** Point to reverse geocode
- `$0.url` **[string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String)?** optional URL to override Mapzen reverse endpoint (optional, default `'https://search.mapzen.com/v1/reverse'`)

Returns **[Promise](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise)** A Promise that'll get resolved with reverse geocode result
16 changes: 11 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const searchUrl = `${mapzenUrl}/search`
* {@link https://mapzen.com/documentation/search/autocomplete/#layers|layer types}
* @param {string} [$0.sources='gn,oa,osm,wof']
* @param {string} $0.text query text
* @param {string} [$0.url='https://search.mapzen.com/v1/autocomplete'] optional URL to override Mapzen autocomplete endpoint
* @return {Promise} A Promise that'll get resolved with the autocomplete result
*/
export function autocomplete ({
Expand All @@ -35,7 +36,8 @@ export function autocomplete ({
format,
layers,
sources = 'gn,oa,osm,wof',
text
text,
url = autocompleteUrl
}) {
// build query
const query = {
Expand Down Expand Up @@ -75,7 +77,7 @@ export function autocomplete ({
return run({
format,
query,
url: autocompleteUrl
url
})
}

Expand All @@ -92,6 +94,7 @@ export function autocomplete ({
* @param {number} [$0.size=10]
* @param {string} [$0.sources='gn,oa,osm,wof']
* @param {string} $0.text The address text to query for
* @param {string} [$0.url='https://search.mapzen.com/v1/search'] optional URL to override Mapzen search endpoint
* @return {Promise} A Promise that'll get resolved with search result
*/
export function search ({
Expand All @@ -101,7 +104,8 @@ export function search ({
format,
size = 10,
sources = 'gn,oa,osm,wof',
text
text,
url = searchUrl
}) {
if (!text) return Promise.resolve([])

Expand Down Expand Up @@ -146,12 +150,14 @@ export function search ({
* @param {string} $0.apiKey The Mapzen API key
* @param {boolean} $0.format
* @param {{lat: number, lon: number}} $0.point Point to reverse geocode
* @param {string} [$0.url='https://search.mapzen.com/v1/reverse'] optional URL to override Mapzen reverse endpoint
* @return {Promise} A Promise that'll get resolved with reverse geocode result
*/
export function reverse ({
apiKey,
format,
point
point,
url = reverseUrl
}) {
const {lon, lat} = lonlat(point)
return run({
Expand All @@ -161,7 +167,7 @@ export function reverse ({
'point.lat': lat,
'point.lon': lon
},
url: reverseUrl
url
})
}

Expand Down

0 comments on commit 7bfe973

Please sign in to comment.