-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathGeocoder.svelte
More file actions
54 lines (47 loc) · 1.15 KB
/
Geocoder.svelte
File metadata and controls
54 lines (47 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<div
id={fieldId}
use:action={optionsWithDefaults}
on:ready={init}
on:results
on:result
on:loading
on:error
on:clear
on:load
></div>
<script>
import { createEventDispatcher } from 'svelte'
import action from './geocoder-action.js'
export let accessToken
export let options = {}
export let version = 'v5.0.3'
export let types = [ 'country', 'region', 'postcode', 'district', 'place', 'locality', 'neighborhood', 'address' ]
export let placeholder = 'Search'
export let value = null
export let customStylesheetUrl = false
export let geocoder
/**
* Allows you to provide the mapbox geocoder, in case it isn't possible to access it globally
*/
export let MapboxGeocoder = undefined
const dispatch = createEventDispatcher()
const fieldId = 'bsm-' + Math.random().toString(36).substring(6)
const optionsWithDefaults = Object.assign({
version,
accessToken,
types: types.join(','),
placeholder,
customStylesheetUrl,
value,
MapboxGeocoder
}, options)
function init ({ detail }) {
geocoder = detail.geocoder
dispatch('ready')
}
</script>
<style>
div {
padding: 0;
}
</style>