Skip to content

Files

Latest commit

61bdca9 · Jul 3, 2019

History

History
This branch is 99 commits behind urbica/react-map-gl:main.

MapContext

MapContext provides React Context API for the Mapbox GL JS map instance.

Using MapContext

You can also use MapContext.Consumer to obtain Mapbox GL JS Map instance.

import React from 'react';
import MapGL, { MapContext } from '@urbica/react-map-gl';
import 'mapbox-gl/dist/mapbox-gl.css';

<MapGL
  style={{ width: '100%', height: '400px' }}
  mapStyle='mapbox://styles/mapbox/light-v9'
  accessToken={MAPBOX_ACCESS_TOKEN}
  latitude={37.78}
  longitude={-122.41}
  zoom={11}
>
  <MapContext.Consumer>
    {map => {
      map.setPaintProperty('water', 'fill-color', '#fdbdba');
      return;
    }}
  </MapContext.Consumer>
</MapGL>;