Skip to content

Commit b5218c4

Browse files
author
Natalia Kowalczyk
committed
add support for hogfish forward geocoder
1 parent cf1dca7 commit b5218c4

File tree

2 files changed

+25
-9
lines changed

2 files changed

+25
-9
lines changed

demo/index.js

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,15 @@ function onMapInit() {
3434
searchFormEl.addEventListener('submit', function (event) {
3535
event.preventDefault();
3636
const { place, ll, type, max, partial } = searchFormEl;
37-
if (place) {
37+
if (ll.value) {
38+
const detail = {
39+
ll: ll.value.split(',').map(l => parseFloat(l.trim())),
40+
max: max.value,
41+
type: place.value
42+
};
43+
window.dispatchEvent(new CustomEvent('ll', { detail }));
44+
}
45+
else if (place.value) {
3846
const detail = {
3947
bounds: map.bounds(),
4048
max: max.value,
@@ -44,12 +52,6 @@ function onMapInit() {
4452
detail.partial = true;
4553
}
4654
window.dispatchEvent(new CustomEvent('place', { detail }));
47-
} else if (ll.value) {
48-
const detail = {
49-
ll: ll.value.split(',').map(l => parseFloat(l.trim())),
50-
max: max.value
51-
};
52-
window.dispatchEvent(new CustomEvent('ll', { detail }));
5355
}
5456
});
5557
}
@@ -83,6 +85,9 @@ if (process.env.HOGFISH_KEY) {
8385
],
8486
fillingstation: [
8587
'provider=fuel'
88+
],
89+
place: [
90+
'provider=universal'
8691
]
8792
}
8893
},

lib/service/hogfish/index.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,29 @@ function getUrl(url, types, op, query) {
2222
case 'reverse':
2323
q.push('ll=' + query.ll.join(','));
2424
q.push('radius=100');
25-
q.push(...types[query.type]);
2625
break;
27-
default:
26+
case 'forward':
27+
q.push('q=' + encodeURIComponent(query.place || query.address));
28+
if (query.bounds) {
29+
q.push('sw=' + query.bounds[0].join(','));
30+
q.push('ne=' + query.bounds[1].join(','));
31+
}
32+
break;
33+
default:
2834
// invalid operation
2935
return;
3036
}
37+
q.push(...types[query.type]);
3138
if (query.max) {
3239
q.push('limit=' + query.max);
3340
}
3441
return url + '?' + q.join('&');
3542
}
3643

3744
function prepareRequest(types, op, query) {
45+
if (op === 'forward') {
46+
query.type = query.type ?? ['place', 'address'].find(type => query.hasOwnProperty(type));
47+
}
3848
return Boolean(types[query.type]);
3949
}
4050

@@ -115,6 +125,7 @@ function init(options) {
115125
}
116126
options = util.defaults(options, {
117127
reverse: true,
128+
forward: true,
118129
url: getUrl.bind(undefined, options.hogfish_url, options.types),
119130
status: getStatus,
120131
prepareRequest: prepareRequest.bind(undefined, options.types),

0 commit comments

Comments
 (0)