Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
Pessimistress authored Jul 5, 2024
2 parents 9ce9a3c + 2c369d0 commit 3af6098
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
2 changes: 1 addition & 1 deletion docs/api-reference/map.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# default (Map)

React component that wraps the base library's `Map` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)). This is also the default export from react-map-gl.
React component that wraps the base library's `Map` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)). This is also the default export from react-map-gl.

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
Expand Down
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 3af6098

Please sign in to comment.