
Security News
GitHub Actions Checkout Now Blocks Risky pull_request_target Checkouts
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.
pmtiles-protocol
Advanced tools
This package makes it easy to work with Protomaps PMTiles directly in the browser. It provides fetch and XMLHttpRequest versions that support urls starting with pmtiles://, returning the respective TileJSON or tiles. It is meant to be used in browser applications.
pmtiles://https://example.com/path/to/mytiles.pmtiles (absolute)pmtiles://path/to/mytiles.pmtiles (relative to window.location.href)pmtiles://https://example.com/path/to/mytiles.pmtiles/{z}/{x}/{y}.mvt (absolute)pmtiles://path/to/mytiles.pmtiles/{z}/{x}/{y}.mvt (relative to window.location.href)The global overrides for fetch() and XMLHttpRequest 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.
To restore the original global fetch() and XMLHttpRequest versions, call
unregister();
If global overrides are not desired, pmtiles-protocol also provides a dedicated fetch() function and a dedicated XMLHttpRequest replacement:
import { fetch, XMLHttpRequest } from 'pmtiles-protocol';
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.
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.
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"
}
}
}
This package won't add support for PMTiles when loading images by simply setting the src of an Image or HTTPImageElement. However, using an object url, the following would work:
const img = new Image();
fetch('pmtiles://path/to/mytiles.pmtiles/0/0/0.png')
.then((response) => response.blob())
.then((blob) => {
const objectUrl = URL.createObjectURL(blob);
img.onload = () => {
console.log('Image loaded');
URL.revokeObjectURL(objectUrl);
};
img.onerror = () => {
console.error('Image load error');
URL.revokeObjectURL(objectUrl);
};
img.src = objectUrl;
})
.catch((error) => {
console.error('Fetch error:', error);
});
No known limitations.
The limitations below only apply when XMLHttpRequest is used with a pmtiles:// url.
load and error events are fired.open() and send().response and responseText properties are supported.200 and 404 status codes are used.FAQs
PMTiles protocol (pmtiles://) for fetch, XMLHttpRequest and Image
The npm package pmtiles-protocol receives a total of 521 weekly downloads. As such, pmtiles-protocol popularity was classified as not popular.
We found that pmtiles-protocol demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
GitHub Actions checkout now blocks risky pull_request_target checkouts by default to help prevent pwn request supply chain attacks.

Product
Socket now supports Custom Roles and Repository Access Permissions so organizations can control who can access specific repositories and actions.

Product
Socket MCP now lets AI assistants review org alerts, investigate threats using the Socket threat feed, and inspect package files in addition to dependency scoring.