mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-03 06:55:41 +00:00
Adapt location feature to maplibre.compose 0.18.0 API
This commit is contained in:
+1
-1
@@ -140,7 +140,7 @@ fun MapBottomSheetScaffold(
|
|||||||
isReady && mapState != null -> {
|
isReady && mapState != null -> {
|
||||||
MaplibreMap(
|
MaplibreMap(
|
||||||
state = mapState,
|
state = mapState,
|
||||||
cameraPadding = sheetPadding,
|
viewportInsets = sheetPadding,
|
||||||
renderOptions = renderOptions,
|
renderOptions = renderOptions,
|
||||||
interactions = interactions,
|
interactions = interactions,
|
||||||
uiOptions = uiOptions,
|
uiOptions = uiOptions,
|
||||||
|
|||||||
+14
-19
@@ -8,33 +8,28 @@
|
|||||||
package io.element.android.features.location.impl.common.ui
|
package io.element.android.features.location.impl.common.ui
|
||||||
|
|
||||||
import androidx.compose.runtime.Composable
|
import androidx.compose.runtime.Composable
|
||||||
import androidx.compose.ui.unit.dp
|
|
||||||
import io.element.android.compound.theme.ElementTheme
|
import io.element.android.compound.theme.ElementTheme
|
||||||
|
import org.maplibre.compose.layers.LocationIndicatorDefaults
|
||||||
|
import org.maplibre.compose.layers.LocationIndicatorLayer
|
||||||
import org.maplibre.compose.location.LocationMeasurement
|
import org.maplibre.compose.location.LocationMeasurement
|
||||||
import org.maplibre.compose.location.LocationPuck
|
|
||||||
import org.maplibre.compose.location.LocationPuckColors
|
|
||||||
import org.maplibre.compose.location.LocationPuckSizes
|
|
||||||
import org.maplibre.spatialk.units.Length
|
|
||||||
|
|
||||||
@Composable
|
@Composable
|
||||||
fun UserLocationPuck(
|
fun UserLocationPuck(
|
||||||
location: LocationMeasurement?,
|
location: LocationMeasurement?,
|
||||||
) {
|
) {
|
||||||
LocationPuck(
|
LocationIndicatorLayer(
|
||||||
idPrefix = "user-location",
|
id = "user-location",
|
||||||
location = location,
|
location = location?.position,
|
||||||
// Hide the accuracy circle.
|
// Hide the accuracy circle and the bearing accuracy sector: leaving `accuracyRadius`
|
||||||
accuracyThreshold = Length.PositiveInfinity,
|
// and `bearingAccuracy` null is what hides them.
|
||||||
// Hide the bearing (and bearing accuracy) indicator.
|
accuracyRadius = null,
|
||||||
|
bearingAccuracy = null,
|
||||||
|
// Hide the bearing indicator.
|
||||||
bearing = null,
|
bearing = null,
|
||||||
sizes = LocationPuckSizes(
|
bearingImage = null,
|
||||||
dotRadius = 8.dp,
|
topImage = LocationIndicatorDefaults.topImage(
|
||||||
dotStrokeWidth = 2.dp,
|
color = ElementTheme.colors.iconAccentPrimary,
|
||||||
|
borderColor = ElementTheme.colors.bgCanvasDefault,
|
||||||
),
|
),
|
||||||
colors = LocationPuckColors(
|
|
||||||
dotFillColorCurrentLocation = ElementTheme.colors.iconAccentPrimary,
|
|
||||||
dotFillColorOldLocation = ElementTheme.colors.iconAccentTertiary,
|
|
||||||
dotStrokeColor = ElementTheme.colors.bgCanvasDefault,
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-1
@@ -17,6 +17,7 @@ import androidx.compose.runtime.setValue
|
|||||||
import androidx.compose.runtime.snapshotFlow
|
import androidx.compose.runtime.snapshotFlow
|
||||||
import io.element.android.features.location.impl.common.MapDefaults
|
import io.element.android.features.location.impl.common.MapDefaults
|
||||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||||
|
import org.maplibre.compose.camera.CameraAnimation
|
||||||
import org.maplibre.compose.location.LocationMeasurement
|
import org.maplibre.compose.location.LocationMeasurement
|
||||||
import org.maplibre.compose.map.MapState
|
import org.maplibre.compose.map.MapState
|
||||||
import kotlin.math.abs
|
import kotlin.math.abs
|
||||||
@@ -77,7 +78,7 @@ internal fun UserLocationTrackingEffect(
|
|||||||
zoom = mapState.cameraPosition.zoom.coerceAtLeast(MapDefaults.DEFAULT_ZOOM)
|
zoom = mapState.cameraPosition.zoom.coerceAtLeast(MapDefaults.DEFAULT_ZOOM)
|
||||||
)
|
)
|
||||||
if (hasPositioned) {
|
if (hasPositioned) {
|
||||||
mapState.animateCameraPosition(position)
|
mapState.animateCamera(position.toCameraUpdate(), CameraAnimation.Fly())
|
||||||
} else {
|
} else {
|
||||||
mapState.setCameraPosition(position)
|
mapState.setCameraPosition(position)
|
||||||
hasPositioned = true
|
hasPositioned = true
|
||||||
|
|||||||
+2
-1
@@ -54,6 +54,7 @@ import io.element.android.libraries.designsystem.theme.components.TopAppBar
|
|||||||
import io.element.android.libraries.ui.strings.CommonStrings
|
import io.element.android.libraries.ui.strings.CommonStrings
|
||||||
import kotlinx.collections.immutable.toImmutableList
|
import kotlinx.collections.immutable.toImmutableList
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import org.maplibre.compose.camera.CameraAnimation
|
||||||
import org.maplibre.compose.camera.CameraMoveReason
|
import org.maplibre.compose.camera.CameraMoveReason
|
||||||
import org.maplibre.compose.camera.CameraPosition
|
import org.maplibre.compose.camera.CameraPosition
|
||||||
import org.maplibre.compose.map.MapState
|
import org.maplibre.compose.map.MapState
|
||||||
@@ -149,7 +150,7 @@ private fun ShowLocationViewContent(
|
|||||||
zoom = mapState.cameraPosition.zoom.coerceAtLeast(MapDefaults.DEFAULT_ZOOM),
|
zoom = mapState.cameraPosition.zoom.coerceAtLeast(MapDefaults.DEFAULT_ZOOM),
|
||||||
)
|
)
|
||||||
coroutineScope.launch {
|
coroutineScope.launch {
|
||||||
mapState.animateCameraPosition(position = position)
|
mapState.animateCamera(update = position.toCameraUpdate(), animation = CameraAnimation.Fly())
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
modifier = modifier,
|
modifier = modifier,
|
||||||
|
|||||||
Reference in New Issue
Block a user