PredictiveCacheController

class PredictiveCacheController @JvmOverloads constructor(    predictiveCacheLocationOptions: PredictiveCacheLocationOptions = PredictiveCacheLocationOptions.Builder().build(),     predictiveCacheGuidanceLocationOptions: PredictiveCacheLocationOptions = PredictiveCacheLocationOptions.Builder().build(),     predictiveCacheControllerErrorHandler: PredictiveCacheControllerErrorHandler? = null)

Predictive caching is a system that downloads necessary visual map and guidance data resources along the route upfront, before they are needed, in an attempt to provide a smooth experience even when connectivity is lost while using the app.

Once instantiated, the controller will immediately start caching guidance data.

In order to start caching map data, provide an instance via createMapControllers. To specify sources to cache, pass a list of id's via createMapControllers. Source id's should look like "mapbox://mapbox.satellite", "mapbox://mapbox.mapbox-terrain-v2". The system only supports source hosted on Mapbox Services which URL starts with "mapbox://". If no ids are passed all available style sources will be cached.

The controller as well as MapboxNavigation instance it's holding can have a different lifecycle than the MapboxMap instance, so make sure to call removeMapControllers whenever the MapView is destroyed to avoid leaking references or downloading unnecessary resources. When the map instance is recreated, set it back with createMapControllers.

The map instance has to be configured with the same TileStore instance that was provided to RoutingTilesOptions.tileStore. You need to call TileStore.create with a path and pass it to ResourceOptions.tileStore or use the Maps SDK's tile store path XML attribute.

Call onDestroy to cleanup all map and navigation state related references. This can be called when navigation session finishes and predictive caching is not needed anymore.

  • When migrating please ensure you have cleaned up old navigation tiles cache folder to reclaim disk space. Navigation SDK 2.0 caches navigation tiles in a default folder under APP_FOLDER/mbx_nav/tiles/api.mapbox.com. Previous versions of Nav SDK used to cache tiles under a default folder APP_FOLDER/Offline/api.mapbox.com/$tilesVersion/tiles. Old cache is not compatible with a new version of SDK 2.0. It makes sense to delete any folders used previously for caching including a default one.

  • OnboardRouterOptions enabled you to specify a path where nav-tiles will be saved and if a custom directory was used, it should be cleared as well.

Parameters

predictiveCacheLocationOptions

PredictiveCacheLocationOptions location configuration for visual map predictive caching (optional)

predictiveCacheGuidanceLocationOptions

PredictiveCacheLocationOptions location configuration for guidance predictive caching (optional)

predictiveCacheControllerErrorHandler

Constructors

Link copied to clipboard
fun PredictiveCacheController(predictiveCacheLocationOptions: PredictiveCacheLocationOptions = PredictiveCacheLocationOptions.Builder().build(), predictiveCacheControllerErrorHandler: PredictiveCacheControllerErrorHandler? = null)

Predictive caching is a system that downloads necessary visual map and guidance data resources along the route upfront, before they are needed, in an attempt to provide a smooth experience even when connectivity is lost while using the app.

Link copied to clipboard
fun PredictiveCacheController(    predictiveCacheLocationOptions: PredictiveCacheLocationOptions = PredictiveCacheLocationOptions.Builder().build(),     predictiveCacheGuidanceLocationOptions: PredictiveCacheLocationOptions = PredictiveCacheLocationOptions.Builder().build(),     predictiveCacheControllerErrorHandler: PredictiveCacheControllerErrorHandler? = null)

Functions

Link copied to clipboard
fun createMapControllers(map: MapboxMap, sourceIdsToCache: List<String> = emptyList())

Create cache controllers for a map instance. Call when a new map instance is available.

Link copied to clipboard
fun createStyleMapControllers(    map: MapboxMap,     cacheCurrentMapStyle: Boolean = true,     styles: List<String> = emptyList())

Create cache controllers for a map instance. Call when a new map instance is available.

Link copied to clipboard
fun onDestroy()

Cleans up all map and navigation state related references. This can be called when navigation session finishes and predictive caching is not needed anymore.

Link copied to clipboard
fun removeMapControllers(map: MapboxMap)

Remove the map instance. Call this whenever the MapView is destroyed to avoid leaking references or downloading unnecessary resources.