Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
Set gps bearing immediately while change to gps mode (#470)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Li authored Jul 15, 2020
1 parent f0e65cf commit e443fe9
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,11 @@ void cancelTiltAnimation() {
cancelAnimator(ANIMATOR_TILT);
}

void cancelAndRemoveGpsBearingAnimation() {
cancelAnimator(ANIMATOR_LAYER_GPS_BEARING);
animatorArray.remove(ANIMATOR_LAYER_GPS_BEARING);
}

/**
* Cancel the pulsing circle location animator.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.DEFAULT_TRACKING_TILT_ANIM_DURATION;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.DEFAULT_TRACKING_ZOOM_ANIM_DURATION;
import static com.mapbox.mapboxsdk.location.LocationComponentConstants.TRANSITION_ANIMATION_DURATION_MS;
import static com.mapbox.mapboxsdk.location.modes.RenderMode.GPS;

/**
* The Location Component provides location awareness to your mobile application. Enabling this
Expand Down Expand Up @@ -673,6 +674,10 @@ public int getCameraMode() {
*/
public void setRenderMode(@RenderMode.Mode int renderMode) {
checkActivationState();
if (lastLocation != null && renderMode == GPS) {
locationAnimatorCoordinator.cancelAndRemoveGpsBearingAnimation();
locationLayerController.setGpsBearing(lastLocation.getBearing());
}
locationLayerController.setRenderMode(renderMode);
updateLayerOffsets(true);
updateCompassListenerState(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ void applyStyle(@NonNull LocationComponentOptions options) {
}
}

void setGpsBearing(float gpsBearing) {
locationLayerRenderer.setGpsBearing(gpsBearing);
}

void setRenderMode(@RenderMode.Mode int renderMode) {
if (this.renderMode == renderMode) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,6 +677,15 @@ class LocationAnimatorCoordinatorTest {
verify { animatorProvider.floatAnimator(any(), any(), 5) }
}

@Test
fun remove_gps_animator() {
val animator = mockk<MapboxFloatAnimator>(relaxed = true)
locationAnimatorCoordinator.animatorArray.put(ANIMATOR_LAYER_GPS_BEARING, animator)

locationAnimatorCoordinator.cancelAndRemoveGpsBearingAnimation()
assertTrue(locationAnimatorCoordinator.animatorArray.get(ANIMATOR_LAYER_GPS_BEARING) == null)
}

private fun getListenerHoldersSet(vararg animatorTypes: Int): Set<AnimatorListenerHolder> {
return HashSet<AnimatorListenerHolder>().also {
for (type in animatorTypes) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,34 @@ class LocationComponentTest {
verify(renderChangeListener).onRenderModeChanged(RenderMode.NORMAL)
}

@Test
fun change_to_gps_mode_symbolLayerBearingValue() {
val location = Location("test")
location.bearing = 50f
val projection: Projection = mock(Projection::class.java)
`when`(projection.getMetersPerPixelAtLatitude(location.latitude)).thenReturn(10.0)
`when`(mapboxMap.projection).thenReturn(projection)
`when`(style.isFullyLoaded).thenReturn(true)
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)

locationComponent.activateLocationComponent(
LocationComponentActivationOptions.builder(context, style)
.locationComponentOptions(locationComponentOptions)
.useDefaultLocationEngine(false)
.build()
)
locationComponent.isLocationComponentEnabled = true
locationComponent.onStart()
locationComponent.renderMode = RenderMode.NORMAL
locationComponent.forceLocationUpdate(location)

verify(locationLayerController, times(0)).setGpsBearing(50f)

locationComponent.renderMode = RenderMode.GPS
verify(locationLayerController, times(1)).setGpsBearing(50f)
verify(locationAnimatorCoordinator).cancelAndRemoveGpsBearingAnimation()
}

@Test
fun tiltWhileTracking_notReady() {
`when`(mapboxMap.cameraPosition).thenReturn(CameraPosition.DEFAULT)
Expand Down

0 comments on commit e443fe9

Please sign in to comment.