重要前提
安装AI Skills的关键前提是:必须科学上网,且开启TUN模式,这一点至关重要,直接决定安装能否顺利完成,在此郑重提醒三遍:科学上网,科学上网,科学上网。查看完整安装教程 →
maplibre-pmtiles-patterns by maplibre/maplibre-agent-skills
npx skills add https://github.com/maplibre/maplibre-agent-skills --skill maplibre-pmtiles-patternsPMTiles 是一种用于矢量或栅格地图瓦片的单文件格式。您可以在任何静态主机上托管一个(或几个)文件;MapLibre 通过 HTTP 请求字节范围。无需瓦片服务器,无需动态后端。本技能涵盖何时使用 PMTiles、如何生成和托管它们,以及如何将它们连接到 MapLibre GL JS。
type: 'vector'、type: 'raster' 或 type: 'raster-dem'。.pmtiles 文件通常包含完整的瓦片金字塔(所有缩放级别)和所有图层(矢量或栅格),全部在一个存档中。该格式以紧凑的布局(例如希尔伯特曲线)存储瓦片,因此客户端可以仅请求其所需的字节范围。对于非常大的覆盖范围,您可以按区域拆分为多个文件。Range 头部的主机都可以工作。广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
何时应优先选择 PMTiles 而非传统的瓦片服务器:
何时应优先选择瓦片服务器(例如 tileserver-gl、Martin):
MapLibre 本身不支持 PMTiles。您需要使用 PMTiles 库来添加协议处理器,以便 pmtiles://(或指向 .pmtiles 文件的 https://)源能够工作。
安装:
npm install pmtiles
注册协议并在样式中使用:
import * as pmtiles from 'pmtiles';
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
// 添加 PMTiles 协议,以便源可以引用 .pmtiles URL
const protocol = new pmtiles.Protocol();
maplibregl.addProtocol('pmtiles', protocol.tile);
const map = new maplibregl.Map({
container: 'map',
style: {
version: 8,
sources: {
tiles: {
type: 'vector',
url: 'pmtiles://https://example.com/data.pmtiles'
}
},
layers: [
{
id: 'background',
type: 'background',
paint: { 'background-color': '#f8f4f0' }
},
{
id: 'water',
type: 'fill',
source: 'tiles',
'source-layer': 'water',
paint: { 'fill-color': '#a0c8f0' }
}
// 根据需要添加更多图层 — 每个图层使用相同的源,不同的 'source-layer'
]
},
center: [0, 0],
zoom: 2
});
// 可选:在地图销毁时移除协议
// map.on('remove', () => maplibregl.removeProtocol('pmtiles'));
引用图层: 样式有一个源(例如 sources.tiles)指向 .pmtiles URL。layers 数组中从该文件绘制的每个图层都使用 source: 'tiles' 和 "source-layer": "layerName",其中 layerName 是文件内矢量图层的名称(来自瓦片使用的任何模式)。添加多个具有不同 source-layer 值的样式图层,以显示来自同一文件的道路、标签等。
重要提示: url 可以是 pmtiles://https://...(协议 + 指向 .pmtiles 文件的 HTTPS URL)。库将通过范围请求获取文件。如果您使用标签或图标,您的样式仍必须定义字形和雪碧图(参见 maplibre-tile-sources)。
栅格和栅格高程数据: 相同的协议适用于栅格 PMTiles。对于影像,使用 type: 'raster' 源。对于地形/高程,使用 type: 'raster-dem' 源,并设置 "encoding": "terrarium"(或 "mapbox"),以便 MapLibre 可以应用山体阴影或 3D 地形;然后在样式的 terrain 属性中引用它。示例源:
"elevation": {
"type": "raster-dem",
"url": "pmtiles://https://example.com/elevation.pmtiles",
"encoding": "terrarium"
}
在 React 中使用 PMTiles: 在应用程序启动时注册协议一次,而不是在每个组件内部,以便 MapLibre 在任何地图挂载之前拥有处理器。例如,在根级 effect 中或地图提供程序初始化时调用 maplibregl.addProtocol('pmtiles', protocol.tile)。在卸载最后一个地图时(或应用程序销毁时),调用 maplibregl.removeProtocol('pmtiles') 以避免内存泄漏。有关面向 React 的设置,请参阅 PMTiles for MapLibre GL(Protomaps)。
任何能够提供文件并支持 HTTP 范围请求 的主机都适用。
Cache-Control,并可选择使用 CloudFront。Accept-Ranges: bytes 并正确响应 Range 头部。CORS: 浏览器将向 PMTiles URL 发送跨域请求。主机必须发送 Access-Control-Allow-Origin: *(或您的域名)和 Access-Control-Allow-Headers: Range(或允许所有)。否则 MapLibre 将无法加载瓦片。
缓存头部: 为了获得更好的性能,为 .pmtiles 文件设置长缓存(例如,如果文件是不可变的,则设置 Cache-Control: public, max-age=31536000)。CDN 将缓存范围响应。
pmtiles CLI 是用于处理 PMTiles(以及用于转换的 MBTiles)的官方命令行工具。它是一个没有运行时依赖的单一二进制文件——下载后即可运行。
为何安装和使用它:
pmtiles convert in.mbtiles out.pmtiles。当您的流水线已经生成 MBTiles 时,这通常是获取 PMTiles 的最简单方法。pmtiles show <file> 打印头部和元数据(边界、缩放范围、瓦片数量)。pmtiles verify <file> 检查存档完整性。对于调试或在上传前确认文件很有用。pmtiles extract 从现有文件创建较小的 .pmtiles 文件(例如,通过边界框或缩放范围),因此您可以提供区域或有限的缩放带,而无需从源重新生成。安装: 从 GitHub Releases (go-pmtiles) 下载适用于您操作系统/架构的二进制文件,或使用 Docker:protomaps/go-pmtiles。
它不能做什么: CLI 仅适用于瓦片存档(MBTiles 和 PMTiles)。它不能读取 GeoJSON、Shapefile、OSM 或其他源格式。要从这些格式创建 PMTiles,请使用生成瓦片的工具(参见下面的 生成 PMTiles),如果该工具输出 MBTiles,则运行 pmtiles convert 以获取 PMTiles。
两种路径: (1) 转换 — PMTiles CLI 仅转换 MBTiles ↔ PMTiles;它不能读取 GeoJSON、Shapefile、OSM 或其他源格式。(2) 从源数据生成 — 像 tippecanoe、Planetiler 和通过 GDAL 的 ogr2ogr 这样的工具可以从多种文件类型或数据库读取并生成矢量瓦片(PMTiles 或 MBTiles)。如果它们输出 MBTiles,请使用 pmtiles convert 以获取 PMTiles。
有关为何安装它以及其他命令(show、verify、extract)的信息,请参阅上面的 PMTiles CLI。要将 MBTiles 转换为 PMTiles:
pmtiles convert input.mbtiles output.pmtiles
以下工具从源数据生成瓦片(GeoJSON、OSM、Shapefile、PostGIS 等)。它们输出 PMTiles 或 MBTiles;如果是 MBTiles,请运行 pmtiles convert 以获取 PMTiles。
Planetiler 读取 OpenStreetMap(或其他源)并以 OpenMapTiles 模式输出 PMTiles 或 MBTiles。
# 示例:为区域构建 PMTiles 文件(例如,从 .osm.pbf 下载)
java -jar planetiler.jar --area=monaco --output=monaco.pmtiles
有关区域名称、自定义源和模式选项,请参阅 Planetiler 文档。输出是一个单独的 .pmtiles 文件,您可以上传到 S3/R2/静态主机。
tippecanoe 从源格式生成矢量瓦片:GeoJSON、FlatGeobuf、CSV。从 v2.17 开始,它可以直接输出 PMTiles(-o output.pmtiles)。您也可以输出 MBTiles 并使用 pmtiles convert 进行转换。
# 直接输出 PMTiles(v2.17+)
tippecanoe -zg -o output.pmtiles input.geojson
# 或者先输出 MBTiles 再转换:tippecanoe -o output.mbtiles -z 14 input.geojson && pmtiles convert output.mbtiles output.pmtiles
GDAL 的 ogr2ogr 从许多地理空间格式生成瓦片(Shapefile、PostGIS、GeoJSON 等),并且可以写入 MBTiles 或 PMTiles(GDAL 3.8+)。最适合较小的数据集;对于大型矢量瓦片集,tippecanoe 更高效。
PMTiles 支持栅格瓦片(PNG/JPEG,例如卫星或预渲染影像)和栅格高程数据(高程/地形,例如 Terrarium 或 Mapbox 编码)。使用生成栅格或栅格高程数据 PMTiles 的工具;相同的协议和托管方式适用。在样式中,对于影像使用 type: 'raster',对于地形使用 type: 'raster-dem' 并设置 "encoding": "terrarium"(或 "mapbox")——有关示例,请参阅上面的 MapLibre 集成。
Overture Maps 发布全球开放地图数据。一些提供商将 Overture 衍生的数据作为 PMTiles 分发(例如,用于建筑物、地点、交通)。您也可以使用 Planetiler 或其他流水线从 Overture 数据构建 PMTiles。像上面一样在您的 MapLibre 样式中使用 PMTiles URL。
convert、show、verify、extract)每周安装次数
60
仓库
GitHub Stars
31
首次出现
2026年2月28日
安全审计
安装于
opencode47
github-copilot47
codex47
gemini-cli46
amp46
kimi-cli46
PMTiles is a single-file format for vector or raster map tiles. You host one (or a few) files on any static host; MapLibre requests byte ranges over HTTP. No tile server, no dynamic backend. This skill covers when to use PMTiles, how to generate and host them, and how to connect them to MapLibre GL JS.
type: 'vector', type: 'raster', or type: 'raster-dem' accordingly..pmtiles file typically contains the full tile pyramid (all zoom levels) and all layers (vector or raster) in one archive. The format stores tiles in a compact layout (e.g. Hilbert curve) so the client can request only the byte ranges it needs. For very large coverage you may split by region into multiple files.Range headers works.When to prefer PMTiles over a traditional tile server:
When to prefer a tile server (e.g. tileserver-gl, Martin):
MapLibre does not speak PMTiles natively. You use the PMTiles library to add a protocol handler so that a pmtiles:// (or https:// to a .pmtiles file) source works.
Install:
npm install pmtiles
Register the protocol and use in a style:
import * as pmtiles from 'pmtiles';
import maplibregl from 'maplibre-gl';
import 'maplibre-gl/dist/maplibre-gl.css';
// Add PMTiles protocol so sources can reference .pmtiles URLs
const protocol = new pmtiles.Protocol();
maplibregl.addProtocol('pmtiles', protocol.tile);
const map = new maplibregl.Map({
container: 'map',
style: {
version: 8,
sources: {
tiles: {
type: 'vector',
url: 'pmtiles://https://example.com/data.pmtiles'
}
},
layers: [
{
id: 'background',
type: 'background',
paint: { 'background-color': '#f8f4f0' }
},
{
id: 'water',
type: 'fill',
source: 'tiles',
'source-layer': 'water',
paint: { 'fill-color': '#a0c8f0' }
}
// add more layers as needed — each uses the same source, different 'source-layer'
]
},
center: [0, 0],
zoom: 2
});
// Optional: remove protocol on map teardown
// map.on('remove', () => maplibregl.removeProtocol('pmtiles'));
Referencing layers: The style has one source (e.g. sources.tiles) pointing at the .pmtiles URL. Each layer in the layers array that draws from that file uses source: 'tiles' and "source-layer": "layerName", where layerName is the name of a vector layer inside the file (from whatever schema the tiles use). Add multiple style layers with different source-layer values to show roads, labels, etc. from the same file.
Important: The url can be pmtiles://https://... (protocol + HTTPS URL to the .pmtiles file). The library will fetch the file via range requests. Your style must still define glyphs and sprite if you use labels or icons (see maplibre-tile-sources).
Raster and raster-dem: The same protocol works for raster PMTiles. Use a type: 'raster' source for imagery. For terrain/elevation, use a type: 'raster-dem' source with "encoding": "terrarium" (or "mapbox") so MapLibre can apply hillshade or 3D terrain; then reference it in the style’s terrain property. Example source:
"elevation": {
"type": "raster-dem",
"url": "pmtiles://https://example.com/elevation.pmtiles",
"encoding": "terrarium"
}
Using PMTiles with React: Register the protocol once at application startup, not inside each component, so MapLibre has the handler before any map mounts. For example, call maplibregl.addProtocol('pmtiles', protocol.tile) in a root-level effect or when your map provider initializes. On unmount of the last map (or when the app tears down), call maplibregl.removeProtocol('pmtiles') to avoid leaks. See PMTiles for MapLibre GL (Protomaps) for a React-oriented setup.
Any host that serves the file and supports HTTP Range requests is suitable.
Cache-Control and optionally use CloudFront.Accept-Ranges: bytes and responds correctly to Range headers.CORS: Browsers will send cross-origin requests to the PMTiles URL. The host must send Access-Control-Allow-Origin: * (or your domain) and Access-Control-Allow-Headers: Range (or allow all). Otherwise MapLibre will fail to load tiles.
Cache headers: For better performance, set long cache for the .pmtiles file (e.g. Cache-Control: public, max-age=31536000 if the file is immutable). CDNs will cache range responses.
The pmtiles CLI is the official command-line tool for working with PMTiles (and MBTiles for conversion). It’s a single binary with no runtime dependencies—you download it and run it.
Why install and use it:
pmtiles convert in.mbtiles out.pmtiles. This is often the simplest way to get PMTiles when your pipeline already produces MBTiles.pmtiles show <file> prints header and metadata (bounds, zoom range, tile count). pmtiles verify <file> checks archive integrity. Useful for debugging or confirming a file before uploading.pmtiles extract creates a smaller .pmtiles file from an existing one (e.g. by bounding box or zoom range), so you can ship a region or a limited zoom band without regenerating from source.Install: Download the binary for your OS/arch from GitHub Releases (go-pmtiles), or use Docker: protomaps/go-pmtiles.
What it does not do: The CLI only works with tile archives (MBTiles and PMTiles). It does not read GeoJSON, Shapefile, OSM, or other source formats. To create PMTiles from those, use a tool that generates tiles (see Generating PMTiles below) and, if that tool outputs MBTiles, run pmtiles convert to get PMTiles.
Two paths: (1) Convert — The PMTiles CLI converts MBTiles ↔ PMTiles only; it does not read GeoJSON, Shapefile, OSM, or other source formats. (2) Generate from source data — Tools like tippecanoe, Planetiler and ogr2ogr via GDAL read from many file types or databases and produce vector tiles (PMTiles or MBTiles). If they output MBTiles, use pmtiles convert to get PMTiles.
See The PMTiles CLI above for why to install it and other commands (show, verify, extract). To convert MBTiles to PMTiles:
pmtiles convert input.mbtiles output.pmtiles
The following tools generate tiles from source data (GeoJSON, OSM, Shapefile, PostGIS, etc.). They output PMTiles or MBTiles; if MBTiles, run pmtiles convert to get PMTiles.
Planetiler reads OpenStreetMap (or other sources) and outputs PMTiles or MBTiles in the OpenMapTiles schema.
# Example: build a PMTiles file for a region (e.g. from a .osm.pbf download)
java -jar planetiler.jar --area=monaco --output=monaco.pmtiles
See Planetiler docs for area names, custom sources, and schema options. Output is a single .pmtiles file you can upload to S3/R2/static host.
tippecanoe generates vector tiles from source formats: GeoJSON, FlatGeobuf, CSV. From v2.17 onward it can output PMTiles directly (-o output.pmtiles). You can also output MBTiles and convert with pmtiles convert.
# Direct PMTiles output (v2.17+)
tippecanoe -zg -o output.pmtiles input.geojson
# Or MBTiles then convert: tippecanoe -o output.mbtiles -z 14 input.geojson && pmtiles convert output.mbtiles output.pmtiles
GDAL’s ogr2ogr generates tiles from many geospatial formats (Shapefile, PostGIS, GeoJSON, etc.) and can write MBTiles or PMTiles (GDAL 3.8+). Best for smaller datasets; tippecanoe is more efficient for large vector tile sets.
PMTiles supports raster tiles (PNG/JPEG, e.g. satellite or pre-rendered imagery) and raster-dem (elevation/terrain, e.g. Terrarium or Mapbox encoding). Use tools that produce raster or raster-dem PMTiles; the same protocol and hosting apply. In the style use type: 'raster' for imagery or type: 'raster-dem' with "encoding": "terrarium" (or "mapbox") for terrain—see MapLibre Integration above for an example.
Overture Maps publishes global open map data. Some providers distribute Overture-derived data as PMTiles (e.g. for buildings, places, transportation). You can also build PMTiles from Overture data with Planetiler or other pipelines. Use the PMTiles URL in your MapLibre style as above.
convert, show, verify, extract)Weekly Installs
60
Repository
GitHub Stars
31
First Seen
Feb 28, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode47
github-copilot47
codex47
gemini-cli46
amp46
kimi-cli46
GSAP 框架集成指南:Vue、Svelte 等框架中 GSAP 动画最佳实践
3,700 周安装
错误追踪与监控专家:实施全面错误监控解决方案,提升系统稳定性
177 周安装
SVG 插图入门指南:创建专业图表、排查嵌入问题、提升幻灯片视觉效果
180 周安装
iOS/Swift 内存调试与泄漏修复指南 - 使用 Instruments 和 Xcode 诊断循环引用、计时器泄漏
184 周安装
Apify 社交平台数据抓取工具集:Twitter、Reddit、LinkedIn、Instagram 等自动化爬虫
177 周安装
SSL证书自动化管理指南 - Cert-Manager、Let's Encrypt与AWS ACM最佳实践
178 周安装
AXe iOS模拟器自动化工具:通过无障碍API实现iOS模拟器自动化测试与交互
175 周安装