Skip to content
Please note that GitHub no longer supports Internet Explorer.

We recommend upgrading to the latest Microsoft Edge, Google Chrome, or Firefox.

Learn more
React friendly API wrapper around MapboxGL JS
Branch: master
Clone or download
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs update what's new (#752) Mar 13, 2019
examples move FullscreenControl example to examples/controls (#740) Feb 28, 2019
flow-typed/npm Set up flow (#651) Nov 5, 2018
ocular add geolocate control (#724) Feb 20, 2019
scripts fix mapbox wrapper viewstate support (#521) Jun 4, 2018
src Fix mapbox export warning (#757) Mar 14, 2019
test loose TransitionManager test criteria (#755) Mar 14, 2019
website add fullscreen support (#696) Feb 7, 2019
.babelrc Set up flow (#651) Nov 5, 2018
.editorconfig Upgrade uber-standard and use typical .editorconfig file. Jan 5, 2016
.eslintignore Buble+webpack2 (#169) Mar 7, 2017
.eslintrc
.flowconfig Set up flow (#651) Nov 5, 2018
.gitignore
.travis.yml Support relative map size (#614) Oct 12, 2018
CHANGELOG.md
LICENSE Remove unrelated licenses from LICENSE (#359) Sep 19, 2017
README.md 4.0.0-beta.7 Nov 5, 2018
TESTING.md Add `transformRequest` prop to map components. (#426) Dec 19, 2017
aliases.js use class properties for binding (#598) Sep 24, 2018
index.html Fix flow build process Mar 24, 2017
package.json
yarn.lock fix security vulnerability (#742) Feb 25, 2019

README.md

version build downloads

react-map-gl | Docs

React Components Suite for Mapbox GL JS.

In addition to exposing MapboxGL functionality to React apps, react-map-gl also integrates seamlessly with deck.gl.

Before You Begin

This library provides convenient wrappers around initializing and (to some degree) tracking the state of a Mapbox WebGL map. Because most of the functionality of Mapbox's JS API depends on the use of HTML5 canvases and WebGL, which React is not built to manipulate, the React component does not mirror all the functionality of Mapbox GL JS's Map class. You may access the native Mapbox API exposed by the getMap() function in this library. However, proceed with caution as calling the native APIs may break the connection between the React layer props and the underlying map state.

Installation

Using react-map-gl requires react >= 16.3.

npm install --save react-map-gl

Example

import {Component} from 'react';
import ReactMapGL from 'react-map-gl';

class Map extends Component {

  state = {
    viewport: {
      width: 400,
      height: 400,
      latitude: 37.7577,
      longitude: -122.4376,
      zoom: 8
    }
  };

  render() {
    return (
      <ReactMapGL
        {...this.state.viewport}
        onViewportChange={(viewport) => this.setState({viewport})}
      />
    );
  }
}

About Mapbox Tokens

To show maps from a service such as Mapbox you will need to register on their website in order to retrieve an access token required by the map component, which will be used to identify you and start serving up map tiles. The service will be 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 mapboxApiAccessToken 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

But we would recommend using something like dotenv and put your key in an untracked .env file, that will then expose it as a process.env variable, with much less leaking risks.

Contribute

See developer guide.

You can’t perform that action at this time.