Aditya's Blog

Mapbox Android: Animate Icon Size

We can animate almost any style property of Mapbox elements using ValueAnimator class in Android (minSdk 11). Here’s an example using Mapbox recommended method customization using Source Layer+ Expression Styles:

Style Expression

symbolLayer.setProperties(
        iconSize(get("icon-size"))
);

Animate Property Value

ValueAnimator markerAnimator = new ValueAnimator();
markerAnimator.setObjectValues(1f, 1.5f, 1f);
markerAnimator.setDuration(1200);
markerAnimator.setRepeatCount(ValueAnimator.INFINITE);
markerAnimator.addUpdateListener(animation -> {
    animatePoint.addNumberProperty("icon-size", (float) animation.getAnimatedValue());
    geoJsonSource.setGeoJson(featureCollection);
    //geoJsonSource is of class GeoJsonSource, featureCollection is of clas FeatureCollection and animatePoint is Feature residing in featureCollection
});
markerAnimator.start();

You can, obiviously, use any Expression in style layer with and customize animatation using many customization method of ValueAnimator class (such as duration, repeat, custom interpolator).

Let me know if you any question in comments below.