メインコンテンツまでスキップ

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.

PLAYGROUND
Location Helper

To experiment with camera pitch, bearing, tilt, and zoom and get values to use in your code, try our Location Helper tool.

Android Examples App Available

This example code is part of the Maps SDK for Android Examples App, a working Android project available on GitHub. Android developers are encouraged to run the examples app locally to interact with this example in an emulator and explore other features of the Maps SDK.

See our Run the Maps SDK for Android Examples App tutorial for step-by-step instructions.

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.geojson.Point
import com.mapbox.maps.MapView
import com.mapbox.maps.MapboxMap
import com.mapbox.maps.Style
import com.mapbox.maps.dsl.cameraOptions
import com.mapbox.maps.plugin.animation.CameraAnimatorOptions.Companion.cameraAnimatorOptions
import com.mapbox.maps.plugin.animation.camera

class LowLevelCameraAnimatorActivity : AppCompatActivity() {

private lateinit var mapboxMap: MapboxMap

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
val mapView = MapView(this)
setContentView(mapView)
mapboxMap = mapView.mapboxMap
mapboxMap.setCamera(CAMERA_TARGET)
mapboxMap.loadStyle(
Style.STANDARD
) {
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)
}
}
}

private companion object {
private val CAMERA_TARGET = cameraOptions {
center(Point.fromLngLat(-74.0060, 40.7128))
zoom(3.0)
}
}
}
この{Type}は役に立ちましたか?