Skip to content

Commit e7d2ee7

Browse files
authored
Invoke setter with default when prop missing (#2560)
1 parent 465bd4b commit e7d2ee7

File tree

2 files changed

+30
-4
lines changed

2 files changed

+30
-4
lines changed

modules/react-mapbox/src/mapbox/mapbox.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ export type MapboxProps = Partial<ViewState> &
8585

8686
const DEFAULT_STYLE = {version: 8, sources: {}, layers: []} as StyleSpecification;
8787

88+
const DEFAULT_SETTINGS = {
89+
minZoom: 0,
90+
maxZoom: 22,
91+
minPitch: 0,
92+
maxPitch: 85,
93+
maxBounds: [-180, -85.051129, 180, 85.051129],
94+
projection: 'mercator',
95+
renderWorldCopies: true
96+
};
97+
8898
const pointerEvents = {
8999
mousedown: 'onMouseDown',
90100
mouseup: 'onMouseUp',
@@ -461,10 +471,13 @@ export default class Mapbox {
461471
const map = this._map;
462472
let changed = false;
463473
for (const propName of settingNames) {
464-
if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) {
474+
const propPresent = propName in nextProps || propName in currProps;
475+
476+
if (propPresent && !deepEqual(nextProps[propName], currProps[propName])) {
465477
changed = true;
478+
const nextValue = propName in nextProps ? nextProps[propName] : DEFAULT_SETTINGS[propName];
466479
const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`];
467-
setter?.call(map, nextProps[propName]);
480+
setter?.call(map, nextValue);
468481
}
469482
}
470483
return changed;

modules/react-maplibre/src/maplibre/maplibre.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,16 @@ export type MaplibreProps = Partial<ViewState> &
8080

8181
const DEFAULT_STYLE = {version: 8, sources: {}, layers: []} as StyleSpecification;
8282

83+
const DEFAULT_SETTINGS = {
84+
minZoom: 0,
85+
maxZoom: 22,
86+
minPitch: 0,
87+
maxPitch: 85,
88+
maxBounds: [-180, -85.051129, 180, 85.051129],
89+
projection: 'mercator',
90+
renderWorldCopies: true
91+
};
92+
8393
const pointerEvents = {
8494
mousedown: 'onMouseDown',
8595
mouseup: 'onMouseUp',
@@ -413,10 +423,13 @@ export default class Maplibre {
413423
const map = this._map;
414424
let changed = false;
415425
for (const propName of settingNames) {
416-
if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) {
426+
const propPresent = propName in nextProps || propName in currProps;
427+
428+
if (propPresent && !deepEqual(nextProps[propName], currProps[propName])) {
417429
changed = true;
430+
const nextValue = propName in nextProps ? nextProps[propName] : DEFAULT_SETTINGS[propName];
418431
const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`];
419-
setter?.call(map, nextProps[propName]);
432+
setter?.call(map, nextValue);
420433
}
421434
}
422435
return changed;

0 commit comments

Comments
 (0)