Merge pull request #4364 from Leaflet/fix-canvas-dasharray

Initialize canvas dash on init. Check that canvas supports setLineDash.
This commit is contained in:
Yohan Boniface 2016-04-02 11:51:57 +02:00
commit ec10c1bb6b
2 changed files with 13 additions and 3 deletions

View File

@ -83,6 +83,11 @@
}); });
group.addLayer(polygon); group.addLayer(polygon);
var line = new L.Polyline([h1, h4, h5], {
dashArray: '5, 5'
});
group.addLayer(line);
polygon.bindPopup('I am a polygon'); polygon.bindPopup('I am a polygon');
map.addLayer(group); map.addLayer(group);

View File

@ -54,6 +54,7 @@ L.Canvas = L.Renderer.extend({
}, },
_initPath: function (layer) { _initPath: function (layer) {
this._updateDashArray(layer);
this._layers[L.stamp(layer)] = layer; this._layers[L.stamp(layer)] = layer;
}, },
@ -74,12 +75,14 @@ L.Canvas = L.Renderer.extend({
}, },
_updateStyle: function (layer) { _updateStyle: function (layer) {
this._updateDashArray();
this._requestRedraw(layer);
},
_updateDashArray: function (layer) {
if (layer.options.dashArray) { if (layer.options.dashArray) {
layer.options._dashArray = layer.options.dashArray.split(',').map(Number); layer.options._dashArray = layer.options.dashArray.split(',').map(Number);
} }
this._requestRedraw(layer);
}, },
_requestRedraw: function (layer) { _requestRedraw: function (layer) {
@ -138,7 +141,9 @@ L.Canvas = L.Renderer.extend({
ctx.beginPath(); 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 (i = 0; i < len; i++) {
for (j = 0, len2 = parts[i].length; j < len2; j++) { for (j = 0, len2 = parts[i].length; j < len2; j++) {