Files
MapLibreParticleLab/platform/android/docs/camera/cameraposition.md

1.4 KiB

CameraPosition Capabilities

{{ activity_source_note("CameraPositionActivity.kt") }}

This example showcases how to listen to camera change events.

The camera animation is kicked off with this code:

--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraPositionActivity.kt:cameraPosition"

Notice how the color of the button in the bottom right changes color. Depending on the state of the camera.

We can listen for changes to the state of the camera by registering a OnCameraMoveListener, OnCameraIdleListener, OnCameraMoveCanceledListener or OnCameraMoveStartedListener with the MapLibreMap. For example, the OnCameraMoveListener is defined with:

--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraPositionActivity.kt:moveListener"

And registered with:

--8<-- "MapLibreAndroidTestApp/src/main/java/org/maplibre/android/testapp/activity/camera/CameraPositionActivity.kt:addOnCameraMoveListener"

Refer to the full example to learn the methods to register the other types of camera change events.