Skip to main content

TileStore

TileStore manages downloads and storage for requests to tile-related API endpoints, enforcing a disk usage quota. Tiles available on disk may be deleted to make room for new downloads. This interface can be used by app developers to set the disk quota and configure tile storage options.

Import

import { TileStore } from '@rnmapbox/maps';

Basic Usage

import { TileStore } from '@rnmapbox/maps';

// Get the default tile store
const tileStore = await TileStore.shared();

// Or create/get a tile store at a specific path
const customTileStore = await TileStore.shared('/path/to/tiles');

// Configure tile store options
await tileStore.setOption('disk-quota', 'Maps', 500 * 1024 * 1024); // 500MB

Static Methods

shared()

static shared(path?: string): Promise<TileStore>
Creates or retrieves a TileStore instance for the given storage path. The returned instance exists as long as it is retained by the client. If a tile store instance already exists for the given path, this method will return it without creating a new instance, ensuring there is only one tile store instance for a path at a time. If the given path is empty, the tile store at the default location is returned.
path
string
The path on disk where tiles and metadata will be stored. If not provided, uses the default location.Platform Notes:
  • iOS: This storage path is automatically excluded from cloud backup
  • Android: You should exclude the storage path in your Manifest. See Android Auto Backup documentation
Returns: Promise that resolves to a TileStore instance. Example:
// Default tile store
const defaultStore = await TileStore.shared();

// Custom path tile store
const customStore = await TileStore.shared('/custom/tile/path');

Instance Methods

setOption()

setOption(
  key: string,
  domain: TileDataDomain,
  value: string | number
): Promise<void>
Sets additional options for this instance that are specific to a data type.
key
string
required
The configuration option that should be changed. Valid keys are listed in TileStoreOptions.Common options:
  • 'disk-quota' - Maximum disk space for tiles (in bytes)
domain
TileDataDomain
required
The data type this setting should be applied for.Valid values:
  • 'Maps'
  • 'Navigation'
  • 'Search'
  • 'ADAS'
value
string | number
required
The value for the configuration option, or null if it should be reset.
Example:
const tileStore = await TileStore.shared();

// Set disk quota to 500MB for Maps
await tileStore.setOption('disk-quota', 'Maps', 500 * 1024 * 1024);

// Set disk quota for Navigation
await tileStore.setOption('disk-quota', 'Navigation', 1024 * 1024 * 1024); // 1GB

Types

TileDataDomain

type TileDataDomain = 'Maps' | 'Navigation' | 'Search' | 'ADAS';
Represents the type of data the tile store manages.

TileDataValue

type TileDataValue = string | number;
The value type for tile store options.

Examples

import { TileStore } from '@rnmapbox/maps';

async function setDiskQuota() {
  const tileStore = await TileStore.shared();
  
  // Set 500MB quota for Maps
  await tileStore.setOption(
    'disk-quota',
    'Maps',
    500 * 1024 * 1024
  );
  
  console.log('Disk quota set to 500MB');
}

Best Practices

  1. Set Appropriate Quotas: Consider your app’s needs and device storage when setting disk quotas
  2. Use Default Store: Unless you have specific requirements, use the default tile store
  3. Platform Considerations: Remember to configure Android Manifest for backup exclusion
  4. Monitor Usage: Regularly check and adjust quotas based on actual usage patterns

Platform-Specific Notes

iOS

  • The tile store path is automatically excluded from iCloud backup
  • No additional configuration needed

Android

  • You should exclude the tile store path in your AndroidManifest.xml
  • Add the path to your backup rules to prevent automatic cloud backup
  • See Android Auto Backup documentation

Build docs developers (and LLMs) love