From 2eea5c352382e6236f06b48076c3483229d0074b Mon Sep 17 00:00:00 2001 From: Matthew Mattson Date: Thu, 4 Dec 2014 03:27:48 -0800 Subject: [PATCH] Update Spherical.js The current implementation of OpenLayers.Spherical.computeHeading() is wrong based on the relevant [link](http://www.movable-type.co.uk/scripts/latlong.html) listed in Spherical.js. The delta of the longitudes is reversed in both the 'y' and the 'x' portion of the equations. Instead of `from.lon - to.lon`, it should be `to.lon - from.lon`. --- lib/OpenLayers/Spherical.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/OpenLayers/Spherical.js b/lib/OpenLayers/Spherical.js index 74e14a8c75..9f09a46324 100644 --- a/lib/OpenLayers/Spherical.js +++ b/lib/OpenLayers/Spherical.js @@ -60,8 +60,8 @@ OpenLayers.Spherical.computeDistanceBetween = function(from, to, radius) { * {Float} The heading in degrees. */ OpenLayers.Spherical.computeHeading = function(from, to) { - var y = Math.sin(Math.PI * (from.lon - to.lon) / 180) * Math.cos(Math.PI * to.lat / 180); + var y = Math.sin(Math.PI * (to.lon - from.lon) / 180) * Math.cos(Math.PI * to.lat / 180); var x = Math.cos(Math.PI * from.lat / 180) * Math.sin(Math.PI * to.lat / 180) - - Math.sin(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180) * Math.cos(Math.PI * (from.lon - to.lon) / 180); + Math.sin(Math.PI * from.lat / 180) * Math.cos(Math.PI * to.lat / 180) * Math.cos(Math.PI * (to.lon - from.lon) / 180); return 180 * Math.atan2(y, x) / Math.PI; };