export type PointTuple = [number, number]; export type BoundsTuple = [PointTuple, PointTuple]; export interface LatLng { lat: number; lng: number; } export interface SearchResult { x: number; y: number; label: string; bounds: BoundsTuple | null; raw: TRawResult; } export interface ProviderParams { [key: string]: string | number | boolean; } export interface ProviderOptions { params?: ProviderParams; } export declare enum RequestType { SEARCH = 0, REVERSE = 1 } export interface EndpointArgument { query: string | { [key: string]: string | number | boolean; }; type?: RequestType; } export interface SearchArgument { query: string; /** aborts the request, e.g. when a newer search starts */ signal?: AbortSignal; } export interface ReverseArgument extends LatLng { /** aborts the request */ signal?: AbortSignal; } export interface ParseArgument { data: TData; } export interface Provider { options: ProviderOptions; endpoint(options: EndpointArgument): string; getParamString(params: ProviderParams): string; parse(response: ParseArgument): SearchResult[]; search(options: SearchArgument): Promise[]>; reverse?(options: ReverseArgument): Promise[]>; } export default abstract class AbstractProvider implements Provider { options: ProviderOptions; constructor(options?: ProviderOptions); abstract endpoint(options: EndpointArgument): string; abstract parse(response: ParseArgument): SearchResult[]; getParamString(params?: ProviderParams): string; getUrl(url: string, params?: ProviderParams): string; search(options: SearchArgument): Promise[]>; /** * the query of a reverse request for a position. The names differ per * service. Providers that can't reverse geocode return null */ reverseParams(_position: LatLng): ProviderParams | null; /** the places at a position, closest first */ reverse({ lat, lng, signal, }: ReverseArgument): Promise[]>; } /** * Reads a JSON body. Error responses with a JSON body are still returned, as * some providers answer "no results" that way. Error responses that aren't * JSON (e.g. an html block page) throw an error that mentions the status. */ export declare function readJson(response: Response): Promise;