React-map-gl: Getting map bounds

Created on 5 Apr 2018  路  3Comments  路  Source: visgl/react-map-gl

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

Most helpful comment

mapRef.getMap() will give you the underlying mapbox Map instance.

All 3 comments

mapRef.getMap() will give you the underlying mapbox Map instance.

Awesome, Thanks!

getMap() no longer works in the existing version of react-map-gl.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ckalas picture ckalas  路  5Comments

yangshun picture yangshun  路  4Comments

jenyeeiam picture jenyeeiam  路  4Comments

sudoStatus200 picture sudoStatus200  路  5Comments

bogdancaspar picture bogdancaspar  路  3Comments