Setting up the tile source

The map draws from one file: a PMTiles v3 archive of vector tiles (MVT, gzip-compressed or not). The engine reads it with HTTP range requests, so any static host serves it, and no tile server is needed.

The default

A bare ImmersiveMapView() draws the hosted archive, ImmersiveMapTilesService.tileArchiveURL: the whole planet from OpenStreetMap, credited “© OpenStreetMap” on the map.

Your own archive

ImmersiveMapView()
    .tileArchive(URL(string: "https://tiles.example.com/planet.pmtiles")!)
  • Schema. The built-in style reads tiles in the Protomaps basemap schema, the one the hosted archive uses. An archive in another schema needs a style and a schema of your own (see Custom style).
  • Keys. A query string is sent as written, so a key can live in the URL. Credentials sent as headers go in headers, which are added to every request:
    .tileArchive(url, headers: ["Authorization": "Bearer …"])
    
  • Offline. A file URL reads the archive from disk (see Offline maps).
  • Depth. The map reads how deep the archive goes from its header, and never asks for a deeper tile. Past that zoom, the deepest tiles are stretched. To read less, cap it with .tileMaximumZoomLevel(14).
  • Updates. You can upload a new archive under the same URL. The map notices by the ETag the host sends, and parses the changed tiles again. A host that sends no ETag needs a new URL for each upload.

Offline maps

The map works offline from a PMTiles file on the device. Put a .pmtiles file in the app’s bundle, or download one to disk, and give the map its file URL:

ImmersiveMapView()
    .tileArchive(Bundle.main.url(forResource: "city", withExtension: "pmtiles")!)
    .modelArchive(nil)
  • No network. The tiles are read from the file, so the map needs no connection and no tile server. On macOS a sandboxed app needs no Outgoing Connections for it.
  • 3D building models. They come from a hosted archive of their own, so an offline map turns them off with .modelArchive(nil), or reads a local PMTiles file of models the same way (see 3D content).
  • Relief. The relief is off by default. Turned on, it loads its heights from the network unless .terrain(_:) names a file URL template (see Relief).
  • The globe. The biomes and the roads of the far zooms ship inside the package, and need nothing.
  • The file. Any PMTiles v3 archive of vector tiles in the Protomaps basemap schema works. One city at full depth is tens of megabytes, and the whole planet is over a hundred gigabytes, so cut the area an app ships (the pmtiles extract command of the PMTiles tool does it).

Caching

The map keeps every tile it has parsed on disk, up to 2 GB by default, so a place seen before comes back without the network. Set the size in the unit that reads best:

ImmersiveMapView()
    .preparedTileDiskCacheSize(.gigabytes(4))

The size is an ImmersiveMapByteCount: .gigabytes(_:), .megabytes(_:), .kilobytes(_:) or .bytes(_:). Fractions work, as in .megabytes(1.5). A gigabyte here is 1024 megabytes. The cache is shared by every map in the app, and the most recently created map sets its size.