-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet-search-geocoder.js
68 lines (62 loc) · 2.02 KB
/
leaflet-search-geocoder.js
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
this file is work in progress and represent an extension
of the main plugin to support programmatically most famous geocoder services
the base idea is:
- any geocoder services is identified by name passed to the plugin option
- any geocoder sub module implemnt custom parameters anc a custom callback to extract resulta in leaflet search format result
- any geocoder accept only two parameters, api key and user key, passed to remote service
any contributions is welcome <3
*/
(function (factory) {
// eslint-disable-next-line
if (typeof define === 'function' && define.amd) {
// AMD
// eslint-disable-next-line
define(['leaflet'], factory)
} else if (typeof module !== 'undefined') {
// Node/CommonJS
module.exports = factory(require('leaflet'))
} else {
// Browser globals
if (typeof window.L === 'undefined') { throw new Error('Leaflet must be loaded first') }
factory(window.L)
}
})(function (L) {
L.Control.Search.include({
options: {
geocoder: 'google',
markerLocation: true,
autoType: false,
autoCollapse: true,
minLength: 2
},
/* onAdd: function (map) {
L.Control.Search.prototype.onAdd.call(this, map);
console.log('Geocoder',this.options)
}, */
geocoders: {
/*
'google': {
urlTmpl: "//maps.googleapis.com/maps/api/geocode/json?key={key}&address={text}"
//todo others
},
'here': {
urlTmpl: https://geocoder.ls.hereapi.com/6.2/geocode.json?apiKey={apiKey}&searchtext={text}"
params: function(opts, text) {
//opts is leaflet options input
//text is input text searched
return {
'apiKey': opts.apikey,
'format': 'json',
'q': text,
'jsonp': 'herejsoncallback',
};
},
callback: function(resp) {
//TODO refact resp data
}
"//nominatim.openstreetmap.org/search?"
} */
}
})
})