Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Removal from map no longer removes any markers or clusters. #108

Closed
Driklyn opened this issue Dec 18, 2012 · 2 comments
Closed

[BUG] Removal from map no longer removes any markers or clusters. #108

Driklyn opened this issue Dec 18, 2012 · 2 comments

Comments

@Driklyn
Copy link

Driklyn commented Dec 18, 2012

PROBLEM

After updating to the latest version, I noticed that removing a L.MarkerClusterGroup from a map no longer removes any markers or clusters. Good news is it's an easy fix.

In L.MarkerClusterGroup's onRemove function, you have this code:

this._map = null;

//Clean up all the layers we added to the map
for (var i in this._layers) {
    if (this._layers.hasOwnProperty(i)) {
        L.FeatureGroup.prototype.removeLayer.call(this, this._layers[i]);
    }
}

Trouble is, _this.map is set to null before L.FeatureGroup's removeLayer is called, which relies on _this.map (technically L.LayerGroup's removeLayer does) with this code:

if (this._map) {
    this._map.removeLayer(layer);
}

Since _this.map is already set to null by the time the above code executes, nothing happens.

SOLUTION

Set this.map to null _after removeLayer is called:

//Clean up all the layers we added to the map
for (var i in this._layers) {
    if (this._layers.hasOwnProperty(i)) {
        L.FeatureGroup.prototype.removeLayer.call(this, this._layers[i]);
    }
}

this._map = null;
@danzel
Copy link
Member

danzel commented Dec 18, 2012

lmao thanks :-)
I'll fix this up later today!

@Driklyn
Copy link
Author

Driklyn commented Dec 18, 2012

:)

@danzel danzel closed this as completed in 46ca075 Dec 21, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants