[GIS] Leaflet polyline offset artifacts

javascriptleaflet

I tried to offset features from GeoJSON (2 way road) to make them visible on map (they are too close) but it creates "artifacts" – I guess at the start/end of each feature. There is no problem with the data without offset.

My not working fiddle: https://jsfiddle.net/rrq81rw9/27/

Original working fiddle: https://jsfiddle.net/tlohnes/rrq81rw9/

Leaflet offset: https://github.com/bbecquet/Leaflet.PolylineOffset

enter image description here

enter image description here

enter image description here

Best Answer

This looks to be a known bug (#1) of Leaflet.PolylineOffset plugin.

It is triggered by closely positioned vertices in your polyline, so the effect is more obvious at low zoom when vertices get displayed even closer one to each other.

For example, it is easy to make the "working" example buggy by introducing an extra point in the middle, close to an existing one. If you zoom in, the bug disappears.

https://jsfiddle.net/rrq81rw9/29/

You can also make your "non working" example even buggier by simply zooming out a lot (since you do not have minZoom, you can zoom out far enough).

We can suspect the root cause being pixel rounding of vertices position, which makes the plugin having difficulty in guessing the correct line segment orientation.

As for solving this issue, there is a PR submitted (#13), but not merged yet unfortunately. Feel free to heads up on that PR page or on the issue to get it noticed again.

In the meantime, you can use the PR author fork:

https://github.com/BartWaardenburg/Leaflet.PolylineOffset

Updated JSFiddle of "non working" example, now much better with the fork:

https://jsfiddle.net/rrq81rw9/30/