Issue on removing item from clustermanager

DonaDev picture DonaDev · Feb 26, 2014 · Viewed 7.4k times · Source

In my Android application, I have to delete and re-add a cluster item in my GoogleMap, that represents my current location. But when I run this code:

clusterMng.remove(myitem);

I get this Exception:

java.lang.UnsupportedOperationException: NonHierarchicalDistanceBasedAlgorithm.remove    
not implemented.

Can someone explain to me what this means? Do I have to rewrite some methods of ClusterManager.java in the external library? Or can I simply change my algorithm?

Answer

Serge Populov picture Serge Populov · Mar 5, 2014

By default ClusterManager uses NonHierarchicalDistanceBasedAlgorithm, that doesn't implement removing elements.

Try to use GridBasedAlgorithm instead (it supports elements remove):

clusterMng.setAlgorithm(new GridBasedAlgorithm<MyClusterItem>());

Or, for better performance, wrap it with PreCachingAlgorithmDecorator, as ClusterManager does by default:

clusterMng.setAlgorithm(new PreCachingAlgorithmDecorator<MyClusterItem>(new GridBasedAlgorithm<MyClusterItem>()));