diff --git a/app/src/main/java/de/westnordost/streetcomplete/map/Compass.kt b/app/src/main/java/de/westnordost/streetcomplete/map/Compass.kt index b75959b208..02836341bb 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/map/Compass.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/map/Compass.kt @@ -161,7 +161,7 @@ class Compass( companion object { private const val MAX_DISPATCH_FPS = 30 private const val SMOOTHEN_FACTOR = 0.1f - private const val MIN_DIFFERENCE = 0.005f + private const val MIN_DIFFERENCE = 0.001f } } diff --git a/app/src/main/java/de/westnordost/streetcomplete/map/LocationAwareMapFragment.kt b/app/src/main/java/de/westnordost/streetcomplete/map/LocationAwareMapFragment.kt index d6bb336b3b..80185071e1 100644 --- a/app/src/main/java/de/westnordost/streetcomplete/map/LocationAwareMapFragment.kt +++ b/app/src/main/java/de/westnordost/streetcomplete/map/LocationAwareMapFragment.kt @@ -74,6 +74,7 @@ open class LocationAwareMapFragment : MapFragment() { } } } + private var viewDirection: Float? = null interface Listener { /** Called after the map fragment updated its displayed location */ @@ -279,10 +280,21 @@ open class LocationAwareMapFragment : MapFragment() { } if (isCompassMode) { - controller?.updateCameraPosition { rotation = -rot } + viewDirection = + if (viewDirection == null) -rot + else smoothenAngle(-rot, viewDirection ?: 0f, 0.05f) + + controller?.updateCameraPosition { rotation = viewDirection } } } + private fun smoothenAngle( newValue: Float, oldValue: Float, factor: Float): Float { + var delta = newValue - oldValue + while (delta > +PI) delta -= 2 * PI.toFloat() + while (delta < -PI) delta += 2 * PI.toFloat() + return oldValue + factor * delta + } + /* -------------------------------- Save and Restore State ---------------------------------- */ private fun restoreMapState() {