Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ClusterManager.clearItems() does not clear items

This is a follow-up to my previous question: ClusterManager isn't redrawing Markers

I've done some investigation and found something interesting. ClusterManager.clearItems() does not always clear items.

After adding one marker to the ClusterManager I run this block:

mClusterManager.clearItems();
Log.d(TAG, "Marker list is empty: " + String.valueOf(mClusterManager.getMarkerCollection().getMarkers().isEmpty()));
for (Marker m : mClusterManager.getMarkerCollection().getMarkers()) {
    Log.d(TAG, m.getId() + "| "  + m.getPosition());
}

Which provides the following output:

02-03 12:30:52.953 14328-14328/com.app.mobile D/app:MapsActivity: Marker list is empty: false
02-03 12:30:52.954 14328-14328/com.app.mobile D/app:MapsActivity: m7| lat/lng: (33.2980945,-111.953964)

It is never empty in spite of clear being called. What's going on here?

If it never empties, is adding an updated m7 Marker to the ClusterManager ignored?

Link to Google's implementation of clearItems()

like image 903
nukeforum Avatar asked Feb 03 '16 19:02

nukeforum


2 Answers

Call the cluster() function just after clearItems()

like image 79
foobarcode Avatar answered Sep 20 '22 14:09

foobarcode


I ended up discovering that my override implementation of hashCode() in my implementation of Marker was causing the usual replace/remove/clear functionality to malfunction.

My solution was to remove my implementation of hashCode() and work around my need for a custom hash solution.

like image 32
nukeforum Avatar answered Sep 16 '22 14:09

nukeforum