CloudMade/Leaflet — Issue #325: removeIcon marker error
Author: jfgirard
Created: 2011-10-13 17:50:19+00:00
State: open

Hi,

I'm using leaflet with a lot of markers. I add and remove markers on pan and zoom. Using the stable branch, it's OK. But using the master, I get an error saying this._map is null in the _removeIcon function of the Marker class. I cannot just do nothing if the _map is null because I get invalid markers on the map. Luckily, I only have one map to show. I can easily set the this._map back if it's missing.

Here is the patch i made in my application code to remove the error.
var map = new L.Map('map', {});
L.Marker.prototype._removeIcon = function() {
//add this if to set the missing this_map value
if (!this._map) {
this._map = map;
}
this._map._panes.markerPane.removeChild(this._icon);
if (this._shadow) {
this._map._panes.shadowPane.removeChild(this._shadow);
}
this._icon = this._shadow = null;
}

Jeff