This commit is contained in:
Dimitris
2025-11-21 07:08:14 +01:00
parent 33f5ef4f34
commit b1a9a2c7fe
13 changed files with 711 additions and 454 deletions

View File

@@ -118,7 +118,7 @@ data class ValhallaLocation (
object Constants {
const val STYLE: String = "https://kouros-online.de/liberty2"
const val STYLE: String = "https://kouros-online.de/liberty.json"
//baseStyle = BaseStyle.Uri("https://tiles.openfreemap.org/styles/liberty"),
const val TAG: String = "Navigation"
@@ -138,6 +138,11 @@ object Constants {
home2Location.latitude = 48.1164817
home2Location.longitude = 11.594322
}
const val SHARED_PREF_KEY = "NavigationPrefs"
const val SHOW_THREED_BUILDING = "Show3D"
}

View File

@@ -16,7 +16,7 @@ data class Route (
*
* @since 1.0.0
*/
val maneuvers: List<Maneuvers>,
var maneuvers: List<Maneuvers>,
/**
* The distance traveled from origin to destination.
@@ -43,8 +43,6 @@ data class Route (
val time: Double,
var routingManeuvers : List<Maneuvers>,
var routeGeoJson : String,
var currentIndex: Int
@@ -63,8 +61,6 @@ data class Route (
private lateinit var trip : Trip
private lateinit var routingManeuvers: List<Maneuvers>
private var routeGeoJson = ""
fun route (route: String ) = apply {
@@ -87,21 +83,22 @@ data class Route (
points.add(point)
}
pointLocations = points
val routings = mutableListOf<Maneuvers>()
for (maneuver in maneuvers) {
routings.add(maneuver)
}
this.routingManeuvers = routings
this.routeGeoJson = createGeoJson(waypoints)
return Route(
maneuvers, distance, waypoints, pointLocations, summary, trip, time, routingManeuvers, routeGeoJson, 0
maneuvers, distance, waypoints, pointLocations, summary, trip, time, routeGeoJson, 0
)
}
}
fun maneuverLocations(): List<Point> {
val beginShapeIndex = currentManeuver().beginShapeIndex
val endShapeIndex = currentManeuver().endShapeIndex
return pointLocations.subList(beginShapeIndex, endShapeIndex)
}
fun clear() {
waypoints = mutableListOf()
routingManeuvers = mutableListOf()
maneuvers = mutableListOf()
routeGeoJson = ""
}

View File

@@ -81,7 +81,6 @@ open class RouteModel() {
fun currentStep(): StepData {
val maneuver = route.currentManeuver()
var text = ""
println("Maneuver $maneuver")
if (maneuver.streetNames != null && maneuver.streetNames.isNotEmpty()) {
text = maneuver.streetNames[0]
}
@@ -156,16 +155,10 @@ open class RouteModel() {
return nearestLocation
}
fun maneuverLocations(): List<Point> {
val beginShapeIndex = route.currentManeuver().beginShapeIndex
val endShapeIndex = route.currentManeuver().endShapeIndex
return route.pointLocations.subList(beginShapeIndex, endShapeIndex)
}
fun travelLeftTime(): Double {
var timeLeft = 0.0
for (i in route.currentIndex + 1..<route.routingManeuvers.size) {
val maneuver = route.routingManeuvers[i]
for (i in route.currentIndex + 1..<route.maneuvers.size) {
val maneuver = route.maneuvers[i]
timeLeft += maneuver.time
}
if (endIndex > 0) {
@@ -180,7 +173,7 @@ open class RouteModel() {
/** Returns the current [Step] left distance in km. */
fun leftStepDistance(): Double {
val maneuver = route.routingManeuvers[route.currentIndex]
val maneuver = route.currentManeuver()
var leftDistance = maneuver.length
if (endIndex > 0) {
leftDistance = (distanceToStepEnd / 1000).toDouble()
@@ -190,12 +183,12 @@ open class RouteModel() {
fun travelLeftDistance(): Double {
var leftDistance = 0.0
for (i in route.currentIndex + 1..<route.routingManeuvers.size) {
val maneuver = route.routingManeuvers[i]
for (i in route.currentIndex + 1..<route.maneuvers.size) {
val maneuver = route.maneuvers[i]
leftDistance += maneuver.length
}
if (endIndex > 0) {
val maneuver = route.routingManeuvers[route.currentIndex]
val maneuver = route.currentManeuver()
val curDistance = maneuver.length
val percent = 100 * (endIndex - currentIndex) / (endIndex - beginIndex)
val time = curDistance * percent / 100
@@ -215,7 +208,6 @@ open class RouteModel() {
fun stopNavigation() {
route.clear()
navigating = false
//maneuverIndex = 0
currentIndex = 0
distanceToStepEnd = 0F
beginIndex = 0

View File

@@ -1,7 +1,11 @@
package com.kouros.navigation.utils
import android.content.Context
import android.location.Location
import android.location.LocationManager
import androidx.core.content.edit
import com.kouros.navigation.data.Constants.SHARED_PREF_KEY
import com.kouros.navigation.data.Constants.SHOW_THREED_BUILDING
import com.kouros.navigation.data.GeoJsonFeature
import com.kouros.navigation.data.GeoJsonFeatureCollection
import com.kouros.navigation.data.GeoJsonLineString
@@ -25,6 +29,28 @@ import kotlin.math.sin
object NavigationUtils {
fun getBooleanKeyValue(context: Context, key: String) : Boolean {
return context
.getSharedPreferences(
SHARED_PREF_KEY,
Context.MODE_PRIVATE
)
.getBoolean(key, false)
}
fun setBooleanKeyValue(context: Context, `val`: Boolean, key: String) {
context
.getSharedPreferences(
SHARED_PREF_KEY,
Context.MODE_PRIVATE
)
.edit {
putBoolean(
key, `val`
)
apply()
}
}
fun snapLocation(location: Location, stepCoordinates: List<Point>): Location {
val oldPoint = Point.fromLngLat(location.longitude, location.latitude)
if (stepCoordinates.size > 1) {