Closed missinglink closed 2 years ago
Should I maybe refactor the constructor to only accept a single variable like in https://github.com/smeijer/leaflet-geosearch/blob/develop/src/providers/openStreetMapProvider.ts#L28
@all-contributors please add @missinglink for code, tests
@smeijer
I've put up a pull request to add @missinglink! :tada:
Actioned feedback via rebase, diff:
diff --git a/docs/providers/pelias.mdx b/docs/providers/pelias.mdx
index afc68ce..93ed5e8 100644
--- a/docs/providers/pelias.mdx
+++ b/docs/providers/pelias.mdx
@@ -24,10 +24,10 @@ See the [Pelias documentation][2] for more detailed information about the availa
```js
import { PeliasProvider } from 'leaflet-geosearch';
-// Pelias servers are self-hosted so you'll need to configure the 'host' string
+// Pelias servers are self-hosted so you'll need to configure the 'options.host' string
// to identify where requests to your running pelias/api server instance should be sent.
// note: you SHOULD include the scheme, domain and port but NOT any path or parameters.
-const provider = new PeliasProvider('http://localhost:4000');
+const provider = new PeliasProvider({ host: 'http://localhost:4000' });
// add to leaflet
import { GeoSearchControl } from 'leaflet-geosearch';
diff --git a/src/providers/peliasProvider.ts b/src/providers/peliasProvider.ts
index cf06880..9f6af08 100644
--- a/src/providers/peliasProvider.ts
+++ b/src/providers/peliasProvider.ts
@@ -11,6 +11,10 @@ export interface RequestResult {
features: RawResult[];
}
+export type PeliasProviderOptions = {
+ host?: string;
+} & ProviderOptions;
+
export interface RawResult {
type: 'Feature';
geometry: {
@@ -90,16 +94,16 @@ export default class PeliasProvider extends AbstractProvider<
RequestResult,
RawResult
> {
- // Pelias servers are self-hosted so you'll need to configure the 'host' string
+ // Pelias servers are self-hosted so you'll need to configure the 'options.host' string
// to identify where requests to your running pelias/api server instance should be sent.
// note: you SHOULD include the scheme, domain and port but NOT any path or parameters.
// If you're using the Docker setup (https://github.com/pelias/docker)
// then the default host of 'http://localhost:4000' will work out of the box.
host: string;
- constructor(host = 'http://localhost:4000', options: ProviderOptions = {}) {
+ constructor(options: PeliasProviderOptions = {}) {
super(options);
- this.host = host;
+ this.host = options.host || 'http://localhost:4000';
}
/**
Sweet! Thanks so much.
I've published https://github.com/smeijer/leaflet-geosearch/releases/tag/v3.6.0, which includes this pull.
This PR adds a new provider for Pelias.
Since Pelias is self-hosted and FOSS I've
had to change the constructor a littleadded a 'host' option to allow the user to configure the location of a running Pelias server. The default value for this ishttp://localhost:4000
which matches the default port bound by Docker projects.As such you'll need a locally running instance to test, I'll follow up with a small PR which adds the GeocodeEarth provider, this is a hosted version of Pelias run by the core team which provides the same API but with an additional
api_key
param.I'm new to TypeScript so please let me know what I broke :P