Skip to content

Commit

Permalink
Merge pull request #67 from jakeonrails/master
Browse files Browse the repository at this point in the history
Finish pull request for issue #50 (mapping markers to clusters, cluster items, and vice-versa)
  • Loading branch information
broady committed Jun 19, 2014
2 parents ec675b2 + 60b5501 commit f83f36c
Showing 1 changed file with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ public class DefaultClusterRenderer<T extends ClusterItem> implements ClusterRen
* Lookup between markers and the associated cluster.
*/
private Map<Marker, Cluster<T>> mMarkerToCluster = new HashMap<Marker, Cluster<T>>();
private Map<Cluster<T>, Marker> mClusterToMarker = new HashMap<Cluster<T>, Marker>();

/**
* The target zoom level for the current set of clusters.
Expand Down Expand Up @@ -610,6 +611,8 @@ private void performNextTask() {
}

private void removeMarker(Marker m) {
Cluster<T> cluster = mMarkerToCluster.get(m);
mClusterToMarker.remove(cluster);
mMarkerCache.remove(m);
mMarkerToCluster.remove(m);
mClusterManager.getMarkerManager().remove(m);
Expand Down Expand Up @@ -715,6 +718,42 @@ protected void onClusterRendered(Cluster<T> cluster, Marker marker) {
*/
protected void onClusterItemRendered(T clusterItem, Marker marker) {
}

/**
* Get the marker from a ClusterItem
* @param clusterItem ClusterItem which you will obtain its marker
* @return a marker from a ClusterItem or null if it does not exists
*/
protected Marker getMarker(T clusterItem) {
return mMarkerCache.get(clusterItem);
}

/**
* Get the ClusterItem from a marker
* @param marker which you will obtain its ClusterItem
* @return a ClusterItem from a marker or null if it does not exists
*/
protected T getClusterItem(Marker marker) {
return mMarkerCache.get(marker);
}

/**
* Get the marker from a Cluster
* @param cluster which you will obtain its marker
* @return a marker from a cluster or null if it does not exists
*/
protected Marker getMarker(Cluster<T> cluster) {
return mClusterToMarker.get(cluster);
}

/**
* Get the Cluster from a marker
* @param marker which you will obtain its Cluster
* @return a Cluster from a marker or null if it does not exists
*/
protected Cluster<T> getCluster(Marker marker) {
return mMarkerToCluster.get(marker);
}

/**
* Creates markerWithPosition(s) for a particular cluster, animating it if necessary.
Expand Down Expand Up @@ -772,6 +811,7 @@ private void perform(MarkerModifier markerModifier) {

Marker marker = mClusterManager.getClusterMarkerCollection().addMarker(markerOptions);
mMarkerToCluster.put(marker, cluster);
mClusterToMarker.put(cluster, marker);
MarkerWithPosition markerWithPosition = new MarkerWithPosition(marker);
if (animateFrom != null) {
markerModifier.animate(markerWithPosition, animateFrom, cluster.getPosition());
Expand Down Expand Up @@ -841,6 +881,8 @@ public void perform() {
@Override
public void onAnimationEnd(Animator animation) {
if (mRemoveOnComplete) {
Cluster<T> cluster = mMarkerToCluster.get(marker);
mClusterToMarker.remove(cluster);
mMarkerCache.remove(marker);
mMarkerToCluster.remove(marker);
mMarkerManager.remove(marker);
Expand Down Expand Up @@ -868,4 +910,4 @@ public void onAnimationUpdate(ValueAnimator valueAnimator) {
marker.setPosition(position);
}
}
}
}

0 comments on commit f83f36c

Please sign in to comment.