amaury1093/react-mapbox-gl-draw

Draw Events

Closed this issue · 4 comments

Hello,

How can I attach event listeners?

Thanks

I did a fork that implements the draw events as props here . Let me know if it helps or any improvements.. thanks

Hi @rcbyrne. As stated in the react-mapbox-gl docs, you can get access to the map object in onStyleLoad.

Once you have the map object, a simple

map.on('draw.create', function (e) {
  console.log(e.features);
});

would do the trick.

Here's the full code:

<Map
  // ...other props
  onStyleLoad={map => {
    map.on('draw.create', e => {
      console.log(e.features);
    });
  }}
/>

Another method proposed by @erick-otenyo with props, see ongoing PR #5.

Fixed by #5.

Awesome