forked from MapComplete/MapComplete
Small refactoring of search
This commit is contained in:
parent
fc3a043795
commit
14956e229c
2 changed files with 33 additions and 35 deletions
|
@ -1,23 +1,22 @@
|
|||
import State from "../../State";
|
||||
import {Utils} from "../../Utils";
|
||||
import {BBox} from "../BBox";
|
||||
|
||||
export interface GeoCodeResult {
|
||||
display_name: string,
|
||||
lat: number, lon: number, boundingbox: number[],
|
||||
osm_type: string, osm_id: string
|
||||
}
|
||||
|
||||
export class Geocoding {
|
||||
|
||||
private static readonly host = "https://nominatim.openstreetmap.org/search?";
|
||||
|
||||
static Search(query: string,
|
||||
handleResult: ((places: {
|
||||
display_name: string, lat: number, lon: number, boundingbox: number[],
|
||||
osm_type: string, osm_id: string
|
||||
}[]) => void),
|
||||
onFail: (() => void)) {
|
||||
const b = State.state.currentBounds.data;
|
||||
static async Search(query: string): Promise<GeoCodeResult[]> {
|
||||
const b = State?.state?.currentBounds?.data ?? BBox.global;
|
||||
const url = Geocoding.host + "format=json&limit=1&viewbox=" +
|
||||
`${b.getEast()},${b.getNorth()},${b.getWest()},${b.getSouth()}` +
|
||||
"&accept-language=nl&q=" + query;
|
||||
Utils.downloadJson(
|
||||
url)
|
||||
.then(handleResult)
|
||||
.catch(onFail);
|
||||
return Utils.downloadJson(url)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue