makinacorpus / Leaflet.Spin

Show a spinner on the map using Spin.js
http://makinacorpus.github.io/Leaflet.Spin/
MIT License
134 stars 49 forks source link

Problem when calling this.spin(true) more times than this.spin(false) #25

Open woodwards opened 4 years ago

woodwards commented 4 years ago

I am trying to use Leaflet.Spin in R Shiny to show the spinner when adding layers to the map. I've done this by setting up events as suggested here and shown below.

I'm having trouble because this.spin(true) increments this._spinning while this.spin(false) decrements it. If I remove more layers than I add then this._spinning remains above zero and the spinner doesn't switch off. How would I fix this? Thanks!


function(el, x) {
  console.log('spin event added'); 
  this.on('layerremove', function(e) {
    console.log('layerremove fired');
    this.spin(true);
  });
  this.on('layeradd', function(e) {
    console.log('layeradd fired');
    this.spin(false);
  })
}