From 4267291527cef8fccf141e67091951217a0947cc Mon Sep 17 00:00:00 2001 From: Per Liedman Date: Fri, 1 Apr 2016 18:05:30 +0200 Subject: [PATCH] Initialize canvas dash on init. Check that canvas supports setLineDash. Close #4363. Close #4351. --- debug/vector/vector-canvas.html | 5 +++++ src/layer/vector/Canvas.js | 11 ++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/debug/vector/vector-canvas.html b/debug/vector/vector-canvas.html index c1749115..f89c2c94 100644 --- a/debug/vector/vector-canvas.html +++ b/debug/vector/vector-canvas.html @@ -83,6 +83,11 @@ }); group.addLayer(polygon); + var line = new L.Polyline([h1, h4, h5], { + dashArray: '5, 5' + }); + group.addLayer(line); + polygon.bindPopup('I am a polygon'); map.addLayer(group); diff --git a/src/layer/vector/Canvas.js b/src/layer/vector/Canvas.js index 935f3df6..f11715cd 100644 --- a/src/layer/vector/Canvas.js +++ b/src/layer/vector/Canvas.js @@ -54,6 +54,7 @@ L.Canvas = L.Renderer.extend({ }, _initPath: function (layer) { + this._updateDashArray(layer); this._layers[L.stamp(layer)] = layer; }, @@ -74,12 +75,14 @@ L.Canvas = L.Renderer.extend({ }, _updateStyle: function (layer) { + this._updateDashArray(); + this._requestRedraw(layer); + }, + _updateDashArray: function (layer) { if (layer.options.dashArray) { layer.options._dashArray = layer.options.dashArray.split(',').map(Number); } - - this._requestRedraw(layer); }, _requestRedraw: function (layer) { @@ -138,7 +141,9 @@ L.Canvas = L.Renderer.extend({ ctx.beginPath(); - ctx.setLineDash(layer.options && layer.options._dashArray || []); + if (ctx.setLineDash) { + ctx.setLineDash(layer.options && layer.options._dashArray || []); + } for (i = 0; i < len; i++) { for (j = 0, len2 = parts[i].length; j < len2; j++) {