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

Moving a marker throws an error and marker disappears #11

Closed
AsamK opened this issue Aug 15, 2017 · 3 comments
Closed

Moving a marker throws an error and marker disappears #11

AsamK opened this issue Aug 15, 2017 · 3 comments

Comments

@AsamK
Copy link
Contributor

AsamK commented Aug 15, 2017

Moving a marker inside a MarkerCluster.LayerSupport layer with marker.setLatLng() produces an error:

error TypeError: Cannot read property 'x' of undefined
    at L.DistanceGrid._sqDist (https://unpkg.com/[email protected]/dist/leaflet.markercluster-src.js:1917:20)
    at L.DistanceGrid.getNearObject (https://unpkg.com/[email protected]/dist/leaflet.markercluster-src.js:1899:20)
    at NewClass._addLayer (https://unpkg.com/[email protected]/dist/leaflet.markercluster-src.js:984:36)
    at NewClass.<anonymous> (https://unpkg.com/[email protected]/dist/leaflet.markercluster-src.js:253:11)
    at NewClass.addLayers (https://unpkg.com/[email protected]/dist/leaflet.markercluster-src.js:287:4)
    at NewClass.addLayers (https://unpkg.com/[email protected]/dist/leaflet.markercluster.layersupport-src.js:115:8)
    at NewClass._processSingleAddRemoveBuffer (https://unpkg.com/[email protected]/dist/leaflet.markercluster.layersupport-src.js:267:29)

See: https://playground-leaflet.rhcloud.com/cave/edit?html,output

The problem is that LayerSupport buffers the add/remove operations and MarkerCluster implements moving a marker via removing and readding the marker. MarkerCluster expects the remove/add calls to be synchronous:

	_moveChild: function (layer, from, to) {
		layer._latlng = from;
		this.removeLayer(layer);

		layer._latlng = to;
		this.addLayer(layer);
	},

The issue can be worked around by disabling buffering in LayerSupport (by setting singleAddRemoveBufferDuration: 0).
See: https://playground-leaflet.rhcloud.com/yayab/edit?html,output

I'm not sure if this issue can be fixed in LayerSupport, or needs an improved move behaviour in MarkerCluster.

@ghybs
Copy link
Owner

ghybs commented Aug 22, 2017

Hi,

Thank you for the detailed report!

Hum I see the issue…
I cannot think of an easy solution to make _moveChild compatible with singleAddRemoveBufferDuration right now.

As you say, the easy workaround is to set singleAddRemoveBufferDuration option to 0.
Maybe it could be even better to have 0 as the default value?
Or at least mention it in the README?

@AsamK
Copy link
Contributor Author

AsamK commented Aug 23, 2017

Hm, I think making 0 the default value would be good then. It's better to work correctly by default than optimize for performance. The singleAddRemoveBufferDuration option should be documented to have issues with moving markers.

@ghybs
Copy link
Owner

ghybs commented Feb 6, 2018

Shipped in version v2.0.0

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