Permalink
Browse files

fix issue with 180 longs being clamped to -180

  • Loading branch information...
Alex Graul
Alex Graul committed Dec 21, 2011
1 parent 50a5790 commit 57f44bc4234f869bee221c84a795ef1487002005
Showing with 9 additions and 3 deletions.
  1. +8 −2 spec/suites/geo/LatLngSpec.js
  2. +1 −1 src/geo/LatLng.js
@@ -21,7 +21,7 @@ describe('LatLng', function() {
it("should clamp longtitude to lie between -180 and 180", function() {
var a = new L.LatLng(0, 190).lng;
expect(a).toEqual(-170);
-
+
var b = new L.LatLng(0, 360).lng;
expect(b).toEqual(0);
@@ -36,7 +36,13 @@ describe('LatLng', function() {
var f = new L.LatLng(0, -380).lng;
expect(f).toEqual(-20);
- });
+
+ var g = new L.LatLng(0, 90).lng;
+ expect(g).toEqual(90);
+
+ var h = new L.LatLng(0, 180).lng;
+ expect(h).toEqual(180);
+ });
it("should not clamp latitude and longtitude if unbounded flag set to true", function() {
var a = new L.LatLng(150, 0, true).lat;
View
@@ -12,7 +12,7 @@ L.LatLng = function (/*Number*/ rawLat, /*Number*/ rawLng, /*Boolean*/ noWrap) {
if (noWrap !== true) {
lat = Math.max(Math.min(lat, 90), -90); // clamp latitude into -90..90
- lng = (lng + 180) % 360 + (lng < -180 ? 180 : -180); // wrap longtitude into -180..180
+ lng = (lng + 180) % 360 + ((lng < -180 || lng === 180) ? 180 : -180); // wrap longtitude into -180..180
}
//TODO change to lat() & lng()

0 comments on commit 57f44bc

Please sign in to comment.