react-map-gl | Docs
npm install --save react-map-gl
-
browserify
- react-map-gl is extensively tested withbrowserify
and works without configuration. -
webpack 2
- Most of the provided react-map-gl examples use webpack 2. For a minimal example, look at the exhibit-webpack folder, demonstrating a working demo usingwebpack 2
. -
create-react-app
- At this point configuration-free builds are not possible with webpack. You will need to eject your app (sorry) and add one line alias to your webpack config.
For more information, please refer to the docs docs.
import MapGL from 'react-map-gl';
<MapGL
width={400}
height={400}
latitude={37.7577}
longitude={-122.4376}
zoom={8}
onChangeViewport={viewport => {
// Call `setState` and use the state to update the map.
}}
/>
The main point of using a map is usually to visualize geospatial data on top of it. react-map-gl provides several solutions
-
Components - react-map-gl provides React components like
Marker
,Popup
etc that takeslongitude
andlatitude
props and will automatically follow the map. -
Overlays - react-map-gl provides a basic overlay API. Each overlay takes long/lat encoded data and displays it on top of the map. You can use one of the provided visualization overlays, or create your own.
-
deck.gl Layers - deck.gl is a companion module to react-map-gl that provides high-performance geospatial data visualiation layers (
ScatterplotLayer
,GeoJsonLayer
,PointCloudLayer
etc) that are 3D enabled and 100% compatible with mapbox perspective mode. These layers are particularly suitable for very large and/or dynamic data sets.
Install project dependencies and check that the tests run
npm install
npm test
Then start the main example in examples/main
by running the shortcut
npm start
This should open a new tab in your browser with the examples.
To make the maps load, either:
- add
?access_token=TOKEN
to the URL whereTOKEN
is a valid Mapbox access token, or - set the
MapboxAccessToken
environment variable before runningnpm start
- Unit Tests - it is expected that any feature is accompanied by standard unit tests in test folder.
- Run Unit Tests in Node - Note that This component uses WebGL, but it still runs under Node.js (using headless-gl and jsdom). This is how the standard
npm test
script runs. - Run Unit Tests in Browser - It is also important to run unit tests in the browser, via
npm run test-browser
. - Manual Testing - In addition, please test drive new and existing features by running
npm start
and manually testing the demos.
Contributions are welcome. It can be helpful to check with maintainers before opening your PR, just open an issue and describe your proposal. Also, be aware that you will need to complete a short open source contribution form before your pull request can be accepted.