Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions modules/react-mapbox/src/mapbox/mapbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@

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

const DEFAULT_SETTINGS = {
Copy link
Contributor

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?

Copy link
Author

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 maxPitch is 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

minZoom: 0,
maxZoom: 22,
minPitch: 0,
maxPitch: 85,
maxBounds: [-180, -85.051129, 180, 85.051129],
projection: 'mercator',
renderWorldCopies: true
};

const pointerEvents = {
mousedown: 'onMouseDown',
mouseup: 'onMouseUp',
Expand Down Expand Up @@ -464,10 +474,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;
Expand Down Expand Up @@ -502,7 +515,7 @@
@param {object} currProps
@returns {bool} true if anything is changed
*/
_updateStyleComponents(nextProps: MapboxProps, currProps: MapboxProps): boolean {

Check warning on line 518 in modules/react-mapbox/src/mapbox/mapbox.ts

View workflow job for this annotation

GitHub Actions / test-node

Method '_updateStyleComponents' has a complexity of 13. Maximum allowed is 11
const map = this._map;
let changed = false;
if (map.isStyleLoaded()) {
Expand Down
17 changes: 15 additions & 2 deletions modules/react-maplibre/src/maplibre/maplibre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Copy link
Contributor

Choose a reason for hiding this comment

The 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/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The 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 MapOptions for the js library

renderWorldCopies: true
};

const pointerEvents = {
mousedown: 'onMouseDown',
mouseup: 'onMouseUp',
Expand Down Expand Up @@ -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

View workflow job for this annotation

GitHub Actions / test-node

Promises must be awaited, end with a call to .catch, end with a call to .then with a rejection handler or be explicitly marked as ignored with the `void` operator
}

// Force reload
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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 {

Check warning on line 461 in modules/react-maplibre/src/maplibre/maplibre.ts

View workflow job for this annotation

GitHub Actions / test-node

Method '_updateStyleComponents' has a complexity of 14. Maximum allowed is 11
const map = this._map;
const currProps = this._styleComponents;
// We can safely manipulate map style once it's loaded
Expand Down
Loading