Skip to content

#15 Support showing ClusteredPoint at centroid of all contained points instead of at initial point. #16

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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
18 changes: 18 additions & 0 deletions library/src/com/twotoasters/clusterkraf/ClusterPoint.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
* due to pixel proximity
*/
public class ClusterPoint extends BasePoint {
private static Options options;

private final ArrayList<InputPoint> pointsInClusterList = new ArrayList<InputPoint>();
private final HashSet<InputPoint> pointsInClusterSet = new HashSet<InputPoint>();
Expand All @@ -36,9 +37,23 @@ void add(InputPoint point) {
pointsInClusterList.add(point);
pointsInClusterSet.add(point);

if (options.isClusterShownAtCentroid()) {
mapPosition = getCenterLatLng();
}

boundsOfInputPoints = null;
}

private LatLng getCenterLatLng() {
LatLngBounds bounds = getBoundsOfInputPoints();
LatLng loc = new LatLng(avg(bounds.northeast.latitude, bounds.southwest.latitude), avg(bounds.northeast.longitude, bounds.southwest.longitude));
return loc;
}

private double avg(double a, double b) {
return (a + b) / 2;
}

ArrayList<InputPoint> getPointsInCluster() {
return pointsInClusterList;
}
Expand Down Expand Up @@ -92,4 +107,7 @@ LatLngBounds getBoundsOfInputPoints() {
return boundsOfInputPoints;
}

public static void setOptions(Options options) {
ClusterPoint.options = options;
}
}
1 change: 1 addition & 0 deletions library/src/com/twotoasters/clusterkraf/Clusterkraf.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class Clusterkraf {
public Clusterkraf(GoogleMap map, Options options, ArrayList<InputPoint> points) {
this.mapRef = new WeakReference<GoogleMap>(map);
this.options = options;
ClusterPoint.setOptions(options);
this.innerCallbackListener = new InnerCallbackListener(this);
this.transitionsAnimation = new ClusterTransitionsAnimation(map, options, innerCallbackListener);

Expand Down
15 changes: 15 additions & 0 deletions library/src/com/twotoasters/clusterkraf/Options.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,13 @@ public class Options {
* triggering cluster update processes.
*/
private long clusteringOnCameraChangeListenerDirtyLifetimeMillis = 200l;

/**
* controls location of the cluster marker. If true, it is shown at the center
* of the clustered points bounding box. If false, it is shown on the default
* location (which is a marker's location).
*/
private boolean showClusterOnCentroid = false;

/**
*
Expand Down Expand Up @@ -337,6 +344,14 @@ long getClusteringOnCameraChangeListenerDirtyLifetimeMillis() {
public void setClusteringOnCameraChangeListenerDirtyLifetimeMillis(long clusteringOnCameraChangeListenerDirtyLifetimeMillis) {
this.clusteringOnCameraChangeListenerDirtyLifetimeMillis = clusteringOnCameraChangeListenerDirtyLifetimeMillis;
}

public void setClusterShownAtCentroid(boolean showClusterOnCentroid) {
this.showClusterOnCentroid = showClusterOnCentroid;
}

public boolean isClusterShownAtCentroid() {
return showClusterOnCentroid;
}

ProcessingListener getProcessingListener() {
return processingListener;
Expand Down