Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Offline maps

Keep map imagery and routing working without a network. The SDK’s offline story has two layers: a disk response cache that holds raster tile imagery under your byte budget, and a compiled routing archive that answers routes with no network round trip at all.

Register the providers with a tile cache

One registration call installs the map-platform provider set and wraps the raster-tile contract in the disk response cache. The reference application’s offline-maps demo runs exactly this:

val tileCacheDatabaseFile = File(context.cacheDir, "reference-tile-cache.sqlite")
val tileCacheBudgetBytes = 16777216UL   // 16 MiB, the demo's absolute budget

mapSdk.registerMapquestProvidersWithTileCache(
    mapQuestApiKey,
    tileCacheDatabaseFile.absolutePath,
    tileCacheBudgetBytes,
)

The call opens (or creates) the SQLite response cache at the path. A refusal (unusable path, non-positive budget) surfaces verbatim.

Read and tune the caching terms

The cache starts at the tiles category’s default time-to-live, 30 calendar days — the imagery-provider terms ceiling. Tune the live value and read what went into force:

mapSdk.setRasterTileCacheTimeToLive(timeToLiveSeconds)
val terms = mapSdk.rasterTileCacheTerms()
// terms.effectiveTimeToLiveSeconds
// terms.providerTermsCeilingSeconds
// terms.defaultTimeToLiveSeconds

A request above the provider’s declared ceiling is accepted, and the ceiling clamps what the cache retains; the readback shows the effective value, so display it in your offline-maps settings screen.

Pre-warm the tiles you need

Cached tile responses render whenever the network is unavailable: a cache miss goes to the network and back-fills, and a cache hit answers from disk. Render the regions your users expect to revisit once while online, and the cache holds them until the budget or time-to-live says otherwise.

Route without the network

The offline routing layer runs inside the SDK: a compiled routing archive — OpenStreetMap extract in, self-describing archive file out — answers routes with A* over a memory-mapped graph, honoring recorded turn restrictions and deriving maneuver text from the geometry’s bearing change.

The direct route call from foreign code joins the contract as an addition-only member in a later slice; today the offline layer answers the automatic fallback (the routing decorator retries over the offline graph when the online provider fails) and the WebAssembly surface’s offline route seam, and its maneuver texts stay honest where the extract carries no street names.

Register the providers with a tile cache

let tileCacheDatabasePath = FileManager.default
    .cachesDirectory.appendingPathComponent("reference-tile-cache.sqlite")
    .path
let tileCacheBudgetBytes: UInt64 = 16_777_216   // 16 MiB

try mapSdk.registerMapquestProvidersWithTileCache(
    mapQuestApiKey,
    tileCacheDatabasePath: tileCacheDatabasePath,
    tileCacheAbsoluteMaximumBytes: tileCacheBudgetBytes
)

Read and tune the caching terms

try mapSdk.setRasterTileCacheTimeToLive(timeToLiveSeconds)
let terms = try mapSdk.rasterTileCacheTerms()
// terms.effectiveTimeToLiveSeconds
// terms.providerTermsCeilingSeconds
// terms.defaultTimeToLiveSeconds

Pre-warm and render offline

Cached tiles render whenever the network is unavailable. Render the regions your users revisit while online; the cache answers from disk.

Route without the network

The offline routing layer runs inside the SDK over a compiled archive: A* on a memory-mapped graph, recorded turn restrictions honored, maneuver text derived from the geometry. The direct route call from Swift joins the contract as an addition-only member in a later slice; today the layer serves the automatic fallback when the online provider fails, and the WebAssembly surface’s offline route seam.

Register the providers with a tile cache

import { MapSdk } from '@angoratek/rustic-maps-sdk';

const mapSdk = new MapSdk();
await mapSdk.registerMapquestProvidersWithTileCache(
  mapQuestApiKey,
  tileCacheDatabasePath,   // a writable SQLite path your app owns
  16_777_216,              // the absolute byte budget (16 MiB)
);

Read and tune the caching terms

await mapSdk.setRasterTileCacheTimeToLive(timeToLiveSeconds);
const terms = await mapSdk.rasterTileCacheTerms();
// terms.effectiveTimeToLiveSeconds
// terms.providerTermsCeilingSeconds
// terms.defaultTimeToLiveSeconds

Show the effective terms in your offline-maps settings screen; a value above the provider’s ceiling is accepted and clamped, and the readback is what went into force.

Scope note

The wasm surface renders from the same-origin /tiles/ imagery path you host, and loads the offline routing archive from in-memory bytes; the SQLite tile cache is a native-platform surface (the provider registration seam has no wasm exposure yet).

Route over the archive

The Search and routing tutorial’s WebAssembly tab shows the full offline routing call: archive bytes in, contract-shaped route records out, no network. The same compiled archive serves the native platforms, so one compiler run feeds every target.