diff --git a/src/control.ts b/src/control.ts index 493aa10..539351d 100644 --- a/src/control.ts +++ b/src/control.ts @@ -1,6 +1,6 @@ import * as L from 'leaflet'; import { Nominatim } from './geocoders/index'; -import { IGeocoder, GeocodingResult } from './geocoders/api'; +import { IGeocoder, GeocodingResult, GeocodingContext } from './geocoders/api'; export interface GeocoderControlOptions extends L.ControlOptions { /** @@ -316,7 +316,7 @@ export class GeocoderControl extends EventedControl { const event: StartGeocodeEvent = { input: value }; this.fire(suggest ? 'startsuggest' : 'startgeocode', event); - const context = { map: this._map }; + const context: GeocodingContext = { map: this._map }; const results = suggest ? await this.options.geocoder!.suggest!(value, context) : await this.options.geocoder!.geocode(value, context); diff --git a/src/geocoders/api.ts b/src/geocoders/api.ts index 0bdf642..3a02fdf 100644 --- a/src/geocoders/api.ts +++ b/src/geocoders/api.ts @@ -1,5 +1,15 @@ import * as L from 'leaflet'; +/** + * Context for geocoding operations + */ +export interface GeocodingContext { + /** + * The map instance + */ + map: L.Map; +} + /** * An object that represents a result from a geocoding query */ @@ -38,12 +48,12 @@ export interface IGeocoder { * Performs a geocoding query and returns the results as promise * @param query the query */ - geocode(query: string): Promise; + geocode(query: string, context?: GeocodingContext): Promise; /** * Performs a geocoding query suggestion (this happens while typing) and returns the results as promise * @param query the query */ - suggest?(query: string): Promise; + suggest?(query: string, context?: GeocodingContext): Promise; /** * Performs a reverse geocoding query and returns the results as promise * @param location the coordinate to reverse geocode