From 3ef5afc11fdb6cd07816448b2c4acc8c357883ce Mon Sep 17 00:00:00 2001 From: danzel Date: Tue, 7 Aug 2012 10:15:36 +1200 Subject: [PATCH] Make clearLayers work when we aren't on the map. Fixes #26 --- src/MarkerClusterGroup.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/MarkerClusterGroup.js b/src/MarkerClusterGroup.js index 417612ea2..ea4c24519 100644 --- a/src/MarkerClusterGroup.js +++ b/src/MarkerClusterGroup.js @@ -66,6 +66,12 @@ L.MarkerClusterGroup = L.FeatureGroup.extend({ clearLayers: function () { //Need our own special implementation as the LayerGroup one doesn't work for us + //If we aren't on the map yet, just blow away the markers we know of + if (!this._map) { + this._needsClustering = []; + return this; + } + //Remove all the visible layers for (var i in this._layers) { if (this._layers.hasOwnProperty(i)) {