meface/docs/article/gis/geoserver/mbstyle.md

129 lines
4.2 KiB
Markdown
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
title: mbstyle (Mapbox 样式规范)
date: 2023-10-14
author: ac
tags:
- Mapbox GL
categories:
- GIS
---
> [Mapbox style document](https://www.mapbox.com/mapbox-gl-js/style-spec/) 是一种基于`JSON`的语言,它定义了地图的视觉外观、绘制的数据以及绘制时要使用的顺序数据和样式,`Mapbox`样式的文档是`SLD`的替代品。
<!-- more -->
### 1.简介
`Mapbox` [样式](https://docs.mapbox.com/help/glossary/style/)是定义地图视觉外观的文档:**绘制哪些数据**、绘制数据的**顺序**以及绘制数据时如何设置**数据样式**。
**样式文档结构**
样式文档是具有特定根级别和嵌套属性的[JSON对象](http://www.json.org/),规范定义并描述了这些属性。
Mapbox 样式由一组[根属性](https://docs.mapbox.com/style-spec/reference/root/)组成,其中一些描述单个全局属性,其中一些包含嵌套属性。
某些根属性(例如[`version`](https://docs.mapbox.com/style-spec/reference/root/#version)、[`name`](https://docs.mapbox.com/style-spec/reference/root/#name)和[`metadata`](https://docs.mapbox.com/style-spec/reference/root/#metadata))对地图的外观或行为没有任何影响,但提供与地图相关的重要描述信息。其他要素(如[`layers`](https://docs.mapbox.com/style-spec/reference/layers/)和[`sources`](https://docs.mapbox.com/style-spec/reference/sources/))至关重要,它们决定哪些地图要素将出现在您的地图上以及它们的外观。某些属性(如[`center`](https://docs.mapbox.com/style-spec/reference/root/#center)、[`zoom`](https://docs.mapbox.com/style-spec/reference/root/#zoom)、[`pitch`](https://docs.mapbox.com/style-spec/reference/root/#pitch)和[`bearing`](https://docs.mapbox.com/style-spec/reference/root/#bearing))为地图渲染器提供了一组在初始显示地图时使用的默认值。
### 2. 规范参考
#### 2.1 根级别属性
Mapbox 样式的根级别属性指定地图的图层、图块源、其他资源,以及在其他地方未指定时初始相机位置的默认值。
```json
{
// 必填项
"version": 8,// 样式规范的版本号必须是8
"sources": {...},// 数据源规范。
"layers": [...],// 图层将按照该数组的顺序绘制。
// 选填项
"name": "Mapbox Streets",//样式名称
"sprite": "mapbox://sprites/mapbox/streets-v8",
"glyphs": "mapbox://fonts/mapbox/{fontstack}/{range}.pbf",
"bearing": 29,// 水平方位角,单位:度
"center": [ -73.9749, 40.7736 ], // 默认地图中心点
"fog": {},// 雾也可以叫大气层用于global的三维效果
"light": { // 全局的光源
"anchor": "viewport",
"color": "white",
"intensity": 0.4
},
"metadata": {},// 元数据,自定义属性可以放这里
"pitch": ,// 单位为度默认为0
"projection": ,//d
}
```
#### Layer 属性
- `id`:图层标识
- `type`可选值fill、line、symbol、circle、heatmap、fill-extrusion、raster、hillshade、background、sky
type属性指定图层要渲染的类型
fill带有可选的边界的填充面
line线类型
symbol图标点或label标签图层
circle填充圆
heatmap热力图
fill-extrusion 3D 面
raster栅格影像图层如WSM|WMTS|单张图片
hillshade地形数据
background图层的背景色
sky一个围绕地图的球形圆顶在所有其他图层后面渲染。
-
Layers有两个子属性决定图层layer的渲染`layout` 和 `paint`
+ `layout` 属性出现在图层的`"layout"`对象中。它们在渲染过程的早期应用,并定义该层的数据如何传递到 GPU。该属性的更改需要异步“layout”步骤。
+ *`paint`属性* 稍后在渲染过程中应用,出现在图层的`"paint"`对象中。属性的更改成本低廉并且同步发生。
### 参考文章
[1] Mapbox Style Specification [https://docs.mapbox.com/style-spec/guides/](https://docs.mapbox.com/style-spec/guides/)
[2] mbstyle样式 — GeoServer 2.24.x User Manual (osgeo.cn) [https://www.osgeo.cn/geoserver-user-manual/styling/mbstyle/index.html](https://www.osgeo.cn/geoserver-user-manual/styling/mbstyle/index.html)