diff --git a/.github/SECURITY.md b/.github/SECURITY.md new file mode 100644 index 000000000..1885df604 --- /dev/null +++ b/.github/SECURITY.md @@ -0,0 +1,13 @@ +# Security Policy + +## Supported Versions + +Security updates are applied only to the latest release. + +## Reporting a Vulnerability + +If you have discovered a security vulnerability in this project, please report it privately. **Do not disclose it as a public issue.** This gives us time to work with you to fix the issue before public exposure, reducing the chance that the exploit will be used before a patch is released. + +Please disclose it at [security advisory](https://github.com/visgl/react-map-gl/security/advisories/new). + +This project is maintained by a team of volunteers on a reasonable-effort basis. As such, please give us at least 90 days to work on a fix before public exposure. diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c639c86a2..6c149c520 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,23 +7,23 @@ on: jobs: release-notes: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 if: github.repository_owner == 'visgl' + permissions: + contents: write + env: - ADMIN_TOKEN: ${{ secrets.ADMIN_TOKEN }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} steps: - - uses: actions/checkout@v2.1.1 - - - name: Get git tags (https://github.com/actions/checkout/issues/206) - run: git fetch --tags -f + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 with: - node-version: '16.x' + node-version: '18.x' - name: Publish release run: | @@ -33,4 +33,4 @@ jobs: -H "Accept: application/vnd.github.v3+json" \ https://api.github.com/repos/visgl/react-map-gl/releases \ -d "${body}" \ - -H "Authorization: token ${ADMIN_TOKEN}" + -H "Authorization: token ${GITHUB_TOKEN}" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 548694819..535715695 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -9,28 +9,27 @@ on: jobs: test-node: - runs-on: ubuntu-latest - - env: - VITE_MAPBOX_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN_CI }} + runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v2.1.1 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 - name: Use Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 with: - node-version: '16.x' + node-version: '18.x' - name: Install dependencies run: | yarn bootstrap - name: Run tests + env: + VITE_MAPBOX_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN_CI }} run: | yarn test ci - name: Coveralls - uses: coverallsapp/github-action@master + uses: coverallsapp/github-action@09b709cf6a16e30b0808ba050c7a6e8a5ef13f8d # v1.2.5 with: github-token: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/website.yml b/.github/workflows/website.yml index dd792c6f7..b4bd4c01c 100644 --- a/.github/workflows/website.yml +++ b/.github/workflows/website.yml @@ -6,42 +6,51 @@ on: - '*-release' jobs: - publish-website: - runs-on: ubuntu-latest + check_branch: + runs-on: ubuntu-22.04 + outputs: + should_deploy: ${{ endsWith(github.ref, steps.get_version.outputs.latest) }} - if: github.repository_owner == 'visgl' + steps: + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + + - name: Get version + id: get_version + run: | + LATEST=$(npm show react-map-gl version | grep -o -E "^[0-9]+\.[0-9]+") + echo "latest=${LATEST}-release" >> "$GITHUB_OUTPUT" + + deploy: + runs-on: ubuntu-22.04 + needs: check_branch + + permissions: + contents: write - env: - MapboxAccessToken: ${{ secrets.MAPBOX_ACCESS_TOKEN }} + if: ${{ github.repository_owner == 'visgl' && needs.check_branch.outputs.should_deploy }} steps: - - uses: actions/checkout@v2.1.1 + - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4.1.1 + with: + token: ${{ secrets.WEBSITE_DEPLOY_TOKEN }} - name: Use Node.js - uses: actions/setup-node@v1 + uses: actions/setup-node@8f152de45cc393bb48ce5d89d36b731f54556e65 # v4.0.0 with: - node-version: '16.x' + node-version: '18.x' - - name: Get version - id: get-version - run: LATEST=$(npm show react-map-gl version | grep -o -E "^[0-9]+\.[0-9]+") && echo "::set-output name=latest::/${LATEST}-release" - - - name: Check version - if: ${{ !endsWith(github.ref, steps.get-version.outputs.latest) }} + - name: Install dependencies run: | - echo "Website is only published from the latest release branch" + yarn bootstrap + (cd website && yarn) - name: Build website - if: ${{ endsWith(github.ref, steps.get-version.outputs.latest) }} - run: | - yarn bootstrap - cd website - yarn - yarn build + env: + MapboxAccessToken: ${{ secrets.MAPBOX_ACCESS_TOKEN }} + run: (cd website && yarn build) - name: Deploy - if: ${{ endsWith(github.ref, steps.get-version.outputs.latest) }} - uses: JamesIves/github-pages-deploy-action@3.7.1 + uses: JamesIves/github-pages-deploy-action@132898c54c57c7cc6b80eb3a89968de8fc283505 # 3.7.1 with: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} BRANCH: gh-pages diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 000000000..446285711 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,3 @@ +# Code of Conduct + +react-map-gl is an [OpenJS Foundation](https://openjsf.org/) project. Please be mindful of and adhere to the OpenJS Foundation's [Code of Conduct](https://github.com/openjs-foundation/cross-project-council/blob/main/CODE_OF_CONDUCT.md) when contributing to react-map-gl. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d020695b8..9197da871 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -68,7 +68,7 @@ react-map-gl follows the [Semantic Versioning](https://semver.org/) guidelines. ## Community Governance -vis.gl is part of the [Urban Computing Foundation](https://uc.foundation/). See the organization's [Technical Charter](https://github.com/visgl/tsc/blob/master/Technical%20Charter.md). +vis.gl is part of the [OpenJS Foundation](https://openjsf.org/). See the organization's [Technical Charter](https://github.com/visgl/tsc/blob/master/Technical%20Charter.md). ### Technical Steering Committee @@ -84,8 +84,4 @@ Maintainers of react-map-gl have commit access to this GitHub repository, and ta If you are interested in becoming a maintainer, read the [governance guidelines](https://github.com/visgl/tsc/blob/master/governance.md). The vis.gl TSC meets monthly and publishes meeting notes via a [mailing list](https://lists.uc.foundation/g/visgl). -This mailing list can also be utilized to reach out to the TSC. - -## Code of Conduct - -Please be mindful of and adhere to the Linux Foundation's [Code of Conduct](https://lfprojects.org/policies/code-of-conduct/) when contributing to react-map-gl. +This mailing list can also be utilized to reach out to the TSC. \ No newline at end of file diff --git a/LICENSE b/LICENSE index 028aef4df..155928579 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2020 Urban Computing Foundation +Copyright Vis.gl contributors. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index a00776b8d..6584bb63c 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@

