trafficonese / leaflet.extras

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

'draw_start' and 'draw_stop' events only trigger when new shape type is used #144

Closed atmichel closed 5 years ago

atmichel commented 6 years ago

I am using _draw_start and _draw_stop as events, but they don't trigger unless a different shape type is drawn (e.g., first a rectangle, then a polygon), which causes problems when I draw multiple rectangles, for example. This behavior is clear in the draw-events example. Any other events I can use that correspond with a draw shape button click?

atmichel commented 5 years ago

I revisited this problem this week and found a solution by editing lfx-draw-bindings.js and adding a nonce to the event listeners DRAWSTART and DRAWSTOP, as follows:

map.on(L.Draw.Event.DRAWSTART, function(e) {
      if (!HTMLWidgets.shinyMode) return;
      Shiny.onInputChange(map.id+'_draw_start', {'feature_type': e.layerType, 'nonce': Math.random()});
    });

    map.on(L.Draw.Event.DRAWSTOP, function(e) {
      if (!HTMLWidgets.shinyMode) return;
      Shiny.onInputChange(map.id+'_draw_stop', {'feature_type': e.layerType,'nonce': Math.random()});
    });