diff --git a/demo/index.js b/demo/index.js index dea8f88..dcf60d2 100644 --- a/demo/index.js +++ b/demo/index.js @@ -34,7 +34,15 @@ function onMapInit() { searchFormEl.addEventListener('submit', function (event) { event.preventDefault(); const { place, ll, type, max, partial } = searchFormEl; - if (place) { + if (ll.value) { + const detail = { + ll: ll.value.split(',').map(l => parseFloat(l.trim())), + max: max.value, + type: place.value + }; + window.dispatchEvent(new CustomEvent('ll', { detail })); + } + else if (place.value) { const detail = { bounds: map.bounds(), max: max.value, @@ -44,12 +52,6 @@ function onMapInit() { detail.partial = true; } window.dispatchEvent(new CustomEvent('place', { detail })); - } else if (ll.value) { - const detail = { - ll: ll.value.split(',').map(l => parseFloat(l.trim())), - max: max.value - }; - window.dispatchEvent(new CustomEvent('ll', { detail })); } }); } @@ -83,6 +85,9 @@ if (process.env.HOGFISH_KEY) { ], fillingstation: [ 'provider=fuel' + ], + place: [ + 'provider=universal' ] } }, diff --git a/lib/service/hogfish/index.js b/lib/service/hogfish/index.js index 86629a4..2231145 100644 --- a/lib/service/hogfish/index.js +++ b/lib/service/hogfish/index.js @@ -22,12 +22,19 @@ function getUrl(url, types, op, query) { case 'reverse': q.push('ll=' + query.ll.join(',')); q.push('radius=100'); - q.push(...types[query.type]); break; - default: + case 'forward': + q.push('q=' + encodeURIComponent(query.place || query.address)); + if (query.bounds) { + q.push('sw=' + query.bounds[0].join(',')); + q.push('ne=' + query.bounds[1].join(',')); + } + break; + default: // invalid operation return; } + q.push(...types[query.type]); if (query.max) { q.push('limit=' + query.max); } @@ -35,6 +42,9 @@ function getUrl(url, types, op, query) { } function prepareRequest(types, op, query) { + if (op === 'forward') { + query.type = query.type ?? ['place', 'address'].find(type => query.hasOwnProperty(type)); + } return Boolean(types[query.type]); } @@ -115,6 +125,7 @@ function init(options) { } options = util.defaults(options, { reverse: true, + forward: true, url: getUrl.bind(undefined, options.hogfish_url, options.types), status: getStatus, prepareRequest: prepareRequest.bind(undefined, options.types),