Skip to content

Latest commit

 

History

History
27 lines (23 loc) · 698 Bytes

README.md

File metadata and controls

27 lines (23 loc) · 698 Bytes

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>;