L.Deflate = L.FeatureGroup.extend({
    options: {
        minSize: 10,
        markerCluster: false,
        markerOptions: {},
        markerClusterOptions: {}
    },

    initialize: function (options) {
        L.Util.setOptions(this, options);
        this._allLayers = [];
        this._featureGroup = this.options.markerCluster ? L.markerClusterGroup(this.options.markerClusterOptions) : L.featureGroup();
    },

    _isCollapsed: function(path, zoom) {
        var bounds = path.getBounds();

        var ne_px = this._map.project(bounds.getNorthEast(), zoom);
        var sw_px = this._map.project(bounds.getSouthWest(), zoom);

        var width = ne_px.x - sw_px.x;
        var height = sw_px.y - ne_px.y;
        return (height < this.options.minSize || width < this.options.minSize);
    },

    _getZoomThreshold: function(path) {
        var zoomThreshold = null;
        var zoom = this._map.getZoom();
        if (this._isCollapsed(path, this._map.getZoom())) {
            while (!zoomThreshold) {
                zoom += 1;
                if (!this._isCollapsed(path, zoom)) {
                    zoomThreshold = zoom - 1;
                }
            }
        } else {
            while (!zoomThreshold) {
                zoom -= 1;
                if (this._isCollapsed(path, zoom)) {
                    zoomThreshold = zoom;
                }
            }
        }
        return zoomThreshold;
    },

    _bindInfoTools: function(marker, parentLayer) {
        if (parentLayer._popupHandlersAdded) {
            marker.bindPopup(parentLayer._popup._content, parentLayer._popup.options);
        }

        if (parentLayer._tooltipHandlersAdded) {
            marker.bindTooltip(parentLayer._tooltip._content, parentLayer._tooltip.options);
        }
    },

    _bindEvents: function(marker, parentLayer) {
        this._bindInfoTools(marker, parentLayer);

        var events = parentLayer._events;
        for (var event in events) {
            if (events.hasOwnProperty(event)) {
                var listeners = events[event];
                for (var i = 0, len = listeners.length; i < len; i++) {
                    marker.on(event, listeners[i].fn);
                }
            }
        }

        // For FeatureGroups we need to bind all events, tooltips and popups
        // from the FeatureGroup to each marker
        if (!parentLayer._eventParents) { return; }

        for (var key in parentLayer._eventParents) {
            if (parentLayer._eventParents.hasOwnProperty(key)) {
                if (parentLayer._eventParents[key]._map) { continue; }
                this._bindEvents(marker, parentLayer._eventParents[key]);

                // We're copying all layers of a FeatureGroup, so we need to bind
                // all tooltips and popups to the original feature.
                this._bindInfoTools(parentLayer, parentLayer._eventParents[key]);
            }
        }
    },

    _makeMarker: function(layer) {
        var markerOptions;

        if (typeof this.options.markerOptions === 'function') {
            markerOptions = this.options.markerOptions(layer);
        } else {
            markerOptions = this.options.markerOptions;
        }

        var marker = L.marker(layer.getBounds().getCenter(), markerOptions);
        this._bindEvents(marker, layer);

        return marker
    },

    addLayer: function (layer) {
        if (layer instanceof L.FeatureGroup) {
            for (var i in layer._layers) {
                this.addLayer(layer._layers[i]);
            }
        } else {
            var layerToAdd = layer;
            if (layer.getBounds && !layer.zoomThreshold && !layer.marker) {
                var zoomThreshold = this._getZoomThreshold(layer);

                layer.zoomThreshold = zoomThreshold;
                layer.marker = this._makeMarker(layer);
                layer.zoomState = this._map.getZoom();

                if (this._map.getZoom() <= zoomThreshold) {
                    layerToAdd = layer.marker;
                }
                this._allLayers.push(layer);
            }

            this._featureGroup.addLayer(layerToAdd);    
        }
    },

    removeLayer: function(layer) {
        if (layer instanceof L.FeatureGroup) {
            for (var i in layer._layers) {
                this.removeLayer(layer._layers[i]);
            }
        } else {
            this._featureGroup.removeLayer(layer.marker);
            this._featureGroup.removeLayer(layer);

            var index = this._allLayers.indexOf(layer);
            if (index !== -1) { this._allLayers.splice(index, 1); }
        }
    },

    _switchDisplay: function(layer, showMarker) {
        if (showMarker) {
            this._featureGroup.addLayer(layer.marker);
            this._featureGroup.removeLayer(layer);
        } else {
            this._featureGroup.addLayer(layer);
            this._featureGroup.removeLayer(layer.marker);
        }
    },

    _deflate: function() {
        var bounds = this._map.getBounds();
        var endZoom = this._map.getZoom();
        var markersToAdd = [];
        var markersToRemove = [];

        for (var i = 0, len = this._allLayers.length; i < len; i++) {
            if (this._allLayers[i].zoomState !== endZoom && this._allLayers[i].getBounds().intersects(bounds)) {
                this._switchDisplay(this._allLayers[i], endZoom <= this._allLayers[i].zoomThreshold);
                this._allLayers[i].zoomState = endZoom;
            }
        }
    },

    getBounds: function() {
        return this._featureGroup.getBounds();
    },

    onAdd: function(map) {
        this._featureGroup.addTo(map);
        this._map.on("zoomend", this._deflate, this);
        this._map.on("moveend", this._deflate, this);
    },

    onRemove: function(map) {
        map.removeLayer(this._featureGroup);
        this._map.off("zoomend", this._deflate, this);
        this._map.off("moveend", this._deflate, this);
    }
});

L.deflate = function (options) {
    return new L.Deflate(options);
};

@@ -272,39 +272,35 @@
 s = %5B%5D;%0A        
-this._f
+L.F
 eatureGroup = th
@@ -298,113 +298,52 @@
 roup
- = this.options.markerCluster ? L.markerClusterGroup(this.options.markerClusterOptions) : L.featureGroup(
+.prototype.initialize.call(this, %5B%5D, options
 );%0A 
@@ -4026,39 +4026,35 @@
  %7D%0A%0A            
-this._f
+L.F
 eatureGroup.addL
@@ -4045,33 +4045,54 @@
 eatureGroup.
-addLayer(
+prototype.addLayer.call(this, 
 layerToAdd);
@@ -4091,20 +4091,16 @@
 rToAdd);
-    
 %0A       
@@ -4332,35 +4332,26 @@
       this._
-featureGrou
+ma
 p.removeLaye
@@ -4381,35 +4381,26 @@
       this._
-featureGrou
+ma
 p.removeLaye
@@ -4642,35 +4642,26 @@
       this._
-featureGrou
+ma
 p.addLayer(l
@@ -4688,35 +4688,26 @@
       this._
-featureGrou
+ma
 p.removeLaye
@@ -4747,35 +4747,26 @@
       this._
-featureGrou
+ma
 p.addLayer(l
@@ -4790,27 +4790,18 @@
   this._
-featureGrou
+ma
 p.remove
@@ -4956,73 +4956,8 @@
 m();
-%0A        var markersToAdd = %5B%5D;%0A        var markersToRemove = %5B%5D;
 %0A%0A  
@@ -5335,152 +5335,30 @@
     
-getBounds: function() %7B%0A        return this._featureGroup.getBounds();%0A    %7D,%0A%0A    onAdd: function(map) %7B%0A        this._featureGroup.addTo(map);
+onAdd: function(map) %7B
 %0A   
@@ -5504,53 +5504,8 @@
 ) %7B%0A
-        map.removeLayer(this._featureGroup);%0A
     

Remove inline FeatureGroup