Package com.mapbox.mapboxsdk.offline

Contains the Mapbox Maps Android Offline API classes.

Types

Name Summary
OfflineGeometryRegionDefinition
open class OfflineGeometryRegionDefinition : OfflineRegionDefinition
An offline region defined by a style URL, geometry, zoom range, and device pixel ratio.
OfflineManager
@UiThread()
open class OfflineManager
The offline manager is the main entry point for offline-related functionality.
OfflineRegion
open class OfflineRegion
An offline region is the basic building block for offline mobile maps.
OfflineRegionDefinition
interface OfflineRegionDefinition : Parcelable
This is the interface that all Offline Region definitions have to implement.
OfflineRegionError
open class OfflineRegionError
An Offline Region error
OfflineRegionStatus
open class OfflineRegionStatus
A region’s status includes its active/inactive state as well as counts of the number of resources that have completed downloading, their total size in bytes, and the total number of resources that are required.
OfflineTilePyramidRegionDefinition
open class OfflineTilePyramidRegionDefinition : OfflineRegionDefinition
An offline region defined by a style URL, geographic bounding box, zoom range, and device pixel ratio.

OfflineGeometryRegionDefinition

open class OfflineGeometryRegionDefinition : OfflineRegionDefinition

An offline region defined by a style URL, geometry, zoom range, and device pixel ratio.

Both minZoom and maxZoom must be ≥ 0, and maxZoom must be ≥ minZoom.

maxZoom may be ∞, in which case for each tile source, the region will include tiles from minZoom up to the maximum zoom level provided by that source.

pixelRatio must be ≥ 0 and should typically be 1.0 or 2.0.

if includeIdeographs is false, offline region will not include CJK glyphs

Constructors

Name Summary
OfflineGeometryRegionDefinition open fun OfflineGeometryRegionDefinition(styleURL: String, geometry: Geometry, minZoom: Double, maxZoom: Double, pixelRatio: Float)Constructor to create an OfflineGeometryRegionDefinition from parameters.
OfflineGeometryRegionDefinition open fun OfflineGeometryRegionDefinition(styleURL: String, geometry: Geometry, minZoom: Double, maxZoom: Double, pixelRatio: Float, includeIdeographs: Boolean)Constructor to create an OfflineGeometryRegionDefinition from parameters.
OfflineGeometryRegionDefinition open fun OfflineGeometryRegionDefinition(parcel: Parcel)Constructor to create an OfflineGeometryRegionDefinition from a Parcel.

Functions

Name Summary
describeContents
abstract fun describeContents(): Int
open fun describeContents(): Int
getBounds
@Nullable()
open fun getBounds(): LatLngBounds
Calculates the bounding box for the Geometry it containsto retain backwards compatibility
getType
@NonNull()
open fun getType(): String
Gets the type of the OfflineRegionDefinition (“tileregion”, “shaperegion”).
writeToParcel
abstract fun writeToParcel(p: Parcel, p1: Int)
open fun writeToParcel(dest: Parcel, flags: Int)

Properties

Name Summary
CREATOR val CREATOR: Parcelable.Creator
geometry @Nullable()
private open val geometry: Geometry
includeIdeographs private open val includeIdeographs: Boolean
maxZoom private open val maxZoom: Double
minZoom private open val minZoom: Double
pixelRatio private open val pixelRatio: Float
styleURL private open val styleURL: String

CREATOR

val CREATOR: Parcelable.Creator

describeContents

open fun describeContents(): Int

geometry

@Nullable()

private open val geometry: Geometry

getBounds

@Nullable()

open fun getBounds(): LatLngBounds

Calculates the bounding box for the Geometry it containsto retain backwards compatibility

Return

the LatLngBounds or null

getType

@NonNull()

open fun getType(): String

Gets the type of the OfflineRegionDefinition (“tileregion”, “shaperegion”).

Return

The type of the OfflineRegionDefinition.

includeIdeographs

private open val includeIdeographs: Boolean

maxZoom

private open val maxZoom: Double

minZoom

private open val minZoom: Double

pixelRatio

private open val pixelRatio: Float

styleURL

private open val styleURL: String

writeToParcel

open fun writeToParcel(dest: Parcel, flags: Int)

OfflineManager

@UiThread()

open class OfflineManager

The offline manager is the main entry point for offline-related functionality.

It’ll help you list and create offline regions.

See also

Name Summary
Offline Maps Information/
Offline Maps Information/
   

Types

