Skip to content

Commit

Permalink
Merge pull request #4364 from Leaflet/fix-canvas-dasharray
Browse files Browse the repository at this point in the history
Initialize canvas dash on init. Check that canvas supports setLineDash.
  • Loading branch information
yohanboniface committed Apr 2, 2016
2 parents 9cfeab6 + 4267291 commit ec10c1b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 5 additions & 0 deletions debug/vector/vector-canvas.html
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions src/layer/vector/Canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ L.Canvas = L.Renderer.extend({
},

_initPath: function (layer) {
this._updateDashArray(layer);
this._layers[L.stamp(layer)] = layer;
},

Expand All @@ -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) {
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit ec10c1b

Please sign in to comment.