Skip to content
Closed
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
2 changes: 2 additions & 0 deletions library/src/com/google/maps/android/clustering/Cluster.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ public interface Cluster<T extends ClusterItem> {
Collection<T> getItems();

int getSize();

boolean isOneLocation();
}
Original file line number Diff line number Diff line change
Expand Up @@ -184,5 +184,10 @@ public Set<T> getItems() {
public int getSize() {
return 1;
}

@Override
public boolean isOneLocation() {
return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,31 @@ public Collection<T> getItems() {
public int getSize() {
return mItems.size();
}

private static boolean isEqual(double d0, double d1) {
final double epsilon = 0.0000001;
return Math.abs(d0 - d1) < epsilon;
}

private static boolean isEqualPosition(LatLng position0, LatLng position1) {
return isEqual(position0.latitude, position1.latitude) &&
isEqual(position0.longitude, position1.longitude);
}

@Override
public boolean isOneLocation() {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is never called - did you mean to call this within "shouldRenderAsCluster"?

LatLng position = null;
for (T item : mItems) {
if (position == null || isEqualPosition(item.getPosition(), position)) {
position = item.getPosition();
} else {
position = null;
break;
}
}

return position != null;
}

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class DefaultClusterRenderer<T extends ClusterItem> implements ClusterRen
/**
* If cluster size is less than this size, display individual markers.
*/
private static final int MIN_CLUSTER_SIZE = 4;
private int mMinClusterSize = 4;

/**
* The currently displayed set of clusters.
Expand Down Expand Up @@ -213,7 +213,15 @@ protected int getBucket(Cluster<T> cluster) {
return BUCKETS[BUCKETS.length - 1];
}

/**
public int getMinClusterSize() {
return mMinClusterSize;
}

public void setMinClusterSize(int minClusterSize) {
mMinClusterSize = minClusterSize;
}

/**
* ViewModifier ensures only one re-rendering of the view occurs at a time, and schedules
* re-rendering, which is performed by the RenderTask.
*/
Expand Down Expand Up @@ -275,8 +283,8 @@ public void queue(Set<? extends Cluster<T>> clusters) {
/**
* Determine whether the cluster should be rendered as individual markers or a cluster.
*/
protected boolean shouldRenderAsCluster(Cluster cluster) {
return cluster.getSize() > MIN_CLUSTER_SIZE;
protected boolean shouldRenderAsCluster(Cluster<T> cluster) {
return cluster.getSize() > mMinClusterSize;
}

/**
Expand Down