urbica / react-map-gl

React Component Library for Mapbox GL JS
https://urbica.github.io/react-map-gl/
MIT License
416 stars 50 forks source link

Question: How to implement user interaction with layers #554

Closed derwaldgeist closed 11 months ago

derwaldgeist commented 11 months ago

We'd like to have the user draw a simple rectangle on top of the map, to mark a specific region. Is such interactivity possible with this library?

I found this addon for react-map-gl, but I don't know if it is possible to make it work with Urbica's implementation:

https://github.com/mapbox/mapbox-gl-draw

Basically, I want to achieve something like this:

https://visgl.github.io/react-map-gl/examples/draw-polygon

stepankuzmin commented 11 months ago

Hi @derwaldgeist 👋

There is a separate React wrapper for Mapbox GL Draw: https://github.com/urbica/react-map-gl-draw

derwaldgeist commented 11 months ago

Wow, I did not see that, that's awesome! Thanks for the super fast response.

Does it work with mapbox-gl 1.x? I am still using this version because I am connecting to maptiler instead of mapbox, as it is a cheaper service.

I had tried to integrate the regular drawing package (not the urbica one) yesterday. It kind of worked, but when I tried to add a Feature on load, I got an exception ("ctx.store" was not found). Will try your version now.

Have a Happy New Year!

derwaldgeist commented 11 months ago

Ok, it works! Thanks again!