Co-authored-by: sora-ext Co-authored-by: soraefir Reviewed-on: #160
This commit is contained in:
27
src/server/api_nominatim.ts
Normal file
27
src/server/api_nominatim.ts
Normal file
@ -0,0 +1,27 @@
|
||||
|
||||
function drop_fields(results) {
|
||||
results.forEach(e => {
|
||||
delete e.licence;
|
||||
delete e.place_rank;
|
||||
delete e.importance;
|
||||
delete e.boundingbox;
|
||||
});
|
||||
return results
|
||||
}
|
||||
|
||||
export function nominatim_get_data(id: string, bb: string[][] | null = null): Promise<any> {
|
||||
if (!id) return Promise.resolve([])
|
||||
|
||||
const url = new URL("https://nominatim.openstreetmap.org/search");
|
||||
url.searchParams.append('format', 'jsonv2')
|
||||
url.searchParams.append('q', id)
|
||||
url.searchParams.append('limit', '20')
|
||||
if (bb) {
|
||||
url.searchParams.append('viewbox', `${bb[0][0]},${bb[0][1]},${bb[1][0]},${bb[1][1]}`)
|
||||
url.searchParams.append('bounded', `1`)
|
||||
}
|
||||
return fetch(url).then((res) => {
|
||||
if (!res.ok) throw new Error("Nominatim Error")
|
||||
return res.json().then(r => drop_fields(r))
|
||||
})
|
||||
}
|
Reference in New Issue
Block a user