I am clustering markers on a Google map on Android using a cluster from android-maps-utils . I want to disable clustering when the map is at the maximum zoom level (i.e. Always display individual ClusterItems objects if the map is at the maximum zoom level, otherwise the cluster is as usual).
I can almost get it working by running a test for the zoom level in shouldRenderAsCluster () in a custom class extending DefaultClusterRenderer. However, my solution is one step behind the actual zoom level. For example, if the maximum zoom for the map is level 21, and the user zooms in from level 20 to level 21, then the check will include the current zoom level 20. If the user is scaled to level 20, the check will get level 21 ClusterItems gets rendered as separate elements as I want, but one zoom action is too late.
I get "Current Zoom" (which, apparently, is not current) from the mZoom variable, which is set to DefaultClusterRenderer.
This is the code:
public class UserClusterRenderer extends PosMapDefaultClusterRenderer<UserClusterItem> {
@Override
protected boolean shouldRenderAsCluster(Cluster cluster) {
return mZoom < mMap.getMaxZoomLevel() && cluster.getSize() > 1;
}
}
mZoom mMap DefaultClusterRenderer. , DefaultClusterRenderer PosMapDefaultClusterRenderer. , mZoom mMap , UserClusterRenderer.
mZoom ? , ?
animateCamera . . .
StackOverflow, , .. .
: :
public class UserClusterRenderer extends DefaultClusterRenderer<UserClusterItem> {
GoogleMap mMapCopy;
@Override
protected boolean shouldRenderAsCluster(Cluster cluster) {
float currentZoom = mMapCopy.getCameraPosition().zoom;
float currentMaxZoom = mMapCopy.getMaxZoomLevel();
return currentZoom < currentMaxZoom && cluster.getSize() > 1;
}
}