Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions docs/api-reference/maplibre/map.md
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,25 @@ Default: `null`

The padding in pixels around the viewport.

#### `minZoom`: number {#minzoom}
#### `minZoom`: number | null {#minzoom}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Are those not number/undefined/null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes — optional React props also include undefined. Updated the docs to show the full type.


Default: `0`

The minimum zoom level of the map (0-24).

#### `maxZoom`: number {#maxzoom}
#### `maxZoom`: number | null {#maxzoom}

Default: `22`

The maximum zoom level of the map (0-24).

#### `minPitch`: number {#minpitch}
#### `minPitch`: number | null {#minpitch}

Default: `0`

The minimum pitch of the map (0-85).

#### `maxPitch`: number {#maxpitch}
#### `maxPitch`: number | null {#maxpitch}

Default: `60`

Expand Down
14 changes: 7 additions & 7 deletions modules/react-maplibre/src/maplibre/maplibre.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import type {
TerrainSpecification,
ProjectionSpecification
} from '../types/style-spec';
import type {MapInstance} from '../types/lib';
import type {MapInstance, MapOptions} from '../types/lib';
import type {CameraUpdateTransformFunction, MapEventType} from 'maplibre-gl';
import type {
MapCallbacks,
Expand Down Expand Up @@ -87,27 +87,27 @@ export type MaplibreProps = Partial<ViewState> &
/** Minimum zoom available to the map.
* @default 0
*/
minZoom?: number;
minZoom?: MapOptions['minZoom'];
/** Maximum zoom available to the map.
* @default 22
*/
maxZoom?: number;
maxZoom?: MapOptions['maxZoom'];
/** Minimum pitch available to the map.
* @default 0
*/
minPitch?: number;
minPitch?: MapOptions['minPitch'];
/** Maximum pitch available to the map.
* @default 85
*/
maxPitch?: number;
maxPitch?: MapOptions['maxPitch'];
/** Bounds of the map.
* @default [-180, -85.051129, 180, 85.051129]
*/
maxBounds?: [number, number, number, number];
maxBounds?: MapOptions['maxBounds'];
/** Whether to render copies of the world or not.
* @default true
*/
renderWorldCopies?: boolean;
renderWorldCopies?: MapOptions['renderWorldCopies'];
};

const DEFAULT_STYLE = {version: 8, sources: {}, layers: []} as StyleSpecification;
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@
"playwright:install": "playwright install chromium",
"publish-beta": "ocular-publish version-only-beta",
"publish-prod": "ocular-publish version-only-prod",
"test": "ocular-test node headless",
"test": "npm run test-types && ocular-test node headless",
"test-browser": "ocular-test browser",
"test-fast": "ocular-build && ocular-test node",
"test-headless": "ocular-test headless",
"test-node": "ocular-test node",
"test-node": "npm run test-types && ocular-test node",
"test-types": "tsc --build modules/main/tsconfig.json && tsc --project test/types/tsconfig.json",
"metrics": "ocular-metrics",
"update-release-branch": "scripts/update-release-branch.sh"
},
Expand All @@ -42,6 +43,7 @@
"pre-commit": "^1.2.2",
"react": "^18.0.0",
"react-dom": "^18.0.0",
"typescript": "^6.0.3",
"vitest": "^4.0.18"
},
"pre-commit": [
Expand Down
25 changes: 25 additions & 0 deletions test/types/maplibre-map-props.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import type {ComponentProps} from 'react';
import Map from 'react-map-gl/maplibre';
import type {MapOptions} from 'maplibre-gl';

type MapProps = ComponentProps<typeof Map>;

type MutableMapOptionKeys =
| 'minZoom'
| 'maxZoom'
| 'minPitch'
| 'maxPitch'
| 'maxBounds'
| 'renderWorldCopies';

declare const mapOptions: Pick<MapOptions, MutableMapOptionKeys>;
const mapProps: Pick<MapProps, MutableMapOptionKeys> = mapOptions;
const nullableCameraConstraints: Pick<MapProps, 'minZoom' | 'maxZoom' | 'minPitch' | 'maxPitch'> = {
minZoom: null,
maxZoom: null,
minPitch: null,
maxPitch: null
};

void mapProps;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this something this project does? Also the declare above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You’re right. This pattern is not established in the repository, so I removed it.

void nullableCameraConstraints;
12 changes: 12 additions & 0 deletions test/types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"extends": "../../tsconfig.json",

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Personally I don't understand this part. Like the whole "consumer test".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Agreed. I removed the standalone consumer test. The types now derive directly from MapOptions, with runtime coverage in the existing test suites.

"compilerOptions": {
"allowJs": false,
"noEmit": true,
"strictNullChecks": true,
"paths": {
"react-map-gl/maplibre": ["../../modules/main/dist/maplibre.d.ts"]
}
},
"include": ["maplibre-map-props.ts"]
}
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6444,6 +6444,7 @@ __metadata:
pre-commit: "npm:^1.2.2"
react: "npm:^18.0.0"
react-dom: "npm:^18.0.0"
typescript: "npm:^6.0.3"
vitest: "npm:^4.0.18"
dependenciesMeta:
esbuild:
Expand Down