All docsMaps SDK for AndroidExamplesUsing custom camera animations

Using custom camera animations

Animate the map camera to a new position using camera animators. Individual camera properties such as zoom, bearing, and center coordinate can be animated independently.

activity_camera_animate
<?xml version="1.0" encoding="utf-8"?>
<com.mapbox.maps.MapView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:mapbox="http://schemas.android.com/apk/res-auto"
android:id="@+id/mapView"
android:layout_width="match_parent"
android:layout_height="match_parent"
mapbox:mapbox_cameraTargetLat="40.7128"
mapbox:mapbox_cameraTargetLng="-74.0060"
mapbox:mapbox_cameraZoom="3" />
LowLevelCameraAnimatorActivity.kt
package com.mapbox.maps.testapp.examples.camera
import android.os.Bundle
import android.view.animation.AccelerateDecelerateInterpolator
import androidx.appcompat.app.AppCompatActivity
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.Style
import com.mapbox.maps.plugin.animation.CameraAnimatorOptions.Companion.cameraAnimatorOptions
import com.mapbox.maps.plugin.animation.camera
import com.mapbox.maps.testapp.databinding.ActivityCameraAnimateBinding
class LowLevelCameraAnimatorActivity : AppCompatActivity() {
private lateinit var mapboxMap: MapboxMap
private lateinit var binding: ActivityCameraAnimateBinding
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityCameraAnimateBinding.inflate(layoutInflater)
setContentView(binding.root)
mapboxMap = binding.mapView.getMapboxMap()
mapboxMap.loadStyleUri(
Style.MAPBOX_STREETS
) {
animateCameraDelayed()
}
}
private fun animateCameraDelayed() {
binding.mapView.camera.apply {
val bearing = createBearingAnimator(cameraAnimatorOptions(-45.0)) {
duration = 4000
interpolator = AccelerateDecelerateInterpolator()
}
val zoom = createZoomAnimator(
cameraAnimatorOptions(14.0) {
startValue(3.0)
}
) {
duration = 4000
interpolator = AccelerateDecelerateInterpolator()
}
val pitch = createPitchAnimator(
cameraAnimatorOptions(55.0) {
startValue(0.0)
}
) {
duration = 4000
interpolator = AccelerateDecelerateInterpolator()
}
playAnimatorsSequentially(zoom, pitch, bearing)
}
}
}