From 4c12fb2c2012ab485b389106ce5b126ed513d23b Mon Sep 17 00:00:00 2001 From: Kevin Li Date: Wed, 1 Jul 2020 19:09:16 +0800 Subject: [PATCH] Rotate camera in the shortest path. (#426) * Rotate camera in the shortest path. * Revert "Rotate camera in the shortest path." This reverts commit 0858d5ba * Fix puck rotate error. * Remove useless codes. * Update test cases --- .../location/LocationAnimatorCoordinator.java | 4 +-- .../LocationAnimatorCoordinatorTest.kt | 29 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java index 380c1707b..f4fec06b9 100644 --- a/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java +++ b/MapboxGLAndroidSDK/src/main/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinator.java @@ -114,9 +114,9 @@ void feedNewLocation(@NonNull @Size(min = 1) Location[] newLocations, // replace the animation start with the camera's previous value latLngValues[0] = previousCameraLatLng; if (isGpsNorth) { - bearingValues = new Float[] {previousCameraBearing, 0f}; + bearingValues = new Float[] {previousCameraBearing, shortestRotation(0f, previousCameraBearing)}; } else { - bearingValues[0] = previousCameraBearing; + bearingValues = getBearingValues(previousCameraBearing, newLocations); } updateCameraAnimators(latLngValues, bearingValues); diff --git a/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinatorTest.kt b/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinatorTest.kt index cd4c6c1f8..e3701d228 100644 --- a/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinatorTest.kt +++ b/MapboxGLAndroidSDK/src/test/java/com/mapbox/mapboxsdk/location/LocationAnimatorCoordinatorTest.kt @@ -171,6 +171,35 @@ class LocationAnimatorCoordinatorTest { } } + @Test + fun feedNewLocation_animatorValue_bearing() { + val previous = Location("") + previous.latitude = 51.1 + previous.longitude = 17.1 + previous.bearing = 355f + + val current = Location("") + current.latitude = 51.2 + current.longitude = 17.2 + current.bearing = 0f + + locationAnimatorCoordinator.feedNewLocation(arrayOf(previous, current), cameraPosition, false, false) + + verify { + animatorProvider.floatAnimator( + arrayOf(0f, -5f, 0f), any(), any() + ) + } + + locationAnimatorCoordinator.feedNewLocation(arrayOf(previous, current), cameraPosition, true, false) + + verify { + animatorProvider.floatAnimator( + arrayOf(0f, 0f), any(), any() + ) + } + } + @Test fun feedNewLocation_animatorValue_multiplePoints_animationDuration() { every { projection.getMetersPerPixelAtLatitude(any()) } answers { 10000.0 } // disable snap