Repository: visgl/react-map-gl
Branch: master
Commit: c41e00c2d815
Files: 586
Total size: 2.2 MB
Directory structure:
gitextract_r_hkj0e0/
├── .eslintignore
├── .eslintrc.cjs
├── .github/
│ ├── ISSUE_TEMPLATE/
│ │ ├── bug-report.yml
│ │ ├── config.yml
│ │ └── feature-request.yml
│ ├── SECURITY.md
│ └── workflows/
│ ├── release.yml
│ ├── test.yml
│ └── website.yml
├── .gitignore
├── .nvmrc
├── .ocularrc.js
├── .prettierrc
├── CHANGELOG.md
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── LICENSE
├── README.md
├── TESTING.md
├── docs/
│ ├── .gitignore
│ ├── README.md
│ ├── api-reference/
│ │ ├── mapbox/
│ │ │ ├── attribution-control.md
│ │ │ ├── fullscreen-control.md
│ │ │ ├── geolocate-control.md
│ │ │ ├── layer.md
│ │ │ ├── map-provider.md
│ │ │ ├── map.md
│ │ │ ├── marker.md
│ │ │ ├── navigation-control.md
│ │ │ ├── popup.md
│ │ │ ├── scale-control.md
│ │ │ ├── source.md
│ │ │ ├── types.md
│ │ │ ├── use-control.md
│ │ │ └── use-map.md
│ │ └── maplibre/
│ │ ├── attribution-control.md
│ │ ├── fullscreen-control.md
│ │ ├── geolocate-control.md
│ │ ├── globe-control.md
│ │ ├── layer.md
│ │ ├── logo-control.md
│ │ ├── map-provider.md
│ │ ├── map.md
│ │ ├── marker.md
│ │ ├── navigation-control.md
│ │ ├── popup.md
│ │ ├── scale-control.md
│ │ ├── source.md
│ │ ├── terrain-control.md
│ │ ├── types.md
│ │ ├── use-control.md
│ │ └── use-map.md
│ ├── get-started/
│ │ ├── adding-custom-data.md
│ │ ├── get-started.md
│ │ ├── mapbox-tokens.md
│ │ ├── state-management.md
│ │ └── tips-and-tricks.md
│ ├── table-of-contents.json
│ ├── upgrade-guide.md
│ └── whats-new.md
├── examples/
│ ├── .data/
│ │ ├── bart-station.json
│ │ ├── cities.json
│ │ ├── feature-example-sf.json
│ │ ├── us-election-2016.json
│ │ └── us-income.geojson
│ ├── .eslintrc
│ ├── get-started/
│ │ ├── basic/
│ │ │ ├── README.md
│ │ │ ├── app.jsx
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ └── vite.config.js
│ │ ├── controlled/
│ │ │ ├── README.md
│ │ │ ├── app.jsx
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ └── vite.config.js
│ │ ├── hook/
│ │ │ ├── README.md
│ │ │ ├── app.jsx
│ │ │ ├── controls.jsx
│ │ │ ├── controls2.jsx
│ │ │ ├── index.html
│ │ │ ├── map.jsx
│ │ │ ├── package.json
│ │ │ └── vite.config.js
│ │ ├── maplibre/
│ │ │ ├── README.md
│ │ │ ├── app.jsx
│ │ │ ├── index.html
│ │ │ └── package.json
│ │ ├── nextjs/
│ │ │ ├── .gitignore
│ │ │ ├── README.md
│ │ │ ├── next.config.js
│ │ │ ├── package.json
│ │ │ └── pages/
│ │ │ ├── _app.js
│ │ │ └── index.js
│ │ └── redux/
│ │ ├── README.md
│ │ ├── app.jsx
│ │ ├── controls.jsx
│ │ ├── index.html
│ │ ├── map.jsx
│ │ ├── package.json
│ │ ├── store.js
│ │ └── vite.config.js
│ ├── mapbox/
│ │ ├── clusters/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── layers.ts
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── controls/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── pin.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── custom-cursor/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── custom-overlay/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── custom-overlay.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── deckgl-overlay/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ └── app.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── draggable-markers/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── pin.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── draw-polygon/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── draw-control.ts
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── filter/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── map-style.ts
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── geocoder/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── geocoder-control.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── geojson/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ ├── map-style.ts
│ │ │ │ └── utils.ts
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── geojson-animation/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── heatmap/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── map-style.ts
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── interaction/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── layers/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── map-style-basic-v8.json
│ │ ├── side-by-side/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── terrain/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ ├── viewport-animation/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ ├── tsconfig.json
│ │ │ └── vite.config.js
│ │ └── zoom-to-bounds/
│ │ ├── README.md
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── src/
│ │ │ ├── app.tsx
│ │ │ ├── control-panel.tsx
│ │ │ └── map-style.tsx
│ │ ├── tsconfig.json
│ │ └── vite.config.js
│ ├── maplibre/
│ │ ├── clusters/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── layers.ts
│ │ │ └── tsconfig.json
│ │ ├── controls/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── pin.tsx
│ │ │ └── tsconfig.json
│ │ ├── custom-cursor/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ └── tsconfig.json
│ │ ├── custom-overlay/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── custom-overlay.tsx
│ │ │ └── tsconfig.json
│ │ ├── deckgl-overlay/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ └── app.tsx
│ │ │ └── tsconfig.json
│ │ ├── draggable-markers/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── pin.tsx
│ │ │ └── tsconfig.json
│ │ ├── draw-polygon/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── draw-control.ts
│ │ │ └── tsconfig.json
│ │ ├── filter/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── map-style.ts
│ │ │ └── tsconfig.json
│ │ ├── geocoder/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── geocoder-control.tsx
│ │ │ └── tsconfig.json
│ │ ├── geojson/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ ├── map-style.ts
│ │ │ │ └── utils.ts
│ │ │ └── tsconfig.json
│ │ ├── geojson-animation/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ └── tsconfig.json
│ │ ├── globe/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ └── tsconfig.json
│ │ ├── heatmap/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ ├── control-panel.tsx
│ │ │ │ └── map-style.ts
│ │ │ └── tsconfig.json
│ │ ├── interaction/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ └── tsconfig.json
│ │ ├── layers/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ └── tsconfig.json
│ │ ├── map-style-basic-v8.json
│ │ ├── side-by-side/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ └── tsconfig.json
│ │ ├── terrain/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ └── tsconfig.json
│ │ ├── viewport-animation/
│ │ │ ├── README.md
│ │ │ ├── index.html
│ │ │ ├── package.json
│ │ │ ├── src/
│ │ │ │ ├── app.tsx
│ │ │ │ └── control-panel.tsx
│ │ │ └── tsconfig.json
│ │ └── zoom-to-bounds/
│ │ ├── README.md
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── src/
│ │ │ ├── app.tsx
│ │ │ ├── control-panel.tsx
│ │ │ └── map-style.tsx
│ │ └── tsconfig.json
│ └── vite.config.local.js
├── index.html
├── lerna.json
├── modules/
│ ├── main/
│ │ ├── package.json
│ │ ├── src/
│ │ │ ├── mapbox-legacy/
│ │ │ │ ├── components/
│ │ │ │ │ ├── attribution-control.ts
│ │ │ │ │ ├── fullscreen-control.ts
│ │ │ │ │ ├── geolocate-control.ts
│ │ │ │ │ ├── layer.ts
│ │ │ │ │ ├── map.tsx
│ │ │ │ │ ├── marker.ts
│ │ │ │ │ ├── navigation-control.ts
│ │ │ │ │ ├── popup.ts
│ │ │ │ │ ├── scale-control.ts
│ │ │ │ │ ├── source.ts
│ │ │ │ │ ├── use-control.ts
│ │ │ │ │ └── use-map.tsx
│ │ │ │ ├── index.ts
│ │ │ │ ├── mapbox/
│ │ │ │ │ ├── create-ref.ts
│ │ │ │ │ └── mapbox.ts
│ │ │ │ ├── types/
│ │ │ │ │ ├── common.ts
│ │ │ │ │ ├── events.ts
│ │ │ │ │ ├── internal.ts
│ │ │ │ │ ├── lib.ts
│ │ │ │ │ └── style-spec.ts
│ │ │ │ └── utils/
│ │ │ │ ├── apply-react-style.ts
│ │ │ │ ├── assert.ts
│ │ │ │ ├── deep-equal.ts
│ │ │ │ ├── set-globals.ts
│ │ │ │ ├── style-utils.ts
│ │ │ │ ├── transform.ts
│ │ │ │ └── use-isomorphic-layout-effect.ts
│ │ │ ├── mapbox.ts
│ │ │ └── maplibre.ts
│ │ ├── test/
│ │ │ ├── components/
│ │ │ │ ├── controls.spec.jsx
│ │ │ │ ├── index.js
│ │ │ │ ├── layer.spec.jsx
│ │ │ │ ├── map.spec.jsx
│ │ │ │ ├── marker.spec.jsx
│ │ │ │ ├── popup.spec.jsx
│ │ │ │ ├── source.spec.jsx
│ │ │ │ └── use-map.spec.jsx
│ │ │ └── utils/
│ │ │ ├── apply-react-style.spec.js
│ │ │ ├── deep-equal.spec.js
│ │ │ ├── index.js
│ │ │ ├── mapbox-gl-mock/
│ │ │ │ ├── edge_insets.js
│ │ │ │ ├── lng_lat.js
│ │ │ │ ├── lng_lat_bounds.js
│ │ │ │ ├── transform.js
│ │ │ │ └── util.js
│ │ │ ├── style-utils.spec.js
│ │ │ ├── test-utils.jsx
│ │ │ └── transform.spec.js
│ │ └── tsconfig.json
│ ├── react-mapbox/
│ │ ├── package.json
│ │ ├── src/
│ │ │ ├── components/
│ │ │ │ ├── attribution-control.ts
│ │ │ │ ├── fullscreen-control.ts
│ │ │ │ ├── geolocate-control.ts
│ │ │ │ ├── layer.ts
│ │ │ │ ├── map.tsx
│ │ │ │ ├── marker.ts
│ │ │ │ ├── navigation-control.ts
│ │ │ │ ├── popup.ts
│ │ │ │ ├── scale-control.ts
│ │ │ │ ├── source.ts
│ │ │ │ ├── use-control.ts
│ │ │ │ └── use-map.tsx
│ │ │ ├── index.ts
│ │ │ ├── mapbox/
│ │ │ │ ├── create-ref.ts
│ │ │ │ ├── mapbox.ts
│ │ │ │ └── proxy-transform.ts
│ │ │ ├── types/
│ │ │ │ ├── common.ts
│ │ │ │ ├── events.ts
│ │ │ │ ├── internal.ts
│ │ │ │ ├── lib.ts
│ │ │ │ └── style-spec.ts
│ │ │ └── utils/
│ │ │ ├── apply-react-style.ts
│ │ │ ├── assert.ts
│ │ │ ├── compare-class-names.ts
│ │ │ ├── deep-equal.ts
│ │ │ ├── set-globals.ts
│ │ │ ├── style-utils.ts
│ │ │ ├── transform.ts
│ │ │ └── use-isomorphic-layout-effect.ts
│ │ ├── test/
│ │ │ ├── components/
│ │ │ │ ├── controls.spec.jsx
│ │ │ │ ├── index.js
│ │ │ │ ├── layer.spec.jsx
│ │ │ │ ├── map.spec.jsx
│ │ │ │ ├── marker.spec.jsx
│ │ │ │ ├── popup.spec.jsx
│ │ │ │ ├── source.spec.jsx
│ │ │ │ └── use-map.spec.jsx
│ │ │ └── utils/
│ │ │ ├── apply-react-style.spec.js
│ │ │ ├── compare-class-names.spec.js
│ │ │ ├── deep-equal.spec.js
│ │ │ ├── index.js
│ │ │ ├── mapbox-gl-mock/
│ │ │ │ ├── edge_insets.js
│ │ │ │ ├── lng_lat.js
│ │ │ │ ├── lng_lat_bounds.js
│ │ │ │ ├── transform.js
│ │ │ │ └── util.js
│ │ │ ├── style-utils.spec.js
│ │ │ ├── test-utils.jsx
│ │ │ ├── token.js
│ │ │ └── transform.spec.js
│ │ └── tsconfig.json
│ └── react-maplibre/
│ ├── package.json
│ ├── src/
│ │ ├── components/
│ │ │ ├── attribution-control.ts
│ │ │ ├── fullscreen-control.ts
│ │ │ ├── geolocate-control.ts
│ │ │ ├── globe-control.ts
│ │ │ ├── layer.ts
│ │ │ ├── logo-control.ts
│ │ │ ├── map.tsx
│ │ │ ├── marker.ts
│ │ │ ├── navigation-control.ts
│ │ │ ├── popup.ts
│ │ │ ├── scale-control.ts
│ │ │ ├── source.ts
│ │ │ ├── terrain-control.ts
│ │ │ ├── use-control.ts
│ │ │ └── use-map.tsx
│ │ ├── index.ts
│ │ ├── maplibre/
│ │ │ ├── create-ref.ts
│ │ │ └── maplibre.ts
│ │ ├── types/
│ │ │ ├── common.ts
│ │ │ ├── events.ts
│ │ │ ├── internal.ts
│ │ │ ├── lib.ts
│ │ │ └── style-spec.ts
│ │ └── utils/
│ │ ├── apply-react-style.ts
│ │ ├── assert.ts
│ │ ├── compare-class-names.ts
│ │ ├── deep-equal.ts
│ │ ├── set-globals.ts
│ │ ├── style-utils.ts
│ │ ├── transform.ts
│ │ └── use-isomorphic-layout-effect.ts
│ ├── test/
│ │ ├── .eslintrc
│ │ ├── components/
│ │ │ ├── controls.spec.jsx
│ │ │ ├── index.js
│ │ │ ├── layer.spec.jsx
│ │ │ ├── map.spec.jsx
│ │ │ ├── marker.spec.jsx
│ │ │ ├── popup.spec.jsx
│ │ │ ├── source.spec.jsx
│ │ │ └── use-map.spec.jsx
│ │ └── utils/
│ │ ├── apply-react-style.spec.js
│ │ ├── compare-class-names.spec.js
│ │ ├── deep-equal.spec.js
│ │ ├── index.js
│ │ ├── style-utils.spec.js
│ │ ├── test-utils.jsx
│ │ └── transform.spec.js
│ └── tsconfig.json
├── package.json
├── scripts/
│ └── update-release-branch.sh
├── test/
│ ├── .eslintrc
│ ├── apps/
│ │ └── reuse-maps/
│ │ ├── index.html
│ │ ├── package.json
│ │ ├── src/
│ │ │ └── app.tsx
│ │ ├── tsconfig.json
│ │ └── vite.config.js
│ ├── browser.js
│ ├── data/
│ │ ├── glyph/
│ │ │ └── UberMove/
│ │ │ └── 0-255
│ │ ├── sprite/
│ │ │ └── tools/
│ │ │ └── 14/
│ │ │ └── sprites.json
│ │ ├── style.json
│ │ └── tile/
│ │ └── v1/
│ │ └── 12/
│ │ └── 655/
│ │ ├── 1582/
│ │ │ ├── COMPOSITE
│ │ │ └── POI
│ │ └── 1583/
│ │ ├── COMPOSITE
│ │ └── POI
│ ├── node.js
│ ├── render/
│ │ ├── index.jsx
│ │ └── test-cases.jsx
│ ├── size/
│ │ ├── mapbox-legacy.js
│ │ ├── mapbox.js
│ │ └── maplibre.js
│ ├── src/
│ │ └── exports.ts
│ └── test-utils.js
├── tsconfig.json
└── website/
├── .eslintignore
├── .gitignore
├── babel.config.js
├── docusaurus.config.js
├── package.json
└── src/
├── examples/
│ ├── index.mdx
│ ├── mapbox/
│ │ ├── clusters.mdx
│ │ ├── controls.mdx
│ │ ├── custom-cursor.mdx
│ │ ├── draggable-markers.mdx
│ │ ├── draw-polygon.mdx
│ │ ├── filter.mdx
│ │ ├── geocoder.mdx
│ │ ├── geojson-animation.mdx
│ │ ├── geojson.mdx
│ │ ├── heatmap.mdx
│ │ ├── interaction.mdx
│ │ ├── layers.mdx
│ │ ├── side-by-side.mdx
│ │ ├── terrain.mdx
│ │ ├── viewport-animation.mdx
│ │ └── zoom-to-bounds.mdx
│ ├── maplibre/
│ │ ├── clusters.mdx
│ │ ├── controls.mdx
│ │ ├── custom-cursor.mdx
│ │ ├── draggable-markers.mdx
│ │ ├── draw-polygon.mdx
│ │ ├── filter.mdx
│ │ ├── geocoder.mdx
│ │ ├── geojson-animation.mdx
│ │ ├── geojson.mdx
│ │ ├── heatmap.mdx
│ │ ├── interaction.mdx
│ │ ├── layers.mdx
│ │ ├── side-by-side.mdx
│ │ ├── terrain.mdx
│ │ ├── viewport-animation.mdx
│ │ └── zoom-to-bounds.mdx
│ └── table-of-contents.json
├── mapbox-gl.css
├── maplibre-gl.css
├── pages/
│ └── index.jsx
└── styles.css
================================================
FILE CONTENTS
================================================
================================================
FILE: .eslintignore
================================================
dist/
node_modules/
test/
modules/**/test/
**/vite.config.js
examples/vite.config.local.js
================================================
FILE: .eslintrc.cjs
================================================
const {getESLintConfig} = require('@vis.gl/dev-tools/configuration');
module.exports = getESLintConfig({
react: '16.8.2',
overrides: {
parserOptions: {
project: ['./tsconfig.json'],
ecmaVersion: 2020
},
rules: {
'max-depth': ['warn', 4],
complexity: ['warn'],
'max-statements': ['warn'],
'callback-return': 0
},
overrides: [
{
files: ['**/*.ts', '**/*.tsx', '**/*.d.ts'],
rules: {
// Gradually enable
'@typescript-eslint/ban-ts-comment': 0,
'@typescript-eslint/ban-types': 0,
'@typescript-eslint/no-unsafe-member-access': 0,
'@typescript-eslint/no-unsafe-assignment': 0,
'import/named': 0,
'@typescript-eslint/explicit-module-boundary-types': 0,
'@typescript-eslint/no-unsafe-return': 0,
'@typescript-eslint/no-unsafe-call': 0,
'@typescript-eslint/restrict-plus-operands': 0,
'@typescript-eslint/no-explicit-any': 0,
'@typescript-eslint/no-unsafe-argument': 0,
'@typescript-eslint/no-shadow': 1,
'@typescript-eslint/no-redundant-type-constituents': 1
}
}
]
}
});
================================================
FILE: .github/ISSUE_TEMPLATE/bug-report.yml
================================================
name: Bug Report
description: Something does not work as expected
title: "[Bug]"
labels: bug
body:
- type: markdown
attributes:
value: |
Thank you for taking the time to report a bug!
You may find answers faster by searching in [the documentation](https://visgl.github.io/react-map-gl/search) and [existing issues](https://github.com/visgl/react-map-gl/issue).
If you are unsure whether it is a bug in your own implementation or the library itself, consider starting a conversation in [Discussions](https://github.com/visgl/react-map-gl/discussions) instead.
- type: textarea
attributes:
label: Description
description: What you're experiencing.
validations:
required: true
- type: textarea
attributes:
label: Expected Behavior
description: What you expect to see.
validations:
required: false
- type: textarea
attributes:
label: Steps to Reproduce
description: |
Providing a Code Sandbox that reproduces the behavior. You can use [this boiler plate](https://codesandbox.io/s/react-map-gl-boiler-plate-717vw) as a starting point.
validations:
required: true
- type: textarea
attributes:
label: Environment
description: |
Example:
- **Framework version**: react-map-gl@7.0.0
- **Map library**: mapbox-gl@2.7.0
- **Browser**: Chrome 98.0
- **OS**: iOS 15.1
value: |
- Framework version:
- Map library:
- Browser:
- OS:
validations:
required: true
- type: textarea
attributes:
label: Logs
description: Check the browser console for any relevant errors or warnings.
validations:
required: false
================================================
FILE: .github/ISSUE_TEMPLATE/config.yml
================================================
blank_issues_enabled: false
contact_links:
- name: I have a question / I need help
url: https://github.com/visgl/react-map-gl/discussions
about: Ask generic questions or request help here
================================================
FILE: .github/ISSUE_TEMPLATE/feature-request.yml
================================================
name: Feature Request
description: Request for a new feature or enhancement
title: "[Feat]"
labels: feature
body:
- type: markdown
attributes:
value: |
Tell us what you are using react-map-gl for and how we can make it better.
This project is maintained by volunteers and sponsoring companies. While we cannot promise a timeline for any specific feature, we try to prioritize those that will benefit the most users.
- type: textarea
attributes:
label: Target Use Case
description: How would this benefit you and other developers?
validations:
required: true
- type: textarea
attributes:
label: Proposal
description: How would this feature work? If it's a new API, use code samples to show how it will be used. If it's visual, link to an image that illustrate the desired effect.
validations:
required: true
================================================
FILE: .github/SECURITY.md
================================================
# 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.
================================================
FILE: .github/workflows/release.yml
================================================
name: release
on:
push:
tags:
- v*
jobs:
check_branch:
runs-on: ubuntu-latest
outputs:
should_build: ${{ steps.permitted.outputs.result }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Fetch remote branches
run: |
git fetch origin --depth=1
- name: Check if on permitted branch
id: permitted
run: |
result=
if git branch -a --contains $GITHUB_SHA | grep -q 'remotes/origin/master$'; then
result=true
elif git branch -a --contains $GITHUB_SHA | grep -q 'remotes/origin/.*-release$'; then
result=true
fi
echo "result=${result}" >> "$GITHUB_OUTPUT"
release:
runs-on: ubuntu-22.04
needs: check_branch
permissions:
contents: write
if: ${{ github.repository_owner == 'visgl' && needs.check_branch.outputs.should_build }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
NPM_ACCESS_TOKEN: ${{ secrets.NPM_ACCESS_TOKEN }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Enable Corepack
run: corepack enable yarn
- name: Install dependencies
run: yarn
- name: Build packages
run: yarn build
- name: Run tests from transpiled code
run: npx ocular-test dist
- name: Login to NPM
run: npm config set "//registry.npmjs.org/:_authToken=${NPM_ACCESS_TOKEN}"
- name: Publish to NPM
run: npx ocular-publish from-git
================================================
FILE: .github/workflows/test.yml
================================================
name: test
# On every pull request, but only on push to master
on:
push:
branches:
- master
pull_request:
permissions:
contents: read
jobs:
test-node:
runs-on: ubuntu-22.04
permissions:
checks: write
contents: read
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Setup Node.js
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Enable Corepack
run: corepack enable yarn
- name: Install dependencies
run: yarn bootstrap
- name: Run tests
env:
VITE_MAPBOX_TOKEN: ${{ secrets.MAPBOX_ACCESS_TOKEN_CI }}
run: |
yarn lint
yarn test ci
- name: Coveralls
uses: coverallsapp/github-action@648a8eb78e6d50909eff900e4ec85cab4524a45b # v2.3.6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
================================================
FILE: .github/workflows/website.yml
================================================
name: website
on:
push:
branches:
- '*-release'
jobs:
check_branch:
runs-on: ubuntu-22.04
outputs:
should_deploy: ${{ endsWith(github.ref, steps.get_version.outputs.latest) }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- 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
if: ${{ github.repository_owner == 'visgl' && needs.check_branch.outputs.should_deploy }}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
token: ${{ secrets.WEBSITE_DEPLOY_TOKEN }}
- name: Setup Node.js
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version-file: '.nvmrc'
cache: 'yarn'
- name: Enable Corepack
run: corepack enable yarn
- name: Install dependencies
run: |
yarn bootstrap
(cd website && yarn)
- name: Build website
env:
MapboxAccessToken: ${{ secrets.MAPBOX_ACCESS_TOKEN }}
run: (cd website && yarn build)
- name: Deploy
uses: JamesIves/github-pages-deploy-action@132898c54c57c7cc6b80eb3a89968de8fc283505 # 3.7.1
with:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
BRANCH: gh-pages
FOLDER: website/build
CLEAN: true
================================================
FILE: .gitignore
================================================
dist/
dist-es6/
node_modules
.nyc_output/
coverage
npm-debug.log
package-lock.json
examples/**/yarn.lock
test/**/yarn.lock
**/package-lock.json
**/tsconfig.tsbuildinfo
yarn-error.log
.DS_Store
.reify-cache
tsconfig.tsbuildinfo
.idea
================================================
FILE: .nvmrc
================================================
18.19.0
================================================
FILE: .ocularrc.js
================================================
/** @typedef {import('@vis.gl/dev-tools').OcularConfig} OcularConfig */
import {resolve} from 'path';
/** @type {OcularConfig} */
export default {
lint: {
paths: ['modules', 'test', 'examples']
},
coverage: {
test: 'browser'
},
aliases: {
},
browserTest: {
server: {wait: 5000}
},
entry: {
test: 'test/node.js',
'test-browser': 'test/browser.js',
size: [
'test/size/mapbox-legacy.js',
'test/size/maplibre.js',
'test/size/mapbox.js'
]
}
};
================================================
FILE: .prettierrc
================================================
printWidth: 100
semi: true
singleQuote: true
trailingComma: none
bracketSpacing: false
arrowParens: avoid
================================================
FILE: CHANGELOG.md
================================================
# CHANGELOG
# Version 8.1
## v8.1.0-alpha.2 (Apr 9, 2025)
- wrap jumpTo as internal update (#2516)
## v8.1.0-alpha.1 (Mar 28, 2025)
- feat(mapbox): Replace shadow transform with proxied approach (#2514)
# Version 8.0
## v8.0.0-beta.1 (Jan 31, 2025)
- feat: remove `RTLTextPlugin` default for MapLibre (#2480)
## v8.0.0-alpha.2 (Jan 27, 2025)
- Migrate to monorepo (#2459)
# Version 7.2
## 7.2.0-beta.1 (Sep 12, 2023)
- Switch to ESM module (#2281)
# Version 7.1
## 7.1.0-beta.3 (Jun 22, 2023)
- Remap event types (#2207)
- Restore fog, light and terrain types on MapProps (#2206)
## 7.1.0-beta.2 (Jun 14, 2023)
- Make source prop of Layer optional (#2200)
- Fix maplibre-gl peerDependencies typo (#2197)
## 7.1.0-beta.1 (Jun 5, 2023)
- Add ref forwarding to Marker and Popup (#2191)
- Split exports into separate endpoints (#2178)
- Make mapbox-gl an optional dependency (#2175)
- Remove defaultProps and displayName (#2173)
# Version 7.0
## 7.0.0 (Feb 4, 2022)
v7 is a complete rewrite of the library. It addresses many long-standing issues in v5 and v6 limited by legacy architecture decisions. The most notable results of this redesign are:
- Performance: minimize the overhead of React, offer the same fast and smooth interaction as the native library
- Lightweight: the ESM build size is reduced from 219k to 57k
- Predictability: Components behave the same as their mapbox counterparts. Props are mapped 1:1 from the native options wherever appropriate. Almost all imperative APIs (`flyTo`, `fitBounds` etc.) can now be called directly without breaking the React binding.
- Compatibility: first and third-party plugins! Directly use [mapbox-gl-draw](https://github.com/visgl/react-map-gl/tree/7.0-release/examples/draw-polygon), [mapbox-gl-geocoder](https://github.com/visgl/react-map-gl/tree/7.0-release/examples/geocoder), to name a few.
- TypeScript compliant: the code base is now entirely written in TypeScript, and all types can be [imported](/docs/api-reference/types.md).
Visit the [upgrade guide](https://visgl.github.io/react-map-gl/docs/upgrade-guide) if you are trying to upgrade from v5 and v6.
## 7.0.0-beta.1 (Jan 26, 2022)
- Add mapLib API (#1703)
- Support inline styling for all components (#1702)
- Refactor Mapbox class (#1701)
## 7.0.0-alpha.7 (Jan 17, 2022)
- Improve typing (#1695)
- [v7] Fix popup className update in mapbox v1/maplibre (#1694)
## 7.0.0-alpha.6 (Jan 9, 2022)
- [v7] Fix double controls in strict mode (#1678)
- [v7] Fix AttributionControl prop typo (#1679)
## 7.0.0-alpha.5 (Jan 6, 2022)
- [v7] Handle unmount order (#1676)
- [v7] Fix synchronization during transition (#1675)
- [v7] Update MapRef (#1674)
- [v7] Bug fixes (#1673)
## 7.0.0-alpha.4 (Jan 4, 2022)
- [v7] Fix resize synchronization (#1670)
- [v7] Add fog, light, terrain props (#1669)
- [v7] support global settings with MapProps (#1668)
## 7.0.0-alpha.3 (Jan 3, 2022)
- [v7] Clean up typings and expose more utility types (#1667)
- Drop flow types support (#1666)
## 7.0.0-alpha.2 (Jan 2, 2022)
- Update `@types/mapbox-gl` dependency
## 7.0.0-alpha.1 (Jan 2, 2022)
- [v7] utility hooks (#1663)
- [v7] Add Layer and Source (#1657)
- [v7] Control components (#1656)
- [v7] Marker and Popup (#1655)
- [v7] Map component (#1652)
- Typescript dev setup
================================================
FILE: CODE_OF_CONDUCT.md
================================================
# 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.
================================================
FILE: CONTRIBUTING.md
================================================
# Contributing
**Thanks for taking the time to contribute!**
PRs and bug reports are welcome, and we are actively looking for new maintainers.
## Setting Up Dev Environment
The **master** branch is the active development branch.
Building react-map-gl locally from the source requires node.js `>=8`.
We use [yarn](https://yarnpkg.com/en/docs/install) to manage the dependencies.
```bash
git checkout master
yarn bootstrap
yarn test
```
Test:
```bash
$ yarn test
```
Test in Node:
```bash
$ yarn test node
```
Test in browser (can use Chrome dev tools for debugging):
```bash
$ yarn test browser
```
## Pull Requests
Any intended change to the code base must open a [pull request](https://help.github.com/articles/creating-a-pull-request/) and be approved.
Generally speaking, all PRs are open against the `master` branch, unless the feature being affected no longer exists on master.
### PR Checklist
- [ ] Tests
- `yarn test` must be successful.
+ New code should be covered by unit tests whenever possible.
- [ ] Documentation
+ If public APIs are added/modified, update component documentation in `docs/api-reference`.
+ Breaking changes and deprecations must be added to `docs/upgrade-guide.md`.
+ Noteworthy new features should be added to `docs/whats-new.md`.
- [ ] Description on GitHub
+ Link to relevant issue.
+ Label with a milestone (latest release or vNext).
+ If public APIs are added/modified, describe the intended behavior.
+ If visual/interaction is affected, consider attaching a screenshot/GIF.
## Release
react-map-gl follows the [Semantic Versioning](https://semver.org/) guidelines. Steps for publishing releases can be found [here](https://www.github.com/visgl/tsc/tree/master/developer-process).
## Community Governance
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
react-map-gl development is governed by the vis.gl Technical Steering Committee (TSC).
### Maintainers
- [Xiaoji Chen](https://github.com/Pessimistress)
- [Xintong Xia](https://github.com/xintongxia)
Maintainers of react-map-gl have commit access to this GitHub repository, and take part in the decision making process.
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.
================================================
FILE: LICENSE
================================================
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
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
This contains code from MapboxGL-js
Copyright (c) 2014, Mapbox
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of Mapbox GL JS nor the names of its contributors
may be used to endorse or promote products derived from this software
without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-------------------------------------------------------------------------------
Contains code from Mapbox GL Style JSON
Mapbox Open Styles are copyright (c) 2014, Mapbox, all rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
================================================
FILE: README.md
================================================
react-map-gl | Docs
`react-map-gl` is a suite of [React](https://react.dev/) 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).
### Installation
Using `react-map-gl` requires `react >= 16.3`.
```sh
# Using Maplibre
npm install react-map-gl maplibre-gl
```
_or_
```sh
# Using Mapbox
npm install react-map-gl mapbox-gl
```
### Example
```js
// Using Maplibre
import * as React from 'react';
import Map from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return (
);
}
```
_or_
```js
// Using Mapbox
import * as React from 'react';
import Map from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
return (
);
}
```
Learn more with in our [Getting Started](https://visgl.github.io/react-map-gl/docs/get-started) guide.
### Contribute
See [contribution guide](/CONTRIBUTING.md).
### Attributions
react-map-gl is part of vis.gl, an [OpenJS Foundation](https://openjsf.org) project.
Development is also supported by
================================================
FILE: TESTING.md
================================================
# Testing
## Unit, Lint
```
npm run test
```
## Browser
```
npm run test-browser
```
**You'll need to specify a valid Mapbox Access Token in the URL** for the tests to pass.
```
http://localhost:8080/?access_token=MAPBOX_ACCESS_TOKEN
```
# Bumping Mapbox Version
Always pin Mapbox to a specific release.
The React controls (`NavigationControl`, `Popup` and `Marker`) are dependent on
the Mapbox stylesheet, and may be broken by Mapbox updates.
Always run `examples/controls` after bumping Mapbox version to make sure they
still work.
================================================
FILE: docs/.gitignore
================================================
api-reference/web-mercator-viewport.md
================================================
FILE: docs/README.md
================================================
# Introduction
> These docs are for v8.0. For v7, see [here](https://github.com/visgl/react-map-gl/tree/7.1-release/docs).
react-map-gl is a suite of [React](http://facebook.github.io/react/) components for
[mapbox-gl](https://www.npmjs.com/package/mapbox-gl), [maplibre-gl](https://www.npmjs.com/package/maplibre-gl) or compatible libraries.
| Library | Description |
| --- | --- |
| [MapLibre GL JS](https://maplibre.org/maplibre-gl-js/docs/) | An Open-source TypeScript library for publishing web maps. |
| [Mapbox GL JS](https://www.mapbox.com/mapbox-gljs) | A JavaScript library for interactive, customizable vector maps on the web. |
| [Mapbox GL JS v1](https://github.com/mapbox/mapbox-gl-js/tree/release-v1.13.3) | The last free-open-source version of Mapbox GL JS. This version can be used without a Mapbox token if you do not use Mapbox hosted basemaps. |
| Other compatible forks | It may be possible to use react-map-gl with mapbox-gl/maplibre-gl forks, but this is not a supported use case. Minor PRs to enable other forks to be used may be accepted. |
If you need help choosing a base map library that is right for you:
- Decide where to get your vector map data.
+ `mapbox-gl` is designed to work seamlessly with Mapbox's own data service. You will need a billable Mapbox token to use it.
+ There are a number of [map data providers](./get-started/mapbox-tokens.md#display-maps-without-a-mapbox-token) who support `maplibre-gl`, with a variaty of data quality and price options.
+ You can create and host your own map tiles and use them with `maplibre-gl` for (almost) free, if you are comfortable of using [open source tools](./get-started/mapbox-tokens.md#display-maps-without-a-mapbox-token) and setting up a cloud storage account.
- Visit Mapbox and MapLibre websites for examples and documentation. Each library offer unique features that may not exist in another.
New to react-map-gl? [Get Started](./get-started/get-started.md)
Want to contribute? See our [Developer Guide](./contributing.md)
## Design Philosophy
react-map-gl was first created by Uber's Visualization team, where Mapbox was used as a component to build powerful web tools such as [geospatial analytics](https://kepler.gl) and [self-driving data visualization](https://avs.auto/). To manage the complexity of these applications, we fully embrace React and reactive programming.
The stock mapbox-gl APIs are [imperative](https://en.wikipedia.org/wiki/Imperative_programming). That is, you instruct the map to do something (for example, [map.flyTo](https://docs.mapbox.com/mapbox-gl-js/api/#map#flyto)), and it will execute the command at its own pace.
This does not scale when we have many components that need to synchronize with each other. We sometimes render two maps side by side, and when the user interacts with one, update both cameras. We draw React UI outside of the map container, that moves with the camera. We also render WebGL graphic overlays on top of the map, most notably with [deck.gl](https://deck.gl). In these use cases, in order for all components to synchronize correctly, they must have their shared states managed by React. We might store the **source of truth** in a parent component state, or Redux store, or hooks, and let it propagate down to the map as well as its peers.
Ultimately, in the spirit of the [reactive programming paradigm](https://en.wikipedia.org/wiki/Reactive_programming), data always flows **down**. As long as the map manages its own state, as mapbox-gl is designed to do, we risk the components going out of sync.
react-map-gl creates a fully reactive wrapper for mapbox-gl/maplibre-gl. The [Map](./api-reference/maplibre/map.md) component can be fully [controlled](https://reactjs.org/docs/forms.html#controlled-components), that is, the map's camera would never deviate from the props that it's assigned. Read more about this core behavior in [state management](./get-started/state-management.md).
## Limitations
In v7.0, react-map-gl was fully rewritten to better align its API with the underlying Mapbox GL JS library. Wherever the reactive usage patterns permits, the wrapper's props and methods are 1:1 mappings to their native API equivelants.
It is possible to call the native methods directly from the `Map` instance obtained via [getMap](./api-reference/maplibre/map.md#gemap). However, doing so may result in the map's state to deviate from its props. For example, calling `map.setMaxZoom` directly will cause the map's constraint settings to differ from the value of the `maxZoom` prop. Generally speaking, calling a native method is disencouraged if the same thing can be achieved through the React interface. If a third-party plugin does so, then it may lead to some unexpected behaviors.
================================================
FILE: docs/api-reference/mapbox/attribution-control.md
================================================
# AttributionControl
React component that wraps mapbox-gl's [AttributionControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#attributioncontrol) class.
```tsx
import * as React from 'react';
import Map, {AttributionControl} from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Other Properties
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/classes/AttributionControl/)), such as
- `compact`
- `customAttribution`
Plus the following:
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'bottom-right'`
Placement of the control relative to the map.
## Source
[attribution-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/attribution-control.ts)
================================================
FILE: docs/api-reference/mapbox/fullscreen-control.md
================================================
# FullscreenControl
React component that wraps mapbox-gl's [FullscreenControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#fullscreencontrol) class.
```tsx
import * as React from 'react';
import Map, {FullscreenControl} from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
#### `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}
Default: `'top-right'`
Placement of the control relative to the map.
## Source
[fullscreen-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/fullscreen-control.ts)
================================================
FILE: docs/api-reference/mapbox/geolocate-control.md
================================================
# GeolocateControl
React component that wraps mapbox-gl's [GeolocateControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol) class.
```tsx
import * as React from 'react';
import Map, {GeolocateControl} from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Callbacks
#### `onGeolocate`: (evt: [GeolocateResultEvent](./types.md#geolocateresultevent)) => void {#ongeolocate}
Called on each Geolocation API position update that returned as success.
#### `onError`: (evt: [GeolocateErrorEvent](./types.md#geolocateerrorevent)) => void {#onerror}
Called on each Geolocation API position update that returned as an error.
#### `onOutOfMaxBounds`: (evt: [GeolocateResultEvent](./types.md#geolocateresultevent)) => void {#onoutofmaxbounds}
Called on each Geolocation API position update that returned as success but user position is out of map `maxBounds`.
#### `onTrackUserLocationStart`: (evt: [GeolocateEvent](./types.md#geolocateevent)) => void {#ontrackuserlocationstart}
Called when the GeolocateControl changes to the active lock state.
#### `onTrackUserLocationEnd`: (evt: [GeolocateEvent](./types.md#geolocateevent)) => void {#ontrackuserlocationend}
Called when the GeolocateControl changes to the background state.
### Other Properties
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/classes/GeolocateControl/)), such as
- `positionOptions`
- `fitBoundsOptions`
- `trackUserLocation`
- `showAccuracyCircle`
- `showUserLocation`
Plus the following:
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'bottom-right'`
Placement of the control relative to the map.
## Methods
The underlying native `GeolocateControl` instance is accessible via a [React ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) hook.
You may use it to call any imperative methods:
```tsx
import * as React from 'react';
import {useRef, useEffect} from 'react';
import Map, {GeolocateControl} from 'react-map-gl/mapbox';
import type mapboxgl from 'mapbox-gl';
function App() {
const geoControlRef = useRef();
useEffect(() => {
// Activate as soon as the control is loaded
geoControlRef.current?.trigger();
}, [geoControlRef.current]);
return ;
}
```
## Source
[geolocate-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/geolocate-control.ts)
================================================
FILE: docs/api-reference/mapbox/layer.md
================================================
# Layer
This component allows apps to create a [map layer](https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers) using React.
```tsx
import * as React from 'react';
import Map, {Layer} from 'react-map-gl/mapbox';
import type {FillLayer} from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
const parkLayer: FillLayer = {
id: 'landuse_park',
type: 'fill',
source: 'mapbox',
'source-layer': 'landuse',
filter: ['==', 'class', 'park'],
paint: {
'fill-color': '#4E3FC8'
}
};
function App() {
return ;
}
```
## Properties
The props provided to this component should be conforming to the [Mapbox layer specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/#layers).
When props change *shallowly*, the component will perform style diffing to update the layer. Avoid defining constant objects/arrays inline may help performance.
### Identity Properties
Once a `` is mounted, the following props should not change. If you add/remove multiple JSX layers dynamically, make sure you use React's [key prop](https://reactjs.org/docs/lists-and-keys.html#keys) to give each element a stable identity.
#### `id`: string {#id}
Unique identifier of the layer. If not provided, a default id will be assigned.
#### `type`: string {#type}
Required. Type of the layer.
### Options
#### `beforeId`: string {#beforeid}
The ID of an existing layer to insert this layer before. If this prop is omitted, the layer will be appended to the end of the layers array. This is useful when using dynamic layers with a map style from a URL.
Note that layers are added by the order that they mount. They are *NOT* reordered later if their relative positions in the JSX tree change. If dynamic reordering is desired, you should manipulate `beforeId` for consistent behavior.
#### `source`: string {#source}
`source` is required by some layer types in the Mapbox style specification. If `` is used as the immediate child of a [Source](./source.md) component, this prop will be overwritten by the id of the parent source. If the `` component is not an immediate descendant of ``, e.g wrapped inside a helper component, source property needs to be provided same as the id of the `` component for the `` component to show.
## Source
[layer.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/layer.ts)
================================================
FILE: docs/api-reference/mapbox/map-provider.md
================================================
# MapProvider
A [Context.Provider](https://reactjs.org/docs/context.html#contextprovider) that facilitates map operations outside of the component that directly renders a [Map](./map.md).
The component should wrap all nodes in which you may want to access the maps:
```tsx
import {MapProvider} from 'react-map-gl/mapbox';
function Root() {
return (
{
// Application tree, somewhere one or more component(s) are rendered
}
);
}
```
See [useMap](./use-map.md) for more information.
## Source
[use-map.tsx](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/use-map.tsx)
================================================
FILE: docs/api-reference/mapbox/map.md
================================================
# default (Map)
React component that wraps mapbox-gl's [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/) class. This is also the default export from react-map-gl.
```tsx title="app.tsx"
import * as React from 'react';
import Map from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
return (
);
}
```
## 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/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
#### `id`: string {#id}
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%'}`
Map container CSS.
#### `cursor`: string {#cursor}
Default: `'auto'`
The current cursor [type](https://developer.mozilla.org/en-US/docs/Web/CSS/cursor).
### Styling options
#### `fog`: [Fog](./types.md#fog) {#fog}
The fog property of the style. Must conform to the [Fog Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/fog/).
If `undefined` is provided, removes the fog from the map.
#### `light`: [Light](./types.md#light) {#light}
Light properties of the style. Must conform to the [Light Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#light).
#### `mapStyle`: [MapStyle](./types.md#mapstyle) | string | Immutable {#mapstyle}
Default: (empty style)
The map's Mapbox style. This must be an a JSON object conforming to the schema described in the [Mapbox Style Specification](https://mapbox.com/mapbox-gl-style-spec/), or a URL to such JSON.
#### `projection`: string | [Projection](./types.md#projection) {#projection}
Default: `'mercator'`
The projection the map should be rendered in. Available projections are Albers (`'albers'`), Equal Earth (`'equalEarth'`), Equirectangular/Plate Carrée/WGS84 (`'equirectangular'`), Lambert (`'lambertConformalConic'`), Mercator (`'mercator'`), Natural Earth (`'naturalEarth'`), and Winkel Tripel (`'winkelTripel'`). Conic projections such as Albers and Lambert have configurable `center` and `parallels` properties that allow developers to define the region in which the projection has minimal distortion; see [example](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#setprojection).
#### `renderWorldCopies`: boolean {#renderworldcopies}
Default: `true`
If `true`, multiple copies of the world will be rendered, when zoomed out.
#### `styleDiffing`: boolean {#stylediffing}
Default: `true`
Enable diffing when `mapStyle` changes. If `false`, force a 'full' update, removing the current style and building the given one instead of attempting a diff-based update.
#### `terrain`: [Terrain](./types.md#terrain) {#terrain}
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}
The initial view state of the map. If specified, `longitude`, `latitude`, `zoom` etc. in props are ignored when constructing the map. Only specify `initialViewState` if `Map` is being used as an **uncontrolled component**. See [state management](../../get-started/state-management.md) for examples.
- `bounds`: [LngLatBoundsLike](./types.md#lnglatboundslike) - The initial bounds of the map. If specified, it overrides the `longitude`, `latitude` and `zoom` options. Default `null`.
- `fitBoundsOptions` - An object to use only when setting the `bounds` option. Default `null`.
+ `fitBoundsOptions.offset`: [PointLike](./types.md#pointlike)
+ `fitBoundsOptions.minZoom`: number
+ `fitBoundsOptions.maxZoom`: number
+ `fitBoundsOptions.padding`: [PaddingOptions](./types.md#paddingoptions)
- `longitude`: number - The initial longitude of the map center. Default `0`.
- `latitude`: number - The initial latitude of the map center. Default `0`.
- `zoom`: number - The initial zoom level. Default `0`.
- `pitch`: number - The initial pitch (tilt) of the map. Default `0`.
- `bearing`: number - The initial bearing (rotation) of the map. Default `0`.
#### `longitude`: number {#longitude}
The longitude of the map center.
#### `latitude`: number {#latitude}
The latitude of the map center.
#### `zoom`: number {#zoom}
The [zoom level](https://docs.mapbox.com/help/glossary/camera/#zoom-level) of the map.
#### `pitch`: number {#pitch}
The initial [pitch](https://docs.mapbox.com/help/glossary/camera/#pitch) (tilt) of the map, measured in degrees away from the plane of the screen (0-85).
#### `bearing`: number {#bearing}
The initial [bearing](https://docs.mapbox.com/help/glossary/camera/#bearing) (rotation) of the map, measured in degrees counter-clockwise from north.
#### `padding`: [PaddingOptions](./types.md#paddingoptions) {#padding}
Default: `null`
The padding in pixels around the viewport.
#### `minZoom`: number {#minzoom}
Default: `0`
The minimum zoom level of the map (0-24).
#### `maxZoom`: number {#maxzoom}
Default: `22`
The maximum zoom level of the map (0-24).
#### `minPitch`: number {#minpitch}
Default: `0`
The minimum pitch of the map (0-85).
#### `maxPitch`: number {#maxpitch}
Default: `60`
The maximum pitch of the map (0-85).
#### `maxBounds`: [LngLatBoundsLike](./types.md#lnglatboundslike) {#maxbounds}
Default: `null`
If set, the map is constrained to the given bounds.
### Input handler options
#### `boxZoom`: boolean {#boxzoom}
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/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/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/DragRotateHandler/)).
#### `dragPan`: boolean | Object {#dragpan}
Default: `true`
If `true`, the "drag to pan" interaction is enabled. Optionally accept 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/KeyboardHandler/)).
#### `scrollZoom`: boolean | Object {#scrollzoom}
Default: `true`
If `true`, the "scroll to zoom" interaction is enabled. Optionally accept 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 accept 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 accept 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}
Default: `null`
The id(s) of style layer(s).
If specified, pointer event (`mousemove`, `click` etc.) listeners will be triggered only if its location is within a visible feature in these layers, and the event will have a `features` property containing an array of the matching features.
If not specified, pointer event listeners will be triggered by a corresponding event happening anywhere on the map, and the event will not have a `features` property.
See the [Callbacks](#callbacks) section for affected events.
### Callbacks
#### `onResize`: (event: [MapEvent](./types.md#mapevent)) => void {#onresize}
Called when the map has been resized.
#### `onLoad`: (event: [MapEvent](./types.md#mapevent)) => void {#onload}
Called after all necessary resources have been downloaded and the first visually complete rendering of the map has occurred.
#### `onRender`: (event: [MapEvent](./types.md#mapevent))) => void {#onrender}
Called whenever the map is drawn to the screen.
#### `onIdle`: (event: [MapEvent](./types.md#mapevent))) => void {#onidle}
Called after the last frame rendered before the map enters an "idle" state:
- No camera transitions are in progress
- All currently requested tiles have loaded
- All fade/transition animations have completed
#### `onRemove`: (event: [MapEvent](./types.md#mapevent))) => void {#onremove}
Called when the map has been removed.
#### `onError`: (event: [ErrorEvent](./types.md#errorevent)) => void {#onerror}
Default: `evt => console.error(evt.error)`
Called when an error occurs.
#### `onMouseDown`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmousedown}
Called when a pointing device (usually a mouse) is pressed within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onMouseUp`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseup}
Called when a pointing device (usually a mouse) is released within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onMouseOver`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseover}
Called when a pointing device (usually a mouse) is moved within the map. As you move the cursor across a web page containing a map, the event will fire each time it enters the map or any child elements.
#### `onMouseEnter`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseenter}
Called when a pointing device (usually a mouse) enters a visible portion of the layer(s) specified by `interactiveLayerIds` from outside that layer or outside the map canvas.
#### `onMouseMove`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmousemove}
Called when a pointing device (usually a mouse) is moved while the cursor is inside the map. As you move the cursor across the map, the event will fire every time the cursor changes position within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onMouseLeave`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseleave}
Called when a pointing device (usually a mouse) leaves a visible portion of the layer(s) specified by `interactiveLayerIds` or moves from the layer to outside the map canvas.
#### `onMouseOut`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseout}
Called when a point device (usually a mouse) leaves the map's canvas.
#### `onClick`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onclick}
Called when a pointing device (usually a mouse) is pressed and released at the same point on the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onDblClick`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#ondblclick}
Called when a pointing device (usually a mouse) is pressed and released twice at the same point on the map in rapid succession.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onContextMenu`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#oncontextmenu}
Called when the right button of the mouse is clicked or the context menu key is pressed within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onWheel`: (event: [MapWheelEvent](./types.md#mapwheelevent)) => void {#onwheel}
Called when a wheel event occurs within the map.
#### `onTouchStart`: (event: [MapLayerTouchEvent](./types.md#maplayertouchevent)) => void {#ontouchstart}
Called when a `touchstart` event occurs within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onTouchEnd`: (event: [MapLayerTouchEvent](./types.md#maplayertouchevent)) => void {#ontouchend}
Called when a `touchend` event occurs within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onTouchMove`: (event: [MapLayerTouchEvent](./types.md#maplayertouchevent)) => void {#ontouchmove}
Called when a `touchmove` event occurs within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onTouchCancel`: (event: [MapLayerTouchEvent](./types.md#maplayertouchevent)) => void {#ontouchcancel}
Called when a `touchcancel` event occurs within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layers.
#### `onMoveStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onmovestart}
Called just before the map begins a transition from one view to another.
#### `onMove`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onmove}
Called repeatedly during an animated transition from one view to another.
When `Map` is used as a controlled component, `event.viewState` reflects the view state that the camera "proposes" to move to, as a result of either user interaction or methods such as [flyTo](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#flyto). The camera does not actually change until the application updates the view state props (`longitude`, `latitude`, `zoom` etc.).
See [state management](../../get-started/state-management.md) for examples.
#### `onMoveEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onmoveend}
Called just after the map completes a transition from one view to another.
#### `onDragStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#ondragstart}
Called when a "drag to pan" interaction starts.
#### `onDrag`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#ondrag}
Called repeatedly during a "drag to pan" interaction.
#### `onDragEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#ondragend}
Called when a "drag to pan" interaction ends.
#### `onZoomStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onzoomstart}
Called just before the map begins a transition from one zoom level to another.
#### `onZoom`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onzoom}
Called repeatedly during an animated transition from one zoom level to another.
When `Map` is used as a controlled component, `event.viewState.zoom` reflects the zoom that the camera "proposes" to change to, as a result of either user interaction or methods such as [flyTo](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#flyto). The camera does not actually change until the application updates the `zoom` prop.
#### `onZoomEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onzoomend}
Called just after the map completes a transition from one zoom level to another.
#### `onRotateStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onrotatestart}
Called just before the map begins a transition from one bearing (rotation) to another.
#### `onRotate`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onrotate}
Called repeatedly during an animated transition from one bearing (rotation) to another.
When `Map` is used as a controlled component, `event.viewState.bearing` reflects the zoom that the camera "proposes" to change to, as a result of either user interaction or methods such as [flyTo](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#flyto). The camera does not actually change until the application updates the `bearing` prop.
#### `onRotateEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onrotateend}
Called just after the map completes a transition from one bearing (rotation) to another.
#### `onPitchStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onpitchstart}
Called just before the map begins a transition from one pitch (tilt) to another.
#### `onPitch`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onpitch}
Called repeatedly during an animated transition from one pitch (tilt) to another.
When `Map` is used as a controlled component, `event.viewState.pitch` reflects the zoom that the camera "proposes" to change to, as a result of either user interaction or methods such as [flyTo](https://docs.mapbox.com/mapbox-gl-js/api/map/#map#flyto). The camera does not actually change until the application updates the `pitch` prop.
#### `onPitchEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onpitchend}
Called just after the map completes a transition from one pitch (tilt) to another.
#### `onBoxZoomStart`: (event: [MapBoxZoomEvent](./types.md#mapboxzoomevent)) => void {#onboxzoomstart}
Called when a "box zoom" interaction starts.
#### `onBoxZoomEnd`: (event: [MapBoxZoomEvent](./types.md#mapboxzoomevent)) => void {#onboxzoomend}
Called when a "box zoom" interaction ends.
#### `onBoxZoomCancel`: (event:[MapBoxZoomEvent](./types.md#mapboxzoomevent)) => void {#onboxzoomcancel}
Called when the user cancels a "box zoom" interaction, or when the bounding box does not meet the minimum size threshold.
#### `onData`: (event: [MapStyleDataEvent](./types.md#mapstyledataevent) | [MapSourceDataEvent](./types.md#mapsourcedataevent)) => void {#ondata}
Called when any map data loads or changes. See [MapDataEvent](https://docs.mapbox.com/mapbox-gl-js/api/events/#mapdataevent) for more information.
#### `onStyleData`: (event: [MapStyleDataEvent](./types.md#mapstyledataevent)) => void {#onstyledata}
Called when the map's style loads or changes. See [MapDataEvent](https://docs.mapbox.com/mapbox-gl-js/api/events/#mapdataevent) for more information.
#### `onSourceData`: (event: [MapSourceDataEvent](./types.md#mapsourcedataevent)) => void {#onsourcedata}
Called when one of the map's sources loads or changes, including if a tile belonging to a source loads or changes. See [MapDataEvent](https://docs.mapbox.com/mapbox-gl-js/api/events/#mapdataevent) for more information.
### 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/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`
Specify the underlying base map library for the Map component. The value can be provided with several options:
By module import (and embedding in the final bundle):
```tsx
import * as React from 'react';
import Map from 'react-map-gl/mapbox';
import mapboxgl from 'mapbox-gl';
function App() {
return ;
}
```
By dynamic import (thus enable bundle splitting):
```tsx
import * as React from 'react';
import Map from 'react-map-gl/mapbox';
function App() {
return ;
}
```
Or to load a pre-bundled version of the library:
```html title="index.html"
```
```tsx title="app.tsx"
import * as React from 'react';
import Map from 'react-map-gl/mapbox';
function App() {
return ;
}
```
#### `mapboxAccessToken`: string {#mapboxaccesstoken}
Token used to access the Mapbox data service. See [about map tokens](../../get-started/mapbox-tokens.md).
#### `baseApiUrl`: string {#baseapiurl}
The map's default API URL for requesting tiles, styles, sprites, and glyphs.
#### `maxParallelImageRequests`: number {#maxparallelimagerequests}
Default: `16`
The maximum number of images (raster tiles, sprites, icons) to load in parallel.
#### `reuseMaps`: boolean {#reusemaps}
Default: `false`
By default, every time a map component is unmounted, all internal resources associated with the underlying `Map` instance are released. If the map gets mounted again, a new `Map` instance is constructed.
If `reuseMaps` is set to `true`, when a map component is unmounted, the underlying `Map` instance is retained in memory. The next time a map component gets mounted, the saved instance is reused. This behavior may be desirable if an application frequently mounts/unmounts map(s), for example in a tabbed or collapsable UI, and wants to avoid Mapbox's [billable events](https://github.com/mapbox/mapbox-gl-js/releases/tag/v2.0.0) triggered by initialization.
Note that since some map options cannot be modified after initialization, when reusing maps, only the reactive props and `initialViewState` of the new component are respected.
#### `RTLTextPlugin`: string | false {#rtltextplugin}
Default: `'https://api.mapbox.com/mapbox-gl-js/plugins/mapbox-gl-rtl-text/v0.2.3/mapbox-gl-rtl-text.js'`
Sets the map's [RTL text plugin](https://www.mapbox.com/mapbox-gl-js/plugins/#mapbox-gl-rtl-text). Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left.
Setting this prop is the equivalent of calling [mapboxgl.setRTLTextPlugin](https://docs.mapbox.com/mapbox-gl-js/api/properties/#setrtltextplugin) with `lazy: true`. Set to `false` to disable loading the RTL text plugin.
#### `workerClass`: object {#workerclass}
Default: `null`
Provides an interface for external module bundlers such as Webpack or Rollup to package mapbox-gl's WebWorker into a separate class and integrate it with the library.
Takes precedence over `workerUrl`.
#### `workerCount`: number {#workercount}
Default: `2`
The number of web workers instantiated on a page with mapbox-gl maps.
#### `workerUrl`: string {#workerurl}
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.
```tsx
import * as React from 'react';
import {useRef, useCallback} from 'react';
import Map from 'react-map-gl/mapbox';
import type {MapRef} from 'react-map-gl/mapbox';
function App() {
const mapRef = useRef(null);
const onMapLoad = useCallback(() => {
mapRef.current.on('move', () => {
// do something
});
}, []);
return ;
}
```
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/classes/Map/)) instance associated with this component.
## Source
[map.tsx](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/map.tsx)
================================================
FILE: docs/api-reference/mapbox/marker.md
================================================
# Marker
React component that wraps mapbox-gl's [Marker](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker) class.
```tsx
import * as React from 'react';
import Map, {Marker} from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
return ;
}
```
If `Marker` is mounted with child components, then its content will be rendered to the specified location. If it is mounted with no content, then a default marker will be used.
## Properties
### Reactive Properties
#### `draggable`: boolean {#draggable}
Default: `false`
If `true`, the marker is able to be dragged to a new position on the map.
#### `latitude`: number {#latitude}
Required. The latitude of the anchor location.
#### `longitude`: number {#longitude}
Required. The longitude of the anchor location.
#### `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}
Default: `'auto'`
- `map` aligns the `Marker` to the plane of the map.
- `viewport` aligns the `Marker` to the plane of the viewport.
- `auto` automatically matches the value of `rotationAlignment`.
#### `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/classes/Popup/)) to attach to this marker. If undefined or null, any popup set on this Marker instance is unset.
#### `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}
Default: `'auto'`
- `map` aligns the `Marker`'s rotation relative to the map, maintaining a bearing as the map rotates.
- `viewport` aligns the `Marker`'s rotation relative to the viewport, agnostic to map rotations.
- `auto` is equivalent to `viewport`.
#### `style`: CSSProperties {#style}
CSS style override that applies to the marker's container.
### Callbacks
#### `onClick`: (evt: [MapEvent](./types.md#mapevent)) => void {#onclick}
Called when the marker is clicked on.
#### `onDragStart`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondragstart}
Called when dragging starts, if `draggable` is `true`.
#### `onDrag`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondrag}
Called while dragging, if `draggable` is `true`.
#### `onDragEnd`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondragend}
Called when dragging ends, if `draggable` is `true`.
### Other Properties
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/type-aliases/MarkerOptions/)), such as
- `anchor`
- `color`
- `scale`
- `clickTolerance`
## Methods
The underlying native `Marker` instance is accessible via a [React ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) hook.
You may use it to call any imperative methods:
```tsx
import * as React from 'react';
import {useRef, useMemo, useCallback} from 'react';
import Map, {Marker} from 'react-map-gl/mapbox';
import mapboxgl from 'mapbox-gl';
function App() {
const markerRef = useRef();
const popup = useMemo(() => {
return mapboxgl.Popup().setText('Hello world!');
}, [])
const togglePopup = useCallback(() => {
markerRef.current?.togglePopup();
}, []);
return <>
>;
}
```
## Source
[marker.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/marker.ts)
================================================
FILE: docs/api-reference/mapbox/navigation-control.md
================================================
# NavigationControl
React component that wraps mapbox-gl's [NavigationControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#navigationcontrol) class.
```tsx
import * as React from 'react';
import Map, {NavigationControl} from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Other Properties
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/type-aliases/NavigationControlOptions/)), such as
- `showCompass`
- `showZoom`
- `visualizePitch`
Plus the following:
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'top-right'`
Placement of the control relative to the map.
## Source
[navigation-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/navigation-control.ts)
================================================
FILE: docs/api-reference/mapbox/popup.md
================================================
# Popup
React component that wraps mapbox-gl's [Popup](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup) class.
```tsx
import * as React from 'react';
import {useState} from 'react';
import Map, {Popup} from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
const [showPopup, setShowPopup] = useState(true);
return ;
}
```
## Properties
### Reactive Properties
#### `anchor`: 'center' | 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | undefined {#anchor}
A string indicating the part of the popup that should be positioned closest to the coordinate, set via `longitude` and `latitude`.
If unset, the anchor will be dynamically set to ensure the popup falls within the map container with a preference for `'bottom'`.
#### `className`: string {#classname}
Space-separated CSS class names to add to popup container.
#### `offset`: number | [PointLike](./types.md#pointlike) | Record\ {#offset}
Default: `null`
A pixel offset applied to the popup's location specified as:
- a single number specifying a distance from the popup's location
- a PointLike specifying a constant offset
- an object of Points specifing an offset for each anchor position.
Negative offsets indicate left and up.
#### `maxWidth`: string {#maxwidth}
Default: `240px`
A string that sets the CSS property of the popup's maximum width.
#### `style`: CSSProperties {#style}
CSS style override that applies to the popup's container.
### Callbacks
#### `onOpen`: (evt: [PopupEvent](./types.md#popupevent)) => void {#onopen}
Called when the popup is opened.
#### `onClose`: (evt: [PopupEvent](./types.md#popupevent)) => void {#onclose}
Called when the popup is closed by the user clicking on the close button or outside (if `closeOnClick: true`).
### Other Properties
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/type-aliases/PopupOptions/)), such as
- `closeButton`
- `closeOnClick`
- `closeOnMove`
- `focusAfterOpen`
## Methods
The underlying native `Popup` instance is accessible via a [React ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) hook.
You may use it to call any imperative methods:
```tsx
import * as React from 'react';
import {useRef, useEffect} from 'react';
import Map, {Popup} from 'react-map-gl/mapbox';
import mapboxgl from 'mapbox-gl';
function App() {
const popupRef = useRef();
useEffect(() => {
popupRef.current?.trackPointer();
}, [popupRef.current])
return ;
}
```
## Source
[popup.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/popup.ts)
================================================
FILE: docs/api-reference/mapbox/scale-control.md
================================================
# ScaleControl
React component that wraps mapbox-gl's [ScaleControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#scalecontrol) class.
```tsx
import * as React from 'react';
import Map, {ScaleControl} from 'react-map-gl/mapbox';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `maxWidth`: string {#maxwidth}
Default: `100`
The maximum length of the scale control in pixels.
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
#### `unit`: 'imperial' | 'metric' | 'nautical' {#unit}
Default: `'metric'`
Unit of the distance.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'top-right'`
Placement of the control relative to the map.
## Source
[scale-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/scale-control.ts)
================================================
FILE: docs/api-reference/mapbox/source.md
================================================
# Source
This component allows apps to create a [map source](https://docs.mapbox.com/mapbox-gl-js/style-spec/#sources) using React. It may contain [Layer](./layer.md) components as children.
```tsx
import * as React from 'react';
import Map, {Source, Layer} from 'react-map-gl/mapbox';
import type {CircleLayer} from 'react-map-gl/mapbox';
import type {FeatureCollection} from 'geojson';
import 'mapbox-gl/dist/mapbox-gl.css';
const geojson: FeatureCollection = {
type: 'FeatureCollection',
features: [
{type: 'Feature', geometry: {type: 'Point', coordinates: [-122.4, 37.8]}}
]
};
const layerStyle: CircleLayer = {
id: 'point',
type: 'circle',
paint: {
'circle-radius': 10,
'circle-color': '#007cbf'
}
};
function App() {
return ;
}
```
## Properties
The props provided to this component should be conforming to the [Mapbox source specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/#sources) or [CanvasSourceOptions](https://docs.mapbox.com/mapbox-gl-js/api/#canvassourceoptions).
When props change _shallowly_, the component will attempt to update the source. Do not define objects/arrays inline to avoid perf hit.
Once a `` is mounted, the following props should not change. If add/remove multiple JSX sources dynamically, make sure you use React's [key prop](https://reactjs.org/docs/lists-and-keys.html#keys) to give each element a stable identity.
#### `id`: string {#id}
Unique identifier of the source. If not provided, a default id will be assigned.
#### `type`: string {#type}
Required. Type of the source.
## Source
[source.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/source.ts)
================================================
FILE: docs/api-reference/mapbox/types.md
================================================
# Types
The following types can be imported from `react-map-gl/mapbox` when using TypeScript.
## Components
#### IControl
A [custom control implementation](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol).
#### CustomLayerInterface
A [custom layer implementation](https://docs.mapbox.com/mapbox-gl-js/api/#customlayerinterface).
#### MapRef
Instance [ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) of a `Map` component. See [Map documentation](./map.md#methods) for details.
## Styling
#### StyleSpecification
An object conforming to the [Mapbox Style Specification](https://mapbox.com/mapbox-gl-style-spec/).
#### FogSpecification
An object conforming to the [Fog Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/fog/).
#### LightSpecification
An object conforming to the [Light Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#light).
#### TerrainSpecification
An object conforming to the [Terrain Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/terrain/).
#### ProjectionSpecification
An object conforming to the [Projection Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/projection/).
#### BackgroundLayerSpecification
A JSON object that defines a `background` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#background).
#### CircleLayerSpecification
A JSON object that defines a `circle` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#circle).
#### FillExtrusionLayerSpecification
A JSON object that defines a `fill-extrusion` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#fill-extrusion).
#### FillLayerSpecification
A JSON object that defines a `fill` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#fill).
#### HeatmapLayerSpecification
A JSON object that defines a `heatmap` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#heatmap).
#### HillshadeLayerSpecification
A JSON object that defines a `hillshade` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#hillshade).
#### LineLayerSpecification
A JSON object that defines a `line` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#line).
#### RasterLayerSpecification
A JSON object that defines a `raster` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#raster).
#### SymbolLayerSpecification
A JSON object that defines a `symbol` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#symbol).
#### SkyLayerSpecification
A JSON object that defines a `sky` layer according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/layers/#sky).
#### GeoJSONSourceSpecification
A JSON object that defines a `geojson` source according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#geojson).
#### VideoSourceSpecification
A JSON object that defines a `video` source according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#video).
#### ImageSourceSpecification
A JSON object that defines a `image` source according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#image).
#### VectorSourceSpecification
A JSON object that defines a `vector` source according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#vector).
#### RasterSourceSpecification
A JSON object that defines a `raster` source according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#raster).
#### RasterDEMSourceSpecification
A JSON object that defines a `raster-dem` source according to the [Mapbox Style Specification](https://docs.mapbox.com/mapbox-gl-js/style-spec/sources/#raster-dem).
#### CanvasSourceSpecification
A JSON object that defines a `canvas` source type. See [CanvasSourceOptions](https://docs.mapbox.com/mapbox-gl-js/api/sources/#canvassourceoptions).
## Configurations
#### ControlPosition
One of `'top-right'`, `'top-left'`, `'bottom-right'` and `'bottom-left'`.
#### PaddingOptions
An object with the following fields:
- `left`: number - in pixels.
- `top`: number - in pixels.
- `right`: number - in pixels.
- `bottom`: number - in pixels.
## Data Types
#### LngLat
A Mapbox [LngLat](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglat) object.
#### LngLatLike
A Mapbox [LngLatLike](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglatlike) object.
#### LngLatBounds
A Mapbox [LngLatBounds](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglatbounds) object.
#### LngLatBoundsLike
A Mapbox [LngLatBoundsLike](https://docs.mapbox.com/mapbox-gl-js/api/geography/#lnglatboundslike) object.
#### Point
A Mapbox [Point](https://docs.mapbox.com/mapbox-gl-js/api/geography/#point) object.
#### PointLike
A Mapbox [PointLike](https://docs.mapbox.com/mapbox-gl-js/api/geography/#pointlike) object.
#### MapGeoJSONFeature
A [GeoJSON](http://geojson.org/) feature that also contains the following library-specific fields:
- `layer`: Layer
- `source`: string
- `sourceLayer`: string
- `state`: `{ [key: string]: any }`
#### ViewState
An object with the following fields:
- `longitude`: number - The longitude of the map center.
- `latitude`: number - The latitude of the map center.
- `zoom`: number - The zoom level.
- `pitch`: number - The pitch (tilt) of the map, in degrees.
- `bearing`: number - The bearing (rotation) of the map, in degrees.
- `elevation`: number|undefined - The map center elevation from sea leavel on terrain surface, if any
## Events
#### MapEvent
An object with the following fields:
- `type`: string - Event type
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `originalEvent?`: [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event)
#### MapLayerMouseEvent
An object with the following fields:
- `type`: string
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `originalEvent?`: [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)
- `point`: [Point](#point)
- `lngLat`: [LngLat](#lnglat)
- `preventDefault`: () => void
- `defaultPrevented`: boolean
- `features?`: [MapGeoJSONFeature](#mapgeojsonfeature)[]
#### MapWheelEvent
An object with the following fields:
- `type`: string
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `originalEvent?`: [WheelEvent](https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent)
- `preventDefault`: () => void
- `defaultPrevented`: boolean
#### MapLayerTouchEvent
An object with the following fields:
- `type`: string
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `originalEvent?`: [TouchEvent](https://developer.mozilla.org/en-US/docs/Web/API/TouchEvent)
- `point`: [Point](#point)
- `lngLat`: [LngLat](#lnglat)
- `points`: [Point](#point)[]
- `lngLats`: [LngLat](#lnglat)[]
- `preventDefault`: () => void
- `defaultPrevented`: boolean
- `features?`: [MapGeoJSONFeature](#mapgeojsonfeature)[]
#### ViewStateChangeEvent
An object with the following fields:
- `type`: string - Event type
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `viewState`: [ViewState](#viewstate) - the next view state that the camera wants to change to based on user input or transition.
#### MapBoxZoomEvent
An object with the following fields:
- `type`: string
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `originalEvent?`: [MouseEvent](https://developer.mozilla.org/en-US/docs/Web/API/MouseEvent)
- `boxZoomBounds`: [LngLatBounds](#lnglatbounds)
#### MapStyleDataEvent
An object with the following fields:
- `type`: string
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `dataType`: 'style'
#### MapSourceDataEvent
An object with the following fields:
- `type`: string
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `dataType`: 'source'
- `isSourceLoaded`: boolean
- `source`: string
- `sourceId`: string
- `sourceDataType`: 'metadata' | 'content'
- `tile`: any
- `coord`: Coordinate
See [MapDataEvent](https://docs.mapbox.com/mapbox-gl-js/api/events/#mapdataevent).
#### ErrorEvent
An object with the following fields:
- `type`: 'error'
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `error`: [Error](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error)
#### GeolocateEvent
An object with the following fields:
- `type`: string
- `target`: [Map](https://docs.mapbox.com/mapbox-gl-js/api/map/)
- `target`: [GeolocateControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#geolocatecontrol)
#### GeolocateResultEvent
An object with the following fields:
- `type`: string
- `target`: [GeolocateControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#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.
#### GeolocateErrorEvent
An object with the following fields:
- `type`: string
- `target`: [GeolocateControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#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.
#### MarkerEvent
An object with the following fields:
- `type`: string
- `target`: [Marker](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker)
#### MarkerDragEvent
An object with the following fields:
- `type`: string
- `target`: [Marker](https://docs.mapbox.com/mapbox-gl-js/api/markers/#marker)
- `lngLat`: [LngLat](#lnglat) - the new location of the marker
#### PopupEvent
An object with the following fields:
- `type`: string
- `target`: [Popup](https://docs.mapbox.com/mapbox-gl-js/api/markers/#popup)
================================================
FILE: docs/api-reference/mapbox/use-control.md
================================================
# useControl
The `useControl` hook is used to create React wrappers for custom map controls.
```tsx
import MapboxDraw from '@mapbox/mapbox-gl-draw';
import Map, {useControl} from 'react-map-gl/mapbox';
function DrawControl(props: DrawControlProps) {
useControl(() => new MapboxDraw(props), {
position: props.position
});
return null;
}
function App() {
return (
);
}
```
See a full example [here](/examples/mapbox/draw-polygon).
## Signature
```js
useControl(
onCreate: ({map: MapRef, mapLib: mapboxgl}) => IControl,
options?: {
position?: ControlPosition;
}
): T
useControl(
onCreate: ({map: MapRef, mapLib: mapboxgl}) => IControl,
onRemove: ({map: MapRef, mapLib: mapboxgl}) => void,
options?: {
position?: ControlPosition;
}
): T
useControl(
onCreate: ({map: MapRef, mapLib: mapboxgl}) => IControl,
onAdd: ({map: MapRef, mapLib: mapboxgl}) => void,
onRemove: ({map: MapRef, mapLib: mapboxgl}) => void,
options?: {
position?: ControlPosition;
}
): T
```
The hook creates an [IControl](https://docs.mapbox.com/mapbox-gl-js/api/markers/#icontrol) instance, adds it to the map when it's available, and removes it upon unmount.
Parameters:
- `onCreate`: (`{map: MapRef, mapLib: mapboxgl}`) => [IControl](./types.md#icontrol) - called to create an instance of the control.
- `onAdd`: (`{map: MapRef, mapLib: mapboxgl}`) => void - called when the control has been added to the map.
- `onRemove`: (`{map: MapRef, mapLib: mapboxgl}`) => void - called when the control is about to be removed from the map.
- `options`: object
+ `position`: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' - control position relative to the map
Returns:
[IControl](./types.md#icontrol) - the control instance from `onCreate`.
## Source
[use-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/use-control.ts)
================================================
FILE: docs/api-reference/mapbox/use-map.md
================================================
# useMap
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.
```tsx
import {Map, useMap} from 'react-map-gl/mapbox';
function Root() {
return (
);
}
function NavigateButton() {
const {current: map} = useMap();
const onClick = () => {
map.flyTo({center: [-122.4, 37.8]});
};
return ;
}
```
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 ``.
```tsx
import {MapProvider, Map, useMap} from 'react-map-gl/mapbox';
function Root() {
// Note: `useMap` will not work in , only children of can use `useMap`
return (
);
}
function NavigateButton() {
const {myMapA, myMapB} = useMap();
const onClick = () => {
myMapA.flyTo({center: [-122.4, 37.8]});
myMapB.flyTo({center: [-74, 40.7]});
};
return ;
}
```
See a full example [here](https://github.com/visgl/react-map-gl/tree/8.0-release/examples/get-started/hook).
## Signature
`useMap(): {current?: MapRef, [id: string]: MapRef}`
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 additionally contains a `current` field that references the containing map.
## Source
[use-map.tsx](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-mapbox/src/components/use-map.tsx)
================================================
FILE: docs/api-reference/maplibre/attribution-control.md
================================================
# AttributionControl
React component that wraps maplibre-gl's [AttributionControl](https://maplibre.org/maplibre-gl-js/docs/API/classes/AttributionControl/) class.
```tsx
import * as React from 'react';
import {Map, AttributionControl} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
Any [options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/AttributionControlOptions/) supported by the `AttributionControl` class, such as
- `compact`
- `customAttribution`
Plus the following:
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'bottom-right'`
Placement of the control relative to the map.
## Source
[attribution-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/attribution-control.ts)
================================================
FILE: docs/api-reference/maplibre/fullscreen-control.md
================================================
# FullscreenControl
React component that wraps maplibre-gl's [FullscreenControl](https://maplibre.org/maplibre-gl-js/docs/API/classes/FullscreenControl/) class.
```tsx
import * as React from 'react';
import {Map, FullscreenControl} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
#### `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}
Default: `'top-right'`
Placement of the control relative to the map.
## Source
[fullscreen-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/fullscreen-control.ts)
================================================
FILE: docs/api-reference/maplibre/geolocate-control.md
================================================
# GeolocateControl
React component that wraps maplibre-gl's [GeolocateControl](https://maplibre.org/maplibre-gl-js/docs/API/classes/GeolocateControl/) class.
```tsx
import * as React from 'react';
import {Map, GeolocateControl} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Callbacks
#### `onGeolocate`: (evt: [GeolocateResultEvent](./types.md#geolocateresultevent)) => void {#ongeolocate}
Called on each Geolocation API position update that returned as success.
#### `onError`: (evt: [GeolocateErrorEvent](./types.md#geolocateerrorevent)) => void {#onerror}
Called on each Geolocation API position update that returned as an error.
#### `onOutOfMaxBounds`: (evt: [GeolocateResultEvent](./types.md#geolocateresultevent)) => void {#onoutofmaxbounds}
Called on each Geolocation API position update that returned as success but user position is out of map `maxBounds`.
#### `onTrackUserLocationStart`: (evt: [GeolocateEvent](./types.md#geolocateevent)) => void {#ontrackuserlocationstart}
Called when the GeolocateControl changes to the active lock state.
#### `onTrackUserLocationEnd`: (evt: [GeolocateEvent](./types.md#geolocateevent)) => void {#ontrackuserlocationend}
Called when the GeolocateControl changes to the background state.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
Any [options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/GeolocateControlOptions/) supported by the `GeolocateControl` class, such as
- `positionOptions`
- `fitBoundsOptions`
- `trackUserLocation`
- `showAccuracyCircle`
- `showUserLocation`
Plus the following:
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'bottom-right'`
Placement of the control relative to the map.
## Methods
The underlying native `GeolocateControl` instance is accessible via a [React ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) hook.
You may use it to call any imperative methods:
```tsx
import * as React from 'react';
import {useRef, useEffect} from 'react';
import {Map, GeolocateControl} from 'react-map-gl/maplibre';
import type maplibregl from 'maplibre-gl';
function App() {
const geoControlRef = useRef();
useEffect(() => {
// Activate as soon as the control is loaded
geoControlRef.current?.trigger();
}, [geoControlRef.current]);
return ;
}
```
## Source
[geolocate-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/geolocate-control.ts)
================================================
FILE: docs/api-reference/maplibre/globe-control.md
================================================
# GlobeControl
React component that wraps maplibre-gl's [GlobeControl](https://maplibre.org/maplibre-gl-js/docs/API/classes/GlobeControl/) class.
```tsx
import * as React from 'react';
import {Map, GlobeControl} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'top-right'`
Placement of the control relative to the map.
## Source
[globe-control.ts](https://github.com/visgl/react-map-gl/tree/9.0-release/modules/react-maplibre/src/components/globe-control.ts)
================================================
FILE: docs/api-reference/maplibre/layer.md
================================================
# Layer
This component allows apps to create a [map layer](https://maplibre.org/maplibre-style-spec/layers/) using React.
```tsx
import * as React from 'react';
import {Map, Layer} from 'react-map-gl/maplibre';
import type {FillLayer} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
const parkLayer: FillLayer = {
id: 'landuse_park',
type: 'fill',
source: 'vector',
'source-layer': 'landuse',
filter: ['==', 'class', 'park'],
paint: {
'fill-color': '#4E3FC8'
}
};
function App() {
return ;
}
```
## Properties
The props provided to this component should be conforming to the [Maplibre layer specification](https://maplibre.org/maplibre-style-spec/layers/).
When props change *shallowly*, the component will perform style diffing to update the layer. Avoid defining constant objects/arrays inline may help performance.
### Identity Properties
Once a `` is mounted, the following props should not change. If you add/remove multiple JSX layers dynamically, make sure you use React's [key prop](https://reactjs.org/docs/lists-and-keys.html#keys) to give each element a stable identity.
#### `id`: string {#id}
Unique identifier of the layer. If not provided, a default id will be assigned.
#### `type`: string {#type}
Required. Type of the layer.
### Options
#### `beforeId`: string {#beforeid}
The ID of an existing layer to insert this layer before. If this prop is omitted, the layer will be appended to the end of the layers array. This is useful when using dynamic layers with a map style from a URL.
Note that layers are added by the order that they mount. They are *NOT* reordered later if their relative positions in the JSX tree change. If dynamic reordering is desired, you should manipulate `beforeId` for consistent behavior.
#### `source`: string {#source}
`source` is required by some layer types in the Mapbox style specification. If `` is used as the immediate child of a [Source](./source.md) component, this prop will be overwritten by the id of the parent source. If the `` component is not an immediate descendant of ``, e.g wrapped inside a helper component, source property needs to be provided same as the id of the `` component for the `` component to show.
## Source
[layer.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/layer.ts)
================================================
FILE: docs/api-reference/maplibre/logo-control.md
================================================
# LogoControl
React component that wraps maplibre-gl's [LogoControl](https://maplibre.org/maplibre-gl-js/docs/API/classes/LogoControl/) class.
```tsx
import * as React from 'react';
import {Map, LogoControl} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
Any [options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/LogoControlOptions/) supported by the `LogoControl` class, such as
- `compact`
Plus the following:
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'top-right'`
Placement of the control relative to the map.
## Source
[logo-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/logo-control.ts)
================================================
FILE: docs/api-reference/maplibre/map-provider.md
================================================
# MapProvider
A [Context.Provider](https://reactjs.org/docs/context.html#contextprovider) that facilitates map operations outside of the component that directly renders a [Map](./map.md).
The component should wrap all nodes in which you may want to access the maps:
```tsx
import {MapProvider} from 'react-map-gl/maplibre';
function Root() {
return (
{
// Application tree, somewhere one or more component(s) are rendered
}
);
}
```
See [useMap](./use-map.md) for more information.
## Source
[use-map.tsx](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/use-map.tsx)
================================================
FILE: docs/api-reference/maplibre/map.md
================================================
# default (Map)
React component that wraps maplibre-gl's [Map](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/) class. This is also the default export from `react-map-gl/maplibre`.
```tsx
import * as React from 'react';
import {Map} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return (
);
}
```
## Properties
Aside from the props listed below, the `Map` component supports all [options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/) of the `Map` class constructor. 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
#### `id`: string {#id}
Map container id.
#### `style`: CSSProperties {#style}
Default: `{position: 'relative', width: '100%', height: '100%'}`
Map container CSS.
#### `cursor`: string {#cursor}
Default: `'auto'`
The current cursor [type](https://developer.mozilla.org/en-US/docs/Web/CSS/cursor).
### Styling options
#### `light`: [Light](./types.md#light) {#light}
Light properties of the style. Must conform to the [Light Style Specification](https://maplibre.org/maplibre-style-spec/light/).
#### `mapStyle`: [MapStyle](./types.md#mapstyle) | string | Immutable {#mapstyle}
Default: (empty style)
The map's Maplibre style. This must be an a JSON object conforming to the schema described in the [MapLibre Style Specification](https://maplibre.org/maplibre-style-spec/), or a URL to such JSON.
#### `projection`: string | [Projection](./types.md#projection) {#projection}
Default: `'mercator'`
The projection the map should be rendered in. See [Projection Specification](https://maplibre.org/maplibre-style-spec/projection/).
#### `renderWorldCopies`: boolean {#renderworldcopies}
Default: `true`
If `true`, multiple copies of the world will be rendered, when zoomed out.
#### `sky`: [Sky](./types.md#sky) {#sky}
The sky property of the style. Must conform to the [Sky Style Specification](https://maplibre.org/maplibre-style-spec/sky/).
#### `styleDiffing`: boolean {#stylediffing}
Default: `true`
Enable diffing when `mapStyle` changes. If `false`, force a 'full' update, removing the current style and building the given one instead of attempting a diff-based update.
#### `terrain`: [Terrain](./types.md#terrain)|null {#terrain}
Terrain property of the style. Must conform to the [Terrain Style Specification](https://maplibre.org/maplibre-style-spec/terrain/).
If `null` is provided, removes terrain from the map.
### Camera options
#### `initialViewState`: object {#initialviewstate}
The initial view state of the map. If specified, `longitude`, `latitude`, `zoom` etc. in props are ignored when constructing the map. Only specify `initialViewState` if `Map` is being used as an **uncontrolled component**. See [state management](../../get-started/state-management.md) for examples.
- `bounds`: [LngLatBoundsLike](./types.md#lnglatboundslike) - The initial bounds of the map. If specified, it overrides the `longitude`, `latitude` and `zoom` options. Default `null`.
- `fitBoundsOptions` - An object to use only when setting the `bounds` option. Default `null`.
+ `fitBoundsOptions.offset`: [PointLike](./types.md#pointlike)
+ `fitBoundsOptions.minZoom`: number
+ `fitBoundsOptions.maxZoom`: number
+ `fitBoundsOptions.padding`: [PaddingOptions](./types.md#paddingoptions)
- `longitude`: number - The initial longitude of the map center. Default `0`.
- `latitude`: number - The initial latitude of the map center. Default `0`.
- `zoom`: number - The initial zoom level. Default `0`.
- `pitch`: number - The initial pitch (tilt) of the map. Default `0`.
- `bearing`: number - The initial bearing (rotation) of the map. Default `0`.
#### `longitude`: number {#longitude}
The longitude of the map center.
#### `latitude`: number {#latitude}
The latitude of the map center.
#### `zoom`: number {#zoom}
The [zoom level](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/#zoom) of the map.
#### `pitch`: number {#pitch}
The initial [pitch](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/#pitch) (tilt) of the map, measured in degrees away from the plane of the screen (0-85).
#### `bearing`: number {#bearing}
The initial [bearing](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/#bearing) (rotation) of the map, measured in degrees counter-clockwise from north.
#### `padding`: [PaddingOptions](./types.md#paddingoptions) {#padding}
Default: `null`
The padding in pixels around the viewport.
#### `minZoom`: number {#minzoom}
Default: `0`
The minimum zoom level of the map (0-24).
#### `maxZoom`: number {#maxzoom}
Default: `22`
The maximum zoom level of the map (0-24).
#### `minPitch`: number {#minpitch}
Default: `0`
The minimum pitch of the map (0-85).
#### `maxPitch`: number {#maxpitch}
Default: `60`
The maximum pitch of the map (0-85).
#### `maxBounds`: [LngLatBoundsLike](./types.md#lnglatboundslike) {#maxbounds}
Default: `null`
If set, the map is constrained to the given bounds.
### Input handler options
#### `boxZoom`: boolean {#boxzoom}
Default: `true`
If `true`, the "box zoom" interaction is enabled. See [BoxZoomHandler](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](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](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 accept an object value that is the options to [DragPanHandler](https://maplibre.org/maplibre-gl-js/docs/API/classes/DragPanHandler/).
#### `keyboard`: boolean {#keyboard}
Default: `true`
If `true`, keyboard shortcuts are enabled. See [KeyboardHandler](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 accept an object value that is the options to [ScrollZoomHandler](https://maplibre.org/maplibre-gl-js/docs/API/classes/ScrollZoomHandler/).
#### `touchPitch`: boolean | Object {#touchpitch}
Default: `true`
If `true`, the "drag to pitch" interaction is enabled. Optionally accept an object value that is the options to [TwoFingersTouchPitchHandler](https://maplibre.org/maplibre-gl-js/docs/API/classes/TwoFingersTouchPitchHandler/).
#### `touchZoomRotate`: boolean | Object {#touchzoomrotate}
Default: `true`
If `true`, the "pinch to rotate and zoom" interaction is enabled. Optionally accept an object value that is the options to [TwoFingersTouchZoomRotateHandler](https://maplibre.org/maplibre-gl-js/docs/API/classes/TwoFingersTouchZoomRotateHandler/).
#### `interactiveLayerIds`: string[] {#interactivelayerids}
Default: `null`
The id(s) of style layer(s).
If specified, pointer event (`mousemove`, `click` etc.) listeners will be triggered only if its location is within a visible feature in these layers, and the event will have a `features` property containing an array of the matching features.
If not specified, pointer event listeners will be triggered by a corresponding event happening anywhere on the map, and the event will not have a `features` property.
See the [Callbacks](#callbacks) section for affected events.
### Callbacks
#### `onResize`: (event: [MapEvent](./types.md#mapevent)) => void {#onresize}
Called when the map has been resized.
#### `onLoad`: (event: [MapEvent](./types.md#mapevent)) => void {#onload}
Called after all necessary resources have been downloaded and the first visually complete rendering of the map has occurred.
#### `onRender`: (event: [MapEvent](./types.md#mapevent))) => void {#onrender}
Called whenever the map is drawn to the screen.
#### `onIdle`: (event: [MapEvent](./types.md#mapevent))) => void {#onidle}
Called after the last frame rendered before the map enters an "idle" state:
- No camera transitions are in progress
- All currently requested tiles have loaded
- All fade/transition animations have completed
#### `onRemove`: (event: [MapEvent](./types.md#mapevent))) => void {#onremove}
Called when the map has been removed.
#### `onError`: (event: [ErrorEvent](./types.md#errorevent)) => void {#onerror}
Default: `evt => console.error(evt.error)`
Called when an error occurs.
#### `onMouseDown`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmousedown}
Called when a pointing device (usually a mouse) is pressed within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onMouseUp`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseup}
Called when a pointing device (usually a mouse) is released within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onMouseOver`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseover}
Called when a pointing device (usually a mouse) is moved within the map. As you move the cursor across a web page containing a map, the event will fire each time it enters the map or any child elements.
#### `onMouseEnter`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseenter}
Called when a pointing device (usually a mouse) enters a visible portion of the layer(s) specified by `interactiveLayerIds` from outside that layer or outside the map canvas.
#### `onMouseMove`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmousemove}
Called when a pointing device (usually a mouse) is moved while the cursor is inside the map. As you move the cursor across the map, the event will fire every time the cursor changes position within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onMouseLeave`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseleave}
Called when a pointing device (usually a mouse) leaves a visible portion of the layer(s) specified by `interactiveLayerIds` or moves from the layer to outside the map canvas.
#### `onMouseOut`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onmouseout}
Called when a point device (usually a mouse) leaves the map's canvas.
#### `onClick`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#onclick}
Called when a pointing device (usually a mouse) is pressed and released at the same point on the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onDblClick`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#ondblclick}
Called when a pointing device (usually a mouse) is pressed and released twice at the same point on the map in rapid succession.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onContextMenu`: (event: [MapLayerMouseEvent](./types.md#maplayermouseevent)) => void {#oncontextmenu}
Called when the right button of the mouse is clicked or the context menu key is pressed within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onWheel`: (event: [MapWheelEvent](./types.md#mapwheelevent)) => void {#onwheel}
Called when a wheel event occurs within the map.
#### `onTouchStart`: (event: [MapLayerTouchEvent](./types.md#maplayertouchevent)) => void {#ontouchstart}
Called when a `touchstart` event occurs within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onTouchEnd`: (event: [MapLayerTouchEvent](./types.md#maplayertouchevent)) => void {#ontouchend}
Called when a `touchend` event occurs within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onTouchMove`: (event: [MapLayerTouchEvent](./types.md#maplayertouchevent)) => void {#ontouchmove}
Called when a `touchmove` event occurs within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onTouchCancel`: (event: [MapLayerTouchEvent](./types.md#maplayertouchevent)) => void {#ontouchcancel}
Called when a `touchcancel` event occurs within the map.
If `interactiveLayerIds` is specified, the event will contain an additional `features` field that contains features under the cursor from the specified layer.
#### `onMoveStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onmovestart}
Called just before the map begins a transition from one view to another.
#### `onMove`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onmove}
Called repeatedly during an animated transition from one view to another.
When `Map` is used as a controlled component, `event.viewState` reflects the view state that the camera "proposes" to move to, as a result of either user interaction or methods such as [flyTo](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#flyto). The camera does not actually change until the application updates the view state props (`longitude`, `latitude`, `zoom` etc.).
See [state management](../../get-started/state-management.md) for examples.
#### `onMoveEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onmoveend}
Called just after the map completes a transition from one view to another.
#### `onDragStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#ondragstart}
Called when a "drag to pan" interaction starts.
#### `onDrag`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#ondrag}
Called repeatedly during a "drag to pan" interaction.
#### `onDragEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#ondragend}
Called when a "drag to pan" interaction ends.
#### `onZoomStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onzoomstart}
Called just before the map begins a transition from one zoom level to another.
#### `onZoom`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onzoom}
Called repeatedly during an animated transition from one zoom level to another.
When `Map` is used as a controlled component, `event.viewState.zoom` reflects the zoom that the camera "proposes" to change to, as a result of either user interaction or methods such as [flyTo](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#flyto). The camera does not actually change until the application updates the `zoom` prop.
#### `onZoomEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onzoomend}
Called just after the map completes a transition from one zoom level to another.
#### `onRotateStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onrotatestart}
Called just before the map begins a transition from one bearing (rotation) to another.
#### `onRotate`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onrotate}
Called repeatedly during an animated transition from one bearing (rotation) to another.
When `Map` is used as a controlled component, `event.viewState.bearing` reflects the zoom that the camera "proposes" to change to, as a result of either user interaction or methods such as [flyTo](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#flyto). The camera does not actually change until the application updates the `bearing` prop.
#### `onRotateEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onrotateend}
Called just after the map completes a transition from one bearing (rotation) to another.
#### `onPitchStart`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onpitchstart}
Called just before the map begins a transition from one pitch (tilt) to another.
#### `onPitch`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onpitch}
Called repeatedly during an animated transition from one pitch (tilt) to another.
When `Map` is used as a controlled component, `event.viewState.pitch` reflects the zoom that the camera "proposes" to change to, as a result of either user interaction or methods such as [flyTo](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/#flyto). The camera does not actually change until the application updates the `pitch` prop.
#### `onPitchEnd`: (event: [ViewStateChangeEvent](./types.md#viewstatechangeevent)) => void {#onpitchend}
Called just after the map completes a transition from one pitch (tilt) to another.
#### `onBoxZoomStart`: (event: [MapBoxZoomEvent](./types.md#mapboxzoomevent)) => void {#onboxzoomstart}
Called when a "box zoom" interaction starts.
#### `onBoxZoomEnd`: (event: [MapBoxZoomEvent](./types.md#mapboxzoomevent)) => void {#onboxzoomend}
Called when a "box zoom" interaction ends.
#### `onBoxZoomCancel`: (event:[MapBoxZoomEvent](./types.md#mapboxzoomevent)) => void {#onboxzoomcancel}
Called when the user cancels a "box zoom" interaction, or when the bounding box does not meet the minimum size threshold.
#### `onData`: (event: [MapStyleDataEvent](./types.md#mapstyledataevent) | [MapSourceDataEvent](./types.md#mapsourcedataevent)) => void {#ondata}
Called when any map data loads or changes. See [MapDataEvent](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapDataEvent/) for more information.
#### `onStyleData`: (event: [MapStyleDataEvent](./types.md#mapstyledataevent)) => void {#onstyledata}
Called when the map's style loads or changes. See [MapDataEvent](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapDataEvent/) for more information.
#### `onSourceData`: (event: [MapSourceDataEvent](./types.md#mapsourcedataevent)) => void {#onsourcedata}
Called when one of the map's sources loads or changes, including if a tile belonging to a source loads or changes. See [MapDataEvent](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapDataEvent/) for more information.
### Other options
The following props, along with any [options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapOptions/) of the `Map` class 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('maplibre-gl')`
Specify the underlying base map library for the Map component. The value can be provided with several options:
By module import (and embedding in the final bundle):
```tsx
import * as React from 'react';
import {Map} from 'react-map-gl/maplibre';
import maplibregl from 'maplibre-gl';
function App() {
return ;
}
```
By dynamic import (thus enable bundle splitting):
```tsx
import * as React from 'react';
import {Map} from 'react-map-gl/maplibre';
function App() {
return ;
}
```
Or to load a pre-bundled version of the library:
```html title="index.html"
```
```tsx title="app.tsx"
import * as React from 'react';
import {Map} from 'react-map-gl/maplibre';
function App() {
return ;
}
```
#### `maxParallelImageRequests`: number {#maxparallelimagerequests}
Default: `16`
The maximum number of images (raster tiles, sprites, icons) to load in parallel.
#### `reuseMaps`: boolean {#reusemaps}
Default: `false`
By default, every time a map component is unmounted, all internal resources associated with the underlying `Map` instance are released. If the map gets mounted again, a new `Map` instance is constructed.
If `reuseMaps` is set to `true`, when a map component is unmounted, the underlying `Map` instance is retained in memory. The next time a map component gets mounted, the saved instance is reused. This behavior may be desirable if an application frequently mounts/unmounts map(s), for example in a tabbed or collapsable UI, and wants to avoid recreating the Map and its data cache triggered by initialization.
Note that since some map options cannot be modified after initialization, when reusing maps, only the reactive props and `initialViewState` of the new component are respected.
#### `RTLTextPlugin`: string | object {#rtltextplugin}
- `pluginUrl`: `string` URL to the plugin JS file.
- `lazy`: `boolean` When true, the plugin is only loaded when the map first encounters Hebrew or Arabic text. Default `true`.
Sets the map's RTL text plugin via [setRTLTextPlugin](https://maplibre.org/maplibre-gl-js/docs/API/functions/setRTLTextPlugin/). Can be used with [mapbox-gl-rtl-text](https://github.com/mapbox/mapbox-gl-rtl-text). Necessary for supporting the Arabic and Hebrew languages, which are written right-to-left.
#### `workerCount`: number {#workercount}
Default: `2`
The number of web workers instantiated on a page with maplibre-gl maps.
#### `workerUrl`: string {#workerurl}
Provides an interface for loading maplibre-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.
```tsx
import * as React from 'react';
import {useRef, useCallback} from 'react';
import {Map} from 'react-map-gl/maplibre';
import type {MapRef} from 'react-map-gl/maplibre';
function App() {
const mapRef = useRef();
const onMapLoad = useCallback(() => {
mapRef.current.on('move', () => {
// do something
});
}, []);
return ;
}
```
The [MapRef](./types.md#mapref) object exposes [Map methods](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](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/) instance associated with this component.
## Source
[map.tsx](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/map.tsx)
================================================
FILE: docs/api-reference/maplibre/marker.md
================================================
# Marker
React component that wraps maplibre-gl's [Marker](https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/) class.
```tsx
import * as React from 'react';
import {Map, Marker} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return ;
}
```
If `Marker` is mounted with child components, then its content will be rendered to the specified location. If it is mounted with no content, then a default marker will be used.
## Properties
### Reactive Properties
#### `draggable`: boolean {#draggable}
Default: `false`
If `true`, the marker is able to be dragged to a new position on the map.
#### `latitude`: number {#latitude}
Required. The latitude of the anchor location.
#### `longitude`: number {#longitude}
Required. The longitude of the anchor location.
#### `offset`: [PointLike](./types.md#pointlike) {#offset}
Default: `null`
The offset in pixels as a [PointLike](./types.md#pointlike) object to apply relative to the element's center. Negatives indicate left and up.
#### `pitchAlignment`: 'map' | 'viewport' | 'auto' {#pitchalignment}
Default: `'auto'`
- `map` aligns the `Marker` to the plane of the map.
- `viewport` aligns the `Marker` to the plane of the viewport.
- `auto` automatically matches the value of `rotationAlignment`.
#### `popup`: Popup | null {#popup}
An instance of the [Popup](https://maplibre.org/maplibre-gl-js/docs/API/classes/Popup/) class to attach to this marker. If undefined or null, any popup set on this Marker instance is unset.
#### `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}
Default: `'auto'`
- `map` aligns the `Marker`'s rotation relative to the map, maintaining a bearing as the map rotates.
- `viewport` aligns the `Marker`'s rotation relative to the viewport, agnostic to map rotations.
- `auto` is equivalent to `viewport`.
#### `style`: CSSProperties {#style}
CSS style override that applies to the marker's container.
### Callbacks
#### `onClick`: (evt: [MapEvent](./types.md#mapevent)) => void {#onclick}
Called when the marker is clicked on.
#### `onDragStart`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondragstart}
Called when dragging starts, if `draggable` is `true`.
#### `onDrag`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondrag}
Called while dragging, if `draggable` is `true`.
#### `onDragEnd`: (evt: [MarkerDragEvent](./types.md#markerdragevent)) => void {#ondragend}
Called when dragging ends, if `draggable` is `true`.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
Any [options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MarkerOptions/) supported by the `Marker` class, such as
- `anchor`
- `color`
- `scale`
- `clickTolerance`
## Methods
The underlying native `Marker` instance is accessible via a [React ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) hook.
You may use it to call any imperative methods:
```tsx
import * as React from 'react';
import {useRef, useMemo, useCallback} from 'react';
import {Map, Marker} from 'react-map-gl/maplibre';
import maplibregl from 'maplibre-gl';
function App() {
const markerRef = useRef();
const popup = useMemo(() => {
return maplibregl.Popup().setText('Hello world!');
}, [])
const togglePopup = useCallback(() => {
markerRef.current?.togglePopup();
}, []);
return <>
>;
}
```
## Source
[marker.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/marker.ts)
================================================
FILE: docs/api-reference/maplibre/navigation-control.md
================================================
# NavigationControl
React component that wraps maplibre-gl's [NavigationControl](https://maplibre.org/maplibre-gl-js/docs/API/classes/NavigationControl/) class.
```tsx
import * as React from 'react';
import {Map, NavigationControl} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
Any [options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/NavigationControlOptions/) supported by the `NavigationControl` class, such as
- `showCompass`
- `showZoom`
- `visualizePitch`
Plus the following:
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'top-right'`
Placement of the control relative to the map.
## Source
[navigation-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/navigation-control.ts)
================================================
FILE: docs/api-reference/maplibre/popup.md
================================================
# Popup
React component that wraps maplibre-gl's [Popup](https://maplibre.org/maplibre-gl-js/docs/API/classes/Popup/) class.
```tsx
import * as React from 'react';
import {useState} from 'react';
import {Map, Popup} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
const [showPopup, setShowPopup] = useState(true);
return ;
}
```
## Properties
### Reactive Properties
#### `anchor`: 'center' | 'left' | 'right' | 'top' | 'bottom' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' | undefined {#anchor}
A string indicating the part of the popup that should be positioned closest to the coordinate, set via `longitude` and `latitude`.
If unset, the anchor will be dynamically set to ensure the popup falls within the map container with a preference for `'bottom'`.
#### `className`: string {#classname}
Space-separated CSS class names to add to popup container.
#### `offset`: number | [PointLike](./types.md#pointlike) | Record\ {#offset}
Default: `null`
A pixel offset applied to the popup's location specified as:
- a single number specifying a distance from the popup's location
- a PointLike specifying a constant offset
- an object of Points specifing an offset for each anchor position.
Negative offsets indicate left and up.
#### `maxWidth`: string {#maxwidth}
Default: `240px`
A string that sets the CSS property of the popup's maximum width.
#### `style`: CSSProperties {#style}
CSS style override that applies to the popup's container.
### Callbacks
#### `onOpen`: (evt: [PopupEvent](./types.md#popupevent)) => void {#onopen}
Called when the popup is opened.
#### `onClose`: (evt: [PopupEvent](./types.md#popupevent)) => void {#onclose}
Called when the popup is closed by the user clicking on the close button or outside (if `closeOnClick: true`).
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
Any [options](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PopupOptions/) supported by the `Popup` class, such as
- `closeButton`
- `closeOnClick`
- `closeOnMove`
- `focusAfterOpen`
## Methods
The underlying native `Popup` instance is accessible via a [React ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) hook.
You may use it to call any imperative methods:
```tsx
import * as React from 'react';
import {useRef, useEffect} from 'react';
import {Map, Popup} from 'react-map-gl/maplibre';
import maplibregl from 'maplibre-gl';
function App() {
const popupRef = useRef();
useEffect(() => {
popupRef.current?.trackPointer();
}, [popupRef.current])
return ;
}
```
## Source
[popup.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/popup.ts)
================================================
FILE: docs/api-reference/maplibre/scale-control.md
================================================
# ScaleControl
React component that wraps maplibre-gl's [ScaleControl](https://maplibre.org/maplibre-gl-js/docs/API/classes/ScaleControl/) class.
```tsx
import * as React from 'react';
import {Map, ScaleControl} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `maxWidth`: string {#maxwidth}
Default: `100`
The maximum length of the scale control in pixels.
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
#### `unit`: 'imperial' | 'metric' | 'nautical' {#unit}
Default: `'metric'`
Unit of the distance.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'top-right'`
Placement of the control relative to the map.
## Source
[scale-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/scale-control.ts)
================================================
FILE: docs/api-reference/maplibre/source.md
================================================
# Source
This component allows apps to create a [map source](https://maplibre.org/maplibre-style-spec/sources/) using React. It may contain [Layer](./layer.md) components as children.
```tsx
import * as React from 'react';
import {Map, Source, Layer} from 'react-map-gl/maplibre';
import type {CircleLayer} from 'react-map-gl/maplibre';
import type {FeatureCollection} from 'geojson';
import 'maplibre-gl/dist/maplibre-gl.css';
const geojson: FeatureCollection = {
type: 'FeatureCollection',
features: [
{type: 'Feature', geometry: {type: 'Point', coordinates: [-122.4, 37.8]}}
]
};
const layerStyle: CircleLayer = {
id: 'point',
type: 'circle',
paint: {
'circle-radius': 10,
'circle-color': '#007cbf'
}
};
function App() {
return ;
}
```
## Properties
The props provided to this component should be conforming to the [Mapbox source specification](https://maplibre.org/maplibre-style-spec/sources/) or [CanvasSourceSpecification](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/CanvasSourceSpecification/).
When props change _shallowly_, the component will attempt to update the source. Do not define objects/arrays inline to avoid perf hit.
Once a `` is mounted, the following props should not change. If add/remove multiple JSX sources dynamically, make sure you use React's [key prop](https://reactjs.org/docs/lists-and-keys.html#keys) to give each element a stable identity.
#### `id`: string {#id}
Unique identifier of the source. If not provided, a default id will be assigned.
#### `type`: string {#type}
Required. Type of the source.
## Source
[source.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/source.ts)
================================================
FILE: docs/api-reference/maplibre/terrain-control.md
================================================
# TerrainControl
React component that wraps maplibre-gl's [TerrainControl](https://maplibre.org/maplibre-gl-js/docs/API/classes/TerrainControl/) class.
```tsx
import * as React from 'react';
import {Map, MapStyle, TerrainControl} from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
// https://maplibre.org/maplibre-gl-js/docs/examples/3d-terrain/
const MAP_STYLE: MapStyle = {
version: 8,
sources: {
osm: {
type: 'raster',
tiles: ['https://a.tile.openstreetmap.org/{z}/{x}/{y}.png'],
tileSize: 256,
attribution: '© OpenStreetMap Contributors',
maxzoom: 19
},
terrainSource: {
type: 'raster-dem',
url: 'https://demotiles.maplibre.org/terrain-tiles/tiles.json',
tileSize: 256
}
},
layers: [
{
id: 'osm',
type: 'raster',
source: 'osm'
}
],
terrain: {
source: 'terrainSource',
exaggeration: 1
},
sky: {}
};
function App() {
return ;
}
```
## Properties
### Reactive Properties
#### `style`: CSSProperties {#style}
CSS style override that applies to the control's container.
### Other Properties
The properties in this section are not reactive. They are only used when the component first mounts.
Any [options](https://maplibre.org/maplibre-style-spec/terrain/) supported by the `TerrainControl` class, such as
- `source`
- `exageration`
Plus the following:
#### `position`: 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' {#position}
Default: `'top-right'`
Placement of the control relative to the map.
## Source
[terrain-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/terrain-control.ts)
================================================
FILE: docs/api-reference/maplibre/types.md
================================================
# Types
The following types can be imported from `react-map-gl/maplibre` when using TypeScript.
## Components
#### IControl
A [custom control implementation](https://maplibre.org/maplibre-gl-js/docs/API/interfaces/IControl/).
#### CustomLayerInterface
A [custom layer implementation](https://maplibre.org/maplibre-gl-js/docs/API/interfaces/CustomLayerInterface/).
#### MapRef
Instance [ref](https://reactjs.org/docs/refs-and-the-dom.html#creating-refs) of a `Map` component. See [Map documentation](./map.md#methods) for details.
## Styling
#### StyleSpecification
An object conforming to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/).
#### SkySpecification
An object conforming to the [Sky Style Specification](https://maplibre.org/maplibre-style-spec/sky/).
#### LightSpecification
An object conforming to the [Light Style Specification](https://maplibre.org/maplibre-style-spec/light/).
#### TerrainSpecification
An object conforming to the [Terrain Style Specification](https://maplibre.org/maplibre-style-spec/terrain/).
#### ProjectionSpecification
An object conforming to the [Projection Style Specification](https://maplibre.org/maplibre-style-spec/projection/).
#### BackgroundLayerSpecification
A JSON object that defines a `background` layer according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/#background).
#### CircleLayerSpecification
A JSON object that defines a `circle` layer according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/layers//#circle).
#### FillExtrusionLayerSpecification
A JSON object that defines a `fill-extrusion` layer according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/#fill-extrusion).
#### FillLayerSpecification
A JSON object that defines a `fill` layer according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/#fill).
#### HeatmapLayerSpecification
A JSON object that defines a `heatmap` layer according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/#heatmap).
#### HillshadeLayerSpecification
A JSON object that defines a `hillshade` layer according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/#hillshade).
#### LineLayerSpecification
A JSON object that defines a `line` layer according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/#line).
#### RasterLayerSpecification
A JSON object that defines a `raster` layer according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/#raster).
#### SymbolLayerSpecification
A JSON object that defines a `symbol` layer according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/layers/#symbol).
#### GeoJSONSourceSpecification
A JSON object that defines a `geojson` source according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/sources/#geojson).
#### VideoSourceSpecification
A JSON object that defines a `video` source according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/sources/#video).
#### ImageSourceSpecification
A JSON object that defines a `image` source according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/sources/#image).
#### VectorSourceSpecification
A JSON object that defines a `vector` source according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/sources/#vector).
#### RasterSourceSpecification
A JSON object that defines a `raster` source according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/sources/#raster).
#### RasterDEMSourceSpecification
A JSON object that defines a `raster-dem` source according to the [Maplibre Style Specification](https://maplibre.org/maplibre-style-spec/sources/#raster-dem).
#### CanvasSourceSpecification
A JSON object that defines a `canvas` source type. See [CanvasSourceSpecification](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/CanvasSourceSpecification/).
## Configurations
#### ControlPosition
One of `'top-right'`, `'top-left'`, `'bottom-right'` and `'bottom-left'`.
#### PaddingOptions
An object with the following fields:
- `left`: number - in pixels.
- `top`: number - in pixels.
- `right`: number - in pixels.
- `bottom`: number - in pixels.
## Data Types
#### LngLat
A Maplibre [LngLat](https://maplibre.org/maplibre-gl-js/docs/API/classes/LngLat/) object.
#### LngLatLike
A Maplibre [LngLatLike](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/LngLatLike/) object.
#### LngLatBounds
A Maplibre [LngLatBounds](https://maplibre.org/maplibre-gl-js/docs/API/classes/LngLatBounds/) object.
#### LngLatBoundsLike
A Maplibre [LngLatBoundsLike](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/LngLatBoundsLike/) object.
#### Point
A Maplibre [Point](https://github.com/mapbox/point-geometry) object.
#### PointLike
A Maplibre [PointLike](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/PointLike/) object.
#### MapGeoJSONFeature
A [GeoJSON](http://geojson.org/) feature that also contains the following library-specific fields:
- `layer`: Layer
- `source`: string
- `sourceLayer`: string
- `state`: `{ [key: string]: any }`
#### ViewState
An object with the following fields:
- `longitude`: number - The longitude of the map center.
- `latitude`: number - The latitude of the map center.
- `zoom`: number - The zoom level.
- `pitch`: number - The pitch (tilt) of the map, in degrees.
- `bearing`: number - The bearing (rotation) of the map, in degrees.
## Events
#### MapEvent
An object with the following fields:
- `type`: string - Event type
- `target`: [Map](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)
- `originalEvent?`: [Event](https://developer.mozilla.org/en-US/docs/Web/API/Event)
#### MapLayerMouseEvent
An object with the following fields:
- `type`: string
- `target`: [Map](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)
- `preventDefault`: () => void
- `defaultPrevented`: boolean
- `features?`: [MapGeoJSONFeature](#mapgeojsonfeature)[]
#### MapWheelEvent
An object with the following fields:
- `type`: string
- `target`: [Map](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
#### MapLayerTouchEvent
An object with the following fields:
- `type`: string
- `target`: [Map](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)
- `points`: [Point](#point)[]
- `lngLats`: [LngLat](#lnglat)[]
- `preventDefault`: () => void
- `defaultPrevented`: boolean
- `features?`: [MapGeoJSONFeature](#mapgeojsonfeature)[]
#### ViewStateChangeEvent
An object with the following fields:
- `type`: string - Event type
- `target`: [Map](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
An object with the following fields:
- `type`: string
- `target`: [Map](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)
#### MapStyleDataEvent
An object with the following fields:
- `type`: string
- `target`: [Map](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)
- `dataType`: 'style'
#### MapSourceDataEvent
An object with the following fields:
- `type`: string
- `target`: [Map](https://maplibre.org/maplibre-gl-js/docs/API/classes/Map/)
- `dataType`: 'source'
- `isSourceLoaded`: boolean
- `source`: string
- `sourceId`: string
- `sourceDataType`: 'metadata' | 'content'
- `tile`: any
- `coord`: Coordinate
See [MapDataEvent](https://maplibre.org/maplibre-gl-js/docs/API/type-aliases/MapDataEvent/).
#### ErrorEvent
An object with the following fields:
- `type`: 'error'
- `target`: [Map](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
An object with the following fields:
- `type`: string
- `target`: [GeolocateControl](https://maplibre.org/maplibre-gl-js/docs/API/classes/GeolocateControl/)
#### GeolocateResultEvent
An object with the following fields:
- `type`: string
- `target`: [GeolocateControl](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.
#### GeolocateErrorEvent
An object with the following fields:
- `type`: string
- `target`: [GeolocateControl](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.
#### MarkerEvent
An object with the following fields:
- `type`: string
- `target`: [Marker](https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/)
#### MarkerDragEvent
An object with the following fields:
- `type`: string
- `target`: [Marker](https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/)
- `lngLat`: [LngLat](#lnglat) - the new location of the marker
#### PopupEvent
An object with the following fields:
- `type`: string
- `target`: [Popup](https://maplibre.org/maplibre-gl-js/docs/API/classes/Popup/)
================================================
FILE: docs/api-reference/maplibre/use-control.md
================================================
# useControl
The `useControl` hook is used to create React wrappers for custom map controls.
```tsx
import MapboxDraw from '@mapbox/mapbox-gl-draw';
import {Map, useControl} from 'react-map-gl/maplibre';
function DrawControl(props: DrawControlProps) {
useControl(() => new MapboxDraw(props), {
position: props.position
});
return null;
}
function App() {
return (
);
}
```
See a full example [here](/examples/maplibre/draw-polygon).
## Signature
```js
useControl(
onCreate: ({map: MapRef, mapLib: maplibregl}) => IControl,
options?: {
position?: ControlPosition;
}
): T
useControl(
onCreate: ({map: MapRef, mapLib: maplibregl}) => IControl,
onRemove: ({map: MapRef, mapLib: maplibregl}) => void,
options?: {
position?: ControlPosition;
}
): T
useControl(
onCreate: ({map: MapRef, mapLib: maplibregl}) => IControl,
onAdd: ({map: MapRef, mapLib: maplibregl}) => void,
onRemove: ({map: MapRef, mapLib: maplibregl}) => void,
options?: {
position?: ControlPosition;
}
): T
```
The hook creates an [IControl](https://maplibre.org/maplibre-gl-js/docs/API/interfaces/IControl/) instance, adds it to the map when it's available, and removes it upon unmount.
Parameters:
- `onCreate`: `({map: MapRef, mapLib: maplibregl}) => IControl` - called to create an instance of the control.
- `onAdd`: `({map: MapRef, mapLib: maplibregl}) => void` - called when the control has been added to the map.
- `onRemove`: `({map: MapRef, mapLib: maplibregl}) => void` - called when the control is about to be removed from the map.
- `options`: object
+ `position`: 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right' - control position relative to the map
Returns:
[IControl](./types.md#icontrol) - the control instance from `onCreate`.
## Source
[use-control.ts](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/use-control.ts)
================================================
FILE: docs/api-reference/maplibre/use-map.md
================================================
# useMap
The `useMap` hook allows a custom component to reference the [Map](./map.md) that contains it.
```tsx
import {Map, useMap} from 'react-map-gl/maplibre';
function Root() {
return (
);
}
function NavigateButton() {
const {current: map} = useMap();
const onClick = () => {
map.flyTo({center: [-122.4, 37.8]});
};
return ;
}
```
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.
```tsx
import {MapProvider, Map, useMap} from 'react-map-gl/maplibre';
function Root() {
return (
);
}
function NavigateButton() {
const {myMapA, myMapB} = useMap();
const onClick = () => {
myMapA.flyTo({center: [-122.4, 37.8]});
myMapB.flyTo({center: [-74, 40.7]});
};
return ;
}
```
See a full example [here](https://github.com/visgl/react-map-gl/tree/8.0-release/examples/get-started/hook).
## Signature
`useMap(): {current?: MapRef, [id: string]: MapRef}`
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.
## Source
[use-map.tsx](https://github.com/visgl/react-map-gl/tree/8.0-release/modules/react-maplibre/src/components/use-map.tsx)
================================================
FILE: docs/get-started/adding-custom-data.md
================================================
# Adding Custom Data
## Native Mapbox Layers
You can inject data and mapbox native layers using the [Source](../api-reference/mapbox/source.md) and [Layer](../api-reference/mapbox/layer.md) components:
```tsx
import * as React from 'react';
import Map, {Source, Layer} from 'react-map-gl/maplibre';
import type {CircleLayer} from 'react-map-gl/maplibre';
import type {FeatureCollection} from 'geojson';
const geojson: FeatureCollection = {
type: 'FeatureCollection',
features: [
{
type: 'Feature',
geometry: {
type: 'Point',
coordinates: [-122.4, 37.8]
},
properties: {title: '915 Front Street, San Francisco, California'}
}
]
};
const layerStyle: CircleLayer = {
id: 'point',
type: 'circle',
paint: {
'circle-radius': 10,
'circle-color': '#007cbf'
}
};
function App() {
return (
);
}
```
For details about data sources and layer configuration, check out the [Mapbox style specification](https://www.mapbox.com/mapbox-gl-js/style-spec).
For dynamically updating data sources and layers, check out the [GeoJSON](https://visgl.github.io/react-map-gl/examples/maplibre/geojson) and [GeoJSON animation](http://visgl.github.io/react-map-gl/examples/maplibre/geojson-animation) examples.
## Custom Overlays
You can implement a custom HTML or SVG overlay on top of the map that redraws whenever the camera changes. By calling `map.project()` you can adjust the DOM or CSS properties so that the customly-drawn features are always aligned with the map. See a full example [here](https://github.com/visgl/react-map-gl/tree/8.0-release/examples/maplibre/custom-overlay).
## Other vis.gl Libraries
For more feature rich and performant data visualization overlay use cases, you may consider using other visualization libraries. react-map-gl is part of the [vis.gl](https://www.github.com/visgl) ecosystem, a suite of high-performance data visualization tools for the Web.
- [deck.gl](https://deck.gl) - WebGL-powered framework for the visualization of large datasets.
- [loaders.gl](https://loaders.gl) - loaders for file formats focused on visualization of big data, including point clouds, 3D geometries, images, geospatial formats as well as tabular data.
- [nebula.gl](https://nebula.gl) - 3D-enabled GeoJSON editing based on deck.gl and React.
================================================
FILE: docs/get-started/get-started.md
================================================
# Get Started
You may find complete project setups in [get-started examples](https://github.com/visgl/react-map-gl/tree/8.0-release/examples/get-started).
## Installation
Using `react-map-gl` requires `node >= 12` and `react >= 16.3`.
import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
```bash
npm install react-map-gl mapbox-gl @types/mapbox-gl
```
```bash
npm install react-map-gl maplibre-gl
```
## Example
```tsx title="app.tsx"
import * as React from 'react';
import Map from 'react-map-gl/mapbox';
// If using with mapbox-gl v1:
// import Map from 'react-map-gl/mapbox-legacy';
import 'mapbox-gl/dist/mapbox-gl.css';
function App() {
return (
);
}
```
See [about Mapbox tokens](./mapbox-tokens.md) for alternatives to providing a Mapbox token.
```tsx title="app.tsx"
import * as React from 'react';
import Map from 'react-map-gl/maplibre';
import 'maplibre-gl/dist/maplibre-gl.css';
function App() {
return (
);
}
```
## Styling
The base map library requires its stylesheet be included at all times. The marker, popup and navigation components in react-map-gl also need the stylesheet to work properly.
The above example code imports the CSS file directly into the app. Most bundlers support this syntax out-of-the-box or with an official plugin.
Alternatively, you may add the stylesheet to the head of your page:
```html title="index.html"
```
Find out your mapbox version by running `yarn list mapbox-gl` or `npm ls mapbox-gl`.
```html title="index.html"
```
Find out your maplibre version by running `yarn list maplibre-gl` or `npm ls maplibre-gl`.
================================================
FILE: docs/get-started/mapbox-tokens.md
================================================
# About Mapbox Tokens
`react-map-gl` itself is open source and free. It provides a React wrapper for `mapbox-gl`, `maplibre-gl` or compatible projects.
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` - 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.
There are several ways to provide a token to your app, as showcased in some of the example folders:
* Provide a `mapboxAccessToken` prop to the map component
* Set the `MapboxAccessToken` environment variable (or set `REACT_APP_MAPBOX_ACCESS_TOKEN` if you are using Create React App)
* Provide it in the URL, e.g `?access_token=TOKEN`
We recommend using an environment variable to minimize leaking risks. See [securing Mapbox token](./tips-and-tricks.md#securing-mapbox-token) for examples.
## Display Maps Without A Mapbox Token
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/). 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.
Some alternative map data providers include:
- [MapTiler](https://www.maptiler.com)
- [Amazon Location Service](https://docs.aws.amazon.com/location/latest/developerguide/map-concepts.html)
Useful resources for creating your own map tiles and service:
- [Martin Tile Server](https://maplibre.org/martin/introduction.html)
- [OpenMapTiles](https://openmaptiles.org)
- [Mapbox Vector Tile Spec](https://github.com/mapbox/vector-tile-spec)
- [PMTiles](https://github.com/protomaps/PMTiles)
- [List of open source tools](https://github.com/mapbox/awesome-vector-tiles)
If you are using a third party service that requires header based authentication, you can do this by defining a function to pass to `Map` using the `transformRequest` prop.
An example function:
```ts
const transformRequest = (url, resourceType) => {
if (resourceType === 'Tile' && url.match('yourTileSource.com')) {
return {
url: url,
headers: { 'Authorization': 'Bearer ' + yourAuthToken }
}
}
}
```
================================================
FILE: docs/get-started/state-management.md
================================================
# State Management
There are two ways to use a [Map](../api-reference/maplibre/map.md):
- [Uncontrolled](https://reactjs.org/docs/uncontrolled-components.html): The application sets the initial view state (Camera options) when the map is mounted, and the component automatically makes changes to the view states afterwards. This mode works very similarly to the mapbox-gl `Map` class.
- [Controlled](https://reactjs.org/docs/forms.html#controlled-components): The application manages the view state, and pass it to the map via props. The map invokes a callback with a new view state during user interaction transition, and the application can decide what to do with it. This mode is the most powerful when an application has other components that need to interact with the map, or implements its own user input and data handling logic.
## Uncontrolled Map
You may clone a full app configuration for this example [here](https://github.com/visgl/react-map-gl/tree/8.0-release/examples/get-started/basic).
```tsx
import * as React from 'react';
import Map from 'react-map-gl/maplibre';
function App() {
return ;
}
```
## Controlled Map
You may clone a full app configuration for this example [here](https://github.com/visgl/react-map-gl/tree/8.0-release/examples/get-started/controlled).
```tsx
import * as React from 'react';
import Map from 'react-map-gl/maplibre';
function App() {
const [viewState, setViewState] = React.useState({
longitude: -100,
latitude: 40,
zoom: 3.5
});
return