2

I am trying to get center coordinates when moving map. Is this possible using this library https://visgl.github.io/react-map-gl/. I have been reading documentation and i came across this getMap() method which says:

Returns the Mapbox instance if initialized. The Map instance will have full access to MapboxGL's API.

So i think i have to use this method to then have access to getCenter() (https://docs.mapbox.com/mapbox-gl-js/api/map/#map#getcenter), but i do not know how to do this.

Thanks!

const [viewport, setViewport] = React.useState({
    latitude: 44.568127,
    longitude: 14.075559,
    zoom: 2,
    width: "100vw",
    height: "100vh",
  });

   return (
    <div>
      <h2>Dashboard</h2>
      <ReactMapGL
        mapboxApiAccessToken={""}
        {...viewport}
        onViewportChange={(viewport) => setViewport(viewport)}
        mapStyle="mapbox://styles/mapbox/streets-v11"
      ></ReactMapGL>
    </div>
  );
};
Krneki123
  • 67
  • 5

0 Answers0