From 949d88ae6dc474c3ff350ceefaaabcbc6470b72c Mon Sep 17 00:00:00 2001 From: ghybs Date: Sat, 25 Nov 2017 10:46:00 +0400 Subject: [PATCH 1/2] Fix(Spiderfier): min leg distance for circle and skip 1st pos for spiral so that markers (especially important for Circle Markers, which are displayed under DivIcons by default) are positioned outside the default Cluster icon in all situations. --- src/MarkerCluster.Spiderfier.js | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/MarkerCluster.Spiderfier.js b/src/MarkerCluster.Spiderfier.js index 39ccda1d..6634037c 100644 --- a/src/MarkerCluster.Spiderfier.js +++ b/src/MarkerCluster.Spiderfier.js @@ -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, @@ -57,6 +57,8 @@ 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--) { @@ -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; From e8ca4e8c6dde7e912ee53727bd5b7ed82dc87758 Mon Sep 17 00:00:00 2001 From: ghybs Date: Sat, 25 Nov 2017 12:55:34 +0400 Subject: [PATCH 2/2] Refactor(Spiderfier): circle spiderfy clockwise like spiral so that the switch between circle and spiral is less disruptive. --- src/MarkerCluster.Spiderfier.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MarkerCluster.Spiderfier.js b/src/MarkerCluster.Spiderfier.js index 6634037c..7c9574d4 100644 --- a/src/MarkerCluster.Spiderfier.js +++ b/src/MarkerCluster.Spiderfier.js @@ -61,7 +61,7 @@ L.MarkerCluster.include({ 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(); }