-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Invoke setter with default when prop missing #2560
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,6 +80,16 @@ | |
|
|
||
| const DEFAULT_STYLE = {version: 8, sources: {}, layers: []} as StyleSpecification; | ||
|
|
||
| const DEFAULT_SETTINGS = { | ||
| minZoom: 0, | ||
| maxZoom: 22, | ||
| minPitch: 0, | ||
| maxPitch: 85, | ||
| maxBounds: [-180, -85.051129, 180, 85.051129], | ||
| projection: 'mercator', | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is projection in maplibre? Might want to cross reference https://www.maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/ There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a different API I think. That's the JSON style spec whereas this is the |
||
| renderWorldCopies: true | ||
| }; | ||
|
|
||
| const pointerEvents = { | ||
| mousedown: 'onMouseDown', | ||
| mouseup: 'onMouseUp', | ||
|
|
@@ -249,7 +259,7 @@ | |
| if (map.isStyleLoaded()) { | ||
| map.fire('load'); | ||
| } else { | ||
| map.once('style.load', () => map.fire('load')); | ||
|
Check warning on line 262 in modules/react-maplibre/src/maplibre/maplibre.ts
|
||
| } | ||
|
|
||
| // Force reload | ||
|
|
@@ -413,10 +423,13 @@ | |
| const map = this._map; | ||
| let changed = false; | ||
| for (const propName of settingNames) { | ||
| if (propName in nextProps && !deepEqual(nextProps[propName], currProps[propName])) { | ||
| const propPresent = propName in nextProps || propName in currProps; | ||
|
|
||
| if (propPresent && !deepEqual(nextProps[propName], currProps[propName])) { | ||
| changed = true; | ||
| const nextValue = propName in nextProps ? nextProps[propName] : DEFAULT_SETTINGS[propName]; | ||
| const setter = map[`set${propName[0].toUpperCase()}${propName.slice(1)}`]; | ||
| setter?.call(map, nextProps[propName]); | ||
| setter?.call(map, nextValue); | ||
| } | ||
| } | ||
| return changed; | ||
|
|
@@ -445,7 +458,7 @@ | |
| * 1. They can not be applied right away. Certain conditions (style loaded, source loaded, etc.) must be met | ||
| * 2. They can be overwritten by mapStyle | ||
| */ | ||
| private _updateStyleComponents({light, projection, sky, terrain}: MaplibreProps): void { | ||
| const map = this._map; | ||
| const currProps = this._styleComponents; | ||
| // We can safely manipulate map style once it's loaded | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Where do these defaults come from, and should they be applied anywhere else to keep systems in sync?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked them up in the docs, they seem pretty reasonable. Only
maxPitchis a bit weird, in that it depends on the library version. It would be nice if they could be extracted from the map lib at runtime, but I didn't see a way to do that