The Wayback Machine - https://web.archive.org/web/20200525112016/https://github.com/visgl/react-map-gl
Skip to content
React friendly API wrapper around MapboxGL JS
JavaScript Other
Branch: master
Clone or download

Latest commit

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
docs update contribution guide (#1106) May 18, 2020
examples examples: fix draw polygon examples (#1092) May 1, 2020
flow-typed/npm Fix test failure (#1082) Apr 21, 2020
scripts add release script (#754) May 31, 2019
src Fix test failure (#1082) Apr 21, 2020
test Migrate to import * as React from 'react' (#1038) Feb 25, 2020
website Revert "website: fix gatsby config (#1096)" May 4, 2020
.editorconfig Upgrade uber-standard and use typical .editorconfig file. Jan 5, 2016
.eslintignore Buble+webpack2 (#169) Mar 7, 2017
.eslintrc.js Bump dev tools (#1040) Feb 28, 2020
.flowconfig Set up flow (#651) Nov 5, 2018
.gitignore Dev tools setup (#803) May 31, 2019
.nycrc Avoid mutating style objects during normalization (#926) Oct 29, 2019
.prettierrc Upgrade dev tools to ocular (#780) May 8, 2019
.travis.yml Dev tools setup (#803) May 31, 2019
CHANGELOG.md Update github links (#1078) Apr 19, 2020
CONTRIBUTING.md update contribution guide (#1106) May 18, 2020
LICENSE Remove unrelated licenses from LICENSE (#359) Sep 19, 2017
README.md update contribution guide (#1106) May 18, 2020
TESTING.md Add `transformRequest` prop to map components. (#426) Dec 19, 2017
aliases.js Upgrade dev tools to ocular (#780) May 8, 2019
babel.config.js Add babel react preset and migrate react components to jsx (#875) Sep 16, 2019
index.html Fix flow build process Mar 24, 2017
ocular-dev-tools.config.js Dev tools setup (#803) May 31, 2019
package.json Update github links (#1078) Apr 19, 2020
webpack.config.js Update dev setup (#976) Jan 2, 2020
yarn.lock upgrade dependencies (#1095) May 21, 2020

README.md

version build downloads

react-map-gl | Docs

react-map-gl is a suite of React components for Mapbox GL JS.

Mapbox GL JS is an awesome library for making modern web maps. It is beautiful, efficient (WebGL-powered), and fully open source. You may load map data from Mapbox's own service, which is free until a certain level of traffic is exceeded; or you can create and host your own map data using one of the many open source tools.

See our Design Philosophy.

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})}
      />
    );
  }
}

Using 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
  • Provide mapboxApiUrl prop to the map component to override the default mapbox API URL

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.

Limitations

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.

Contribute

See contribution guide.

You can’t perform that action at this time.