add better docs

This commit is contained in:
Stephan Meijer
2020-04-12 19:27:45 +02:00
parent 9561b34ee7
commit dc733dbfb0
55 changed files with 27056 additions and 8162 deletions

62
docs/usage.mdx Normal file
View File

@@ -0,0 +1,62 @@
---
name: Usage
route: /usage
---
import Playground from './components/Playground';
import Map from './components/Map';
import Search from './components/Search';
# Usage
There are two ways in which `leaflet-geosearch` can be used. Direct usage, for example for address forms, or embedded in a leaflet map to search for points of interest.
## Using the providers directly
All providers can be used without leaflet. You might want to bind them to a form;
<Playground>
<Search provider="OpenStreetMap" />
</Playground>
```js
import { OpenStreetMapProvider } from 'leaflet-geosearch';
const provider = new OpenStreetMapProvider();
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;
<Playground>
<Map provider="OpenStreetMap" />
</Playground>
```js
import { GeoSearchControl, OpenStreetMapProvider } from 'leaflet-geosearch';
const searchControl = new GeoSearchControl({
provider: new OpenStreetMapProvider(),
});
map.addControl(searchControl);
```
## Results
The search event of all providers return an array of `result` objects. The base structure is uniform between the providers. It contains objects matching the following interface:
```ts
interface result {
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
}
```