Oliver Roick

Leaflet.Deflate 0.2

Recently, I have rolled out an update to Leaflet.Deflate, which adds a few changes and new features.

Instantiating the plugin and adding it to the map is now more in line with other Leaflet plugins:

var map = L.map("map");
L.Deflate({minSize: 10}).addTo(map);

Big thanks to Lindsey Jacks, who helped with this.

Then, you can apply Leaflet.Deflate to selected features by adding the features to a FeatureGroup and then appying Leaflet.Deflate to that FeatureGroup. Here’s how:

var map = L.map("map");

var featureGroup = L.featureGroup().addTo(map)
L.Deflate({minSize: 10, featureGroup: featureGroup}).addTo(map);

// The polygon will be deflated
var polygon = L.polygon([
    [51.509, -0.08],
    [51.503, -0.06],
    [51.51, -0.047]
]);
featureGroup.addLayer(polygon);

And finally, you can cluster markers using Leaflet.Markercluster and Leaflet.Markercluster.LayerSupport. Again, add the features to a FeatureGroup and then check-in the FeatureGroup with a MarkerClusterGroup:

var featureGroup = L.featureGroup();
L.Deflate({minSize: 10, featureGroup: featureGroup}).addTo(map);

var polygon = L.polygon([
    [51.509, -0.08],
    [51.503, -0.06],
    [51.51, -0.047]
]);
featureGroup.addLayer(polygon);

var markerGroup = L.markerClusterGroup.layerSupport()
markerGroup.addTo(map);
markerGroup.checkIn(featureGroup);
featureGroup.addTo(map);