From 4c202d7ff267024de1925c91307e92e6bafcb71a Mon Sep 17 00:00:00 2001 From: johan12345 Date: Sat, 17 May 2025 18:04:50 +0200 Subject: [PATCH] disable extendBounds if map is zoomed out far --- .../net/vonforst/evmap/viewmodel/MapViewModel.kt | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt b/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt index 06fe0f78..c446e5e9 100644 --- a/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt +++ b/app/src/main/java/net/vonforst/evmap/viewmodel/MapViewModel.kt @@ -471,12 +471,17 @@ class MapViewModel(application: Application, private val state: SavedStateHandle private fun extendBounds(bounds: LatLngBounds): LatLngBounds { val sw = bounds.southwest val ne = bounds.northeast - var west = sw.longitude - (ne.longitude - sw.longitude) * 0.25 - var east = ne.longitude + (ne.longitude - sw.longitude) * 0.25 + + // do not expand bounds if the map area shown is very large + val expansion = if (ne.longitude - sw.longitude > 10) 1.0 else 1.5 + val factor = (expansion - 1.0) * 0.5 + + var west = sw.longitude - (ne.longitude - sw.longitude) * factor + var east = ne.longitude + (ne.longitude - sw.longitude) * factor val south = - sw.latitude - (ne.latitude - sw.latitude) * 0.25 * cos(Math.toRadians(sw.latitude)) + sw.latitude - (ne.latitude - sw.latitude) * factor * cos(Math.toRadians(sw.latitude)) val north = - ne.latitude + (ne.latitude - sw.latitude) * 0.25 * cos(Math.toRadians(ne.latitude)) + ne.latitude + (ne.latitude - sw.latitude) * factor * cos(Math.toRadians(ne.latitude)) if (east - west >= 360) { west = -180.0