Skip to content

Commit 1880f69

Browse files
committed
Invoke setter with default when prop missing
1 parent 948fd2e commit 1880f69

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',
@@ -464,10 +474,13 @@ export default class Mapbox {
464474
const map = this._map;
465475
let changed = false;
466476
for (const propName of settingNames) {
467-
if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) {
477+
const propPresent = propName in nextProps || propName in currProps;
478+
479+
if (propPresent && !deepEqual(nextProps[propName], currProps[propName])) {
468480
changed = true;
481+
const nextValue = propName in nextProps ? nextProps[propName] : DEFAULT_SETTINGS[propName];
469482
const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`];
470-
setter?.call(map, nextProps[propName]);
483+
setter?.call(map, nextValue);
471484
}
472485
}
473486
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)