-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathleaflet-typeahead.js
58 lines (56 loc) · 1.76 KB
/
leaflet-typeahead.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
L.Control.Typeahead = L.Control.extend({
options: {
// topright, topleft, bottomleft, bottomright
position: 'topleft',
placeholder: 'Search...'
},
initialize: function (args) {
// constructor
this.arguments = [];
for(var i = 0; i < args.length-1; i++)
this.arguments.push(args[i]);
//console.log(this.arguments);
L.Util.setOptions(this, args[args.length-1]);
},
onAdd: function (map) {
var that = this;
// happens after added to map
//top: -65px; left: 40px
var container = L.DomUtil.create('div', '');
container.style.position = "absolute";
container.style.top = "0px";
container.style.left = "50px";
this.typeahead = L.DomUtil.create('input', 'typeahead tt-input', container);
this.typeahead.type = 'text';
this.typeahead.placeholder = this.options.placeholder;
$(this.typeahead).typeahead.apply($(this.typeahead),this.arguments);
["typeahead:active", "typeahead:idle", "typeahead:open", "typeahead:close",
"typeahead:change", "typeahead:render", "typeahead:select",
"typeahead:autocomplete", "typeahead:cursorchange",
"typeahead:asyncrequest", "typeahead:asynccancel",
"typeahead:asyncreceive"].forEach(function(method){
if(that.options[method]){
$(that.typeahead).bind(method, that.options[method]);
}
});
L.DomEvent.disableClickPropagation(container);
return container;
},
onRemove: function (map) {
},
keyup: function(e) {
if (e.keyCode === 38 || e.keyCode === 40) {
// do nothing
} else {
}
},
itemSelected: function(e) {
L.DomEvent.preventDefault(e);
},
submit: function(e) {
L.DomEvent.preventDefault(e);
}
});
L.control.typeahead = function(args) {
return new L.Control.Typeahead(arguments);
}