Refactor map layer management and navigation infrastructure (#4921)

Signed-off-by: James Rich <2199651+jamesarich@users.noreply.github.com>
This commit is contained in:
James Rich 2026-03-25 19:29:24 -05:00 committed by GitHub
parent b608a04ca4
commit a005231d94
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
142 changed files with 5408 additions and 3090 deletions

View file

@ -712,6 +712,10 @@ private fun MapLayerOverlay(layerItem: MapLayerItem, mapViewModel: MapViewModel)
var currentLayer by remember { mutableStateOf<com.google.maps.android.data.Layer?>(null) }
MapEffect(layerItem.id, layerItem.isRefreshing) { map ->
// Cleanup old layer if we're reloading
currentLayer?.safeRemoveLayerFromMap()
currentLayer = null
val inputStream = mapViewModel.getInputStreamFromUri(layerItem) ?: return@MapEffect
val layer =
try {
@ -727,7 +731,7 @@ private fun MapLayerOverlay(layerItem: MapLayerItem, mapViewModel: MapViewModel)
layer?.let {
if (layerItem.isVisible) {
it.addLayerToMap()
it.safeAddLayerToMap()
}
currentLayer = it
}
@ -735,7 +739,7 @@ private fun MapLayerOverlay(layerItem: MapLayerItem, mapViewModel: MapViewModel)
DisposableEffect(layerItem.id) {
onDispose {
currentLayer?.removeLayerFromMap()
currentLayer?.safeRemoveLayerFromMap()
currentLayer = null
}
}
@ -745,13 +749,33 @@ private fun MapLayerOverlay(layerItem: MapLayerItem, mapViewModel: MapViewModel)
LaunchedEffect(layerItem.isVisible) {
val layer = currentLayer ?: return@LaunchedEffect
if (layerItem.isVisible) {
if (!layer.isLayerOnMap) layer.addLayerToMap()
layer.safeAddLayerToMap()
} else {
if (layer.isLayerOnMap) layer.removeLayerFromMap()
layer.safeRemoveLayerFromMap()
}
}
}
private fun com.google.maps.android.data.Layer.safeRemoveLayerFromMap() {
try {
removeLayerFromMap()
} catch (e: Exception) {
// Log it and ignore. This specifically handles a NullPointerException in
// KmlRenderer.hasNestedContainers which can occur when disposing layers.
Logger.withTag("MapView").e(e) { "Error removing map layer" }
}
}
private fun com.google.maps.android.data.Layer.safeAddLayerToMap() {
try {
if (!isLayerOnMap) {
addLayerToMap()
}
} catch (e: Exception) {
Logger.withTag("MapView").e(e) { "Error adding map layer" }
}
}
internal fun convertIntToEmoji(unicodeCodePoint: Int): String = try {
String(Character.toChars(unicodeCodePoint))
} catch (e: IllegalArgumentException) {