react-map-gl | Docs

-`react-map-gl` is a suite of [React](http://facebook.github.io/react/) components designed to provide a React API for [mapbox-gl](https://github.com/mapbox/mapbox-gl-js) or [maplibre-gl](https://maplibre.org/maplibre-gl-js-docs/api/). More information in the online documentation. +`react-map-gl` is a suite of [React](http://facebook.github.io/react/) components designed to provide a React API for [mapbox-gl](https://github.com/mapbox/mapbox-gl-js) or [maplibre-gl](https://maplibre.org/maplibre-gl-js/docs/). More information in the online documentation. See our [Design Philosophy](docs/README.md#design-philosophy). @@ -63,7 +63,7 @@ See [contribution guide](/CONTRIBUTING.md). ### Attributions -react-map-gl is part of vis.gl, an [Urban Computing Foundation](https://uc.foundation) project. +react-map-gl is part of vis.gl, an [OpenJS Foundation](https://openjsf.org) project. Development is also supported by diff --git a/docs/README.md b/docs/README.md index 29807687e..5ff4db353 100644 --- a/docs/README.md +++ b/docs/README.md @@ -16,11 +16,11 @@

react-map-gl is a suite of [React](http://facebook.github.io/react/) components for -[mapbox-gl](https://github.com/mapbox/mapbox-gl-js), [maplibre-gl](https://maplibre.org/maplibre-gl-js-docs/api/) or compatible libraries. +[mapbox-gl](https://github.com/mapbox/mapbox-gl-js), [maplibre-gl](https://maplibre.org/maplibre-gl-js/docs/) or compatible libraries. | Library | Description | | --- | --- | -| [MapLibre](https://github.com/MapLibre/maplibre-gl-js) | An open fork of mapbox-gl v1, that can be used without a mapbox token. | +| [MapLibre GL JS](https://github.com/MapLibre/maplibre-gl-js) | An open fork of mapbox-gl v1, that can be used without a mapbox token. | | [Mapbox GL JS v1](https://github.com/mapbox/mapbox-gl-js) | The previous version of mapbox GL JS. This version is free open source and can be used with non-mapbox basemaps without a mapbox token. | | [Mapbox GL JS v2](https://github.com/mapbox/mapbox-gl-js) | The latest version of Mapbox GL JS. Note that version 2 is not free open source, and a mapbox token is required and billable events are generated even if you do not use mapbox hosted basemaps. | | Other mapbox-gl forks | It may be possible to use react-map-gl with other mapbox forks, but this is not a supported use case. Minor PRs to enable other forks to be used may be accepted. | diff --git a/docs/api-reference/attribution-control.md b/docs/api-reference/attribution-control.md index 56c14cb8b..78789367d 100644 --- a/docs/api-reference/attribution-control.md +++ b/docs/api-reference/attribution-control.md @@ -1,6 +1,6 @@ # AttributionControl -React component that wraps the base library's `AttributionControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#attributioncontrol)). +React component that wraps the base library's `AttributionControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/AttributionControl/)). import Tabs from '@theme/Tabs'; @@ -68,7 +68,7 @@ CSS style override that applies to the control's container. The properties in this section are not reactive. They are only used when the component first mounts. -Any options supported by the `AttributionControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#attributioncontrol)), such as +Any options supported by the `AttributionControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/AttributionControl/)), such as - `compact` - `customAttribution` diff --git a/docs/api-reference/fullscreen-control.md b/docs/api-reference/fullscreen-control.md index a40fe3b74..ae3257115 100644 --- a/docs/api-reference/fullscreen-control.md +++ b/docs/api-reference/fullscreen-control.md @@ -1,6 +1,6 @@ # FullscreenControl -React component that wraps the base library's `FullscreenControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#fullscreencontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#fullscreencontrol)). +React component that wraps the base library's `FullscreenControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#fullscreencontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/FullscreenControl/)). import Tabs from '@theme/Tabs'; @@ -56,7 +56,7 @@ function App() { ### Reactive Properties -#### `style`: CSSProperties {#style} +#### `style`: CSSProperties {#style} CSS style override that applies to the control's container. @@ -65,11 +65,11 @@ CSS style override that applies to the control's container. The properties in this section are not reactive. They are only used when the component first mounts. -#### `containerId`: string {#containerid} +#### `containerId`: string {#containerid} Id of the DOM element which should be made full screen. By default, the map container element will be made full screen. -#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position} +#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position} Default: `'top-right'` @@ -78,4 +78,4 @@ Placement of the control relative to the map. ## Source -[fullscreen-control.ts](https://github.com/visgl/react-map-gl/tree/7.0-release/src/components/fullscreen-control.ts) +[fullscreen-control.ts](https://github.com/visgl/react-map-gl/tree/7.1-release/src/components/fullscreen-control.tsx) diff --git a/docs/api-reference/geolocate-control.md b/docs/api-reference/geolocate-control.md index 972413489..e605d68e0 100644 --- a/docs/api-reference/geolocate-control.md +++ b/docs/api-reference/geolocate-control.md @@ -1,6 +1,6 @@ # GeolocateControl -React component that wraps the base library's `GeolocateControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#geolocatecontrol)). +React component that wraps the base library's `GeolocateControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/GeolocateControl/)). import Tabs from '@theme/Tabs'; @@ -88,7 +88,7 @@ Called when the GeolocateControl changes to the background state. The properties in this section are not reactive. They are only used when the component first mounts. -Any options supported by the `GeolocateControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#geolocatecontrol)), such as +Any options supported by the `GeolocateControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/GeolocateControl/)), such as - `positionOptions` - `fitBoundsOptions` diff --git a/docs/api-reference/map.md b/docs/api-reference/map.md index 7f1b5c20a..01535d680 100644 --- a/docs/api-reference/map.md +++ b/docs/api-reference/map.md @@ -1,6 +1,6 @@ # default (Map) -React component that wraps the base library's `Map` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)). This is also the default export from react-map-gl. +React component that wraps the base library's `Map` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)). This is also the default export from react-map-gl. import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; @@ -53,10 +53,9 @@ function App() { - ## Properties -Aside from the props listed below, the `Map` component supports all parameters of the `Map` class constructor ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)). Beware that this is not an exhaustive list of all props. Different base map libraries may offer different options and default values. When in doubt, refer to your base map library's documentation. +Aside from the props listed below, the `Map` component supports all parameters of the `Map` class constructor ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/)). Beware that this is not an exhaustive list of all props. Different base map libraries may offer different options and default values. When in doubt, refer to your base map library's documentation. ### Layout options @@ -64,6 +63,10 @@ Aside from the props listed below, the `Map` component supports all parameters o Map container id. +Required when [`MapProvider`](./map-provider.md)s are used. Used to reference the map with [`useMap`](./use-map.md). + +Make sure to pick a name that has no conflict with other imports (there are no checks or errors in this case). + #### `style`: CSSProperties {#style} Default: `{position: 'relative', width: '100%', height: '100%'}` @@ -116,7 +119,6 @@ Enable diffing when `mapStyle` changes. If `false`, force a 'full' update, remov Terrain property of the style. Must conform to the [Terrain Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/terrain/). If `undefined` is provided, removes terrain from the map. - ### Camera options #### `initialViewState`: object {#initialviewstate} @@ -198,49 +200,49 @@ If set, the map is constrained to the given bounds. Default: `true` If `true`, the "box zoom" interaction is enabled. See `BoxZoomHandler` -([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#boxzoomhandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.BoxZoomHandler/)) +([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#boxzoomhandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/BoxZoomHandler/)) #### `doubleClickZoom`: boolean {#doubleclickzoom} Default: `true` -If `true`, the "double click to zoom" interaction is enabled. See `DoubleClickZoomHandler` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#doubleclickzoomhandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.DoubleClickZoomHandler/)). +If `true`, the "double click to zoom" interaction is enabled. See `DoubleClickZoomHandler` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#doubleclickzoomhandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/DoubleClickZoomHandler/)). #### `dragRotate`: boolean {#dragrotate} Default: `true` -If `true`, the "drag to rotate" interaction is enabled. See `DragRotateHandler` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#dragrotatehandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.DragRotateHandler/)). +If `true`, the "drag to rotate" interaction is enabled. See `DragRotateHandler` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#dragrotatehandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/DragRotateHandler/)). #### `dragPan`: boolean | Object {#dragpan} Default: `true` -If `true`, the "drag to pan" interaction is enabled. Optionally accpt an object value that is the options to `DragPanHandler.enable` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#dragpanhandler#enable) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.DragPanHandler/#enable)). +If `true`, the "drag to pan" interaction is enabled. Optionally accpt an object value that is the options to `DragPanHandler.enable` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#dragpanhandler#enable) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/DragPanHandler/#enable)). #### `keyboard`: boolean {#keyboard} Default: `true` -If `true`, keyboard shortcuts are enabled. See `KeyboardHandler` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#keyboardhandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.KeyboardHandler/)). +If `true`, keyboard shortcuts are enabled. See `KeyboardHandler` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#keyboardhandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/KeyboardHandler/)). #### `scrollZoom`: boolean | Object {#scrollzoom} Default: `true` -If `true`, the "scroll to zoom" interaction is enabled. Optionally accpt an object value that is the options to `ScrollZoomHandler.enable` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#scrollzoomhandler#enable) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.ScrollZoomHandler/#enable)) +If `true`, the "scroll to zoom" interaction is enabled. Optionally accpt an object value that is the options to `ScrollZoomHandler.enable` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#scrollzoomhandler#enable) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/ScrollZoomHandler/#enable)) #### `touchPitch`: boolean | Object {#touchpitch} Default: `true` -If `true`, the "drag to pitch" interaction is enabled. Optionally accpt an object value that is the options to `TouchPitchHandler.enable`([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#touchpitchhandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.TwoFingersTouchPitchHandler/#enable)). +If `true`, the "drag to pitch" interaction is enabled. Optionally accpt an object value that is the options to `TouchPitchHandler.enable`([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#touchpitchhandler) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/TwoFingersTouchPitchHandler/#enable)). #### `touchZoomRotate`: boolean | Object {#touchzoomrotate} Default: `true` -If `true`, the "pinch to rotate and zoom" interaction is enabled. Optionally accpt an object value that is the options to `TouchZoomRotateHandler.enable` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#touchzoomrotatehandler#enable) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.TwoFingersTouchZoomHandler/#enable)). +If `true`, the "pinch to rotate and zoom" interaction is enabled. Optionally accpt an object value that is the options to `TouchZoomRotateHandler.enable` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/handlers/#touchzoomrotatehandler#enable) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/TwoFingersTouchZoomRotateHandler/#enable)). #### `interactiveLayerIds`: string[] {#interactivelayerids} @@ -461,13 +463,14 @@ Called when one of the map's sources loads or changes, including if a tile belon ### Other options -The following props, along with any options of the `Map` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) not listed above, can be specified to construct the underlying `Map` instance. +The following props, along with any options of the `Map` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/)) not listed above, can be specified to construct the underlying `Map` instance. Note: props in this section are not reactive. They are only used once when the Map instance is constructed. #### `mapLib`: any {#maplib} Default: + - `import('mapbox-gl')` if imported from `react-map-gl` - `import('maplibre-gl')` if imported from `react-map-gl/maplibre` @@ -499,7 +502,7 @@ function App() { Or to load a pre-bundled version of the library: ```html title="index.html" - + ``` ```tsx title="app.tsx" @@ -511,7 +514,6 @@ function App() { } ``` - #### `mapboxAccessToken`: string {#mapboxaccesstoken} Token used to access the Mapbox data service. See [about map tokens](../get-started/mapbox-tokens.md). @@ -561,8 +563,6 @@ The number of web workers instantiated on a page with mapbox-gl maps. Provides an interface for loading mapbox-gl's WebWorker bundle from a self-hosted URL. This is useful if your site needs to operate in a strict CSP (Content Security Policy) environment wherein you are not allowed to load JavaScript code from a Blob URL, which is default behavior. - - ## Methods Imperative methods are accessible via a [React ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) or the [useMap](./use-map.md) hook. @@ -577,7 +577,7 @@ import Map from 'react-map-gl'; import type {MapRef} from 'react-map-gl'; function App() { - const mapRef = useRef(); + const mapRef = useRef(null); const onMapLoad = useCallback(() => { mapRef.current.on('move', () => { @@ -592,7 +592,6 @@ function App() { - ```tsx import * as React from 'react'; import {useRef, useCallback} from 'react'; @@ -612,19 +611,16 @@ function App() { } ``` - -The [MapRef](./types.md#mapref) object exposes Map methods ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/#map-instance-members) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.Map/#methods)) that **are safe to call without breaking the React bindings**. For example, `setStyle()` is hidden from the ref object, because the style is supposed to be changed by updating the `mapStyle` prop. Calling the method directly may cause the the React prop to mismatch with the underlying state, and lead to unexpected behaviors. +The [MapRef](./types.md#mapref) object exposes Map methods ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/#map-instance-members) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#methods)) that **are safe to call without breaking the React bindings**. For example, `setStyle()` is hidden from the ref object, because the style is supposed to be changed by updating the `mapStyle` prop. Calling the method directly may cause the the React prop to mismatch with the underlying state, and lead to unexpected behaviors. You can still access the hidden members via `getMap()`: #### `getMap()` {#getmap} -Returns the native `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) instance associated with this component. - - +Returns the native `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) instance associated with this component. ## Source diff --git a/docs/api-reference/marker.md b/docs/api-reference/marker.md index 21c90a964..8d59ac79b 100644 --- a/docs/api-reference/marker.md +++ b/docs/api-reference/marker.md @@ -1,6 +1,6 @@ # Marker -React component that wraps the base library's `Marker` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#marker)). +React component that wraps the base library's `Marker` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/)). import Tabs from '@theme/Tabs'; @@ -63,27 +63,27 @@ If `Marker` is mounted with child components, then its content will be rendered ### Reactive Properties -#### `draggable`: boolean {#draggable} +#### `draggable`: boolean {#draggable} Default: `false` If `true`, the marker is able to be dragged to a new position on the map. -#### `latitude`: number {#latitude} +#### `latitude`: number {#latitude} Required. The latitude of the anchor location. -#### `longitude`: number {#longitude} +#### `longitude`: number {#longitude} Required. The longitude of the anchor location. -#### `offset`: [PointLike](./types.md#pointlike) {#offset} +#### `offset`: [PointLike](./types.md#pointlike) {#offset} Default: `null` The offset in pixels as a [PointLike](https://docs.mapbox.com/mapbox-gl-js/api/geography/#pointlike) object to apply relative to the element's center. Negatives indicate left and up. -#### `pitchAlignment`: 'map' | 'viewport' | 'auto' {#pitchalignment} +#### `pitchAlignment`: 'map' | 'viewport' | 'auto' {#pitchalignment} Default: `'auto'` @@ -91,17 +91,17 @@ Default: `'auto'` - `viewport` aligns the `Marker` to the plane of the viewport. - `auto` automatically matches the value of `rotationAlignment`. -#### `popup`: Popup | null {#popup} +#### `popup`: Popup | null {#popup} -An instance of the `Popup` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#popup)) to attach to this marker. If undefined or null, any popup set on this Marker instance is unset. +An instance of the `Popup` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Popup/)) to attach to this marker. If undefined or null, any popup set on this Marker instance is unset. -#### `rotation`: number {#rotation} +#### `rotation`: number {#rotation} Default: `0` The rotation angle of the marker in degrees, relative to its `rotationAlignment` setting. A positive value will rotate the marker clockwise. -#### `rotationAlignment`: 'map' | 'viewport' | 'auto' {#rotationalignment} +#### `rotationAlignment`: 'map' | 'viewport' | 'auto' {#rotationalignment} Default: `'auto'` @@ -109,25 +109,25 @@ Default: `'auto'` - `viewport` aligns the `Marker`'s rotation relative to the viewport, agnostic to map rotations. - `auto` is equivalent to `viewport`. -#### `style`: CSSProperties {#style} +#### `style`: CSSProperties {#style} CSS style override that applies to the marker's container. ### Callbacks -#### `onClick`: (evt: [MapEvent](./types.md#mapevent)) => void {#onclick} +#### `onClick`: (evt: [MapEvent](./types.md#mapevent)) => void {#onclick} Called when the marker is clicked on. -#### `onDragStart`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondragstart} +#### `onDragStart`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondragstart} Called when dragging starts, if `draggable` is `true`. -#### `onDrag`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondrag} +#### `onDrag`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondrag} Called while dragging, if `draggable` is `true`. -#### `onDragEnd`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondragend} +#### `onDragEnd`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondragend} Called when dragging ends, if `draggable` is `true`. @@ -136,7 +136,7 @@ Called when dragging ends, if `draggable` is `true`. The properties in this section are not reactive. They are only used when the component first mounts. -Any options supported by the `Marker` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#marker)), such as +Any options supported by the `Marker` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MarkerOptions/)), such as - `anchor` - `color` @@ -192,7 +192,7 @@ function App() { const markerRef = useRef(); const popup = useMemo(() => { - return maplibregl.Popup().setText('Hello world!'); + return new maplibregl.Popup().setText('Hello world!'); }, []) const togglePopup = useCallback(() => { diff --git a/docs/api-reference/navigation-control.md b/docs/api-reference/navigation-control.md index 9b4be43e5..630e83660 100644 --- a/docs/api-reference/navigation-control.md +++ b/docs/api-reference/navigation-control.md @@ -1,6 +1,6 @@ # NavigationControl -React component that wraps the base library's `NavigationControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#navigationcontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#navigationcontrol)). +React component that wraps the base library's `NavigationControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#navigationcontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/NavigationControl/)). import Tabs from '@theme/Tabs'; @@ -66,7 +66,7 @@ CSS style override that applies to the control's container. The properties in this section are not reactive. They are only used when the component first mounts. -Any options supported by the `NavigationControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#navigationcontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#navigationcontrol)), such as +Any options supported by the `NavigationControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#navigationcontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/NavigationControlOptions/)), such as - `showCompass` - `showZoom` diff --git a/docs/api-reference/popup.md b/docs/api-reference/popup.md index 95e1c24ef..a9e084112 100644 --- a/docs/api-reference/popup.md +++ b/docs/api-reference/popup.md @@ -1,6 +1,6 @@ # Popup -React component that wraps the base library's `Popup` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#popup)). +React component that wraps the base library's `Popup` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Popup/)). import Tabs from '@theme/Tabs'; @@ -120,7 +120,7 @@ Called when the popup is closed by the user clicking on the close button or outs The properties in this section are not reactive. They are only used when the component first mounts. -Any options supported by the `Popup` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#popup)), such as +Any options supported by the `Popup` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PopupOptions/)), such as - `closeButton` - `closeOnClick` diff --git a/docs/api-reference/scale-control.md b/docs/api-reference/scale-control.md index 20018ea5d..590d2bef2 100644 --- a/docs/api-reference/scale-control.md +++ b/docs/api-reference/scale-control.md @@ -1,6 +1,6 @@ # ScaleControl -React component that wraps the base library's `ScaleControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#scalecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/markers/#scalecontrol)). +React component that wraps the base library's `ScaleControl` class ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#scalecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/ScaleControl/)). import Tabs from '@theme/Tabs'; diff --git a/docs/api-reference/types.md b/docs/api-reference/types.md index 68250df9d..9965e8616 100644 --- a/docs/api-reference/types.md +++ b/docs/api-reference/types.md @@ -128,27 +128,27 @@ An object with the following fields: #### LngLat -A [mapboxgl.LngLat](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglat) object. +A `LngLat` object ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglat) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/LngLat/)). #### LngLatLike -A [LngLat](#lnglat) object, an array of two numbers representing longitude and latitude, or an object with `lng` and `lat` or `lon` and `lat` properties. +A [`LngLat`](#lnglat) object, an array of two numbers representing longitude and latitude, or an object with `lng` and `lat` or `lon` and `lat` properties. ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglatlike) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/LngLatLike/)) #### LngLatBounds -A [mapboxgl.LngLatBounds](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglatbounds) object. +A `LngLatBounds` object ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglatbounds) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/LngLatBounds/)). #### LngLatBoundsLike -A [LngLatBounds](#lnglatbounds) object, an array of [LngLatLike](#lnglatlike) objects in [sw, ne] order, or an array of numbers in [west, south, east, north] order. +A [`LngLatBounds`](#lnglatbounds) object, an array of [`LngLatLike`](#lnglatlike) objects in [sw, ne] order, or an array of numbers in [west, south, east, north] order. ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglatboundslike) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/LngLatBoundsLike/)) #### Point -A [mapboxgl.Point](https://github.com/mapbox/point-geometry) object. +A `Point` object. ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/geography/#point) | [Maplibre](https://github.com/mapbox/point-geometry)) #### PointLike -A [Point](#point) or an array of two numbers representing x and y screen coordinates in pixels. +A [Point](#point) or an array of two numbers representing x and y screen coordinates in pixels ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/geography/#pointlike) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PointLike/)). #### MapGeoJSONFeature @@ -171,27 +171,27 @@ An object with the following fields: ## Sources -The following are implementations of source types that could be retrieved with `Map.getSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#getsource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.Map/#getsource)). +The following are implementations of source types that could be retrieved with `Map.getSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#getsource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#getsource)). #### GeoJSONSource -A source containing GeoJSON. See `GeoJSONSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#geojsonsource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.GeoJSONSource/)). +A source containing GeoJSON. See `GeoJSONSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#geojsonsource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/GeoJSONSource/)). #### VideoSource -A source containing video. See `VideoSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#videosource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.VideoSource/)). +A source containing video. See `VideoSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#videosource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/VideoSource/)). #### ImageSource -A source containing image. See `ImageSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#imagesource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.ImageSource/)). +A source containing image. See `ImageSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#imagesource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/ImageSource/)). #### CanvasSource -A source containing the contents of an HTML canvas. See `CanvasSource`([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#canvassource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.CanvasSource/)). +A source containing the contents of an HTML canvas. See `CanvasSource`([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#canvassource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/CanvasSource/)). #### VectorTileSource -A source containing vector tiles in [Mapbox Vector Tile format](https://docs.mapbox.com/vector-tiles/reference/). See `VectorTileSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#vectortilesource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.VectorTileSource/)). +A source containing vector tiles in [Mapbox Vector Tile format](https://docs.mapbox.com/vector-tiles/reference/). See `VectorTileSource` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/sources/#vectortilesource) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/VectorTileSource/)). ## Events @@ -200,7 +200,7 @@ A source containing vector tiles in [Mapbox Vector Tile format](https://docs.map An object with the following fields: - `type`: string - Event type -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) - `originalEvent?`: [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event) #### MapLayerMouseEvent @@ -208,7 +208,7 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) - `originalEvent?`: [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent) - `point`: [Point](#point) - `lngLat`: [LngLat](#lnglat) @@ -221,7 +221,7 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) - `originalEvent?`: [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent) - `preventDefault`: () => void - `defaultPrevented`: boolean @@ -231,7 +231,7 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) - `originalEvent?`: [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent) - `point`: [Point](#point) - `lngLat`: [LngLat](#lnglat) @@ -246,7 +246,7 @@ An object with the following fields: An object with the following fields: - `type`: string - Event type -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) - `viewState`: [ViewState](#viewstate) - the next view state that the camera wants to change to based on user input or transition. #### MapBoxZoomEvent @@ -254,7 +254,7 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) - `originalEvent?`: [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent) - `boxZoomBounds`: [LngLatBounds](#lnglatbounds) @@ -263,7 +263,7 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) - `dataType`: 'style' #### MapSourceDataEvent @@ -271,7 +271,7 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) - `dataType`: 'source' - `isSourceLoaded`: boolean - `source`: string @@ -287,7 +287,7 @@ See [MapDataEvent](https://docs.mapbox.com/mapbox-gl-js/api/events/#mapdataevent An object with the following fields: - `type`: 'error' -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) - `error`: [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error) #### GeolocateEvent @@ -295,15 +295,15 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js-docs/api/map/)) -- `target`: `GeolocateControl` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.GeolocateControl/)) +- `target`: `Map` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/map/) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)) +- `target`: `GeolocateControl` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/GeolocateControl/)) #### GeolocateResultEvent An object with the following fields: - `type`: string -- `target`: `GeolocateControl` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.GeolocateControl/)) +- `target`: `GeolocateControl` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/GeolocateControl/)) - `coords`: [GeolocationCoordinates](https://developer.mozilla.org/en-US/docs/Web/API/GeolocationCoordinates) - the current location. - `timestamp`: number - the time at which the location was retrieved. @@ -312,7 +312,7 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `GeolocateControl` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.GeolocateControl/)) +- `target`: `GeolocateControl` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/GeolocateControl/)) - `code`: PERMISSION_DENIED | POSITION_UNAVAILABLE | TIMEOUT - see [GeolocationPositionError](https://developer.mozilla.org/en-US/docs/Web/API/GeolocationPositionError) - `message`: string - the details of the error. Specifications note that this is primarily intended for debugging use and not to be shown directly in a user interface. @@ -321,14 +321,14 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `Marker` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.Marker/)) +- `target`: `Marker` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/)) #### MarkerDragEvent An object with the following fields: - `type`: string -- `target`: `Marker` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.Marker/)) +- `target`: `Marker` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/)) - `lngLat`: [LngLat](#lnglat) - the new location of the marker #### PopupEvent @@ -336,4 +336,4 @@ An object with the following fields: An object with the following fields: - `type`: string -- `target`: `Popup` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/maplibregl.Popup/)) +- `target`: `Popup` ([Mapbox](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) | [Maplibre](https://maplibre.org/maplibre-gl-js/docs/API/classes/Popup/)) diff --git a/docs/api-reference/use-map.md b/docs/api-reference/use-map.md index 26fc19b40..319deacae 100644 --- a/docs/api-reference/use-map.md +++ b/docs/api-reference/use-map.md @@ -1,6 +1,8 @@ # useMap -The `useMap` hook allows a custom component to reference the [Map](./map.md) that contains it. +The `useMap` hook allows a component to reference the [Map](./map.md) that contains it. + +When used with [MapProvider](./map-provider.md), this hook can also reference maps that are rendered outside of the current map component's direct render tree. import Tabs from '@theme/Tabs'; import TabItem from '@theme/TabItem'; @@ -60,7 +62,7 @@ function NavigateButton() { -When used with the [MapProvider](./map-provider.md), this hook can also reference maps that are rendered outside of the current component's direct render tree. +When used with the [MapProvider](./map-provider.md), this hook can also reference maps that are rendered outside of the current component's direct render tree as long as both trees are part of the current ``. @@ -70,6 +72,8 @@ When used with the [MapProvider](./map-provider.md), this hook can also referenc import {MapProvider, Map, useMap} from 'react-map-gl'; function Root() { + // Note: `useMap` will not work in , only children of can use `useMap` + return ( @@ -131,7 +135,7 @@ See a full example [here](https://github.com/visgl/react-map-gl/tree/7.0-release The hook returns an object that contains all mounted maps under the closest `MapProvider`. The keys are each map's [id](./map.md#id) and the values are the [MapRef](./types.md#mapref). -If the hook is used inside a decendent of a `Map` component, the returned object also contains a `current` field that references the containing map. +If the hook is used inside a decendent of a `Map` component, the returned object additionally contains a `current` field that references the containing map. ## Source diff --git a/docs/get-started/adding-custom-data.md b/docs/get-started/adding-custom-data.md index b3f5d2758..c9e214862 100644 --- a/docs/get-started/adding-custom-data.md +++ b/docs/get-started/adding-custom-data.md @@ -13,7 +13,14 @@ import type {FeatureCollection} from 'geojson'; const geojson: FeatureCollection = { type: 'FeatureCollection', features: [ - {type: 'Feature', geometry: {type: 'Point', coordinates: [-122.4, 37.8]}} + { + type: 'Feature', + geometry: { + type: 'Point', + coordinates: [-122.4, 37.8] + }, + properties: {title: '915 Front Street, San Francisco, California'} + } ] }; diff --git a/docs/get-started/get-started.md b/docs/get-started/get-started.md index 724266949..241421e3c 100644 --- a/docs/get-started/get-started.md +++ b/docs/get-started/get-started.md @@ -13,14 +13,14 @@ import TabItem from '@theme/TabItem'; ```bash -npm install --save react-map-gl mapbox-gl @types/mapbox-gl +npm install react-map-gl mapbox-gl @types/mapbox-gl ``` ```bash -npm install --save react-map-gl maplibre-gl +npm install react-map-gl maplibre-gl ``` @@ -129,7 +129,7 @@ import 'maplibre-gl/dist/maplibre-gl.css'; ## Using with a Compatible Fork ```bash -npm install --save react-map-gl my-mapbox-fork +npm install react-map-gl my-map-gl-fork ``` Then override the `mapLib` prop of `Map`: @@ -139,9 +139,9 @@ import * as React from 'react'; import Map from 'react-map-gl'; // Include style sheet -import 'my-mapbox-fork/path/to/style-sheet.css'; +import 'my-map-gl-fork/path/to/style-sheet.css'; function App() { - return ; + return ; } ``` diff --git a/docs/get-started/mapbox-tokens.md b/docs/get-started/mapbox-tokens.md index f8fd8e3cd..669e4be26 100644 --- a/docs/get-started/mapbox-tokens.md +++ b/docs/get-started/mapbox-tokens.md @@ -4,7 +4,7 @@ Depending on which base map library you use, you may need a Mapbox token. You will need a Mapbox token if you use: - [mapbox-gl@>=2.0.0](https://github.com/mapbox/mapbox-gl-js/releases/tag/v2.0.0) - requires a mapbox access token in order to access the map renderer, and generates billable events regardlesss of whether you are displaying your own maps. -- `mapbox-gl@1.x` or `maplibre-gl@1.x` - requires an access token only if you load the map styles and tiles from Mapbox's data service. See "Display Maps Without A Mapbox Token" section below for using non-Mapbox tiles. +- `mapbox-gl@1.x` - requires an access token only if you load the map styles and tiles from Mapbox's data service. See "Display Maps Without A Mapbox Token" section below for using non-Mapbox tiles. To get a Mapbox token, you will need to register on [the Mapbox website](https://www.mapbox.com). The token will be used to identify you and start serving up map tiles. The service is free until a certain level of traffic is exceeded. @@ -20,7 +20,7 @@ We recommend using an environment variable to minimize leaking risks. See [secur It is possible to use the map component without the Mapbox service, if you use another tile source (for example, if you host your own map tiles). Note that this is no longer allowed using `mapbox-gl` v2.0 and above. The options are: -- Use [maplibre-gl](https://maplibre.org/maplibre-gl-js-docs/api/). See [Get Started](./get-started.md) for how to configure your project. +- Use [maplibre-gl](https://maplibre.org/maplibre-gl-js/docs/). See [Get Started](./get-started.md) for how to configure your project. - Stay on `mapbox-gl@1.x`. react-map-gl plans to continue supporting this release in the foreseeable future, however, this version will not include any of the latest features of the map renderer, nor get any future updates from Mapbox. To use your own map service, you will need a custom map style that points to your own [tile source](https://maplibre.org/maplibre-style-spec/sources/), and pass it to `Map` using the `mapStyle` prop. diff --git a/docs/get-started/state-management.md b/docs/get-started/state-management.md index 7b0a7e289..3cd564a1c 100644 --- a/docs/get-started/state-management.md +++ b/docs/get-started/state-management.md @@ -80,7 +80,7 @@ function App() { const newCenter = [viewState.longitude, viewState.latitude]; // Only update the view state if the center is inside the geofence if (turf.booleanPointInPolygon(newCenter, GEOFENCE)) { - setViewState(newCenter); + setViewState(viewState); } }, []) diff --git a/examples/geojson/src/control-panel.tsx b/examples/geojson/src/control-panel.tsx index d31fc0bdd..e8d65f280 100644 --- a/examples/geojson/src/control-panel.tsx +++ b/examples/geojson/src/control-panel.tsx @@ -11,7 +11,10 @@ function ControlPanel(props) { see details.

- Data source: US Census Bureau + Data source:{' '} + + US Census Bureau +

diff --git a/examples/get-started/hook/controls.jsx b/examples/get-started/hook/controls.jsx index 06cea0011..c1e23baef 100644 --- a/examples/get-started/hook/controls.jsx +++ b/examples/get-started/hook/controls.jsx @@ -4,14 +4,34 @@ import {useCallback, useState, useEffect} from 'react'; import {useMap} from 'react-map-gl'; export default function Controls() { - const {mymap} = useMap(); + /** + * ## This is how `useMap` works: + * ``` + * const maps = useMap(); + * console.log('Controls useMap()', maps); + * ``` + * ### First render: + * ``` + * { + * "current": undefined + * } + * ``` + * ### Second render: + * ``` + * { + * "current": undefined, + * "mymap": {...} // See https://visgl.github.io/react-map-gl/docs/api-reference/types#mapref + * } + * ``` + */ + + const {mymap} = useMap(); // `mymap` is the id in + const [inputValue, setInputValue] = useState(''); const [hasError, setError] = useState(false); useEffect(() => { - if (!mymap) { - return undefined; - } + if (!mymap) return undefined; const onMove = () => { const {lng, lat} = mymap.getCenter(); @@ -31,6 +51,8 @@ export default function Controls() { }, []); const onSubmit = useCallback(() => { + if (!mymap) return; + const [lng, lat] = inputValue.split(',').map(Number); if (Math.abs(lng) <= 180 && Math.abs(lat) <= 85) { mymap.easeTo({ diff --git a/examples/get-started/hook/controls2.jsx b/examples/get-started/hook/controls2.jsx new file mode 100644 index 000000000..139ac5a35 --- /dev/null +++ b/examples/get-started/hook/controls2.jsx @@ -0,0 +1,24 @@ +// import {useMap} from 'react-map-gl'; + +export default function Controls2() { + /** + * ## This is how `useMap` works: + * This component does nothing. It's purpose is to demo `useMap`. + * When a component is a child of ``, `useMap` has a `current` field that references the containing map. + * See https://visgl.github.io/react-map-gl/docs/api-reference/use-map + * See https://visgl.github.io/react-map-gl/docs/api-reference/types#mapref + * ``` + * const maps = useMap(); + * console.log('Controls2 useMap()', maps); + * ``` + * ### First render: + * ``` + * { + * "current": {...}, // this is the same as `mymap` + * "mymap": {...} + * } + * ``` + */ + + return null; +} diff --git a/examples/get-started/hook/map.jsx b/examples/get-started/hook/map.jsx index f7c0e222f..dad4e6cd7 100644 --- a/examples/get-started/hook/map.jsx +++ b/examples/get-started/hook/map.jsx @@ -1,14 +1,35 @@ import * as React from 'react'; import Map from 'react-map-gl'; +// import {useMap} from 'react-map-gl'; import 'mapbox-gl/dist/mapbox-gl.css'; +import Controls2 from './controls2'; const MAPBOX_TOKEN = ''; // Set your mapbox token here export default function MapView() { + /** + * ## This is how `useMap` works: + * ``` + * const maps = useMap(); + * console.log('MapView useMap()', maps); + * ``` + * ### First render: + * ``` + * { + * "current": undefined + * } + * Second render: + * { + * "current": undefined, + * "mymap": {...} // See https://visgl.github.io/react-map-gl/docs/api-reference/types#mapref + * } + * ``` + */ + return ( + > + + ); } diff --git a/package.json b/package.json index 52ade2940..47136c0dc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "react-map-gl", - "description": "React components for Mapbox GL JS-compatible libraries", + "description": "React components for MapLibre GL JS and Mapbox GL JS", "version": "7.2.0-beta.1", "keywords": [ "mapbox", @@ -20,14 +20,14 @@ "module": "dist/index.js", "exports": { ".": { - "import": "./dist/index.js", + "types": "./dist/index.d.ts", "require": "./dist/index.cjs", - "types": "./dist/index.d.ts" + "import": "./dist/index.js" }, "./maplibre": { - "import": "./dist/exports-maplibre.js", + "types": "./dist/exports-maplibre.d.ts", "require": "./dist/exports-maplibre.cjs", - "types": "./dist/exports-maplibre.d.ts" + "import": "./dist/exports-maplibre.js" } }, "files": [ diff --git a/scripts/github-release.js b/scripts/github-release.js index 2a450ce4f..29f1444b5 100644 --- a/scripts/github-release.js +++ b/scripts/github-release.js @@ -28,7 +28,7 @@ console.log(JSON.stringify(requestBody)); function getGitTag() { try { - return execSync('git describe --exact-match HEAD', { + return execSync('git describe --tags --exact-match HEAD', { stdio: [null, 'pipe', null], encoding: 'utf-8' }).trim(); diff --git a/src/types/lib.ts b/src/types/lib.ts index ef2d6aa5d..ac20ab405 100644 --- a/src/types/lib.ts +++ b/src/types/lib.ts @@ -81,6 +81,18 @@ export interface MapInstance extends Evented { triggerRepaint(): void; + getCenter(): LngLat; + + getZoom(): number; + + getBearing(): number; + + getPitch(): number; + + getPadding(): PaddingOptions; + + getRenderWorldCopies(): boolean; + setPadding(padding: PaddingOptions); fitBounds(bounds: any, options?: any); diff --git a/src/utils/transform.ts b/src/utils/transform.ts index 5f5cefe37..63e724aa7 100644 --- a/src/utils/transform.ts +++ b/src/utils/transform.ts @@ -57,12 +57,6 @@ export function applyViewStateToTransform(tr: Transform, props: MapboxProps): bo const v: Partial = props.viewState || props; let changed = false; - if ('longitude' in v && 'latitude' in v) { - const center = tr.center; - // @ts-ignore - tr.center = new center.constructor(v.longitude, v.latitude); - changed = changed || center !== tr.center; - } if ('zoom' in v) { const zoom = tr.zoom; tr.zoom = v.zoom; @@ -82,5 +76,11 @@ export function applyViewStateToTransform(tr: Transform, props: MapboxProps): bo changed = true; tr.padding = v.padding; } + if ('longitude' in v && 'latitude' in v) { + const center = tr.center; + // @ts-ignore + tr.center = new center.constructor(v.longitude, v.latitude); + changed = changed || center !== tr.center; + } return changed; } diff --git a/test/src/utils/transform.spec.js b/test/src/utils/transform.spec.js index 28876a77d..ddd04cf75 100644 --- a/test/src/utils/transform.spec.js +++ b/test/src/utils/transform.spec.js @@ -90,5 +90,11 @@ test('applyViewStateToTransform', t => { changed = applyViewStateToTransform(tr, {viewState: {pitch: 30}}); t.notOk(changed, 'nothing changed'); + applyViewStateToTransform(tr, {longitude: 0, latitude: 0, zoom: 0}); + changed = applyViewStateToTransform(tr, {longitude: 12, latitude: 34, zoom: 15}); + t.ok(changed, 'center and zoom changed'); + t.equal(tr.zoom, 15, 'zoom is correct'); + t.equal(tr.center.lat, 34, 'center latitude is correct'); + t.end(); }); diff --git a/website/docusaurus.config.js b/website/docusaurus.config.js index 7e6b0d79e..345d83d2e 100644 --- a/website/docusaurus.config.js +++ b/website/docusaurus.config.js @@ -9,7 +9,7 @@ const {resolve} = require('path'); /** @type {import('@docusaurus/types').Config} */ const config = { title: 'React Map GL', - tagline: 'React wrapper for Mapbox GL JS', + tagline: 'React wrapper for MapLibre GL JS and Mapbox GL JS', url: 'https://visgl.github.io/', baseUrl: '/react-map-gl/', onBrokenLinks: 'throw', @@ -164,8 +164,8 @@ const config = { href: 'https://loaders.gl' }, { - label: 'nebula.gl', - href: 'https://nebula.gl' + label: 'kepler.gl', + href: 'https://kepler.gl' } ] }, @@ -187,7 +187,7 @@ const config = { ] } ], - copyright: `Copyright © ${new Date().getFullYear()} OpenJS Foundation` + copyright: '

Copyright OpenJS Foundation and vis.gl contributors. All rights reserved. The OpenJS Foundation has registered trademarks and uses trademarks. For a list of trademarks of the OpenJS Foundation, please see our Trademark Policy and Trademark List. Trademarks and logos not indicated on the list of OpenJS Foundation trademarks are trademarks™ or registered® trademarks of their respective holders. Use of them does not imply any affiliation with or endorsement by them.

The OpenJS Foundation | Terms of Use | Privacy Policy | Bylaws | Code of Conduct | Trademark Policy | Trademark List | Cookie Policy

' }, prism: { theme: lightCodeTheme, diff --git a/website/src/pages/index.jsx b/website/src/pages/index.jsx index dda7b50e5..6799f435e 100644 --- a/website/src/pages/index.jsx +++ b/website/src/pages/index.jsx @@ -57,7 +57,7 @@ export default function IndexPage() {

- react-map-gl makes using Mapbox GL JS in React applications easy. + react-map-gl makes using MapLibre GL JS and Mapbox GL JS in React applications easy.


@@ -66,7 +66,7 @@ export default function IndexPage() { React Integration

- Use Mapbox GL JS Map as a fully controlled reactive component. + Use a MapLibre GL JS or Mapbox GL JS map as a fully controlled reactive component.

@@ -88,7 +88,7 @@ export default function IndexPage() { target="_blank" rel="noopener noreferrer"> deck.gl to render performant and compelling 2D and 3D - WebGL visualizations on top of your Mapbox GL JS based maps. + WebGL visualizations on top of your MapLibre GL JS and Mapbox GL JS based maps.