Permalink
Browse files

Rebuild with MM.Location.bearing

  • Loading branch information...
tmcw committed Apr 26, 2012
1 parent 4ed4372 commit 32cd6918933e909f2e542d48af61df82f1081a14
Showing with 18 additions and 12 deletions.
  1. +17 −11 modestmaps.js
  2. +1 −1 modestmaps.min.js
View
@@ -368,17 +368,6 @@ var MM = com.modestmaps = {
Math.pow(Math.sin((lat1 - lat2) / 2), 2) +
Math.cos(lat1) * Math.cos(lat2) *
Math.pow(Math.sin((lon1 - lon2) / 2), 2)));
- var bearing = Math.atan2(
- Math.sin(lon1 - lon2) *
- Math.cos(lat2),
- Math.cos(lat1) *
- Math.sin(lat2) -
- Math.sin(lat1) *
- Math.cos(lat2) *
- Math.cos(lon1 - lon2)
- ) / -(Math.PI / 180);
-
- bearing = bearing < 0 ? 360 + bearing : bearing;
var A = Math.sin((1-f)*d)/Math.sin(d);
var B = Math.sin(f*d)/Math.sin(d);
@@ -393,7 +382,24 @@ var MM = com.modestmaps = {
return new MM.Location(latN / deg2rad, lonN / deg2rad);
};
+
+ // Returns bearing from one point to another
+ //
+ // * FIXME: bearing is not constant along significant great circle arcs.
+ MM.Location.bearing = function(l1, l2) {
+ var result = Math.atan2(
+ Math.sin(lon1 - lon2) *
+ Math.cos(lat2),
+ Math.cos(lat1) *
+ Math.sin(lat2) -
+ Math.sin(lat1) *
+ Math.cos(lat2) *
+ Math.cos(lon1 - lon2)
+ ) / -(Math.PI / 180);
+ // map it into 0-360 range
+ return (result < 0) ? result + 360 : result;
+ };
// Extent
// ----------
// An object representing a map's rectangular extent, defined by its north,
Oops, something went wrong.

0 comments on commit 32cd691

Please sign in to comment.