Bearing
This commit is contained in:
@@ -187,7 +187,7 @@ class NavigationSession : Session() {
|
||||
fun update(location: Location) {
|
||||
surfaceRenderer.updateLocation(location)
|
||||
if (routeModel.isNavigating()) {
|
||||
routeModel.findManeuver(location)
|
||||
routeModel.updateLocation(location)
|
||||
// if (routeModel.distanceToRoute > 50) {
|
||||
// routeModel.stopNavigation()
|
||||
// locationIndex = 0
|
||||
|
||||
@@ -11,11 +11,9 @@ import androidx.car.app.AppManager
|
||||
import androidx.car.app.CarContext
|
||||
import androidx.car.app.SurfaceCallback
|
||||
import androidx.car.app.SurfaceContainer
|
||||
import androidx.compose.foundation.isSystemInDarkTheme
|
||||
import androidx.compose.foundation.layout.PaddingValues
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.LaunchedEffect
|
||||
import androidx.compose.runtime.collectAsState
|
||||
import androidx.compose.runtime.getValue
|
||||
import androidx.compose.runtime.livedata.observeAsState
|
||||
import androidx.compose.ui.graphics.Color
|
||||
@@ -28,8 +26,8 @@ import androidx.lifecycle.MutableLiveData
|
||||
import androidx.lifecycle.setViewTreeLifecycleOwner
|
||||
import androidx.savedstate.setViewTreeSavedStateRegistryOwner
|
||||
import com.kouros.navigation.car.navigation.RouteCarModel
|
||||
import com.kouros.navigation.model.RouteModel
|
||||
import com.kouros.navigation.utils.NavigationUtils
|
||||
import kotlinx.coroutines.flow.onSubscription
|
||||
import org.maplibre.compose.camera.CameraPosition
|
||||
import org.maplibre.compose.camera.rememberCameraState
|
||||
import org.maplibre.compose.expressions.dsl.const
|
||||
@@ -65,6 +63,7 @@ class SurfaceRenderer(
|
||||
|
||||
val previewRouteData = MutableLiveData("")
|
||||
|
||||
lateinit var centerLocation : Location
|
||||
var preview = false
|
||||
|
||||
lateinit var mapView: ComposeView
|
||||
@@ -72,7 +71,7 @@ class SurfaceRenderer(
|
||||
val tilt = 55.0
|
||||
val padding = PaddingValues(start = 150.dp, top = 250.dp)
|
||||
|
||||
val prePadding = PaddingValues(start = 150.dp, bottom = 300.dp)
|
||||
val prePadding = PaddingValues(start = 150.dp, bottom = 0.dp)
|
||||
|
||||
val mSurfaceCallback: SurfaceCallback = object : SurfaceCallback {
|
||||
|
||||
@@ -107,7 +106,7 @@ class SurfaceRenderer(
|
||||
this.setViewTreeLifecycleOwner(lifecycleOwner)
|
||||
this.setViewTreeSavedStateRegistryOwner(lifecycleOwner)
|
||||
setContent {
|
||||
Map()
|
||||
MapView()
|
||||
}
|
||||
}
|
||||
presentation = Presentation(carContext, virtualDisplay.display)
|
||||
@@ -154,7 +153,9 @@ class SurfaceRenderer(
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun Map() {
|
||||
fun MapView() {
|
||||
val locationProvider = rememberDefaultLocationProvider()
|
||||
val locationState = rememberUserLocationState(locationProvider)
|
||||
val position: CameraPosition? by cameraPosition.observeAsState()
|
||||
val route: String? by routeData.observeAsState()
|
||||
val previewRoute: String? by previewRouteData.observeAsState()
|
||||
@@ -171,8 +172,6 @@ class SurfaceRenderer(
|
||||
padding = getPaddingValues()
|
||||
)
|
||||
)
|
||||
val locationProvider = rememberDefaultLocationProvider()
|
||||
val locationState = rememberUserLocationState(locationProvider)
|
||||
MaplibreMap(
|
||||
cameraState = cameraState,
|
||||
//baseStyle = BaseStyle.Uri("https://tiles.openfreemap.org/styles/liberty"),
|
||||
@@ -191,17 +190,32 @@ class SurfaceRenderer(
|
||||
)
|
||||
}
|
||||
|
||||
LaunchedEffect(position) {
|
||||
cameraState.animateTo(
|
||||
finalPosition = CameraPosition(
|
||||
bearing = position!!.bearing,
|
||||
zoom = position!!.zoom,
|
||||
target = position!!.target,
|
||||
tilt = tilt,
|
||||
padding = getPaddingValues()
|
||||
),
|
||||
duration = 3.seconds
|
||||
)
|
||||
if (!preview) {
|
||||
LaunchedEffect(position) {
|
||||
cameraState.animateTo(
|
||||
finalPosition = CameraPosition(
|
||||
bearing = position!!.bearing,
|
||||
zoom = position!!.zoom,
|
||||
target = position!!.target,
|
||||
tilt = tilt,
|
||||
padding = getPaddingValues()
|
||||
),
|
||||
duration = 3.seconds
|
||||
)
|
||||
}
|
||||
} else {
|
||||
LaunchedEffect(position) {
|
||||
cameraState.animateTo(
|
||||
finalPosition = CameraPosition(
|
||||
bearing = 0.0,
|
||||
zoom = 9.0,
|
||||
target = Position(centerLocation.longitude, centerLocation.latitude),
|
||||
tilt = 0.0,
|
||||
padding = getPaddingValues()
|
||||
),
|
||||
duration = 3.seconds
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -266,41 +280,52 @@ class SurfaceRenderer(
|
||||
|
||||
fun updateLocation(location: Location) {
|
||||
synchronized(this) {
|
||||
var bearing: Double
|
||||
if (routeModel.isNavigating()) {
|
||||
bearing = routeModel.currentStep().bearing
|
||||
} else {
|
||||
bearing = cameraPosition.value!!.bearing
|
||||
if (lastLocation.latitude != location.latitude) {
|
||||
if (lastLocation.distanceTo(location) > 5) {
|
||||
bearing = lastLocation.bearingTo(location).toDouble()
|
||||
if (!preview) {
|
||||
var bearing: Double
|
||||
if (routeModel.isNavigating()) {
|
||||
bearing = routeModel.currentStep().bearing
|
||||
} else {
|
||||
bearing = cameraPosition.value!!.bearing
|
||||
if (lastLocation.latitude != location.latitude) {
|
||||
if (lastLocation.distanceTo(location) > 5) {
|
||||
bearing = lastLocation.bearingTo(location).toDouble()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
var zoom = NavigationUtils().calculateZoom(location.speed.toDouble())
|
||||
if (preview) {
|
||||
bearing = 0.0
|
||||
zoom = 11.0
|
||||
}
|
||||
cameraPosition.postValue(
|
||||
cameraPosition.value!!.copy(
|
||||
bearing = bearing,
|
||||
zoom = zoom,
|
||||
padding = getPaddingValues(),
|
||||
target = Position(location.longitude, location.latitude),
|
||||
val zoom = NavigationUtils().calculateZoom(location.speed.toDouble())
|
||||
cameraPosition.postValue(
|
||||
cameraPosition.value!!.copy(
|
||||
bearing = bearing,
|
||||
zoom = zoom,
|
||||
padding = getPaddingValues(),
|
||||
target = Position(location.longitude, location.latitude),
|
||||
)
|
||||
)
|
||||
)
|
||||
lastLocation = location
|
||||
lastLocation = location
|
||||
} else {
|
||||
val bearing = 0.0
|
||||
val zoom = 11.0
|
||||
cameraPosition.postValue(
|
||||
cameraPosition.value!!.copy(
|
||||
bearing = bearing,
|
||||
zoom = zoom,
|
||||
tilt = 0.0,
|
||||
target = Position(centerLocation.longitude, centerLocation.latitude)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
fun setRouteData() {
|
||||
routeData.value = routeModel.route
|
||||
preview = false
|
||||
}
|
||||
|
||||
fun setPreviewRouteData(route: String) {
|
||||
previewRouteData.value = route
|
||||
fun setPreviewRouteData(routeModel: RouteModel) {
|
||||
previewRouteData.value = routeModel.route
|
||||
centerLocation = routeModel.centerLocation
|
||||
preview = true
|
||||
}
|
||||
|
||||
|
||||
@@ -134,7 +134,7 @@ class RouteCarModel() : RouteModel() {
|
||||
|
||||
ManeuverType.Left.value -> {
|
||||
type = Maneuver.TYPE_TURN_NORMAL_LEFT
|
||||
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_slight_left)
|
||||
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_normal_left)
|
||||
}
|
||||
|
||||
ManeuverType.RampLeft.value -> {
|
||||
@@ -149,7 +149,7 @@ class RouteCarModel() : RouteModel() {
|
||||
|
||||
ManeuverType.StayLeft.value -> {
|
||||
type = Maneuver.TYPE_KEEP_LEFT
|
||||
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_slight_left)
|
||||
currentTurnIcon = createCarIcon(carContext, R.drawable.ic_turn_name_change)
|
||||
}
|
||||
}
|
||||
maneuverType = type
|
||||
|
||||
@@ -53,7 +53,7 @@ class PlaceListScreen(
|
||||
}
|
||||
if (category == Constants.CONTACTS) {
|
||||
viewModel.contactAddress.observe(this, observerAddress)
|
||||
viewModel.loadContacts(carContext)
|
||||
viewModel.loadContacts(carContext, location)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -47,6 +47,9 @@ import com.kouros.navigation.car.navigation.RouteCarModel
|
||||
import com.kouros.navigation.data.NavigationRepository
|
||||
import com.kouros.navigation.data.Place
|
||||
import com.kouros.navigation.model.ViewModel
|
||||
import java.math.BigDecimal
|
||||
import java.math.RoundingMode
|
||||
import kotlin.math.roundToInt
|
||||
|
||||
/** Creates a screen using the new [androidx.car.app.navigation.model.MapWithContentTemplate] */
|
||||
class RoutePreviewScreen(
|
||||
@@ -68,7 +71,7 @@ class RoutePreviewScreen(
|
||||
val observer = Observer<String> { route ->
|
||||
if (route.isNotEmpty()) {
|
||||
routeModel.startNavigation(route)
|
||||
surfaceRenderer.setPreviewRouteData(routeModel.route)
|
||||
surfaceRenderer.setPreviewRouteData(routeModel)
|
||||
val geocoder = Geocoder(carContext)
|
||||
geocoder.getFromLocation(destination.latitude, destination.longitude, 1) {
|
||||
for (address in it) {
|
||||
@@ -198,8 +201,9 @@ class RoutePreviewScreen(
|
||||
|
||||
|
||||
private fun createRouteText(index: Int): CarText {
|
||||
val time = routeModel.summary.getInt("time")
|
||||
val length = routeModel.summary.getInt("length")
|
||||
val time = routeModel.routeTime
|
||||
|
||||
val length = BigDecimal(routeModel.routeDistance).setScale(1, RoundingMode.HALF_EVEN)
|
||||
val firstRoute = SpannableString(" \u00b7 $length km")
|
||||
firstRoute.setSpan(
|
||||
DurationSpan.create(time.toLong()), 0, 1,0
|
||||
@@ -208,7 +212,6 @@ class RoutePreviewScreen(
|
||||
.build()
|
||||
}
|
||||
|
||||
|
||||
private fun onNavigate() {
|
||||
setResult(destination)
|
||||
finish()
|
||||
|
||||
@@ -9,6 +9,7 @@ import com.kouros.navigation.model.RouteModel
|
||||
import com.kouros.navigation.model.ViewModel
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.runner.RunWith
|
||||
|
||||
/**
|
||||
* Example local unit test, which will execute on the development machine (host).
|
||||
|
||||
Reference in New Issue
Block a user