feat(map): replace Google Maps + OSMDroid with unified MapLibre Compose Multiplatform

Replace the dual flavor-specific map implementations (Google Maps for google,
OSMDroid for fdroid) with a single MapLibre Compose Multiplatform implementation
in feature:map/commonMain, eliminating ~8,500 lines of duplicated code.

Key changes:
- Add maplibre-compose v0.12.1 dependency (KMP: Android, Desktop, iOS)
- Create unified MapViewModel with camera persistence via MapCameraPrefs
- Create MapScreen, MaplibreMapContent, NodeTrackLayers, TracerouteLayers,
  InlineMap, NodeTrackMap, TracerouteMap, NodeMapScreen in commonMain
- Create MapStyle enum with predefined OpenFreeMap tile styles
- Create GeoJsonConverters for Node/Waypoint/Position to GeoJSON
- Move TracerouteMapScreen from feature:node/androidMain to commonMain
- Wire navigation to use direct imports instead of CompositionLocal providers
- Delete 61 flavor-specific map files (google + fdroid source sets)
- Remove 8 CompositionLocal map providers from core:ui
- Remove SharedMapViewModel (replaced by new MapViewModel)
- Remove dead google-maps and osmdroid entries from version catalog
- Add MapViewModelTest with 10 test cases in commonTest

Baseline verified: spotlessCheck, detekt, assembleGoogleDebug, allTests all pass.
This commit is contained in:
James Rich 2026-04-12 18:25:15 -05:00
parent a2763bdfeb
commit 598cae564e
86 changed files with 1653 additions and 8333 deletions

View file

@ -0,0 +1,126 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.prefs.map
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.doublePreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.floatPreferencesKey
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.core.stringSetPreferencesKey
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import org.koin.core.annotation.Named
import org.koin.core.annotation.Single
import org.meshtastic.core.di.CoroutineDispatchers
import org.meshtastic.core.repository.MapCameraPrefs
@Single
class MapCameraPrefsImpl(
@Named("MapDataStore") private val dataStore: DataStore<Preferences>,
dispatchers: CoroutineDispatchers,
) : MapCameraPrefs {
private val scope = CoroutineScope(SupervisorJob() + dispatchers.default)
override val cameraLat: StateFlow<Double> =
dataStore.data.map { it[KEY_CAMERA_LAT] ?: DEFAULT_LAT }.stateIn(scope, SharingStarted.Eagerly, DEFAULT_LAT)
override fun setCameraLat(value: Double) {
scope.launch { dataStore.edit { it[KEY_CAMERA_LAT] = value } }
}
override val cameraLng: StateFlow<Double> =
dataStore.data.map { it[KEY_CAMERA_LNG] ?: DEFAULT_LNG }.stateIn(scope, SharingStarted.Eagerly, DEFAULT_LNG)
override fun setCameraLng(value: Double) {
scope.launch { dataStore.edit { it[KEY_CAMERA_LNG] = value } }
}
override val cameraZoom: StateFlow<Float> =
dataStore.data.map { it[KEY_CAMERA_ZOOM] ?: DEFAULT_ZOOM }.stateIn(scope, SharingStarted.Eagerly, DEFAULT_ZOOM)
override fun setCameraZoom(value: Float) {
scope.launch { dataStore.edit { it[KEY_CAMERA_ZOOM] = value } }
}
override val cameraTilt: StateFlow<Float> =
dataStore.data.map { it[KEY_CAMERA_TILT] ?: DEFAULT_TILT }.stateIn(scope, SharingStarted.Eagerly, DEFAULT_TILT)
override fun setCameraTilt(value: Float) {
scope.launch { dataStore.edit { it[KEY_CAMERA_TILT] = value } }
}
override val cameraBearing: StateFlow<Float> =
dataStore.data
.map { it[KEY_CAMERA_BEARING] ?: DEFAULT_BEARING }
.stateIn(scope, SharingStarted.Eagerly, DEFAULT_BEARING)
override fun setCameraBearing(value: Float) {
scope.launch { dataStore.edit { it[KEY_CAMERA_BEARING] = value } }
}
override val selectedStyleUri: StateFlow<String> =
dataStore.data
.map { it[KEY_SELECTED_STYLE_URI] ?: DEFAULT_STYLE_URI }
.stateIn(scope, SharingStarted.Eagerly, DEFAULT_STYLE_URI)
override fun setSelectedStyleUri(value: String) {
scope.launch { dataStore.edit { it[KEY_SELECTED_STYLE_URI] = value } }
}
override val hiddenLayerUrls: StateFlow<Set<String>> =
dataStore.data
.map { it[KEY_HIDDEN_LAYER_URLS] ?: emptySet() }
.stateIn(scope, SharingStarted.Eagerly, emptySet())
override fun setHiddenLayerUrls(value: Set<String>) {
scope.launch { dataStore.edit { it[KEY_HIDDEN_LAYER_URLS] = value } }
}
override val networkMapLayers: StateFlow<Set<String>> =
dataStore.data
.map { it[KEY_NETWORK_MAP_LAYERS] ?: emptySet() }
.stateIn(scope, SharingStarted.Eagerly, emptySet())
override fun setNetworkMapLayers(value: Set<String>) {
scope.launch { dataStore.edit { it[KEY_NETWORK_MAP_LAYERS] = value } }
}
companion object {
private const val DEFAULT_LAT = 0.0
private const val DEFAULT_LNG = 0.0
private const val DEFAULT_ZOOM = 7f
private const val DEFAULT_TILT = 0f
private const val DEFAULT_BEARING = 0f
private const val DEFAULT_STYLE_URI = ""
val KEY_CAMERA_LAT = doublePreferencesKey("map_camera_lat")
val KEY_CAMERA_LNG = doublePreferencesKey("map_camera_lng")
val KEY_CAMERA_ZOOM = floatPreferencesKey("map_camera_zoom")
val KEY_CAMERA_TILT = floatPreferencesKey("map_camera_tilt")
val KEY_CAMERA_BEARING = floatPreferencesKey("map_camera_bearing")
val KEY_SELECTED_STYLE_URI = stringPreferencesKey("map_selected_style_uri")
val KEY_HIDDEN_LAYER_URLS = stringSetPreferencesKey("map_hidden_layer_urls")
val KEY_NETWORK_MAP_LAYERS = stringSetPreferencesKey("map_network_layers")
}
}

