aboutsummaryrefslogtreecommitdiffstats
path: root/extlib/leaflet/src/layer/vector/Path.VML.js
blob: 8481d994e6acd3701771d76660b716bd08050ce3 (plain)
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
/*
 * Vector rendering for IE6-8 through VML. 
 * Thanks to Dmitry Baranovsky and his Raphael library for inspiration!
 */

L.Path.VML = (function() {
	var d = document.createElement('div'), s;
	d.innerHTML = '<v:shape adj="1"/>';
	s = d.firstChild;
	s.style.behavior = 'url(#default#VML)';
	
	return (s && (typeof s.adj == 'object'));
})();

L.Path = L.Path.SVG || !L.Path.VML ? L.Path : L.Path.extend({
	statics: {
		CLIP_PADDING: 0.02
	},
	
	_createElement: (function() { 
		try {
			document.namespaces.add('lvml', 'urn:schemas-microsoft-com:vml');
			return function(name) {
				return document.createElement('<lvml:' + name + ' class="lvml">');
			};
		} catch (e) {
			return function(name) {
				return document.createElement('<' + name + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">');
			};
		}
	})(),
	
	_initRoot: function() {
		if (!this._map._pathRoot) {
			this._map._pathRoot = document.createElement('div');
			this._map._pathRoot.className = 'leaflet-vml-container';
			this._map._panes.overlayPane.appendChild(this._map._pathRoot);

			this._map.on('moveend', this._updateViewport, this);
			this._updateViewport();
		}
	},
	
	_initPath: function() {
		this._container = this._createElement('shape');
		this._container.className += ' leaflet-vml-shape' + 
				(this.options.clickable ? ' leaflet-clickable' : '');
		this._container.coordsize = '1 1';
		
		this._path = this._createElement('path');
		this._container.appendChild(this._path);
		
		this._map._pathRoot.appendChild(this._container);
	},
	
	_initStyle: function() {
		if (this.options.stroke) {
			this._stroke = this._createElement('stroke');
			this._stroke.endcap = 'round';
			this._container.appendChild(this._stroke);
		} else {
			this._container.stroked = false;
		}
		if (this.options.fill) {
			this._container.filled = true;
			this._fill = this._createElement('fill');
			this._container.appendChild(this._fill);
		} else {
			this._container.filled = false;
		}
		this._updateStyle();
	},
	
	_updateStyle: function() {
		if (this.options.stroke) {
			this._stroke.weight = this.options.weight + 'px';
			this._stroke.color = this.options.color;
			this._stroke.opacity = this.options.opacity;
		}
		if (this.options.fill) {
			this._fill.color = this.options.fillColor || this.options.color;
			this._fill.opacity = this.options.fillOpacity;
		}
	},
	
	_updatePath: function() {
		this._container.style.display = 'none';
		this._path.v = this.getPathString() + ' '; // the space fixes IE empty path string bug
		this._container.style.display = '';
	}
});