leaflet-geosearch icon indicating copy to clipboard operation
leaflet-geosearch copied to clipboard

Multiple Providers

Open brotkiste opened this issue 7 years ago • 6 comments
trafficstars

is it possible to use multiple providers with the leaflet controls? For example using nominatim for points in osm and another provider for features in a geojson layer?

brotkiste avatar Dec 01 '17 13:12 brotkiste

I guess you could create your own provider that wrap's the two you want to use. This custom provider can then be assigned to the control.

smeijer avatar Dec 02 '17 11:12 smeijer

ok, thanks :) Would it make sense to do a pull request on this provider that wraps a list of other providers? I don't know when I will have time to do this

brotkiste avatar Dec 04 '17 14:12 brotkiste

@brotkiste did you figure out how to wrap multiple providers (needing OSM + my own geoJson layers searched).

Any clues would be very much appreciated!

bradstdev avatar Jan 11 '19 18:01 bradstdev

@austere-rm Hi, sorry unfortunately I didn't have the time for that so far :/ My use case would be the same.

brotkiste avatar Jan 20 '19 06:01 brotkiste

Did anyone figure this out? Looking into doing this. Unsure how to add a provider and trigger search inside the custom provider.

I'm trying to wrap the google provider.

marct83 avatar Apr 10 '23 15:04 marct83

I got this working..

export class Provider {
  public landLocationRegEx: RegExp =
    /[NSEW]{2}\s\d{1,2}-\d{1,2}-\d{1,2}-[NSEW]\d/;
  public googleProvider = new GoogleProvider({
    params: {
      key: environment.google.mapsKey,
    },
  });
  constructor(private service: TestService) {}

  parse(
    response: ParseArgument<TestType.LandLocationLookupResult>,
    query
  ) {
    return [
      {
        x: Number(response.data.lng), // lon
        y: Number(response.data.lat), // lat
        label: query, // formatted address
        bounds: null,
        raw: response,
      },
    ];
  }

  async search({ query }) {
    if (this.landLocationRegEx.test(query)) {
      const test = await this.service.LandLocationLookup(query);
      return this.parse({ data: test }, query);
    } else {
      return this.googleProvider.search({ query });
    }
  }
}

marct83 avatar Apr 10 '23 22:04 marct83