PredictiveCacheController

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 and search data.

In order to start caching map data, provide an instance via createStyleMapControllers. To specify styles to cache, pass a list of Mapbox style URIs via createStyleMapControllers. 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 createStyleMapControllers.

Also, note that MapboxNavigation instance should be created before PredictiveCacheController and the lifecycle of the MapboxNavigation instance should be longer than that of the PredictiveCacheController. Specifically, MapboxNavigation should not be destroyed before PredictiveCacheController.onDestroy is called.

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 MapboxMapsOptions.tileStore or use the Maps SDK's tile store path XML attribute.

Call onDestroy to cleanup all map, navigation and search 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.

Constructors

Link copied to clipboard
constructor(mapboxNavigation: MapboxNavigation, predictiveCacheOptions: PredictiveCacheOptions)

Constructs a new instance of the PredictiveCacheController using the provided MapboxNavigation and PredictiveCacheOptions.

constructor(predictiveCacheOptions: PredictiveCacheOptions)

Constructs a new instance of the PredictiveCacheController using the provided PredictiveCacheOptions. Throws IllegalStateException if MapboxNavigation was not instantiated before. Use PredictiveCacheController constructor which explicitly accepts MapboxNavigation instance.

Properties

Functions

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

Create Maps 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 for Maps data. Call this whenever the MapView is destroyed to avoid leaking references or downloading unnecessary resources.