UNPKG

leaflet-geosearch

Version:

Adds support for address lookup (a.k.a. geocoding / geosearching) to Leaflet.

52 lines (51 loc) 1.69 kB
export declare type PointTuple = [number, number]; export declare type BoundsTuple = [PointTuple, PointTuple]; export interface LatLng { lat: number; lng: number; } export interface SearchResult<TRawResult = any> { 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; } export interface ParseArgument<TData> { data: TData; } export interface Provider<TRequestResult, TRawResult> { options: ProviderOptions; endpoint(options: EndpointArgument): string; getParamString(params: ProviderParams): string; parse(response: ParseArgument<TRequestResult>): SearchResult<TRawResult>[]; search(options: SearchArgument): Promise<SearchResult<TRawResult>[]>; } export default abstract class AbstractProvider<TRequestResult = any, TRawResult = any> implements Provider<TRequestResult, TRawResult> { options: ProviderOptions; constructor(options?: ProviderOptions); abstract endpoint(options: EndpointArgument): string; abstract parse(response: ParseArgument<TRequestResult>): SearchResult<TRawResult>[]; getParamString(params?: ProviderParams): string; getUrl(url: string, params?: ProviderParams): string; search(options: SearchArgument): Promise<SearchResult<TRawResult>[]>; }