I'd like to get the visible bounds of a map from within the component rendering the map. I referred initially to #242 but the proposed solution in that conversation seems no longer to be viable.
I am using V3.2.1 and this is what my code looks like
const MapBoxRender = ReactMapboxGl({
...
});
class elem extends PureComponent{
constructor(){
...
this.mapRef = React.createRef()
}
componentDidMount(){
console.log(this.mapRef) // don't see any obvious way to get bounds from this ref
}
render(){
...
<MapBoxRender ... ref={map => this.mapRef = map}>
<ViewController .../>
...
</MapBoxRender>
}
}
mapRef.getMap() will give you the underlying mapbox Map instance.
Awesome, Thanks!
getMap() no longer works in the existing version of react-map-gl.
Most helpful comment
mapRef.getMap()will give you the underlying mapboxMapinstance.