From a6373d58338549980ca16391ecb6d8150e351d4a Mon Sep 17 00:00:00 2001 From: johan12345 Date: Sun, 11 Aug 2024 19:26:57 +0200 Subject: [PATCH] avoid stutter when moving map away from current location --- app/src/main/java/net/vonforst/evmap/auto/MapScreen.kt | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/net/vonforst/evmap/auto/MapScreen.kt b/app/src/main/java/net/vonforst/evmap/auto/MapScreen.kt index 82330b20c..cde838716 100644 --- a/app/src/main/java/net/vonforst/evmap/auto/MapScreen.kt +++ b/app/src/main/java/net/vonforst/evmap/auto/MapScreen.kt @@ -138,6 +138,7 @@ class MapScreen(ctx: CarContext, val session: EVMapSession) : private var map: AnyMap? = null private var markerManager: MarkerManager? = null private var myLocationEnabled = false + private var myLocationNeedsUpdate = false private val formatter = ChargerListFormatter(ctx, this) private val backPressedCallback = object : OnBackPressedCallback(false) { @@ -625,18 +626,23 @@ class MapScreen(ctx: CarContext, val session: EVMapSession) : mapSurfaceCallback.cameraMoveStartedListener = { if (myLocationEnabled) { myLocationEnabled = false - invalidate() + myLocationNeedsUpdate = true } } mapSurfaceCallback.cameraIdleListener = { loadChargers() + if (myLocationNeedsUpdate) { + invalidate() + myLocationNeedsUpdate = false + } } loadChargers() } private fun enableLocation() { myLocationEnabled = true + myLocationNeedsUpdate = true if (location != null) { val map = map ?: return mapSurfaceCallback.animateCamera( @@ -646,6 +652,5 @@ class MapScreen(ctx: CarContext, val session: EVMapSession) : ) ) } - invalidate() } } \ No newline at end of file