Skip to content

Commit 4eb5e16

Browse files
committed
Add interface GeocodingContext
See #339.
1 parent 66e361e commit 4eb5e16

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/control.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as L from 'leaflet';
22
import { Nominatim } from './geocoders/index';
3-
import { IGeocoder, GeocodingResult } from './geocoders/api';
3+
import { IGeocoder, GeocodingResult, GeocodingContext } from './geocoders/api';
44

55
export interface GeocoderControlOptions extends L.ControlOptions {
66
/**
@@ -316,7 +316,7 @@ export class GeocoderControl extends EventedControl {
316316
const event: StartGeocodeEvent = { input: value };
317317
this.fire(suggest ? 'startsuggest' : 'startgeocode', event);
318318

319-
const context = { map: this._map };
319+
const context: GeocodingContext = { map: this._map };
320320
const results = suggest
321321
? await this.options.geocoder!.suggest!(value, context)
322322
: await this.options.geocoder!.geocode(value, context);

src/geocoders/api.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,15 @@
11
import * as L from 'leaflet';
22

3+
/**
4+
* Context for geocoding operations
5+
*/
6+
export interface GeocodingContext {
7+
/**
8+
* The map instance
9+
*/
10+
map: L.Map;
11+
}
12+
313
/**
414
* An object that represents a result from a geocoding query
515
*/
@@ -38,12 +48,12 @@ export interface IGeocoder {
3848
* Performs a geocoding query and returns the results as promise
3949
* @param query the query
4050
*/
41-
geocode(query: string): Promise<GeocodingResult[]>;
51+
geocode(query: string, context?: GeocodingContext): Promise<GeocodingResult[]>;
4252
/**
4353
* Performs a geocoding query suggestion (this happens while typing) and returns the results as promise
4454
* @param query the query
4555
*/
46-
suggest?(query: string): Promise<GeocodingResult[]>;
56+
suggest?(query: string, context?: GeocodingContext): Promise<GeocodingResult[]>;
4757
/**
4858
* Performs a reverse geocoding query and returns the results as promise
4959
* @param location the coordinate to reverse geocode

0 commit comments

Comments
 (0)