alex3165 / react-mapbox-gl

A React binding of mapbox-gl-js
http://alex3165.github.io/react-mapbox-gl/
MIT License
1.93k stars 534 forks source link

How to access the underlying map object #73

Closed davidascher closed 7 years ago

davidascher commented 7 years ago

I'm trying to add the Geolocate control (https://www.mapbox.com/mapbox-gl-js/api/#GeolocateControl) to my map, but I'm struggling to figure how. The React devtools tell me that ReactMapboxGL's state contains the map object, but it seems improper to poke into the state of a child component from a container component.

What's the best way to use mapbox-gl APIs that aren't encapsulated by the reactified wrapper?

davidascher commented 7 years ago

Found the answer in the API doc:

To use the original Mapbox API use onStyleLoad property, the callback function will receive the map object as a first arguments, then you can add your own logic using mapbox gl API.

alex3165 commented 7 years ago

Happy to see that the documentation is explicit enough 👍

radeno commented 7 years ago

It should be helpful to write example :)