mapcomplete/Logic/Osm/Geocoding.ts

24 lines
844 B
TypeScript
Raw Normal View History

import State from "../../State";
2021-07-03 22:24:12 +02:00
import {Utils} from "../../Utils";
2020-07-01 02:12:33 +02:00
export class Geocoding {
private static readonly host = "https://nominatim.openstreetmap.org/search?";
2020-07-01 21:21:29 +02:00
static Search(query: string,
handleResult: ((places: {
display_name: string, lat: number, lon: number, boundingbox: number[],
osm_type: string, osm_id: string
}[]) => void),
2020-07-01 21:21:29 +02:00
onFail: (() => void)) {
2021-01-02 21:03:40 +01:00
const b = State.state.leafletMap.data.getBounds();
2021-07-03 22:24:12 +02:00
const url = Geocoding.host + "format=json&limit=1&viewbox=" +
`${b.getEast()},${b.getNorth()},${b.getWest()},${b.getSouth()}` +
2021-07-03 22:24:12 +02:00
"&accept-language=nl&q=" + query;
Utils.downloadJson(
url)
.then(handleResult)
.catch(onFail);
2020-07-01 02:12:33 +02:00
}
}