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


Animate Property Value

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

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.

Mapbox Android: How to set padding in Location Layer plugin

LocationLayer plugin allows changing most of style defining custom styles in res but for padding we have to use LocationLayerOptions to set padding.
Here’s an example to set padding on top, to shift camera a bit below.

LocationLayerOptions options = locationLayerPlugin
                    .getLocationLayerOptions() // Get current options
                    .toBuilder() // Convert to LocationLayerOptions.Builder
                    .padding(new int[]{0, 800, 0, 0}) // Change padding (Left, Top, Right, Bottom)
                    .build(); // Build back with new padding
locationLayerPlugin.applyStyle(options); //Set new options

It took me a while to figure this, hope this will be helpful for someone. Let me know if you know any better implementation in comments below.

So, Make As Many Mistakes As You Can

It is wrongly assumed that mistakes are not good.
Mistakes are good, NOT learning from your mistake is NOT good.
Learning from our mistakes is essential to positively move forward.

Here, I’m NOT referencing to any particular “mistakes”. Mistakes might be a mistake you made deciding your career, or a mistake of leaving a semicolon at end of a syntax. It doesn’t matter.