Skip to content

DefaultClusterRenderer, check for mAnimate done sooner #337

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

Merged
merged 3 commits into from
Apr 18, 2018

Conversation

jeffdgr8
Copy link
Contributor

This avoids redundantly finding clusters that are close by when they're not needed for animation.

There was a bug where if a cluster already has a marker on the map when
a cluster operation occurs, the cluster would add a new marker without
reusing the existing marker. The new marker would update the mapping to
mClusterToMarker, adding a new mapping in mMarkerToCluster, while
leaving the old marker mapped in mMarkerToCluster. When the old marker
is then removed, it also removes the new marker's mapping in
mClusterToMarker.

This results in there no longer existing a mapping for the cluster in
mClusterToMarker and getMarker() returns null. If
OnClusterClickListener.onClusterClick() wants to do something like this:

public boolean onClusterClick(Cluster<ClusterItem> cluster) {
Marker marker = mClusterRenderer.getMarker(cluster);
marker.showInfoWindow(); <-- NullPointerException
}

it is unable.

This is easily reproducible by zooming on the map such that the clusters
don't change at all but a new cluster operation occurs. All of the
clusters that did not change at all will have the described issue.

The change uses the same pattern as cluster item uses to reuse an
existing marker for a cluster if it already exists, rather than creating
a new one and removing the old one. This ensures mClusterToMarker and
mMarkerToCluster are always the same size.

Also removed the OnInfoWindowClickListeners in onRemove() the same as
OnMarkerClickListeners. Both are added in onAdd().

Also, as mMap.getProjection() is annotated as @nonnull, the check for
projection == null was unneccesary.
This avoids redundantly finding clusters that are close by when they're
not needed for animation.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants