simple question ... how to add animation to the marker of the cluster before the cluster draw it on the map !? I kept looking but no hope. I just need to know where to start
this is how I add my cluster and how I tried to do the animation
private class AddMarker implements Runnable {
private MarkerOptions options;
public AddMarker(MarkerOptions options) {
this.options = options;
}
@Override
public void run() {
MyPoi poi = new MyPoi(options.getPosition());
mClusterManager.addItem(poi);
List<Marker> markers = new ArrayList<>();
markers.addAll(mClusterManager.getMarkerCollection().getMarkers());
if(markers.size() == 0){
}else if (markers.size() == 1){
animateMarker(markers.get(0),Constants.MARKER_ADD);
}else if(markers.size() > 1){
animateMarker(markers.get(markers.size()-1),Constants.MARKER_ADD);
}
mClusterManager.cluster();
//Marker newMarker = googleMap.addMarker(options);
//newMarker.setIcon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE));
}
}
Here is my solution:
private void setMarkerBounce(Marker marker) {
for (final com.google.android.gms.maps.model.Marker m : mClusterManager.getMarkerCollection().getMarkers()) {
if (m.getPosition().equals(marker.getPosition())) {
final Handler handler = new Handler();
final long startTime = SystemClock.uptimeMillis();
final long duration = 2000;
final Interpolator interpolator = new BounceInterpolator();
handler.post(new Runnable() {
@Override
public void run() {
long elapsed = SystemClock.uptimeMillis() - startTime;
float t = Math.max(1 - interpolator.getInterpolation((float) elapsed / duration), 0);
m.setAnchor(0.5f, 1.0f + t);
if (t > 0.0) {
handler.postDelayed(this, 16);
}
}
});
return;
}
}
}
It's a bit ugly, but works fine. You have to pass your custom ClusterItem instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With