Show dot pin for user location

This commit is contained in:
Maxime Naturel 2022-03-07 16:13:33 +01:00
parent 93c397d492
commit 57fcfeb1c1
5 changed files with 34 additions and 10 deletions

View file

@ -146,6 +146,7 @@ class LocationSharingViewModel @AssistedInject constructor(
}
override fun onLocationUpdate(locationData: LocationData) {
// TODO compare location with lastTargetLocation => need to save info into the ViewState
setState {
copy(lastKnownUserLocation = locationData)
}

View file

@ -46,5 +46,6 @@ fun LocationSharingViewState.toMapState() = MapState(
zoomOnlyOnce = true,
userLocationData = lastKnownUserLocation,
pinId = DEFAULT_PIN_ID,
pinDrawable = locationTargetDrawable
pinDrawable = null,
showPin = areTargetAndUserLocationEqual == false
)

View file

@ -24,5 +24,6 @@ data class MapState(
val userLocationData: LocationData? = null,
val pinId: String,
val pinDrawable: Drawable? = null,
val showPin: Boolean = true,
@Px val logoMarginBottom: Int = 0
)

View file

@ -18,6 +18,7 @@ package im.vector.app.features.location
import android.content.Context
import android.util.AttributeSet
import androidx.core.content.ContextCompat
import com.mapbox.mapboxsdk.camera.CameraPosition
import com.mapbox.mapboxsdk.geometry.LatLng
import com.mapbox.mapboxsdk.maps.MapView
@ -26,6 +27,7 @@ import com.mapbox.mapboxsdk.maps.Style
import com.mapbox.mapboxsdk.plugins.annotation.SymbolManager
import com.mapbox.mapboxsdk.plugins.annotation.SymbolOptions
import com.mapbox.mapboxsdk.style.layers.Property
import im.vector.app.R
import timber.log.Timber
class MapTilerMapView @JvmOverloads constructor(
@ -42,6 +44,9 @@ class MapTilerMapView @JvmOverloads constructor(
val style: Style
)
private val userLocationDrawable by lazy {
ContextCompat.getDrawable(context, R.drawable.ic_location_user)
}
private var mapRefs: MapRefs? = null
private var initZoomDone = false
@ -88,13 +93,13 @@ class MapTilerMapView @JvmOverloads constructor(
safeMapRefs.map.uiSettings.setLogoMargins(0, 0, 0, state.logoMarginBottom)
// TODO display a dot pin for userLocation instead of pinDrawable
// TODO add reset to user location button
// TODO check conflict of rendering with preview location in timeline
state.pinDrawable?.let { pinDrawable ->
val pinDrawable = state.pinDrawable ?: userLocationDrawable
pinDrawable?.let { drawable ->
if (!safeMapRefs.style.isFullyLoaded ||
safeMapRefs.style.getImage(state.pinId) == null) {
safeMapRefs.style.addImage(state.pinId, pinDrawable)
safeMapRefs.style.addImage(state.pinId, drawable)
}
}
@ -105,12 +110,14 @@ class MapTilerMapView @JvmOverloads constructor(
}
safeMapRefs.symbolManager.deleteAll()
safeMapRefs.symbolManager.create(
SymbolOptions()
.withLatLng(LatLng(locationData.latitude, locationData.longitude))
.withIconImage(state.pinId)
.withIconAnchor(Property.ICON_ANCHOR_BOTTOM)
)
if(pinDrawable != null && state.showPin) {
safeMapRefs.symbolManager.create(
SymbolOptions()
.withLatLng(LatLng(locationData.latitude, locationData.longitude))
.withIconImage(state.pinId)
.withIconAnchor(Property.ICON_ANCHOR_BOTTOM)
)
}
}
}

View file

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<size
android:width="13dp"
android:height="13dp" />
<solid android:color="?colorPrimary" />
<stroke
android:width="2dp"
android:color="@color/palette_white" />
</shape>
</item>
</layer-list>