mirror of
https://github.com/jlengrand/leaflet-geosearch.git
synced 2026-03-10 08:31:26 +00:00
Add LocationIQ provider
This commit is contained in:
@@ -1,2 +1,3 @@
|
||||
BING_API_KEY=___YOUR_KEY___
|
||||
GOOGLE_API_KEY=___YOUR_KEY___
|
||||
LOCATIONIQ_API_KEY=___YOUR_KEY___
|
||||
|
||||
2
docs/dist/bundle.min.js
vendored
2
docs/dist/bundle.min.js
vendored
File diff suppressed because one or more lines are too long
2
docs/dist/style.css
vendored
2
docs/dist/style.css
vendored
@@ -1 +1 @@
|
||||
.Code__code___31Vg8{position:absolute;top:110px;right:10px;bottom:10px;width:425px;background:rgba(0,0,0,.7);color:#fff;border-radius:4px;padding:24px;font-family:Roboto,monospace;white-space:pre;font-size:14px;line-height:22px}.Layout__header___33oX6{position:relative;width:100%;height:100px;padding:0 0 0 20px}.Layout__header___33oX6 h1{font-family:Roboto,sans-serif;font-size:32px;font-weight:300;line-height:64px;margin:0;padding:0}.Layout__header___33oX6 ul{list-style:none;display:block;overflow:hidden;margin:0;padding:0;line-height:32px}.Layout__header___33oX6 ul li{float:left;display:block;cursor:pointer}.Layout__header___33oX6 ul li:hover{border-bottom:4px solid #00bcd4}.Layout__header___33oX6 ul li.active{border-bottom:4px solid #2196f3}.Layout__header___33oX6 ul li a{text-decoration:none;color:inherit;display:block;width:100%;height:100%;padding:0 24px}.Layout__content___GDRpI{position:absolute;top:100px;bottom:0;left:20px;right:465px}.Layout__fullWidth___2Qlah{left:0;right:0}.Map__map___2UbOE{position:absolute;display:block;width:100%;height:100%}.SearchResults__item___3yUT->*{border:1px solid transparent;line-height:32px;padding:0 18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.SearchResults__item___3yUT->.active,.SearchResults__item___3yUT->:hover{background-color:#f8f8f8;border-color:#c6c6c6}.Search__search___2kQjw form{position:relative;margin:32px 0;background-color:#fff;vertical-align:top;border-radius:2px;box-shadow:0 2px 2px 0 rgba(0,0,0,.16),0 0 0 1px rgba(0,0,0,.08);transition:box-shadow .2s cubic-bezier(.4,0,.2,1)}.Search__search___2kQjw.active form,.Search__search___2kQjw form:hover{box-shadow:0 3px 8px 0 rgba(0,0,0,.2),0 0 0 1px rgba(0,0,0,.08)}.Search__search___2kQjw input{border:none;padding:0;margin:0;width:100%;outline:none;font:16px arial,sans-serif;line-height:48px;height:48px;text-indent:18px}body,html{font-family:Open Sans,sans-serif;margin:0;padding:0;height:100%;width:100%}*,:after,:before,body,html{box-sizing:border-box}.leaflet-control-geosearch.bar{position:absolute!important;left:50px;right:515px}
|
||||
.Code__code___2Fodu{position:absolute;top:110px;right:10px;bottom:10px;width:425px;background:rgba(0,0,0,.7);color:#fff;border-radius:4px;padding:24px;font-family:Roboto,monospace;white-space:pre;font-size:14px;line-height:22px}.Layout__header___1OdPt{position:relative;width:100%;height:100px;padding:0 0 0 20px}.Layout__header___1OdPt h1{font-family:Roboto,sans-serif;font-size:32px;font-weight:300;line-height:64px;margin:0;padding:0}.Layout__header___1OdPt ul{list-style:none;display:block;overflow:hidden;margin:0;padding:0;line-height:32px}.Layout__header___1OdPt ul li{float:left;display:block;cursor:pointer}.Layout__header___1OdPt ul li:hover{border-bottom:4px solid #00bcd4}.Layout__header___1OdPt ul li.active{border-bottom:4px solid #2196f3}.Layout__header___1OdPt ul li a{text-decoration:none;color:inherit;display:block;width:100%;height:100%;padding:0 24px}.Layout__content___3B6ar{position:absolute;top:100px;bottom:0;left:20px;right:465px}.Layout__fullWidth___rFTw3{left:0;right:0}.Map__map___pw2iZ{position:absolute;display:block;width:100%;height:100%}.SearchResults__item___NCXDt>*{border:1px solid transparent;line-height:32px;padding:0 18px;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}.SearchResults__item___NCXDt>.active,.SearchResults__item___NCXDt>:hover{background-color:#f8f8f8;border-color:#c6c6c6}.Search__search___LX680 form{position:relative;margin:32px 0;background-color:#fff;vertical-align:top;border-radius:2px;box-shadow:0 2px 2px 0 rgba(0,0,0,.16),0 0 0 1px rgba(0,0,0,.08);transition:box-shadow .2s cubic-bezier(.4,0,.2,1)}.Search__search___LX680 form:hover,.Search__search___LX680.active form{box-shadow:0 3px 8px 0 rgba(0,0,0,.2),0 0 0 1px rgba(0,0,0,.08)}.Search__search___LX680 input{border:none;padding:0;margin:0;width:100%;outline:none;font:16px arial,sans-serif;line-height:48px;height:48px;text-indent:18px}body,html{font-family:Open Sans,sans-serif;margin:0;padding:0;height:100%;width:100%}*,:after,:before,body,html{box-sizing:border-box}.leaflet-control-geosearch.bar{position:absolute!important;left:50px;right:515px}
|
||||
21
readme.md
21
readme.md
@@ -50,12 +50,13 @@ 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 four providers:
|
||||
The control comes with a default set of five providers:
|
||||
|
||||
- [Bing](#bing-provider).
|
||||
- [Esri](#esri-provider).
|
||||
- [Google](#google-provider).
|
||||
- [OpenStreetMap](#openstreetmap-provider).
|
||||
- [LocationIQ](#locationiq-provider).
|
||||
|
||||
Although this project is still named `leaflet-geosearch`, this library is also
|
||||
usable without LeafletJS, and does not have any dependencies whatsoever.
|
||||
@@ -131,7 +132,7 @@ use your debugger)
|
||||
|
||||
# Providers
|
||||
When `OpenStreetMap` does not match your needs; you can also choose to use the
|
||||
`Bing`, `Esri` or `Google` providers. Those providers do however require API
|
||||
`Bing`, `Esri`, `Google` or `LocationIQ` providers. Those providers do however require API
|
||||
keys. See the documentation pages on the relevant organisations on how to obtain
|
||||
these keys.
|
||||
|
||||
@@ -190,6 +191,20 @@ import { OpenStreetMapProvider } from 'leaflet-geosearch';
|
||||
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({
|
||||
params: {
|
||||
key: '__YOUR_LOCATIONIQ_KEY__',
|
||||
},
|
||||
});
|
||||
```
|
||||
|
||||
# Using with LeafletJS
|
||||
|
||||
This project comes with a leaflet control to hook the search providers into
|
||||
@@ -333,3 +348,5 @@ to share your work with us.
|
||||
[15]: https://unpkg.com/leaflet-geosearch@latest/dist/bundle.min.js
|
||||
[16]: https://www.npmjs.com/package/babel-polyfill
|
||||
[17]: https://www.npmjs.com/package/whatwg-fetch
|
||||
[18]: https://locationiq.org
|
||||
[19]: https://locationiq.org/#docs
|
||||
|
||||
33
src/providers/__tests__/locationiqProvider.spec.js
Normal file
33
src/providers/__tests__/locationiqProvider.spec.js
Normal file
@@ -0,0 +1,33 @@
|
||||
import test from 'ava';
|
||||
import Provider from '../locationIQProvider';
|
||||
|
||||
test.skip('Can fetch results with LocationIQ', async (t) => {
|
||||
const provider = new Provider({
|
||||
params: {
|
||||
key: process.env.LOCATIONIQ_API_KEY,
|
||||
},
|
||||
});
|
||||
|
||||
const results = await provider.search({ query: 'netherlands' });
|
||||
const result = results[0];
|
||||
|
||||
t.truthy(result.label);
|
||||
t.true(result.x > 5 && result.x < 6);
|
||||
t.true(result.y > 50 && result.y < 55);
|
||||
t.true(result.bounds[0][0] > result.bounds[0][1]);
|
||||
t.true(result.bounds[1][0] > result.bounds[1][1]);
|
||||
t.true(result.bounds[0][0] < result.bounds[1][0]);
|
||||
t.true(result.bounds[0][1] < result.bounds[1][1]);
|
||||
});
|
||||
|
||||
test.skip('Can get localized results', async (t) => {
|
||||
const provider = new Provider({
|
||||
params: {
|
||||
'key': process.env.LOCATIONIQ_API_KEY,
|
||||
'accept-language': 'nl',
|
||||
},
|
||||
});
|
||||
|
||||
const results = await provider.search({ query: 'nederland' });
|
||||
t.is(results[0].label, 'Nederland');
|
||||
});
|
||||
28
src/providers/locationIQProvider.js
Normal file
28
src/providers/locationIQProvider.js
Normal file
@@ -0,0 +1,28 @@
|
||||
import BaseProvider from './provider';
|
||||
|
||||
export default class Provider extends BaseProvider {
|
||||
endpoint({ query, protocol } = {}) {
|
||||
const { params } = this.options;
|
||||
|
||||
const paramString = this.getParamString({
|
||||
...params,
|
||||
format: 'json',
|
||||
q: query,
|
||||
});
|
||||
|
||||
return `${protocol}//locationiq.org/v1/search.php?${paramString}`;
|
||||
}
|
||||
|
||||
parse({ data }) {
|
||||
return data.map(r => ({
|
||||
x: r.lon,
|
||||
y: r.lat,
|
||||
label: r.display_name,
|
||||
bounds: [
|
||||
[parseFloat(r.boundingbox[0]), parseFloat(r.boundingbox[2])], // s, w
|
||||
[parseFloat(r.boundingbox[1]), parseFloat(r.boundingbox[3])], // n, e
|
||||
],
|
||||
raw: r,
|
||||
}));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user