Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions lib/src/marker_cluster_layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ class _MarkerClusterLayerState extends State<MarkerClusterLayer>

_MarkerClusterLayerState();

bool _shouldSpiderfy(MarkerClusterNode cluster) {
return widget.options.spiderfyCluster &&
(widget.options.disableSpiderfyAboveMarkerCount <= 0 ||
cluster.markers.length <=
widget.options.disableSpiderfyAboveMarkerCount);
}

bool _isSpiderfyCluster(MarkerClusterNode cluster) {
return spiderfyCluster != null &&
spiderfyCluster!.bounds.center == cluster.bounds.center;
Expand Down Expand Up @@ -623,7 +630,7 @@ class _MarkerClusterLayerState extends State<MarkerClusterLayer>
widget.options.onClusterTap?.call(cluster);

if (!widget.options.zoomToBoundsOnClick) {
if (widget.options.spiderfyCluster) {
if (_shouldSpiderfy(cluster)) {
if (spiderfyCluster != null) {
if (spiderfyCluster == cluster) {
_unspiderfy();
Expand Down Expand Up @@ -691,7 +698,7 @@ class _MarkerClusterLayerState extends State<MarkerClusterLayer>
zoomTween.begin == zoomTween.end;

if (isAlreadyFit) {
if (cannotDivide && widget.options.spiderfyCluster) {
if (cannotDivide && _shouldSpiderfy(cluster)) {
_spiderfy(cluster);
}
return;
Expand All @@ -711,7 +718,7 @@ class _MarkerClusterLayerState extends State<MarkerClusterLayer>
..removeListener(listener)
..reset();

if (cannotDivide && widget.options.spiderfyCluster) {
if (cannotDivide && _shouldSpiderfy(cluster)) {
_spiderfy(cluster);
}
});
Expand Down
5 changes: 5 additions & 0 deletions lib/src/marker_cluster_layer_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ class MarkerClusterLayerOptions {
/// If false remove spiderfy effect on tap
final bool spiderfyCluster;

/// If set, spiderfy will be disabled above this marker count
/// 0 -> No limit
final int disableSpiderfyAboveMarkerCount;

/// Increase to increase the distance away that circle spiderfied markers appear from the center
final int spiderfyCircleRadius;

Expand Down Expand Up @@ -210,6 +214,7 @@ class MarkerClusterLayerOptions {
this.circleSpiralSwitchover = 9,
this.spiderfyShapePositions,
this.spiderfyCluster = true,
this.disableSpiderfyAboveMarkerCount = 0,
this.polygonOptions = const PolygonOptions(),
this.showPolygon = true,
this.onMarkerTap,
Expand Down