Skip to content

Commit

Permalink
Merge pull request #846 from ghybs/spiderfyLegFix
Browse files Browse the repository at this point in the history
Fix(Spiderfier): min leg length for circle and skip 1st pos for spiral
  • Loading branch information
danzel committed Nov 26, 2017
2 parents 645e3a8 + e8ca4e8 commit 584add2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/MarkerCluster.Spiderfier.js
Expand Up @@ -5,7 +5,7 @@ L.MarkerCluster.include({

_2PI: Math.PI * 2,
_circleFootSeparation: 25, //related to circumference of circle
_circleStartAngle: Math.PI / 6,
_circleStartAngle: 0,

_spiralFootSeparation: 28, //related to size of spiral (experiment!)
_spiralLengthStart: 11,
Expand Down Expand Up @@ -57,9 +57,11 @@ L.MarkerCluster.include({
res = [],
i, angle;

legLength = Math.max(legLength, 35); // Minimum distance to get outside the cluster icon.

res.length = count;

for (i = count - 1; i >= 0; i--) {
for (i = 0; i < count; i++) { // Clockwise, like spiral.
angle = this._circleStartAngle + i * angleStep;
res[i] = new L.Point(centerPt.x + legLength * Math.cos(angle), centerPt.y + legLength * Math.sin(angle))._round();
}
Expand All @@ -79,9 +81,13 @@ L.MarkerCluster.include({
res.length = count;

// Higher index, closer position to cluster center.
for (i = count - 1; i >= 0; i--) {
for (i = count; i >= 0; i--) {
// Skip the first position, so that we are already farther from center and we avoid
// being under the default cluster icon (especially important for Circle Markers).
if (i < count) {
res[i] = new L.Point(centerPt.x + legLength * Math.cos(angle), centerPt.y + legLength * Math.sin(angle))._round();
}
angle += separation / legLength + i * 0.0005;
res[i] = new L.Point(centerPt.x + legLength * Math.cos(angle), centerPt.y + legLength * Math.sin(angle))._round();
legLength += lengthFactor / angle;
}
return res;
Expand Down

0 comments on commit 584add2

Please sign in to comment.