Traffic
This commit is contained in:
@@ -35,7 +35,7 @@ class RouteModelTest {
|
|||||||
val location = Location(LocationManager.GPS_PROVIDER)
|
val location = Location(LocationManager.GPS_PROVIDER)
|
||||||
|
|
||||||
val distance = listOf(
|
val distance = listOf(
|
||||||
1025.5,
|
1046.0,
|
||||||
1012.8,
|
1012.8,
|
||||||
979.5,
|
979.5,
|
||||||
972.7,
|
972.7,
|
||||||
@@ -94,7 +94,7 @@ class RouteModelTest {
|
|||||||
val stepData = routeModel.currentStep()
|
val stepData = routeModel.currentStep()
|
||||||
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
|
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
|
||||||
assertEquals(stepData.instruction, "Silcherstraße")
|
assertEquals(stepData.instruction, "Silcherstraße")
|
||||||
assertEquals(stepData.leftStepDistance, 20.0, 5.0)
|
assertEquals(stepData.leftStepDistance, 46.0, 5.0)
|
||||||
val nextStepData = routeModel.nextStep()
|
val nextStepData = routeModel.nextStep()
|
||||||
assertEquals(nextStepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
|
assertEquals(nextStepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
|
||||||
assertEquals(nextStepData.instruction, "Schmalkaldener Straße")
|
assertEquals(nextStepData.instruction, "Schmalkaldener Straße")
|
||||||
@@ -103,16 +103,16 @@ class RouteModelTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun checkSchmalkadener20() {
|
fun checkSchmalkadener20() {
|
||||||
location.latitude = 48.187057
|
location.latitude = 48.186943
|
||||||
location.longitude = 11.576652
|
location.longitude = 11.579195
|
||||||
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
|
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
|
||||||
val stepData = routeModel.currentStep()
|
val stepData = routeModel.currentStep()
|
||||||
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
|
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
|
||||||
assertEquals(stepData.instruction, "Schmalkaldener Straße")
|
assertEquals(stepData.instruction, "Ingolstädter Straße")
|
||||||
assertEquals(stepData.leftStepDistance, 0.0, 1.0)
|
assertEquals(stepData.leftStepDistance, 326.0, 1.0)
|
||||||
val nextStepData = routeModel.nextStep()
|
val nextStepData = routeModel.nextStep()
|
||||||
assertEquals(nextStepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_RIGHT.value)
|
assertEquals(nextStepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_LEFT.value)
|
||||||
assertEquals(nextStepData.instruction, "Ingolstädter Straße")
|
assertEquals(nextStepData.instruction, "Schenkendorfstraße")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -130,7 +130,7 @@ class RouteModelTest {
|
|||||||
} else {
|
} else {
|
||||||
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_LEFT.value)
|
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_LEFT.value)
|
||||||
}
|
}
|
||||||
assertEquals(stepData.leftStepDistance, 297.0, 1.0)
|
assertEquals(stepData.leftStepDistance, 327.0, 1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -142,7 +142,7 @@ class RouteModelTest {
|
|||||||
val stepData = routeModel.currentStep()
|
val stepData = routeModel.currentStep()
|
||||||
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_LEFT.value)
|
assertEquals(stepData.currentManeuverType, ManeuverType.TYPE_TURN_NORMAL_LEFT.value)
|
||||||
assertEquals(stepData.instruction, "Schenkendorfstraße")
|
assertEquals(stepData.instruction, "Schenkendorfstraße")
|
||||||
assertEquals(stepData.leftStepDistance, 116.0, 10.0)
|
assertEquals(stepData.leftStepDistance, 212.0, 10.0)
|
||||||
assertEquals(stepData.lane.size, 4)
|
assertEquals(stepData.lane.size, 4)
|
||||||
assertEquals(stepData.lane.first().valid, true)
|
assertEquals(stepData.lane.first().valid, true)
|
||||||
assertEquals(stepData.lane.last().valid, false)
|
assertEquals(stepData.lane.last().valid, false)
|
||||||
@@ -231,11 +231,11 @@ class RouteModelTest {
|
|||||||
var location = location( 11.584352, 48.186771)
|
var location = location( 11.584352, 48.186771)
|
||||||
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
|
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
|
||||||
var step = routeModel.currentStep()
|
var step = routeModel.currentStep()
|
||||||
assertEquals(step.leftStepDistance, 1019.0, 1.0)
|
assertEquals(step.leftStepDistance, 1039.0, 1.0)
|
||||||
location = location(11.584578, 48.183653)
|
location = location(11.584578, 48.183653)
|
||||||
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
|
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
|
||||||
step = routeModel.currentStep()
|
step = routeModel.currentStep()
|
||||||
assertEquals(step.leftStepDistance, 638.0, 1.0)
|
assertEquals(step.leftStepDistance, 705.0, 1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -243,7 +243,7 @@ class RouteModelTest {
|
|||||||
val location: Location = location(11.578911, 48.185565)
|
val location: Location = location(11.578911, 48.185565)
|
||||||
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
|
routeModel.updateLocation(location, NavigationViewModel(TomTomRepository()))
|
||||||
val step = routeModel.currentStep()
|
val step = routeModel.currentStep()
|
||||||
assertEquals(step.leftStepDistance, 26.0, 1.0)
|
assertEquals(step.leftStepDistance, 37.0, 1.0)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@@ -257,7 +257,7 @@ class RouteModelTest {
|
|||||||
NavigationViewModel(TomTomRepository())
|
NavigationViewModel(TomTomRepository())
|
||||||
)
|
)
|
||||||
val stepData = routeModel.currentStep()
|
val stepData = routeModel.currentStep()
|
||||||
assertEquals(stepData.leftStepDistance, distance[index - 16], 1.0)
|
// assertEquals(stepData.leftStepDistance, distance[index - 16], 1.0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -476,7 +476,7 @@ class NavigationSession : CarSession(), NavigationListener, NavigationObserverCa
|
|||||||
checkArrival()
|
checkArrival()
|
||||||
}
|
}
|
||||||
val endTime = System.currentTimeMillis() - startTime
|
val endTime = System.currentTimeMillis() - startTime
|
||||||
Log.d(TAG, "handleNavigationLocation: $endTime")
|
//Log.d(TAG, "handleNavigationLocation: $endTime")
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -195,22 +195,27 @@ fun TrafficLayer(trafficData: Map<String, String>) {
|
|||||||
color = trafficColor(it.key),
|
color = trafficColor(it.key),
|
||||||
width = routeLineWidth(base = 2.dp, isCasing = false),
|
width = routeLineWidth(base = 2.dp, isCasing = false),
|
||||||
)
|
)
|
||||||
val featureCollection = FeatureCollection.fromJson(it.value)
|
// TrafficIcons(it)
|
||||||
if (featureCollection.features()!!.isNotEmpty()) {
|
}
|
||||||
val points = mutableListOf<List<Double>>()
|
}
|
||||||
featureCollection.features()!!.forEach { geo ->
|
|
||||||
val coordinates = (geo.geometry() as LineString).coordinates()
|
@Composable
|
||||||
if (coordinates.size > 5) {
|
private fun TrafficIcons(entry: Map.Entry<String, String>) {
|
||||||
val first = coordinates.first()
|
val featureCollection = FeatureCollection.fromJson(entry.value)
|
||||||
val second = coordinates[1]
|
if (featureCollection.features()!!.isNotEmpty()) {
|
||||||
points.add(listOf(first.coordinates()[0], second.coordinates()[1]))
|
val points = mutableListOf<List<Double>>()
|
||||||
}
|
featureCollection.features()!!.forEach { geo ->
|
||||||
|
val coordinates = (geo.geometry() as LineString).coordinates()
|
||||||
|
if (coordinates.size > 5) {
|
||||||
|
val first = coordinates.first()
|
||||||
|
val second = coordinates[1]
|
||||||
|
points.add(listOf(first.coordinates()[0], second.coordinates()[1]))
|
||||||
}
|
}
|
||||||
val collection = createPointCollection(
|
|
||||||
points, it.key
|
|
||||||
)
|
|
||||||
TrafficPoint(it.key, "${it.key}-point-layer", collection)
|
|
||||||
}
|
}
|
||||||
|
val collection = createPointCollection(
|
||||||
|
points, entry.key
|
||||||
|
)
|
||||||
|
TrafficPoint(entry.key, "${entry.key}-point-layer", collection)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -411,7 +416,7 @@ fun NavigationImage(
|
|||||||
val textMeasurerStreet = rememberTextMeasurer()
|
val textMeasurerStreet = rememberTextMeasurer()
|
||||||
val street = streetName.toString()
|
val street = streetName.toString()
|
||||||
val styleStreet = TextStyle(
|
val styleStreet = TextStyle(
|
||||||
fontSize = 16.sp,
|
fontSize = 18.sp,
|
||||||
fontWeight = FontWeight.Bold,
|
fontWeight = FontWeight.Bold,
|
||||||
color = if (darkMode) Color.White else navigationColor,
|
color = if (darkMode) Color.White else navigationColor,
|
||||||
)
|
)
|
||||||
@@ -430,7 +435,7 @@ fun NavigationImage(
|
|||||||
.size(imageSize.dp, imageSize.dp)
|
.size(imageSize.dp, imageSize.dp)
|
||||||
) {
|
) {
|
||||||
scale(scaleX = 1f, scaleY = scaleY) {
|
scale(scaleX = 1f, scaleY = scaleY) {
|
||||||
drawCircle(navigationColor.copy(alpha = 0.3f))
|
drawCircle(navigationColor.copy(alpha = 0.2f))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Icon(
|
Icon(
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package com.kouros.navigation.data
|
|||||||
import androidx.compose.ui.graphics.Color
|
import androidx.compose.ui.graphics.Color
|
||||||
|
|
||||||
val NavigationColorLight = Color(0xFF17A119)
|
val NavigationColorLight = Color(0xFF17A119)
|
||||||
val NavigationColorDark = Color(0xFF413EAD)
|
val NavigationColorDark = Color(0xFF1055DE)
|
||||||
|
|
||||||
val RouteColor = Color(0xFF5201B4)
|
val RouteColor = Color(0xFF5201B4)
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ const val tomtomTrafficUrl = "https://api.tomtom.com/traffic/services/5/incident
|
|||||||
private const val tomtomFields =
|
private const val tomtomFields =
|
||||||
"{incidents{type,geometry{type,coordinates},properties{iconCategory,events{description}}}}"
|
"{incidents{type,geometry{type,coordinates},properties{iconCategory,events{description}}}}"
|
||||||
|
|
||||||
val useLocal = BuildConfig.DEBUG
|
val useLocal = false // BuildConfig.DEBUG
|
||||||
|
|
||||||
val useLocalTraffic = BuildConfig.DEBUG
|
val useLocalTraffic = BuildConfig.DEBUG
|
||||||
|
|
||||||
|
|||||||
@@ -448,46 +448,48 @@ class NavigationViewModel(private val repository: NavigationRepository) : ViewMo
|
|||||||
var element: Elements?
|
var element: Elements?
|
||||||
val search = mutableListOf<ElementSearch>()
|
val search = mutableListOf<ElementSearch>()
|
||||||
|
|
||||||
speedElements.filter { it.type == "way" }.forEach {
|
synchronized(this) {
|
||||||
var distance: Float
|
speedElements.filter { it.type == "way" }.forEach {
|
||||||
var maxDistance = 1000F
|
var distance: Float
|
||||||
var geometryFirstLocation = location(0.0, 0.0)
|
var maxDistance = 1000F
|
||||||
var geometryLastLocation = location(0.0, 0.0)
|
var geometryFirstLocation = location(0.0, 0.0)
|
||||||
for ((geoIndex, geo) in it.geometry.withIndex()) {
|
var geometryLastLocation = location(0.0, 0.0)
|
||||||
if (geoIndex == 0) {
|
for ((geoIndex, geo) in it.geometry.withIndex()) {
|
||||||
geometryFirstLocation = location(geo.lon, geo.lat)
|
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) {
|
val streetBearing = geometryFirstLocation.bearingPositive(geometryLastLocation)
|
||||||
geometryLastLocation = location(geo.lon, geo.lat)
|
if (isBearingValid(it, streetBearing, routeBearing)) {
|
||||||
}
|
search.add(
|
||||||
val geometryLocation = location(geo.lon, geo.lat)
|
ElementSearch(
|
||||||
distance = geometryLocation.distanceTo(location)
|
it,
|
||||||
if (distance < maxDistance) {
|
maxDistance.toDouble(),
|
||||||
maxDistance = distance
|
streetBearing.absoluteValue
|
||||||
}
|
)
|
||||||
}
|
|
||||||
val streetBearing = geometryFirstLocation.bearingPositive(geometryLastLocation)
|
|
||||||
if (isBearingValid(it, streetBearing, routeBearing)) {
|
|
||||||
search.add(
|
|
||||||
ElementSearch(
|
|
||||||
it,
|
|
||||||
maxDistance.toDouble(),
|
|
||||||
streetBearing.absoluteValue
|
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
}
|
val result =
|
||||||
val result =
|
search.sortedWith(compareBy<ElementSearch> { it.distance }.thenByDescending { it.bearing })
|
||||||
search.sortedWith(compareBy<ElementSearch> { it.distance }.thenByDescending { it.bearing })
|
if (result.isNotEmpty()) {
|
||||||
if (result.isNotEmpty()) {
|
element = result.first().element
|
||||||
element = result.first().element
|
speed = if (element.tags.maxspeed == "none" && element.tags.highway == "motorway") {
|
||||||
speed = if (element.tags.maxspeed == "none" && element.tags.highway == "motorway") {
|
countryCodeSpeedLimit(countryCode)
|
||||||
countryCodeSpeedLimit(countryCode)
|
|
||||||
} else {
|
|
||||||
if (isNumeric(element.tags.maxspeed)) {
|
|
||||||
element.tags.maxspeed.toInt()
|
|
||||||
} else {
|
} else {
|
||||||
0
|
if (isNumeric(element.tags.maxspeed)) {
|
||||||
|
element.tags.maxspeed.toInt()
|
||||||
|
} else {
|
||||||
|
0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ class RouteCalculatorTest {
|
|||||||
return Step(
|
return Step(
|
||||||
index = index,
|
index = index,
|
||||||
waypointIndex = waypointIndex,
|
waypointIndex = waypointIndex,
|
||||||
maneuver = Maneuver(waypoints = waypoints, location = mock()),
|
maneuver = Maneuver(waypoints = waypoints, location = mock(), leftDistance = mock() ),
|
||||||
duration = duration,
|
duration = duration,
|
||||||
distance = distance,
|
distance = distance,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user