mapcomplete/Logic/Osm/Geocoding.ts

26 lines
846 B
TypeScript
Raw Normal View History

2020-07-29 22:59:08 +00:00
import $ from "jquery"
import State from "../../State";
2020-07-01 00:12:33 +00:00
export class Geocoding {
private static readonly host = "https://nominatim.openstreetmap.org/search?";
2020-07-01 19:21:29 +00: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 19:21:29 +00:00
onFail: (() => void)) {
2021-01-02 20:03:40 +00:00
const b = State.state.leafletMap.data.getBounds();
2020-07-01 19:21:29 +00:00
console.log(b);
2020-07-01 00:12:33 +00:00
$.getJSON(
2020-07-01 19:21:29 +00:00
Geocoding.host + "format=json&limit=1&viewbox=" +
`${b.getEast()},${b.getNorth()},${b.getWest()},${b.getSouth()}`+
"&accept-language=nl&q=" + query,
2020-07-01 00:12:33 +00:00
function (data) {
2020-07-01 19:21:29 +00:00
handleResult(data);
}).fail(() => {
onFail();
});
2020-07-01 00:12:33 +00:00
}
}