-
Notifications
You must be signed in to change notification settings - Fork 92
/
Copy pathosm.js
62 lines (55 loc) · 1.42 KB
/
osm.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/**
* @class OpenStreet
*/
export class OpenStreet {
/**
* @constructor
*/
constructor() {
this.settings = {
url: 'https://nominatim.openstreetmap.org/search/',
params: {
q: '',
format: 'json',
addressdetails: 1,
limit: 10,
countrycodes: '',
'accept-language': 'en-US',
},
};
}
getParameters(opt) {
return {
url: this.settings.url,
params: {
q: opt.query,
format: this.settings.params.format,
addressdetails: this.settings.params.addressdetails,
limit: opt.limit || this.settings.params.limit,
countrycodes: opt.countrycodes || this.settings.params.countrycodes,
'accept-language': opt.lang || this.settings.params['accept-language'],
},
};
}
handleResponse(results) {
if (results.length === 0) return [];
return results.map((result) => ({
lon: result.lon,
lat: result.lat,
bbox: result.boundingbox,
address: {
name: result.display_name,
road: result.address.road || '',
houseNumber: result.address.house_number || '',
postcode: result.address.postcode,
city: result.address.city || result.address.town,
state: result.address.state,
country: result.address.country,
},
original: {
formatted: result.display_name,
details: result.address,
},
}));
}
}