From 167ef4aa1e4e30a1f957595def95579a4b3397b0 Mon Sep 17 00:00:00 2001 From: danzel Date: Mon, 20 Aug 2012 10:59:27 +1200 Subject: [PATCH] Remove coverage polygon from map when we are removed from the map. Fixes #38 --- src/MarkerClusterGroup.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index b68fdcf37..f685d8d82 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -192,6 +192,12 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ shownPolygon = null; } }, this); + map.on('layerremove', function (opt) { + if (shownPolygon && opt.layer === this) { + map.removeLayer(shownPolygon); + shownPolygon = null; + } + }, this); } },