From c8e5d7c61bfd03fa79620f205d37d1200e4a2108 Mon Sep 17 00:00:00 2001 From: Sergey Kruk Date: Fri, 5 Dec 2014 20:25:02 +0300 Subject: [PATCH] L.latLng factory not to throw error on empty array parameter --- spec/suites/geo/LatLngSpec.js | 3 +++ src/geo/LatLng.js | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/spec/suites/geo/LatLngSpec.js b/spec/suites/geo/LatLngSpec.js index bca6c31c..9da63f8e 100644 --- a/spec/suites/geo/LatLngSpec.js +++ b/spec/suites/geo/LatLngSpec.js @@ -80,7 +80,10 @@ describe('LatLng', function () { }); it('accepts an array of coordinates', function () { + expect(L.latLng([])).to.eql(null); + expect(L.latLng([50])).to.eql(null); expect(L.latLng([50, 30])).to.eql(new L.LatLng(50, 30)); + expect(L.latLng([50, 30, 100])).to.eql(new L.LatLng(50, 30, 100)); }); it('passes null or undefined as is', function () { diff --git a/src/geo/LatLng.js b/src/geo/LatLng.js index 0e451597..80af58e5 100644 --- a/src/geo/LatLng.js +++ b/src/geo/LatLng.js @@ -61,10 +61,10 @@ L.latLng = function (a, b, c) { return a; } if (L.Util.isArray(a) && typeof a[0] !== 'object') { - if (a.length === 3) { + if (a.length >= 2) { return new L.LatLng(a[0], a[1], a[2]); } - return new L.LatLng(a[0], a[1]); + return null; } if (a === undefined || a === null) { return a;