Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information