Repository navigation
Expand file tree
/
Copy pathleaflet-text.js
More file actions
52 lines (47 loc) · 1.56 KB
/
Copy pathleaflet-text.js
File metadata and controls
52 lines (47 loc) · 1.56 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
/*
*
* A Leaflet extension for showing text on a map
* by Andreas Rauchenbacher - Team122.at
* Github Repo: https://github.com/fitforfire/leaflet.text.git
*/
(function () {
L.TextIcon = L.DivIcon.extend({
initialize: function(options) {
if (!options.size) {
options.size = 24;
}
if (!options.color) {
options.color = 'blue';
}
if (!options.text) {
options.text = 'Text';
}
L.setOptions(this, options);
},
createIcon: function() {
var containerElement = document.createElement('div');
containerElement.className = 'leaflet-marker-icon leaflet-text-marker';
this._spanElement = document.createElement('span');
this.update();
containerElement.appendChild(this._spanElement);
return containerElement;
},
update: function() {
this._spanElement.className = 'leaflet-color-' + this.options.color ;
this._spanElement.style.fontSize = this.options.size + 'px';
this._spanElement.innerText = this.options.text;
},
fontsizeIncrease: function() {
this.options.size += 8;
this.update();
},
fontsizeDecrease: function() {
this.options.size -= 8;
this.update();
},
setText: function(text) {
this.options.text = text;
this.update();
}
});
}());