PluginProbe
Leaflet Map / 2.11.2
Leaflet Map v2.11.2
3.4.7 3.4.6 trunk 2.10.0 2.10.1 2.11.0 2.11.1 2.11.2 2.11.3 2.11.4 2.11.5 2.12.0 2.13.0 2.14.0 2.15.0 2.16.0 2.16.1 2.16.2 2.17.0 2.17.1 2.17.2 2.17.3 2.18.0 2.19.0 2.19.1 All 49 releases
leaflet-map / scripts / leaflet-svg-icon.js

leaflet-svg-icon.js in Leaflet Map 2.11.2, at scripts/leaflet-svg-icon.js

73 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 L.SVGIcon = L.Icon.extend({
2 options: {
3 iconSize: [26, 42],
4 popupAnchor: [1, -42],
5 tooltipAnchor: [16, -28],
6 iconClass: '',
7 background: '#2b82cb',
8 color: 'white'
9 },
10 createIcon: function (oldIcon) {
11 var div = (oldIcon && oldIcon.tagName === 'DIV') ?
12 oldIcon : document.createElement('div');
13 var options = this.options;
14 var size = options.iconSize;
15 var x = size[0];
16 var y = size[1];
17
18 var svgCreate = function svgCreate (tag, attrs) {
19 var el = document.createElementNS('http://www.w3.org/2000/svg', tag);
20 for (var k in attrs) {
21 el.setAttribute(k, attrs[k]);
22 }
23 return el;
24 };
25
26 var svg = svgCreate('svg', {
27 viewBox: '0 0 365 560'
28 });
29
30 var path = svgCreate('path', {
31 fill: this.options.background,
32 d: 'M182.9,551.7c0,0.1,0.2,0.3,0.2,0.3S358.3,' +
33 '283,358.3,194.6c0-130.1-88.8-186.7-175.4-186.9' +
34 'C96.3,7.9,7.5,64.5,7.5,194.6c0,88.4,175.3,357.4,' +
35 '175.3,357.4S182.9,551.7,182.9,551.7z'
36 });
37
38 svg.appendChild(path);
39 div.appendChild(svg);
40
41 div.setAttribute('style', 'margin-left: ' + (-x/2) + 'px;' +
42 'margin-top: ' + -y + 'px;' +
43 'width: ' + x + 'px;' +
44 'height: ' + y + 'px;'
45 );
46
47 // add icon
48 var i = document.createElement('i');
49 i.className = this.options.iconClass;
50 i.setAttribute('style', 'position:absolute;' +
51 'top: 34%;' +
52 'left: 50%;' +
53 'transform: translate3d(-50%, -34%, 0);' +
54 'color: ' + (this.options.color) + ';' +
55 'line-height: 0;'
56 );
57 div.appendChild(i);
58
59 return div;
60 }
61 });
62
63 L.SVGMarker = L.Marker.extend({
64 initialize: function (latlng, options) {
65 options = options || {};
66 var svg_options = L.extend({},
67 L.SVGIcon.prototype.options,
68 options
69 );
70 options.icon = new L.SVGIcon( svg_options );
71 L.Marker.prototype.initialize.call(this, latlng, options);
72 }
73 });