Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@

public class OnboardRouterActivityJava extends AppCompatActivity {

private Router offboardRouter;
private Router offboardRouter;

@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setupRouter();
}
setupRouter();
}

private void setupRouter() {
Config config = new Config(
this.getApplication().getExternalFilesDir(null).getPath(),
null,
null,
null,
null);
private void setupRouter() {
Config config = new Config(
this.getApplication().getExternalFilesDir(null).getPath(),
null,
null,
null,
null);

offboardRouter = new MapboxOnboardRouter(Mapbox.getAccessToken(), config);
}
offboardRouter = new MapboxOnboardRouter(Mapbox.getAccessToken(), config);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,32 @@
package com.mapbox.services.android.navigation.v5.utils.extensions

import com.mapbox.api.directions.v5.WalkingOptions
import com.mapbox.api.directions.v5.models.BannerComponents
import com.mapbox.api.directions.v5.models.BannerInstructions
import com.mapbox.api.directions.v5.models.BannerText
import com.mapbox.api.directions.v5.models.DirectionsRoute
import com.mapbox.api.directions.v5.models.IntersectionLanes
import com.mapbox.api.directions.v5.models.LegAnnotation
import com.mapbox.api.directions.v5.models.LegStep
import com.mapbox.api.directions.v5.models.MaxSpeed
import com.mapbox.api.directions.v5.models.RouteLeg
import com.mapbox.api.directions.v5.models.RouteOptions
import com.mapbox.api.directions.v5.models.StepIntersection
import com.mapbox.api.directions.v5.models.StepManeuver
import com.mapbox.api.directions.v5.models.VoiceInstructions
import com.mapbox.navigation.base.route.model.BannerComponentsNavigation
import com.mapbox.navigation.base.route.model.BannerInstructionsNavigation
import com.mapbox.navigation.base.route.model.BannerTextNavigation
import com.mapbox.navigation.base.route.model.IntersectionLanesNavigation
import com.mapbox.navigation.base.route.model.LegAnnotationNavigation
import com.mapbox.navigation.base.route.model.LegStepNavigation
import com.mapbox.navigation.base.route.model.MaxSpeedNavigation
import com.mapbox.navigation.base.route.model.Route
import com.mapbox.navigation.base.route.model.RouteLegNavigation
import com.mapbox.navigation.base.route.model.RouteOptionsNavigation
import com.mapbox.navigation.base.route.model.StepIntersectionNavigation
import com.mapbox.navigation.base.route.model.StepManeuverNavigation
import com.mapbox.navigation.base.route.model.VoiceInstructionsNavigation
import com.mapbox.navigation.base.route.model.WalkingOptionsNavigation

fun WalkingOptionsNavigation.mapToWalkingOptions(): WalkingOptions = WalkingOptions
Expand All @@ -16,16 +39,158 @@ fun WalkingOptionsNavigation.mapToWalkingOptions(): WalkingOptions = WalkingOpti
.build()

fun Route.mapToDirectionsRoute(): DirectionsRoute {
val duration = duration.toDouble()
val legs = legs?.let { it as List<RouteLeg> }

return DirectionsRoute.builder()
return DirectionsRoute.builder() // FIXME route index
.distance(distance)
.duration(duration)
.duration(duration.toDouble())
.geometry(geometry)
.weight(weight)
.weightName(weightName)
.voiceLanguage(voiceLanguage)
.legs(legs)
.legs(legs?.map(RouteLegNavigation::mapToRouteLeg))
.routeOptions(routeOptions?.mapToRouteOptions())
.build()
}

fun RouteOptionsNavigation.mapToRouteOptions() =
RouteOptions.builder()
.apply {
walkingOptions?.let { walkingOptions(it.mapToWalkingOptions()) }
accessToken?.let { accessToken(it) }
exclude?.let { exclude(it) }
requestUuid?.let { requestUuid(it) }
}
.profile(profile)
.user(user)
.baseUrl(baseUrl)
.alternatives(alternatives)
.annotations(annotations)
.approaches(approaches)!!
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should fix (remove @Nullable) annotations in mapbox-java e.g. https://github.com/mapbox/mapbox-java/blob/9bd6158292374fc6dd5f7eba33e7586ca1d76177/services-directions/src/main/java/com/mapbox/api/directions/v5/models/RouteOptions.java#L568 Builder cannot be null to avoid unnecessary !!. The same thing happens with another methods below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we make it self or create a ticket for Direction API team? what is algorithm for it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah feel free to cut a PR in mapbox-java fixing this (should be a pretty straightforward one 😛). We're in charge of maintaining the nav-related services, the Directions API team does know nothing about these wrappers 😅

.bannerInstructions(bannerInstructions)
.bearings(bearings)
.continueStraight(continueStraight)
.coordinates(coordinates)
.geometries(geometries)
.approaches(approaches)!!
.language(language)
.overview(overview)
.radiuses(radiuses)
.roundaboutExits(roundaboutExits)
.steps(steps)
.alternatives(alternatives)
.voiceInstructions(voiceInstructions)
.voiceUnits(voiceUnits)
.waypointIndices(waypointIndices)!!
.waypointNames(waypointNames)!!
.waypointTargets(waypointTargets)!!
.build()

fun RouteLegNavigation.mapToRouteLeg() =
RouteLeg.builder()
.annotation(annotation?.mapToLegAnnotation())
.distance(distance)
.duration(duration)
.steps(steps?.map(LegStepNavigation::mapToLegStep))
.summary(summary)
.build()

fun LegAnnotationNavigation.mapToLegAnnotation() =
LegAnnotation.builder()
.congestion(congestion)
.distance(distance)
.duration(duration)
.maxspeed(maxspeed?.map(MaxSpeedNavigation::mapToMaxSpeed))
.speed(speed)
.build()

fun LegStepNavigation.mapToLegStep() =
LegStep.builder()
.bannerInstructions(bannerInstructions?.map(BannerInstructionsNavigation::mapToBannerInstruction) ?: emptyList())
.destinations(destinations)
.distance(distance)
.drivingSide(drivingSide)
.duration(duration)
.exits(exits)
.geometry(geometry)
.intersections(intersections?.map(StepIntersectionNavigation::mapToStepIntersection) ?: emptyList())
.maneuver(maneuver.mapToStepManeuver())
.mode(mode)
.name(name)
.pronunciation(pronunciation)
.ref(ref)
.rotaryName(rotaryName)
.rotaryPronunciation(rotaryPronunciation)
.voiceInstructions(voiceInstructions?.map(VoiceInstructionsNavigation::mapToVoiceInstructions) ?: emptyList())
.weight(weight)
.build()

fun MaxSpeedNavigation.mapToMaxSpeed() =
MaxSpeed.builder()
.speed(speed)
.none(none)
.unit(unit)
.unknown(unknown)
.build()

fun BannerInstructionsNavigation.mapToBannerInstruction() =
BannerInstructions.builder()
.distanceAlongGeometry(distanceAlongGeometry)
.primary(primary?.mapToBannerText() ?: BannerText.builder().build())
.secondary(secondary?.mapToBannerText())
.sub(sub?.mapToBannerText())
.build()

fun StepIntersectionNavigation.mapToStepIntersection() =
StepIntersection.builder()
.bearings(bearings)
.classes(classes)
.entry(entry)
.`in`(into)
.out(out)
.lanes(lanes?.map(IntersectionLanesNavigation::mapToIntersectionLanes))
.rawLocation(rawLocation)
.build()

fun StepManeuverNavigation.mapToStepManeuver() =
StepManeuver.builder()
.bearingAfter(bearingAfter)
.bearingBefore(bearingBefore)
.exit(exit)
.instruction(instruction)
.modifier(modifier)
.rawLocation(rawLocation)
.type(type)
.build()

fun VoiceInstructionsNavigation.mapToVoiceInstructions() =
VoiceInstructions.builder()
.announcement(announcement)
.distanceAlongGeometry(distanceAlongGeometry)
.ssmlAnnouncement(ssmlAnnouncement)
.build()

fun BannerTextNavigation.mapToBannerText() =
BannerText.builder()
.text(text ?: "")!!
.components(components?.map(BannerComponentsNavigation::mapToBannerComponents))!!
.degrees(degrees)
.drivingSide(drivingSide)
.modifier(modifier)
.type(type)
.build()

fun IntersectionLanesNavigation.mapToIntersectionLanes() =
IntersectionLanes.builder()
.indications(indications)
.valid(valid)
.build()

fun BannerComponentsNavigation.mapToBannerComponents() =
BannerComponents.builder()
.abbreviation(abbreviation)
.abbreviationPriority(abbreviationPriority)
.active(active)
.directions(directions)
.imageBaseUrl(imageBaseUrl)
.text(text)
.type(type)
.build()
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.google.gson.annotations.SerializedName
import com.mapbox.navigation.base.route.model.BannerComponentsNavigation

class BannerComponentsNavigationDto(
val text: String?,
val type: String?,
val text: String,
val type: String,
@SerializedName("abbr")
val abbreviation: String?,
@SerializedName("abbr_priority")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ internal class LegStepNavigationDto(
val name: String?,
val ref: String?,
val destinations: String?,
val mode: String?,
val mode: String,
val pronunciation: String?,
@SerializedName("rotary_name")
val rotaryName: String?,
@SerializedName("rotary_pronunciation")
val rotaryPronunciation: String?,
val maneuver: StepManeuverNavigation?,
val maneuver: StepManeuverNavigation,
val voiceInstructions: List<VoiceInstructionsNavigationDto>?,
val bannerInstructions: List<BannerInstructionsNavigationDto>?,
@SerializedName("driving_side")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ package com.mapbox.navigation.base.route.model
* @since 1.0
*/
data class BannerComponentsNavigation(
val text: String?,
val type: String?,
val text: String,
val type: String,
val abbreviation: String?,
val abbreviationPriority: Int?,
val imageBaseUrl: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ class LegStepNavigation(
val name: String?,
val ref: String?,
val destinations: String?,
val mode: String?,
val mode: String,
val pronunciation: String?,
val rotaryName: String?,
val rotaryPronunciation: String?,
val maneuver: StepManeuverNavigation?,
val maneuver: StepManeuverNavigation,
val voiceInstructions: List<VoiceInstructionsNavigation>?,
val bannerInstructions: List<BannerInstructionsNavigation>?,
val drivingSide: String?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ class RouteOptionsNavigation(
}
}

val coordinates: List<Point>
get() = listOf(origin.point) + waypoints.map { it.point } + destination.point

class Builder internal constructor() {
private lateinit var _origin: RoutePointNavigation
private lateinit var _destination: RoutePointNavigation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,7 @@ class StepIntersectionNavigation(
val into: Int?,
val out: Int?,
val lanes: List<IntersectionLanesNavigation>?
)
) {
val rawLocation: DoubleArray
get() = doubleArrayOf(location.longitude(), location.latitude())
}
Original file line number Diff line number Diff line change
Expand Up @@ -200,4 +200,7 @@ class StepManeuverNavigation(
EXIT_ROTARY
)
annotation class StepManeuverTypeNavigation

val rawLocation: DoubleArray
get() = doubleArrayOf(location.longitude(), location.latitude())
}