L.latLng factory not to throw error on empty array parameter

This commit is contained in:
Sergey Kruk 2014-12-05 20:25:02 +03:00
parent 7cafaa6346
commit c8e5d7c61b
2 changed files with 5 additions and 2 deletions

View File

@ -80,7 +80,10 @@ describe('LatLng', function () {
}); });
it('accepts an array of coordinates', 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])).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 () { it('passes null or undefined as is', function () {

View File

@ -61,10 +61,10 @@ L.latLng = function (a, b, c) {
return a; return a;
} }
if (L.Util.isArray(a) && typeof a[0] !== 'object') { 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], a[2]);
} }
return new L.LatLng(a[0], a[1]); return null;
} }
if (a === undefined || a === null) { if (a === undefined || a === null) {
return a; return a;