trafficonese / leaflet.extras

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

Customizing Delete Layers button in draw #119

Open rfineman opened 6 years ago

rfineman commented 6 years ago

Is there a way to edit the "delete layers" button so that instead of providing the options Save|Cancel|Clear All, it merely clears all by clicking the trash can?

image

bhaskarvk commented 6 years ago

I am afraid not. It's a two step process AFAIK. Please check with original draw authers/repo if there is a known work-around.

trafficonese commented 7 months ago

Here is a workaround for a Shiny-App. Include this snippet anywhere in your ui.

  tags$script(HTML("
   $(document).ready(function() {
      function waitForElement() {
        var element = document.querySelector('.leaflet-draw-edit-remove');
        if (element) {
          element.addEventListener('click', function() {
            setTimeout(function() {
              var eletoclick = $('.leaflet-draw-actions li a')[3];
              if (eletoclick) {
                eletoclick.click();
              }
            }, 100);
          });
        } else {
          setTimeout(waitForElement, 100);
        }
      }
      waitForElement();
    });
    "))