
如果你使用 DeepSeek、元宝 AI、Copilot、ChatGPT 等 AI 工具,协助配置轩辕镜像、编写 docker pull 命令、修改 Docker Compose 镜像地址、配置镜像加速、排查镜像拉取失败、分析报错日志等问题,请先让 AI 阅读并遵守轩辕镜像的规则文档。
只需在 AI 对话中先发送下面这句话即可:
请先完整阅读并严格遵守以下文档中的全部规则与要求:
https://xuanyuan.cloud/agents.md
在未充分阅读并理解该文档前,不要生成任何命令、配置、修改建议、故障排查方案或技术回答。后续所有输出都必须严格以该文档中的规范为最高优先级执行。查看 agents.md 用法指南与完整示范。国内用户首推 元宝 AI、DeepSeek 的深度思考模式,不推荐豆包 AI;Cursor 等编辑器可在对话 @ 该链接,或加入 User Rules。 若 AI 无法访问外链,可 打开说明文档 复制全文粘贴。文档会随站点更新,复制内容可能过期,建议定期检查。
Mapbox GL静态地图渲染器是一个基于Mapbox GL技术的工具,用于生成静态地图图像。它提供命令行界面、HTTP接口和NodeJS API三种使用方式,支持栅格和矢量瓦片,兼容Mapbox及其他瓦片提供商的服务,还可使用本地mbtiles文件进行渲染。
警告:本项目依赖Mapbox GL的NodeJS绑定(
mapbox-gl-native),该绑定已不再由Mapbox维护,且仅支持NodeJS 10(已超出生命周期)。目前项目处于维护模式,主要功能不会有重大更新。
mapbox-gl-native通过NodeJS渲染静态地图使用地图时,需根据数据和样式提供商的要求进行适当归因:
所有渲染方法的核心输入是Mapbox GL Style JSON文件,详细格式参考Mapbox文档。
标签配置
如需使用文本标签,需在Style JSON中添加glyphs字段(与sources同级):
使用Mapbox托管字体(需Mapbox token):
json"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf"
使用OpenMapTiles托管字体:
json"glyphs": "http://fonts.openmaptiles.org/{fontstack}/{range}.pbf"
需使用Babel提供ES6特性支持。
基础示例(中心坐标+缩放级别)
javascriptimport render from 'mbgl-renderer'; import style from 'tests/fixtures/example-style.json'; import fs from 'fs'; const width = 512; const height = 256; const center = [-79.86, 32.68]; const zoom = 10; render(style, width, height, { zoom, center }) .then((data) => { fs.writeFileSync('test.png', data); });
边界范围渲染
javascriptconst width = 512; const height = 256; const bounds = [-80.23, 32.678, -79.73, 32.891]; render(style, width, height, { bounds }) .then((data) => { fs.writeFileSync('test.png', data); });
带内边距的边界渲染
javascriptconst width = 512; const height = 256; const bounds = [-80.23, 32.678, -79.73, 32.891]; const padding = 25; // 像素值,需小于宽/高的1/2 render(style, width, height, { bounds, padding }) .then((data) => { fs.writeFileSync('test.png', data); });
高DPI渲染
javascriptconst width = 512; const height = 256; const center = [-79.86, 32.68]; const zoom = 10; const ratio = 2; // 像素比率,通常>1(已测试最大31) render(style, width, height, { zoom, center, ratio }) .then((data) => { fs.writeFileSync('test.png', data); });
方位角和俯仰角设置
javascriptconst width = 512; const height = 256; const center = [-79.86, 32.68]; const zoom = 10; const bearing = 90; // 方位角(0-360度) const pitch = 30; // 俯仰角(0-60度) render(style, width, height, { zoom, center, bearing, pitch }) .then((data) => { fs.writeFileSync('test.png', data); });
使用Mapbox托管资源(需token)
javascriptrender(style, width, height, { bounds, token: '<your access token>' }) .then((data) => { fs.writeFileSync('test.png', data); });
基本用法
bashmbgl-render <style.json> <img_filename> <width> <height> [options]
选项说明
-c, --center <longitude,latitude>: 地图中心(无空格)-z, --zoom <n>: 缩放级别-r, --ratio <n>: 像素比率-b, --bounds <west,south,east,north>: 边界范围(无空格)--padding <padding>: 内边距像素(仅与bounds配合使用)--bearing <degrees>: 方位角(0-360度)--pitch <degrees>: 俯仰角(0-60度)-t, --tiles <mbtiles_path>: 本地mbtiles文件目录--token <mapbox access token>: Mapbox访问令牌使用示例
中心坐标+缩放级别渲染:
bashmbgl-render tests/fixtures/example-style.json test.png 512 256 -c -79.86,32.68 -z 10
边界范围渲染:
bashmbgl-render tests/fixtures/example-style.json test.png 512 256 -b -80.23,32.678,-79.73,32.891
带内边距的边界渲染:
bashmbgl-render tests/fixtures/example-style.json test.png 512 256 -b -80.23,32.678,-79.73,32.891 --padding 25
使用本地mbtiles:
bashmbgl-render tests/fixtures/example-style-mbtiles-source-vector.json test.png 1024 1024 -z 0 -c 0,0 -t tests/fixtures
使用Mapbox托管样式:
bashmbgl-render mapbox://styles/mapbox/outdoors-v10 test.png 1024 1024 -c 0,0 -z 0 --token <your mapbox token>
启动服务器
bashmbgl-static-server [options]
选项说明
-p, --port <n>: 服务器端口-t, --tiles <mbtiles_path>: 本地mbtiles文件目录-v, --verbose: 启用请求日志启动示例
bash# 启动在8080端口,使用本地tiles目录 mbgl-static-server -p 8080 -t tests/fixtures # 通过npm启动(需使用--传递参数) npm start -- --port 8080 --tiles tests/fixtures
请求方法
GET请求
参数说明:
height/width: 图像尺寸(整数)zoom: 缩放级别(浮点数)ratio: 像素比率(整数)center: 中心坐标(格式:longitude,latitude,无空格)bounds: 边界范围(格式:west,south,east,north,无空格)padding: 内边距(整数,仅与bounds配合使用)bearing: 方位角(0-360度,浮点数)pitch: 俯仰角(0-60度,浮点数)token: Mapbox访问令牌style: URL编码的Style JSON示例:
bash# 使用httpie工具测试 http :8080/render width=400 height=400 zoom=0 center=0,0 style:=@tests/fixtures/example-style.json > /tmp/test.png
POST请求
支持所有GET参数,Style JSON可直接作为JSON传递(无需URL编码),适用于Style JSON过长的场景。
bashdocker pull docker.xuanyuan.run/consbio/mbgl-renderer:latest
bash# 基本运行(端口8080) docker run --rm -p 8080:80 docker.xuanyuan.run/consbio/mbgl-renderer # 挂载本地tiles目录 docker run --rm -p 8080:80 -v $(pwd)/tests/fixtures:/app/tiles docker.xuanyuan.run/consbio/mbgl-renderer
bashdocker build -t <image_name> -f docker/Dockerfile .
mapbox-gl-nativexvfb提供GL环境,参考Dockerfile配置MAPBOX_API_TOKEN环境变量(创建.env.test文件)您可以使用以下命令拉取该镜像。请将 <标签> 替换为具体的标签版本。如需查看所有可用标签版本,请访问 标签列表页面。
来自真实用户的反馈,见证轩辕镜像的优质服务