Add a platform independent MapContainer that can be called from shared ui
Wraps Google Maps on both Android and iOS Also bumps targetSDK to 36 because it was required by the library.
This commit is contained in:
52
shared/src/commonMain/kotlin/app/klottr/maps/MapContainer.kt
Normal file
52
shared/src/commonMain/kotlin/app/klottr/maps/MapContainer.kt
Normal file
@@ -0,0 +1,52 @@
|
||||
package app.klottr.maps
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import kotlinx.coroutines.flow.Flow
|
||||
|
||||
data class LatLng(val latitude: Double, val longitude: Double)
|
||||
data class CameraPosition(val target: LatLng, val zoom: Float = 12f)
|
||||
|
||||
sealed interface MapFeature {
|
||||
data class Marker(
|
||||
val id: String,
|
||||
val position: LatLng,
|
||||
val title: String? = null,
|
||||
val snippet: String? = null,
|
||||
val draggable: Boolean = false,
|
||||
) : MapFeature
|
||||
// Add Polyline/Polygon later if needed
|
||||
}
|
||||
|
||||
data class MapUiSettings(
|
||||
val compassEnabled: Boolean = true,
|
||||
val zoomControlsEnabled: Boolean = false,
|
||||
val myLocationButtonEnabled: Boolean = false,
|
||||
)
|
||||
|
||||
interface MapController {
|
||||
val cameraPosition: Flow<CameraPosition>
|
||||
fun moveCamera(position: CameraPosition)
|
||||
fun animateCamera(position: CameraPosition)
|
||||
fun setFeatures(features: List<MapFeature>)
|
||||
fun clear()
|
||||
fun setMyLocationEnabled(enabled: Boolean) // no-op on iOS if not granted
|
||||
}
|
||||
|
||||
class MapState(
|
||||
initialCamera: CameraPosition = CameraPosition(LatLng(0.0, 0.0), 2f),
|
||||
initialUi: MapUiSettings = MapUiSettings(),
|
||||
initialFeatures: List<MapFeature> = emptyList()
|
||||
) {
|
||||
var camera: CameraPosition = initialCamera
|
||||
var ui: MapUiSettings = initialUi
|
||||
var features: List<MapFeature> = initialFeatures
|
||||
}
|
||||
|
||||
/** Platform container composable. Returns a controller when ready. */
|
||||
@Composable
|
||||
expect fun MapContainer(
|
||||
state: MapState,
|
||||
onMapClick: ((LatLng) -> Unit)? = null,
|
||||
onMarkerClick: ((id: String) -> Unit)? = null,
|
||||
onReady: (MapController) -> Unit = {},
|
||||
)
|
||||
@@ -24,6 +24,8 @@ import kotlinx.serialization.json.Json
|
||||
object WikipediaShared {
|
||||
|
||||
// En HttpClient per process – återanvänds (lazy).
|
||||
// OH: Jag gjorde denna publik så den kan användas av WikiThumb.
|
||||
// OH: Det finns nu fyra olika httpclients i appen (wiki, fornsök, klottr, dm), behövs det eller kan vi dela?
|
||||
val client by lazy {
|
||||
HttpClient(platformEngine()) {
|
||||
// JSON-konfiguration: tolerant och ignorera okända fält
|
||||
|
||||
Reference in New Issue
Block a user