Leaflet Polylines crossing dateline

Viewed 181

I am developing an application which needs to show a polyline which occassionally crosses the dateline. Problem is longitude bounds are -180 and +180. I have fenagled things to determine the index of the dateline in the array of coordinates. After crossing the index I just add +360 or -360 to continue the line as-is. This works and it shows the polyline. There is one catch. The user has to move the map left or right over the dateline. When that happens the polyline appears. This is obviously not a good solution.

Has anybody figured out how to display a polyline over dateline properly in leaflet from the get-go? Meaning without the need to move the map left or right to cross the dateline to make the polyline appear.

1 Answers

move the map left or right to cross the dateline to make the polyline appear

From the behaviour you describe, you probably have the map worldCopyJump option enabled.

With this option enabled, the map tracks when you pan to another "copy" of the world and seamlessly jumps to the original one so that all overlays like markers and vector layers are still visible.

But in your very case, your feature exists only on one "edge" of the world, so when the map jumps to the other edge, it looks like your feature disappeared.

In that case, simply remove that option from your map.

Related