Convert Figma logo to code with AI

protomaps logoPMTiles

Pyramids of map tiles in a single file on static storage

2,330
143
2,330
8

Top Related Projects

Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.

Build vector tilesets from large collections of GeoJSON features.

2,802

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.

OpenMapTiles Vector Tile Schema Implementation

Quick Overview

PMTiles is an open-source, cloud-native format for storing and serving map tiles. It provides a single-file archive format for map tiles, designed to be efficiently hosted on cloud storage platforms like S3. PMTiles aims to simplify the process of serving vector and raster tiles for web maps.

Pros

  • Efficient storage and delivery of map tiles in a single file
  • Cloud-native design, optimized for content delivery networks (CDNs)
  • Supports both vector and raster tiles
  • Compatible with existing map rendering libraries and tools

Cons

  • Relatively new format, may have limited adoption compared to traditional tile formats
  • Requires specific tooling for creation and management of PMTiles archives
  • May not be suitable for scenarios requiring frequent updates to small portions of the tileset

Code Examples

  1. Loading a PMTiles source in Maplibre GL JS:
import * as pmtiles from "pmtiles";
import { Protocol } from "pmtiles";
import maplibregl from 'maplibre-gl';

const protocol = new Protocol();
maplibregl.addProtocol("pmtiles", protocol.tile);

const map = new maplibregl.Map({
  container: 'map',
  style: 'https://demotiles.maplibre.org/style.json',
  center: [0, 0],
  zoom: 1
});

map.on('load', () => {
  map.addSource('pmtiles-source', {
    type: 'vector',
    url: 'pmtiles://https://example.com/mytiles.pmtiles'
  });
});
  1. Reading metadata from a PMTiles archive:
import { PMTiles } from "pmtiles";

const p = new PMTiles("https://example.com/mytiles.pmtiles");

p.getMetadata().then(metadata => {
  console.log(metadata);
});
  1. Fetching a specific tile from a PMTiles archive:
import { PMTiles } from "pmtiles";

const p = new PMTiles("https://example.com/mytiles.pmtiles");

p.getZxy(0, 0, 0).then(result => {
  if (result) {
    console.log(result.data); // ArrayBuffer containing tile data
  }
});

Getting Started

To use PMTiles in your project:

  1. Install the PMTiles library:

    npm install pmtiles
    
  2. Import and use PMTiles in your code:

    import { PMTiles } from "pmtiles";
    
    const p = new PMTiles("https://example.com/mytiles.pmtiles");
    
    // Use PMTiles methods to interact with the archive
    p.getMetadata().then(metadata => {
      console.log(metadata);
    });
    
  3. For use with map libraries like Maplibre GL JS, follow the example in the "Code Examples" section above to set up the PMTiles protocol and add the source to your map.

Competitor Comparisons

Vector and raster maps with GL styles. Server side rendering by MapLibre GL Native. Map tile server for MapLibre GL JS, Android, iOS, Leaflet, OpenLayers, GIS via WMTS, etc.

Pros of tileserver-gl

  • Supports multiple tile formats (MBTiles, PMTiles, GeoJSON, KML, etc.)
  • Offers built-in caching mechanisms for improved performance
  • Provides a user-friendly web interface for tile visualization

Cons of tileserver-gl

  • Requires more setup and configuration compared to PMTiles
  • Higher resource consumption due to its full-featured nature
  • May have slower serving speeds for large datasets

Code Comparison

PMTiles:

import { PMTiles } from "pmtiles";

const p = new PMTiles("https://example.com/tiles.pmtiles");
const tileData = await p.getZxy(0, 0, 0);

tileserver-gl:

const tileserver = require('tileserver-gl');

const options = {
  paths: { root: __dirname },
  styles: { basic: require('./styles/basic.json') }
};
tileserver.serve(options);

Both projects aim to serve map tiles efficiently, but PMTiles focuses on a specific file format and lightweight implementation, while tileserver-gl offers a more comprehensive solution with support for various formats and additional features. PMTiles excels in simplicity and performance for its specific use case, whereas tileserver-gl provides greater flexibility and functionality at the cost of increased complexity and resource usage.

Build vector tilesets from large collections of GeoJSON features.

Pros of Tippecanoe

  • More mature and widely adopted in the geospatial community
  • Supports a broader range of input formats (GeoJSON, CSV, TopoJSON)
  • Offers advanced features like attribute preservation and feature dropping

Cons of Tippecanoe

  • Slower processing speed for large datasets
  • More complex setup and usage, requiring command-line expertise
  • Limited to generating MBTiles output format

Code Comparison

Tippecanoe:

tippecanoe -o output.mbtiles -zg input.geojson

PMTiles:

pmtiles convert input.geojson output.pmtiles

Key Differences

  • PMTiles focuses on a single, optimized file format, while Tippecanoe supports multiple input and output formats
  • PMTiles offers faster processing and simpler usage, making it more accessible for beginners
  • Tippecanoe provides more granular control over tile generation and feature selection

