/*
* Vector rendering for IE7-8 through VML.
* Thanks to Dmitry Baranovsky and his Raphael library for inspiration!
*/
L.Browser.vml = !L.Browser.svg && (function () {
try {
var div = document.createElement('div');
div.innerHTML = '';
var shape = div.firstChild;
shape.style.behavior = 'url(#default#VML)';
return shape && (typeof shape.adj === 'object');
} catch (e) {
return false;
}
}());
// redefine some SVG methods to handle VML syntax which is similar but with some differences
L.SVG.include(!L.Browser.vml ? {} : {
_initContainer: function () {
this._container = L.DomUtil.create('div', 'leaflet-vml-container');
},
_update: function () {
if (this._map._animatingZoom) { return; }
L.Renderer.prototype._update.call(this);
},
_initPath: function (layer) {
var container = layer._container = L.SVG.create('shape');
L.DomUtil.addClass(container, 'leaflet-vml-shape ' + (this.options.className || ''));
container.coordsize = '1 1';
layer._path = L.SVG.create('path');
container.appendChild(layer._path);
if (layer.options.clickable) {
this._initEvents(layer, container);
}
this._updateStyle(layer);
},
_addPath: function (layer) {
this._container.appendChild(layer._container);
},
_removePath: function (layer) {
L.DomUtil.remove(layer._container);
},
_updateStyle: function (layer) {
var stroke = layer._stroke,
fill = layer._fill,
options = layer.options,
container = layer._container;
container.stroked = !!options.stroke;
container.filled = !!options.fill;
if (options.stroke) {
if (!stroke) {
stroke = layer._stroke = L.SVG.create('stroke');
container.appendChild(stroke);
}
stroke.weight = options.weight + 'px';
stroke.color = options.color;
stroke.opacity = options.opacity;
if (options.dashArray) {
stroke.dashStyle = L.Util.isArray(options.dashArray) ?
options.dashArray.join(' ') :
options.dashArray.replace(/( *, *)/g, ' ');
} else {
stroke.dashStyle = '';
}
stroke.endcap = options.lineCap.replace('butt', 'flat');
stroke.joinstyle = options.lineJoin;
} else if (stroke) {
container.removeChild(stroke);
layer._stroke = null;
}
if (options.fill) {
if (!fill) {
fill = layer._fill = L.SVG.create('fill');
container.appendChild(fill);
}
fill.color = options.fillColor || options.color;
fill.opacity = options.fillOpacity;
} else if (fill) {
container.removeChild(fill);
layer._fill = null;
}
},
_updateCircle: function (layer) {
var p = layer._point,
r = Math.round(layer._radius),
r2 = Math.round(layer._radiusY || r);
this._setPath(layer, layer._empty() ? 'M0 0' :
'AL ' + p.x + ',' + p.y + ' ' + r + ',' + r2 + ' 0,' + (65535 * 360));
},
_setPath: function (layer, path) {
layer._path.v = path;
}
});
if (L.Browser.vml) {
L.SVG.create = (function () {
try {
document.namespaces.add('lvml', 'urn:schemas-microsoft-com:vml');
return function (name) {
return document.createElement('');
};
} catch (e) {
return function (name) {
return document.createElement('<' + name + ' xmlns="urn:schemas-microsoft.com:vml" class="lvml">');
};
}
})();
L.SVG.instance = L.svg();
}