Skip to content

Commit

Permalink
Add interface GeocodingContext
Browse files Browse the repository at this point in the history
See #339.
  • Loading branch information
simon04 committed Dec 26, 2024
1 parent 66e361e commit 4eb5e16
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/control.ts
Original file line number Diff line number Diff line change
@@ -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 {
/**
Expand Down Expand Up @@ -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);
Expand Down
14 changes: 12 additions & 2 deletions src/geocoders/api.ts
Original file line number Diff line number Diff line change
@@ -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
*/
Expand Down Expand Up @@ -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<GeocodingResult[]>;
geocode(query: string, context?: GeocodingContext): Promise<GeocodingResult[]>;
/**
* Performs a geocoding query suggestion (this happens while typing) and returns the results as promise
* @param query the query
*/
suggest?(query: string): Promise<GeocodingResult[]>;
suggest?(query: string, context?: GeocodingContext): Promise<GeocodingResult[]>;
/**
* Performs a reverse geocoding query and returns the results as promise
* @param location the coordinate to reverse geocode
Expand Down

0 comments on commit 4eb5e16

Please sign in to comment.