From c5ebd534b22e991183ca565585851193a685bd2a Mon Sep 17 00:00:00 2001 From: Sergey Kruk Date: Mon, 1 Dec 2014 16:02:43 +0300 Subject: [PATCH] Factory L.latLng to accept altitude as third parameter or an object's 'alt' property --- spec/suites/geo/LatLngSpec.js | 9 +++++++++ src/geo/LatLng.js | 6 +++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/spec/suites/geo/LatLngSpec.js b/spec/suites/geo/LatLngSpec.js index 1c050df0..bca6c31c 100644 --- a/spec/suites/geo/LatLngSpec.js +++ b/spec/suites/geo/LatLngSpec.js @@ -103,6 +103,15 @@ describe('LatLng', function () { it('returns null if lng not specified', function () { expect(L.latLng(50)).to.be(null); }); + + it('accepts altitude as third parameter', function () { + expect(L.latLng(50, 30, 100)).to.eql(new L.LatLng(50, 30, 100)); + }); + + it('accepts an object with alt', function () { + expect(L.latLng({lat: 50, lng: 30, alt:100})).to.eql(new L.LatLng(50, 30, 100)); + expect(L.latLng({lat: 50, lon: 30, alt:100})).to.eql(new L.LatLng(50, 30, 100)); + }); }); }); diff --git a/src/geo/LatLng.js b/src/geo/LatLng.js index f56de668..0e451597 100644 --- a/src/geo/LatLng.js +++ b/src/geo/LatLng.js @@ -56,7 +56,7 @@ L.LatLng.prototype = { // constructs LatLng with different signatures // (LatLng) or ([Number, Number]) or (Number, Number) or (Object) -L.latLng = function (a, b) { +L.latLng = function (a, b, c) { if (a instanceof L.LatLng) { return a; } @@ -70,11 +70,11 @@ L.latLng = function (a, b) { return a; } if (typeof a === 'object' && 'lat' in a) { - return new L.LatLng(a.lat, 'lng' in a ? a.lng : a.lon); + return new L.LatLng(a.lat, 'lng' in a ? a.lng : a.lon, a.alt); } if (b === undefined) { return null; } - return new L.LatLng(a, b); + return new L.LatLng(a, b, c); };