Name Summary
CreateOfflineRegionCallback
interface CreateOfflineRegionCallback
This callback receives an asynchronous response containing the newly createdOfflineRegion in the database or an error message otherwise.
FileSourceCallback
interface FileSourceCallback
This callback receives an asynchronous response indicating if an operation has succeeded or failed.
ListOfflineRegionsCallback
interface ListOfflineRegionsCallback
This callback receives an asynchronous response containing a list of allOfflineRegion in the database or an error message otherwise.
MergeOfflineRegionsCallback
interface MergeOfflineRegionsCallback
This callback receives an asynchronous response containing a list of allOfflineRegion added to the database during the merge.

Functions

Name Summary
clearAmbientCache
open fun clearAmbientCache(callback: OfflineManager.FileSourceCallback)
Erase resources from the ambient cache, freeing storage space.
createOfflineRegion
open fun createOfflineRegion(definition: OfflineRegionDefinition, metadata: Array, callback: [OfflineManager.CreateOfflineRegionCallback](#offlinemanager.createofflineregioncallback))
Creates an offline region in the database by downloading the resources needed to usethe given region offline.
invalidateAmbientCache
open fun invalidateAmbientCache(callback: OfflineManager.FileSourceCallback)
Forces re-validation of the ambient cache.
listOfflineRegions
open fun listOfflineRegions(callback: OfflineManager.ListOfflineRegionsCallback)
Retrieve all regions in the offline database.
mergeOfflineRegions
open fun mergeOfflineRegions(path: String, callback: OfflineManager.MergeOfflineRegionsCallback)
Merge offline regions from a secondary database into the main offline database.
packDatabase
open fun packDatabase(callback: OfflineManager.FileSourceCallback)
Packs the existing database file into a minimal amount of disk space.
putResourceWithUrl
open fun putResourceWithUrl(url: String, data: Array, modified: Long, expires: Long, etag: String, mustRevalidate: Boolean)
Insert the provided resource into the ambient cacheThis method mimics the caching that would take place if the equivalentresource were requested in the process of map rendering.Use this method to pre-warm the cache with resources you knowwill be requested.
resetDatabase
open fun resetDatabase(callback: OfflineManager.FileSourceCallback)
Delete existing database and re-initialize.
runPackDatabaseAutomatically
open fun runPackDatabaseAutomatically(autopack: Boolean)
Sets whether database file packing occurs automatically.By default, the automatic database file packing is enabled.
setMaximumAmbientCacheSize
open fun setMaximumAmbientCacheSize(size: Long, callback: OfflineManager.FileSourceCallback)
Sets the maximum size in bytes for the ambient cache.
setOfflineMapboxTileCountLimit
open fun setOfflineMapboxTileCountLimit(limit: Long)
Sets the maximum number of Mapbox-hosted tiles that may be downloaded and stored on the current device.By default, the limit is set to 6,000.

Properties

Name Summary
instance private open var instance: OfflineManager

clearAmbientCache

open fun clearAmbientCache(callback: OfflineManager.FileSourceCallback)

Erase resources from the ambient cache, freeing storage space.

Erases the ambient cache, freeing resources.Note that this operation can be potentially slow if packing the databaseoccurs automatically (runPackDatabaseAutomatically).

Resources overlapping with offline regions will not be affectedby this call.

Parameters
Name Summary
callback
the callback to be invoked when the ambient cache was cleared or when the operation erred.
   
   

createOfflineRegion

open fun createOfflineRegion(definition: OfflineRegionDefinition, metadata: Array, callback: [OfflineManager.CreateOfflineRegionCallback](#offlinemanager.createofflineregioncallback))

Creates an offline region in the database by downloading the resources needed to usethe given region offline.

As of version 8.3.0 of the Maps SDK for Android, offline tile requests are no longer exempt frombilling on mobile. Developers are subject to separate Vector Tile or Raster Tile API pricing foroffline use. See our pricing page for more information.

When the initial database queries have completed, the provided callback will beexecuted on the main thread.

Note that the resulting region will be in an inactive download state; to begindownloading resources, call OfflineRegion.setDownloadState(DownloadState.STATE_ACTIVE),optionally registering an OfflineRegionObserver beforehand.

Parameters
Name Summary
definition
the offline region definition
metadata
the metadata in bytes
callback
the callback to be invoked
   
   

instance

private open var instance: OfflineManager

invalidateAmbientCache

open fun invalidateAmbientCache(callback: OfflineManager.FileSourceCallback)

Forces re-validation of the ambient cache.

Forces Mapbox GL Native to revalidate resources stored in the ambientcache with the tile server before using them, making sure theyare the latest version. This is more efficient than cleaning thecache because if the resource is considered valid after the serverlookup, it will not get downloaded again.

Resources overlapping with offline regions will not be affectedby this call.

Parameters
Name Summary
callback
the callback to be invoked when the ambient cache was invalidated or when the operation erred.
   
   

listOfflineRegions

open fun listOfflineRegions(callback: OfflineManager.ListOfflineRegionsCallback)

Retrieve all regions in the offline database.

The query will be executed asynchronously and the results passed to the givencallback on the main thread.

Parameters
Name Summary
callback
the callback to be invoked
   
   

mergeOfflineRegions

open fun mergeOfflineRegions(path: String, callback: OfflineManager.MergeOfflineRegionsCallback)

Merge offline regions from a secondary database into the main offline database.

When the merge is completed, or fails, the MergeOfflineRegionsCallback will be invoked on the main thread.The callback reference is strongly kept throughout the process,so it needs to be wrapped in a weak reference or released on the client side if necessary.

The secondary database may need to be upgraded to the latest schema.This is done in-place and requires write-access to the provided path.If the app’s process doesn’t have write-access to the provided path,the file will be copied to the temporary, internal directory for the duration of the merge.

Only resources and tiles that belong to a region will be copied over. Identicalregions will be flattened into a single new region in the main database.

The operation will be aborted and onError with an appropriate messagewill be invoked if the merge would result in the offline tile count limit being exceeded.

Merged regions may not be in a completed status if the secondary databasedoes not contain all the tiles or resources required by the region definition.

Parameters
Name Summary
path
secondary database writable path
callback
completion/error callback
   
   

packDatabase

open fun packDatabase(callback: OfflineManager.FileSourceCallback)

Packs the existing database file into a minimal amount of disk space.

This operation has a performance impact as it will vacuum the database,forcing it to move pages on the filesystem.

When the operation is complete or encounters an error, the given callback will beexecuted on the database thread; it is the responsibility of the SDK bindingsto re-execute a user-provided callback on the main thread.

Parameters
Name Summary
callback
the callback to be invoked when the database was reset or when the operation erred.
   
   

putResourceWithUrl

open fun putResourceWithUrl(url: String, data: Array, modified: Long, expires: Long, etag: String, mustRevalidate: Boolean)

Insert the provided resource into the ambient cacheThis method mimics the caching that would take place if the equivalentresource were requested in the process of map rendering.Use this method to pre-warm the cache with resources you knowwill be requested.

This call is asynchronous: the data may not be immediately availablefor in-progress requests, although subsequent requests should haveaccess to the cached data.

Parameters
Name Summary
url
The URL of the resource to insert
data
Response data to store for this resource. Data is expected to be uncompressed;internally, the cache will compress data as necessary.
modified
Optional “modified” response header, in seconds since 1970, or 0 if not set
expires
Optional “expires” response header, in seconds since 1970, or 0 if not set
etag
Optional “entity tag” response header
mustRevalidate
Indicates whether response can be used after it’s stale
   
   

resetDatabase

open fun resetDatabase(callback: OfflineManager.FileSourceCallback)

Delete existing database and re-initialize.

When the operation is complete or encounters an error, the given callback will beexecuted on the database thread; it is the responsibility of the SDK bindingsto re-execute a user-provided callback on the main thread.

Parameters
Name Summary
callback
the callback to be invoked when the database was reset or when the operation erred.
   
   

runPackDatabaseAutomatically

open fun runPackDatabaseAutomatically(autopack: Boolean)

Sets whether database file packing occurs automatically.By default, the automatic database file packing is enabled.

If packing is enabled, database file packing occurs automaticallyafter an offline region is deleted by calling delete or the ambient cache is cleared by calling clearAmbientCache.If packing is disabled, disk space will not be freed afterresources are removed unless packDatabase is explicitly called.

Parameters
Name Summary
autopack
flag setting the automatic database file packing.
   
   

setMaximumAmbientCacheSize

open fun setMaximumAmbientCacheSize(size: Long, callback: OfflineManager.FileSourceCallback)

Sets the maximum size in bytes for the ambient cache.

This call is potentially expensive because it will tryto trim the data in case the database is larger than thesize defined. The size of offline regions are not affectedby this settings, but the ambient cache will always tryto not exceed the maximum size defined, taking into accountthe current size for the offline regions.

Note that if you use the SDK’s offline functionality, your ability to set the ambient cache size will be limited.Space that offline regions take up detract from the space available for ambient caching, and the ambient cachesize does not block offline downloads. For example: if the maximum cache size is set to 50 MB and 40 MB arealready used by offline regions, the ambient cache size will effectively be 10 MB.

Setting the size to 0 will disable the cache if there is nooffline region on the database.

<[

This method should always be called at the start of an app, before setting the style and loading a map.Otherwise, the map will instantiate with the default cache size of 50 MB.

Parameters
Name Summary
size
the maximum size of the ambient cache
callback
the callback to be invoked when the the maximum size has been set or when the operation erred.
   
   

setOfflineMapboxTileCountLimit

open fun setOfflineMapboxTileCountLimit(limit: Long)

Sets the maximum number of Mapbox-hosted tiles that may be downloaded and stored on the current device.By default, the limit is set to 6,000.

Once this limit is reached, mapboxTileCountLimitExceeded fires every additional attempt to download additional tiles until already downloaded tiles are removedby calling delete.

Parameters
Name Summary
limit
the maximum number of tiles allowed to be downloaded
   
   

CreateOfflineRegionCallback

interface CreateOfflineRegionCallback

This callback receives an asynchronous response containing the newly createdOfflineRegion in the database or an error message otherwise.

Functions

Name Summary
onCreate
abstract fun onCreate(offlineRegion: OfflineRegion)
Receives the newly created offline region.
onError
abstract fun onError(error: String)
Receives the error message.

onCreate

abstract fun onCreate(offlineRegion: OfflineRegion)

Receives the newly created offline region.

Parameters
Name Summary
offlineRegion
the offline region to create
   
   

onError

abstract fun onError(error: String)

Receives the error message.

Parameters
Name Summary
error
the error message to be shown
   
   

FileSourceCallback

interface FileSourceCallback

This callback receives an asynchronous response indicating if an operation has succeeded or failed.

Functions

Name Summary
onError
abstract fun onError(message: String)
Receives an error message if an operation was not successful
onSuccess
abstract fun onSuccess()
Receives the success of an operation

onError

abstract fun onError(message: String)

Receives an error message if an operation was not successful

Parameters
Name Summary
message
the error message
   
   

onSuccess

abstract fun onSuccess()

Receives the success of an operation

ListOfflineRegionsCallback

interface ListOfflineRegionsCallback

This callback receives an asynchronous response containing a list of allOfflineRegion in the database or an error message otherwise.

Functions

Name Summary
onError
abstract fun onError(error: String)
Receives the error message.
onList
abstract fun onList(offlineRegions: Array<OfflineRegion>)
Receives the list of offline regions.

onError

abstract fun onError(error: String)

Receives the error message.

Parameters
Name Summary
error
the error message
   
   

onList

abstract fun onList(offlineRegions: Array<OfflineRegion>)

Receives the list of offline regions.

Parameters
Name Summary
offlineRegions
the offline region array
   
   

MergeOfflineRegionsCallback

interface MergeOfflineRegionsCallback

This callback receives an asynchronous response containing a list of allOfflineRegion added to the database during the merge.

Functions

Name Summary
onError
abstract fun onError(error: String)
Receives the error message.
onMerge
abstract fun onMerge(offlineRegions: Array<OfflineRegion>)
Receives the list of merged offline regions.

onError

abstract fun onError(error: String)

Receives the error message.

Parameters
Name Summary
error
the error message
   
   

onMerge

abstract fun onMerge(offlineRegions: Array<OfflineRegion>)

Receives the list of merged offline regions.

Parameters
Name Summary
offlineRegions
the offline region array
   
   

OfflineRegion

open class OfflineRegion

An offline region is the basic building block for offline mobile maps. Use com.mapbox.mapboxsdk.offline.OfflineManager.CreateOfflineRegionCallback to create a new offline region.

Types

Name Summary
DownloadState
@Retention(value = RetentionPolicy.SOURCE)
annotation class DownloadState
A region is either inactive (not downloading, but previously-downloadedresources are available for use), or active (resources are being downloadedor will be downloaded, if necessary, when network access is available).
OfflineRegionDeleteCallback
interface OfflineRegionDeleteCallback
This callback receives an asynchronous response containing a notification whenan offline region has been deleted, or a String error message otherwise.
OfflineRegionInvalidateCallback
interface OfflineRegionInvalidateCallback
This callback receives an asynchronous response containing a notification whenan offline region has been invalidated, or a String error message otherwise.
OfflineRegionObserver
interface OfflineRegionObserver
A region can have a single observer, which gets notified whenever a changeto the region’s status occurs.
OfflineRegionStatusCallback
interface OfflineRegionStatusCallback
This callback receives an asynchronous response containing the OfflineRegionStatusof the offline region, or a String error message otherwise.
OfflineRegionUpdateMetadataCallback
interface OfflineRegionUpdateMetadataCallback
This callback receives an asynchronous response containing the newly updateOfflineMetadata in the database, or an error message otherwise.

Functions

Name Summary
delete
open fun delete(callback: OfflineRegion.OfflineRegionDeleteCallback)
Remove an offline region from the database and perform any resources evictionsnecessary as a result.
getStatus
open fun getStatus(callback: OfflineRegion.OfflineRegionStatusCallback)
Retrieve the current status of the region.
invalidate
open fun invalidate(callback: OfflineRegion.OfflineRegionInvalidateCallback)
Invalidate all the tiles from an offline region forcing Mapbox GL to revalidatethe tiles with the server before using.
isDeliveringInactiveMessages
open fun isDeliveringInactiveMessages(): Boolean
Gets whether or not the OfflineRegionObserver will continue to deliver messages even ifthe region state has been set as STATE_INACTIVE.
setDownloadState
open fun setDownloadState(state: Int)
Pause or resume downloading of regional resources.
setObserver
open fun setObserver(observer: OfflineRegion.OfflineRegionObserver)
Register an observer to be notified when the state of the region changes.
updateMetadata
open fun updateMetadata(bytes: Array, callback: [OfflineRegion.OfflineRegionUpdateMetadataCallback](#offlineregion.offlineregionupdatemetadatacallback))
Update an offline region metadata from the database.

Properties

Name Summary
definition private open val definition: OfflineRegionDefinition
deliverInactiveMessages private open var deliverInactiveMessages: Boolean
id private open val id: Long
metadata private open val metadata: ArrayArbitrary binary region metadata.
STATE_ACTIVE val STATE_ACTIVE: Int
STATE_INACTIVE val STATE_INACTIVE: Int

STATE_ACTIVE

val STATE_ACTIVE: Int

STATE_INACTIVE

val STATE_INACTIVE: Int

definition

private open val definition: OfflineRegionDefinition

delete

open fun delete(callback: OfflineRegion.OfflineRegionDeleteCallback)

Remove an offline region from the database and perform any resources evictionsnecessary as a result.

Eviction works by removing the least-recently requested resources not also requiredby other regions, until the database shrinks below a certain size.

When the operation is complete or encounters an error, the given callback will beexecuted on the main thread.

Note that this operation can be potentially slow if packing the databaseoccurs automatically (runPackDatabaseAutomatically)

After you call this method, you may not call any additional methods on this object.

Parameters
Name Summary
callback
the callback to be invoked
   
   

deliverInactiveMessages

private open var deliverInactiveMessages: Boolean

getStatus

open fun getStatus(callback: OfflineRegion.OfflineRegionStatusCallback)

Retrieve the current status of the region. The query will be executedasynchronously and the results passed to the given callback which will beexecuted on the main thread.

Parameters
Name Summary
callback
the callback to invoked.
   
   

id

private open val id: Long

invalidate

open fun invalidate(callback: OfflineRegion.OfflineRegionInvalidateCallback)

Invalidate all the tiles from an offline region forcing Mapbox GL to revalidatethe tiles with the server before using. This is more efficient than deleting theoffline region and downloading it again because if the data on the cache matchesthe server, no new data gets transmitted.

Parameters
Name Summary
callback
the callback to be invoked
   
   

isDeliveringInactiveMessages

open fun isDeliveringInactiveMessages(): Boolean

Gets whether or not the OfflineRegionObserver will continue to deliver messages even ifthe region state has been set as STATE_INACTIVE.

Return

true if delivering inactive messages

metadata

private open val metadata: Array

Arbitrary binary region metadata. The contents are opaque to the SDK implementation;it just stores and retrieves a byte[]. Check the OfflineActivity in the TestAppfor a sample implementation that uses JSON to store an offline region name.

setDownloadState

open fun setDownloadState(state: Int)

Pause or resume downloading of regional resources.

After a download has been completed, you are required to reset the state of the region to STATE_INACTIVE.

Parameters
Name Summary
state
the download state
   
   

setObserver

open fun setObserver(observer: OfflineRegion.OfflineRegionObserver)

Register an observer to be notified when the state of the region changes.

Parameters
Name Summary
observer
the observer to be notified
   
   

updateMetadata

open fun updateMetadata(bytes: Array, callback: [OfflineRegion.OfflineRegionUpdateMetadataCallback](#offlineregion.offlineregionupdatemetadatacallback))

Update an offline region metadata from the database.

When the operation is complete or encounters an error, the given callback will beexecuted on the main thread.

Parameters
Name Summary
bytes
the metadata in bytes
callback
the callback to be invoked
   
   

DownloadState

@Retention(value = RetentionPolicy.SOURCE)

annotation class DownloadState

A region is either inactive (not downloading, but previously-downloadedresources are available for use), or active (resources are being downloadedor will be downloaded, if necessary, when network access is available).

This state is independent of whether or not the complete set of resourcesis currently available for offline use. To check if that is the case, useOfflineRegionStatus.isComplete().

Functions

Name Summary
annotationType
abstract fun annotationType(): Class
equals
abstract fun equals(p: Any): Boolean
hashCode
abstract fun hashCode(): Int
toString
abstract fun toString(): String

OfflineRegionDeleteCallback

interface OfflineRegionDeleteCallback

This callback receives an asynchronous response containing a notification whenan offline region has been deleted, or a String error message otherwise.

Functions

Name Summary
onDelete
abstract fun onDelete()
Receives the delete notification
onError
abstract fun onError(error: String)
Receives the error message

onDelete

abstract fun onDelete()

Receives the delete notification

onError

abstract fun onError(error: String)

Receives the error message

Parameters
Name Summary
error
the error message
   
   

OfflineRegionInvalidateCallback

interface OfflineRegionInvalidateCallback

This callback receives an asynchronous response containing a notification whenan offline region has been invalidated, or a String error message otherwise.

Functions

Name Summary
onError
abstract fun onError(error: String)
Receives the error message
onInvalidate
abstract fun onInvalidate()
Receives the invalidate notification

onError

abstract fun onError(error: String)

Receives the error message

Parameters
Name Summary
error
the error message
   
   

onInvalidate

abstract fun onInvalidate()

Receives the invalidate notification

OfflineRegionObserver

interface OfflineRegionObserver

A region can have a single observer, which gets notified whenever a changeto the region’s status occurs.

Functions

Name Summary
mapboxTileCountLimitExceeded
abstract fun mapboxTileCountLimitExceeded(limit: Long)
onError
abstract fun onError(error: OfflineRegionError)
Implement this method to be notified of errors encountered while downloadingregional resources.
onStatusChanged
abstract fun onStatusChanged(status: OfflineRegionStatus)
Implement this method to be notified of a change in the status of anoffline region.

mapboxTileCountLimitExceeded

abstract fun mapboxTileCountLimitExceeded(limit: Long)

onError

abstract fun onError(error: OfflineRegionError)

Implement this method to be notified of errors encountered while downloadingregional resources. Such errors may be recoverable; for example the implementationwill attempt to re-request failed resources based on an exponential backoffalgorithm, or when it detects that network access has been restored.

This method will be executed on the main thread.

Parameters
Name Summary
error
the offline region error message
   
   

onStatusChanged

abstract fun onStatusChanged(status: OfflineRegionStatus)

Implement this method to be notified of a change in the status of anoffline region. Status changes include any change in state of the membersof OfflineRegionStatus.

This method will be executed on the main thread.

Parameters
Name Summary
status
the changed status
   
   

OfflineRegionStatusCallback

interface OfflineRegionStatusCallback

This callback receives an asynchronous response containing the OfflineRegionStatusof the offline region, or a String error message otherwise.

Functions

Name Summary
onError
abstract fun onError(error: String)
Receives the error message
onStatus
abstract fun onStatus(status: OfflineRegionStatus)
Receives the status

onError

abstract fun onError(error: String)

Receives the error message

Parameters
Name Summary
error
the error message
   
   

onStatus

abstract fun onStatus(status: OfflineRegionStatus)

Receives the status

Parameters
Name Summary
status
the offline region status
   
   

OfflineRegionUpdateMetadataCallback

interface OfflineRegionUpdateMetadataCallback

This callback receives an asynchronous response containing the newly updateOfflineMetadata in the database, or an error message otherwise.

Functions

Name Summary
onError
abstract fun onError(error: String)
Receives the error message.
onUpdate
abstract fun onUpdate(metadata: Array)
Receives the newly update offline region metadata.

onError

abstract fun onError(error: String)

Receives the error message.

Parameters
Name Summary
error
the error message to be shown
   
   

onUpdate

abstract fun onUpdate(metadata: Array)

Receives the newly update offline region metadata.

Parameters
Name Summary
metadata
the offline metadata to u[date
   
   

OfflineRegionDefinition

interface OfflineRegionDefinition : Parcelable

This is the interface that all Offline Region definitions have to implement.

For the present, a tile pyramid is the only type of offline region.

Functions

Name Summary
describeContents
abstract fun describeContents(): Int
getBounds
abstract fun getBounds(): LatLngBounds
Gets the bounds of the OfflineRegion.
getIncludeIdeographs
abstract fun getIncludeIdeographs(): Boolean
Specifies whether to include ideographic glyphs in downloaded font data.Ideographic glyphs make up the majority of downloaded font data, butit is possible to configure the renderer to use locally installed fontsinstead of relying on fonts downloaded as part of the offline pack.
getMaxZoom
abstract fun getMaxZoom(): Double
Gets the maximum zoom level the OfflineRegion map can be displayed at.
getMinZoom
abstract fun getMinZoom(): Double
Gets the minimum zoom level the OfflineRegion map can be displayed at.
getPixelRatio
abstract fun getPixelRatio(): Float
Gets the pixel ratio of the OfflineRegion map.
getStyleURL
abstract fun getStyleURL(): String
Returns the map style url of the OfflineRegion.
getType
abstract fun getType(): String
Gets the type of the OfflineRegionDefinition (“tileregion”, “shaperegion”).
writeToParcel
abstract fun writeToParcel(p: Parcel, p1: Int)

Inheritors

Name
OfflineGeometryRegionDefinition
OfflineTilePyramidRegionDefinition

getBounds

abstract fun getBounds(): LatLngBounds

Gets the bounds of the OfflineRegion.

Return

the bounds of the OfflineRegion.

getIncludeIdeographs

abstract fun getIncludeIdeographs(): Boolean

Specifies whether to include ideographic glyphs in downloaded font data.Ideographic glyphs make up the majority of downloaded font data, butit is possible to configure the renderer to use locally installed fontsinstead of relying on fonts downloaded as part of the offline pack.Defaults to true

Return

true if offline region will include ideographic glyphs

See also

Name Summary
com.mapbox.mapboxsdk.maps.MapboxMapOptions
MapboxMapOptions#localIdeographFontFamily(String)
   
   

getMaxZoom

abstract fun getMaxZoom(): Double

Gets the maximum zoom level the OfflineRegion map can be displayed at.

Return

The maximum zoom level.

getMinZoom

abstract fun getMinZoom(): Double

Gets the minimum zoom level the OfflineRegion map can be displayed at.

Return

The minimum zoom level.

getPixelRatio

abstract fun getPixelRatio(): Float

Gets the pixel ratio of the OfflineRegion map.

Return

The pixel ratio of the OfflineRegion map.

getStyleURL

abstract fun getStyleURL(): String

Returns the map style url of the OfflineRegion.

Return

The URL of the map style.

getType

abstract fun getType(): String

Gets the type of the OfflineRegionDefinition (“tileregion”, “shaperegion”).

Return

The type of the OfflineRegionDefinition.

OfflineRegionError

open class OfflineRegionError

An Offline Region error

Types

Name Summary
ErrorReason
@Retention(value = RetentionPolicy.SOURCE)
annotation class ErrorReason
Error code, as a string, self-explanatory.

Functions

Name Summary
equals
open fun equals(o: Any): Boolean
hashCode
open fun hashCode(): Int
toString
open fun toString(): String

Properties

Name Summary
message @NonNull()
private val message: String/* An error message from the request handler, e.g.
reason @NonNull()
private val reason: String
REASON_CONNECTION val REASON_CONNECTION: String
REASON_NOT_FOUND val REASON_NOT_FOUND: String
REASON_OTHER val REASON_OTHER: String
REASON_SERVER val REASON_SERVER: String
REASON_SUCCESS val REASON_SUCCESS: String

REASON_CONNECTION

val REASON_CONNECTION: String

REASON_NOT_FOUND

val REASON_NOT_FOUND: String

REASON_OTHER

val REASON_OTHER: String

REASON_SERVER

val REASON_SERVER: String

REASON_SUCCESS

val REASON_SUCCESS: String

equals

open fun equals(o: Any): Boolean

hashCode

open fun hashCode(): Int

message

@NonNull()

private val message: String

/An error message from the request handler, e.g. a server message or a system message/ informing the user about the reason for the failure.

reason

@NonNull()

private val reason: String

toString

open fun toString(): String

ErrorReason

@Retention(value = RetentionPolicy.SOURCE)

annotation class ErrorReason

Error code, as a string, self-explanatory.

Functions

Name Summary
annotationType
abstract fun annotationType(): Class
equals
abstract fun equals(p: Any): Boolean
hashCode
abstract fun hashCode(): Int
toString
abstract fun toString(): String

OfflineRegionStatus

open class OfflineRegionStatus

A region’s status includes its active/inactive state as well as counts of the number of resources that have completed downloading, their total size in bytes, and the total number of resources that are required.

Note that the total required size in bytes is not currently available. A future API release may provide an estimate of this number.

Functions

Name Summary
isComplete
open fun isComplete(): Boolean
Validates if the region download has completed
isRequiredResourceCountPrecise
open fun isRequiredResourceCountPrecise(): Boolean
Returns when the value of requiredResourceCount is a precisecount of the number of required resources, and false when it is merely a lowerbound.

Properties

Name Summary
completedResourceCount private val completedResourceCount: LongThe number of resources (inclusive of tiles) that have been fully downloadedand are ready for offline access.
completedResourceSize private val completedResourceSize: LongThe cumulative size, in bytes, of all resources (inclusive of tiles) that havebeen fully downloaded.
completedTileCount private val completedTileCount: LongThe number of tiles that have been fully downloaded and are ready foroffline access.
completedTileSize private val completedTileSize: LongThe cumulative size, in bytes, of all tiles that have been fully downloaded.
downloadState private open val downloadState: Int
requiredResourceCount private val requiredResourceCount: LongThe number of resources that are known to be required for this region.

completedResourceCount

private val completedResourceCount: Long

The number of resources (inclusive of tiles) that have been fully downloadedand are ready for offline access.

completedResourceSize

private val completedResourceSize: Long

The cumulative size, in bytes, of all resources (inclusive of tiles) that havebeen fully downloaded.

completedTileCount

private val completedTileCount: Long

The number of tiles that have been fully downloaded and are ready foroffline access.

completedTileSize

private val completedTileSize: Long

The cumulative size, in bytes, of all tiles that have been fully downloaded.

downloadState

private open val downloadState: Int

isComplete

open fun isComplete(): Boolean

Validates if the region download has completed

Return

true if download is complete, false if not

isRequiredResourceCountPrecise

open fun isRequiredResourceCountPrecise(): Boolean

Returns when the value of requiredResourceCount is a precisecount of the number of required resources, and false when it is merely a lowerbound.

Specifically, it is false during early phases of an offline download. Oncestyle and tile sources have been downloaded, it is possible to calculate theprecise number of required resources, at which point it is set to true.

Return

True if the required resource count is precise, false if not

requiredResourceCount

private val requiredResourceCount: Long

The number of resources that are known to be required for this region. See thedocumentation for requiredResourceCountIsPrecise for an important caveatabout this number.

OfflineTilePyramidRegionDefinition

open class OfflineTilePyramidRegionDefinition : OfflineRegionDefinition

An offline region defined by a style URL, geographic bounding box, zoom range, and device pixel ratio.

Both minZoom and maxZoom must be ≥ 0, and maxZoom must be ≥ minZoom.

maxZoom may be ∞, in which case for each tile source, the region will include tiles from minZoom up to the maximum zoom level provided by that source.

pixelRatio must be ≥ 0 and should typically be 1.0 or 2.0.

if includeIdeographs is false, offline region will not include CJK glyphs

Constructors

Name Summary
OfflineTilePyramidRegionDefinition open fun OfflineTilePyramidRegionDefinition(styleURL: String, bounds: LatLngBounds, minZoom: Double, maxZoom: Double, pixelRatio: Float)Constructor to create an OfflineTilePyramidDefinition from parameters.
OfflineTilePyramidRegionDefinition open fun OfflineTilePyramidRegionDefinition(styleURL: String, bounds: LatLngBounds, minZoom: Double, maxZoom: Double, pixelRatio: Float, includeIdeographs: Boolean)Constructor to create an OfflineTilePyramidDefinition from parameters.
OfflineTilePyramidRegionDefinition open fun OfflineTilePyramidRegionDefinition(parcel: Parcel)Constructor to create an OfflineTilePyramidDefinition from a Parcel.

Functions

Name Summary
describeContents
abstract fun describeContents(): Int
open fun describeContents(): Int
getType
@NonNull()
open fun getType(): String
Gets the type of the OfflineRegionDefinition (“tileregion”, “shaperegion”).
writeToParcel
abstract fun writeToParcel(p: Parcel, p1: Int)
open fun writeToParcel(dest: Parcel, flags: Int)

Properties

Name Summary
bounds private open val bounds: LatLngBounds
CREATOR val CREATOR: Parcelable.Creator
includeIdeographs private open val includeIdeographs: Boolean
maxZoom private open val maxZoom: Double
minZoom private open val minZoom: Double
pixelRatio private open val pixelRatio: Float
styleURL private open val styleURL: String

CREATOR

val CREATOR: Parcelable.Creator

bounds

private open val bounds: LatLngBounds

describeContents

open fun describeContents(): Int

getType

@NonNull()

open fun getType(): String

Gets the type of the OfflineRegionDefinition (“tileregion”, “shaperegion”).

Return

The type of the OfflineRegionDefinition.

includeIdeographs

private open val includeIdeographs: Boolean

maxZoom

private open val maxZoom: Double

minZoom

private open val minZoom: Double

pixelRatio

private open val pixelRatio: Float

styleURL

private open val styleURL: String

writeToParcel

open fun writeToParcel(dest: Parcel, flags: Int)