npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@earthranger/react-native-mapbox-pmtiles

v0.0.1

Published

Serve tiles from local PMTiles files to Mapbox

Readme

Serve tiles from local PMTiles files to Mapbox in React Native apps built with @rnmapbox/maps. Works offline, with no tile server and no changes to Mapbox.

Status: prototype. Vector PMTiles render on iOS and Android. See Limitations.

How it works

The library registers a Mapbox HTTP interceptor that answers requests to the reserved host https://pmtiles.local/<name>/{z}/{x}/{y}.<ext> by reading the tile from <directory>/<name>.pmtiles. Requests to any other host pass through to the network. You point a normal VectorSource or RasterSource at that URL.

See docs/architecture.md for diagrams.

Requirements

  • React Native 0.76+ (new architecture supported through the interop layer)
  • @rnmapbox/maps 10.1+ using the Mapbox Maps SDK v11 (RNMapboxMapsVersion 11.x)
  • PMTiles v3 files with gzip or no compression

Installation

yarn add @earthranger/react-native-mapbox-pmtiles
cd ios && pod install

No changes to AppDelegate or MainApplication are needed; autolinking registers the native module on both platforms.

Android: Mapbox Common version

The library compiles against Mapbox Common, which @rnmapbox/maps supplies at runtime. It defaults to 24.16.2 (Mapbox Maps 11.16.x). If your app uses a different Mapbox version, set the matching Common version in android/build.gradle:

buildscript {
  ext {
    PMTilesMapboxCommonVersion = "24.16.2"
  }
}

Usage

1. Install the interceptor at startup

Call install once, before the map renders, with the folder that holds your .pmtiles files:

import { DocumentDirectoryPath } from 'react-native-fs';
import { install } from '@earthranger/react-native-mapbox-pmtiles';

install(`${DocumentDirectoryPath}/pmtiles`);

install throws if the native module isn't linked (rebuild the app after adding the library).

2. Put files in that folder

Each file is addressed by its name without the extension: counties.pmtiles becomes counties. Names may contain letters, numbers, - and _. Files are opened on first use.

3. Add a source to the map

import { FillLayer, LineLayer, MapView, VectorSource } from '@rnmapbox/maps';
import { tileUrl } from '@earthranger/react-native-mapbox-pmtiles';

<MapView>
  <VectorSource
    id="counties"
    tileUrlTemplates={[tileUrl('counties', 'mvt')]}
    minZoomLevel={0}
    maxZoomLevel={7}
  >
    <FillLayer
      id="counties-fill"
      sourceLayerID="UScountiesfgb"
      style={{ fillColor: '#ff00ff', fillOpacity: 0.12 }}
    />
    <LineLayer
      id="counties-line"
      sourceLayerID="UScountiesfgb"
      style={{ lineColor: '#8b008b', lineWidth: 1 }}
    />
  </VectorSource>
</MapView>

For raster files use a RasterSource with tileUrl(name, 'png') (or 'jpg', 'webp') and a RasterLayer.

Set minZoomLevel / maxZoomLevel to the file's zoom range so Mapbox overzooms instead of requesting missing tiles. Vector layers need the file's source-layer names (e.g. from pmtiles show <file>).

API

| Export | Description | |---|---| | install(directory: string): void | Registers the interceptor and sets the folder files are read from. Calling it again changes the folder and closes open files. | | tileUrl(name: string, extension: TileExtension): string | Returns https://pmtiles.local/<name>/{z}/{x}/{y}.<extension> for tileUrlTemplates. | | PMTILES_HOST | https://pmtiles.local | | TileExtension | 'mvt' \| 'pbf' \| 'png' \| 'jpg' \| 'webp' |

Responses: 200 with the tile and cache-control: no-store, 204 when the file has no tile at that position, 404 for a malformed URL or a missing or invalid file.

Loading files onto a device for testing

Debug builds only.

# iOS
xcrun devicectl device copy to --device <device-id> --domain-type appDataContainer \
  --domain-identifier <bundle-id> --source counties.pmtiles \
  --destination Documents/pmtiles/counties.pmtiles

# Android
adb push counties.pmtiles /data/local/tmp/
adb shell "run-as <application-id> sh -c 'mkdir -p files/pmtiles && cp /data/local/tmp/counties.pmtiles files/pmtiles/'"

Logs: PMTiles served … in the Xcode console, adb logcat -s PMTiles on Android.

Limitations

  • One interceptor per app. Mapbox allows a single HTTP interceptor. Mapbox.addCustomHeader in @rnmapbox/maps installs its own and replaces this one.
  • No file metadata yet. Bounds, zoom range, tile type and vector layer names must be supplied by the app.
  • Files stay open. Replacing or deleting a file while the app runs keeps serving the old copy until install is called again or the app restarts.
  • Offline base style. Sources are added on top of the Mapbox style, which must already be cached (or replaced by a local styleJSON) for the map to load offline.
  • Compression: gzip or none. Brotli and Zstandard are not supported.

Tests

Both PMTiles readers are tested against the same fixtures and expected results in test/fixtures/:

| Fixture | Covers | |---|---| | vector-gzip.pmtiles | MVT, gzip directories and tiles, root directory only, missing tiles | | raster-leaves.pmtiles | PNG, uncompressed tiles, leaf directories, run-length and deduplicated entries | | webp-uncompressed.pmtiles | WebP, no compression anywhere, minZoom above 0 | | invalid-magic.pmtiles, truncated.pmtiles | Files that must fail to open |

expected.json holds the header values, tile sizes and SHA-256 hashes the readers must produce. It is generated from the tiles generate.py writes, not by reading the files back, and the fixtures were checked with the official pmtiles Python reader.

yarn test:ios       # swift test (Package.swift builds only the reader)
yarn test:android   # JUnit via the host app's Gradle; set APP_ROOT if the app isn't at ../er-mobile
yarn fixtures       # regenerate fixtures and expected.json after changing generate.py

When adding reader features (e.g. metadata, new compression), add a fixture and its expected values to generate.py first, then make both readers pass.

License

Apache 2.0. See LICENSE.