Get coordinate on click
See original GitHub issueHow 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 <div>
<Map
style="mapbox://styles/mapbox/outdoors-v10"
containerStyle={{
height: 400,
width: "100vw",
marginTop: 60
}}
center={[-104.99, 39.75]}
zoom={[9]}
onClick={this._onClickMap}/>
</div>
I would expect to be able to access the lngLat
property similarly to this example: https://www.mapbox.com/mapbox-gl-js/example/mouse-position/
Issue Analytics
- State:
- Created 6 years ago
- Reactions:6
- Comments:8 (1 by maintainers)
Top Results From Across the Web
javascript get x and y coordinates on mouse click
Using event.clientX and **event.clientY provides the coordinates relative to the element taking into account margin, padding and border measures ...
Read more >Getting the Mouse Click Position in JavaScript | kirupa.com
To get the position of all the elements between what you clicked on and the document, you have the getPosition function. This function...
Read more >How to get the coordinates of a mouse click ... - GeeksforGeeks
The position of x-coordinate of the mouse click is found by subtracting the event's x position with the bounding rectangle's x position. The...
Read more >How to Get Mouse Coordinates in JavaScript - Linux Hint
To get mouse coordinates in JavaScript, use clientX and clientY properties with onclick event, pageX and pageY properties or the onmousemove event.
Read more >MouseEvent clientX Property - W3Schools
Output the coordinates of the mouse pointer when the mouse button is clicked on an element: var x = event.clientX; // Get the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Almost that, sorry it is not clear in the documentation, here is what you need:
Thanks so much for this!