I've got a map style set up in Mapbox Studio. This style contains a layer with markers. I want to be able to click on this layer in my React project using react-map-gl.
In any other situation i would do something like
map.on('click', 'needed-layer', () => {this.dostuff()});
This does not seem to work in ReactMapGL.
I made a reference to the map like so:
<ReactMapGL
ref={this.mapRef}
...
/>
this.mapRef = React.createRef();
this.map = this.mapRef.current.getMap();
If I log this.map i get a Map object which is good, but I would think the following code would detect a click on the predefined layer:
this.map.on('click', 'needed-layer', () => {this.dostuff()});
but it doesn't. Any ideas on how to click on a marker layer predefined in Mapbox Studio?