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 LngLatBounds.extend() with literal LngLat object #12605

Merged
merged 1 commit into from
Mar 7, 2023
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_bounds.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ class LngLatBounds {
const lngLatObj = ((obj: any): LngLatLike);
return this.extend(LngLat.convert(lngLatObj));
}
} else if (typeof obj === 'object' && obj !== null && obj.hasOwnProperty("lat") && obj.hasOwnProperty("lon")) {
} else if (typeof obj === 'object' && obj !== null && obj.hasOwnProperty("lat") && (obj.hasOwnProperty("lon") || obj.hasOwnProperty("lng"))) {
return this.extend(LngLat.convert(obj));
} else {
return this;
Expand Down
14 changes: 14 additions & 0 deletions test/unit/geo/lng_lat_bounds.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,20 @@ test('LngLatBounds', (t) => {
t.end();
});

t.test('#extend with literal object LngLat', (t) => {
const bounds1 = new LngLatBounds([0, 0], [10, 10]);
const bounds2 = {lng: -10, lat: -10};

bounds1.extend(bounds2);

t.equal(bounds1.getSouth(), -10);
t.equal(bounds1.getWest(), -10);
t.equal(bounds1.getNorth(), 10);
t.equal(bounds1.getEast(), 10);

t.end();
});

t.test('#extend with null', (t) => {
const bounds = new LngLatBounds([0, 0], [10, 10]);

Expand Down