-
Notifications
You must be signed in to change notification settings - Fork 0
/
Leaflet.Icon.Glyph.js
116 lines (95 loc) · 4.88 KB
/
Leaflet.Icon.Glyph.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
L.Icon.Glyph = L.Icon.extend({
options: {
iconSize: [25, 41],
iconAnchor: [12, 41],
popupAnchor: [1, -34],
shadowSize: [41, 41],
// iconUrl: 'glyph-marker-icon.png',
// iconSize: [35, 45],
// iconAnchor: [17, 42],
// popupAnchor: [1, -32],
// shadowAnchor: [10, 12],
// shadowSize: [36, 16],
// bgPos: (Point)
className: '',
prefix: '',
glyph: 'home',
glyphColor: 'white',
glyphSize: '11px', // in CSS units
glyphAnchor: [0, -7] // In pixels, counting from the center of the image.
},
createIcon: function () {
var div = document.createElement('div'),
options = this.options;
if (options.glyph) {
div.appendChild(this._createGlyph());
}
this._setIconStyles(div, options.className);
return div;
},
_createGlyph: function() {
var glyphClass,
textContent,
options = this.options;
if (!options.prefix) {
glyphClass = '';
textContent = options.glyph;
} else if((options.prefix === "fab") || (options.prefix === "fal") || (options.prefix === "far") || (options.prefix === "fas")) {
// Hack for Font Awesome 5 - it needs two different prefixes.
glyphClass = "fa-" + options.glyph;
} else if(options.glyph.slice(0, options.prefix.length+1) === options.prefix + "-") {
glyphClass = options.glyph;
} else {
glyphClass = options.prefix + "-" + options.glyph;
}
var span = L.DomUtil.create('span', options.prefix + ' ' + glyphClass);
span.style.fontSize = options.glyphSize;
span.style.color = options.glyphColor;
span.style.width = options.iconSize[0] + 'px';
span.style.lineHeight = options.iconSize[1] + 'px';
span.style.textAlign = 'center';
span.style.marginLeft = options.glyphAnchor[0] + 'px';
span.style.marginTop = options.glyphAnchor[1] + 'px';
span.style.pointerEvents = 'none';
span.style.display = 'inline-block';
if (textContent) {
span.innerHTML = textContent;
}
return span;
},
_setIconStyles: function (div, name) {
if (name === 'shadow') {
return L.Icon.prototype._setIconStyles.call(this, div, name);
}
var options = this.options,
size = L.point(options['iconSize']),
anchor = L.point(options.iconAnchor);
if (!anchor && size) {
anchor = size.divideBy(2, true);
}
div.className = 'leaflet-marker-icon leaflet-glyph-icon ' + name;
var src = this._getIconUrl('icon');
if (src) {
div.style.backgroundImage = "url('" + src + "')";
}
if (options.bgPos) {
div.style.backgroundPosition = (-options.bgPos.x) + 'px ' + (-options.bgPos.y) + 'px';
}
if (options.bgSize) {
div.style.backgroundSize = (options.bgSize.x) + 'px ' + (options.bgSize.y) + 'px';
}
if (anchor) {
div.style.marginLeft = (-anchor.x) + 'px';
div.style.marginTop = (-anchor.y) + 'px';
}
if (size) {
div.style.width = size.x + 'px';
div.style.height = size.y + 'px';
}
}
});
L.icon.glyph = function (options) {
return new L.Icon.Glyph(options);
};
// Base64-encoded version of glyph-marker-icon.png
L.Icon.Glyph.prototype.options.iconUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAApCAYAAADAk4LOAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAN1wAADdcBQiibeAAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAAAUlSURBVFjDrZdLiBxVFIb/e289uqt6kkx6zIiIoKgLRReKuMhCcaOIAUEIiCCE4CIPggZ8kBjooPgM0TiYEUUjqBGchZqAQlyYRTA+kJiJQiJGMjN5zYzT3dP1rrr3HBeTjDGTSfc8Dvyruud89Z9z6kIJdBj31763MivsJXKuZYF6dak5++2mh7NOcsXVHq6sHbhOK/24kOJJMO4AE1vKygwZhxlKSHGKiD+RSu09vOXB43OCrHz96y6T2lsh+OmKXzFdlbLne2UopSAupBhjECcZgjDM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