2020-10-02 19:00:24 +02:00
|
|
|
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,
|
2021-09-09 00:05:51 +02:00
|
|
|
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=" +
|
2021-09-09 00:05:51 +02:00
|
|
|
`${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
|
|
|
}
|
|
|
|
}
|