Peter G.
Peter G.

Reputation: 8054

React Native: Center MapBox in a given area, not just in center coordinate

Here I am trying to achieve centering a MapBox map in a given area:

From what I know from its documentation, MapBox only allows centering in a single centerCoordinate and setting zoomLevel. By setting zoomLevel there seems to be no guarantee that the rectangle will be contained inside the MapBox.

How to achieve a whole area being displayed at once and the map being centered around it?

<Mapbox
  accessToken={'ACCESS_TOKEN'}
  centerCoordinate={this.state.currentView.coordinates}
  zoomLevel={this.state.currentView.zoomLevel}
/> 

Upvotes: 0

Views: 638

Answers (1)

Lucas Wojciechowski
Lucas Wojciechowski

Reputation: 3802

The Map#fitBounds method seems to do exactly what you're looking for. I'm not sure if / how to use it with the react wrapper, however.

Upvotes: 2

Related Questions