diff --git a/src/layer/vector/Canvas.js b/src/layer/vector/Canvas.js index e4ba7801..fc6482e0 100644 --- a/src/layer/vector/Canvas.js +++ b/src/layer/vector/Canvas.js @@ -181,7 +181,7 @@ L.Browser.canvas = (function () { }()); L.canvas = function () { - return new L.Canvas(); + return L.Browser.canvas ? new L.Canvas() : null; }; if (L.Browser.canvas) { diff --git a/src/layer/vector/SVG.VML.js b/src/layer/vector/SVG.VML.js index 94a87f42..edd798bb 100644 --- a/src/layer/vector/SVG.VML.js +++ b/src/layer/vector/SVG.VML.js @@ -45,7 +45,7 @@ L.SVG.include(!L.Browser.vml ? {} : { container.appendChild(layer._path); if (layer.options.clickable) { - this._initEvents(layer); + this._initEvents(layer, container); } this._updateStyle(layer); @@ -65,8 +65,8 @@ L.SVG.include(!L.Browser.vml ? {} : { options = layer.options, container = layer._container; - container.stroked = options.stroke; - container.filled = options.fill; + container.stroked = !!options.stroke; + container.filled = !!options.fill; if (options.stroke) { if (!stroke) { @@ -140,4 +140,6 @@ if (L.Browser.vml) { }; } })(); + + L.SVG.instance = L.svg(); } diff --git a/src/layer/vector/SVG.js b/src/layer/vector/SVG.js index 3c2be1f8..66b15723 100644 --- a/src/layer/vector/SVG.js +++ b/src/layer/vector/SVG.js @@ -43,14 +43,14 @@ L.SVG = L.Renderer.extend({ }, _initPath: function (layer) { - layer._path = L.SVG.create('path'); + var path = layer._path = L.SVG.create('path'); if (layer.options.className) { - L.DomUtil.addClass(layer._path, layer.options.className); + L.DomUtil.addClass(path, layer.options.className); } if (layer.options.clickable) { - this._initEvents(layer); + this._initEvents(layer, path); } this._updateStyle(layer); @@ -124,14 +124,14 @@ L.SVG = L.Renderer.extend({ }, // TODO remove duplication with L.Map - _initEvents: function (layer) { - L.DomUtil.addClass(layer._path, 'leaflet-clickable'); + _initEvents: function (layer, el) { + L.DomUtil.addClass(el, 'leaflet-clickable'); - L.DomEvent.on(layer._path, 'click', layer._onMouseClick, layer); + L.DomEvent.on(el, 'click', layer._onMouseClick, layer); var events = ['dblclick', 'mousedown', 'mouseover', 'mouseout', 'mousemove', 'contextmenu']; for (var i = 0; i < events.length; i++) { - L.DomEvent.on(layer._path, events[i], layer._fireMouseEvent, layer); + L.DomEvent.on(el, events[i], layer._fireMouseEvent, layer); } } }); @@ -142,22 +142,22 @@ L.extend(L.SVG, { return document.createElementNS('http://www.w3.org/2000/svg', name); }, - pointsToPath: function (points, closed) { - var flat = points[0] instanceof L.Point, - str = ''; + pointsToPath: function (rings, closed) { + var str = '', + i, j, len, len2, points, p; - for (var i = 0, len = points.length, p; i < len; i++) { - p = points[i]; - str += flat ? (i ? 'L' : 'M') + p.x + ' ' + p.y : L.SVG.pointsToPath(p, closed); + for (i = 0, len = rings.length; i < len; i++) { + points = rings[i]; + + for (j = 0, len2 = points.length; j < len2; j++) { + p = points[j]; + str += (j ? 'L' : 'M') + Math.round(p.x) + ' ' + Math.round(p.y); + } + + str += closed ? (L.Browser.svg ? 'z' : 'x') : ''; } - str = str || 'M0 0'; - - if (closed) { - str += L.Browser.svg ? 'z' : 'x'; - } - - return str; + return str || 'M0 0'; } });