Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fix issue with 180 longs being clamped to -180

  • Loading branch information...
commit 57f44bc4234f869bee221c84a795ef1487002005 1 parent 50a5790
@alexgraul authored
Showing with 9 additions and 3 deletions.
  1. +8 −2 spec/suites/geo/LatLngSpec.js
  2. +1 −1  src/geo/LatLng.js
View
10 spec/suites/geo/LatLngSpec.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
2  src/geo/LatLng.js
@@ -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()
Please sign in to comment.
Something went wrong with that request. Please try again.