Leaflet.markercluster icon indicating copy to clipboard operation
Leaflet.markercluster copied to clipboard

spiderfyShapePositions not working.

Open Alexithemia opened this issue 4 years ago • 4 comments

@noreflection @danzel

  • [X] I'm reporting a bug, not asking for help
  • [X ] I'm sure this is a Leaflet.MarkerCluster code issue, not an issue with my own code nor with the framework I'm using (Cordova, Ionic, Angular, React…)
  • [X] I've searched through the issues to make sure it's not yet reported

How to reproduce

  • Leaflet version I'm using: 1.5.1
  • Leaflet.MarkerCluster version I'm using: 1.4.1
  • Browser (with version) I'm using: Chrome
  • OS/Platform (with version) I'm using: Browser on windows/server hosted on centos7
  • Add a spiderfyShapePositions function to cluster options
  • Create a cluster on leaflet
  • spiderfy it

I'm am just testing with the example code in the readme and the spiderfy is still default spiral.

https://plnkr.co/edit/IBRJ0X49U8vjHlMN (right click to spiderfy)

  • [X] this example is as simple as possible
  • [X] this example does not rely on any third party code

Using http://leafletjs.com/edit.html

Alexithemia avatar May 08 '20 16:05 Alexithemia

Leaflet.Markercluster 1.4.1 was released on 14th September 2018 while spiderfyShapePositions was introduced 23rd September 2018. Not sure why there wasn't a new release in 2 years...

vchrisb avatar Jul 15 '20 12:07 vchrisb

I just came across this exact problem. A dirty fix is to manually overwrite MarkerCluster's spiderfy function with the newer version that does support adding a custom spiderfyShapePositions function. Add it to your project like this:

L.MarkerCluster.include({ spiderfy: function () {
	if (this._group._spiderfied === this || this._group._inZoomAnimation) {
		return;
	}

	var childMarkers = this.getAllChildMarkers(null, true),
		group = this._group,
		map = group._map,
		center = map.latLngToLayerPoint(this._latlng),
		positions;

	this._group._unspiderfy();
	this._group._spiderfied = this;

	//TODO Maybe: childMarkers order by distance to center

	if (this._group.options.spiderfyShapePositions) {
		positions = this._group.options.spiderfyShapePositions(childMarkers.length, center);
	} else if (childMarkers.length >= this._circleSpiralSwitchover) {
		positions = this._generatePointsSpiral(childMarkers.length, center);
	} else {
		center.y += 10; // Otherwise circles look wrong => hack for standard blue icon, renders differently for other icons.
		positions = this._generatePointsCircle(childMarkers.length, center);
	}

	this._animationSpiderfy(childMarkers, positions);
}});

It goes without saying that this should really only be temporary, while we wait for a new release.

rhlt avatar Aug 29 '20 14:08 rhlt

Not sure why there wasn't a new release in 2 years...

See #979

kentr avatar Nov 15 '20 20:11 kentr

¿Is this issue fixed even if it's not production ready?

ignacio-ambia-bego avatar Feb 02 '22 18:02 ignacio-ambia-bego