mirror of
https://github.com/jlengrand/leaflet-geosearch.git
synced 2026-03-10 08:31:26 +00:00
chore: run linter
This commit is contained in:
@@ -8,8 +8,8 @@ import Playground from './components/Playground';
|
||||
import Map from './components/Map';
|
||||
|
||||
# Introduction
|
||||
`leaflet-geosearch` adds support for geocoding (address lookup, a.k.a. geoseaching) to your (web) application. It comes with controls to be embedded in your Leaflet map.
|
||||
|
||||
`leaflet-geosearch` adds support for geocoding (address lookup, a.k.a. geoseaching) to your (web) application. It comes with controls to be embedded in your Leaflet map.
|
||||
|
||||
We support the following providers out-of-the-box; [Bing](/providers/bing), [Esri](/providers/esri), [Google](/providers/google), [OpenStreetMap](/providers/openstreetmap), [LocationIQ](/providers/locationiq), [OpenCage](/providers/opencage).
|
||||
|
||||
@@ -26,6 +26,7 @@ npm install leaflet-geosearch
|
||||
```
|
||||
|
||||
## Providers
|
||||
|
||||
`leaflet-geosearch` uses so-called "providers" to take care of building the correct service URL and parsing the retrieved data into a uniform format. Thanks to this architecture, it is trivial to add your own providers, so you can use your own geocoding service.
|
||||
|
||||
When [`OpenStreetMap`](/providers/openstreet) does not match your needs; you can also choose to use the [`Bing`](/providers/bing), [`Esri`](/providers/esri), [`Google`](/providers/google), [`LocationIQ`](/providers/locationiq), or [`OpenCage`](/providers/opencage) providers. Most of those providers do however require `API keys`. See the documentation pages on the relevant organisations on how to obtain these keys.
|
||||
@@ -35,6 +36,7 @@ In case you decide to write your own provider, please consider submitting a PR t
|
||||
Providers are unaware of any options you can give them. They are simple proxies to their endpoints. There is only one special property, and that is the `params` option. The difference being; that `params` will be included in the endpoint url. Being Often used for `API KEYS`, while the other attributes can be used for provider configuration.
|
||||
|
||||
## Browser support / Polyfills
|
||||
|
||||
This project is written with the latest technologies in mind. Thereby it is required to include some polyfills when you wish to support older browsers. These polyfills are recommended for IE and Safari support:
|
||||
|
||||
- [babel-polyfill][1], for `array.includes` support.
|
||||
|
||||
@@ -16,7 +16,7 @@ Or add the `SearchControl` to the leaflet map instance, to render a search contr
|
||||
See [Leaflet Control](/leaflet-control) for more info about the the options this control provides.
|
||||
|
||||
<Playground>
|
||||
<Map provider="OpenStreetMap" />
|
||||
<Map provider="OpenStreetMap" />
|
||||
</Playground>
|
||||
|
||||
```js
|
||||
@@ -32,7 +32,7 @@ map.addControl(searchControl);
|
||||
## Style
|
||||
|
||||
<Playground>
|
||||
<Map provider="OpenStreetMap" controlOptions={{ style: 'button' }} />
|
||||
<Map provider="OpenStreetMap" controlOptions={{ style: 'button' }} />
|
||||
</Playground>
|
||||
|
||||
```js
|
||||
|
||||
@@ -15,7 +15,6 @@ For more options and configurations, see the [Algolia docs][1].
|
||||
<Map provider="Algolia" />
|
||||
</Playground>
|
||||
|
||||
|
||||
```js
|
||||
import { AlgoliaProvider } from 'leaflet-geosearch';
|
||||
|
||||
@@ -24,9 +23,11 @@ const provider = new AlgoliaProvider();
|
||||
// add to leaflet
|
||||
import { GeoSearchControl } from 'leaflet-geosearch';
|
||||
|
||||
map.addControl(new GeoSearchControl({
|
||||
provider,
|
||||
}));
|
||||
map.addControl(
|
||||
new GeoSearchControl({
|
||||
provider,
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
[1]: https://community.algolia.com/places/api-clients.html#rest-api
|
||||
|
||||
@@ -16,22 +16,23 @@ For more options and configurations, see the [Microsoft developer docs][2].
|
||||
<Map provider="Bing" />
|
||||
</Playground>
|
||||
|
||||
|
||||
```js
|
||||
import { BingProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new BingProvider({
|
||||
params: {
|
||||
key: '__YOUR_BING_KEY__'
|
||||
key: '__YOUR_BING_KEY__',
|
||||
},
|
||||
});
|
||||
|
||||
// add to leaflet
|
||||
import { GeoSearchControl } from 'leaflet-geosearch';
|
||||
|
||||
map.addControl(new GeoSearchControl({
|
||||
provider,
|
||||
}));
|
||||
map.addControl(
|
||||
new GeoSearchControl({
|
||||
provider,
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
[1]: https://docs.microsoft.com/en-us/bingmaps/getting-started/bing-maps-dev-center-help/getting-a-bing-maps-key
|
||||
|
||||
@@ -58,7 +58,7 @@ class MyProvider extends JsonProvider {
|
||||
parse({ data }) {
|
||||
// Note that `data` is the raw result returned by the server. This
|
||||
// method should return data in the SearchResult format.
|
||||
return data.map(x => ({
|
||||
return data.map((x) => ({
|
||||
x: data.x,
|
||||
y: data.y,
|
||||
label: data.label,
|
||||
@@ -69,6 +69,7 @@ class MyProvider extends JsonProvider {
|
||||
```
|
||||
|
||||
## Sharing
|
||||
|
||||
When you've build a custom provider that can be used by others, please consider opening a [pull-request][2], or publishing it to `npm`.
|
||||
|
||||
[1]: /providers/openstreetmap
|
||||
|
||||
@@ -8,13 +8,13 @@ import Playground from '../components/Playground';
|
||||
import Map from '../components/Map';
|
||||
|
||||
# Esri Provider
|
||||
|
||||
For more options and configurations, see the [ArcGIS developer docs][1].
|
||||
|
||||
<Playground>
|
||||
<Map provider="Esri" />
|
||||
</Playground>
|
||||
|
||||
|
||||
```js
|
||||
import { EsriProvider } from 'leaflet-geosearch';
|
||||
|
||||
@@ -23,9 +23,11 @@ const provider = new EsriProvider();
|
||||
// add to leaflet
|
||||
import { GeoSearchControl } from 'leaflet-geosearch';
|
||||
|
||||
map.addControl(new GeoSearchControl({
|
||||
provider,
|
||||
}));
|
||||
map.addControl(
|
||||
new GeoSearchControl({
|
||||
provider,
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
[1]: https://developers.arcgis.com/rest/geocode/api-reference/overview-world-geocoding-service.htm
|
||||
|
||||
@@ -16,22 +16,23 @@ For more options and configurations, see the [Google Maps developer docs][2].
|
||||
<Map provider="Google" />
|
||||
</Playground>
|
||||
|
||||
|
||||
```js
|
||||
import { GoogleProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new GoogleProvider({
|
||||
params: {
|
||||
key: '__YOUR_GOOGLE_KEY__'
|
||||
key: '__YOUR_GOOGLE_KEY__',
|
||||
},
|
||||
});
|
||||
|
||||
// add to leaflet
|
||||
import { GeoSearchControl } from 'leaflet-geosearch';
|
||||
|
||||
map.addControl(new GeoSearchControl({
|
||||
provider,
|
||||
}));
|
||||
map.addControl(
|
||||
new GeoSearchControl({
|
||||
provider,
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
## Optional parameters
|
||||
@@ -45,7 +46,7 @@ const provider = new GoogleProvider({
|
||||
params: {
|
||||
key: '__YOUR_GOOGLE_KEY__',
|
||||
language: 'nl', // render results in Dutch
|
||||
region: 'nl', // prioritize matches within The Netherlands
|
||||
region: 'nl', // prioritize matches within The Netherlands
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
@@ -16,22 +16,23 @@ For more options and configurations, see the [Here developer docs][2].
|
||||
<Map provider="Here" />
|
||||
</Playground>
|
||||
|
||||
|
||||
```js
|
||||
import { HereProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new HereProvider({
|
||||
params: {
|
||||
apiKey: '__YOUR_HERE_KEY__'
|
||||
apiKey: '__YOUR_HERE_KEY__',
|
||||
},
|
||||
});
|
||||
|
||||
// add to leaflet
|
||||
import { GeoSearchControl } from 'leaflet-geosearch';
|
||||
|
||||
map.addControl(new GeoSearchControl({
|
||||
provider,
|
||||
}));
|
||||
map.addControl(
|
||||
new GeoSearchControl({
|
||||
provider,
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
[1]: https://developer.here.com
|
||||
|
||||
@@ -16,22 +16,23 @@ For more options and configurations, see the [LocationIQ developer docs][2].
|
||||
<Map provider="LocationIQ" />
|
||||
</Playground>
|
||||
|
||||
|
||||
```js
|
||||
import { LocationIQProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new LocationIQProvider({
|
||||
params: {
|
||||
key: '__YOUR_LOCATIONIQ_KEY__'
|
||||
key: '__YOUR_LOCATIONIQ_KEY__',
|
||||
},
|
||||
});
|
||||
|
||||
// add to leaflet
|
||||
import { GeoSearchControl } from 'leaflet-geosearch';
|
||||
|
||||
map.addControl(new GeoSearchControl({
|
||||
provider,
|
||||
}));
|
||||
map.addControl(
|
||||
new GeoSearchControl({
|
||||
provider,
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
[1]: https://locationiq.org
|
||||
|
||||
@@ -16,22 +16,23 @@ For more options and configurations, see the [OpenCage developer docs][2].
|
||||
<Map provider="OpenCage" />
|
||||
</Playground>
|
||||
|
||||
|
||||
```js
|
||||
import { OpenCageProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new OpenCageProvider({
|
||||
params: {
|
||||
key: '__YOUR_OPENCAGE_KEY__'
|
||||
key: '__YOUR_OPENCAGE_KEY__',
|
||||
},
|
||||
});
|
||||
|
||||
// add to leaflet
|
||||
import { GeoSearchControl } from 'leaflet-geosearch';
|
||||
|
||||
map.addControl(new GeoSearchControl({
|
||||
provider,
|
||||
}));
|
||||
map.addControl(
|
||||
new GeoSearchControl({
|
||||
provider,
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
[1]: https://geocoder.opencagedata.com
|
||||
|
||||
@@ -15,18 +15,20 @@ For more options and configurations, see the [OpenStreetMap Nominatim wiki][1].
|
||||
<Map provider="OpenStreetMap" />
|
||||
</Playground>
|
||||
|
||||
|
||||
```js
|
||||
import { OpenStreetMapProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new OpenStreetMapProvider();
|
||||
|
||||
// add to leaflet
|
||||
import { GeoSearchControl } from 'leaflet-geosearch'; import {OpenStreetMapProvider} from "./index";
|
||||
import { GeoSearchControl } from 'leaflet-geosearch';
|
||||
import { OpenStreetMapProvider } from './index';
|
||||
|
||||
map.addControl(new GeoSearchControl({
|
||||
provider,
|
||||
}));
|
||||
map.addControl(
|
||||
new GeoSearchControl({
|
||||
provider,
|
||||
}),
|
||||
);
|
||||
```
|
||||
|
||||
## Authentication
|
||||
@@ -51,7 +53,7 @@ All options defined next to the `params` key, would have been added to the reque
|
||||
const provider = new OpenStreetMapProvider({
|
||||
params: {
|
||||
'accept-language': 'nl', // render results in Dutch
|
||||
'countrycodes': 'nl', // limit search results to the Netherlands
|
||||
countrycodes: 'nl', // limit search results to the Netherlands
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
@@ -16,7 +16,7 @@ There are two ways in which `leaflet-geosearch` can be used. Direct usage, for e
|
||||
All providers can be used without leaflet. You might want to bind them to a form;
|
||||
|
||||
<Playground>
|
||||
<Search provider="OpenStreetMap" />
|
||||
<Search provider="OpenStreetMap" />
|
||||
</Playground>
|
||||
|
||||
```js
|
||||
@@ -27,15 +27,15 @@ const results = await provider.search({ query: input.value });
|
||||
```
|
||||
|
||||
## Using the leaflet control
|
||||
|
||||
Or add the `GeoSearchControl` to the leaflet map instance, to render a search control on your map;
|
||||
|
||||
See [Leaflet Control](/leaflet-control) for more info about the the options this control provides.
|
||||
|
||||
<Playground>
|
||||
<Map provider="OpenStreetMap" />
|
||||
<Map provider="OpenStreetMap" />
|
||||
</Playground>
|
||||
|
||||
|
||||
```js
|
||||
import { GeoSearchControl, OpenStreetMapProvider } from 'leaflet-geosearch';
|
||||
|
||||
@@ -52,13 +52,13 @@ The search event of all providers return an array of `result` objects. The base
|
||||
|
||||
```ts
|
||||
interface result {
|
||||
x: number; // lon
|
||||
y: number; // lat
|
||||
label: string; // formatted address
|
||||
x: number; // lon
|
||||
y: number; // lat
|
||||
label: string; // formatted address
|
||||
bounds: [
|
||||
[number, number], // south, west - lat, lon
|
||||
[number, number], // north, east - lat, lon
|
||||
],
|
||||
raw: any, // raw provider result
|
||||
[number, number], // south, west - lat, lon
|
||||
[number, number], // north, east - lat, lon
|
||||
];
|
||||
raw: any; // raw provider result
|
||||
}
|
||||
```
|
||||
|
||||
179
readme.md
179
readme.md
@@ -12,20 +12,22 @@ See: [#172](https://github.com/smeijer/leaflet-geosearch/issues/172) for more in
|
||||
|
||||
[][10]
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
with npm:
|
||||
|
||||
```bash
|
||||
npm install --save leaflet-geosearch
|
||||
```
|
||||
|
||||
or yarn:
|
||||
|
||||
```bash
|
||||
yarn add leaflet-geosearch
|
||||
```
|
||||
|
||||
or bower:
|
||||
|
||||
```bash
|
||||
bower install leaflet-geosearch
|
||||
```
|
||||
@@ -33,56 +35,63 @@ bower install leaflet-geosearch
|
||||
**TypeScript**
|
||||
|
||||
If you use TypeScript then consider to install types:
|
||||
|
||||
```bash
|
||||
npm install --save-dev @types/leaflet-geosearch
|
||||
```
|
||||
|
||||
or yarn:
|
||||
|
||||
```bash
|
||||
yarn add @types/leaflet-geosearch -D
|
||||
```
|
||||
---
|
||||
If you don’t use [npm][11], you may grab the latest [UMD][12] build from
|
||||
[unpkg][13] (either a [development][14] or a [production][15] build). The UMD build
|
||||
exports a global called `window.GeoSearch` if you add it to your page via a
|
||||
`<script>` tag.
|
||||
|
||||
We *don’t* recommend UMD builds for any serious application.
|
||||
---
|
||||
|
||||
If you don’t use [npm][11], you may grab the latest [UMD][12] build from
|
||||
[unpkg][13] (either a [development][14] or a [production][15] build). The UMD build
|
||||
exports a global called `window.GeoSearch` if you add it to your page via a
|
||||
`<script>` tag.
|
||||
|
||||
We _don’t_ recommend UMD builds for any serious application.
|
||||
|
||||
## Browser support / Polyfills
|
||||
|
||||
This library is written with the latest technologies in mind. Thereby it is required to include some polyfills when you wish to support older browsers. These polyfills are recommended for IE and Safari support:
|
||||
|
||||
- [babel-polyfill][16], for `array.includes` support.
|
||||
- [whatwg-fetch][17], for `fetch` requests.
|
||||
|
||||
# About
|
||||
This library adds support for geocoding *(address lookup, a.k.a. geoseaching)*
|
||||
to your (web) application. It comes with controls to be embedded in your
|
||||
|
||||
This library adds support for geocoding _(address lookup, a.k.a. geoseaching)_
|
||||
to your (web) application. It comes with controls to be embedded in your
|
||||
[Leaflet][1]
|
||||
map.
|
||||
|
||||
Check out the [demo][2] for various possibilities.
|
||||
|
||||
The library uses so-called "providers" to take care of building the correct
|
||||
service URL and parsing the retrieved data into a uniform format. Thanks to this
|
||||
architecture, it is pretty easy to add your own providers, so you can use
|
||||
The library uses so-called "providers" to take care of building the correct
|
||||
service URL and parsing the retrieved data into a uniform format. Thanks to this
|
||||
architecture, it is pretty easy to add your own providers, so you can use
|
||||
your own geocoding service(s).
|
||||
|
||||
The control comes with a default set of six providers:
|
||||
|
||||
- [Bing](#bing-provider).
|
||||
- [Esri](#esri-provider).
|
||||
- [Google](#google-provider).
|
||||
- [OpenStreetMap](#openstreetmap-provider).
|
||||
- [LocationIQ](#locationiq-provider).
|
||||
- [OpenCage](#opencage-provider).
|
||||
- [Bing](#bing-provider).
|
||||
- [Esri](#esri-provider).
|
||||
- [Google](#google-provider).
|
||||
- [OpenStreetMap](#openstreetmap-provider).
|
||||
- [LocationIQ](#locationiq-provider).
|
||||
- [OpenCage](#opencage-provider).
|
||||
|
||||
Although this project is still named `leaflet-geosearch`, this library is also
|
||||
Although this project is still named `leaflet-geosearch`, this library is also
|
||||
usable without LeafletJS, and does not have any dependencies whatsoever.
|
||||
|
||||
# Usage
|
||||
|
||||
Let's first start with an little example on how to use this control without
|
||||
leaflet. For example as an address lookup on a webshop order form. Perhaps to
|
||||
Let's first start with an little example on how to use this control without
|
||||
leaflet. For example as an address lookup on a webshop order form. Perhaps to
|
||||
search for the closest alternative package delivery point? Or to link it to your
|
||||
own custom map component.
|
||||
|
||||
@@ -97,7 +106,7 @@ const provider = new OpenStreetMapProvider();
|
||||
const results = await provider.search({ query: input.value });
|
||||
```
|
||||
|
||||
Of course, something like this should be bound to something like a form or
|
||||
Of course, something like this should be bound to something like a form or
|
||||
input:
|
||||
|
||||
```js
|
||||
@@ -117,67 +126,68 @@ form.addEventListener('submit', async (event) => {
|
||||
Instead of es6 `async` / `await` you can also use promises like:
|
||||
|
||||
```js
|
||||
provider
|
||||
.search({ query: '...' })
|
||||
.then(function(result) {
|
||||
// do something with result;
|
||||
});
|
||||
provider.search({ query: '...' }).then(function (result) {
|
||||
// do something with result;
|
||||
});
|
||||
```
|
||||
|
||||
## Results
|
||||
|
||||
The `search` event of all providers return an array of `result objects`. The
|
||||
The `search` event of all providers return an array of `result objects`. The
|
||||
base structure is uniform between the providers. It provides a object like:
|
||||
|
||||
```js
|
||||
const result = {
|
||||
x: Number, // lon,
|
||||
y: Number, // lat,
|
||||
label: String, // formatted address
|
||||
x: Number, // lon,
|
||||
y: Number, // lat,
|
||||
label: String, // formatted address
|
||||
bounds: [
|
||||
[Number, Number], // s, w - lat, lon
|
||||
[Number, Number], // n, e - lat, lon
|
||||
[Number, Number], // s, w - lat, lon
|
||||
[Number, Number], // n, e - lat, lon
|
||||
],
|
||||
raw: {}, // raw provider result
|
||||
}
|
||||
raw: {}, // raw provider result
|
||||
};
|
||||
```
|
||||
|
||||
The contents of the `raw` property differ per provider. This is the unprocessed
|
||||
result from the 3th party service. This property is included for developer
|
||||
convenience. `leaflet-geosearch` does not use it. If you need to know the
|
||||
result from the 3th party service. This property is included for developer
|
||||
convenience. `leaflet-geosearch` does not use it. If you need to know the
|
||||
contents of this property, you should check the 3th party developer docs. (or
|
||||
use your debugger)
|
||||
|
||||
|
||||
# Providers
|
||||
When `OpenStreetMap` does not match your needs; you can also choose to use the
|
||||
`Bing`, `Esri`, `Google` `LocationIQ`, or `OpenCage` providers. Those providers do however require API
|
||||
keys. See the documentation pages on the relevant organisations on how to obtain
|
||||
|
||||
When `OpenStreetMap` does not match your needs; you can also choose to use the
|
||||
`Bing`, `Esri`, `Google` `LocationIQ`, or `OpenCage` providers. Those providers do however require API
|
||||
keys. See the documentation pages on the relevant organisations on how to obtain
|
||||
these keys.
|
||||
|
||||
|
||||
In case you decide to write your own provider, please consider submitting a PR
|
||||
to share your work with us.
|
||||
|
||||
Providers are unaware of any options you can give them. They are simple proxies
|
||||
Providers are unaware of any options you can give them. They are simple proxies
|
||||
to their endpoints. There is only one `special property`, and that is the `params`
|
||||
option. The difference being; that `params` will be included in the endpoint url.
|
||||
option. The difference being; that `params` will be included in the endpoint url.
|
||||
Often being used for `API KEYS`, where as the other attributes can be used for
|
||||
provider configuration.
|
||||
|
||||
## Bing Provider
|
||||
**note**: Bing services require an API key. [Obtain here][7].
|
||||
|
||||
**note**: Bing services require an API key. [Obtain here][7].
|
||||
For more options and configurations, see the [MSDN developer docs][6].
|
||||
|
||||
```js
|
||||
import { BingProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new BingProvider({
|
||||
const provider = new BingProvider({
|
||||
params: {
|
||||
key: '__YOUR_BING_KEY__'
|
||||
key: '__YOUR_BING_KEY__',
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## Esri Provider
|
||||
|
||||
For more options and configurations, see the [ArcGIS developer docs][3].
|
||||
|
||||
```js
|
||||
@@ -187,13 +197,14 @@ const provider = new EsriProvider();
|
||||
```
|
||||
|
||||
## Google Provider
|
||||
|
||||
**note**: Google services require an API key. [Obtain here][8].
|
||||
For more options and configurations, see the [Google Maps developer docs][4].
|
||||
|
||||
```js
|
||||
import { GoogleProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new GoogleProvider({
|
||||
const provider = new GoogleProvider({
|
||||
params: {
|
||||
key: '__YOUR_GOOGLE_KEY__',
|
||||
},
|
||||
@@ -201,6 +212,7 @@ const provider = new GoogleProvider({
|
||||
```
|
||||
|
||||
## OpenStreetMap Provider
|
||||
|
||||
For more options and configurations, see the [OpenStreetMap Nominatim wiki][5].
|
||||
|
||||
```js
|
||||
@@ -210,26 +222,29 @@ const provider = new OpenStreetMapProvider();
|
||||
```
|
||||
|
||||
## LocationIQ Provider
|
||||
|
||||
**note**: LocationIQ services require an API key. [Obtain here][18].
|
||||
For more options and configurations, see the [LocationIQ developer docs][19].
|
||||
|
||||
```js
|
||||
import { LocationIQProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new LocationIQProvider({
|
||||
const provider = new LocationIQProvider({
|
||||
params: {
|
||||
key: '__YOUR_LOCATIONIQ_KEY__',
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
## OpenCage Provider
|
||||
|
||||
**note**: OpenCage services require an API key. [Obtain here][20].
|
||||
For more options and configurations, see the [OpenCage developer docs][21].
|
||||
|
||||
```js
|
||||
import { OpenCageProvider } from 'leaflet-geosearch';
|
||||
|
||||
const provider = new OpenCageProvider({
|
||||
const provider = new OpenCageProvider({
|
||||
params: {
|
||||
key: '__YOUR_OPENCAGE_KEY__',
|
||||
},
|
||||
@@ -238,10 +253,10 @@ const provider = new OpenCageProvider({
|
||||
|
||||
# Using with LeafletJS
|
||||
|
||||
This project comes with a leaflet control to hook the search providers into
|
||||
leaflet. The example below uses the `OpenStreetMap Provider`, but you can exchange
|
||||
this with on of the other included providers as well as your own custom made
|
||||
providers. Remember to setup the provider with a `key` when required (Google and
|
||||
This project comes with a leaflet control to hook the search providers into
|
||||
leaflet. The example below uses the `OpenStreetMap Provider`, but you can exchange
|
||||
this with on of the other included providers as well as your own custom made
|
||||
providers. Remember to setup the provider with a `key` when required (Google and
|
||||
Bing for example).
|
||||
|
||||

|
||||
@@ -261,13 +276,14 @@ map.addControl(searchControl);
|
||||
```
|
||||
|
||||
## GeoSearchControl
|
||||
|
||||
There are some configurable options like setting the position of the search input
|
||||
and whether or not a marker should be displayed at the position of the search result.
|
||||
|
||||

|
||||
There are two visual styles of this control. One is the more 'leaflet-way' by
|
||||
putting the search control under a button (see image above). And one where the
|
||||
search control is permanently shown as a search bar (see image under
|
||||
There are two visual styles of this control. One is the more 'leaflet-way' by
|
||||
putting the search control under a button (see image above). And one where the
|
||||
search control is permanently shown as a search bar (see image under
|
||||
[using with LeafletJS](#using-with-leafletjs)).
|
||||
|
||||
**Render style**
|
||||
@@ -276,49 +292,50 @@ This render style can be set by the optional `style` option.
|
||||
|
||||
```js
|
||||
new GeoSearchControl({
|
||||
provider: myProvider, // required
|
||||
style: 'bar', // optional: bar|button - default button
|
||||
provider: myProvider, // required
|
||||
style: 'bar', // optional: bar|button - default button
|
||||
}).addTo(map);
|
||||
```
|
||||
|
||||
**AutoComplete**
|
||||
**AutoComplete**
|
||||
|
||||
Auto complete can be configured by the parameters `autoComplete` and
|
||||
Auto complete can be configured by the parameters `autoComplete` and
|
||||
`autoCompleteDelay`. A little delay is required to not DDOS the server on every
|
||||
keystroke.
|
||||
|
||||
```js
|
||||
new GeoSearchControl({
|
||||
provider: myProvider, // required
|
||||
autoComplete: true, // optional: true|false - default true
|
||||
autoCompleteDelay: 250, // optional: number - default 250
|
||||
provider: myProvider, // required
|
||||
autoComplete: true, // optional: true|false - default true
|
||||
autoCompleteDelay: 250, // optional: number - default 250
|
||||
}).addTo(map);
|
||||
```
|
||||
|
||||
**Show result**
|
||||
|
||||
There are a number of options to adjust the way results are visualized.
|
||||
|
||||
|
||||
```js
|
||||
new GeoSearchControl({
|
||||
provider: myProvider, // required
|
||||
showMarker: true, // optional: true|false - default true
|
||||
showPopup: false, // optional: true|false - default false
|
||||
marker: { // optional: L.Marker - default L.Icon.Default
|
||||
provider: myProvider, // required
|
||||
showMarker: true, // optional: true|false - default true
|
||||
showPopup: false, // optional: true|false - default false
|
||||
marker: {
|
||||
// optional: L.Marker - default L.Icon.Default
|
||||
icon: new L.Icon.Default(),
|
||||
draggable: false,
|
||||
},
|
||||
popupFormat: ({ query, result }) => result.label, // optional: function - default returns result label
|
||||
maxMarkers: 1, // optional: number - default 1
|
||||
retainZoomLevel: false, // optional: true|false - default false
|
||||
animateZoom: true, // optional: true|false - default true
|
||||
autoClose: false, // optional: true|false - default false
|
||||
searchLabel: 'Enter address', // optional: string - default 'Enter address'
|
||||
keepResult: false // optional: true|false - default false
|
||||
popupFormat: ({ query, result }) => result.label, // optional: function - default returns result label
|
||||
maxMarkers: 1, // optional: number - default 1
|
||||
retainZoomLevel: false, // optional: true|false - default false
|
||||
animateZoom: true, // optional: true|false - default true
|
||||
autoClose: false, // optional: true|false - default false
|
||||
searchLabel: 'Enter address', // optional: string - default 'Enter address'
|
||||
keepResult: false, // optional: true|false - default false
|
||||
});
|
||||
```
|
||||
|
||||
`showMarker` and `showPopup` determine whether or not to show a marker and/or
|
||||
`showMarker` and `showPopup` determine whether or not to show a marker and/or
|
||||
open a popup with the location text.
|
||||
|
||||
`marker` can be set to any instance of a (custom) `L.Icon`.
|
||||
@@ -326,7 +343,7 @@ open a popup with the location text.
|
||||
`popupFormat` is callback function for displaying text on popup.
|
||||
|
||||
`maxMarker` determines how many last results are kept in memory. Default 1, but
|
||||
perhaps you want to show the last `x` results when searching for new queries as
|
||||
perhaps you want to show the last `x` results when searching for new queries as
|
||||
well.
|
||||
|
||||
`retainZoomLevel` is a setting that fixes the zoomlevel. Default behaviour is to
|
||||
@@ -337,20 +354,20 @@ only panned.
|
||||
|
||||
`autoClose` closes the result list if a result is selected by click/enter.
|
||||
|
||||
`keepResult` is used to keep the selected result in the search field. This prevents markers to disappear while using the `autoClose` feature.
|
||||
`keepResult` is used to keep the selected result in the search field. This prevents markers to disappear while using the `autoClose` feature.
|
||||
|
||||
**Events**
|
||||
|
||||
`geosearch/showlocation` is fired when location is chosen from the result list.
|
||||
|
||||
```js
|
||||
map.on('geosearch/showlocation', yourEventHandler)
|
||||
map.on('geosearch/showlocation', yourEventHandler);
|
||||
```
|
||||
|
||||
`geosearch/marker/dragend` is fired when marker has been dragged.
|
||||
|
||||
```js
|
||||
map.on('geosearch/marker/dragend', yourEventHandler)
|
||||
map.on('geosearch/marker/dragend', yourEventHandler);
|
||||
```
|
||||
|
||||
# Development
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,9 +8,17 @@
|
||||
"resources": [
|
||||
{
|
||||
"__type": "Location:http://schemas.microsoft.com/search/local/ws/rest/v1",
|
||||
"bbox": [52.099399566650391, 4.2973999977111816, 52.099601745605469, 4.2975997924804687],
|
||||
"bbox": [
|
||||
52.099399566650391,
|
||||
4.2973999977111816,
|
||||
52.099601745605469,
|
||||
4.2975997924804687
|
||||
],
|
||||
"name": "Madurodam, Netherlands",
|
||||
"point": { "type": "Point", "coordinates": [52.0994987487793, 4.2975001335144043] },
|
||||
"point": {
|
||||
"type": "Point",
|
||||
"coordinates": [52.0994987487793, 4.2975001335144043]
|
||||
},
|
||||
"address": {
|
||||
"adminDistrict": "South Holland",
|
||||
"adminDistrict2": "Den Haag",
|
||||
|
||||
@@ -66,7 +66,13 @@
|
||||
"compound_code": "37XW+QQ The Hague, Netherlands",
|
||||
"global_code": "9F4637XW+QQ"
|
||||
},
|
||||
"types": ["amusement_park", "establishment", "point_of_interest", "premise", "tourist_attraction"]
|
||||
"types": [
|
||||
"amusement_park",
|
||||
"establishment",
|
||||
"point_of_interest",
|
||||
"premise",
|
||||
"tourist_attraction"
|
||||
]
|
||||
}
|
||||
],
|
||||
"status": "OK"
|
||||
|
||||
@@ -1,11 +1,19 @@
|
||||
{
|
||||
"documentation": "https://opencagedata.com/api",
|
||||
"licenses": [{ "name": "see attribution guide", "url": "https://opencagedata.com/credits" }],
|
||||
"licenses": [
|
||||
{
|
||||
"name": "see attribution guide",
|
||||
"url": "https://opencagedata.com/credits"
|
||||
}
|
||||
],
|
||||
"rate": { "limit": 2500, "remaining": 2498, "reset": 1586736000 },
|
||||
"results": [
|
||||
{
|
||||
"annotations": {
|
||||
"DMS": { "lat": "52\u00b0 5' 56.74884'' N", "lng": "4\u00b0 17' 56.55444'' E" },
|
||||
"DMS": {
|
||||
"lat": "52\u00b0 5' 56.74884'' N",
|
||||
"lng": "4\u00b0 17' 56.55444'' E"
|
||||
},
|
||||
"MGRS": "31UET8898172856",
|
||||
"Maidenhead": "JO22dc53vs",
|
||||
"Mercator": { "x": 478567.267, "y": 6784324.747 },
|
||||
@@ -15,7 +23,12 @@
|
||||
"url": "https://www.openstreetmap.org/?mlat=52.09910&mlon=4.29904#map=16/52.09910/4.29904"
|
||||
},
|
||||
"UN_M49": {
|
||||
"regions": { "EUROPE": "150", "NL": "528", "WESTERN_EUROPE": "155", "WORLD": "001" },
|
||||
"regions": {
|
||||
"EUROPE": "150",
|
||||
"NL": "528",
|
||||
"WESTERN_EUROPE": "155",
|
||||
"WORLD": "001"
|
||||
},
|
||||
"statistical_groupings": ["MEDC"]
|
||||
},
|
||||
"callingcode": 31,
|
||||
@@ -38,8 +51,18 @@
|
||||
"qibla": 124.62,
|
||||
"roadinfo": { "drive_on": "right", "speed_in": "km/h" },
|
||||
"sun": {
|
||||
"rise": { "apparent": 1586667180, "astronomical": 1586659500, "civil": 1586665020, "nautical": 1586662440 },
|
||||
"set": { "apparent": 1586716500, "astronomical": 1586724240, "civil": 1586718660, "nautical": 1586721300 }
|
||||
"rise": {
|
||||
"apparent": 1586667180,
|
||||
"astronomical": 1586659500,
|
||||
"civil": 1586665020,
|
||||
"nautical": 1586662440
|
||||
},
|
||||
"set": {
|
||||
"apparent": 1586716500,
|
||||
"astronomical": 1586724240,
|
||||
"civil": 1586718660,
|
||||
"nautical": 1586721300
|
||||
}
|
||||
},
|
||||
"timezone": {
|
||||
"name": "Europe/Amsterdam",
|
||||
@@ -80,7 +103,10 @@
|
||||
},
|
||||
{
|
||||
"annotations": {
|
||||
"DMS": { "lat": "52\u00b0 5' 50.28756'' N", "lng": "4\u00b0 18' 11.78064'' E" },
|
||||
"DMS": {
|
||||
"lat": "52\u00b0 5' 50.28756'' N",
|
||||
"lng": "4\u00b0 18' 11.78064'' E"
|
||||
},
|
||||
"MGRS": "31UET8927472661",
|
||||
"Maidenhead": "JO22dc63ji",
|
||||
"Mercator": { "x": 479038.092, "y": 6784000.335 },
|
||||
@@ -90,7 +116,12 @@
|
||||
"url": "https://www.openstreetmap.org/?mlat=52.09730&mlon=4.30327#map=16/52.09730/4.30327"
|
||||
},
|
||||
"UN_M49": {
|
||||
"regions": { "EUROPE": "150", "NL": "528", "WESTERN_EUROPE": "155", "WORLD": "001" },
|
||||
"regions": {
|
||||
"EUROPE": "150",
|
||||
"NL": "528",
|
||||
"WESTERN_EUROPE": "155",
|
||||
"WORLD": "001"
|
||||
},
|
||||
"statistical_groupings": ["MEDC"]
|
||||
},
|
||||
"callingcode": 31,
|
||||
@@ -118,8 +149,18 @@
|
||||
"speed_in": "km/h"
|
||||
},
|
||||
"sun": {
|
||||
"rise": { "apparent": 1586667180, "astronomical": 1586659500, "civil": 1586665020, "nautical": 1586662440 },
|
||||
"set": { "apparent": 1586716500, "astronomical": 1586724240, "civil": 1586718660, "nautical": 1586721300 }
|
||||
"rise": {
|
||||
"apparent": 1586667180,
|
||||
"astronomical": 1586659500,
|
||||
"civil": 1586665020,
|
||||
"nautical": 1586662440
|
||||
},
|
||||
"set": {
|
||||
"apparent": 1586716500,
|
||||
"astronomical": 1586724240,
|
||||
"civil": 1586718660,
|
||||
"nautical": 1586721300
|
||||
}
|
||||
},
|
||||
"timezone": {
|
||||
"name": "Europe/Amsterdam",
|
||||
@@ -158,7 +199,10 @@
|
||||
},
|
||||
{
|
||||
"annotations": {
|
||||
"DMS": { "lat": "52\u00b0 5' 52.90188'' N", "lng": "4\u00b0 17' 44.11788'' E" },
|
||||
"DMS": {
|
||||
"lat": "52\u00b0 5' 52.90188'' N",
|
||||
"lng": "4\u00b0 17' 44.11788'' E"
|
||||
},
|
||||
"MGRS": "31UET8874672733",
|
||||
"Maidenhead": "JO22dc53lm",
|
||||
"Mercator": { "x": 478182.702, "y": 6784131.595 },
|
||||
@@ -168,7 +212,12 @@
|
||||
"url": "https://www.openstreetmap.org/?mlat=52.09803&mlon=4.29559#map=16/52.09803/4.29559"
|
||||
},
|
||||
"UN_M49": {
|
||||
"regions": { "EUROPE": "150", "NL": "528", "WESTERN_EUROPE": "155", "WORLD": "001" },
|
||||
"regions": {
|
||||
"EUROPE": "150",
|
||||
"NL": "528",
|
||||
"WESTERN_EUROPE": "155",
|
||||
"WORLD": "001"
|
||||
},
|
||||
"statistical_groupings": ["MEDC"]
|
||||
},
|
||||
"callingcode": 31,
|
||||
@@ -196,8 +245,18 @@
|
||||
"speed_in": "km/h"
|
||||
},
|
||||
"sun": {
|
||||
"rise": { "apparent": 1586667180, "astronomical": 1586659500, "civil": 1586665020, "nautical": 1586662440 },
|
||||
"set": { "apparent": 1586716500, "astronomical": 1586724240, "civil": 1586718660, "nautical": 1586721300 }
|
||||
"rise": {
|
||||
"apparent": 1586667180,
|
||||
"astronomical": 1586659500,
|
||||
"civil": 1586665020,
|
||||
"nautical": 1586662440
|
||||
},
|
||||
"set": {
|
||||
"apparent": 1586716500,
|
||||
"astronomical": 1586724240,
|
||||
"civil": 1586718660,
|
||||
"nautical": 1586721300
|
||||
}
|
||||
},
|
||||
"timezone": {
|
||||
"name": "Europe/Amsterdam",
|
||||
@@ -236,8 +295,14 @@
|
||||
}
|
||||
],
|
||||
"status": { "code": 200, "message": "OK" },
|
||||
"stay_informed": { "blog": "https://blog.opencagedata.com", "twitter": "https://twitter.com/opencagedata" },
|
||||
"stay_informed": {
|
||||
"blog": "https://blog.opencagedata.com",
|
||||
"twitter": "https://twitter.com/opencagedata"
|
||||
},
|
||||
"thanks": "For using an OpenCage API",
|
||||
"timestamp": { "created_http": "Sun, 12 Apr 2020 18:57:00 GMT", "created_unix": 1586717820 },
|
||||
"timestamp": {
|
||||
"created_http": "Sun, 12 Apr 2020 18:57:00 GMT",
|
||||
"created_unix": 1586717820
|
||||
},
|
||||
"total_results": 8
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"target":"ES2015",
|
||||
"target": "ES2015",
|
||||
"module": "ES2015",
|
||||
"moduleResolution": "node",
|
||||
"esModuleInterop": true,
|
||||
@@ -16,13 +16,6 @@
|
||||
"outDir": "lib",
|
||||
"declaration": true
|
||||
},
|
||||
"include": [
|
||||
"src",
|
||||
"typings"
|
||||
],
|
||||
"exclude": [
|
||||
"node_modules",
|
||||
"**/*.spec.ts",
|
||||
"**/*.spec.js"
|
||||
]
|
||||
"include": ["src", "typings"],
|
||||
"exclude": ["node_modules", "**/*.spec.ts", "**/*.spec.js"]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user