-
Notifications
You must be signed in to change notification settings - Fork 59
/
Pattern.SVG.js
97 lines (81 loc) · 2.64 KB
/
Pattern.SVG.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
L.Pattern.SVG_NS = 'http://www.w3.org/2000/svg';
L.Pattern = L.Pattern.extend({
_createElement: function (name) {
return document.createElementNS(L.Pattern.SVG_NS, name);
},
_initDom: function () {
this._dom = this._createElement('pattern');
if (this.options.className) {
L.DomUtil.addClass(this._dom, this.options.className);
}
this._updateStyle();
},
_addDom: function () {
this._map._defRoot.appendChild(this._dom);
},
_removeDom: function () {
L.DomUtil.remove(this._dom);
},
_updateStyle: function () {
var dom = this._dom,
options = this.options;
if (!dom) { return; }
dom.setAttribute('id', L.stamp(this));
dom.setAttribute('x', options.x);
dom.setAttribute('y', options.y);
dom.setAttribute('width', options.width);
dom.setAttribute('height', options.height);
dom.setAttribute('patternUnits', options.patternUnits);
dom.setAttribute('patternContentUnits', options.patternContentUnits);
if (options.patternTransform || options.angle) {
var transform = options.patternTransform ? options.patternTransform + " " : "";
transform += options.angle ? "rotate(" + options.angle + ") " : "";
dom.setAttribute('patternTransform', transform);
}
else {
dom.removeAttribute('patternTransform');
}
for (var i in this._shapes) {
this._shapes[i]._updateStyle();
}
}
});
L.Map.include({
_initDefRoot: function () {
if (!this._defRoot) {
if (typeof this.getRenderer === 'function') {
var renderer = this.getRenderer(this);
this._defRoot = L.Pattern.prototype._createElement('defs');
renderer._container.appendChild(this._defRoot);
} else {
if (!this._pathRoot) {
this._initPathRoot();
}
this._defRoot = L.Pattern.prototype._createElement('defs');
this._pathRoot.appendChild(this._defRoot);
}
}
}
});
if (L.SVG) {
L.SVG.include({
_superUpdateStyle: L.SVG.prototype._updateStyle,
_updateStyle: function (layer) {
this._superUpdateStyle(layer);
if (layer.options.fill && layer.options.fillPattern) {
layer._path.setAttribute('fill', 'url(#' + L.stamp(layer.options.fillPattern) + ")");
}
}
});
}
else {
L.Path.include({
_superUpdateStyle: L.Path.prototype._updateStyle,
_updateStyle: function () {
this._superUpdateStyle();
if (this.options.fill && this.options.fillPattern) {
this._path.setAttribute('fill', 'url(#' + L.stamp(this.options.fillPattern) + ")");
}
}
});
}