This commit is contained in:
Dimitris
2026-04-29 15:59:30 +02:00
parent ae4d3f321e
commit 615141d816
7 changed files with 77 additions and 70 deletions
@@ -3,7 +3,7 @@ package com.kouros.navigation.data
import androidx.compose.ui.graphics.Color
val NavigationColorLight = Color(0xFF17A119)
val NavigationColorDark = Color(0xFF413EAD)
val NavigationColorDark = Color(0xFF1055DE)
val RouteColor = Color(0xFF5201B4)
@@ -21,7 +21,7 @@ const val tomtomTrafficUrl = "https://api.tomtom.com/traffic/services/5/incident
private const val tomtomFields =
"{incidents{type,geometry{type,coordinates},properties{iconCategory,events{description}}}}"
val useLocal = BuildConfig.DEBUG
val useLocal = false // BuildConfig.DEBUG
val useLocalTraffic = BuildConfig.DEBUG
@@ -448,46 +448,48 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
var element: Elements?
val search = mutableListOf<ElementSearch>()
speedElements.filter { it.type == "way" }.forEach {
var distance: Float
var maxDistance = 1000F
var geometryFirstLocation = location(0.0, 0.0)
var geometryLastLocation = location(0.0, 0.0)
for ((geoIndex, geo) in it.geometry.withIndex()) {
if (geoIndex == 0) {
geometryFirstLocation = location(geo.lon, geo.lat)
synchronized(this) {
speedElements.filter { it.type == "way" }.forEach {
var distance: Float
var maxDistance = 1000F
var geometryFirstLocation = location(0.0, 0.0)
var geometryLastLocation = location(0.0, 0.0)
for ((geoIndex, geo) in it.geometry.withIndex()) {
if (geoIndex == 0) {
geometryFirstLocation = location(geo.lon, geo.lat)
}
if (geoIndex == it.geometry.size - 1) {
geometryLastLocation = location(geo.lon, geo.lat)
}
val geometryLocation = location(geo.lon, geo.lat)
distance = geometryLocation.distanceTo(location)
if (distance < maxDistance) {
maxDistance = distance
}
}
if (geoIndex == it.geometry.size - 1) {
geometryLastLocation = location(geo.lon, geo.lat)
}
val geometryLocation = location(geo.lon, geo.lat)
distance = geometryLocation.distanceTo(location)
if (distance < maxDistance) {
maxDistance = distance
}
}
val streetBearing = geometryFirstLocation.bearingPositive(geometryLastLocation)
if (isBearingValid(it, streetBearing, routeBearing)) {
search.add(
ElementSearch(
it,
maxDistance.toDouble(),
streetBearing.absoluteValue
val streetBearing = geometryFirstLocation.bearingPositive(geometryLastLocation)
if (isBearingValid(it, streetBearing, routeBearing)) {
search.add(
ElementSearch(
it,
maxDistance.toDouble(),
streetBearing.absoluteValue
)
)
)
}
}
}
val result =
search.sortedWith(compareBy<ElementSearch> { it.distance }.thenByDescending { it.bearing })
if (result.isNotEmpty()) {
element = result.first().element
speed = if (element.tags.maxspeed == "none" && element.tags.highway == "motorway") {
countryCodeSpeedLimit(countryCode)
} else {
if (isNumeric(element.tags.maxspeed)) {
element.tags.maxspeed.toInt()
val result =
search.sortedWith(compareBy<ElementSearch> { it.distance }.thenByDescending { it.bearing })
if (result.isNotEmpty()) {
element = result.first().element
speed = if (element.tags.maxspeed == "none" && element.tags.highway == "motorway") {
countryCodeSpeedLimit(countryCode)
} else {
0
if (isNumeric(element.tags.maxspeed)) {
element.tags.maxspeed.toInt()
} else {
0
}
}
}
}
@@ -49,7 +49,7 @@ class RouteCalculatorTest {
return Step(
index = index,
waypointIndex = waypointIndex,
maneuver = Maneuver(waypoints = waypoints, location = mock()),
maneuver = Maneuver(waypoints = waypoints, location = mock(), leftDistance = mock() ),
duration = duration,
distance = distance,
)