Fly-to camera animation
Use flyTo function on a map with globe projection, atmosphere and terrain to slowly zoom to a location.
package com.mapbox.maps.testapp.examples.globe import android.graphics.Color.rgbimport android.os.Bundleimport android.widget.Toastimport androidx.appcompat.app.AppCompatActivityimport com.mapbox.geojson.Pointimport com.mapbox.maps.MapViewimport com.mapbox.maps.MapboxMapimport com.mapbox.maps.Styleimport com.mapbox.maps.dsl.cameraOptionsimport com.mapbox.maps.extension.style.atmosphere.generated.atmosphereimport com.mapbox.maps.extension.style.layers.properties.generated.ProjectionNameimport com.mapbox.maps.extension.style.projection.generated.projectionimport com.mapbox.maps.extension.style.sources.generated.rasterDemSourceimport com.mapbox.maps.extension.style.styleimport com.mapbox.maps.extension.style.terrain.generated.terrainimport com.mapbox.maps.plugin.animation.MapAnimationOptions.Companion.mapAnimationOptionsimport com.mapbox.maps.plugin.animation.flyToimport com.mapbox.maps.plugin.gestures.OnMapClickListenerimport com.mapbox.maps.plugin.gestures.addOnMapClickListenerimport com.mapbox.maps.testapp.R /*** Use [MapboxMap.flyTo] on a map with globe projection, atmosphere and terrain to slowly zoom to a location.*/class GlobeFlyToActivity : AppCompatActivity(), OnMapClickListener { private lateinit var mapboxMap: MapboxMapprivate var isAtStart = true override fun onCreate(savedInstanceState: Bundle?) {super.onCreate(savedInstanceState)val mapView = MapView(this)setContentView(mapView)mapboxMap = mapView.mapboxMapmapboxMap.loadStyle(style(Style.SATELLITE_STREETS) {+projection(ProjectionName.GLOBE)+atmosphere {color(rgb(220, 159, 159)) // Pink fog / lower atmospherehighColor(rgb(220, 159, 159)) // Blue sky / upper atmospherehorizonBlend(0.4) // Exaggerate atmosphere (default is .1)}+rasterDemSource("raster-dem") {url("mapbox://mapbox.terrain-rgb")}+terrain("raster-dem")}) {// Toast instructing user to tap on the mapToast.makeText(this@GlobeFlyToActivity,getString(R.string.tap_on_map_instruction),Toast.LENGTH_LONG).show()mapboxMap.addOnMapClickListener(this@GlobeFlyToActivity)}} override fun onMapClick(point: Point): Boolean {val target = if (isAtStart) CAMERA_END else CAMERA_STARTisAtStart = !isAtStartmapboxMap.flyTo(target,mapAnimationOptions {duration(12_000)})return true} private companion object {private val CAMERA_START = cameraOptions {center(Point.fromLngLat(80.0, 36.0))zoom(1.0)pitch(0.0)bearing(0.0)}private val CAMERA_END = cameraOptions {center(Point.fromLngLat(8.11862, 46.58842))zoom(12.5)pitch(75.0)bearing(130.0)}}}
Was this example helpful?