Animation Types
Note
You can find the full source code of this example in CameraAnimationTypeActivity.kt
of the MapLibreAndroidTestApp.
This example showcases the different animation types.
- Move: available via the
MapLibreMap.moveCamera
method. - Ease: available via the
MapLibreMap.easeCamera
method. - Animate: available via the
MapLibreMap.animateCamera
method.
Move
The MapLibreMap.moveCamera
method jumps to the camera position provided.
val cameraPosition =
CameraPosition.Builder()
.target(nextLatLng)
.zoom(14.0)
.tilt(30.0)
.tilt(0.0)
.build()
maplibreMap.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition))
Ease
The MapLibreMap.moveCamera
eases to the camera position provided (with constant ground speed).
val cameraPosition =
CameraPosition.Builder()
.target(nextLatLng)
.zoom(15.0)
.bearing(180.0)
.tilt(30.0)
.build()
maplibreMap.easeCamera(
CameraUpdateFactory.newCameraPosition(cameraPosition),
7500,
callback
)
Animate
The MapLibreMap.animateCamera
uses a powered flight animation move to the camera position provided1.
val cameraPosition =
CameraPosition.Builder().target(nextLatLng).bearing(270.0).tilt(20.0).build()
maplibreMap.animateCamera(
CameraUpdateFactory.newCameraPosition(cameraPosition),
7500,
callback
)
Animation Callbacks
In the previous section a CancellableCallback
was passed to the last two animation methods. This callback shows a toast message when the animation is cancelled or when it is finished.
private val callback: CancelableCallback =
object : CancelableCallback {
override fun onCancel() {
Timber.i("Duration onCancel Callback called.")
Toast.makeText(
applicationContext,
"Ease onCancel Callback called.",
Toast.LENGTH_LONG
)
.show()
}
override fun onFinish() {
Timber.i("Duration onFinish Callback called.")
Toast.makeText(
applicationContext,
"Ease onFinish Callback called.",
Toast.LENGTH_LONG
)
.show()
}
}
-
The implementation is based on Van Wijk, Jarke J.; Nuij, Wim A. A. “Smooth and efficient zooming and panning.” INFOVIS ’03. pp. 15–22. https://www.win.tue.nl/~vanwijk/zoompan.pdf#page=5 ↩