Use Cases

  • Choose Tippecanoe for complex vector tile generation with advanced customization needs
  • Opt for PMTiles when prioritizing speed, simplicity, and efficient storage for web mapping applications

Both tools have their strengths, and the choice depends on specific project requirements and user expertise.

2,802

Blazing fast and lightweight PostGIS, MBtiles and PMtiles tile server, tile generation, and mbtiles tooling.

Pros of Martin

  • Supports multiple data sources (PostGIS, Sprites, Fonts) beyond just vector tiles
  • Offers real-time data updates and dynamic styling
  • Provides a built-in tile server with caching capabilities

Cons of Martin

  • More complex setup and configuration compared to PMTiles
  • Requires a running server, which may increase operational costs
  • Potentially higher resource usage for serving dynamic content

Code Comparison

Martin (Rust):

let mut srv = martin::Server::new(config)?;
srv.add_function(Box::new(martin::functions::MVTFunction::new()));
srv.serve().await?;

PMTiles (JavaScript):

const p = new PMTiles("https://example.com/tiles.pmtiles");
const tileUrl = `${p.getProtocol()}://${p.getHost()}${p.getPathname()}/{z}/{x}/{y}`;

Key Differences

  • Martin is a full-fledged tile server, while PMTiles is a file format and client-side library
  • Martin offers more flexibility in data sources and real-time updates
  • PMTiles is simpler to deploy and use, especially for static datasets
  • Martin requires server-side setup, whereas PMTiles can be used directly on the client-side

OpenMapTiles Vector Tile Schema Implementation

Pros of OpenMapTiles

  • Comprehensive ecosystem with tools for data processing, styling, and serving
  • Extensive documentation and community support
  • Optimized for efficient rendering and storage of global map data

Cons of OpenMapTiles

  • More complex setup and maintenance compared to PMTiles
  • Requires more storage space for full global coverage
  • Less flexible for custom data sources and schemas

Code Comparison

OpenMapTiles (SQL query for water layer):

SELECT geometry, class, intermittent
FROM water_polygons
WHERE zoom_level >= 4

PMTiles (JavaScript for reading tile data):

const archive = new PMTiles('mymap.pmtiles');
const tile = await archive.getZxy(0, 0, 0);

Summary

OpenMapTiles offers a comprehensive solution for creating and serving vector tiles, with extensive tooling and documentation. It's well-suited for large-scale projects requiring global coverage. PMTiles, on the other hand, provides a simpler, more flexible approach for storing and serving tiles, making it easier to work with custom data sources and integrate into existing workflows. The choice between the two depends on project requirements, scale, and desired level of customization.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

pmtiles npm pmtiles pypi rio-pmtiles pypi ol-pmtiles npm

🔎 PMTiles Viewer: https://pmtiles.io/ 🔎

PMTiles

PMTiles is a single-file archive format for tiled data. A PMTiles archive can be hosted on a commodity storage platform such as S3, and enables low-cost, zero-maintenance map applications that are "serverless" - free of a custom tile backend or third party provider.

Demos require MapLibre GL JS v1.15 or later.

See also:

Creating PMTiles

Download the pmtiles binary for your system at go-pmtiles/Releases.

pmtiles convert INPUT.mbtiles OUTPUT.pmtiles
pmtiles upload OUTPUT.pmtiles s3://my-bucket?region=us-west-2 // requires AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY env vars to be set

Consuming PMTiles

JavaScript

See js/README.md and js/examples for usage in Leaflet or MapLibre GL JS.

See openlayers/README.md for usage in OpenLayers.

Go

See the go-pmtiles repository.

Python

See https://github.com/protomaps/PMTiles/tree/main/python/bin for library usage

Serverless

PMTiles on AWS Lambda

PMTiles on Cloudflare Workers

Specification

The current specification version is Version 3.

Recipes

Example of how to create a PMTiles archive from the Census Bureau Zip Code Tabulation Areas Shapefile using tippecanoe:

    # use GDAL/OGR to convert SHP to GeoJSON
    ogr2ogr -t_srs EPSG:4326 cb_2018_us_zcta510_500k.json cb_2018_us_zcta510_500k.shp
    # Creates a layer in the vector tiles named "zcta"
    tippecanoe -zg --projection=EPSG:4326 -o cb_2018_us_zcta510_500k_nolimit.pmtiles -l zcta cb_2018_us_zcta510_500k.json

Uploading to Storage

Using the PMTiles command line tool:

pmtiles upload LOCAL.pmtiles "s3://BUCKET_NAME?endpoint=https://example.com&region=region" REMOTE.pmtiles

Using RClone (do rclone config first)

rclone copyto LOCAL.pmtiles r2:/BUCKET/REMOTE.pmtiles --progress --s3-chunk-size=256M --s3-upload-concurrency=2

License

The reference implementations of PMTiles are published under the BSD 3-Clause License. The PMTiles specification itself is public domain, or under a CC0 license where applicable.

NPM DownloadsLast 30 Days