leaflet-geosearch
leaflet-geosearch copied to clipboard
Multiple Providers
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?
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.
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 did you figure out how to wrap multiple providers (needing OSM + my own geoJson layers searched).
Any clues would be very much appreciated!
@austere-rm Hi, sorry unfortunately I didn't have the time for that so far :/ My use case would be the same.
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.
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 });
}
}
}