rte-antares-rpackage / leaflet.minichart

Leaflet.minichart is a leaflet plugin for adding to a leaflet map small animated charts
https://rte-antares-rpackage.github.io/leaflet.minichart/
Other
31 stars 10 forks source link

Charts don't go away when overlay is deactivated in L.control.layers #6

Open fiendish opened 6 years ago

fiendish commented 6 years ago

If you have a layer control, deactivating any charts layer never actually hides them like it should.

I had to add this to make it work (I have all my charts in an L.layerGroup):

function hide_charts(e) {
   e.layer.eachLayer(
      function(t) {
         if (t._chart) { t._chart.remove(); }
      }
   );
}
map.on('overlayremove', hide_charts)
frankbroniewski commented 6 years ago

I would like to give this a bump, currently it isn't possible to remove charts from the map without using hacks like the above. It would be nice if L.minichart would respect the removeLayer-function call as all other layers do.

FrancoisGuillem commented 4 years ago

Hi,

Sorry if my answer comes very late. Is this still a problem? With Leaflet 1.3.1, I can correctly add and remove "minichart" layers. The following code works for me:

mylayer = L.minichart([0, 0], {data: 1234, type:"pie", labels:"auto"}).addTo(map)
map.removeLayer(mylayer)

Are you using a different version of leaflet or doing something different?

frankbroniewski commented 4 years ago

Hi Francois, I can't really tell. I haven't done any web maps with Leaflet in the last months so I cannot give you more feedback on the matter. If I recall correctly, my problem with the map not removing the charts layer was related to minZoom and maxZoom restrictions on the chart layer. If I remember that right, the chart layer was not removed when the maxZoom restriction kicked in ...

FrancoisGuillem commented 4 years ago

The problem has actually been fixed in version 0.2.5 by @bthieurmel . Thank you for your feedbacks.