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

pmtiles-protocol

v1.1.2

Published

PMTiles protocol (pmtiles://) for fetch, XMLHttpRequest and Image

Readme

pmtiles-protocol

This package makes it easy to work with Protomaps PMTiles directly in the browser. It provides fetch and XMLHttpRequest versions as well as an Image or HTMLImageElement setter for src that support urls starting with pmtiles://, returning the respective TileJSON or tiles. It is meant to be used in browser applications.

Supported URLs

TileJSON

  • pmtiles://https://example.com/path/to/mytiles.pmtiles (absolute)
  • pmtiles://path/to/mytiles.pmtiles (relative to window.location.href)

Tiles

  • pmtiles://https://example.com/path/to/mytiles.pmtiles/{z}/{x}/{y}.mvt (absolute)
  • pmtiles://path/to/mytiles.pmtiles/{z}/{x}/{y}.png (relative to window.location.href)

How to use

The global overrides for fetch(), XMLHttpRequest and Image or HTMLImageElment's src setter are the easiest way to use pmtiles-protocol:

import { register } from 'pmtiles-protocol';

const unregister = register();

Now every request url that starts with pmtiles:// for anything in your web application that uses fetch() or XMLHttpRequest will go through pmtiles. Also, setting the src attribute of an Image or HTMLImageElement to a pmtiles:// url will load the image from the PMTiles archive.

To restore the original global fetch() and XMLHttpRequest versions, and the original src setter on Image and HTMLImageElement, call

unregister();

If global overrides are not desired, pmtiles-protocol also provides a dedicated fetch() function, a dedicated XMLHttpRequest replacement, and a dedicated Image constructor:

import { fetch, XMLHttpRequest, Image } from 'pmtiles-protocol';

Examples

fetch

fetch('pmtiles://https://example.com/mytiles.pmtiles/0/0/0.mvt');

fetches the 0/0/0 tile from the PMTiles file at https://example.com/mytiles.pmtiles.

XMLHttpRequest

const xhr = new XMLHttpRequest();
xhr.open('GET', 'pmtiles://path/to/mytiles.pmtiles');
xhr.onload = () => {
  console.log('TileJSON', xhr.responseText);
};

logs the TileJSON from the PMTiles file at path/to/mytiles.pmtiles (relative to window.location.href) to the console.

Image

const img = new Image();
img.src = 'pmtiles://https://example.com/mytiles.pmtiles/0/0/0.png';
document.body.appendChild(img);

In a Mapbox Style document

The pmtiles source below will use the TileJSON and tiles from https://example.com/mytiles.pmtiles:

{
  "sources": {
    "pmtiles": {
      "type": "vector",
      "url": "pmtiles://https://example.com/mytiles.pmtiles"
    }
  }
}

Limitations

fetch()

No known limitations.

XMLHttpRequest

The limitations below only apply when XMLHttpRequest is used with a pmtiles:// url.

  • Only the load and error events are fired.
  • The only methods that act on the PMTiles file are open() and send().
  • Only the response and responseText properties are supported.
  • Only the 200 and 404 status codes are used.

Image

The limitations below only apply when Image or HTMLImageElement is used with a pmtiles:// url.

  • HTML Attributes: Setting the src attribute via HTML markup (e.g., <img src="pmtiles://...">) or setAttribute (e.g. img.setAttribute('src', ...)) is not supported, because the browser's native network loader handles these before the library's JavaScript interception can run. You must assign to the src property (e.g. img.src = ...) for it to work.
  • CSS: pmtiles:// URLs are not supported in CSS background-image or other CSS properties.
  • Property Read-back: When assigning a pmtiles:// URL to img.src, reading img.src immediately after will not return the pmtiles:// URL. Instead, it will return the previous value or the blob: URL once the image has loaded. This also applies when inspecting img.src inside an onload or onerror handler.
  • srcset: The srcset attribute is not supported.
  • Error Handling: If loading fails, an error event is dispatched on the image element. Note that the error is also logged to console.error.