Search code examples
javaandroidmapboxmapbox-android

Animate the Mapbox Camera in v10


In mapbox v9 I could animate the camera using the animatecamera method.

In mapbox v10 it says to use flyTo or easeTo. However none of these methods exist in the mapboxMap object?

mapView = findViewById(R.id.mapView)
mapboxMap = mapView.getMapboxMap()
mapboxMap.flyTo();  //Method not found??

Sorry but I am not familiar with Kotlin, so this question is for a java based solution.

Mapbox help section:

https://docs.mapbox.com/android/maps/guides/migrate-to-v10/

Solution

  • Received the answer elsewhere. Correct way to animate the camera in java is as below:

    final Cancelable cancelable = CameraAnimationsUtils.easeTo(mapView.getMapboxMap(), new CameraOptions.Builder().zoom(5.0).build(), new MapAnimationOptions.Builder().duration(4000).build());
    
    // or to get actual object of animation plugin and call functions directly with it
    
    final CameraAnimationsPlugin camera = CameraAnimationsUtils.getCamera(mapView);
    final Cancelable cancelable = camera.easeTo(
            new CameraOptions.Builder().zoom(5.0).build(),
            new MapAnimationOptions.Builder().duration(4000).build()
    );