TomTom Routing

This commit is contained in:
Dimitris
2026-02-10 10:50:42 +01:00
parent 5141041b5c
commit 65ff41995d
26 changed files with 182 additions and 201 deletions

View File

@@ -251,11 +251,11 @@ class NavigationSession : Session(), NavigationScreen.Listener {
fun updateLocation(location: Location) {
if (routeModel.isNavigating()) {
navigationScreen.updateTrip(location)
if (!routeModel.arrived) {
if (!routeModel.navState.arrived) {
val snapedLocation = snapLocation(location, routeModel.route.maneuverLocations())
val distance = location.distanceTo(snapedLocation)
if (distance > MAXIMAL_ROUTE_DEVIATION) {
navigationScreen.calculateNewRoute(routeModel.destination)
navigationScreen.calculateNewRoute(routeModel.navState.destination)
return
}
if (distance < MAXIMAL_SNAP_CORRECTION) {

View File

@@ -470,7 +470,7 @@ fun DebugInfo(
contentAlignment = Alignment.CenterStart
) {
val textMeasurerLocation = rememberTextMeasurer()
val location = routeModel.currentLocation.latitude.toString()
val location = routeModel.navState.currentLocation.latitude.toString()
val styleSpeed = TextStyle(
fontSize = 26.sp,
fontWeight = FontWeight.Bold,

View File

@@ -68,8 +68,8 @@ class RouteCarModel() : RouteModel() {
.setManeuver(
maneuver.build()
)
if (destination.street != null) {
step.setRoad(destination.street!!)
if (navState.destination.street != null) {
step.setRoad(navState.destination.street!!)
}
if (stepData.lane.isNotEmpty()) {
addLanes(carContext, step, stepData)
@@ -127,9 +127,9 @@ class RouteCarModel() : RouteModel() {
.setRemainingTimeColor(CarColor.GREEN)
.setRemainingDistanceColor(CarColor.BLUE)
if (travelMessage.isNotEmpty()) {
if (navState.travelMessage.isNotEmpty()) {
travelBuilder.setTripIcon(createCarIcon(carContext, R.drawable.warning_24px))
travelBuilder.setTripText(CarText.create(travelMessage))
travelBuilder.setTripText(CarText.create(navState.travelMessage))
}
return travelBuilder.build()
}
@@ -147,10 +147,10 @@ class RouteCarModel() : RouteModel() {
"${direction}_${it2.trim()}"
}
}
val laneDirection = iconMapper.addLanes(direction, stepData)
val laneDirection = navState.iconMapper.addLanes(direction, stepData)
if (laneDirection != LaneDirection.SHAPE_UNKNOWN) {
if (!laneImageAdded) {
step.setLanesImage(createCarIcon(iconMapper.createLaneIcon(carContext, stepData)))
step.setLanesImage(createCarIcon(navState.iconMapper.createLaneIcon(carContext, stepData)))
laneImageAdded = true
}
val laneType =

View File

@@ -44,10 +44,10 @@ class CategoryScreen(
val loc = location(0.0, 0.0)
elements.forEach {
if (loc.latitude == 0.0) {
loc.longitude = it.lon!!
loc.latitude = it.lat!!
loc.longitude = it.lon
loc.latitude = it.lat
}
coordinates.add(listOf(it.lon!!, it.lat!!))
coordinates.add(listOf(it.lon, it.lat))
}
if (elements.isNotEmpty()) {
val route = createPointCollection(coordinates, category)
@@ -111,7 +111,7 @@ class CategoryScreen(
}
val row = Row.Builder()
.setOnClickListener {
val location = location(it.lon!!, it.lat!!)
val location = location(it.lon, it.lat)
surfaceRenderer.setCategoryLocation(location, category)
}
.setTitle(name)

View File

@@ -31,16 +31,12 @@ import com.kouros.navigation.data.Constants.DESTINATION_ARRIVAL_DISTANCE
import com.kouros.navigation.data.Place
import com.kouros.navigation.data.nominatim.SearchResult
import com.kouros.navigation.data.overpass.Elements
import com.kouros.navigation.data.tomtom.Features
import com.kouros.navigation.data.tomtom.Geometry
import com.kouros.navigation.model.ViewModel
import com.kouros.navigation.utils.GeoUtils
import com.kouros.navigation.utils.location
import java.time.LocalDateTime
import java.time.Period
import java.time.ZoneOffset
import kotlin.math.absoluteValue
import kotlin.time.Duration
class NavigationScreen(
carContext: CarContext,
@@ -154,11 +150,11 @@ class NavigationScreen(
}
private fun navigationEndTemplate(actionStripBuilder: ActionStrip.Builder): Template {
if (routeModel.arrived) {
if (routeModel.navState.arrived) {
val timer = object : CountDownTimer(8000, 1000) {
override fun onTick(millisUntilFinished: Long) {}
override fun onFinish() {
routeModel.arrived = false
routeModel.navState = routeModel.navState.copy(arrived = false)
navigationType = NavigationType.VIEW
invalidate()
}
@@ -177,8 +173,8 @@ class NavigationScreen(
fun navigationArrivedTemplate(actionStripBuilder: ActionStrip.Builder): NavigationTemplate {
var street = ""
if (routeModel.destination.street != null) {
street = routeModel.destination.street!!
if (routeModel.navState.destination.street != null) {
street = routeModel.navState.destination.street!!
}
return NavigationTemplate.Builder()
.setNavigationInfo(
@@ -316,7 +312,7 @@ class NavigationScreen(
navigateTo,
surfaceRenderer.carOrientation
)
routeModel.destination = recentPlace
routeModel.navState = routeModel.navState.copy(destination = recentPlace)
}
.build()
}
@@ -444,7 +440,7 @@ class NavigationScreen(
location,
surfaceRenderer.carOrientation
)
routeModel.destination = place
routeModel.navState = routeModel.navState.copy(destination = place)
invalidate()
}
@@ -492,14 +488,14 @@ class NavigationScreen(
updateSpeedCamera(location)
with(routeModel) {
updateLocation(location, viewModel)
if ((maneuverType == Maneuver.TYPE_DESTINATION
|| maneuverType == Maneuver.TYPE_DESTINATION_LEFT
|| maneuverType == Maneuver.TYPE_DESTINATION_RIGHT
|| maneuverType == Maneuver.TYPE_DESTINATION_STRAIGHT)
if ((navState.maneuverType == Maneuver.TYPE_DESTINATION
|| navState.maneuverType == Maneuver.TYPE_DESTINATION_LEFT
|| navState.maneuverType == Maneuver.TYPE_DESTINATION_RIGHT
|| navState.maneuverType == Maneuver.TYPE_DESTINATION_STRAIGHT)
&& routeCalculator.leftStepDistance() < DESTINATION_ARRIVAL_DISTANCE
) {
stopNavigation()
arrived = true
navState = navState.copy(arrived = true)
surfaceRenderer.routeData.value = ""
navigationType = NavigationType.ARRIVAL
invalidate()

View File

@@ -124,7 +124,7 @@ class PlaceListScreen(
setSpan(
DistanceSpan.create(
Distance.create(
it.distance.toDouble(),
(it.distance/1000).toDouble(),
Distance.UNIT_KILOMETERS
)
), 0, 1, Spannable.SPAN_INCLUSIVE_INCLUSIVE

View File

@@ -220,7 +220,7 @@ class RoutePreviewScreen(
}
private fun onRouteSelected(index: Int) {
routeModel.currentRouteIndex = index
routeModel.navState = routeModel.navState.copy(currentRouteIndex = index)
surfaceRenderer.setPreviewRouteData(routeModel)
//setResult(destination)
//finish()