I am using the [Leaflet markercluster plug in][1], and now want to add a button to turn the clustering on/off. For that I wanted to use the [leaflet button plug in][2], because I am already using it in my code.

I tried around with this piece of code and customized the lines with "sidebar" in it.

    var button = new L.Control.Button('Toggle me', {
    toggleButton: 'active'
    });
    button.addTo(map);
    button.on('click', function () {
    if (button.isToggled()) {
        sidebar.hide();
    } else {
        sidebar.show();
    }
    });

I also have an overlay where I want to implement those layers then.

How I cluster my markers:

    var extern2 = L.markerClusterGroup();
    extern2.addLayer(extern);

I am also using an overlay where the layer is defined like this:

     active:true,
	 name: "externe Maschinen",
	 layer: extern

And I am also doing some visual customization of the overlay with the following code:

    var panelElement = document.getElementById(extern._leaflet_id);
    panelElement.parentNode.parentNode.style = 'border-color: #508B1B';

Do I just delete the old overlay and create a new one? Becuase thats what I tried. This sort of works as it unclusters the Markers but I am having trouble trying to remove the old Overlay, which stays on the screen.




  [1]: https://github.com/Leaflet/Leaflet.markercluster
  [2]: https://github.com/jerroydmoore/leaflet-button