Skip to content

Commit

Permalink
fix: change transformation setters call order (#2391)
Browse files Browse the repository at this point in the history
  • Loading branch information
oxidase authored Jul 5, 2024
1 parent b47bb12 commit 2c369d0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,6 @@ export function applyViewStateToTransform(tr: Transform, props: MapboxProps): bo
const v: Partial<ViewState> = props.viewState || props;
let changed = false;

if ('longitude' in v && 'latitude' in v) {
const center = tr.center;
// @ts-ignore
tr.center = new center.constructor(v.longitude, v.latitude);
changed = changed || center !== tr.center;
}
if ('zoom' in v) {
const zoom = tr.zoom;
tr.zoom = v.zoom;
Expand All @@ -82,5 +76,11 @@ export function applyViewStateToTransform(tr: Transform, props: MapboxProps): bo
changed = true;
tr.padding = v.padding;
}
if ('longitude' in v && 'latitude' in v) {
const center = tr.center;
// @ts-ignore
tr.center = new center.constructor(v.longitude, v.latitude);
changed = changed || center !== tr.center;
}
return changed;
}
6 changes: 6 additions & 0 deletions test/src/utils/transform.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,5 +90,11 @@ test('applyViewStateToTransform', t => {
changed = applyViewStateToTransform(tr, {viewState: {pitch: 30}});
t.notOk(changed, 'nothing changed');

applyViewStateToTransform(tr, {longitude: 0, latitude: 0, zoom: 0});
changed = applyViewStateToTransform(tr, {longitude: 12, latitude: 34, zoom: 15});
t.ok(changed, 'center and zoom changed');
t.equal(tr.zoom, 15, 'zoom is correct');
t.equal(tr.center.lat, 34, 'center latitude is correct');

t.end();
});

0 comments on commit 2c369d0

Please sign in to comment.