Get the "map" object in Mapbox-GL react native

Solution 1:

The moveTo method belongs to Camera object. ref.

I don't have the environment setuped to test. The code will look something like this:

import React, { Component } from 'react';
import {StyleSheet, View} from 'react-native';
import MapboxGL from '@react-native-mapbox-gl/maps';

MapboxGL.setAccessToken('xxxx');

export default class DebugMap extends Component {
 constructor(props) {
  super(props);

  this.camera = React.createRef();
  this.map = React.createRef();

  this.handleOnpress = this.handleOnpress.bind(this);
 }

 handleOnpress(event) {
  const loc = event.geometry.coordinates;
  this.camera.current.moveTo(loc, 200);
 }

 render() {
  return (
   <View style={{ flex: 1 }}>

    <MapboxGL.MapView ref={this.map} 
       onPress={this.handleOnpress} 
       style={{ flex: 1 }}>
     
     <MapboxGL.Camera ref={this.camera} 
        zoomLevel={10} 
        centerCoordinate={[50, 20]} />

    </MapboxGL.MapView>
   </View>
  );
 }
}