Search code examples
javascriptleafletpolyline-decorator

How to draw path superposition with different color on leaflet.js?


I would like to draw several paths from same coordinates on a leaflet.js map. I have thought about making the gap between paths with trigonometric computations, but it's too complex to deal with teh zoom level, translate GPS coordinates to a vector, etc.

The drawing I have now is like this (another path is under the green path):

enter image description here

And I would like something like that:

enter image description here

Of course, the coordinates, angle and zoomlevel can change.


Solution

  • You would probably be interested in Leaflet Polyline Offset plugin:

    This plugin adds to Leaflet Polylines the ability to be drawn with a relative pixel offset, without modifying their actual LatLngs. The offset value can be either negative or positive, for left- or right-side offset, and remains constant across zoom levels.

    Bus lines demo

    Screenshot of Leaflet Polyline Offset plugin bus lines demo