diff --git a/library/src/com/twotoasters/clusterkraf/ClusterPoint.java b/library/src/com/twotoasters/clusterkraf/ClusterPoint.java index d3a2948..09eb65c 100644 --- a/library/src/com/twotoasters/clusterkraf/ClusterPoint.java +++ b/library/src/com/twotoasters/clusterkraf/ClusterPoint.java @@ -12,6 +12,7 @@ * due to pixel proximity */ public class ClusterPoint extends BasePoint { + private static Options options; private final ArrayList pointsInClusterList = new ArrayList(); private final HashSet pointsInClusterSet = new HashSet(); @@ -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 getPointsInCluster() { return pointsInClusterList; } @@ -92,4 +107,7 @@ LatLngBounds getBoundsOfInputPoints() { return boundsOfInputPoints; } + public static void setOptions(Options options) { + ClusterPoint.options = options; + } } diff --git a/library/src/com/twotoasters/clusterkraf/Clusterkraf.java b/library/src/com/twotoasters/clusterkraf/Clusterkraf.java index 95a98c2..01e5035 100644 --- a/library/src/com/twotoasters/clusterkraf/Clusterkraf.java +++ b/library/src/com/twotoasters/clusterkraf/Clusterkraf.java @@ -51,6 +51,7 @@ public class Clusterkraf { public Clusterkraf(GoogleMap map, Options options, ArrayList points) { this.mapRef = new WeakReference(map); this.options = options; + ClusterPoint.setOptions(options); this.innerCallbackListener = new InnerCallbackListener(this); this.transitionsAnimation = new ClusterTransitionsAnimation(map, options, innerCallbackListener); diff --git a/library/src/com/twotoasters/clusterkraf/Options.java b/library/src/com/twotoasters/clusterkraf/Options.java index 2984f90..e7d396a 100644 --- a/library/src/com/twotoasters/clusterkraf/Options.java +++ b/library/src/com/twotoasters/clusterkraf/Options.java @@ -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; /** * @@ -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;