@@ -18,16 +18,18 @@ import com.mapbox.navigation.base.internal.SDKRouteParser
18
18
import com.mapbox.navigation.base.internal.factory.RoadObjectFactory.toUpcomingRoadObjects
19
19
import com.mapbox.navigation.base.internal.route.RouteCompatibilityCache
20
20
import com.mapbox.navigation.base.internal.route.Waypoint
21
+ import com.mapbox.navigation.base.internal.route.toNavigationRoute
21
22
import com.mapbox.navigation.base.internal.utils.mapToSdkRouteOrigin
22
- import com.mapbox.navigation.base.trip.model.roadobject.UpcomingRoadObject
23
23
import com.mapbox.navigation.base.internal.utils.mapToSkd
24
+ import com.mapbox.navigation.base.trip.model.roadobject.UpcomingRoadObject
24
25
import com.mapbox.navigation.utils.internal.ThreadController
25
26
import com.mapbox.navigation.utils.internal.logD
26
27
import com.mapbox.navigation.utils.internal.logE
27
28
import com.mapbox.navigation.utils.internal.logI
28
29
import com.mapbox.navigator.RouteInterface
29
30
import kotlinx.coroutines.async
30
31
import kotlinx.coroutines.coroutineScope
32
+ import org.json.JSONArray
31
33
import java.net.URL
32
34
33
35
/* *
@@ -205,6 +207,34 @@ class NavigationRoute internal constructor(
205
207
}
206
208
}
207
209
210
+ internal fun create (
211
+ directionsRoutes : List <DirectionsRoute >,
212
+ routeOptions : RouteOptions ,
213
+ routerOrigin : RouterOrigin ,
214
+ routeParser : SDKRouteParser = NativeRouteParserWrapper
215
+ ): List <NavigationRoute > {
216
+ val directionsRoutesJson = JSONArray (directionsRoutes.map { it.toJson() }).toString()
217
+ return create(
218
+ directionsRoutesJson,
219
+ routeOptions.toUrl(" " ).toString(),
220
+ routerOrigin,
221
+ routeParser
222
+ )
223
+ }
224
+
225
+ private fun create (
226
+ directionsRoutesJson : String ,
227
+ routeOptionsUrlString : String ,
228
+ routerOrigin : RouterOrigin ,
229
+ routeParser : SDKRouteParser = NativeRouteParserWrapper
230
+ ): List <NavigationRoute > {
231
+ return routeParser.parseDirectionsRoutes(
232
+ directionsRoutesJson, routeOptionsUrlString, routerOrigin
233
+ ).run {
234
+ create(this )
235
+ }
236
+ }
237
+
208
238
internal fun create (
209
239
directionsResponse : DirectionsResponse ,
210
240
routeOptions : RouteOptions ,
@@ -255,6 +285,19 @@ class NavigationRoute internal constructor(
255
285
)
256
286
}.cache()
257
287
}
288
+
289
+ private fun create (
290
+ expected : Expected <String , List <RouteInterface >>
291
+ ): List <NavigationRoute > {
292
+ return expected.fold({ error ->
293
+ logE(" NavigationRoute" , " Failed to parse a route. Reason: $error " )
294
+ listOf ()
295
+ }, { value ->
296
+ value
297
+ }).map { routeInterface ->
298
+ routeInterface.toNavigationRoute()
299
+ }.cache()
300
+ }
258
301
}
259
302
260
303
/* *
0 commit comments