Error when adding markers
See original GitHub issueWhen our markers have got an updated position we remove them from the cluster group and adds them again in order to “recluster”. A few times we have got an error in _addLayer function saying
TypeError: Cannot read property '_zoom' of undefined
The error ocurred in version v0.4.0-hotfix.1 together with leaflet 0.7.3, Chrome browser. I haven’t figured out exactly what the preconditions are in order to reproduce it in a fiddle, but I tracked it down to the following piece of code in function _addLayer of L.MarkerClusterGroup
if (closest) {
var parent = closest.__parent;
if (parent) {
this._removeLayer(closest, false);
}
//Create new cluster with these 2 in it
var newCluster = new L.MarkerCluster(this, zoom, closest, layer);
gridClusters[zoom].addObject(newCluster, this._map.project(newCluster._cLatLng, zoom));
closest.__parent = newCluster;
layer.__parent = newCluster;
//First create any new intermediate parent clusters that don't exist
var lastParent = newCluster;
for (z = zoom - 1; z > parent._zoom; z--) {
lastParent = new L.MarkerCluster(this, z, lastParent);
gridClusters[z].addObject(lastParent, this._map.project(closest.getLatLng(), z));
}
If closest.__parent is undefined then parent will be undefined. When parent._zoom is used in for loop we get the error.
Issue Analytics
- State:
- Created 8 years ago
- Comments:13 (6 by maintainers)
Top Results From Across the Web
How to get the Error Marker in Find the Markers - Roblox
To claim the Error Marker and add it to your Markerdex, simply walk up to it and touch it. Upon doing so, you...
Read more >Error Adding markers in seaborn pairplot in python
As the error clearly indicates, you cannot mixed filled and line markers. See the list of markers here: You need to either choose...
Read more >Add marker not working
I buyed the pro version and I have an error 500 when I want add a marker. Uncaught Error: Internal Server Error at...
Read more >Error when adding stimuli markers - Homer3 and ...
Hi Everyone, When attempting to add stimuli markers I get the error reported below. I had several stimuli markers that I made during...
Read more >Refresh the page error occurs after adding markers to a ...
Refresh the page error occurs after adding markers to a schedule for week, month or resource view. Repro Found in SF Maps v240.7....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think I get it.
If your marker changed position (coordinates) before you remove it, MCG may be in trouble properly eliminating its references from its internal
_gridUnclustered
Distance Grid: it reads its (new) coordinates, derives its associated grid (new) index and may not find it there, stopping reference elimination.Then you are left with a “ghost” in the Distance Grid, even though it is supposed to be removed. In particular,
removeLayer()
deleted its__parent
property.Then later when you add another marker (or even the same one!),
addLayer
may find this ghost and try to cluster with it, but it will fail reading properties of the ghost’s__parent
.Now, in MCG version v1.0.0-beta.2.0 and above (actually since Jan 2014 in commit https://github.com/Leaflet/Leaflet.markercluster/commit/27827b5d63317aa7fb6800500984857ca24f16fa of MCG branch compatible with Leaflet 1.0), MCG adds
"move"
event listener on all markers and automatically handles theremoveLayer
+addLayer
process for you, properly using the old position to avoid creating that “ghost” in Distance Grid.Therefore, if you are using Leaflet 0.7 with MCG 0.5, you could try removing your marker from MCG before actually moving it, if your application can handle the process that way.
But if you are already using Leaflet 1.0 with MCG 1.0 and the automatic clusters update does not happen, please try to bring more details and to provide a case reproduction so we can dig further.
Maybe my decision will help someone: