trafficonese / leaflet.extras

Extra functionality for leaflet R package.
https://trafficonese.github.io/leaflet.extras/
GNU General Public License v3.0
211 stars 74 forks source link

How to programmatically click element on DrawToolbar? #203

Closed Camil88 closed 3 years ago

Camil88 commented 3 years ago

Hello, for some reasons I would like to draw polygon using button but not the one from the Toolbar, just my own button. I tried to use jquery to trigger 'click' action on toolbar but can't do this at all. I noticed that 'buttons' on toolbar are not really buttons but simple classes and I think this is the reson. I also tried to use observeEvent but it doesn't work either. Here is working example and my post on SO: https://stackoverflow.com/questions/66765995/how-to-programmatically-click-element-on-drawtoolbar/66766650#66766650

Is it possible at all? I'm struggling with this issue.

Camil88 commented 3 years ago

Solved. In jQuery this code should be used in function part:

document.querySelector('.leaflet-draw-draw-polygon').click();