react-leafletI currently run into a situation with Canvas renderer where my polylines and polygons are not rendered with the correct dashArray. Sometimes lines with a specified dashArray are rendered without one and lines without one are rendered with one. I wish I could reproduce this with a small example but I can't seem to figure out how to reproduce it exactly (I'm using react-leaflet 1.1.4 for what it's worth).
What seems to be happening is that the settings in https://github.com/Leaflet/Leaflet/blob/da6f20d2d78f9bcb35ff033f7f5744a8e91fbdf4/src/layer/vector/Canvas.js#L314-L334
are being leaked between successive calls. From what I can tell, Canvas renderer attempts to isolate the state between calls in _draw using ctx.save() and ctx.restore(). However in my application, multiple calls to fillStroke are made in a single _draw call (which is called exactly once per map update). If I use ctx.save() and ctx.restore() in _fillStroke, the problem goes away
Hi,
Thank you for using Leaflet.
Please can you provide a Plunker that reproduces that issue, without any wrapper library?
(no react, etc.)
With a bit of digging, I found what the issue is!
https://next.plnkr.co/edit/hhRnU8AT3rQQMvBt
Somewhere in our code, we're passing 'none' as our options.dashArray. This is parsed as [NaN] in _updateDashArray. This actually makes it all the way to the canvas rendering context and when the context receives an invalid argument for setLineDash, it ends up keeping the old state.
This is easily fixable from our end by simply not passing invalid values to dashArray. However this could still be considered a bug because this canvas and SVG render inconsistently for the same value of dashArray.
PS: I found another issue (unrelated?), where the dashArray wouldn't work if I omitted the commas i.e. '5 5' instead of 5, 5. I haven't been able to replicate this yet however.
Thank you for your investigation! :+1:
As for the issue with space-separated values, see https://github.com/Leaflet/Leaflet/issues/6277 (fix should be in Leaflet 1.3.4)
I confirm that exiting _updateDashArray in case dashArray option is "none" (or illegal values) avoids the bug:
https://next.plnkr.co/edit/QBAL7SQ4dkvpXqZd