Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix geojson Position element issue (3rd element) #5608

Merged
merged 1 commit into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/geo/lng_lat.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
5 changes: 5 additions & 0 deletions test/unit/geo/lng_lat.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down