react-mapbox-gl icon indicating copy to clipboard operation
react-mapbox-gl copied to clipboard

onClick not working on Feature

Open abelhOrihuela opened this issue 4 years ago • 6 comments

Render:

<Layer type="heatmap" paint={layerPaint} > {data.map((point, index) => ( <Feature key={index} coordinates={point.latlng} properties={point} onclick={() => this.handleClick(point)} /> ))} </Layer>

Function:

handleClick = (e) => { console.log(e) }

abelhOrihuela avatar Mar 18 '20 02:03 abelhOrihuela

use onClick instead of onclick in Feature

Cantinaband avatar Mar 18 '20 06:03 Cantinaband

I dont have idea how it changed onClick to onclick, but this two options not work

Screen Shot 2020-03-18 at 12 48 12 AM

abelhOrihuela avatar Mar 18 '20 06:03 abelhOrihuela

what is happening then you change in the onClick this.handleClick(item) to console.log('blablabla')? Appears the log in the console?

Cantinaband avatar Mar 18 '20 07:03 Cantinaband

No appear in console

abelhOrihuela avatar Mar 18 '20 15:03 abelhOrihuela

any solution :|

anthonyhungnguyen avatar Sep 29 '20 12:09 anthonyhungnguyen

I believe you need to move the onClick prop to the map element. You can then handle the click, grab the id of the element that was clicked and update your state above to reflect the change you'd like to make.

Let me know how that goes.

cbracewell avatar May 19 '22 01:05 cbracewell