-
Notifications
You must be signed in to change notification settings - Fork 4
/
easy-button.js
57 lines (44 loc) · 1.54 KB
/
easy-button.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
L.Control.EasyButtons = L.Control.extend({
options: {
position: 'topleft',
title: '',
intendedIcon: 'fa-circle-o'
},
onAdd: function () {
var container = L.DomUtil.create('div', 'leaflet-bar leaflet-control');
this.link = L.DomUtil.create('a', 'leaflet-bar-part', container);
this._addImage()
this.link.href = '#';
L.DomEvent.on(this.link, 'click', this._click, this);
this.link.title = this.options.title;
return container;
},
intendedFunction: function(){ alert('no function selected');},
_click: function (e) {
L.DomEvent.stopPropagation(e);
L.DomEvent.preventDefault(e);
this.intendedFunction();
},
_addImage: function () {
var extraClasses = this.options.intendedIcon.lastIndexOf('fa', 0) === 0 ? ' fa fa-lg' : ' glyphicon';
var icon = L.DomUtil.create('i', this.options.intendedIcon + extraClasses, this.link);
icon.id = this.options.id;
}
});
L.easyButton = function( btnIcon , btnFunction , btnTitle , btnMap , btnId) {
var newControl = new L.Control.EasyButtons;
if (btnIcon) newControl.options.intendedIcon = btnIcon;
if (btnId) newControl.options.id = btnId;
if ( typeof btnFunction === 'function'){
newControl.intendedFunction = btnFunction;
}
if (btnTitle) newControl.options.title = btnTitle;
if ( btnMap == '' ){
// skip auto addition
} else if ( btnMap ) {
btnMap.addControl(newControl);
} else {
map.addControl(newControl);
}
return newControl;
};