v00d00
v00d00

Reputation: 3265

OpenLayers draw shortest path between two points near [-180] [180] longitude

I have two points I would like to connect via line string:

 var a = ol.proj.fromLonLat([-159.6597257, 21.995953]);
 var b = ol.proj.fromLonLat([166.644261, 19.279499]);

Is there a way to draw this line in a way it would not cross the globe.

Fiddle: https://jsfiddle.net/82dgrwny/

around the world

Upvotes: 0

Views: 411

Answers (1)

Mike
Mike

Reputation: 17962

OpenLayers understands "wrapped" coorrdinates. Use either

 var a = ol.proj.fromLonLat([360 - 159.6597257, 21.995953]);

or

var b = ol.proj.fromLonLat([166.644261 - 360, 19.279499]);

updated fiddle

screenshot of map with update

Upvotes: 3

Related Questions