mapcomplete/Logic/Geocoding.ts
2020-07-01 21:21:29 +02:00

27 lines
874 B
TypeScript

import * as $ from "jquery"
import {UIEventSource} from "../UI/UIEventSource";
import {Basemap} from "./Basemap";
export class Geocoding {
private static readonly host = "https://nominatim.openstreetmap.org/search?";
static Search(query: string,
basemap: Basemap,
handleResult: ((places: { display_name: string, lat: number, lon: number, boundingbox: number[] }[]) => void),
onFail: (() => void)) {
const b = basemap.map.getBounds();
console.log(b);
$.getJSON(
Geocoding.host + "format=json&limit=1&viewbox=" +
`${b.getEast()},${b.getNorth()},${b.getWest()},${b.getSouth()}`+
"&accept-language=nl&q=" + query,
function (data) {
handleResult(data);
}).fail(() => {
onFail();
});
}
}