PluginProbe
Leaflet Map / 2.16.2
Leaflet Map v2.16.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.16.2, at scripts/leaflet-svg-icon.js

91 lines 2.1 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 =
12 oldIcon && oldIcon.tagName === 'DIV'
13 ? oldIcon
14 : document.createElement('div')
15 var options = this.options
16 var size = options.iconSize
17 var x = size[0]
18 var y = size[1]
19
20 var svgCreate = function svgCreate(tag, attrs) {
21 var el = document.createElementNS('http://www.w3.org/2000/svg', tag)
22 for (var k in attrs) {
23 el.setAttribute(k, attrs[k])
24 }
25 return el
26 }
27
28 var svg = svgCreate('svg', {
29 viewBox: '0 0 365 560'
30 })
31
32 var path = svgCreate('path', {
33 fill: this.options.background,
34 d:
35 'M182.9,551.7c0,0.1,0.2,0.3,0.2,0.3S358.3,' +
36 '283,358.3,194.6c0-130.1-88.8-186.7-175.4-186.9' +
37 'C96.3,7.9,7.5,64.5,7.5,194.6c0,88.4,175.3,357.4,' +
38 '175.3,357.4S182.9,551.7,182.9,551.7z'
39 })
40
41 svg.appendChild(path)
42 div.appendChild(svg)
43
44 div.setAttribute(
45 'style',
46 'margin-left: ' +
47 -x / 2 +
48 'px;' +
49 'margin-top: ' +
50 -y +
51 'px;' +
52 'width: ' +
53 x +
54 'px;' +
55 'height: ' +
56 y +
57 'px;'
58 )
59
60 // add icon
61 var i = document.createElement('i')
62 i.className = this.options.iconClass
63 i.setAttribute(
64 'style',
65 'position:absolute;' +
66 'top: 20%;' +
67 'left: 50%;' +
68 'transform: translate3d(-50%, -20%, 0);' +
69 'color: ' +
70 this.options.color +
71 ';' +
72 'line-height: 0;' +
73 'display: flex;' +
74 'justify-content: center;' +
75 'align-items: center;'
76 )
77 div.appendChild(i)
78
79 return div
80 }
81 })
82
83 L.SVGMarker = L.Marker.extend({
84 initialize: function(latlng, options) {
85 options = options || {}
86 var svg_options = L.extend({}, L.SVGIcon.prototype.options, options)
87 options.icon = new L.SVGIcon(svg_options)
88 L.Marker.prototype.initialize.call(this, latlng, options)
89 }
90 })
91