forked from MapComplete/MapComplete
		
	
		
			
				
	
	
		
			27 lines
		
	
	
	
		
			874 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			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();
 | 
						|
        });
 | 
						|
    }
 | 
						|
 | 
						|
 | 
						|
}
 |