React-mapbox-gl: Get coordinate on click

Created on 26 Jun 2017  路  8Comments  路  Source: alex3165/react-mapbox-gl

How can we get the cursor coordinate using the onClick event on the map?

Here is how I'm trying:

```
_onClickMap(e) {
console.log(e.lngLat);
}

render() {
return


style="mapbox://styles/mapbox/outdoors-v10"
containerStyle={{
height: 400,
width: "100vw",
marginTop: 60
}}
center={[-104.99, 39.75]}
zoom={[9]}
onClick={this._onClickMap}/>

``` I would expect to be able to access thelngLat` property similarly to this example: https://www.mapbox.com/mapbox-gl-js/example/mouse-position/

Most helpful comment

Almost that, sorry it is not clear in the documentation, here is what you need:

_onClickMap(map, evt) {
  console.log(evt.lngLat);
}

All 8 comments

Almost that, sorry it is not clear in the documentation, here is what you need:

_onClickMap(map, evt) {
  console.log(evt.lngLat);
}

Thanks so much for this!

Thanks!!!

Could this be implemented in Kepler Gl? Do you have any guide in where should I add this?

Cool

how do i get only the longitude or the latitude?

Just read out the property you care about from evt.lngLat @SanHolo101

Thanks, You save my day

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aziz-boudi4 picture aziz-boudi4  路  14Comments

suyesh picture suyesh  路  11Comments

PawkaHub picture PawkaHub  路  17Comments

alex3165 picture alex3165  路  15Comments

pronebird picture pronebird  路  19Comments