View file

@ -171,6 +171,41 @@ interface MapPrefs {
fun setLastHeardTrackFilter(seconds: Long)
}
/** Reactive interface for map camera position persistence. */
interface MapCameraPrefs {
val cameraLat: StateFlow<Double>
fun setCameraLat(value: Double)
val cameraLng: StateFlow<Double>
fun setCameraLng(value: Double)
val cameraZoom: StateFlow<Float>
fun setCameraZoom(value: Float)
val cameraTilt: StateFlow<Float>
fun setCameraTilt(value: Float)
val cameraBearing: StateFlow<Float>
fun setCameraBearing(value: Float)
val selectedStyleUri: StateFlow<String>
fun setSelectedStyleUri(value: String)
val hiddenLayerUrls: StateFlow<Set<String>>
fun setHiddenLayerUrls(value: Set<String>)
val networkMapLayers: StateFlow<Set<String>>
fun setNetworkMapLayers(value: Set<String>)
}
/** Reactive interface for map consent. */
interface MapConsentPrefs {
fun shouldReportLocation(nodeNum: Int?): StateFlow<Boolean>
@ -238,6 +273,7 @@ interface AppPreferences {
val emoji: CustomEmojiPrefs
val ui: UiPrefs
val map: MapPrefs
val mapCamera: MapCameraPrefs
val mapConsent: MapConsentPrefs
val mapTileProvider: MapTileProviderPrefs
val radio: RadioPrefs

View file

@ -1159,6 +1159,11 @@
<string name="bluetooth_feature_config">Configuration</string>
<string name="bluetooth_feature_config_description">Wirelessly manage your device settings and channels.</string>
<string name="map_style_selection">Map style selection</string>
<string name="map_style_osm">OpenStreetMap</string>
<string name="map_style_satellite">Satellite</string>
<string name="map_style_terrain">Terrain</string>
<string name="map_style_hybrid">Hybrid</string>
<string name="map_style_dark">Dark</string>
<string name="local_stats_battery">Battery: %1$d%</string>
<string name="local_stats_nodes">Nodes: %1$d online / %2$d total</string>

View file

@ -23,6 +23,7 @@ import org.meshtastic.core.repository.AppPreferences
import org.meshtastic.core.repository.CustomEmojiPrefs
import org.meshtastic.core.repository.FilterPrefs
import org.meshtastic.core.repository.HomoglyphPrefs
import org.meshtastic.core.repository.MapCameraPrefs
import org.meshtastic.core.repository.MapConsentPrefs
import org.meshtastic.core.repository.MapPrefs
import org.meshtastic.core.repository.MapTileProviderPrefs
@ -198,6 +199,56 @@ class FakeMapPrefs : MapPrefs {
}
}
class FakeMapCameraPrefs : MapCameraPrefs {
override val cameraLat = MutableStateFlow(0.0)
override fun setCameraLat(value: Double) {
cameraLat.value = value
}
override val cameraLng = MutableStateFlow(0.0)
override fun setCameraLng(value: Double) {
cameraLng.value = value
}
override val cameraZoom = MutableStateFlow(7f)
override fun setCameraZoom(value: Float) {
cameraZoom.value = value
}
override val cameraTilt = MutableStateFlow(0f)
override fun setCameraTilt(value: Float) {
cameraTilt.value = value
}
override val cameraBearing = MutableStateFlow(0f)
override fun setCameraBearing(value: Float) {
cameraBearing.value = value
}
override val selectedStyleUri = MutableStateFlow("")
override fun setSelectedStyleUri(value: String) {
selectedStyleUri.value = value
}
override val hiddenLayerUrls = MutableStateFlow(emptySet<String>())
override fun setHiddenLayerUrls(value: Set<String>) {
hiddenLayerUrls.value = value
}
override val networkMapLayers = MutableStateFlow(emptySet<String>())
override fun setNetworkMapLayers(value: Set<String>) {
networkMapLayers.value = value
}
}
class FakeMapConsentPrefs : MapConsentPrefs {
private val consent = mutableMapOf<Int?, MutableStateFlow<Boolean>>()
@ -264,6 +315,7 @@ class FakeAppPreferences : AppPreferences {
override val emoji = FakeCustomEmojiPrefs()
override val ui = FakeUiPrefs()
override val map = FakeMapPrefs()
override val mapCamera = FakeMapCameraPrefs()
override val mapConsent = FakeMapConsentPrefs()
override val mapTileProvider = FakeMapTileProviderPrefs()
override val radio = FakeRadioPrefs()

View file

@ -1,24 +0,0 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ui.util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import org.meshtastic.core.model.Node
val LocalInlineMapProvider = compositionLocalOf<@Composable (node: Node, modifier: Modifier) -> Unit> { { _, _ -> } }

View file

@ -1,33 +0,0 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ui.util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import org.meshtastic.core.ui.component.PlaceholderScreen
/**
* Provides the platform-specific Map Main Screen. On Desktop or JVM targets where native maps aren't available yet, it
* falls back to a [PlaceholderScreen].
*/
@Suppress("Wrapping")
val LocalMapMainScreenProvider =
compositionLocalOf<
@Composable (onClickNodeChip: (Int) -> Unit, navigateToNodeDetails: (Int) -> Unit, waypointId: Int?) -> Unit,
> {
{ _, _, _ -> PlaceholderScreen("Map") }
}

View file

@ -1,31 +0,0 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ui.util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import org.meshtastic.core.ui.component.PlaceholderScreen
/**
* Provides the platform-specific Map Screen for a Node (e.g. Google Maps or OSMDroid on Android). On Desktop or JVM
* targets where native maps aren't available yet, it falls back to a [PlaceholderScreen].
*/
@Suppress("Wrapping")
val LocalNodeMapScreenProvider =
compositionLocalOf<@Composable (destNum: Int, onNavigateUp: () -> Unit) -> Unit> {
{ destNum, _ -> PlaceholderScreen("Node Map ($destNum)") }
}

View file

@ -1,50 +0,0 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ui.util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import org.meshtastic.core.ui.component.PlaceholderScreen
import org.meshtastic.proto.Position
/**
* Provides an embeddable position-track map composable that renders a polyline with markers for the given [positions].
* Unlike [LocalNodeMapScreenProvider], this does **not** include a Scaffold or AppBar it is designed to be embedded
* inside another screen layout (e.g. the position-log adaptive layout).
*
* Supports optional synchronized selection:
* - [selectedPositionTime]: the `Position.time` of the currently selected position (or `null` for no selection). When
* non-null, the map should visually highlight the corresponding marker and center the camera on it.
* - [onPositionSelected]: callback invoked when a position marker is tapped on the map, passing the `Position.time` so
* the host can synchronize the card list.
*
* On Desktop/JVM targets where native maps are not yet available, it falls back to a [PlaceholderScreen].
*/
@Suppress("Wrapping")
val LocalNodeTrackMapProvider =
compositionLocalOf<
@Composable (
destNum: Int,
positions: List<Position>,
modifier: Modifier,
selectedPositionTime: Int?,
onPositionSelected: ((Int) -> Unit)?,
) -> Unit,
> {
{ _, _, _, _, _ -> PlaceholderScreen("Position Track Map") }
}

View file

@ -1,30 +0,0 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ui.util
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Alignment
import androidx.compose.ui.unit.dp
data class TracerouteMapOverlayInsets(
val overlayAlignment: Alignment = Alignment.BottomCenter,
val overlayPadding: PaddingValues = PaddingValues(bottom = 16.dp),
val contentHorizontalAlignment: Alignment.Horizontal = Alignment.CenterHorizontally,
)
val LocalTracerouteMapOverlayInsetsProvider = compositionLocalOf { TracerouteMapOverlayInsets() }

View file

@ -1,51 +0,0 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ui.util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
import org.meshtastic.core.model.TracerouteOverlay
import org.meshtastic.core.ui.component.PlaceholderScreen
import org.meshtastic.proto.Position
/**
* Provides an embeddable traceroute map composable that renders node markers and forward/return offset polylines for a
* traceroute result. Unlike [LocalMapViewProvider], this does **not** include a Scaffold, AppBar, waypoints, location
* tracking, custom tiles, or any main-map features it is designed to be embedded inside `TracerouteMapScreen`'s
* scaffold.
*
* On Desktop/JVM targets where native maps are not yet available, it falls back to a [PlaceholderScreen].
*
* Parameters:
* - `tracerouteOverlay`: The overlay with forward/return route node nums.
* - `tracerouteNodePositions`: Map of node num to position snapshots for the route nodes.
* - `onMappableCountChanged`: Callback with (shown, total) node counts.
* - `modifier`: Compose modifier for the map.
*/
@Suppress("Wrapping")
val LocalTracerouteMapProvider =
compositionLocalOf<
@Composable (
tracerouteOverlay: TracerouteOverlay?,
tracerouteNodePositions: Map<Int, Position>,
onMappableCountChanged: (Int, Int) -> Unit,
modifier: Modifier,
) -> Unit,
> {
{ _, _, _, _ -> PlaceholderScreen("Traceroute Map") }
}

View file

@ -1,31 +0,0 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ui.util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import org.meshtastic.core.ui.component.PlaceholderScreen
/**
* Provides the platform-specific Traceroute Map Screen. On Desktop or JVM targets where native maps aren't available
* yet, it falls back to a [PlaceholderScreen].
*/
@Suppress("Wrapping")
val LocalTracerouteMapScreenProvider =
compositionLocalOf<@Composable (destNum: Int, requestId: Int, logUuid: String?, onNavigateUp: () -> Unit) -> Unit> {
{ _, _, _, _ -> PlaceholderScreen("Traceroute Map") }
}

View file

@ -1,31 +0,0 @@
/*
* Copyright (c) 2026 Meshtastic LLC
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package org.meshtastic.core.ui.util
import androidx.compose.runtime.Composable
import androidx.compose.runtime.compositionLocalOf
import androidx.compose.ui.Modifier
/**
* Interface for providing a flavored MapView. This allows the map feature to be decoupled from specific map
* implementations (Google Maps vs OSMDroid). Platform implementations create their own ViewModel via Koin.
*/
interface MapViewProvider {
@Composable fun MapView(modifier: Modifier, navigateToNodeDetails: (Int) -> Unit, waypointId: Int? = null)
}
val LocalMapViewProvider = compositionLocalOf<MapViewProvider?> { null }