-
Notifications
You must be signed in to change notification settings - Fork 0
/
leaflet.icon-material.js
84 lines (67 loc) · 3.26 KB
/
leaflet.icon-material.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
/**
* Lefalet.IconMaterial uses code from
* 1- Leaflet.AwesomeMarkers (c) 2012-2013, Lennard Voogdt <https://github.com/lvoogdt>
* 2- and Wesley Van De Voorde's SVG magic <https://github.com/wesleyvandevoorde>
* to create fully colorable SVG markers with Material icons in them.
*
* Author: Ilya Ilyankou <https://github.com/ilyankou>
* License: MIT
* Version: 1.0
*/
/*global L*/
(function (window, document, undefined) {
"use strict";
L.IconMaterial = {};
L.IconMaterial.version = '1.1.0';
L.IconMaterial.Icon = L.Icon.extend({
options: {
className: 'l-icon-material',
icon: 'radio_button_checked',
markerColor: 'white',
iconColor: 'white',
outlineColor: 'white',
outlineWidth: '1',
iconSize: [31, 42]
},
initialize: function (options) {
options = L.Util.setOptions(this, options);
},
createIcon: function () {
var options = L.Util.setOptions(this);
var svg = document.createElementNS("http://www.w3.org/2000/svg", "svg");
var path = document.createElementNS('http://www.w3.org/2000/svg', "path");
var backgroundCircle = document.createElementNS('http://www.w3.org/2000/svg', "circle");
var icongroup = document.createElementNS('http://www.w3.org/2000/svg', "g");
var icon = document.createElementNS('http://www.w3.org/2000/svg', "text");
svg.setAttribute('width', options.iconSize[0]);
svg.setAttribute('height', options.iconSize[1]);
svg.setAttribute('viewBox', '0 0 31 42');
svg.setAttribute('class', 'l-icon-material');
svg.setAttribute('style', 'margin-left:-' + parseInt(options.iconSize[0]/2) + 'px; margin-top:-' + options.iconSize[1] + 'px')
svg.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns:xlink", "http://www.w3.org/1999/xlink");
backgroundCircle.setAttribute('cx', '15.5');
backgroundCircle.setAttribute('cy', '15');
backgroundCircle.setAttribute('r', '11');
backgroundCircle.setAttribute('fill', options.markerColor);
path.setAttributeNS(null, "d", "M15.6,1c-7.7,0-14,6.3-14,14c0,10.5,14,26,14,26s14-15.5,14-26C29.6,7.3,23.3,1,15.6,1z");
path.setAttribute('fill', options.markerColor);
path.setAttribute('stroke', options.outlineColor);
path.setAttribute('stroke-width', options.outlineWidth);
icon.textContent = options.icon;
icon.setAttribute('x', '7');
icon.setAttribute('y', '23');
icon.setAttribute('class', 'material-icons');
icon.setAttribute('fill', options.iconColor);
icon.setAttribute('font-family', 'Material Icons');
svg.appendChild(path);
svg.appendChild(backgroundCircle);
icongroup.appendChild(icon);
svg.appendChild(icongroup);
svg.setAttribute('transform', "matrix(1 0 0 1 -" + parseInt(options.iconSize[0] / 2) + " " + parseInt(options.iconSize[1]) + ")");
return svg;
}
});
L.IconMaterial.icon = function (options) {
return new L.IconMaterial.Icon(options);
};
}(this, document));