diff --git a/src/geo/lng_lat.js b/src/geo/lng_lat.js index f6781eaae3a..f53194e4762 100644 --- a/src/geo/lng_lat.js +++ b/src/geo/lng_lat.js @@ -107,7 +107,7 @@ class LngLat { if (input instanceof LngLat) { return input; } - if (Array.isArray(input) && input.length === 2) { + if (Array.isArray(input) && (input.length === 2 || input.length === 3)) { return new LngLat(Number(input[0]), Number(input[1])); } if (!Array.isArray(input) && typeof input === 'object' && input !== null) { diff --git a/test/unit/geo/lng_lat.test.js b/test/unit/geo/lng_lat.test.js index d13c3db6291..3f96b6c725e 100644 --- a/test/unit/geo/lng_lat.test.js +++ b/test/unit/geo/lng_lat.test.js @@ -23,8 +23,13 @@ test('LngLat', (t) => { t.test('#convert', (t) => { t.ok(LngLat.convert([0, 10]) instanceof LngLat, 'convert creates a LngLat instance'); + t.ok(LngLat.convert([0, 10, 0]) instanceof LngLat, 'convert creates a LngLat instance (Elevation)'); + t.throw(() => { + LngLat.convert([0, 10, 0, 5]); + }, "LngLat must not accept an array size bigger than 3'", 'detects and throws on invalid input'); t.ok(LngLat.convert({lng: 0, lat: 10}) instanceof LngLat, 'convert creates a LngLat instance'); t.ok(LngLat.convert({lng: 0, lat: 0}) instanceof LngLat, 'convert creates a LngLat instance'); + t.ok(LngLat.convert({lng: 0, lat: 0, elev: 0}) instanceof LngLat, 'convert creates a LngLat instance'); t.ok(LngLat.convert(new LngLat(0, 0)) instanceof LngLat, 'convert creates a LngLat instance'); t.throws(() => { LngLat.convert(0, 10);