Skip to main content

PMTiles source loader

Read archive tiles without downloading the archive.

PMTilesLoader turns a PMTiles archive into a tile source. For remote archives it reads the header and directory with byte ranges, queues nearby tile requests, and coalesces compatible ranges before fetching.

The archive path

Inspect the archive. Find a tile. Fetch only its bytes.

PMTiles keeps a tile pyramid in one archive. The source adds loaders.gl source lifecycle and range scheduling around the format’s header, directory, and tile-content lookups.

Open

Remote URL or in-memory PMTiles data

Discover

Header, metadata, and directory entries

Request

One tile or a coordinated batch of tiles

Transport

Merged HTTP ranges with bounded over-fetch

From-v4.0range requests from v5.0range requests experimental

The PMTilesLoader reads individual tiles from a PMTiles archive file. For remote URL archives, tile requests are queued briefly and nearby HTTP byte ranges are coalesced before the archive bytes are fetched.

PMTilesLoader
File Extension.pmtiles
File TypeBinary Archive
File FormatPMTiles
Data FormatMetadata
Data sourcePMTilesTileSource

Usage​

Detailed guide

Source and range details

The reference below covers construction, explicit tile batches, range scheduling options, diagnostics, and server response requirements.

import {createDataSource} from '@loaders.gl/core';
import {PMTilesLoader} from '@loaders.gl/tiles/pmtiles';

const source = await createDataSource(url, [PMTilesLoader]);
const tile = await source.getTile(...);

Batched tile reads​

getTile() and getTileData() automatically participate in delayed range batching. Requests made during the same rangeRequests.batchDelayMs window are started together; tile-content byte ranges that are close together are fetched as one merged HTTP Range request and then sliced back into per-tile results.

Applications that already know the complete tile set can also call the explicit batch API:

const tilePromises = source.getTileDataBatch?.([tileA, tileB, tileC]);

See the using range requests guide for the shared scheduler model and option tradeoffs.

Use createRangeStats() and getRangeStats() from @loaders.gl/core/loader-utils when you need typed aggregate counters for PMTiles range transport diagnostics.

Options​

See Source options for shared controls and parser configuration. PMTiles can delegate to MVT, MLT, or image parsers. pmtiles.shape overrides mvt.shape or mlt.shape; when omitted, the selected parser's shape is used, falling back to Arrow.

OptionTypeDefaultDescription
rangeRequests.batchDelayMsnumber50Time to wait for sibling tile requests before starting PMTiles tile lookup.
rangeRequests.rangeExpansionBytesnumber65536Maximum byte gap to over-fetch when expanding one HTTP range to include nearby tile content.
rangeRequests.maxGapBytesnumber65536Compatibility alias for rangeExpansionBytes.
rangeRequests.maxMergedBytesnumber8388608Maximum size of one merged byte-range request.
rangeRequests.maxConcurrentRequestsnumber6Reserved concurrency hint for range-request transports.
rangeRequests.statsStatsnoneOptional probe.gl Stats object that receives range batching counters.
rangeRequests.onEventfunctionnoneOptional diagnostics callback for queued, batched, completed, failed, and aborted range requests.
pmtiles.shapestring'arrow'Output shape for vector tiles: 'arrow', 'geojson-table', 'binary-geometry', or 'columnar-table' (MVT only).

Notes​

  • Blob / in-memory PMTiles archives are read directly and do not add the default network batching delay.
  • PMTiles metadata, header, and directory handling is still delegated to the pmtiles package.
  • PMTiles v2 archives may fall back to the package's normal single-tile lookup path.
  • PMTiles URL sources expect byte-range fetches to return 206 Partial Content. If a server ignores Range and responds with 200 OK, loaders.gl aborts the fetch and rejects the tile request instead of downloading the full archive.

Canonical XYZ grid​

PMTiles archive addressing establishes XYZ level IDs and matrix counts, but does not declare a geographic CRS. getMetadata().tileGrid therefore retains partial native geometry by default. Set pmtiles.coordinateReferenceSystem: 'EPSG:3857' only when the source contract establishes Web Mercator to obtain a complete tileMatrixSet. It uses native zoom IDs and the header range. Its default 256-pixel logical frame can be changed with pmtiles.tileSize; this does not resample raster tiles or change vector quantization. Header geographic bounds and sparse directory entries remain separate from world matrix geometry. An advertised level does not guarantee that every tile exists; missing entries return null. Exact tileMatrix IDs and the shared native-ID-first/index-fallback rule resolve to native archive zooms before lookup and vector decoding. Unknown explicit IDs reject.

See the PMTiles specification and Tile matrices.

A tile request's abort signal cancels its metadata wait promptly. Shared metadata discovery continues for other callers; cancelling one tile does not invalidate their requests.

Native grid metadata preserves PMTiles header zooms through 31. Tile payload lookup retains the installed PMTiles JavaScript reader's zoom-26 safe-number limit; higher advertised levels do not prevent metadata discovery or requests at supported lower levels.

Header ranges that cannot form a supported numeric grid retain their native metadata and omit tileGrid; they do not make metadata parsing fail.