116 lines
4.7 KiB
Kotlin
116 lines
4.7 KiB
Kotlin
package eu.ztsh.garmin.data
|
|
|
|
import com.mapbox.navigation.tripdata.maneuver.model.Maneuver
|
|
import com.mapbox.navigation.core.trip.session.LocationMatcherResult
|
|
|
|
class MapboxMapper {
|
|
|
|
companion object {
|
|
|
|
fun asDirection(maneuver: Maneuver): Direction {
|
|
val direction = Direction()
|
|
maneuver.primary.apply {
|
|
when (this.type) {
|
|
"roundabout" -> {
|
|
direction.out = OutType.RightRoundabout
|
|
}
|
|
"arrive" -> {
|
|
direction.out = OutType.Flag
|
|
direction.angle = OutAngle.Right
|
|
}
|
|
"turn" -> {
|
|
when (this.modifier) {
|
|
"straight" -> direction.angle = OutAngle.Straight
|
|
"slight right" -> direction.angle = OutAngle.EasyRight
|
|
"slight left" -> direction.angle = OutAngle.EasyLeft
|
|
"sharp right" -> direction.angle = OutAngle.SharpRight
|
|
"sharp left" -> direction.angle = OutAngle.SharpLeft
|
|
"uturn" -> direction.angle = OutAngle.LeftDown
|
|
}
|
|
}
|
|
}
|
|
when (this.modifier) {
|
|
"right" -> {
|
|
direction.angle = OutAngle.Right
|
|
when (this.type) {
|
|
"roundabout" -> {
|
|
when (this.degrees!!.toInt()) {
|
|
in 22..66 -> direction.angle = OutAngle.SharpRight
|
|
in 67..111 -> direction.angle = OutAngle.Right
|
|
in 112..156 -> direction.angle = OutAngle.EasyRight
|
|
in 157..203 -> direction.angle = OutAngle.Straight
|
|
in 204..248 -> direction.angle = OutAngle.EasyLeft
|
|
in 249..293 -> direction.angle = OutAngle.Left
|
|
in 294..338 -> direction.angle = OutAngle.SharpLeft
|
|
else -> direction.angle = OutAngle.Down
|
|
}
|
|
}
|
|
"fork", "off ramp" -> {
|
|
direction.angle = OutAngle.EasyRight
|
|
direction.out = OutType.LongerLane
|
|
}
|
|
}
|
|
}
|
|
|
|
"left" -> {
|
|
direction.angle = OutAngle.Left
|
|
when (this.type) {
|
|
"fork", "off ramp" -> {
|
|
direction.angle = OutAngle.EasyLeft
|
|
direction.out = OutType.LongerLane
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return direction
|
|
}
|
|
|
|
fun asDistance(maneuver: Maneuver): Distance {
|
|
return maneuver.stepDistance.let { step ->
|
|
step.distanceFormatter.formatDistance(step.distanceRemaining!!).split(" ").let {
|
|
Distance(
|
|
it[0].replace(',', '.').toDouble(),
|
|
when (it[1]) {
|
|
"m" -> Unit.Metres
|
|
"km" -> Unit.Kilometres
|
|
else -> Unit.Any
|
|
}
|
|
)
|
|
}
|
|
}
|
|
}
|
|
|
|
fun asLanes(maneuver: Maneuver): Lanes {
|
|
val laneIterator = Lane.iterator()
|
|
val outlines = mutableSetOf<Lane>()
|
|
val lanes = mutableSetOf<Lane>()
|
|
maneuver.laneGuidance?.apply {
|
|
this.allLanes.reversed().let {
|
|
it.forEach{ indicator ->
|
|
val lane = if (laneIterator.hasNext()) laneIterator.next() else Lane.DotsLeft
|
|
if (lane == Lane.DotsLeft) {
|
|
outlines.add(Lane.DotsLeft)
|
|
} else {
|
|
outlines.add(lane)
|
|
if (indicator.isActive) {
|
|
lanes.add(lane)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return Lanes(Arrows(lanes), Arrows(outlines))
|
|
}
|
|
|
|
fun asSpeed(locationMatcherResult: LocationMatcherResult): Speed {
|
|
return Speed(
|
|
locationMatcherResult.enhancedLocation.speed.let { it?.toInt() ?: 0 },
|
|
locationMatcherResult.speedLimitInfo.speed.let { it ?: 0 },
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|