2

Hello guys I'm having trouble finding in the library how to get the viewport's center in coordinates. Basically my goal is that each time a user wants to create an alert,the pin marker locates the center of the screen so that the user can drag it without being forced to scroll over the map to get the pin( because right now I defined a point static).

Hope you can help me

Lucas Seabra
  • 63
  • 1
  • 1
  • 5

1 Answers1

1

give map an Id then in the component you want to centre import useMap

    <Map
    id='mapData'
     ....
    />
    

in the component you intend to center / find center

import {useMap} from 'react-map-gl'

   function MapComponent(){
     const {mapData} = useMap()
     mapData.getCenter()

   }

I hope this helps someone seeing that this is old. info

emekaokoli
  • 163
  • 4
  • 11