mapbox / mapbox-maps-android

Interactive, thoroughly customizable maps in native Android powered by vector tiles and OpenGL.
https://www.mapbox.com/mobile-maps-sdk
Other
478 stars 134 forks source link

Puck bearingImage slow transition between changes of bearing #2483

Closed bpepper88 closed 2 months ago

bpepper88 commented 2 months ago

Environment

Observed behavior and steps to reproduce

Use code below to draw the puck. On bearing change of the phone sensor I update the position which updats the puck bearing. It works but after I move the phone the puck bearing image is animated to the new position very, VERY, slowly and it's not instant. It looks as it's using an animation to get to latest bearing position.

Code:

MapEffect(currentLocation, bearingState.doubleValue) { mapView ->
  currentLocation?.let {
      navigationLocationProvider.changePosition(
          Location.Builder()
              .longitude(it.longitude)
              .latitude(it.latitude)
              .bearing(bearingState.doubleValue)
              .build()
      )
  }
  with(mapView) {
      location.enabled = true
      location.puckBearingEnabled = true
      location.puckBearing = PuckBearing.HEADING
      location.showAccuracyRing = true
      location.locationPuck = LocationPuck2D(
          bearingImage = ImageHolder.from(
              if (isCurrentLocationAvailable) {
                  Icon.LocationCurrent
              } else {
                  Icon.LocationUnavailable
              }
          )
      )
   }
}

Expected behavior

That puck bearing image will move immediately and with no delay together with bearing of the phone.

bpepper88 commented 2 months ago

And I found the fix.

val transitionOptions: (ValueAnimator.() -> Unit) =
                {
                    duration = 0
                }

currentLocation?.let {
                        navigationLocationProvider.changePosition(
                            Location.Builder()
                                .longitude(it.longitude)
                                .latitude(it.latitude)
                                .bearing(bearingState.doubleValue)
                                .build()
                        , bearingTransitionOptions = transitionOptions)
                    }

Added bearingTransitionOptions with animation duration 0. Maybe it would be good idea to set by default duration to 0 and then developer can add it if needed.