nitaliano / react-native-mapbox-gl

A Mapbox GL react native module for creating custom maps
Other
2.16k stars 697 forks source link

Render markers, but with individual onPress #1474

Closed WeslleyNasRocha closed 5 years ago

WeslleyNasRocha commented 5 years ago

How can i implement some markers when i click on them i know which one was clicked? I've tried with:

<Mapbox.ShapeSource
  id="marker-source"
  onPress={event => {
    console.log(event.currentTarget);
  }}
  shape={this.markers()}
  >
    <Mapbox.SymbolLayer
    id="marker-style-layer"
    style={{
      iconAnchor: 'BOTTOM',
      iconImage: customMarker,
      iconSize: 0.3,
    }}
    />
</Mapbox.ShapeSource>

but every marker shows currentTarget === 77

winseyli commented 5 years ago
const feature = event.nativeEvent.payload;
console.log(feature);

Not sure if this helps.

kristfal commented 5 years ago

If you pass a property to the geoJSON, that property will be available in the payload.