@3clear/basegis 0.1.4 → 0.1.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1700 -642
- package/dist/WindDataGrid-B1KZflZc.js +438 -0
- package/dist/assets.js +6 -2
- package/dist/basegis.js +6421 -3070
- package/dist/basemap.config-Bs1PwVYt.js +176 -0
- package/dist/html2canvas.esm-dgT_1dIT.js +4871 -0
- package/dist/layers.js +78 -69
- package/dist/methods.js +1988 -1503
- package/dist/{pointLarge-Ct8TsOPW.js → pointLarge-CNhpMZoP.js} +54 -58
- package/dist/style.css +1 -1
- package/dist/typhoon-path-BAiUgsJf.js +4 -0
- package/package.json +3 -2
- package/dist/WindDataGrid-AGJaASUG.js +0 -96
package/README.md
CHANGED
|
@@ -1,195 +1,394 @@
|
|
|
1
1
|
# @3clear/basegis
|
|
2
2
|
|
|
3
|
-
`@3clear/basegis` 是 3clear 一张图项目抽出的 GIS
|
|
4
|
-
|
|
3
|
+
`@3clear/basegis` 是 3clear 一张图项目抽出的 GIS 能力包,通过统一入口 `BaseGIS` 封装 Cesium / Leaflet 常用 API。业务页面可复用同一套地图逻辑,复杂图层通过 `methods` 控制器组合公共方法;三维专有能力的支持范围见[能力支持说明](#能力支持说明)。
|
|
4
|
+
|
|
5
5
|
当前包包含:
|
|
6
6
|
|
|
7
|
-
- `BaseGIS
|
|
8
|
-
- `methods
|
|
7
|
+
- `BaseGIS`:初始化、引擎切换、视角与底图、[地图截图导出](#map-screenshot)、基础图形、Canvas 图标与扩散 Marker、GeoJSON、DEM、点击事件,以及统一风场、源解析传输、GPU 风场、三维体与剖面。
|
|
8
|
+
- `methods`:多地图实时视角联动、独立线图层、台风路径、图片图层、网格图层、海量点、点位聚合、点位抽稀、等值线、风场等高级控制器。
|
|
9
9
|
- `layers`:天地图、GeoServer 金字塔瓦片、WMS、WMTS 图层配置快捷构造器。
|
|
10
|
-
- `assets
|
|
11
|
-
- `style.css`:Leaflet
|
|
10
|
+
- `assets`:站点、工厂、信息标记和台风中心 SVG 资源。
|
|
11
|
+
- `style.css`:BaseGIS 自有图层、标注和截图框选样式,不内嵌 Leaflet 官方 CSS。
|
|
12
12
|
|
|
13
13
|
## 能力总览
|
|
14
14
|
|
|
15
15
|
以下按类型展示 `@3clear/basegis` 的主要业务能力;工具型辅助函数不单独作为能力卡展示。点击名称可跳转到下方详细说明,完整导入方式见[出口](#出口)。
|
|
16
16
|
|
|
17
|
-
###
|
|
17
|
+
### 快速开始
|
|
18
18
|
|
|
19
|
-
<table>
|
|
19
|
+
<table width="90%">
|
|
20
|
+
<thead>
|
|
21
|
+
<tr>
|
|
22
|
+
<th width="20%"><small>名称</small></th>
|
|
23
|
+
<th width="65%"><small>介绍</small></th>
|
|
24
|
+
<th width="15%"><small>查看</small></th>
|
|
25
|
+
</tr>
|
|
26
|
+
</thead>
|
|
20
27
|
<tbody>
|
|
21
28
|
<tr>
|
|
29
|
+
<td><small><a href="#base-gis-lifecycle"><strong>初始化与生命周期</strong></a></small></td>
|
|
22
30
|
<td>
|
|
23
|
-
<
|
|
24
|
-
<small>Cesium / Leaflet 统一 GIS 主入口 · <a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small>
|
|
31
|
+
<small>创建并初始化 BaseGIS 实例,管理实例状态、尺寸刷新和资源销毁。</small>
|
|
25
32
|
</td>
|
|
33
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
34
|
+
</tr>
|
|
35
|
+
<tr>
|
|
36
|
+
<td><small><a href="#map-init-config"><strong>地图初始化配置</strong></a></small></td>
|
|
37
|
+
<td>
|
|
38
|
+
<small>说明构造参数、init() 参数优先级、完整配置分组,以及 setConfig() 的用法与生效规则。</small>
|
|
39
|
+
</td>
|
|
40
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
41
|
+
</tr>
|
|
42
|
+
<tr>
|
|
43
|
+
<td><small><a href="#engine-switch"><strong>切换引擎</strong></a></small></td>
|
|
44
|
+
<td>
|
|
45
|
+
<small>支持 Cesium / Leaflet 运行时切换,并保留当前视野、恢复托管图层。</small>
|
|
46
|
+
</td>
|
|
47
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-4" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
48
|
+
</tr>
|
|
49
|
+
<tr>
|
|
50
|
+
<td><small><a href="#view-control-scene"><strong>视角控制与场景模式</strong></a></small></td>
|
|
51
|
+
<td>
|
|
52
|
+
<small>支持视角缩放、重置、范围适配,以及 2D、2.5D、3D 场景模式切换。</small>
|
|
53
|
+
</td>
|
|
54
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
55
|
+
</tr>
|
|
56
|
+
<tr>
|
|
57
|
+
<td><small><a href="#map-view-listener"><strong>地图视角监听</strong></a></small></td>
|
|
58
|
+
<td>
|
|
59
|
+
<small>监听地图移动、缩放和视角变化的开始、过程与结束状态。</small>
|
|
60
|
+
</td>
|
|
61
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-36" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
62
|
+
</tr>
|
|
63
|
+
<tr>
|
|
64
|
+
<td><small><a href="#map-click-events"><strong>点击事件</strong></a></small></td>
|
|
65
|
+
<td>
|
|
66
|
+
<small>统一监听 Cesium / Leaflet 地图点击,返回坐标及命中目标信息。</small>
|
|
67
|
+
</td>
|
|
68
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
26
69
|
</tr>
|
|
27
70
|
</tbody>
|
|
28
71
|
</table>
|
|
29
72
|
|
|
30
|
-
###
|
|
73
|
+
### 地图工具(2)
|
|
31
74
|
|
|
32
|
-
<table>
|
|
75
|
+
<table width="90%">
|
|
76
|
+
<thead>
|
|
77
|
+
<tr>
|
|
78
|
+
<th width="20%"><small>名称</small></th>
|
|
79
|
+
<th width="65%"><small>介绍</small></th>
|
|
80
|
+
<th width="15%"><small>查看</small></th>
|
|
81
|
+
</tr>
|
|
82
|
+
</thead>
|
|
33
83
|
<tbody>
|
|
34
84
|
<tr>
|
|
35
|
-
<td
|
|
36
|
-
|
|
37
|
-
<small
|
|
38
|
-
</td>
|
|
39
|
-
<td width="50%">
|
|
40
|
-
<a href="#point-large-layer-controller"><strong>PointLargeLayerController</strong></a><br>
|
|
41
|
-
<small>海量点 · <a href="http://61.50.111.214:31166/lgmap/test-page-5" target="_blank" rel="noopener noreferrer">查看示例</a></small>
|
|
85
|
+
<td><small><a href="#map-screenshot"><strong>地图截图导出</strong></a></small></td>
|
|
86
|
+
<td>
|
|
87
|
+
<small>支持当前视口、框选区域及指定范围截图,并导出 PNG 图片。</small>
|
|
42
88
|
</td>
|
|
89
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-40" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
43
90
|
</tr>
|
|
44
91
|
<tr>
|
|
45
|
-
<td
|
|
46
|
-
|
|
47
|
-
<small
|
|
48
|
-
</td>
|
|
49
|
-
<td width="50%">
|
|
50
|
-
<a href="#point-density-controller"><strong>PointDensityController</strong></a><br>
|
|
51
|
-
<small>点位视野裁剪抽稀 · <a href="http://61.50.111.214:31166/lgmap/test-page-8" target="_blank" rel="noopener noreferrer">查看示例</a></small>
|
|
92
|
+
<td><small><a href="#map-view-link-controller"><strong>多地图联动</strong></a></small></td>
|
|
93
|
+
<td>
|
|
94
|
+
<small>支持多地图实例注册,以及移动、缩放和视角实时联动。</small>
|
|
52
95
|
</td>
|
|
96
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-36" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
53
97
|
</tr>
|
|
54
98
|
</tbody>
|
|
55
99
|
</table>
|
|
56
100
|
|
|
57
|
-
###
|
|
101
|
+
### 通用点位图层(5)
|
|
58
102
|
|
|
59
|
-
<table>
|
|
103
|
+
<table width="90%">
|
|
104
|
+
<thead>
|
|
105
|
+
<tr>
|
|
106
|
+
<th width="20%"><small>名称</small></th>
|
|
107
|
+
<th width="65%"><small>介绍</small></th>
|
|
108
|
+
<th width="15%"><small>查看</small></th>
|
|
109
|
+
</tr>
|
|
110
|
+
</thead>
|
|
60
111
|
<tbody>
|
|
61
112
|
<tr>
|
|
113
|
+
<td><small><a href="#basic-graphics"><strong>基础图形与点位</strong></a></small></td>
|
|
62
114
|
<td>
|
|
63
|
-
<
|
|
64
|
-
<small>独立线图层、实线/虚线、固定/流动渐变与沿线动画 · <a href="http://61.50.111.214:31166/lgmap/test-page-34" target="_blank" rel="noopener noreferrer">查看示例</a></small><br>
|
|
65
|
-
<small>支持:一条或多条经纬度折线,可选图标引领的逐步出线</small>
|
|
115
|
+
<small>绘制点、线、面、文字和 Marker,支持 Cesium / Leaflet。</small>
|
|
66
116
|
</td>
|
|
117
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
118
|
+
</tr>
|
|
119
|
+
<tr>
|
|
120
|
+
<td><small><a href="#point-large-layer-controller"><strong>海量点</strong></a></small></td>
|
|
121
|
+
<td>
|
|
122
|
+
<small>使用批量渲染展示大规模点位数据。</small>
|
|
123
|
+
</td>
|
|
124
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-5" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
125
|
+
</tr>
|
|
126
|
+
<tr>
|
|
127
|
+
<td><small><a href="#point-cluster-controller"><strong>点位聚合</strong></a></small></td>
|
|
128
|
+
<td>
|
|
129
|
+
<small>根据地图视图和缩放层级对邻近点位进行聚合展示。</small>
|
|
130
|
+
</td>
|
|
131
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-29" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
132
|
+
</tr>
|
|
133
|
+
<tr>
|
|
134
|
+
<td><small><a href="#point-density-controller"><strong>点位抽稀</strong></a></small></td>
|
|
135
|
+
<td>
|
|
136
|
+
<small>根据当前视野裁剪点位,并按屏幕密度进行抽稀展示。</small>
|
|
137
|
+
</td>
|
|
138
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-8" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
139
|
+
</tr>
|
|
140
|
+
<tr>
|
|
141
|
+
<td><small><a href="#marker-icons"><strong>图标</strong></a></small></td>
|
|
142
|
+
<td>
|
|
143
|
+
<small>提供项目常用图标及告警扩散效果图标。</small>
|
|
144
|
+
</td>
|
|
145
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-41" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
67
146
|
</tr>
|
|
68
147
|
</tbody>
|
|
69
148
|
</table>
|
|
70
149
|
|
|
71
|
-
###
|
|
150
|
+
### 行政区划边界图层(1)
|
|
72
151
|
|
|
73
|
-
<table>
|
|
152
|
+
<table width="90%">
|
|
153
|
+
<thead>
|
|
154
|
+
<tr>
|
|
155
|
+
<th width="20%"><small>名称</small></th>
|
|
156
|
+
<th width="65%"><small>介绍</small></th>
|
|
157
|
+
<th width="15%"><small>查看</small></th>
|
|
158
|
+
</tr>
|
|
159
|
+
</thead>
|
|
74
160
|
<tbody>
|
|
75
161
|
<tr>
|
|
162
|
+
<td><small><a href="#geojson-layer"><strong>GeoJSON 图层</strong></a></small></td>
|
|
76
163
|
<td>
|
|
77
|
-
<
|
|
78
|
-
<small>图片覆盖层与时次切换 · <a href="http://61.50.111.214:31166/lgmap/test-page-4" target="_blank" rel="noopener noreferrer">查看示例</a></small><br>
|
|
79
|
-
<small>支持:PNG / JPG / WebP 等浏览器图片、灰度图;可配套 GeoTIFF 取值</small>
|
|
164
|
+
<small>支持 GeoJSON 点、线、面、行政区划边界,以及数据驱动的边线、填充和点样式。</small>
|
|
80
165
|
</td>
|
|
166
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-23" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
81
167
|
</tr>
|
|
82
168
|
</tbody>
|
|
83
169
|
</table>
|
|
84
170
|
|
|
85
|
-
###
|
|
171
|
+
### 轨迹路径图层(2)
|
|
86
172
|
|
|
87
|
-
<table>
|
|
173
|
+
<table width="90%">
|
|
174
|
+
<thead>
|
|
175
|
+
<tr>
|
|
176
|
+
<th width="20%"><small>名称</small></th>
|
|
177
|
+
<th width="65%"><small>介绍</small></th>
|
|
178
|
+
<th width="15%"><small>查看</small></th>
|
|
179
|
+
</tr>
|
|
180
|
+
</thead>
|
|
88
181
|
<tbody>
|
|
89
182
|
<tr>
|
|
183
|
+
<td><small><a href="#line-layer-controller"><strong>走航路径</strong></a></small></td>
|
|
184
|
+
<td>
|
|
185
|
+
<small>轨迹折线、逐顶点浓度着色、时间裁剪与沿线动画;底层支持实线/虚线、固定/流动渐变和图标引领的逐步出线。</small>
|
|
186
|
+
</td>
|
|
187
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-43" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
188
|
+
</tr>
|
|
189
|
+
<tr>
|
|
190
|
+
<td><small><a href="#typhoon-path-controller"><strong>台风路径</strong></a></small></td>
|
|
90
191
|
<td>
|
|
91
|
-
<
|
|
92
|
-
<small>栅格数值注记与鼠标探针 · <a href="http://61.50.111.214:31166/lgmap/test-page-4" target="_blank" rel="noopener noreferrer">查看示例</a></small><br>
|
|
93
|
-
<small>支持:GeoTIFF、灰度图、直接数值网格</small>
|
|
192
|
+
<small>实况路径、强度节点、当前中心、四象限风圈、多机构预报与路径播放;支持 Cesium / Leaflet 同一份规范化台风数据与引擎切换恢复。</small>
|
|
94
193
|
</td>
|
|
194
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-10" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
95
195
|
</tr>
|
|
96
196
|
</tbody>
|
|
97
197
|
</table>
|
|
98
198
|
|
|
99
|
-
###
|
|
199
|
+
### 格点填色图层(2)
|
|
100
200
|
|
|
101
|
-
<table>
|
|
201
|
+
<table width="90%">
|
|
202
|
+
<thead>
|
|
203
|
+
<tr>
|
|
204
|
+
<th width="20%"><small>名称</small></th>
|
|
205
|
+
<th width="65%"><small>介绍</small></th>
|
|
206
|
+
<th width="15%"><small>查看</small></th>
|
|
207
|
+
</tr>
|
|
208
|
+
</thead>
|
|
102
209
|
<tbody>
|
|
103
210
|
<tr>
|
|
104
|
-
<td
|
|
105
|
-
|
|
106
|
-
<small
|
|
211
|
+
<td><small><a href="#image-layer-controller"><strong>图片填色图层</strong></a></small></td>
|
|
212
|
+
<td>
|
|
213
|
+
<small>支持 PNG / JPG / WebP 等图片覆盖、灰度图及时次切换,可配套 GeoTIFF 取值。</small>
|
|
107
214
|
</td>
|
|
108
|
-
<td
|
|
109
|
-
|
|
110
|
-
|
|
215
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-4" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
216
|
+
</tr>
|
|
217
|
+
<tr>
|
|
218
|
+
<td><small><a href="#grid-layer-controller"><strong>网格数值图层</strong></a></small></td>
|
|
219
|
+
<td>
|
|
220
|
+
<small>支持 GeoTIFF、灰度图和直接数值网格的数值注记与鼠标探针。</small>
|
|
111
221
|
</td>
|
|
222
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-4" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
112
223
|
</tr>
|
|
113
224
|
</tbody>
|
|
114
225
|
</table>
|
|
115
226
|
|
|
116
|
-
###
|
|
227
|
+
### 等值线图层(2)
|
|
117
228
|
|
|
118
|
-
<table>
|
|
229
|
+
<table width="90%">
|
|
230
|
+
<thead>
|
|
231
|
+
<tr>
|
|
232
|
+
<th width="20%"><small>名称</small></th>
|
|
233
|
+
<th width="65%"><small>介绍</small></th>
|
|
234
|
+
<th width="15%"><small>查看</small></th>
|
|
235
|
+
</tr>
|
|
236
|
+
</thead>
|
|
119
237
|
<tbody>
|
|
120
238
|
<tr>
|
|
239
|
+
<td><small><a href="#contour-layer-controller"><strong>通用等值线</strong></a></small></td>
|
|
121
240
|
<td>
|
|
122
|
-
<
|
|
123
|
-
<small>Cesium 专有;三维标量场体积采样与裁切 · <a href="http://61.50.111.214:31166/lgmap/test-page-14" target="_blank" rel="noopener noreferrer">查看示例</a></small><br>
|
|
124
|
-
<small>支持:一维体数据 + rows / cols / heights 网格维度</small>
|
|
241
|
+
<small>已有等值线数据,支持线平滑、线值标签、中心标注与标注避让。</small>
|
|
125
242
|
</td>
|
|
243
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-19" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
244
|
+
</tr>
|
|
245
|
+
<tr>
|
|
246
|
+
<td><small><a href="#raster-contour-controller"><strong>栅格等值线</strong></a></small></td>
|
|
247
|
+
<td>
|
|
248
|
+
<small>没有等值线数据,需要前端通过格点数据自动生成等值线,支持线平滑、标注避让,可选自动检测 H/L 中心。</small>
|
|
249
|
+
</td>
|
|
250
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-18" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
126
251
|
</tr>
|
|
127
252
|
</tbody>
|
|
128
253
|
</table>
|
|
129
254
|
|
|
130
|
-
###
|
|
255
|
+
### 三维渲染(不支持2维)
|
|
131
256
|
|
|
132
|
-
<table>
|
|
257
|
+
<table width="90%">
|
|
258
|
+
<thead>
|
|
259
|
+
<tr>
|
|
260
|
+
<th width="20%"><small>名称</small></th>
|
|
261
|
+
<th width="65%"><small>介绍</small></th>
|
|
262
|
+
<th width="15%"><small>查看</small></th>
|
|
263
|
+
</tr>
|
|
264
|
+
</thead>
|
|
133
265
|
<tbody>
|
|
134
266
|
<tr>
|
|
267
|
+
<td><small><a href="#dem-terrain"><strong>DEM 地形</strong></a></small></td>
|
|
268
|
+
<td>
|
|
269
|
+
<small>Cesium 专用,支持椭球地形、World Terrain 与地形夸张。</small>
|
|
270
|
+
</td>
|
|
271
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
272
|
+
</tr>
|
|
273
|
+
<tr>
|
|
274
|
+
<td><small><a href="#source-transport"><strong>源解析传输</strong></a></small></td>
|
|
275
|
+
<td>
|
|
276
|
+
<small>展示贡献弧线、灰色烟羽点云、移动烟团与目标汇聚体,体云复用现有体渲染。</small>
|
|
277
|
+
</td>
|
|
278
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-42" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
279
|
+
</tr>
|
|
280
|
+
<tr>
|
|
281
|
+
<td><small><a href="#volume-rendering"><strong>盒子体渲染</strong></a></small></td>
|
|
135
282
|
<td>
|
|
136
|
-
<
|
|
137
|
-
<small>Cesium 专有;按经度、纬度、高度/气压层切片 · <a href="http://61.50.111.214:31166/lgmap/test-page-15" target="_blank" rel="noopener noreferrer">查看示例</a></small><br>
|
|
138
|
-
<small>支持:{ Bound, DataAry } 三维格点数据</small>
|
|
283
|
+
<small>对三维标量场进行体积采样与裁切,支持原位更新体数据及按屏幕位置取值。</small>
|
|
139
284
|
</td>
|
|
285
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-14" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
286
|
+
</tr>
|
|
287
|
+
<tr>
|
|
288
|
+
<td><small><a href="#section-rendering"><strong>切片/剖面渲染</strong></a></small></td>
|
|
289
|
+
<td>
|
|
290
|
+
<small>基于三维格点数据,按经度、纬度或气压层渲染切片与剖面。</small>
|
|
291
|
+
</td>
|
|
292
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-15" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
140
293
|
</tr>
|
|
141
294
|
</tbody>
|
|
142
295
|
</table>
|
|
143
296
|
|
|
144
|
-
###
|
|
297
|
+
### 风场图层(2)
|
|
145
298
|
|
|
146
|
-
<
|
|
299
|
+
<p><small>推荐使用 <a href="#unified-wind-layer"><code>BaseGIS.upsertWindLayer</code></a> 统一入口:Cesium 自动使用 GPU,Leaflet 自动使用 Canvas,切换引擎时自动恢复风场。</small></p>
|
|
300
|
+
|
|
301
|
+
<table width="90%">
|
|
302
|
+
<thead>
|
|
303
|
+
<tr>
|
|
304
|
+
<th width="20%"><small>名称</small></th>
|
|
305
|
+
<th width="65%"><small>介绍</small></th>
|
|
306
|
+
<th width="15%"><small>查看</small></th>
|
|
307
|
+
</tr>
|
|
308
|
+
</thead>
|
|
147
309
|
<tbody>
|
|
148
310
|
<tr>
|
|
311
|
+
<td><small><a href="#gpu-wind-layer"><strong>GPU 风场</strong></a></small></td>
|
|
312
|
+
<td>
|
|
313
|
+
<small>Cesium 专用,使用 GPU 绘制风场粒子,支持地形采样。</small>
|
|
314
|
+
</td>
|
|
315
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-21" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
316
|
+
</tr>
|
|
317
|
+
<tr>
|
|
318
|
+
<td><small><a href="#wind-field-methods"><strong>Canvas 风场</strong></a></small></td>
|
|
149
319
|
<td>
|
|
150
|
-
<
|
|
151
|
-
<small>Cesium / Leaflet 统一粒子风场 · <a href="http://61.50.111.214:31166/lgmap/test-page-21" target="_blank" rel="noopener noreferrer">查看示例</a></small>
|
|
320
|
+
<small>通过 Canvas 在 Cesium / Leaflet 上绘制风场粒子,支持风速底图。</small>
|
|
152
321
|
</td>
|
|
322
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-3" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
153
323
|
</tr>
|
|
154
324
|
</tbody>
|
|
155
325
|
</table>
|
|
156
326
|
|
|
157
|
-
###
|
|
327
|
+
### 影像瓦片图层(4)
|
|
158
328
|
|
|
159
|
-
<table>
|
|
329
|
+
<table width="90%">
|
|
330
|
+
<thead>
|
|
331
|
+
<tr>
|
|
332
|
+
<th width="20%"><small>名称</small></th>
|
|
333
|
+
<th width="65%"><small>介绍</small></th>
|
|
334
|
+
<th width="15%"><small>查看</small></th>
|
|
335
|
+
</tr>
|
|
336
|
+
</thead>
|
|
160
337
|
<tbody>
|
|
161
338
|
<tr>
|
|
162
|
-
<td
|
|
163
|
-
|
|
164
|
-
<small
|
|
339
|
+
<td><small><a href="#layer-config-builders"><strong>天地图图层</strong></a></small></td>
|
|
340
|
+
<td>
|
|
341
|
+
<small>生成天地图矢量、影像、地形及注记图层配置。</small>
|
|
165
342
|
</td>
|
|
166
|
-
<td
|
|
167
|
-
|
|
168
|
-
|
|
343
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
344
|
+
</tr>
|
|
345
|
+
<tr>
|
|
346
|
+
<td><small><a href="#layer-config-builders"><strong>GeoServer 金字塔瓦片</strong></a></small></td>
|
|
347
|
+
<td>
|
|
348
|
+
<small>生成 GeoServer 金字塔瓦片图层配置,支持标准瓦片地址模板。</small>
|
|
169
349
|
</td>
|
|
350
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
170
351
|
</tr>
|
|
171
352
|
<tr>
|
|
172
|
-
<td
|
|
173
|
-
|
|
174
|
-
<small
|
|
353
|
+
<td><small><a href="#layer-config-builders"><strong>WMS 图层</strong></a></small></td>
|
|
354
|
+
<td>
|
|
355
|
+
<small>生成 WMS 服务图层配置,支持图层名称及附加请求参数。</small>
|
|
175
356
|
</td>
|
|
176
|
-
<td
|
|
177
|
-
|
|
178
|
-
|
|
357
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
358
|
+
</tr>
|
|
359
|
+
<tr>
|
|
360
|
+
<td><small><a href="#layer-config-builders"><strong>WMTS 图层</strong></a></small></td>
|
|
361
|
+
<td>
|
|
362
|
+
<small>生成 WMTS 标准瓦片图层配置,可指定 Cesium / Leaflet 引擎支持范围。</small>
|
|
179
363
|
</td>
|
|
364
|
+
<td><small><a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small></td>
|
|
180
365
|
</tr>
|
|
181
366
|
</tbody>
|
|
182
367
|
</table>
|
|
183
368
|
|
|
184
|
-
### Assets 示例资源(
|
|
369
|
+
### Assets 示例资源(4)
|
|
185
370
|
|
|
186
371
|
<table>
|
|
187
372
|
<tbody>
|
|
188
373
|
<tr>
|
|
189
|
-
<td>
|
|
374
|
+
<td width="50%">
|
|
190
375
|
<a href="#gis-marker-sample"><strong>gisMarkerSample</strong></a><br>
|
|
191
376
|
<small>GIS Marker 示例资源 · <a href="http://61.50.111.214:31166/lgmap/test-page-2" target="_blank" rel="noopener noreferrer">查看示例</a></small>
|
|
192
377
|
</td>
|
|
378
|
+
<td width="50%">
|
|
379
|
+
<a href="#typhoon-path-controller"><strong>typhoonPathIcon</strong></a><br>
|
|
380
|
+
<small>台风路径默认中心 SVG · <a href="http://61.50.111.214:31166/lgmap/test-page-10" target="_blank" rel="noopener noreferrer">查看示例</a></small>
|
|
381
|
+
</td>
|
|
382
|
+
</tr>
|
|
383
|
+
<tr>
|
|
384
|
+
<td width="50%">
|
|
385
|
+
<a href="#gis-marker-sample"><strong>gisFactoryMarker</strong></a><br>
|
|
386
|
+
<small>工厂标记 SVG,可配合图片与数值图标使用</small>
|
|
387
|
+
</td>
|
|
388
|
+
<td width="50%">
|
|
389
|
+
<a href="#gis-marker-sample"><strong>gisInfoMarker</strong></a><br>
|
|
390
|
+
<small>信息标记 SVG,可配合图片与名称图标使用</small>
|
|
391
|
+
</td>
|
|
193
392
|
</tr>
|
|
194
393
|
</tbody>
|
|
195
394
|
</table>
|
|
@@ -200,16 +399,43 @@
|
|
|
200
399
|
npm install @3clear/basegis leaflet axios
|
|
201
400
|
```
|
|
202
401
|
|
|
203
|
-
`d3-contour`、`pixi.js
|
|
402
|
+
`d3-contour`、`pixi.js`、`leaflet-pixi-overlay` 和 `html2canvas` 已随 BaseGIS 构建产物发布,业务项目不需要单独安装。其中 Pixi 相关代码只在首次使用 Leaflet 海量点能力时按需加载,`html2canvas` 只在首次调用 Leaflet 截图时按需加载。
|
|
403
|
+
|
|
404
|
+
在应用入口引入 BaseGIS 与自有样式:
|
|
405
|
+
|
|
406
|
+
```js
|
|
407
|
+
import { BaseGIS } from '@3clear/basegis'
|
|
408
|
+
import '@3clear/basegis/style.css'
|
|
409
|
+
```
|
|
410
|
+
|
|
411
|
+
外部依赖版本以 `package.json` 为准:当前为 `leaflet ^1.9.4`、`axios ^1.15.1`。
|
|
412
|
+
|
|
413
|
+
当前限制:完整 BaseGIS 入口中的剖面工具仍在模块加载时访问 `Cesium.Cartesian3`,因此即使只创建 Leaflet 地图,也需在导入 BaseGIS 前加载下文的 Cesium 脚本,否则会报 `Cesium is not defined`。这是既有的引擎依赖问题,与本次 Leaflet CSS 共用处理无关;纯原生 Leaflet 不受此限制。
|
|
204
414
|
|
|
205
|
-
|
|
415
|
+
Leaflet JS 和 `leaflet/dist/leaflet.css` 都由宿主依赖提供。BaseGIS 保留对官方 CSS 的导入,因此上面的原有用法仍然有效;官方规则不再另行内嵌到包的 `style.css` 中。
|
|
416
|
+
|
|
417
|
+
如果项目同时使用原生 Leaflet,可以在应用入口统一引入:
|
|
206
418
|
|
|
207
419
|
```js
|
|
420
|
+
import L from 'leaflet'
|
|
421
|
+
import 'leaflet/dist/leaflet.css'
|
|
422
|
+
import { BaseGIS } from '@3clear/basegis'
|
|
208
423
|
import '@3clear/basegis/style.css'
|
|
209
424
|
```
|
|
210
425
|
|
|
211
|
-
|
|
212
|
-
|
|
426
|
+
确保 BaseGIS 与业务代码解析到同一份安装的 Leaflet,宿主构建器即可复用同路径的 JS / CSS。不同地图使用各自容器;不需要挂载 `window.L` 或注册 Vue 插件,其他模块需要使用 `L` / `BaseGIS` 时仍按需 import。纯原生页面若不导入 BaseGIS JS,必须自行引入 `leaflet/dist/leaflet.css`,仅引入包的 `style.css` 不包含官方规则。
|
|
427
|
+
|
|
428
|
+
Cesium 不随 npm 包发布。使用 Cesium 时,宿主项目需自行加载 `Cesium.js` 和 `Widgets/widgets.css`,并保留 `Workers`、`Assets` 等完整静态目录;初始化前必须能访问 `window.Cesium`。`config.engine.cesium.scriptUrl/cssUrl` 不会自动注入脚本和样式。
|
|
429
|
+
|
|
430
|
+
例如,将完整 Cesium 资源放入 `public/lib/Cesium` 后,在 Vite 的 `index.html` 中、应用入口脚本之前添加:
|
|
431
|
+
|
|
432
|
+
```html
|
|
433
|
+
<script>window.CESIUM_BASE_URL = '%BASE_URL%lib/Cesium/'</script>
|
|
434
|
+
<link rel="stylesheet" href="%BASE_URL%lib/Cesium/Widgets/widgets.css">
|
|
435
|
+
<script src="%BASE_URL%lib/Cesium/Cesium.js"></script>
|
|
436
|
+
```
|
|
437
|
+
|
|
438
|
+
使用 GeoTIFF 数据时,宿主还需提前提供 `window.GeoTIFF`。本文 `/data/...`、`/mock/...` 均为示例数据地址,不包含在 npm 包中,请替换为项目真实地址;部署在子路径时,应结合宿主的 `import.meta.env.BASE_URL` 生成静态资源 URL。
|
|
213
439
|
|
|
214
440
|
## 出口
|
|
215
441
|
|
|
@@ -219,8 +445,9 @@ import { BaseGIS } from '@3clear/basegis'
|
|
|
219
445
|
|
|
220
446
|
// 高级能力控制器
|
|
221
447
|
import {
|
|
222
|
-
GraphicGroupController,
|
|
223
448
|
LineLayerController,
|
|
449
|
+
MapViewLinkController,
|
|
450
|
+
TyphoonPathController,
|
|
224
451
|
ImageLayerController,
|
|
225
452
|
toImageLayerArea,
|
|
226
453
|
GridLayerController,
|
|
@@ -235,13 +462,19 @@ import {
|
|
|
235
462
|
// 图层配置构造器
|
|
236
463
|
import {
|
|
237
464
|
createTiandituLayer,
|
|
465
|
+
createTiandituTileSource,
|
|
238
466
|
createGeoserverPyramidLayer,
|
|
239
467
|
createWmsLayer,
|
|
240
468
|
createWmtsLayer,
|
|
241
469
|
} from '@3clear/basegis/layers'
|
|
242
470
|
|
|
243
471
|
// 示例资源
|
|
244
|
-
import {
|
|
472
|
+
import {
|
|
473
|
+
gisMarkerSample,
|
|
474
|
+
gisFactoryMarker,
|
|
475
|
+
gisInfoMarker,
|
|
476
|
+
typhoonPathIcon,
|
|
477
|
+
} from '@3clear/basegis/assets'
|
|
245
478
|
```
|
|
246
479
|
|
|
247
480
|
## 快速开始
|
|
@@ -280,8 +513,6 @@ onMounted(() => {
|
|
|
280
513
|
basemap: {
|
|
281
514
|
// 默认内置值:tianditu-imagery。
|
|
282
515
|
defaultVisibleId: 'tianditu-imagery',
|
|
283
|
-
// 默认内置值:tianditu-vector-label。
|
|
284
|
-
defaultAnnotationId: 'tianditu-vector-label',
|
|
285
516
|
},
|
|
286
517
|
},
|
|
287
518
|
})
|
|
@@ -297,17 +528,19 @@ onBeforeUnmount(() => {
|
|
|
297
528
|
})
|
|
298
529
|
</script>
|
|
299
530
|
|
|
300
|
-
<style scoped>
|
|
531
|
+
<style scoped lang="scss">
|
|
301
532
|
.map {
|
|
302
533
|
width: 100%;
|
|
303
|
-
height:
|
|
534
|
+
height: 100vh;
|
|
304
535
|
}
|
|
305
536
|
</style>
|
|
306
537
|
```
|
|
307
538
|
|
|
539
|
+
以下 API 示例默认 `mapCore` 已初始化成功;示例中的业务数据、图片和服务地址需由页面准备。组件卸载时先销毁控制器、移除页面监听,再调用 `mapCore.destroy()`。
|
|
540
|
+
|
|
308
541
|
## 返回值约定
|
|
309
542
|
|
|
310
|
-
|
|
543
|
+
操作方法通常返回统一结果对象;图片、GeoJSON、风场等异步加载方法应使用 `await`:
|
|
311
544
|
|
|
312
545
|
```js
|
|
313
546
|
{
|
|
@@ -325,16 +558,326 @@ onBeforeUnmount(() => {
|
|
|
325
558
|
message: 'error message',
|
|
326
559
|
code: 'NOT_INITIALIZED'
|
|
327
560
|
}
|
|
561
|
+
```
|
|
562
|
+
|
|
563
|
+
`getEngineType()`、`getConfig()`、`getMapInstance()` 等读取方法直接返回值;`createMarkerIcon()` 直接返回图标参数或 `null`。控制器的 `getState()` 也返回状态对象,不能一律按 `result.data` 读取。
|
|
564
|
+
|
|
565
|
+
<a id="map-init-config"></a>
|
|
566
|
+
|
|
567
|
+
## 地图初始化与运行时配置
|
|
568
|
+
|
|
569
|
+
`BaseGIS` 的初始化参数分为两类:需要长期保留的默认配置放在构造函数的 `config` 中;只想覆盖本次初始化时,传给 `init(options)`。地图已经创建后,`setConfig()` 只更新实例保存的配置,不会直接改变当前画面;初始化默认值通常需要重新 `init()` 才会生效。
|
|
570
|
+
|
|
571
|
+
| 配置入口 | 适用场景 | 是否写入运行时配置 | 是否立即重建地图 |
|
|
572
|
+
| --- | --- | --- | --- |
|
|
573
|
+
| `new BaseGIS({ ... })` | 创建实例并设置默认引擎、容器和整套配置。 | 是 | 否,仍需调用 `init()`。 |
|
|
574
|
+
| `init(options)` | 创建或重新创建地图,并单次覆盖容器、引擎、场景模式或初始视角。 | `engineType` 会写入;`sceneMode / initialView` 不写入。 | 是 |
|
|
575
|
+
| `setConfig(config)` | 修改实例保存的配置,供后续初始化或配置查询使用。 | 是 | 否 |
|
|
576
|
+
|
|
577
|
+
### 构造参数
|
|
578
|
+
|
|
579
|
+
```js
|
|
580
|
+
const mapCore = new BaseGIS({
|
|
581
|
+
engineType: 'cesium',
|
|
582
|
+
containerId: 'map',
|
|
583
|
+
config: {
|
|
584
|
+
view: {
|
|
585
|
+
defaultSceneMode: '3d',
|
|
586
|
+
initialView: {
|
|
587
|
+
center: [104, 35],
|
|
588
|
+
height: 5000000,
|
|
589
|
+
zoom: 5,
|
|
590
|
+
heading: 0,
|
|
591
|
+
pitch: -90,
|
|
592
|
+
roll: 0,
|
|
593
|
+
},
|
|
594
|
+
},
|
|
595
|
+
},
|
|
596
|
+
})
|
|
597
|
+
```
|
|
598
|
+
|
|
599
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
600
|
+
| --- | --- | --- | --- |
|
|
601
|
+
| `engineType` | `'cesium' \| 'leaflet'` | `config.engine.active`,内置为 `cesium` | 默认引擎。该参数最终覆盖 `config.engine.active`。 |
|
|
602
|
+
| `container` | `HTMLElement \| string` | - | 地图容器 DOM,也兼容传容器 id 字符串。 |
|
|
603
|
+
| `containerId` | `string` | - | 地图容器 id。与 `container` 二选一即可。 |
|
|
604
|
+
| `config` | `Object` | 内置配置 | 推荐的配置入口,与内置配置做深合并。 |
|
|
605
|
+
| `engine / view / basemap / dem / sourceTransport` | `Object` | - | 兼容直接写在构造参数顶层;推荐统一放入 `config`,避免与控制参数混淆。同名配置同时出现时,`config` 中的值优先。 |
|
|
606
|
+
|
|
607
|
+
### `init(options)` 参数与优先级
|
|
608
|
+
|
|
609
|
+
```js
|
|
610
|
+
const result = mapCore.init({
|
|
611
|
+
// 都是选填;构造时已经设置过的内容不需要重复传。
|
|
612
|
+
containerId: 'map',
|
|
613
|
+
engineType: 'cesium',
|
|
614
|
+
sceneMode: '3d',
|
|
615
|
+
initialView: {
|
|
616
|
+
center: [104, 35],
|
|
617
|
+
height: 5000000,
|
|
618
|
+
zoom: 5,
|
|
619
|
+
pitch: -90,
|
|
620
|
+
},
|
|
621
|
+
})
|
|
622
|
+
|
|
623
|
+
if (!result.success) {
|
|
624
|
+
console.warn(result.message)
|
|
625
|
+
}
|
|
626
|
+
```
|
|
627
|
+
|
|
628
|
+
| 参数 | 类型 | 说明 |
|
|
629
|
+
| --- | --- | --- |
|
|
630
|
+
| `container` | `HTMLElement \| string` | 本次使用的容器 DOM 或容器 id,优先级最高。 |
|
|
631
|
+
| `containerId` | `string` | 本次使用的容器 id。 |
|
|
632
|
+
| `engineType` | `'cesium' \| 'leaflet'` | 本次使用的引擎,同时更新实例保存的 `engine.active`。 |
|
|
633
|
+
| `sceneMode` | `'2d' \| '2.5d' \| '3d'` | 本次初始化的场景模式;Leaflet 只支持 `2d`。不会写回 `config.view.defaultSceneMode`。 |
|
|
634
|
+
| `initialView` | `Object` | 本次初始化的视角。不会写回 `config.view.initialView`。 |
|
|
635
|
+
|
|
636
|
+
`init({ config: ... })` 不是有效写法;`init()` 不会合并 `config`。持久配置必须在构造函数中传入,或先调用 `setConfig()`。
|
|
637
|
+
|
|
638
|
+
各参数的实际取值顺序如下,左侧优先级更高:
|
|
328
639
|
|
|
640
|
+
| 项目 | 取值优先级 |
|
|
641
|
+
| --- | --- |
|
|
642
|
+
| 容器 | `init.container` → `init.containerId` → 构造函数 `container` → 构造函数 `containerId` |
|
|
643
|
+
| 引擎 | `init.engineType` → 实例当前引擎(由构造函数 `engineType` 或 `config.engine.active` 得到)→ `cesium` |
|
|
644
|
+
| 场景模式 | Cesium:`init.sceneMode` → `config.view.defaultSceneMode` → `3d`;Leaflet 始终为 `2d` |
|
|
645
|
+
| 初始视角 | `init.initialView` → `config.view.initialView` → 引擎内置安全视角 |
|
|
646
|
+
|
|
647
|
+
重复调用 `init()` 时会先销毁旧 adapter,再创建新地图;BaseGIS 托管图层会异步恢复。`init()` 本身同步返回初始化结果,后续逻辑依赖图层恢复时还需等待:
|
|
648
|
+
|
|
649
|
+
```js
|
|
650
|
+
const result = mapCore.init()
|
|
651
|
+
if (result.success) {
|
|
652
|
+
const restore = await mapCore.whenReady()
|
|
653
|
+
console.log(restore.restored, restore.failed)
|
|
654
|
+
}
|
|
329
655
|
```
|
|
330
656
|
|
|
331
|
-
|
|
657
|
+
### 完整配置分组
|
|
658
|
+
|
|
659
|
+
`config` 当前只有以下五个顶层分组。页面不要直接依赖包内部的 `src/gis/config` 文件;需要查看当前实例最终合并后的配置时,使用 `mapCore.getConfig()`。
|
|
660
|
+
|
|
661
|
+
| 配置组 | 用途 | 主要生效时机 |
|
|
662
|
+
| --- | --- | --- |
|
|
663
|
+
| `engine` | 默认引擎、引擎接入元数据及 Cesium 渲染质量。 | `init()` / 重新 `init()` |
|
|
664
|
+
| `view` | 默认场景模式和初始视角。 | `init()` / 重新 `init()` |
|
|
665
|
+
| `basemap` | 初始底图、可切换底图列表及内置服务元数据。 | `init()`;列表也供 `setBasemapById()` 查询 |
|
|
666
|
+
| `dem` | Cesium 默认地形及可切换地形列表。 | Cesium `init()`;列表也供 `loadDEMById()` 查询 |
|
|
667
|
+
| `sourceTransport` | 源解析传输图层的实例级默认视觉参数。 | 创建 adapter 时锁定;`setConfig()` 后需重新 `init()`,新 adapter 创建图层时才会读取 |
|
|
668
|
+
|
|
669
|
+
#### `engine` 引擎配置
|
|
670
|
+
|
|
671
|
+
| 配置项 | 内置默认值 | 说明 |
|
|
672
|
+
| --- | --- | --- |
|
|
673
|
+
| `engine.active` | `'cesium'` | 默认引擎;构造参数 `engineType` 或 `init({ engineType })` 的优先级更高。 |
|
|
674
|
+
| `engine.cesium.sourceType` | `'local-script'` | Cesium 接入方式说明字段。 |
|
|
675
|
+
| `engine.cesium.scriptUrl` | `'/lib/Cesium/Cesium.js'` | Cesium 脚本地址说明字段;BaseGIS 不会自动加载该脚本。 |
|
|
676
|
+
| `engine.cesium.cssUrl` | `'/lib/Cesium/Widgets/widgets.css'` | Cesium 样式地址说明字段;BaseGIS 不会自动加载该样式。 |
|
|
677
|
+
| `engine.cesium.renderQuality.maximumDevicePixelRatio` | `2` | Cesium 最大设备像素比,实际值限制在 `1~3`;越高越清晰,也越耗 GPU。 |
|
|
678
|
+
| `engine.cesium.renderQuality.fxaa` | `true` | 是否启用 Cesium FXAA。 |
|
|
679
|
+
| `engine.cesium.renderQuality.msaaSamples` | `4` | Cesium MSAA 采样数,取整并限制在 `1~8`。 |
|
|
680
|
+
| `engine.leaflet.sourceType` | `'npm'` | Leaflet 接入方式说明字段。 |
|
|
681
|
+
| `engine.leaflet.packageName` | `'leaflet'` | Leaflet 依赖包名说明字段。 |
|
|
682
|
+
|
|
683
|
+
`scriptUrl / cssUrl` 只是接入元数据。Cesium 资源的实际加载方法见[安装](#安装)。渲染质量在创建 Cesium Viewer 时读取,修改后需要重新 `init()`。
|
|
684
|
+
|
|
685
|
+
#### `view` 视角配置
|
|
686
|
+
|
|
687
|
+
| 配置项 | 内置默认值 | Cesium | Leaflet | 说明 |
|
|
688
|
+
| --- | --- | --- | --- | --- |
|
|
689
|
+
| `view.defaultSceneMode` | `'3d'` | 使用 | 只接受 `2d` | 默认场景,可选 `2d / 2.5d / 3d`。 |
|
|
690
|
+
| `view.initialView.center` | `[121.4737, 31.2304]` | 使用 | 使用 | `[经度, 纬度]`。 |
|
|
691
|
+
| `view.initialView.height` | `1800000` | 使用 | 忽略 | Cesium 相机高度,单位米。 |
|
|
692
|
+
| `view.initialView.zoom` | `7` | 忽略 | 使用 | Leaflet 缩放级别。 |
|
|
693
|
+
| `view.initialView.heading` | `0` | 使用 | 忽略 | Cesium 航向角,单位度。 |
|
|
694
|
+
| `view.initialView.pitch` | `-90` | 使用 | 忽略 | Cesium 俯仰角,单位度;`-90` 表示垂直俯视。 |
|
|
695
|
+
| `view.initialView.roll` | `0` | 使用 | 忽略 | Cesium 翻滚角,单位度。 |
|
|
696
|
+
|
|
697
|
+
#### `basemap` 底图配置
|
|
698
|
+
|
|
699
|
+
| 配置项 | 内置默认值 | 说明 |
|
|
700
|
+
| --- | --- | --- |
|
|
701
|
+
| `basemap.defaultVisibleId` | `'tianditu-imagery'` | 初始化时从 `basemap.list` 选择的底图 id。 |
|
|
702
|
+
| `basemap.defaultAnnotationId` | `'tianditu-vector-label'` | 当前为保留字段,初始化流程尚未读取;注记应通过所选底图项的 `annotationResourceKey` 配置,天地图也会按底图资源自动推断注记。 |
|
|
703
|
+
| `basemap.list` | 内置天地图、WMS、WMTS 示例列表 | 底图资源数组;完整默认项和字段见下方[默认底图配置](#default-basemap-config)。外部传入数组会整体替换内置数组。 |
|
|
704
|
+
| `basemap.providers` | 内置天地图 provider | 内置服务的地址、子域名、token 池及资源映射。当前适配器读取包内 provider,构造参数或 `setConfig()` 中的覆盖值尚不会生效;自定义服务请在 `basemap.list` 中配置 URL。 |
|
|
705
|
+
|
|
706
|
+
#### `dem` 地形配置
|
|
707
|
+
|
|
708
|
+
| 配置项 | 内置默认值 | 说明 |
|
|
709
|
+
| --- | --- | --- |
|
|
710
|
+
| `dem.defaultEnabled` | `true` | Cesium 初始化时是否加载默认 DEM;`false` 时跳过。 |
|
|
711
|
+
| `dem.defaultVisibleId` | `'ellipsoid-flat'` | 默认 DEM id,必须能在 `dem.list` 中找到、`visible !== false` 且支持 Cesium,否则初始化失败。 |
|
|
712
|
+
| `dem.list` | 平面地形、Cesium World Terrain、天地图 DEM 占位项 | DEM 资源数组;外部传入时整体替换。列表项常用字段为 `id / name / sourceType / factory / url / visible / engineSupport / options`,详细用法见[DEM 地形](#dem-terrain)。 |
|
|
713
|
+
|
|
714
|
+
Leaflet 不加载 DEM。`cesium-world-terrain` 需要 Cesium Ion 能力;`tianditu-dem` 是待补真实服务地址的占位项。
|
|
715
|
+
|
|
716
|
+
#### 常用地图初始化配置示例
|
|
717
|
+
|
|
718
|
+
下面示例把真正参与地图创建的常用配置集中写在一起。未传的字段继续使用上表中的内置默认值:
|
|
719
|
+
|
|
720
|
+
```js
|
|
721
|
+
const mapCore = new BaseGIS({
|
|
722
|
+
containerId: 'map',
|
|
723
|
+
config: {
|
|
724
|
+
engine: {
|
|
725
|
+
active: 'cesium',
|
|
726
|
+
cesium: {
|
|
727
|
+
renderQuality: {
|
|
728
|
+
maximumDevicePixelRatio: 2,
|
|
729
|
+
fxaa: true,
|
|
730
|
+
msaaSamples: 4,
|
|
731
|
+
},
|
|
732
|
+
},
|
|
733
|
+
},
|
|
734
|
+
view: {
|
|
735
|
+
defaultSceneMode: '3d',
|
|
736
|
+
initialView: {
|
|
737
|
+
center: [104, 35],
|
|
738
|
+
height: 5000000,
|
|
739
|
+
zoom: 5,
|
|
740
|
+
heading: 0,
|
|
741
|
+
pitch: -90,
|
|
742
|
+
roll: 0,
|
|
743
|
+
},
|
|
744
|
+
},
|
|
745
|
+
basemap: {
|
|
746
|
+
defaultVisibleId: 'tianditu-imagery',
|
|
747
|
+
},
|
|
748
|
+
dem: {
|
|
749
|
+
defaultEnabled: true,
|
|
750
|
+
defaultVisibleId: 'ellipsoid-flat',
|
|
751
|
+
},
|
|
752
|
+
},
|
|
753
|
+
})
|
|
754
|
+
|
|
755
|
+
const result = mapCore.init()
|
|
756
|
+
if (!result.success) {
|
|
757
|
+
console.warn(result.message)
|
|
758
|
+
}
|
|
759
|
+
```
|
|
760
|
+
|
|
761
|
+
#### `sourceTransport` 源解析传输默认配置
|
|
332
762
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
763
|
+
这一组不是地图容器或相机初始化参数,而是 Cesium [源解析传输](#source-transport)图层的实例级默认值。
|
|
764
|
+
|
|
765
|
+
| 配置项 | 内置默认值 | 说明 |
|
|
766
|
+
| --- | --- | --- |
|
|
767
|
+
| `sourceTransport.visible` | `true` | 新建图层默认是否显示。 |
|
|
768
|
+
| `sourceTransport.running` | `true` | 新建图层默认是否播放烟羽动画。 |
|
|
769
|
+
| `sourceTransport.colors` | 内置 7 色数组 | 多来源默认色板。 |
|
|
770
|
+
| `sourceTransport.path` | 内置对象 | 弧线路径分段、高度与弯曲参数。 |
|
|
771
|
+
| `sourceTransport.line` | 内置对象 | 线宽、透明度、辉光、收尖和命中宽度。 |
|
|
772
|
+
| `sourceTransport.smoke` | 内置对象 | 烟羽数量、大小、透明度、扩散和速度。 |
|
|
773
|
+
| `sourceTransport.sourceNode` | 内置对象 | 来源节点大小与标签数量。 |
|
|
774
|
+
| `sourceTransport.targetNode` | 内置对象 | 目标节点颜色与环半径。 |
|
|
775
|
+
| `sourceTransport.volume` | 内置对象 | 目标体云开关、网格尺寸、渲染参数及色带。 |
|
|
776
|
+
| `sourceTransport.interaction` | 内置对象 | 交互开关、命中容差和鼠标样式。 |
|
|
777
|
+
| `sourceTransport.fog` | 内置对象 | 雾效开关与密度。 |
|
|
778
|
+
| `sourceTransport.camera` | 内置对象 | 定位图层时的俯仰角、高度和动画时长。 |
|
|
779
|
+
|
|
780
|
+
单个图层传入的同名参数优先于这里的实例默认值。
|
|
781
|
+
|
|
782
|
+
### 配置合并规则
|
|
783
|
+
|
|
784
|
+
构造函数和 `setConfig()` 使用同一套合并规则:
|
|
785
|
+
|
|
786
|
+
| 数据类型 | 合并方式 |
|
|
787
|
+
| --- | --- |
|
|
788
|
+
| 普通对象 | 按层级递归合并,只传一个叶子字段不会删除同组其他字段。 |
|
|
789
|
+
| 数组 | 整体替换,不会追加;`basemap.list`、`dem.list`、`sourceTransport.colors` 都遵循此规则。 |
|
|
790
|
+
| 基本类型、函数及其他值 | 使用新值替换旧值。 |
|
|
791
|
+
| 未传字段 | 保留当前配置中的值。 |
|
|
792
|
+
|
|
793
|
+
配置会被克隆后保存,不会直接修改包内默认配置。`getConfig()` 返回当前实例持有的配置对象引用,建议只读;修改配置统一调用 `setConfig()`。
|
|
794
|
+
|
|
795
|
+
例如,只覆盖 Cesium 像素比不会丢失 `fxaa` 和 `msaaSamples`:
|
|
796
|
+
|
|
797
|
+
```js
|
|
798
|
+
mapCore.setConfig({
|
|
799
|
+
engine: {
|
|
800
|
+
cesium: {
|
|
801
|
+
renderQuality: {
|
|
802
|
+
maximumDevicePixelRatio: 1.5,
|
|
803
|
+
},
|
|
804
|
+
},
|
|
805
|
+
},
|
|
806
|
+
})
|
|
807
|
+
```
|
|
808
|
+
|
|
809
|
+
如果要在现有底图列表后追加一项,必须自行保留原数组:
|
|
810
|
+
|
|
811
|
+
```js
|
|
812
|
+
const currentConfig = mapCore.getConfig()
|
|
813
|
+
|
|
814
|
+
mapCore.setConfig({
|
|
815
|
+
basemap: {
|
|
816
|
+
list: [
|
|
817
|
+
...currentConfig.basemap.list,
|
|
818
|
+
{
|
|
819
|
+
id: 'custom-xyz',
|
|
820
|
+
name: '自定义 XYZ',
|
|
821
|
+
category: 'basemap',
|
|
822
|
+
type: 'xyz',
|
|
823
|
+
provider: 'custom',
|
|
824
|
+
url: 'https://example.com/tiles/{z}/{x}/{y}.png',
|
|
825
|
+
engineSupport: ['cesium', 'leaflet'],
|
|
826
|
+
},
|
|
827
|
+
],
|
|
828
|
+
},
|
|
829
|
+
})
|
|
830
|
+
```
|
|
831
|
+
|
|
832
|
+
### `setConfig()` 怎么用
|
|
833
|
+
|
|
834
|
+
`setConfig(overrideConfig)` 是同步方法,不校验配置,也没有统一结果对象或其他返回值。它只更新 `BaseGIS` 实例保存的配置,不会把新配置推送给已经创建的 adapter,也不会自动改变当前场景、视角、底图、DEM 或渲染质量。`engine.active` 是一个需要特别注意的例外:它会同步实例记录的引擎类型,但不会真正替换当前底层地图。
|
|
835
|
+
|
|
836
|
+
需要让整套初始化配置生效时,直接再次 `init()`,不要先调用 `destroy()`;否则托管图层快照会被清空:
|
|
837
|
+
|
|
838
|
+
```js
|
|
839
|
+
mapCore.setConfig({
|
|
840
|
+
engine: {
|
|
841
|
+
cesium: {
|
|
842
|
+
renderQuality: {
|
|
843
|
+
maximumDevicePixelRatio: 1.5,
|
|
844
|
+
fxaa: true,
|
|
845
|
+
msaaSamples: 4,
|
|
846
|
+
},
|
|
847
|
+
},
|
|
848
|
+
},
|
|
849
|
+
view: {
|
|
850
|
+
defaultSceneMode: '2d',
|
|
851
|
+
initialView: {
|
|
852
|
+
center: [116.4, 39.9],
|
|
853
|
+
height: 1800000,
|
|
854
|
+
zoom: 7,
|
|
855
|
+
pitch: -90,
|
|
856
|
+
},
|
|
857
|
+
},
|
|
858
|
+
})
|
|
859
|
+
|
|
860
|
+
const result = mapCore.init()
|
|
861
|
+
if (result.success) {
|
|
862
|
+
await mapCore.whenReady()
|
|
863
|
+
}
|
|
864
|
+
```
|
|
865
|
+
|
|
866
|
+
如果目标只是立即操作当前地图,不要用 `setConfig() + init()` 代替已有的实时 API:
|
|
867
|
+
|
|
868
|
+
| 目标 | 推荐 API | 是否重建地图 |
|
|
869
|
+
| --- | --- | --- |
|
|
870
|
+
| 切换 Cesium / Leaflet | `await mapCore.setEngine(engineType)` | 是,并自动恢复托管图层 |
|
|
871
|
+
| 切换当前场景模式 | `mapCore.setSceneMode({ mode })` | 否 |
|
|
872
|
+
| 移动当前视角 | `mapCore.setInitialView(view)` | 否 |
|
|
873
|
+
| 切换当前底图 | `mapCore.setBasemapById(id)` 或 `mapCore.setBasemap(payload)` | 否 |
|
|
874
|
+
| 切换当前 DEM | `mapCore.loadDEMById(id)`、`mapCore.loadDefaultDEM()` 或 `mapCore.loadDEM(payload)` | 否 |
|
|
875
|
+
| 修改当前或新建源解析传输层 | `mapCore.updateSourceTransportLayer(payload)` 或 `mapCore.upsertSourceTransportLayer(payload)` | 否 |
|
|
876
|
+
| 修改 Cesium 渲染质量或整套初始化默认值 | `setConfig()` 后重新 `init()` | 是 |
|
|
877
|
+
|
|
878
|
+
特别注意:不要用 `setConfig({ engine: { active: 'leaflet' } })` 切换已经显示的地图;应直接调用 `setEngine('leaflet')`。前者会让 `getEngineType()` 变成 `leaflet`,但底层仍可能是 Cesium,随后调用相同目标的 `setEngine('leaflet')` 还会被当作“已经是当前引擎”而跳过。若已经这样修改,应调用 `init()` 重建并校正地图实例。
|
|
879
|
+
|
|
880
|
+
<a id="default-basemap-config"></a>
|
|
338
881
|
|
|
339
882
|
### 默认底图配置
|
|
340
883
|
|
|
@@ -343,6 +886,7 @@ onBeforeUnmount(() => {
|
|
|
343
886
|
```js
|
|
344
887
|
basemap: {
|
|
345
888
|
defaultVisibleId: 'tianditu-imagery',
|
|
889
|
+
// 当前为保留字段,初始化时不会读取。
|
|
346
890
|
defaultAnnotationId: 'tianditu-vector-label',
|
|
347
891
|
}
|
|
348
892
|
```
|
|
@@ -354,29 +898,19 @@ basemap: {
|
|
|
354
898
|
| `tianditu-vector` | 天地图矢量底图 | `basemap` | `true` | `wmts` | `tianditu` | `vector` | 可作为 `defaultVisibleId` | Cesium / Leaflet |
|
|
355
899
|
| `tianditu-imagery` | 天地图影像底图 | `basemap` | `true` | `wmts` | `tianditu` | `imagery` | 内置 `defaultVisibleId` | Cesium / Leaflet |
|
|
356
900
|
| `tianditu-terrain` | 天地图地形底图 | `basemap` | `true` | `wmts` | `tianditu` | `terrain` | 可作为 `defaultVisibleId` | Cesium / Leaflet |
|
|
357
|
-
| `tianditu-vector-label` | 天地图矢量注记 | `annotation` | `true` | `wmts` | `tianditu` | `vectorLabel` |
|
|
358
|
-
| `tianditu-terrain-label` | 天地图地形注记 | `annotation` | `true` | `wmts` | `tianditu` | `terrainLabel` |
|
|
359
|
-
|
|
360
|
-
可用于 `defaultVisibleId` 的内置底图 id:
|
|
361
|
-
|
|
362
|
-
- `tianditu-vector`
|
|
363
|
-
- `tianditu-imagery`
|
|
364
|
-
- `tianditu-terrain`
|
|
365
|
-
|
|
366
|
-
可用于 `defaultAnnotationId` 的内置注记 id:
|
|
367
|
-
|
|
368
|
-
- `tianditu-vector-label`
|
|
369
|
-
- `tianditu-terrain-label`
|
|
901
|
+
| `tianditu-vector-label` | 天地图矢量注记 | `annotation` | `true` | `wmts` | `tianditu` | `vectorLabel` | 可作为底图的 `annotationResourceKey` | Cesium / Leaflet |
|
|
902
|
+
| `tianditu-terrain-label` | 天地图地形注记 | `annotation` | `true` | `wmts` | `tianditu` | `terrainLabel` | 可作为底图的 `annotationResourceKey` | Cesium / Leaflet |
|
|
370
903
|
|
|
371
904
|
说明:
|
|
372
905
|
|
|
373
906
|
- `defaultVisibleId` 应指向 `category: 'basemap'` 的底图。
|
|
374
|
-
- `
|
|
907
|
+
- `defaultVisibleId` 找不到可用项时,会回退到 `basemap.list` 中第一个 `enabled !== false`、分类和引擎均匹配的底图;仍找不到时使用内置天地图矢量兜底配置。
|
|
908
|
+
- `defaultAnnotationId` 当前只是保留字段,不参与初始化。要指定注记,给底图项设置 `annotationResourceKey`;天地图矢量、影像和地形底图未显式设置时,也会分别推断对应注记资源。
|
|
375
909
|
- `tianditu-terrain` 是天地图地形底图瓦片,不是 Cesium 的 DEM 高程地形;如果要控制 Cesium terrainProvider,请看后文 DEM。
|
|
376
910
|
- `geoserver-wmts-sample` 和 `geoserver-wms-sample` 默认 `enabled: false`,只是配置格式示例;如果要作为默认底图,需要替换真实服务地址并改为 `enabled: true`。
|
|
377
911
|
- 天地图 provider 内置资源还包括 `imageryLabel`;默认 `basemap.list` 没有单独注册影像注记 id,但 `resourceKey: 'imagery'` 会自动推断使用 `imageryLabel` 注记。
|
|
378
912
|
|
|
379
|
-
###
|
|
913
|
+
### 底图切换
|
|
380
914
|
|
|
381
915
|
底图可以来自 `config.basemap.list`,也可以直接传配置对象。当前适配层支持:
|
|
382
916
|
|
|
@@ -494,9 +1028,11 @@ const basemapList = [
|
|
|
494
1028
|
id: 'weather-wmts',
|
|
495
1029
|
name: '气象 WMTS',
|
|
496
1030
|
category: 'basemap',
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
1031
|
+
engineSupport: ['cesium'],
|
|
1032
|
+
url: 'https://example.com/geoserver/gwc/service/wmts?' +
|
|
1033
|
+
'SERVICE=WMTS&REQUEST=GetTile&VERSION=1.0.0&LAYER=workspace:weather&' +
|
|
1034
|
+
'STYLE=default&TILEMATRIXSET=EPSG:3857&FORMAT=image/png&' +
|
|
1035
|
+
'TILEMATRIX=EPSG:3857:{z}&TILEROW={y}&TILECOL={x}',
|
|
500
1036
|
}),
|
|
501
1037
|
]
|
|
502
1038
|
|
|
@@ -513,15 +1049,23 @@ const mapCore = new BaseGIS({
|
|
|
513
1049
|
|
|
514
1050
|
四个构造器都会保留额外传入字段,便于继续配置 `engineSupport`、缩放级别、注记资源或服务参数。
|
|
515
1051
|
|
|
1052
|
+
`createWmtsLayer()` 只生成配置,不会根据 `layer / tileMatrixSet` 自动拼接请求。自定义 WMTS 需要完整的 GetTile URL 模板,矩阵标识应按服务实际配置填写;XYZ 瓦片同样使用包含 `{z}/{x}/{y}` 的 URL。
|
|
1053
|
+
|
|
1054
|
+
模板瓦片不会自动重投影。上面的 `EPSG:3857` WMTS 示例限定用于 Cesium;当前 Leaflet 使用 `EPSG:4326`,自定义瓦片需匹配地图的坐标系和瓦片矩阵。
|
|
1055
|
+
|
|
1056
|
+
`layers` 还导出辅助函数 `createTiandituTileSource(resourceKey = 'imagery')`,返回 `{ url, subdomains }`,资源不可用时返回 `null`。它供需要直接操作引擎的特殊页面使用,普通页面仍优先调用 `createTiandituLayer()` 和 `BaseGIS`。
|
|
1057
|
+
|
|
516
1058
|
<a id="base-gis"></a>
|
|
517
1059
|
|
|
518
1060
|
## BaseGIS 基础能力
|
|
519
1061
|
|
|
520
1062
|
这一节列的是 `BaseGIS` 主入口直接提供的基础能力。业务页面优先调用这些方法;图片图层、网格图层、海量点、点位聚合、点位抽稀、等值线、风场等更复杂能力,建议使用后文 `methods` 中对应的 Controller。
|
|
521
1063
|
|
|
522
|
-
|
|
1064
|
+
<a id="base-gis-lifecycle"></a>
|
|
1065
|
+
|
|
1066
|
+
### 1. 生命周期与实例
|
|
523
1067
|
|
|
524
|
-
`BaseGIS`
|
|
1068
|
+
`BaseGIS` 负责地图实例的初始化、状态读取、尺寸刷新和销毁。构造参数、完整配置项、参数优先级及 `setConfig()` 的生效规则见[地图初始化与运行时配置](#map-init-config)。
|
|
525
1069
|
|
|
526
1070
|
```js
|
|
527
1071
|
const mapCore = new BaseGIS({
|
|
@@ -529,58 +1073,49 @@ const mapCore = new BaseGIS({
|
|
|
529
1073
|
containerId: 'map',
|
|
530
1074
|
})
|
|
531
1075
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
await mapCore.setEngine('leaflet')
|
|
1076
|
+
const initResult = mapCore.init()
|
|
1077
|
+
if (!initResult.success) {
|
|
1078
|
+
console.warn(initResult.message)
|
|
1079
|
+
}
|
|
537
1080
|
|
|
538
|
-
|
|
539
|
-
mapCore.
|
|
1081
|
+
const engineType = mapCore.getEngineType()
|
|
1082
|
+
const config = mapCore.getConfig() // 只读使用,不要直接修改。
|
|
1083
|
+
const mapInstance = mapCore.getMapInstance()
|
|
540
1084
|
|
|
541
|
-
|
|
542
|
-
mapCore.getEngineType()
|
|
543
|
-
//获取当前地图配置
|
|
544
|
-
mapCore.getConfig()
|
|
545
|
-
//获取地图实例
|
|
546
|
-
mapCore.getMapInstance()
|
|
547
|
-
// 销毁当前地图实例。
|
|
1085
|
+
mapCore.resize()
|
|
548
1086
|
mapCore.destroy()
|
|
549
1087
|
```
|
|
550
1088
|
|
|
551
|
-
Cesium 默认使用最高 2 倍设备像素比、FXAA 和 4 倍 MSAA,避免高分屏上的细线出现明显像素阶梯。可按设备性能覆盖:
|
|
552
|
-
|
|
553
|
-
```js
|
|
554
|
-
const mapCore = new BaseGIS({
|
|
555
|
-
config: {
|
|
556
|
-
engine: {
|
|
557
|
-
cesium: {
|
|
558
|
-
renderQuality: {
|
|
559
|
-
maximumDevicePixelRatio: 1.5,
|
|
560
|
-
fxaa: true,
|
|
561
|
-
msaaSamples: 4,
|
|
562
|
-
},
|
|
563
|
-
},
|
|
564
|
-
},
|
|
565
|
-
},
|
|
566
|
-
})
|
|
567
|
-
```
|
|
568
|
-
|
|
569
1089
|
方法说明:
|
|
570
1090
|
|
|
571
1091
|
| 方法 | 参数 | 说明 |
|
|
572
1092
|
| --- | --- | --- |
|
|
573
|
-
| `init(options)` | `{ container, containerId, engineType }` |
|
|
574
|
-
| `setEngine(engineType, options)` | 引擎类型、初始化参数 | 未初始化时记录默认引擎;已初始化时自动切换、保留视野并恢复托管图层。 |
|
|
575
|
-
| `switchEngine(engineType, options)` | 引擎类型、初始化参数 | `setEngine()` 的兼容别名。 |
|
|
1093
|
+
| `init(options)` | `{ container, containerId, engineType, sceneMode, initialView }` | 初始化地图。重复调用会重建地图并异步恢复 BaseGIS 托管图层。 |
|
|
576
1094
|
| `whenReady()` | 无 | 等待最近一次 `init()` 触发的托管图层恢复完成。 |
|
|
577
1095
|
| `destroy()` | 无 | 销毁当前地图实例和 adapter,并清空托管图层快照。 |
|
|
578
|
-
| `setConfig(config)` | `Object` |
|
|
1096
|
+
| `setConfig(config)` | `Object` | 合并实例配置,无返回值且不自动重建地图;[查看完整规则](#map-init-config)。 |
|
|
579
1097
|
| `getEngineType()` | 无 | 返回当前引擎类型。 |
|
|
580
|
-
| `getConfig()` | 无 |
|
|
1098
|
+
| `getConfig()` | 无 | 返回当前配置对象引用,建议只读。 |
|
|
581
1099
|
| `getMapInstance()` | 无 | 返回底层地图实例:Cesium `viewer` 或 Leaflet `map`。 |
|
|
1100
|
+
| `getMapContainer()` | 无 | 返回统一结果,`data.container` 为地图容器 DOM。 |
|
|
1101
|
+
| `resize()` | 无 | 在容器尺寸改变、隐藏面板重新显示后刷新地图尺寸。 |
|
|
1102
|
+
|
|
1103
|
+
<a id="engine-switch"></a>
|
|
1104
|
+
|
|
1105
|
+
### 2. 切换引擎
|
|
1106
|
+
|
|
1107
|
+
`BaseGIS` 支持 `cesium` 和 `leaflet` 两种引擎。调用 `setEngine()` 可以在运行时切换引擎、保留当前视野,并恢复 BaseGIS 托管图层。
|
|
1108
|
+
|
|
1109
|
+
| 方法 | 参数 | 说明 |
|
|
1110
|
+
| --- | --- | --- |
|
|
1111
|
+
| `setEngine(engineType, options)` | 引擎类型、初始化参数 | 未初始化时记录默认引擎;已初始化时自动切换、保留视野并恢复托管图层。 |
|
|
1112
|
+
| `switchEngine(engineType, options)` | 引擎类型、初始化参数 | `setEngine()` 的兼容别名。 |
|
|
1113
|
+
|
|
1114
|
+
目标引擎与当前引擎相同时,`setEngine()` 会直接返回,不会应用 `options.sceneMode / initialView / container`。同一引擎下调整场景或视角应调用 `setSceneMode()`、`setInitialView()`;需要重建地图时直接调用 `init()`。
|
|
582
1115
|
|
|
583
|
-
|
|
1116
|
+
发生实际切换时,`setEngine()` 会把目标场景模式,以及显式传入或从当前地图保留的视角写回 `config.view`,供之后再次初始化使用。
|
|
1117
|
+
|
|
1118
|
+
#### 推荐写法
|
|
584
1119
|
|
|
585
1120
|
页面上做 Cesium / Leaflet 切换时,直接调用 `setEngine()`。它会保留当前视野、重建目标引擎,并等待托管图层自动恢复。
|
|
586
1121
|
|
|
@@ -614,27 +1149,32 @@ if (result.success) {
|
|
|
614
1149
|
|
|
615
1150
|
`switchEngine()` 作为兼容别名保留,行为与 `setEngine()` 一致。
|
|
616
1151
|
|
|
1152
|
+
<a id="managed-layer-restore"></a>
|
|
1153
|
+
|
|
617
1154
|
#### 切换后的图层处理
|
|
618
1155
|
|
|
619
1156
|
引擎切换不是把 Cesium 图层对象“搬到” Leaflet,也不是把 Leaflet 图层对象“搬到” Cesium。BaseGIS 会保存托管图层的业务参数,并在新 adapter 中重新创建图层。
|
|
620
1157
|
|
|
621
|
-
-
|
|
1158
|
+
- 自动恢复范围包括图片、网格、海量点、点位聚合、点位抽稀、独立线、源解析传输、台风路径、等值线、统一风场和三维体图层。
|
|
622
1159
|
- 图层最新的数据参数、显隐、清空、删除、海量点删除和高亮状态会同步到 BaseGIS 快照。
|
|
623
1160
|
- 快照只保存业务参数引用,不复制大数组,不保存任何底层引擎对象。
|
|
624
|
-
-
|
|
1161
|
+
- 三维体、源解析传输切到 Leaflet 时会返回不支持结果,但快照仍保留,切回 Cesium 后会继续恢复。
|
|
625
1162
|
- Cesium 专有能力在 Leaflet 下不可用,例如 DEM、三维体渲染、三维切片/剖面渲染。
|
|
626
|
-
-
|
|
1163
|
+
- 基础绘制对象、GeoJSON、点击/视图监听、GPU 专用风场、独立 `WindFieldMethods`、剖面图层和页面直接创建的底层引擎对象不在托管范围内,需要业务重新加载或绑定。
|
|
627
1164
|
|
|
628
1165
|
切换结果中可以查看恢复明细:
|
|
629
1166
|
|
|
630
1167
|
```js
|
|
631
1168
|
const result = await mapCore.setEngine('leaflet')
|
|
632
|
-
console.log(result.data
|
|
633
|
-
console.log(result.data
|
|
1169
|
+
console.log(result.data?.restore?.restored)
|
|
1170
|
+
console.log(result.data?.restore?.failed)
|
|
634
1171
|
```
|
|
635
1172
|
|
|
1173
|
+
`result.success` 表示引擎初始化/切换是否成功,不保证每个图层都恢复成功;应同时检查 `data.restore.failed`。不要在切换前先调用 `destroy()`,它会清空托管快照。
|
|
636
1174
|
|
|
637
|
-
|
|
1175
|
+
<a id="view-control-scene"></a>
|
|
1176
|
+
|
|
1177
|
+
### 3. 视角控制与场景模式
|
|
638
1178
|
|
|
639
1179
|
视角控制分为缩放、重置视角、设置初始视角、场景模式切换、视图状态读取和视图变化监听。
|
|
640
1180
|
|
|
@@ -688,6 +1228,13 @@ const viewStateResult = mapCore.getViewState()
|
|
|
688
1228
|
// Cesium 通常包含 center / bounds / height / heading / pitch / roll / engineType。
|
|
689
1229
|
// Leaflet 通常包含 center / bounds / zoom / engineType。
|
|
690
1230
|
|
|
1231
|
+
// 让地图适配指定经纬度范围,可用于多地图首次统一范围。
|
|
1232
|
+
mapCore.fitViewBounds({
|
|
1233
|
+
bounds: { west: 73, south: 18, east: 135, north: 54 },
|
|
1234
|
+
animate: false,
|
|
1235
|
+
padding: 0,
|
|
1236
|
+
})
|
|
1237
|
+
|
|
691
1238
|
// 经纬度转地图容器像素坐标,常用于自定义 HTML 浮层定位。
|
|
692
1239
|
const pointResult = mapCore.projectToContainerPoint({
|
|
693
1240
|
longitude: 104,
|
|
@@ -697,6 +1244,8 @@ const pointResult = mapCore.projectToContainerPoint({
|
|
|
697
1244
|
// pointResult.data: { x, y }
|
|
698
1245
|
```
|
|
699
1246
|
|
|
1247
|
+
<a id="map-view-listener"></a>
|
|
1248
|
+
|
|
700
1249
|
视图变化监听:
|
|
701
1250
|
|
|
702
1251
|
```js
|
|
@@ -708,6 +1257,10 @@ const viewListener = mapCore.onViewChange({
|
|
|
708
1257
|
// 缩放过程中要实时刷新点位样式时,优先用 onChange。
|
|
709
1258
|
onChange() {},
|
|
710
1259
|
|
|
1260
|
+
// Cesium 交互期间逐渲染帧检测相机变化;适合多地图实时联动。
|
|
1261
|
+
// 默认 false,普通业务监听无需开启。
|
|
1262
|
+
continuous: true,
|
|
1263
|
+
|
|
711
1264
|
// Cesium: camera.moveEnd / morphComplete;Leaflet: moveend / zoomend / resize。
|
|
712
1265
|
onEnd() {},
|
|
713
1266
|
|
|
@@ -730,13 +1283,98 @@ viewListener.data?.off?.()
|
|
|
730
1283
|
| `setSceneMode(payload)` | `'2d'/'2.5d'/'3d'` 或 `{ mode, duration, preserveView }` | 切换场景模式。 |
|
|
731
1284
|
| `getSceneMode()` | 无 | 获取当前场景模式。 |
|
|
732
1285
|
| `getViewBounds()` | 无 | 获取当前视图经纬度边界。 |
|
|
733
|
-
| `getViewState()` |
|
|
734
|
-
| `
|
|
1286
|
+
| `getViewState(payload)` | 可选 `{includeBounds:false}` | 获取当前视图状态;实时同引擎联动可关闭较重的范围采样。 |
|
|
1287
|
+
| `fitViewBounds(payload)` | `{bounds:{west,south,east,north},animate?,padding?,duration?}` | 适配指定经纬度范围;`duration` 仅用于 Cesium 动画。 |
|
|
1288
|
+
| `onViewChange(payload)` | `{ onStart, onChange, onEnd, endDelay, continuous? }` | 监听视图变化,返回 `{ off }`;Cesium 开启 `continuous` 后交互期间逐帧检测。 |
|
|
735
1289
|
| `projectToContainerPoint(payload)` | `{ longitude, latitude, height }` | 经纬度投影到地图容器像素坐标。 |
|
|
736
1290
|
|
|
737
|
-
|
|
1291
|
+
<a id="map-screenshot"></a>
|
|
1292
|
+
|
|
1293
|
+
### 4. 地图截图与导出
|
|
1294
|
+
|
|
1295
|
+
`screenshot()` 用于导出当前 Cesium 或 Leaflet 地图,两个引擎使用完全相同的调用方式、参数和结果对象。默认截取当前可视范围(地图视口)并下载 PNG,不会自动拼接视口外尚未渲染的地图内容;只截取地图内容,不包含页面工具栏、弹窗等地图容器外的 DOM 浮层。
|
|
1296
|
+
|
|
1297
|
+
框选遮罩样式包含在 `@3clear/basegis/style.css` 中,使用 npm 包时应按安装章节导入该样式文件。
|
|
1298
|
+
|
|
1299
|
+
在线示例:[地图截图与 PNG 导出](http://61.50.111.214:31166/lgmap/test-page-40)。
|
|
1300
|
+
|
|
1301
|
+
#### 直接下载 PNG
|
|
1302
|
+
|
|
1303
|
+
默认 `download: true`,页面不需要自己创建下载链接或处理 Blob。`fileName` 可指定文件名;不传时使用前缀和时间戳自动命名。
|
|
1304
|
+
|
|
1305
|
+
```js
|
|
1306
|
+
// 截取当前可视范围并直接下载。
|
|
1307
|
+
const result = await mapCore.screenshot({ fileName: 'weather-map.png' })
|
|
1308
|
+
if (!result.success) {
|
|
1309
|
+
console.warn('截图导出失败', result.code, result.message)
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
// 左键拖拽框选区域,松开后下载;右键或 Esc 取消。
|
|
1313
|
+
const selectResult = await mapCore.screenshot({
|
|
1314
|
+
mode: 'select',
|
|
1315
|
+
namePrefix: 'map-select',
|
|
1316
|
+
})
|
|
1317
|
+
if (!selectResult.success && selectResult.code !== 'CANCELLED') {
|
|
1318
|
+
console.warn('框选导出失败', selectResult.message)
|
|
1319
|
+
}
|
|
1320
|
+
```
|
|
1321
|
+
|
|
1322
|
+
#### 按范围裁剪导出
|
|
1323
|
+
|
|
1324
|
+
```js
|
|
1325
|
+
// 按当前视野中的经纬度范围裁剪。
|
|
1326
|
+
await mapCore.screenshot({
|
|
1327
|
+
namePrefix: 'east-china',
|
|
1328
|
+
bounds: { west: 115, south: 25, east: 123, north: 36 },
|
|
1329
|
+
})
|
|
1330
|
+
|
|
1331
|
+
// 按相对当前地图视口左上角的 CSS 像素区域裁剪。
|
|
1332
|
+
await mapCore.screenshot({
|
|
1333
|
+
rect: { left: 120, top: 80, width: 640, height: 360 },
|
|
1334
|
+
})
|
|
1335
|
+
```
|
|
1336
|
+
|
|
1337
|
+
#### 获取 Blob,不自动下载
|
|
1338
|
+
|
|
1339
|
+
```js
|
|
1340
|
+
const captureResult = await mapCore.screenshot({
|
|
1341
|
+
download: false,
|
|
1342
|
+
fileName: 'weather-map.png',
|
|
1343
|
+
})
|
|
1344
|
+
if (captureResult.success) {
|
|
1345
|
+
const { blob, fileName, width, height } = captureResult.data
|
|
1346
|
+
// 页面可将 blob 交给自己的预览或上传逻辑,BaseGIS 不会自动上传。
|
|
1347
|
+
console.log(blob, fileName, width, height)
|
|
1348
|
+
}
|
|
1349
|
+
```
|
|
1350
|
+
|
|
1351
|
+
#### 方法与参数
|
|
1352
|
+
|
|
1353
|
+
| 方法 | 参数 | 说明 |
|
|
1354
|
+
| --- | --- | --- |
|
|
1355
|
+
| `screenshot(payload)` | `{ mode?, download?, fileName?, namePrefix?, bounds?, area?, rect?, screenRect? }` | 截取 Cesium / Leaflet 地图;`mode: 'select'` 进入交互框选,`download` 默认为 `true`。 |
|
|
1356
|
+
| `cancelScreenshotSelection(reason?)` | 可选取消原因字符串 | 主动取消正在进行的框选;返回布尔值,表示是否取消了现有框选。 |
|
|
1357
|
+
|
|
1358
|
+
| 参数 | 默认值 | 说明 |
|
|
1359
|
+
| --- | --- | --- |
|
|
1360
|
+
| `mode` | 省略 | 默认直接截图;`'select'` 进入鼠标框选,也可简写为 `screenshot('select')`。 |
|
|
1361
|
+
| `download` | `true` | 自动触发浏览器下载;传 `false` 只生成截图结果。 |
|
|
1362
|
+
| `fileName` | 自动生成 | 优先于 `namePrefix`;未以 `.png` 结尾时自动追加扩展名。当前仅导出 PNG。 |
|
|
1363
|
+
| `namePrefix` | `map-screenshot` | 自动文件名前缀;未指定名称的框选截图默认使用 `map-select`。 |
|
|
1364
|
+
| `bounds` / `area` | 当前视口 | 经纬度范围别名,支持 `{ west, south, east, north }` 或 `{ startLon, startLat, endLon, endLat }`。 |
|
|
1365
|
+
| `rect` / `screenRect` | 当前视口 | 屏幕区域别名,支持 `{ left, top, width, height }`,也可用 `x / y` 代替 `left / top`;单位为相对地图视口左上角的 CSS 像素。 |
|
|
1366
|
+
|
|
1367
|
+
取消框选时,原 `screenshot()` Promise 返回 `success: false`、`code: 'CANCELLED'` 和 `data.cancelled: true`;页面通常无需按错误弹窗处理。
|
|
1368
|
+
|
|
1369
|
+
成功结果的 `data` 包含 `blob`、`width`、`height`、`mimeType`、`fileName`、`downloaded`、`screenRect` 和 `pixelRect`。Cesium 读取 WebGL 场景画布;Leaflet 在首次调用时按需加载 DOM 渲染器,合成瓦片、SVG、Canvas 和 DOM Marker,并排除 Leaflet 自带控件。跨域地图资源需要服务端允许 CORS,否则对应资源可能缺失或截图返回 `FAILED`。为保证 WebGL 截图可靠,Cesium 初始化时会保留 drawing buffer;在超高分辨率大屏上会增加一定显存占用。
|
|
1370
|
+
|
|
1371
|
+
`width / height / pixelRect` 使用导出图片的实际像素,可能与 CSS 像素不同;`downloaded: true` 仅表示已触发下载,不代表浏览器已确认文件保存到磁盘。导出范围始终限制在当前视口内,不是整页长截图,也不支持自动加载并拼接屏幕外瓦片。
|
|
738
1372
|
|
|
739
|
-
|
|
1373
|
+
<a id="basic-graphics"></a>
|
|
1374
|
+
|
|
1375
|
+
### 5. 绘制点、线、面、文字和 Marker
|
|
1376
|
+
|
|
1377
|
+
这些方法用于轻量绘制和样例验证。大量点位请优先使用后文的 `PointLargeLayerController`、`PointClusterController`、`PointDensityController` 等控制器。
|
|
740
1378
|
|
|
741
1379
|
点:
|
|
742
1380
|
|
|
@@ -827,11 +1465,188 @@ mapCore.addMarker({
|
|
|
827
1465
|
})
|
|
828
1466
|
```
|
|
829
1467
|
|
|
1468
|
+
<a id="marker-icons"></a>
|
|
1469
|
+
|
|
1470
|
+
#### Canvas 数据图标与扩散效果
|
|
1471
|
+
|
|
1472
|
+
`mapCore.createMarkerIcon(options, data)` 支持圆点、“数值 + 名称”、气象风向、“图片 + 名称”和“图片 + 数值 + 名称”五种 Canvas 样式。圆点用法:
|
|
1473
|
+
|
|
1474
|
+
```js
|
|
1475
|
+
const station = {
|
|
1476
|
+
id: 'station-1',
|
|
1477
|
+
name: '示例站点',
|
|
1478
|
+
position: [104, 35],
|
|
1479
|
+
value: 28.6,
|
|
1480
|
+
status: 'normal',
|
|
1481
|
+
windDirection: 90,
|
|
1482
|
+
windSpeed: 6,
|
|
1483
|
+
}
|
|
1484
|
+
|
|
1485
|
+
const markerIcon = mapCore.createMarkerIcon({
|
|
1486
|
+
type: 'dot',
|
|
1487
|
+
size: 18,
|
|
1488
|
+
color: '#64748b',
|
|
1489
|
+
getColor(data) {
|
|
1490
|
+
if (data.status === 'normal') return '#00e600'
|
|
1491
|
+
if (data.status === 'warning') return '#a67824'
|
|
1492
|
+
return '#6b7280'
|
|
1493
|
+
},
|
|
1494
|
+
}, station)
|
|
1495
|
+
|
|
1496
|
+
mapCore.addMarker({
|
|
1497
|
+
id: station.id,
|
|
1498
|
+
name: station.name,
|
|
1499
|
+
position: station.position,
|
|
1500
|
+
data: station,
|
|
1501
|
+
...markerIcon,
|
|
1502
|
+
})
|
|
1503
|
+
```
|
|
1504
|
+
|
|
1505
|
+
“数值 + 名称”用法:
|
|
1506
|
+
|
|
1507
|
+
```js
|
|
1508
|
+
const markerIcon = mapCore.createMarkerIcon({
|
|
1509
|
+
type: 'value-label',
|
|
1510
|
+
value: station.value,
|
|
1511
|
+
label: station.name,
|
|
1512
|
+
showLabel: station.showName !== false,
|
|
1513
|
+
color: '#64748b',
|
|
1514
|
+
getColor(data) {
|
|
1515
|
+
if (data.status === 'normal') return '#00e600'
|
|
1516
|
+
if (data.status === 'warning') return '#a67824'
|
|
1517
|
+
return '#6b7280'
|
|
1518
|
+
},
|
|
1519
|
+
}, station)
|
|
1520
|
+
|
|
1521
|
+
mapCore.addMarker({
|
|
1522
|
+
id: station.id,
|
|
1523
|
+
name: station.name,
|
|
1524
|
+
position: station.position,
|
|
1525
|
+
data: station,
|
|
1526
|
+
...markerIcon,
|
|
1527
|
+
})
|
|
1528
|
+
```
|
|
1529
|
+
|
|
1530
|
+
气象风向用法:
|
|
1531
|
+
|
|
1532
|
+
```js
|
|
1533
|
+
const markerIcon = mapCore.createMarkerIcon({
|
|
1534
|
+
type: 'wind',
|
|
1535
|
+
direction: station.windDirection,
|
|
1536
|
+
label: station.name,
|
|
1537
|
+
showLabel: station.showName !== false,
|
|
1538
|
+
color: '#64748b',
|
|
1539
|
+
getColor(data) {
|
|
1540
|
+
if (data.windSpeed >= 17.2) return '#e5484d'
|
|
1541
|
+
if (data.windSpeed >= 10.8) return '#f59e0b'
|
|
1542
|
+
if (data.windSpeed >= 5.5) return '#2f80ed'
|
|
1543
|
+
return '#00e600'
|
|
1544
|
+
},
|
|
1545
|
+
}, station)
|
|
1546
|
+
|
|
1547
|
+
mapCore.addMarker({
|
|
1548
|
+
id: station.id,
|
|
1549
|
+
position: station.position,
|
|
1550
|
+
data: station,
|
|
1551
|
+
...markerIcon,
|
|
1552
|
+
})
|
|
1553
|
+
```
|
|
1554
|
+
|
|
1555
|
+
“图片 + 名称”用法:
|
|
1556
|
+
|
|
1557
|
+
```js
|
|
1558
|
+
import { gisInfoMarker } from '@3clear/basegis/assets'
|
|
1559
|
+
|
|
1560
|
+
const stationImage = new Image()
|
|
1561
|
+
// 跨域图片需由服务端允许 CORS,并在设置 src 前配置 crossOrigin。
|
|
1562
|
+
stationImage.src = gisInfoMarker
|
|
1563
|
+
await stationImage.decode()
|
|
1564
|
+
|
|
1565
|
+
const markerIcon = mapCore.createMarkerIcon({
|
|
1566
|
+
type: 'image-label',
|
|
1567
|
+
image: stationImage,
|
|
1568
|
+
imageSize: [20, 20],
|
|
1569
|
+
label: station.name,
|
|
1570
|
+
showLabel: station.showName !== false,
|
|
1571
|
+
}, station)
|
|
1572
|
+
|
|
1573
|
+
mapCore.addMarker({
|
|
1574
|
+
id: station.id,
|
|
1575
|
+
position: station.position,
|
|
1576
|
+
data: station,
|
|
1577
|
+
...markerIcon,
|
|
1578
|
+
})
|
|
1579
|
+
```
|
|
1580
|
+
|
|
1581
|
+
“图片 + 数值 + 名称”用法:
|
|
1582
|
+
|
|
1583
|
+
```js
|
|
1584
|
+
import { gisFactoryMarker } from '@3clear/basegis/assets'
|
|
1585
|
+
|
|
1586
|
+
const company = { id: 'factory-1', name: '示例企业', emissionValue: 12.5 }
|
|
1587
|
+
const factoryImage = new Image()
|
|
1588
|
+
factoryImage.src = gisFactoryMarker
|
|
1589
|
+
await factoryImage.decode()
|
|
1590
|
+
|
|
1591
|
+
const markerIcon = mapCore.createMarkerIcon({
|
|
1592
|
+
type: 'image-value-label',
|
|
1593
|
+
image: factoryImage,
|
|
1594
|
+
imageSize: [14, 14],
|
|
1595
|
+
value: company.emissionValue,
|
|
1596
|
+
label: company.name,
|
|
1597
|
+
showValue: company.showValue !== false,
|
|
1598
|
+
showLabel: company.showName !== false,
|
|
1599
|
+
}, company)
|
|
1600
|
+
|
|
1601
|
+
mapCore.addMarker({
|
|
1602
|
+
id: company.id,
|
|
1603
|
+
position: [104.2, 35.1],
|
|
1604
|
+
data: company,
|
|
1605
|
+
...markerIcon,
|
|
1606
|
+
})
|
|
1607
|
+
```
|
|
1608
|
+
|
|
1609
|
+
`getColor(data)` 同步接收 `createMarkerIcon` 第二个参数传入的原始数据并返回 CSS 颜色。回调异常、返回非法颜色或空值时使用 `options.color`,再无有效静态颜色时使用默认灰色。圆点 `size` 默认 18px,允许 4~96px,并使用中心锚点。`value-label` 的 `value` 位于上方彩色色块,`label` 位于下方白色名称块;`showLabel: false` 时只显示数值块,图标宽高和锚点会自动更新。`wind` 的 `direction` 使用角度,`0` 指向正上方(北)、`90` 指向右侧(东),按顺时针方向增加;`label` 位于下方白色名称块,`showLabel: false` 时可隐藏,风速颜色分级完全由业务回调决定。`image-label` 的 `image` 接收已加载的 CanvasImageSource,`imageSize` 控制图片尺寸;URL 图片应先加载一次再传入,以保持抽稀回调同步。`image-value-label` 在同一规则上增加右侧 `value` 和蓝色圆角色块;`showValue: false` 时不绘制数值底板,只保留图片本身,`showLabel: false` 可独立隐藏名称。两者都隐藏时得到纯图片图标,画布尺寸和锚点会按照 `imageSize` 自动收缩。该类型使用整数锚点减少低 DPR 下的文字模糊。返回的 `iconUrl/iconSize/iconAnchor` 可用于普通 Marker、点位抽稀及其他图片点位能力。
|
|
1610
|
+
|
|
1611
|
+
Cesium / Leaflet 双引擎扩散 Marker:
|
|
1612
|
+
|
|
1613
|
+
```js
|
|
1614
|
+
mapCore.addMarker({
|
|
1615
|
+
id: 'alarm-station',
|
|
1616
|
+
name: '告警站点',
|
|
1617
|
+
position: [121.48, 31.23],
|
|
1618
|
+
data: station,
|
|
1619
|
+
iconUrl: '/marker.png',
|
|
1620
|
+
iconSize: [34, 40],
|
|
1621
|
+
pulse: {
|
|
1622
|
+
color: '#22d3ee',
|
|
1623
|
+
size: 88,
|
|
1624
|
+
duration: 2,
|
|
1625
|
+
ringCount: 2,
|
|
1626
|
+
ringWidth: 2,
|
|
1627
|
+
ringOpacity: 0.72,
|
|
1628
|
+
},
|
|
1629
|
+
clampToGround: true,
|
|
1630
|
+
onClick({ data }) {
|
|
1631
|
+
console.log(data)
|
|
1632
|
+
},
|
|
1633
|
+
})
|
|
1634
|
+
```
|
|
1635
|
+
|
|
1636
|
+
`pulse` 只是图标下方的效果层,不会生成中心点。`pulse.size` 是最大扩散直径(像素),`ringWidth` 是独立的屏幕像素线宽,`ringOpacity` 是圆环不透明度;`duration` 是单个圆环的周期(秒),`ringCount` 支持 1~3。页面不需要判断当前引擎;Leaflet 使用 SVG 动画,Cesium 使用 Billboard 缩放动画,两端保持相同的半径、线宽、透明度和相位变化曲线。只传 `pulse` 时仅显示扩散环;与 `iconUrl` 同时传入时,图标显示在扩散环上层。
|
|
1637
|
+
|
|
830
1638
|
<a id="gis-marker-sample"></a>
|
|
831
1639
|
|
|
832
|
-
#### 使用
|
|
1640
|
+
#### 使用 SVG 资源
|
|
833
1641
|
|
|
834
|
-
`
|
|
1642
|
+
`assets` 导出的资源均为可直接用于 `iconUrl` 的 SVG URL;传给 Canvas 图标的 `image` 时则需要先加载为图片对象。
|
|
1643
|
+
|
|
1644
|
+
| 导出 | 用途 |
|
|
1645
|
+
| --- | --- |
|
|
1646
|
+
| `gisMarkerSample` | 基础 Marker 示例。 |
|
|
1647
|
+
| `gisFactoryMarker` | 工厂标记,适合企业排放数据。 |
|
|
1648
|
+
| `gisInfoMarker` | 信息标记,适合站点名称与数值。 |
|
|
1649
|
+
| `typhoonPathIcon` | 台风路径默认中心图标。 |
|
|
835
1650
|
|
|
836
1651
|
```js
|
|
837
1652
|
import { gisMarkerSample } from '@3clear/basegis/assets'
|
|
@@ -862,13 +1677,115 @@ mapCore.clearGraphics()
|
|
|
862
1677
|
| `drawLine(payload)` | 线配置 | 绘制线。 |
|
|
863
1678
|
| `drawPolygon(payload)` | 面配置 | 绘制面。 |
|
|
864
1679
|
| `drawText(payload)` | 文字配置 | 绘制文字。 |
|
|
865
|
-
| `
|
|
1680
|
+
| `createMarkerIcon(options, data)` | 图标配置、原始数据 | 直接返回 `iconUrl/iconSize/iconAnchor`;未知 `type` 返回 `null`。 |
|
|
1681
|
+
| `addMarker(payload)` | Marker 配置 | 绘制图片或 `pulse` 扩散 Marker;未传图片或扩散参数时,Cesium 使用点、Leaflet 使用默认 Marker。 |
|
|
866
1682
|
| `removeGraphic(payload)` | 图形 id 或 `{ id }` | 删除指定图形。 |
|
|
867
1683
|
| `clearGraphics()` | 无 | 清空通过基础绘制方法创建的图形。 |
|
|
868
1684
|
|
|
869
1685
|
|
|
870
1686
|
|
|
871
|
-
|
|
1687
|
+
<a id="geojson-layer"></a>
|
|
1688
|
+
|
|
1689
|
+
### 6. GeoJSON 图层
|
|
1690
|
+
|
|
1691
|
+
`upsertGeoJsonLayer()` 用同一个 `layerId` 创建或替换 GeoJSON 点、线、面图层,两个引擎共用数据与样式参数。图层基础样式使用 `style`,按要素覆盖的完整样式由 `styleCallback(feature, index)` 返回。坐标按 GeoJSON 顺序传入 `[经度, 纬度, 可选高度]`。
|
|
1692
|
+
|
|
1693
|
+
```js
|
|
1694
|
+
const result = await mapCore.upsertGeoJsonLayer({
|
|
1695
|
+
layerId: 'region-boundaries',
|
|
1696
|
+
data: {
|
|
1697
|
+
type: 'FeatureCollection',
|
|
1698
|
+
features: [{
|
|
1699
|
+
type: 'Feature',
|
|
1700
|
+
id: 'region-1',
|
|
1701
|
+
properties: {
|
|
1702
|
+
name: '示例区域',
|
|
1703
|
+
},
|
|
1704
|
+
geometry: {
|
|
1705
|
+
type: 'Polygon',
|
|
1706
|
+
coordinates: [[[103, 34], [105, 34], [105, 36], [103, 36], [103, 34]]],
|
|
1707
|
+
},
|
|
1708
|
+
}],
|
|
1709
|
+
},
|
|
1710
|
+
styleCallback(feature) {
|
|
1711
|
+
return {
|
|
1712
|
+
color: '#36d3ff',
|
|
1713
|
+
weight: 3,
|
|
1714
|
+
opacity: 1,
|
|
1715
|
+
dashArray: '8 4',
|
|
1716
|
+
fillColor: '#1677ff',
|
|
1717
|
+
fillOpacity: 0.4,
|
|
1718
|
+
}
|
|
1719
|
+
},
|
|
1720
|
+
onClick({ feature, properties }) {
|
|
1721
|
+
console.log(properties.name, feature)
|
|
1722
|
+
},
|
|
1723
|
+
})
|
|
1724
|
+
|
|
1725
|
+
if (result.success && result.data.bounds) {
|
|
1726
|
+
mapCore.fitViewBounds({ bounds: result.data.bounds, animate: false })
|
|
1727
|
+
}
|
|
1728
|
+
```
|
|
1729
|
+
|
|
1730
|
+
| 参数 | 说明 |
|
|
1731
|
+
| --- | --- |
|
|
1732
|
+
| `layerId` | 必填,图层唯一 id。 |
|
|
1733
|
+
| `data` | 必填;支持 FeatureCollection、Feature、Geometry、Feature 数组、JSON 字符串或 URL。也兼容 `geojson / geoJson / source / url`。 |
|
|
1734
|
+
| `fetchOptions` | 使用 URL 时传给 Fetch 的请求参数。业务接口通常由宿主 `api/modules` 获取后再传入 `data`。 |
|
|
1735
|
+
| `style` | 统一样式:`color / weight / opacity / dashArray / fillColor / fillOpacity / stroke / fill`;Leaflet 圆点大小用 `radius`,Cesium 标记大小用 `markerSize`。 |
|
|
1736
|
+
| `styleCallback(feature, index)` | 按数据返回样式覆盖;线、面支持全部 `style` 字段,点还支持 `radius / markerSize`;异常时使用基础样式。 |
|
|
1737
|
+
| `onClick(event)` | 返回 `layerId / feature / properties / data / event / target / engineType`;`data` 为原始 Feature。 |
|
|
1738
|
+
| `visible` | 默认 `true`。 |
|
|
1739
|
+
| `clampToGround` | Cesium 是否贴地,默认 `true`。 |
|
|
1740
|
+
|
|
1741
|
+
```js
|
|
1742
|
+
mapCore.hideGeoJsonLayer({ layerId: 'region-boundaries' })
|
|
1743
|
+
mapCore.showGeoJsonLayer({ layerId: 'region-boundaries' })
|
|
1744
|
+
const stateResult = mapCore.getGeoJsonLayerState({ layerId: 'region-boundaries' })
|
|
1745
|
+
console.log(stateResult.data) // layerId / layerType / visible / featureCount / bounds
|
|
1746
|
+
|
|
1747
|
+
mapCore.clearGeoJsonLayer({ layerId: 'region-boundaries' }) // 清空要素,保留图层。
|
|
1748
|
+
mapCore.removeGeoJsonLayer({ layerId: 'region-boundaries' }) // 删除图层。
|
|
1749
|
+
```
|
|
1750
|
+
|
|
1751
|
+
`styleCallback` 可直接返回完整样式;需要按要素变化时,在回调中读取 `feature.properties` 后决定返回值即可。`opacity: 0`、`fillOpacity: 0`、`stroke: false`、`fill: false` 都会按原值保留。两个引擎都会渲染虚线,但 `dashArray` 的具体节奏是近似效果。
|
|
1752
|
+
|
|
1753
|
+
上述管理方法也可直接传 id 字符串;方法名兼容大写 `GeoJSON`,例如 `upsertGeoJSONLayer()`。更新时需重新提供完整数据和样式。GeoJSON 当前不在自动恢复清单中,切换引擎后需重新调用 `upsertGeoJsonLayer()`。
|
|
1754
|
+
|
|
1755
|
+
<a id="dem-terrain"></a>
|
|
1756
|
+
|
|
1757
|
+
### 7. DEM 地形
|
|
1758
|
+
|
|
1759
|
+
仅 Cesium 支持。默认使用 `ellipsoid-flat` 椭球地形;`tianditu-terrain` 是底图瓦片,不会提供高程。当前 DEM 接口支持椭球和 Cesium World Terrain,配置中的 `tianditu-dem` 仍是占位项,不能作为已实现地形源使用。
|
|
1760
|
+
|
|
1761
|
+
```js
|
|
1762
|
+
// 使用 World Terrain 前,宿主需准备 Cesium Ion 等所需凭据与网络访问。
|
|
1763
|
+
const result = mapCore.loadDEMById('cesium-world-terrain')
|
|
1764
|
+
if (!result.success) {
|
|
1765
|
+
console.warn(result.message)
|
|
1766
|
+
} else if (result.data.loading) {
|
|
1767
|
+
// 某些 Cesium 版本异步加载地形;调用返回成功不等于地形已经就绪。
|
|
1768
|
+
const provider = await result.data.readyPromise
|
|
1769
|
+
if (!provider) console.warn('World Terrain 加载失败')
|
|
1770
|
+
}
|
|
1771
|
+
|
|
1772
|
+
mapCore.setTerrainExaggeration({ factor: 2 })
|
|
1773
|
+
console.log(mapCore.getDEMState().data)
|
|
1774
|
+
```
|
|
1775
|
+
|
|
1776
|
+
| 方法 | 说明 |
|
|
1777
|
+
| --- | --- |
|
|
1778
|
+
| `loadDEMById(id)` | 从 `config.dem.list` 查找地形配置,常用 `ellipsoid-flat / cesium-world-terrain`。 |
|
|
1779
|
+
| `loadDEM(payload)` | 直接传配置;支持 `{ id, sourceType: 'ellipsoid-flat' }` 或 `{ id, sourceType: 'cesium-official', factory: 'worldTerrain' }`。 |
|
|
1780
|
+
| `loadDefaultDEM()` | 按当前 `config.dem` 加载默认地形。 |
|
|
1781
|
+
| `getDEMState()` | `data` 返回 `{ id, enabled, exaggeration }`;`enabled` 按 `id !== 'ellipsoid-flat'` 判断,不代表异步地形已就绪。 |
|
|
1782
|
+
| `setTerrainExaggeration(payload)` | 传数字或 `{ factor }`,范围 `1~10`。 |
|
|
1783
|
+
|
|
1784
|
+
恢复平面地形可调用 `mapCore.loadDEMById('ellipsoid-flat')`。Leaflet 不提供 DEM;调用失败时应检查 `success / code / message`,不要直接假定结果包含地形状态。
|
|
1785
|
+
|
|
1786
|
+
<a id="map-click-events"></a>
|
|
1787
|
+
|
|
1788
|
+
### 8. 点击事件
|
|
872
1789
|
|
|
873
1790
|
`onClick` 注册地图点击事件;`offClick` 移除当前点击监听。当前每个 adapter 只保留一个基础点击监听,重复调用 `onClick` 会先移除旧监听。
|
|
874
1791
|
|
|
@@ -935,50 +1852,149 @@ Leaflet 当前返回坐标点击:
|
|
|
935
1852
|
- 海量点、点位聚合、点位抽稀等图层自己的点击事件,应使用对应 Controller 的点击回调参数。
|
|
936
1853
|
|
|
937
1854
|
|
|
938
|
-
<a id="
|
|
1855
|
+
<a id="map-view-link-controller"></a>
|
|
939
1856
|
|
|
940
|
-
##
|
|
1857
|
+
## 多地图联动(双屏联动)
|
|
941
1858
|
|
|
942
|
-
|
|
1859
|
+
`MapViewLinkController` 注册多个已经初始化的 BaseGIS,并实时同步拖动、缩放和视角。每个地图仍可独立加载不同模式、时次和图层;控制器只负责视角,不创建地图,也不会在 `unregisterMap()`、`clear()` 或 `destroy()` 时销毁 BaseGIS。
|
|
1860
|
+
|
|
1861
|
+
在线示例:[查看分屏布局中的页面地图联动](http://61.50.111.214:31166/lgmap/test-page-36)。布局可混合地图、图表和表格,地图实例与联动由页面管理。
|
|
943
1862
|
|
|
944
1863
|
```js
|
|
945
|
-
import {
|
|
1864
|
+
import { BaseGIS } from '@3clear/basegis'
|
|
1865
|
+
import { MapViewLinkController } from '@3clear/basegis/methods'
|
|
946
1866
|
|
|
947
|
-
const
|
|
1867
|
+
const mapA = new BaseGIS({
|
|
1868
|
+
engineType: 'leaflet',
|
|
1869
|
+
containerId: 'map-a',
|
|
1870
|
+
})
|
|
1871
|
+
const mapB = new BaseGIS({
|
|
1872
|
+
engineType: 'leaflet',
|
|
1873
|
+
containerId: 'map-b',
|
|
1874
|
+
})
|
|
1875
|
+
mapA.init()
|
|
1876
|
+
mapB.init()
|
|
1877
|
+
|
|
1878
|
+
const viewLinks = new MapViewLinkController({
|
|
1879
|
+
enabled: true,
|
|
1880
|
+
realtime: true,
|
|
1881
|
+
mode: 'all', // all | leader | group
|
|
1882
|
+
strategy: 'auto', // auto | view | bounds
|
|
1883
|
+
leaderId: 'map-a',
|
|
1884
|
+
syncInterval: 32, // 实时同步间隔,约 30fps
|
|
1885
|
+
})
|
|
948
1886
|
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
type: 'point',
|
|
952
|
-
id: 'p1',
|
|
953
|
-
longitude: 104,
|
|
954
|
-
latitude: 35,
|
|
955
|
-
},
|
|
956
|
-
{
|
|
957
|
-
type: 'line',
|
|
958
|
-
id: 'l1',
|
|
959
|
-
positions: [
|
|
960
|
-
[103, 34],
|
|
961
|
-
[105, 36],
|
|
962
|
-
],
|
|
963
|
-
},
|
|
964
|
-
{
|
|
965
|
-
type: 'text',
|
|
966
|
-
id: 't1',
|
|
967
|
-
longitude: 104,
|
|
968
|
-
latitude: 35,
|
|
969
|
-
text: '站点',
|
|
970
|
-
},
|
|
971
|
-
])
|
|
1887
|
+
viewLinks.registerMap('map-a', mapA, { group: 'forecast' })
|
|
1888
|
+
viewLinks.registerMap('map-b', mapB, { group: 'forecast' })
|
|
972
1889
|
|
|
973
|
-
|
|
974
|
-
|
|
1890
|
+
// 获取 BaseGIS、底层地图实例和全部 id -> BaseGIS 映射。
|
|
1891
|
+
const registeredMapA = viewLinks.getMap('map-a')
|
|
1892
|
+
const leafletMapA = viewLinks.getNativeMap('map-a')
|
|
1893
|
+
const allMaps = viewLinks.getMaps()
|
|
1894
|
+
|
|
1895
|
+
// 以 map-a 为操作源放大,并实时同步其他地图。
|
|
1896
|
+
viewLinks.zoomIn({ mapId: 'map-a', step: 1 })
|
|
1897
|
+
|
|
1898
|
+
// 程序化控制全部注册地图。
|
|
1899
|
+
viewLinks.setView({ center: [104, 34], zoom: 5, height: 5000000 })
|
|
1900
|
+
viewLinks.fitBounds({ bounds: { west: 73, south: 18, east: 135, north: 54 } })
|
|
1901
|
+
|
|
1902
|
+
// 页面卸载:控制器先解绑,地图仍由页面自己销毁。
|
|
1903
|
+
viewLinks.destroy()
|
|
1904
|
+
mapA.destroy()
|
|
1905
|
+
mapB.destroy()
|
|
975
1906
|
```
|
|
976
1907
|
|
|
1908
|
+
构造参数:
|
|
1909
|
+
|
|
1910
|
+
| 参数 | 类型 | 默认值 | 说明 |
|
|
1911
|
+
| --- | --- | --- | --- |
|
|
1912
|
+
| `enabled` | `Boolean` | `true` | 是否开启联动。 |
|
|
1913
|
+
| `realtime` | `Boolean` | `true` | `true` 按动画帧同步移动/缩放;`false` 只在操作结束时同步。 |
|
|
1914
|
+
| `mode` | `String` | `'all'` | `all` 任意图控制;`leader` 仅主图;`group` 仅同组地图。 |
|
|
1915
|
+
| `strategy` | `String` | `'auto'` | `auto` 自动选择;`view` 优先中心和层级/高度;`bounds` 使用视图范围。 |
|
|
1916
|
+
| `leaderId` | `String` | `''` | 主图 id;空值会使用首个注册地图。 |
|
|
1917
|
+
| `syncInterval` | `Number` | `32` | 实时同步的最小间隔,单位 ms;默认约 30fps,降低多 Cesium 实例同时渲染的压力。 |
|
|
1918
|
+
| `suppressionMs` | `Number` | `220` | 被同步地图的事件抑制时长,避免反向循环。 |
|
|
1919
|
+
| `endDelay` | `Number` | `80` | Cesium 操作结束事件延迟,单位 ms。 |
|
|
1920
|
+
| `onStateChange` | `Function` | `null` | 注册、模式、主图和操作结束后的回调,参数为 `{ reason, state }`。 |
|
|
1921
|
+
|
|
1922
|
+
联动与实例方法:
|
|
1923
|
+
|
|
1924
|
+
| 方法 | 参数 | 返回 / 说明 |
|
|
1925
|
+
| --- | --- | --- |
|
|
1926
|
+
| `registerMap(id,mapCore,options)` | `options:{group?,enabled?,replace?}` | 注册已初始化的 BaseGIS 并绑定实时视图监听。 |
|
|
1927
|
+
| `unregisterMap(id)` | 地图 id | 解除监听和注册,不销毁 BaseGIS。 |
|
|
1928
|
+
| `refreshMap(id)` | 地图 id | `BaseGIS.setEngine()` 后重新绑定新 adapter 的监听。 |
|
|
1929
|
+
| `getMap(id)` | 地图 id | 返回 BaseGIS 或 `null`。 |
|
|
1930
|
+
| `getNativeMap(id)` | 地图 id | 返回 Cesium Viewer / Leaflet Map 或 `null`。 |
|
|
1931
|
+
| `getMaps()` | 无 | 返回新的 `Map<id, BaseGIS>`,修改它不会改变控制器注册表。 |
|
|
1932
|
+
| `getMapIds()` / `hasMap(id)` | 可选 id | 查询注册状态。 |
|
|
1933
|
+
| `forEachMap(callback)` | `(mapCore,id,entry)` | 遍历已注册 BaseGIS。 |
|
|
1934
|
+
| `getLeaderMap()` / `getActiveMap()` | 无 | 获取主图或最近操作地图。 |
|
|
1935
|
+
| `setLeader(id)` | 地图 id | 设置主图。 |
|
|
1936
|
+
| `setMode(mode)` | `all/leader/group` | 更新联动模式。 |
|
|
1937
|
+
| `setStrategy(strategy)` | `auto/view/bounds` | 更新视角映射策略。 |
|
|
1938
|
+
| `setMapGroup(id,group)` | 地图 id、组名 | 更新地图所在联动组。 |
|
|
1939
|
+
| `setMapEnabled(id,enabled)` | 地图 id、布尔值 | 单独启停某张地图的联动。 |
|
|
1940
|
+
| `setEnabled(enabled)` / `pause()` / `resume()` | 可选布尔值 | 整体启停联动。 |
|
|
1941
|
+
| `setRealtime(realtime)` | 布尔值 | 切换实时或操作结束后同步。 |
|
|
1942
|
+
| `syncFrom(id,options)` | 地图 id、`force/strategy` 等 | 立即把指定地图视角同步给目标地图。 |
|
|
1943
|
+
|
|
1944
|
+
统一视角操作:
|
|
1945
|
+
|
|
1946
|
+
| 方法 | 参数 | 说明 |
|
|
1947
|
+
| --- | --- | --- |
|
|
1948
|
+
| `zoomIn(payload)` | `{mapId?,step?,distance?}` | 按显式 `mapId`、最近活动地图、主图的顺序选取操作源,再按联动规则同步。 |
|
|
1949
|
+
| `zoomOut(payload)` | 同上 | 缩小并同步。 |
|
|
1950
|
+
| `setView(payload)` | `center,zoom,height,heading,pitch,roll` | 设置全部注册地图视角。 |
|
|
1951
|
+
| `fitBounds(payload)` | `{bounds,animate?,padding?,duration?}` | 让全部地图适配相同范围。 |
|
|
1952
|
+
| `resetView(payload)` | 可选视角 | 重置全部地图。 |
|
|
1953
|
+
| `resizeAll(payload)` | 可选参数 | 刷新全部地图容器尺寸。 |
|
|
1954
|
+
| `getState()` | 无 | 返回模式、主图、注册地图、最近同步来源等状态。 |
|
|
1955
|
+
| `clear()` / `destroy()` | 无 | 解绑全部监听并释放引用,不销毁 BaseGIS。 |
|
|
1956
|
+
|
|
1957
|
+
`setView / fitBounds / resetView / resizeAll` 始终作用于所有注册地图,不受联动分组或暂停状态限制。
|
|
1958
|
+
|
|
1959
|
+
同为 Leaflet 时会同步 `center + zoom`;同为 Cesium 时会直接同步相机经纬度、`height + heading/pitch/roll`;两种视图模型无法直接对应时,`auto` 才会计算并使用 `bounds`。Cesium 交互期间会逐帧检测相机变化,再按 `syncInterval` 合并为最新状态写入目标地图,避免目标地图追赶稀疏跳点,也避免四五个 Cesium 实例每帧重复计算完整视域。一次拖动期间会锁定唯一交互源,目标地图的程序化相机事件不会反向接管并形成反馈循环。
|
|
1960
|
+
|
|
1961
|
+
> BaseGIS 切换引擎会重建 adapter,原视图监听随旧 adapter 销毁。切换完成后调用 `viewLinks.refreshMap(id)`;控制器不会劫持或改写 `BaseGIS.setEngine()`。
|
|
1962
|
+
|
|
1963
|
+
|
|
977
1964
|
<a id="line-layer-controller"></a>
|
|
978
1965
|
|
|
979
1966
|
## LineLayerController
|
|
980
1967
|
|
|
981
|
-
独立管理一组折线,支持整体更新、显隐、清空、销毁和引擎切换恢复。每条线必须提供唯一 `id` 和至少两个 `[longitude, latitude, height?]`
|
|
1968
|
+
独立管理一组折线,支持整体更新、显隐、清空、销毁和引擎切换恢复。每条线必须提供唯一 `id` 和至少两个 `[longitude, latitude, height?]` 坐标点;同一控制器同一时刻只播放一条线的逐步出线动画。
|
|
1969
|
+
|
|
1970
|
+
### 逐顶点色专题线与时间裁剪
|
|
1971
|
+
|
|
1972
|
+
`lines[].colors` 是六位 HEX 数组,长度必须与 `positions` 完全一致,颜色沿每两个相邻顶点连续插值,优先于 `style.color`:
|
|
1973
|
+
|
|
1974
|
+
```js
|
|
1975
|
+
import { LineLayerController } from '@3clear/basegis/methods'
|
|
1976
|
+
|
|
1977
|
+
const lineLayer = new LineLayerController({ mapCore, layerId: 'sampling-tracks' })
|
|
1978
|
+
const startTime = Date.parse('2026-08-28T08:00:00+08:00')
|
|
1979
|
+
await lineLayer.load({
|
|
1980
|
+
lines: [{
|
|
1981
|
+
id: 'sampling-track',
|
|
1982
|
+
positions: [[113.30, 22.60], [113.31, 22.61]],
|
|
1983
|
+
colors: ['#00FF00', '#FF3B30'],
|
|
1984
|
+
times: [startTime, startTime + 60000],
|
|
1985
|
+
}],
|
|
1986
|
+
style: { width: 5, opacity: 1, clampToGround: false },
|
|
1987
|
+
animation: { enabled: false },
|
|
1988
|
+
currentTime: startTime,
|
|
1989
|
+
})
|
|
1990
|
+
|
|
1991
|
+
lineLayer.setTime(startTime + 30000) // 显示前 30 秒已走过的路线。
|
|
1992
|
+
lineLayer.setTime(null) // 恢复完整路线。
|
|
1993
|
+
```
|
|
1994
|
+
|
|
1995
|
+
需要行驶回放时,为各条线附加 `times: [起点毫秒时间戳, 终点毫秒时间戳, ...]`,长度与坐标相同且严格递增。`load` 可设置 `currentTime`,加载后调用 `lineLayer.setTime(time)` 裁掉未来部分;`setTime(null)` 恢复完整路线。不带 `times` 的线不参与裁剪。成功返回 `{ success: true, data: { layerId, currentTime } }`,非法时间返回友好失败结果。
|
|
1996
|
+
|
|
1997
|
+
Cesium 使用一个批量 Primitive 做顶点色插值,时间用相对秒数存入顶点,回放每帧仅改材质参数。Leaflet 使用共享 Canvas 重绘已走过的线段,不重新投影或创建图层。这是实线专题叠加,不能与虚线、流动、单线 reveal 或贴地混用;Cesium 关闭深度测试,带时间的采样按直线连接,不用于地形遮挡/贴合,位置必须不同。数据/配色更新仍为全量替换,显隐和引擎切换保留时间。浓度映射、分车/断线、时钟和小车属于业务层;参考项目 `/test-page-43`。
|
|
982
1998
|
|
|
983
1999
|
### 实线、虚线与纯色
|
|
984
2000
|
|
|
@@ -1089,6 +2105,10 @@ flightLine.restartAnimation()
|
|
|
1089
2105
|
| 参数 | 默认值 | 说明 |
|
|
1090
2106
|
| --- | --- | --- |
|
|
1091
2107
|
| `layerId` | `line-default` | 独立线图层 id。 |
|
|
2108
|
+
| `lines` | `[]` | 折线数组,每项包含唯一 `id` 和至少两个 `positions` 坐标。 |
|
|
2109
|
+
| `lines[].colors` | - | 与坐标等长的六位 HEX 数组,优先于 `style.color`;用于实线专题叠加。 |
|
|
2110
|
+
| `lines[].times` | - | 与坐标等长、严格递增的有限毫秒时间戳;必须与 `colors` 配合。 |
|
|
2111
|
+
| `currentTime` | `null` | 路线时间裁剪位置;`null` 显示全部。 |
|
|
1092
2112
|
| `visible` | `true` | 初始是否可见。 |
|
|
1093
2113
|
| `style.color` | `#2f80ff` | 纯色字符串或渐变对象。 |
|
|
1094
2114
|
| `style.width` / `style.opacity` | `3` / `1` | 线宽和透明度。 |
|
|
@@ -1104,17 +2124,166 @@ flightLine.restartAnimation()
|
|
|
1104
2124
|
|
|
1105
2125
|
| 方法 | 说明 |
|
|
1106
2126
|
| --- | --- |
|
|
1107
|
-
| `mount(mapCore)` | 后挂载 BaseGIS。 |
|
|
1108
|
-
| `load(payload, options?)` / `update(payload)` | 加载或更新线、样式和动画。 |
|
|
1109
|
-
| `
|
|
1110
|
-
| `
|
|
1111
|
-
| `
|
|
1112
|
-
| `
|
|
1113
|
-
| `
|
|
2127
|
+
| `mount(mapCore)` | 后挂载 BaseGIS。 |
|
|
2128
|
+
| `load(payload, options?)` / `update(payload)` | 加载或更新线、样式和动画。 |
|
|
2129
|
+
| `setTime(currentTime)` | 更新路线时间裁剪;传 `null` 恢复完整路线,不重建全部线数据。 |
|
|
2130
|
+
| `show()` / `hide()` / `toggle()` | 控制显隐。 |
|
|
2131
|
+
| `playAnimation()` / `pauseAnimation()` / `restartAnimation()` | 控制沿线动画。 |
|
|
2132
|
+
| `clear()` | 清空线和动画,保留控制器。 |
|
|
2133
|
+
| `refreshState()` / `getState()` | 获取线数量、点数和动画状态。 |
|
|
2134
|
+
| `destroy()` | 删除图层、动画和引擎恢复快照。 |
|
|
2135
|
+
|
|
2136
|
+
页面卸载时先执行 `lineLayer.destroy()`,再执行 `mapCore.destroy()`。
|
|
2137
|
+
|
|
2138
|
+
在线示例:[查看 LineLayerController 双引擎应用 Demo](http://61.50.111.214:31166/lgmap/test-page-34)。
|
|
2139
|
+
|
|
2140
|
+
<a id="typhoon-path-controller"></a>
|
|
2141
|
+
|
|
2142
|
+
## TyphoonPathController
|
|
2143
|
+
|
|
2144
|
+
把已经整理好的台风实况和预报数据渲染为独立专题图层,统一支持 Cesium / Leaflet。控制器负责实况路径、强度着色节点、生命周期标签、移动中心、当前点 7/10/12 级四象限风圈、多机构预报、不确定性圆和播放定位。
|
|
2145
|
+
|
|
2146
|
+
BaseGIS 不请求台风接口,也不推算强度、风圈、预报或预警等级。分页筛选、接口字段转换、ECharts 和业务面板仍由应用层负责。24/48 小时警戒线属于普通业务折线,推荐与 `LineLayerController` 组合使用。
|
|
2147
|
+
|
|
2148
|
+
### 最小用法
|
|
2149
|
+
|
|
2150
|
+
```js
|
|
2151
|
+
import { TyphoonPathController } from '@3clear/basegis/methods'
|
|
2152
|
+
|
|
2153
|
+
const typhoonLayer = new TyphoonPathController({
|
|
2154
|
+
mapCore,
|
|
2155
|
+
layerId: 'typhoon-senlac',
|
|
2156
|
+
})
|
|
2157
|
+
|
|
2158
|
+
await typhoonLayer.load({
|
|
2159
|
+
typhoon: { id: '2604', code: '2604', name: '森拉克' },
|
|
2160
|
+
tracks: [
|
|
2161
|
+
{
|
|
2162
|
+
id: 'track-1',
|
|
2163
|
+
time: '2026-04-10T18:00:00Z',
|
|
2164
|
+
position: [136.2, 10.5],
|
|
2165
|
+
level: 'TD',
|
|
2166
|
+
stage: '热带低压',
|
|
2167
|
+
windSpeed: 16,
|
|
2168
|
+
pressure: 1002,
|
|
2169
|
+
windCircles: {
|
|
2170
|
+
r7: { ne: 120, se: 140, sw: 90, nw: 110 },
|
|
2171
|
+
},
|
|
2172
|
+
label: '生成 4/10 18时',
|
|
2173
|
+
},
|
|
2174
|
+
{
|
|
2175
|
+
id: 'track-2',
|
|
2176
|
+
time: '2026-04-11T12:00:00Z',
|
|
2177
|
+
position: [133.2, 12],
|
|
2178
|
+
level: 'TY',
|
|
2179
|
+
stage: '台风',
|
|
2180
|
+
windSpeed: 35,
|
|
2181
|
+
pressure: 970,
|
|
2182
|
+
windCircles: {
|
|
2183
|
+
r7: { ne: 300, se: 320, sw: 200, nw: 220 },
|
|
2184
|
+
r10: { ne: 120, se: 140, sw: 80, nw: 100 },
|
|
2185
|
+
},
|
|
2186
|
+
label: '加强 4/11 12时',
|
|
2187
|
+
},
|
|
2188
|
+
],
|
|
2189
|
+
playback: {
|
|
2190
|
+
enabled: true,
|
|
2191
|
+
durationMs: 12000,
|
|
2192
|
+
autoplay: false,
|
|
2193
|
+
loop: true,
|
|
2194
|
+
},
|
|
2195
|
+
onCurrentChange({ index, point, progress }) {
|
|
2196
|
+
console.log(index, point, progress)
|
|
2197
|
+
},
|
|
2198
|
+
})
|
|
2199
|
+
|
|
2200
|
+
typhoonLayer.play()
|
|
2201
|
+
```
|
|
2202
|
+
|
|
2203
|
+
坐标固定为 `[longitude, latitude, height?]`。风圈半径单位是公里,`ne / se / sw / nw` 分别表示东北、东南、西南、西北四个象限;没有某一级风圈时直接省略对应的 `r7 / r10 / r12`。
|
|
2204
|
+
|
|
2205
|
+
### 已准备好的预报路径
|
|
2206
|
+
|
|
2207
|
+
`forecastPaths` 支持同时传入多个机构结果。BaseGIS 只渲染传入结果,不在前端生成预报。
|
|
2208
|
+
|
|
2209
|
+
```js
|
|
2210
|
+
await typhoonLayer.update({
|
|
2211
|
+
forecastPaths: [{
|
|
2212
|
+
id: 'cma',
|
|
2213
|
+
name: '中央气象台',
|
|
2214
|
+
style: {
|
|
2215
|
+
color: '#ffdf4d',
|
|
2216
|
+
width: 2.5,
|
|
2217
|
+
opacity: 0.96,
|
|
2218
|
+
dashLength: 12,
|
|
2219
|
+
gapLength: 8,
|
|
2220
|
+
},
|
|
2221
|
+
points: [
|
|
2222
|
+
{ id: 'f1', time: '2026-04-13T12:00:00Z', position: [127.4, 19.2], level: 'STY' },
|
|
2223
|
+
{
|
|
2224
|
+
id: 'f2',
|
|
2225
|
+
time: '2026-04-14T00:00:00Z',
|
|
2226
|
+
position: [122.8, 20.5],
|
|
2227
|
+
level: 'TY',
|
|
2228
|
+
uncertaintyRadiusKm: 90,
|
|
2229
|
+
},
|
|
2230
|
+
],
|
|
2231
|
+
}],
|
|
2232
|
+
})
|
|
2233
|
+
```
|
|
2234
|
+
|
|
2235
|
+
### 路径点格式
|
|
2236
|
+
|
|
2237
|
+
| 字段 | 必填 | 说明 |
|
|
2238
|
+
| --- | --- | --- |
|
|
2239
|
+
| `id` | 否 | 点 id;未传时使用时次或数组索引生成内部 id。 |
|
|
2240
|
+
| `time` | 建议 | ISO 字符串或浏览器可解析时间;播放优先按真实时距插值。 |
|
|
2241
|
+
| `position` | 是 | `[longitude, latitude, height?]`。 |
|
|
2242
|
+
| `level` | 否 | 强度代码,默认 `TD`;内置 `TD / TS / STS / TY / STY / SuperTY` 颜色。 |
|
|
2243
|
+
| `stage` / `label` | 否 | 中心状态文字和静态生命周期标签。 |
|
|
2244
|
+
| `windSpeed` / `pressure` | 否 | 中心标签可展示的风速和气压业务值。 |
|
|
2245
|
+
| `windCircles` | 否 | `r7 / r10 / r12` 四象限半径对象,单位 km。 |
|
|
2246
|
+
| `data` | 否 | 点击回调透传的业务数据。 |
|
|
2247
|
+
|
|
2248
|
+
### 样式与播放配置
|
|
2249
|
+
|
|
2250
|
+
| 参数 | 默认值 | 说明 |
|
|
2251
|
+
| --- | --- | --- |
|
|
2252
|
+
| `visible` | `true` | 图层初始显隐。 |
|
|
2253
|
+
| `style.trackLine` | 白色、`width: 3` | 实况路径颜色、宽度、透明度及描边。 |
|
|
2254
|
+
| `style.forecastLine` | 白色虚线、`width: 2` | 未给单条预报路径样式时的默认值。 |
|
|
2255
|
+
| `style.point.radius` | `5` | 实况和预报节点半径。 |
|
|
2256
|
+
| `style.label.visible` | `true` | 是否显示传入的生命周期标签。 |
|
|
2257
|
+
| `style.center.iconUrl` | 包内台风 SVG | 可覆盖为业务 GIF、PNG 或 SVG。 |
|
|
2258
|
+
| `style.center.iconSize` | `[36, 36]` | 当前中心图标尺寸。 |
|
|
2259
|
+
| `style.center.rotate` | `true` | 是否旋转中心图标。 |
|
|
2260
|
+
| `style.center.showLabel` | `true` | 是否显示台风编号、名称、强度和风速。 |
|
|
2261
|
+
| `style.windCircle.visible` | `true` | 是否显示当前点的 7/10/12 级风圈。 |
|
|
2262
|
+
| `style.intensityColors` | 内置强度色 | 按 `level` 覆盖节点颜色。 |
|
|
2263
|
+
| `playback.enabled` | `true` | 是否允许路径播放。 |
|
|
2264
|
+
| `playback.durationMs` | `15000` | 从首点到末点的总时长。 |
|
|
2265
|
+
| `playback.autoplay` / `loop` | `false` / `false` | 自动播放与循环。 |
|
|
2266
|
+
| `playback.currentIndex` | `0` | 初始活动路径点。 |
|
|
2267
|
+
|
|
2268
|
+
`onCurrentChange` 只在活动点索引变化或显式定位时触发,不会在每一帧刷业务状态。`onPointClick` 在点击实况点、预报点或当前中心时返回 `{ targetType, point, pointIndex, forecastPathId, coordinate, containerPoint, engineType }`,弹窗由业务页面实现。
|
|
2269
|
+
|
|
2270
|
+
### 方法
|
|
2271
|
+
|
|
2272
|
+
| 方法 | 说明 |
|
|
2273
|
+
| --- | --- |
|
|
2274
|
+
| `mount(mapCore)` | 后挂载已经初始化的 BaseGIS。 |
|
|
2275
|
+
| `load(payload, options?)` / `update(payload)` | 加载或局部更新路径、预报、样式和播放配置。 |
|
|
2276
|
+
| `show()` / `hide()` / `toggle()` | 控制专题显隐;隐藏时暂停,重新显示后恢复原播放意图。 |
|
|
2277
|
+
| `play()` / `pause()` / `restart({ autoplay })` | 控制台风中心播放。 |
|
|
2278
|
+
| `seek(index)` / `seek({ time })` | 按点索引或时次定位。 |
|
|
2279
|
+
| `flyTo(options?)` | 定位到实况和预报路径范围。 |
|
|
2280
|
+
| `clear()` | 清空实况和预报数据,保留空图层及控制器。 |
|
|
2281
|
+
| `refreshState()` / `getState()` | 获取点数、预报数、当前索引、进度和播放状态。 |
|
|
2282
|
+
| `destroy()` | 删除图层、动画、点击监听和引擎恢复快照。 |
|
|
1114
2283
|
|
|
1115
|
-
|
|
2284
|
+
切换引擎会恢复数据、样式、显隐、播放/暂停意图和最后一次显式 `seek` 的位置;不会保存正在播放的逐帧进度。页面卸载时先执行 `typhoonLayer.destroy()`,再执行 `mapCore.destroy()`。
|
|
1116
2285
|
|
|
1117
|
-
在线示例:[查看
|
|
2286
|
+
在线示例:[查看 TyphoonPathController 双引擎应用 Demo](http://61.50.111.214:31166/lgmap/test-page-10)。
|
|
1118
2287
|
|
|
1119
2288
|
<a id="image-layer-controller"></a>
|
|
1120
2289
|
|
|
@@ -1468,6 +2637,9 @@ imageLayer.destroy({ layerId: 'radar-image' })
|
|
|
1468
2637
|
| `imageUrl` | 普通图片、灰度图、图片+TIF 必填 | 图片地址。仅 TIF 模式建议传空字符串清掉旧图片。 |
|
|
1469
2638
|
| `tifUrl` | 仅 TIF、图片+TIF 必填 | GeoTIFF 数值地址,用于鼠标探针或网格注记,不会单独生成彩色图片底图。 |
|
|
1470
2639
|
| `area` | 传 `imageUrl` 时必填 | 图片范围:`startLon / startLat / endLon / endLat`。 |
|
|
2640
|
+
| `sourceProjection` | 选填 | 源图投影;当前支持将 `EPSG:3857` 图片重采样为经纬度图片,不是任意投影转换器。 |
|
|
2641
|
+
| `sourceArea` | 选填 | 源图片范围,默认使用 `area`;支持墨卡托米坐标范围或经纬度范围。 |
|
|
2642
|
+
| `targetProjection` | 选填 | 默认从地图 CRS 推断;源投影与目标相同则不重采样。 |
|
|
1471
2643
|
| `imageSourceType` | 灰度图必填,其他选填 | `color` 表示已填色图片;`grayscale` 表示灰度图。 |
|
|
1472
2644
|
| `colorize` | 灰度图必填 | 灰度图业务值和色带配置。 |
|
|
1473
2645
|
| `colorize.minValue` | 灰度图必填 | 色带映射最小值。 |
|
|
@@ -1475,6 +2647,7 @@ imageLayer.destroy({ layerId: 'radar-image' })
|
|
|
1475
2647
|
| `colorize.noDataValue` | 选填 | 无效值。 |
|
|
1476
2648
|
| `colorize.colors` | 灰度图必填 | 色带颜色数组。 |
|
|
1477
2649
|
| `opacity` | 选填 | 透明度,通常 0 - 1。 |
|
|
2650
|
+
| `zIndex` | 选填 | Leaflet 图片叠放层级,默认 `650`。 |
|
|
1478
2651
|
| `visible` | 选填 | 是否显示图层。 |
|
|
1479
2652
|
| `showProbe` | 选填 | 是否开启鼠标探针,需要 `tifUrl` 或灰度图数值。 |
|
|
1480
2653
|
| `showLabel` | 选填 | 是否显示网格注记,需要 `tifUrl` 或灰度图数值。 |
|
|
@@ -1483,11 +2656,7 @@ imageLayer.destroy({ layerId: 'radar-image' })
|
|
|
1483
2656
|
| `gridTotal` | 选填 | 切片网格数量。 |
|
|
1484
2657
|
| `tileSize` | 选填 | 切片尺寸。 |
|
|
1485
2658
|
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
- `load(items, { index, visible })`:兼容旧的图片集合加载方式,会把 `items[index]` 写入当前图层。
|
|
1489
|
-
- `switchTo(idOrIndex)`:在已加载的 `items` 内切换到某一项。
|
|
1490
|
-
- `next() / prev()`:只适合本地小数组演示,不推荐作为业务时次更新主路径。
|
|
2659
|
+
图片重采样依赖 Canvas 读取像素,跨域图片需要服务端允许 CORS。
|
|
1491
2660
|
|
|
1492
2661
|
<a id="grid-layer-controller"></a>
|
|
1493
2662
|
|
|
@@ -1555,7 +2724,7 @@ await gridLayer.loadData({
|
|
|
1555
2724
|
},
|
|
1556
2725
|
})
|
|
1557
2726
|
|
|
1558
|
-
gridLayer.update({ decimalPlaces: 2 })
|
|
2727
|
+
await gridLayer.update({ decimalPlaces: 2 })
|
|
1559
2728
|
gridLayer.hide()
|
|
1560
2729
|
gridLayer.show()
|
|
1561
2730
|
gridLayer.destroy()
|
|
@@ -1570,9 +2739,31 @@ gridLayer.destroy()
|
|
|
1570
2739
|
|
|
1571
2740
|
灰度图要表达真实业务值时,应显式传入 `minValue / maxValue`。数值图层不使用色带绘制背景;如果需要同时显示彩色图片,请使用 `ImageLayerController`。
|
|
1572
2741
|
|
|
1573
|
-
|
|
2742
|
+
### 方法
|
|
2743
|
+
|
|
2744
|
+
| 方法 | 说明 |
|
|
2745
|
+
| --- | --- |
|
|
2746
|
+
| `mount(mapCore)` | 后挂载 BaseGIS。 |
|
|
2747
|
+
| `load(payload)` | 加载 `tifUrl / imageUrl / grayImageUrl / imageGridData` 数据源。 |
|
|
2748
|
+
| `loadTif(payload)` / `loadGrayImage(payload)` / `loadData(payload)` | 对应三种数据源的快捷加载方法。 |
|
|
2749
|
+
| `update(payload)` | 合并更新已加载数据和参数;首次尚未加载时返回 `NOT_LOADED`。 |
|
|
2750
|
+
| `show()` / `hide()` | 控制显隐。 |
|
|
2751
|
+
| `getState()` | 返回挂载状态、引擎、图层 id、显隐及当前 payload。 |
|
|
2752
|
+
| `destroy()` | 移除网格图层并清理控制器数据。 |
|
|
2753
|
+
|
|
2754
|
+
<a id="unified-wind-layer"></a>
|
|
2755
|
+
|
|
2756
|
+
## 风场统一入口(推荐)
|
|
2757
|
+
|
|
2758
|
+
风场有 GPU 和 Canvas 两种渲染方式,三个调用入口的区别如下:
|
|
2759
|
+
|
|
2760
|
+
| 调用入口 | Cesium | Leaflet | 切换引擎后自动恢复 |
|
|
2761
|
+
| --- | --- | --- | --- |
|
|
2762
|
+
| `BaseGIS.upsertWindLayer()`(推荐) | GPU | Canvas | 支持 |
|
|
2763
|
+
| [`BaseGIS.upsertGpuWindLayer()`](#gpu-wind-layer) | GPU | 不支持 | 不支持 |
|
|
2764
|
+
| [`WindFieldMethods`](#wind-field-methods) | Canvas | Canvas | 不支持 |
|
|
1574
2765
|
|
|
1575
|
-
|
|
2766
|
+
一般使用 `upsertWindLayer()` 即可,它会根据当前引擎自动选择渲染器。需要在 Cesium 上使用 Canvas,或需要叠加风速底图时,使用 `WindFieldMethods`。
|
|
1576
2767
|
|
|
1577
2768
|
```js
|
|
1578
2769
|
const windData = await fetch('/mock/uv.json').then((response) => response.json())
|
|
@@ -1610,9 +2801,13 @@ mapCore.removeWindLayer({ layerId: 'surface-wind' })
|
|
|
1610
2801
|
|
|
1611
2802
|
跨引擎统一使用 `Bound / DataAry` 数据格式。公共参数包括 `maxParticles`、`speedFactor`、`lineWidth`、`fadeOpacity`、`particleOpacity`、`color` 和 `visible`;适配层会统一速度、帧率拖尾、屏幕线宽、设备像素比和粒子视觉密度。`maxParticles` 表示跨引擎视觉预算:Cesium 的实际粒子数会按 GPU 纹理向上取整为整数平方,Leaflet 会按 Canvas 拖尾覆盖率换算实际粒子数,均可通过图层状态查看;算法和投影不同,因此不保证逐像素完全一致。Leaflet 还支持 `particleGap`、`maxAge`、`frameRate`、`minSpeed`。统一风场属于 BaseGIS 托管图层,`setEngine()` 切换引擎时会自动使用原数据和最新参数恢复。
|
|
1612
2803
|
|
|
1613
|
-
|
|
2804
|
+
<a id="gpu-wind-layer"></a>
|
|
2805
|
+
|
|
2806
|
+
## GPU 风场
|
|
1614
2807
|
|
|
1615
|
-
|
|
2808
|
+
`upsertGpuWindLayer()` 与统一入口在 Cesium 下使用同一套 GPU 实现。本节接口直接使用 GPU 参数,不参与 BaseGIS 的引擎切换恢复;统一入口还会换算线宽等参数,因此两组接口的参数值不宜直接照搬。
|
|
2809
|
+
|
|
2810
|
+
GPU 风场仅支持 Cesium。它使用显卡纹理保存和更新粒子,相机平移或缩放期间清空轨迹,操作结束后按新视野重新生成粒子。Leaflet 调用本节接口时会返回 `UNSUPPORTED_CAPABILITY`,不会抛异常。
|
|
1616
2811
|
|
|
1617
2812
|
Cesium 由宿主通过 `window.Cesium` 提供。启用 `terrainEnabled` 后,图层会采样当前 `viewer.terrainProvider`,让轨迹高度随地形变化;如果当前使用椭球地形,采样高度为 0。
|
|
1618
2813
|
|
|
@@ -1652,9 +2847,9 @@ if (!result.success) {
|
|
|
1652
2847
|
const windData = {
|
|
1653
2848
|
// 经度最小值、纬度最小值、经向格点数、纬向格点数、
|
|
1654
2849
|
// 经度跨度、纬度跨度、数值缩放倍数。
|
|
1655
|
-
Bound: [100, 10,
|
|
2850
|
+
Bound: [100, 10, 2, 2, 10, 10, 10],
|
|
1656
2851
|
// 每个格点按 U、V 交错;纬度行从南向北排列。
|
|
1657
|
-
DataAry: [
|
|
2852
|
+
DataAry: [30, 10, 40, 15, 20, 10, 35, 5],
|
|
1658
2853
|
}
|
|
1659
2854
|
```
|
|
1660
2855
|
|
|
@@ -1672,7 +2867,7 @@ const windData = {
|
|
|
1672
2867
|
},
|
|
1673
2868
|
u: new Float32Array(181 * 91),
|
|
1674
2869
|
v: new Float32Array(181 * 91),
|
|
1675
|
-
//
|
|
2870
|
+
// 仅当数据行从北向南排列时设置;默认按南到北排列。
|
|
1676
2871
|
rowOrder: 'north-to-south',
|
|
1677
2872
|
}
|
|
1678
2873
|
```
|
|
@@ -1740,6 +2935,76 @@ mapCore.removeGpuWindLayer({ layerId: 'surface-gpu-wind' })
|
|
|
1740
2935
|
|
|
1741
2936
|
GPU 专用 API 不属于跨引擎自动恢复图层。切换 Cesium/Leaflet 后,业务应重新调用 `upsertGpuWindLayer`;需要自动恢复时改用 `upsertWindLayer`。核心渲染流程改编自 [RaymanNg/3D-Wind-Field](https://github.com/RaymanNg/3D-Wind-Field),遵循源码目录内 `LICENSE-RaymanNg.txt` 的 MIT License。
|
|
1742
2937
|
|
|
2938
|
+
<a id="source-transport"></a>
|
|
2939
|
+
|
|
2940
|
+
## 源解析传输
|
|
2941
|
+
|
|
2942
|
+
源解析传输是 Cesium 专有复合层,包含彩色贡献弧线、灰色烟羽 Billboard、移动烟团、来源/目标节点、路径选择和目标汇聚体。业务接口、城市聚合、污染物字段与时间轴由页面处理,整理好 `target + flows` 后一次调用即可:
|
|
2943
|
+
|
|
2944
|
+
```js
|
|
2945
|
+
const sources = [
|
|
2946
|
+
{ code: 'source-1', name: '来源一', position: [118.1, 24.5], value: 12, percent: 37.5 },
|
|
2947
|
+
{ code: 'source-2', name: '来源二', position: [120.6, 27.9], value: 20, percent: 62.5 },
|
|
2948
|
+
]
|
|
2949
|
+
|
|
2950
|
+
const result = mapCore.upsertSourceTransportLayer({
|
|
2951
|
+
layerId: 'source-analysis',
|
|
2952
|
+
target: {
|
|
2953
|
+
name: '福州市',
|
|
2954
|
+
position: [119.331, 26.0639],
|
|
2955
|
+
label: '福州市 汇聚中心\n累积浓度 32.00 μg/m³',
|
|
2956
|
+
},
|
|
2957
|
+
flows: sources.map(source => ({
|
|
2958
|
+
id: source.code,
|
|
2959
|
+
name: source.name,
|
|
2960
|
+
start: source.position,
|
|
2961
|
+
value: source.value,
|
|
2962
|
+
percent: source.percent,
|
|
2963
|
+
label: source.label,
|
|
2964
|
+
data: source,
|
|
2965
|
+
})),
|
|
2966
|
+
onSelect(flow) {
|
|
2967
|
+
console.log('选中来源', flow)
|
|
2968
|
+
},
|
|
2969
|
+
onHover(flow, screenPosition) {
|
|
2970
|
+
console.log('悬停来源', flow, screenPosition)
|
|
2971
|
+
},
|
|
2972
|
+
})
|
|
2973
|
+
|
|
2974
|
+
if (result.success) {
|
|
2975
|
+
mapCore.flyToSourceTransportLayer({ layerId: 'source-analysis' })
|
|
2976
|
+
}
|
|
2977
|
+
```
|
|
2978
|
+
|
|
2979
|
+
| 参数 | 是否必填 | 说明 |
|
|
2980
|
+
| --- | --- | --- |
|
|
2981
|
+
| `layerId` | 否 | 默认 `source-transport-default`。 |
|
|
2982
|
+
| `target.position` | 创建时必填 | 目标 `[longitude, latitude]`;可附带 `name/label/data`。 |
|
|
2983
|
+
| `flows` | 创建时必填 | 每项至少传 `start`(兼容 `position`);`end` 默认目标位置。 |
|
|
2984
|
+
| `flow.id/code` | 建议 | 稳定且不重复的来源标识。 |
|
|
2985
|
+
| `flow.value/intensity` | 否 | `intensity` 范围 `0~1`;不传时按本批有效 `value` 做最小最大归一化,同值时为 `0.5`。 |
|
|
2986
|
+
| `flow.percent` | 否 | 百分数值,例如 `37.5` 表示 `37.5%`,参与弧高与烟羽速度计算。 |
|
|
2987
|
+
| `flow.bend/arcHeight/color/lineWidth/label/smoke/data` | 否 | 单来源覆盖。 |
|
|
2988
|
+
| `colors` | 否 | 来源颜色调色板,可由每条 flow 的 `color` 覆盖。 |
|
|
2989
|
+
| `visible/running` | 否 | 初始显隐与动画状态,默认均为 `true`。 |
|
|
2990
|
+
| `path/line/smoke/sourceNode/targetNode/volume/interaction/fog/camera` | 否 | 单层视觉配置,可覆盖 BaseGIS 实例级默认值。 |
|
|
2991
|
+
| `onSelect/onHover` | 否 | 分别接收 `flow/null` 和 `flow/null, screenPosition/null`。 |
|
|
2992
|
+
|
|
2993
|
+
`target.volume: false` 或 `volume: { enabled: false }` 可关闭目标汇聚体;也可通过 `target.volume.data/option/parameters/colorRamp` 传真实体数据。未传数据时会生成示意汇聚云,底层复用 `upsertVolumeLayer`,该云形不代表业务浓度的真实三维分布。
|
|
2994
|
+
|
|
2995
|
+
`updateSourceTransportLayer()` 支持部分更新:`target` 对象会合并,`flows` 数组整体替换。只更新 `target.volume` 时,不会重建来源弧线:
|
|
2996
|
+
|
|
2997
|
+
```js
|
|
2998
|
+
mapCore.updateSourceTransportLayer({
|
|
2999
|
+
layerId: 'source-analysis',
|
|
3000
|
+
target: { volume: { parameters: { opacity: 0.5, brightness: 1.1 } } },
|
|
3001
|
+
})
|
|
3002
|
+
```
|
|
3003
|
+
|
|
3004
|
+
目标体云创建失败时,其余部分仍可能加载成功。除 `success` 外,还应检查 `result.data.degraded`(可能包含 `'targetVolume'`)和 `result.data.state.volumeError`。
|
|
3005
|
+
|
|
3006
|
+
生命周期方法:`updateSourceTransportLayer`、`showSourceTransportLayer`、`hideSourceTransportLayer`、`playSourceTransportLayer`、`pauseSourceTransportLayer`、`flyToSourceTransportLayer`、`clearSourceTransportLayer`、`getSourceTransportLayerState`、`removeSourceTransportLayer`。`clear` 会一起清掉来源、目标和内部体云;Leaflet 返回 `UNSUPPORTED_CAPABILITY` 且不抛异常,切回 Cesium 后自动恢复托管快照。
|
|
3007
|
+
|
|
1743
3008
|
<a id="volume-rendering"></a>
|
|
1744
3009
|
|
|
1745
3010
|
## 三维体渲染
|
|
@@ -1751,11 +3016,17 @@ GPU 专用 API 不属于跨引擎自动恢复图层。切换 Cesium/Leaflet 后
|
|
|
1751
3016
|
### 基础用法
|
|
1752
3017
|
|
|
1753
3018
|
```js
|
|
3019
|
+
// 3 个经度 × 2 个纬度 × 2 个高度层,X 最快变化,随后是 Y、Z。
|
|
3020
|
+
const volumeValues = new Uint8Array([
|
|
3021
|
+
20, 80, 120, 60, 160, 220,
|
|
3022
|
+
40, 100, 160, 80, 180, 240,
|
|
3023
|
+
])
|
|
3024
|
+
|
|
1754
3025
|
const result = mapCore.upsertVolumeLayer({
|
|
1755
3026
|
// 建议必填:图层唯一 id。再次使用同一个 layerId 调用会覆盖旧体渲染层。
|
|
1756
3027
|
layerId: 'volume-demo',
|
|
1757
3028
|
|
|
1758
|
-
//
|
|
3029
|
+
// 必填:0~255 编码的一维数组,长度必须等于 rows * cols * heights。
|
|
1759
3030
|
data: volumeValues,
|
|
1760
3031
|
|
|
1761
3032
|
// 必填:体数据范围和网格尺寸。
|
|
@@ -1766,19 +3037,20 @@ const result = mapCore.upsertVolumeLayer({
|
|
|
1766
3037
|
// 纬度范围。
|
|
1767
3038
|
ymin: 30,
|
|
1768
3039
|
ymax: 40,
|
|
1769
|
-
//
|
|
3040
|
+
// 高度范围,单位米。
|
|
1770
3041
|
zmin: 0,
|
|
1771
3042
|
zmax: 10000,
|
|
1772
|
-
//
|
|
1773
|
-
rows:
|
|
1774
|
-
cols:
|
|
1775
|
-
heights:
|
|
3043
|
+
// 经度 X、纬度 Y、高度 Z 的网格数量,均为不小于 2 的整数。
|
|
3044
|
+
rows: 3,
|
|
3045
|
+
cols: 2,
|
|
3046
|
+
heights: 2,
|
|
1776
3047
|
},
|
|
1777
3048
|
|
|
1778
3049
|
// 选填:体渲染 shader 参数,可后续单独更新。
|
|
1779
3050
|
parameters: {
|
|
1780
|
-
//
|
|
1781
|
-
|
|
3051
|
+
// 使用 0~255 编码直接定位色带,不再采用旧的 0~15 映射。
|
|
3052
|
+
normalizedColorRamp: 1,
|
|
3053
|
+
opacity: 0.72,
|
|
1782
3054
|
// 光线步进采样次数。越大越细腻,也越耗性能。
|
|
1783
3055
|
steps: 100,
|
|
1784
3056
|
// x/y/z 三个方向裁切位置,默认 -0.5 表示不裁切。
|
|
@@ -1787,6 +3059,8 @@ const result = mapCore.upsertVolumeLayer({
|
|
|
1787
3059
|
zCut: -0.5,
|
|
1788
3060
|
},
|
|
1789
3061
|
|
|
3062
|
+
colorRamp: ['#2f80ed', '#22c55e', '#facc15', '#ef4444'],
|
|
3063
|
+
|
|
1790
3064
|
// 选填:初始是否显示。
|
|
1791
3065
|
visible: true,
|
|
1792
3066
|
})
|
|
@@ -1798,13 +3072,13 @@ if (!result.success) {
|
|
|
1798
3072
|
|
|
1799
3073
|
### 更新参数
|
|
1800
3074
|
|
|
1801
|
-
|
|
3075
|
+
更新透明度、密度、步进数或裁切面时,不需要重新加载体数据,直接更新参数即可。
|
|
1802
3076
|
|
|
1803
3077
|
```js
|
|
1804
3078
|
mapCore.updateVolumeLayerParameters({
|
|
1805
3079
|
layerId: 'volume-demo',
|
|
1806
3080
|
parameters: {
|
|
1807
|
-
|
|
3081
|
+
opacity: 0.5,
|
|
1808
3082
|
steps: 180,
|
|
1809
3083
|
zCut: 0.1,
|
|
1810
3084
|
},
|
|
@@ -1813,27 +3087,46 @@ mapCore.updateVolumeLayerParameters({
|
|
|
1813
3087
|
|
|
1814
3088
|
### 更新数据
|
|
1815
3089
|
|
|
1816
|
-
|
|
3090
|
+
空间范围和网格尺寸不变时,使用 `updateVolumeLayerData()` 更新同一 Primitive 的体纹理:
|
|
3091
|
+
|
|
3092
|
+
```js
|
|
3093
|
+
mapCore.updateVolumeLayerData({
|
|
3094
|
+
layerId: 'volume-demo',
|
|
3095
|
+
data: Uint8Array.from(volumeValues, (value) => Math.min(255, value + 10)),
|
|
3096
|
+
})
|
|
3097
|
+
```
|
|
3098
|
+
|
|
3099
|
+
新数据长度必须与原网格一致。此方法会恢复显示;如果需要保持隐藏,更新后再调用 `hideVolumeLayer()`。空间范围或网格尺寸改变时,使用同一 `layerId` 重新调用 `upsertVolumeLayer({ data, option, ... })`。新 Primitive 创建并加入场景后才释放旧图层,创建失败时保留旧图层。
|
|
3100
|
+
|
|
3101
|
+
### 按屏幕位置取值
|
|
3102
|
+
|
|
3103
|
+
`sampleVolumeLayerValue()` 沿屏幕位置的相机射线采样,选取对可见体云贡献最大的点,并对数据做三线性插值。`position` 为相对地图画布左上角的 CSS 像素坐标,不是经纬度:
|
|
1817
3104
|
|
|
1818
3105
|
```js
|
|
1819
|
-
mapCore.
|
|
3106
|
+
const sampleResult = mapCore.sampleVolumeLayerValue({
|
|
1820
3107
|
layerId: 'volume-demo',
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
3108
|
+
position: { x: 320, y: 180 },
|
|
3109
|
+
steps: 120,
|
|
3110
|
+
// 可选 data:与纹理同长度、同顺序的原始业务值数组。
|
|
3111
|
+
// 不传则返回渲染数据值;命中位置始终由可见体云决定。
|
|
1824
3112
|
})
|
|
3113
|
+
if (sampleResult.success) {
|
|
3114
|
+
console.log(sampleResult.data) // { value, lon, lat, height },height 单位米。
|
|
3115
|
+
}
|
|
1825
3116
|
```
|
|
1826
3117
|
|
|
3118
|
+
图层隐藏、未命中或被地表遮挡时返回失败结果。取值采样步数限制为 `32~400`,与渲染步数上限不同。
|
|
3119
|
+
|
|
1827
3120
|
### 显隐、定位和移除
|
|
1828
3121
|
|
|
1829
3122
|
```js
|
|
1830
3123
|
mapCore.hideVolumeLayer({ layerId: 'volume-demo' })
|
|
1831
3124
|
mapCore.showVolumeLayer({ layerId: 'volume-demo' })
|
|
1832
3125
|
mapCore.flyToVolumeLayer({ layerId: 'volume-demo', duration: 0.8 })
|
|
1833
|
-
mapCore.removeVolumeLayer({ layerId: 'volume-demo' })
|
|
1834
3126
|
|
|
1835
3127
|
const stateResult = mapCore.getVolumeLayerState({ layerId: 'volume-demo' })
|
|
1836
3128
|
console.log(stateResult.data)
|
|
3129
|
+
mapCore.removeVolumeLayer({ layerId: 'volume-demo' })
|
|
1837
3130
|
```
|
|
1838
3131
|
|
|
1839
3132
|
### 方法总表
|
|
@@ -1841,30 +3134,37 @@ console.log(stateResult.data)
|
|
|
1841
3134
|
| 方法 | 参数 | 说明 |
|
|
1842
3135
|
| --- | --- | --- |
|
|
1843
3136
|
| `upsertVolumeLayer(payload)` | 体渲染配置 | 创建或更新体渲染层。同 `layerId` 会覆盖旧图层。 |
|
|
3137
|
+
| `updateVolumeLayerData(payload)` | `{ layerId, data }` | 同范围、同网格尺寸时更新体纹理,不重建 Primitive。 |
|
|
1844
3138
|
| `updateVolumeLayerParameters(payload)` | `{ layerId, parameters }` | 更新体渲染 shader 参数,不重新加载体数据。 |
|
|
1845
3139
|
| `showVolumeLayer(payload)` | `{ layerId }` | 显示体渲染层。 |
|
|
1846
3140
|
| `hideVolumeLayer(payload)` | `{ layerId }` | 隐藏体渲染层。 |
|
|
1847
3141
|
| `removeVolumeLayer(payload)` | `{ layerId }` | 移除体渲染层并释放 Primitive。 |
|
|
1848
3142
|
| `flyToVolumeLayer(payload)` | `{ layerId, duration }` | 飞到体渲染层经纬度范围。 |
|
|
1849
3143
|
| `getVolumeLayerState(payload)` | `{ layerId }` | 获取图层状态。 |
|
|
3144
|
+
| `sampleVolumeLayerValue(payload)` | `{ layerId, position, data?, steps? }` | 按屏幕位置取值;可用 `windowPosition`、`values` 作为别名。 |
|
|
1850
3145
|
|
|
1851
3146
|
### 参数总表
|
|
1852
3147
|
|
|
1853
3148
|
| 参数 | 是否必填 | 说明 |
|
|
1854
3149
|
| --- | --- | --- |
|
|
1855
3150
|
| `layerId` / `volumeLayerId` / `id` | 建议必填 | 体渲染图层 id,不传默认 `volume-default`。 |
|
|
1856
|
-
| `data` / `value` / `values` | 必填 |
|
|
3151
|
+
| `data` / `value` / `values` | 必填 | `0~255` 字节编码,长度为 `rows * cols * heights`;索引为 `z * rows * cols + y * rows + x`。业务浮点值需先编码,不会自动归一化。 |
|
|
1857
3152
|
| `option` | 必填 | 体数据空间范围和网格尺寸。 |
|
|
1858
3153
|
| `option.xmin / xmax` | 必填 | 经度最小值和最大值。 |
|
|
1859
3154
|
| `option.ymin / ymax` | 必填 | 纬度最小值和最大值。 |
|
|
1860
|
-
| `option.zmin / zmax` | 必填 |
|
|
1861
|
-
| `option.rows` | 必填 |
|
|
1862
|
-
| `option.cols` | 必填 |
|
|
1863
|
-
| `option.heights` | 必填 |
|
|
1864
|
-
| `parameters.threshold` | 选填 |
|
|
1865
|
-
| `parameters.steps` | 选填 |
|
|
3155
|
+
| `option.zmin / zmax` | 必填 | 高度最小值和最大值,单位米。 |
|
|
3156
|
+
| `option.rows` | 必填 | X / 经度方向数量,不小于 `2` 的整数。 |
|
|
3157
|
+
| `option.cols` | 必填 | Y / 纬度方向数量,不小于 `2` 的整数。 |
|
|
3158
|
+
| `option.heights` | 必填 | Z / 高度层数量,不小于 `2` 的整数。 |
|
|
3159
|
+
| `parameters.threshold` | 选填 | 默认 `1.2`;仅累积归一化纹理值小于该阈值的样本,不是整体透明度。 |
|
|
3160
|
+
| `parameters.steps` | 选填 | 默认 `1200`;渲染步进数限制在 `1~4000`。 |
|
|
3161
|
+
| `parameters.densityThreshold` | 选填 | 默认 `0.08`,按色带位置过滤低密度样本的起点。 |
|
|
3162
|
+
| `parameters.densitySoftness` | 选填 | 默认 `0.47`,低密度过滤的过渡宽度。 |
|
|
3163
|
+
| `parameters.densityScale` | 选填 | 默认 `0.34`,每步透明度累积强度。 |
|
|
3164
|
+
| `parameters.opacity / brightness` | 选填 | 默认 `0.72 / 1`,整体透明度和颜色亮度倍率。 |
|
|
3165
|
+
| `parameters.normalizedColorRamp` | 选填 | 默认 `0`;设为 `1` 时用 `data / 255` 定位色带。 |
|
|
1866
3166
|
| `parameters.xCut / yCut / zCut` | 选填 | 三个方向的裁切位置,默认 `-0.5`。 |
|
|
1867
|
-
| `colorRamp`
|
|
3167
|
+
| `colorRamp` | 选填 | CSS 颜色数组、RGBA 数组列表或展平的 RGBA 字节数组。 |
|
|
1868
3168
|
| `geometry` / `dim` | 选填 | 自定义体渲染几何或维度,普通业务通常不需要传。 |
|
|
1869
3169
|
| `visible` | 选填 | 初始是否显示,默认显示。 |
|
|
1870
3170
|
|
|
@@ -1874,27 +3174,28 @@ console.log(stateResult.data)
|
|
|
1874
3174
|
|
|
1875
3175
|
三维切片/剖面渲染也是 Cesium 专有能力,直接通过 `BaseGIS` 调用。它把三维网格数据按 X、Y、Z 三个方向切出剖面,适合气象温度、湿度、风场标量、污染物浓度等三维格点数据查看。
|
|
1876
3176
|
|
|
1877
|
-
这里的“切片”指三维数据剖面,不是 `ImageLayerController`
|
|
3177
|
+
这里的“切片”指三维数据剖面,不是 `ImageLayerController` 里的大图切片。当前 Z 轴按 hPa 气压处理,内部将气压换算为高度后放大 10 倍显示,不接受任意米制高度层。
|
|
1878
3178
|
|
|
1879
3179
|
### 数据格式
|
|
1880
3180
|
|
|
1881
3181
|
```js
|
|
1882
3182
|
const sectionData = {
|
|
1883
3183
|
Bound: [
|
|
1884
|
-
1000, // 0: LayerMax
|
|
3184
|
+
1000, // 0: LayerMax,起始气压值(hPa),较大气压在下方。
|
|
1885
3185
|
108.68, // 1: LonMin,经度最小值。
|
|
1886
3186
|
28.59, // 2: LatMin,纬度最小值。
|
|
1887
3187
|
10, // 3: LayerNums,层数。
|
|
1888
3188
|
147, // 4: LonNums,经向格点数。
|
|
1889
3189
|
198, // 5: LatNums,纬向格点数。
|
|
1890
|
-
900, // 6: DLayer
|
|
3190
|
+
900, // 6: DLayer,气压跨度;LayerMin = LayerMax - DLayer。
|
|
1891
3191
|
16.74, // 7: DLon,经度跨度。
|
|
1892
3192
|
16.71, // 8: DLat,纬度跨度。
|
|
1893
|
-
1, // 9: ValueScale
|
|
1894
|
-
1, // 10:
|
|
3193
|
+
1, // 9: ValueScale,业务值 = 原始值 / ValueScale。
|
|
3194
|
+
1, // 10: Stride,每个格点的分量数;标量为 1。
|
|
1895
3195
|
[1000, 925, 850, 700, 600, 500, 400, 300, 200, 100], // 11: LayerList,气压层列表。
|
|
1896
3196
|
],
|
|
1897
|
-
//
|
|
3197
|
+
// 长度必须等于 LayerNums * LatNums * LonNums * Stride。
|
|
3198
|
+
// 每层从西南角开始,经度最快变化,再纬度,最后气压层。
|
|
1898
3199
|
DataAry: valueList,
|
|
1899
3200
|
}
|
|
1900
3201
|
|
|
@@ -1913,6 +3214,8 @@ const optionData = {
|
|
|
1913
3214
|
}
|
|
1914
3215
|
```
|
|
1915
3216
|
|
|
3217
|
+
`Bound[11]` 可传 `null` 表示等间距气压层;传列表时长度必须等于 `LayerNums`,首项必须等于 `Bound[0]`。`Stride > 1` 时当前实现计算各分量的模长。
|
|
3218
|
+
|
|
1916
3219
|
### 加载或更新数据
|
|
1917
3220
|
|
|
1918
3221
|
同一个 `layerId` 重复调用 `upsertSectionLayer` 就是更新数据。适配层会清理旧切片,再加载新数据。
|
|
@@ -1936,15 +3239,16 @@ const result = mapCore.upsertSectionLayer({
|
|
|
1936
3239
|
|
|
1937
3240
|
// 选填:是否显示坐标轴和刻度。
|
|
1938
3241
|
showAxis: false,
|
|
3242
|
+
// 选填:有 DEM 时避免近地切片被地形裁断,默认 false。
|
|
3243
|
+
ignoreTerrainDepth: true,
|
|
1939
3244
|
})
|
|
1940
3245
|
|
|
1941
|
-
if (
|
|
3246
|
+
if (result.success) {
|
|
3247
|
+
const state = result.data.state
|
|
3248
|
+
console.log(state.XRange, state.YRange, state.ZRange)
|
|
3249
|
+
} else {
|
|
1942
3250
|
console.warn(result.message)
|
|
1943
|
-
return
|
|
1944
3251
|
}
|
|
1945
|
-
|
|
1946
|
-
const state = result.data.state
|
|
1947
|
-
console.log(state.XRange, state.YRange, state.ZRange)
|
|
1948
3252
|
```
|
|
1949
3253
|
|
|
1950
3254
|
### 渲染 X / Y / Z 切片
|
|
@@ -1964,7 +3268,7 @@ mapCore.renderSectionLayer({
|
|
|
1964
3268
|
value: 39.9,
|
|
1965
3269
|
})
|
|
1966
3270
|
|
|
1967
|
-
// Z
|
|
3271
|
+
// Z 气压方向切片,单位 hPa。
|
|
1968
3272
|
mapCore.renderSectionLayer({
|
|
1969
3273
|
layerId: 'section-demo',
|
|
1970
3274
|
sectionType: 2,
|
|
@@ -1978,7 +3282,7 @@ mapCore.renderSectionLayer({
|
|
|
1978
3282
|
| --- | --- | --- |
|
|
1979
3283
|
| `0` | 经度方向剖面 | 经度值。 |
|
|
1980
3284
|
| `1` | 纬度方向剖面 | 纬度值。 |
|
|
1981
|
-
| `2` |
|
|
3285
|
+
| `2` | 气压方向剖面 | 气压值,单位 hPa。 |
|
|
1982
3286
|
| `3` | 全量剖面 | 可不传 `value`。 |
|
|
1983
3287
|
|
|
1984
3288
|
### 显隐、移除和定位
|
|
@@ -1994,16 +3298,16 @@ mapCore.removeSectionLayer({
|
|
|
1994
3298
|
sectionType: 2,
|
|
1995
3299
|
})
|
|
1996
3300
|
|
|
1997
|
-
// 移除整个切片图层。
|
|
1998
|
-
mapCore.removeSectionLayer({ layerId: 'section-demo' })
|
|
1999
|
-
|
|
2000
3301
|
// 飞到切片数据范围。
|
|
2001
3302
|
mapCore.flyToSectionLayer({ layerId: 'section-demo', duration: 0.8 })
|
|
3303
|
+
|
|
3304
|
+
// 移除整个切片图层。
|
|
3305
|
+
mapCore.removeSectionLayer({ layerId: 'section-demo' })
|
|
2002
3306
|
```
|
|
2003
3307
|
|
|
2004
3308
|
### hover 取值
|
|
2005
3309
|
|
|
2006
|
-
页面先用 Cesium
|
|
3310
|
+
页面先用 Cesium 拾取得到鼠标所在三维点,再将经纬度与对应气压交给 `sampleSectionLayerValue`。`hpa` 不是 Cesium 的 `cartographic.height`;应先还原 10 倍高度显示比例,再按剖面使用的气压高度关系换算。
|
|
2007
3311
|
|
|
2008
3312
|
```js
|
|
2009
3313
|
const result = mapCore.sampleSectionLayerValue({
|
|
@@ -2047,9 +3351,10 @@ if (result.success) {
|
|
|
2047
3351
|
| `colorInfo.rgbAry` | 建议必填 | 色标 RGB 数组。 |
|
|
2048
3352
|
| `boxInfo` | 选填 | 自定义剖面盒子范围。不传时根据 `dataInfo` 自动生成。 |
|
|
2049
3353
|
| `showAxis` | 选填 | 是否显示坐标轴和刻度。 |
|
|
2050
|
-
| `
|
|
3354
|
+
| `ignoreTerrainDepth` | 选填 | 默认 `false`;设为 `true` 时,可见剖面暂时关闭 globe 地形深度检测,不改变切片自身深度写入。 |
|
|
3355
|
+
| `sectionType` | 渲染、显隐、移除单个切片时必填 | `0` 经度,`1` 纬度,`2` 气压,`3` 全量。 |
|
|
2051
3356
|
| `value` / `param` | `sectionType` 为 `0/1/2` 时必填 | 切片位置值。 |
|
|
2052
|
-
| `lon / lat / hpa` | hover 取值必填 |
|
|
3357
|
+
| `lon / lat / hpa` | hover 取值必填 | 经度、纬度及换算后的气压(hPa),不是米制高度。 |
|
|
2053
3358
|
| `showZLayer` | hover 取值选填 | Z 切片是否参与 hover 命中,默认参与。 |
|
|
2054
3359
|
|
|
2055
3360
|
<a id="point-large-layer-controller"></a>
|
|
@@ -2062,160 +3367,54 @@ Leaflet 模式使用 BaseGIS 内置的 `pixi.js` 和 `leaflet-pixi-overlay` 异
|
|
|
2062
3367
|
|
|
2063
3368
|
如果业务目标是“地图缩小时按屏幕网格抽稀,只显示代表点”,应使用后文的 `PointDensityController`。
|
|
2064
3369
|
|
|
2065
|
-
###
|
|
2066
|
-
|
|
2067
|
-
仓库内已有对应 demo:
|
|
2068
|
-
|
|
2069
|
-
- 路由:`/test-page-5`
|
|
2070
|
-
- 页面:`src/views/test-page-5/index.vue`
|
|
2071
|
-
- 当前 demo 覆盖能力:加载、更新、显隐、高亮、取消高亮、删除点位、清空、销毁、状态读取、视角复位。
|
|
2072
|
-
|
|
2073
|
-
demo 源码内部使用:
|
|
2074
|
-
|
|
2075
|
-
```js
|
|
2076
|
-
import { BaseGIS } from '@/gis'
|
|
2077
|
-
import { PointLargeLayerController } from '@/gis/methods'
|
|
2078
|
-
```
|
|
3370
|
+
### 基础用法
|
|
2079
3371
|
|
|
2080
|
-
|
|
3372
|
+
地图初始化成功后创建控制器,再调用 `load()` 加载点位。以下使用内置圆点,无需先准备图片资源;实际项目可通过 `icon / highlightIcon` 替换普通与高亮图标。
|
|
2081
3373
|
|
|
2082
3374
|
```js
|
|
2083
|
-
import { BaseGIS } from '@3clear/basegis'
|
|
2084
3375
|
import { PointLargeLayerController } from '@3clear/basegis/methods'
|
|
2085
|
-
```
|
|
2086
|
-
|
|
2087
|
-
### 使用方式一:构造时传入 mapCore
|
|
2088
|
-
|
|
2089
|
-
这是业务页面里最常用的写法。地图初始化完成后创建控制器,再调用 `load` 加载点位。
|
|
2090
|
-
|
|
2091
|
-
```js
|
|
2092
|
-
const mapCore = new BaseGIS({
|
|
2093
|
-
engineType: 'leaflet',
|
|
2094
|
-
containerId: 'map',
|
|
2095
|
-
})
|
|
2096
|
-
|
|
2097
|
-
const initResult = mapCore.init()
|
|
2098
|
-
if (!initResult.success) {
|
|
2099
|
-
console.warn(initResult.message)
|
|
2100
|
-
}
|
|
2101
3376
|
|
|
2102
3377
|
const pointLayer = new PointLargeLayerController({
|
|
2103
|
-
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
// 默认高亮状态图标。调用 setHighlight(id) 后使用。
|
|
2120
|
-
highlightIcon: highlightPointIcon,
|
|
2121
|
-
|
|
2122
|
-
// 样式规则读取的字段名。下面 styleRules 里的 gt/default 会基于 value 判断。
|
|
2123
|
-
styleField: 'value',
|
|
2124
|
-
|
|
2125
|
-
// 点位样式规则。从上到下匹配,命中后使用该规则里的 icon/highlightIcon/style 等配置。
|
|
2126
|
-
styleRules: [
|
|
2127
|
-
{
|
|
2128
|
-
// value < 300 时命中
|
|
2129
|
-
lt: 300,
|
|
2130
|
-
icon: lowPointIcon,
|
|
2131
|
-
highlightIcon: highlightPointIcon,
|
|
2132
|
-
},
|
|
2133
|
-
{
|
|
2134
|
-
// value > 780 时命中
|
|
2135
|
-
gt: 780,
|
|
2136
|
-
icon: warningPointIcon,
|
|
2137
|
-
highlightIcon: highlightPointIcon,
|
|
2138
|
-
},
|
|
2139
|
-
{
|
|
2140
|
-
// 300 <= value < 780
|
|
2141
|
-
gte: 300,
|
|
2142
|
-
lt: 780,
|
|
2143
|
-
icon: normalPointIcon,
|
|
2144
|
-
highlightIcon: highlightPointIcon,
|
|
2145
|
-
},
|
|
2146
|
-
{
|
|
2147
|
-
// 兜底规则。没有命中前面规则的点位使用普通图标。
|
|
2148
|
-
default: true,
|
|
2149
|
-
icon: normalPointIcon,
|
|
2150
|
-
highlightIcon: highlightPointIcon,
|
|
2151
|
-
},
|
|
2152
|
-
],
|
|
2153
|
-
|
|
2154
|
-
// 普通图标宽度,单位像素。
|
|
2155
|
-
width: 18,
|
|
2156
|
-
|
|
2157
|
-
// 普通图标高度,单位像素。
|
|
2158
|
-
height: 18,
|
|
2159
|
-
|
|
2160
|
-
// 普通图标缩放比例。
|
|
2161
|
-
scale: 1,
|
|
2162
|
-
|
|
2163
|
-
// 未传 icon 时,可以使用内置圆点图标。下面这些配置用于控制圆点样式。
|
|
2164
|
-
// color: '#19d3a2',
|
|
2165
|
-
// outlineColor: '#ffffff',
|
|
2166
|
-
// outlineWidth: 2,
|
|
2167
|
-
|
|
2168
|
-
// 未传 highlightIcon 时,可以使用内置高亮圆点图标。下面这些配置用于控制高亮圆点样式。
|
|
2169
|
-
// highlightColor: '#ffcf33',
|
|
2170
|
-
// highlightOutlineColor: '#ffffff',
|
|
2171
|
-
// highlightWidth: 20,
|
|
2172
|
-
// highlightHeight: 20,
|
|
2173
|
-
// highlightScale: 1.18,
|
|
2174
|
-
|
|
2175
|
-
// 分帧构建批量大小。点位很多时可以调大或调小,默认 5000。
|
|
2176
|
-
// chunkSize: 10000,
|
|
2177
|
-
|
|
2178
|
-
// Cesium 专用:禁用深度检测距离。需要点位不被地形或模型遮挡时可使用。
|
|
2179
|
-
// disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
2180
|
-
|
|
2181
|
-
// Cesium 专用:按相机距离缩放图标。
|
|
2182
|
-
// 数组含义:[近距离, 近距离缩放, 远距离, 远距离缩放]。
|
|
2183
|
-
// scaleByDistance: [50000, 1, 9000000, 0.34],
|
|
2184
|
-
|
|
2185
|
-
// 点击点位回调。event.data 是原始点位数据。
|
|
2186
|
-
onClick: ({ id, data }) => {`点击点位:${data || id}。`},
|
|
2187
|
-
|
|
3378
|
+
mapCore,
|
|
3379
|
+
layerId: 'station-large',
|
|
3380
|
+
idKey: 'stationCode',
|
|
3381
|
+
width: 18,
|
|
3382
|
+
height: 18,
|
|
3383
|
+
color: '#ffffff', // 白色基础纹理,供分级规则着色。
|
|
3384
|
+
styleField: 'value',
|
|
3385
|
+
// 从上到下匹配,首个命中的规则生效。
|
|
3386
|
+
styleRules: [
|
|
3387
|
+
{ gte: 150, style: { color: '#ff4d4f' } },
|
|
3388
|
+
{ gte: 75, style: { color: '#faad14' } },
|
|
3389
|
+
{ default: true, style: { color: '#19d3a2' } },
|
|
3390
|
+
],
|
|
3391
|
+
onClick({ id, data }) {
|
|
3392
|
+
console.log('点击点位', id, data)
|
|
3393
|
+
},
|
|
2188
3394
|
})
|
|
2189
3395
|
|
|
2190
3396
|
await pointLayer.load({
|
|
2191
3397
|
points: [
|
|
2192
|
-
{
|
|
2193
|
-
|
|
2194
|
-
|
|
2195
|
-
longitude: 104,
|
|
2196
|
-
latitude: 35,
|
|
2197
|
-
value: 86,
|
|
2198
|
-
},
|
|
3398
|
+
{ stationCode: 'A001', name: '站点 A001', longitude: 104, latitude: 35, value: 86 },
|
|
3399
|
+
{ stationCode: 'A002', name: '站点 A002', longitude: 105, latitude: 35, value: 42 },
|
|
3400
|
+
{ stationCode: 'A003', name: '站点 A003', longitude: 106, latitude: 35, value: 168 },
|
|
2199
3401
|
],
|
|
2200
3402
|
})
|
|
2201
3403
|
```
|
|
2202
3404
|
|
|
2203
3405
|
`styleRules` 常用匹配方式:
|
|
2204
3406
|
|
|
2205
|
-
| 写法
|
|
2206
|
-
|
|
2207
|
-
| `{ field: 'aqi', min: 51, max: 100 }`
|
|
2208
|
-
| `{ gt:
|
|
2209
|
-
| `{ gte: 51, lt: 101 }`
|
|
2210
|
-
| `{ values: ['优', '良'] }`
|
|
2211
|
-
| `{ operator: '>', value: 100 }`
|
|
2212
|
-
| `{ when:(point, index, record)
|
|
2213
|
-
| `{ default: true }`
|
|
2214
|
-
|
|
2215
|
-
|
|
2216
|
-
|
|
3407
|
+
| 写法 | 说明 |
|
|
3408
|
+
| --- | --- |
|
|
3409
|
+
| `{ field: 'aqi', min: 51, max: 100 }` | 指定字段并按区间匹配。 |
|
|
3410
|
+
| `{ gt: 150 }` | 使用 `styleField` 指定的字段做大于判断。 |
|
|
3411
|
+
| `{ gte: 51, lt: 101 }` | 使用 `styleField` 指定的字段做区间判断。 |
|
|
3412
|
+
| `{ values: ['优', '良'] }` | 命中指定值集合。 |
|
|
3413
|
+
| `{ operator: '>', value: 100 }` | 支持 `> / >= / < / <= / == / === / != / !== / in`。 |
|
|
3414
|
+
| `{ when: (point, index, record) => point.value > 100 }` | 自定义匹配函数。 |
|
|
3415
|
+
| `{ default: true }` | 兜底规则。 |
|
|
2217
3416
|
|
|
2218
|
-
###
|
|
3417
|
+
### 更新数据或样式
|
|
2219
3418
|
|
|
2220
3419
|
时间轴、实时刷新等场景中,建议复用同一个控制器实例,不要每次刷新都重新 `new PointLargeLayerController()`。
|
|
2221
3420
|
|
|
@@ -2550,7 +3749,7 @@ onBeforeUnmount(() => {
|
|
|
2550
3749
|
<style scoped lang="scss">
|
|
2551
3750
|
.station-cluster-map {
|
|
2552
3751
|
width: 100%;
|
|
2553
|
-
height:
|
|
3752
|
+
height: 100vh;
|
|
2554
3753
|
}
|
|
2555
3754
|
</style>
|
|
2556
3755
|
```
|
|
@@ -2602,9 +3801,11 @@ if (!result.success) {
|
|
|
2602
3801
|
单点点击的第一个参数是原始点位数据:
|
|
2603
3802
|
|
|
2604
3803
|
```js
|
|
2605
|
-
|
|
2606
|
-
|
|
2607
|
-
|
|
3804
|
+
await stationCluster.setConfig({
|
|
3805
|
+
onClick(point, engineObject, event) {
|
|
3806
|
+
console.log(point.id)
|
|
3807
|
+
},
|
|
3808
|
+
})
|
|
2608
3809
|
```
|
|
2609
3810
|
|
|
2610
3811
|
聚合点击的第一个参数结构如下:
|
|
@@ -2735,9 +3936,9 @@ mapCore.removePointClusterLayer({ layerId: 'station-cluster' })
|
|
|
2735
3936
|
|
|
2736
3937
|
仓库内已有多个点位抽稀 demo:
|
|
2737
3938
|
|
|
2738
|
-
- `/test-page-6`:站点 ICON 抽稀,使用 `imageCallback` 按数据绘制站点图标。
|
|
2739
3939
|
- `/test-page-8`:空气质量站点抽稀,使用固定 `image` 图标。
|
|
2740
3940
|
- `/test-page-13`:空气质量业务页里的城市点位抽稀。
|
|
3941
|
+
- `/test-page-41`:`imageCallback` 同步返回 Canvas 图标和 `pulse` 告警扩散参数。
|
|
2741
3942
|
|
|
2742
3943
|
### 基础用法
|
|
2743
3944
|
|
|
@@ -2763,12 +3964,31 @@ const density = new PointDensityController({
|
|
|
2763
3964
|
// 同一网格内保留哪个点。字段值越大越优先显示。
|
|
2764
3965
|
priorityKey: 'level',
|
|
2765
3966
|
|
|
2766
|
-
//
|
|
2767
|
-
|
|
2768
|
-
|
|
2769
|
-
|
|
2770
|
-
|
|
2771
|
-
|
|
3967
|
+
// 直接复用 BaseGIS 内置 Canvas 图标。
|
|
3968
|
+
imageCallback(point) {
|
|
3969
|
+
const icon = mapCore.createMarkerIcon({
|
|
3970
|
+
type: 'image-value-label',
|
|
3971
|
+
image: factoryImage,
|
|
3972
|
+
imageSize: [24, 24],
|
|
3973
|
+
showValue: false,
|
|
3974
|
+
showLabel: false,
|
|
3975
|
+
}, point)
|
|
3976
|
+
|
|
3977
|
+
return {
|
|
3978
|
+
...icon,
|
|
3979
|
+
iconAnchor: 'center',
|
|
3980
|
+
pulse: point.status === 'alarm'
|
|
3981
|
+
? {
|
|
3982
|
+
color: '#ef4444',
|
|
3983
|
+
size: 72,
|
|
3984
|
+
duration: 1.6,
|
|
3985
|
+
ringCount: 2,
|
|
3986
|
+
ringWidth: 2,
|
|
3987
|
+
ringOpacity: 0.75,
|
|
3988
|
+
}
|
|
3989
|
+
: false,
|
|
3990
|
+
}
|
|
3991
|
+
},
|
|
2772
3992
|
|
|
2773
3993
|
// 点击点位回调。第一个参数是原始点位数据。
|
|
2774
3994
|
onClick(point) {
|
|
@@ -2783,122 +4003,13 @@ const density = new PointDensityController({
|
|
|
2783
4003
|
|
|
2784
4004
|
await density.load({
|
|
2785
4005
|
points: [
|
|
2786
|
-
{ staNum: 'A001', longitude: 104, latitude: 35, level: 5 },
|
|
2787
|
-
{ staNum: 'A002', longitude: 104.01, latitude: 35.01, level: 3 },
|
|
4006
|
+
{ staNum: 'A001', name: '站点一', longitude: 104, latitude: 35, level: 5, value: 22, status: 'normal' },
|
|
4007
|
+
{ staNum: 'A002', name: '站点二', longitude: 104.01, latitude: 35.01, level: 3, value: 68, status: 'alarm' },
|
|
2788
4008
|
],
|
|
2789
4009
|
})
|
|
2790
4010
|
```
|
|
2791
4011
|
|
|
2792
|
-
|
|
2793
|
-
|
|
2794
|
-
下面的配置接近 `test-page-6` 的写法,字段已加注释。业务中按需保留即可。
|
|
2795
|
-
|
|
2796
|
-
```js
|
|
2797
|
-
const density = new PointDensityController({
|
|
2798
|
-
// BaseGIS 实例。控制器只通过 BaseGIS 调用当前引擎能力,不直接依赖 Cesium / Leaflet。
|
|
2799
|
-
mapCore,
|
|
2800
|
-
|
|
2801
|
-
// 图层唯一标识。后续 update/show/hide/clear/destroy 都按该 id 定位图层。
|
|
2802
|
-
layerId: 'station-density',
|
|
2803
|
-
|
|
2804
|
-
// 点位唯一值字段。默认 id;如果点位唯一值在 properties 中,也会尝试读取 properties[idKey]。
|
|
2805
|
-
idKey: 'staNum',
|
|
2806
|
-
|
|
2807
|
-
// 初始是否显示图层。不传默认 true。
|
|
2808
|
-
visible: true,
|
|
2809
|
-
|
|
2810
|
-
// 原始点位数据。也可以不在构造时传,后续 density.load({ points }) 传入。
|
|
2811
|
-
points: stationList,
|
|
2812
|
-
|
|
2813
|
-
// 经度字段候选列表。默认已支持 longitude/lon/lng/x。
|
|
2814
|
-
longitudeKeys: ['longitude', 'lon', 'lng', 'x'],
|
|
2815
|
-
|
|
2816
|
-
// 纬度字段候选列表。默认已支持 latitude/lat/y。
|
|
2817
|
-
latitudeKeys: ['latitude', 'lat', 'y'],
|
|
2818
|
-
|
|
2819
|
-
// 高度字段候选列表。默认已支持 height/altitude/z。
|
|
2820
|
-
heightKeys: ['height', 'altitude', 'z'],
|
|
2821
|
-
|
|
2822
|
-
// 是否开启抽稀。true 时会按屏幕网格去重;false 时只做视野过滤,不做网格碰撞去重。
|
|
2823
|
-
enableThinning: true,
|
|
2824
|
-
|
|
2825
|
-
// 抽稀网格大小,单位屏幕像素。值越大,保留点越少;值越小,保留点越多。
|
|
2826
|
-
gridSize: 150,
|
|
2827
|
-
|
|
2828
|
-
// gridSize 的别名。如果同时传 gridSize 和 pixelRange,以 gridSize 为准。
|
|
2829
|
-
// pixelRange: 150,
|
|
2830
|
-
|
|
2831
|
-
// 最多显示点数量。超过后会按优先级截断。不传默认 Infinity。
|
|
2832
|
-
maxCount: 500,
|
|
2833
|
-
|
|
2834
|
-
// 同一网格内点位优先级字段。字段值越大越优先保留。
|
|
2835
|
-
priorityKey: 'level',
|
|
2836
|
-
|
|
2837
|
-
// 自定义优先级函数。返回值越大越优先保留;传了它后优先级逻辑可完全由业务决定。
|
|
2838
|
-
// priorityCallback(point, markerOrBillboard, index) {
|
|
2839
|
-
// return point.level * 100 + point.value
|
|
2840
|
-
// },
|
|
2841
|
-
|
|
2842
|
-
// 默认图标地址。支持图片 URL、base64、data URL。
|
|
2843
|
-
image: '/icons/station.png',
|
|
2844
|
-
|
|
2845
|
-
// 图标地址别名,和 image 作用一致。
|
|
2846
|
-
// icon: '/icons/station.png',
|
|
2847
|
-
// iconUrl: '/icons/station.png',
|
|
2848
|
-
|
|
2849
|
-
// 按点位动态生成图标。适合空气质量、告警等级等需要每个点图标不同的场景。
|
|
2850
|
-
// 返回值可以是图片地址、base64、data URL。
|
|
2851
|
-
// imageCallback(point, index) {
|
|
2852
|
-
// return createStationIcon(point)
|
|
2853
|
-
// },
|
|
2854
|
-
|
|
2855
|
-
// 图标宽度,单位像素。
|
|
2856
|
-
width: 28,
|
|
2857
|
-
|
|
2858
|
-
// 图标高度,单位像素。
|
|
2859
|
-
height: 28,
|
|
2860
|
-
|
|
2861
|
-
// 地图移动、缩放后重新计算抽稀的节流时间,单位毫秒。
|
|
2862
|
-
throttleTime: 120,
|
|
2863
|
-
|
|
2864
|
-
// Cesium 专用:视野过滤缓冲,单位屏幕像素。
|
|
2865
|
-
// 值越大,视野边缘附近的点越不容易在移动时频繁出现/消失。
|
|
2866
|
-
viewportBuffer: 100,
|
|
2867
|
-
|
|
2868
|
-
// Cesium 专用:3D 场景下是否剔除地球背面的点。
|
|
2869
|
-
cullByGlobe: true,
|
|
2870
|
-
|
|
2871
|
-
// Cesium 专用:Billboard 是否贴地。
|
|
2872
|
-
clampToGround: false,
|
|
2873
|
-
|
|
2874
|
-
// Cesium 专用:Billboard 缩放比例。
|
|
2875
|
-
scale: 1,
|
|
2876
|
-
|
|
2877
|
-
// Cesium 专用:禁用深度检测距离。
|
|
2878
|
-
disableDepthTestDistance: Number.POSITIVE_INFINITY,
|
|
2879
|
-
|
|
2880
|
-
// Cesium 专用:平滑更新,减少刷新抽稀结果时的突兀感。
|
|
2881
|
-
smoothUpdate: true,
|
|
2882
|
-
smoothUpdateFrames: 2,
|
|
2883
|
-
|
|
2884
|
-
// Leaflet 专用:视野 bounds 扩展比例。
|
|
2885
|
-
// 例如 0.1 表示在当前视野基础上向外扩展 10% 后再过滤点位。
|
|
2886
|
-
boundsBufferRatio: 0,
|
|
2887
|
-
|
|
2888
|
-
// Leaflet 专用:Marker 层级偏移。
|
|
2889
|
-
zIndexOffset: 0,
|
|
2890
|
-
|
|
2891
|
-
// 点位点击回调。第一个参数是原始点位数据。
|
|
2892
|
-
onClick(point) {
|
|
2893
|
-
console.log(point)
|
|
2894
|
-
},
|
|
2895
|
-
|
|
2896
|
-
// 状态变化回调。每次抽稀刷新、显隐、清空后会尽量触发。
|
|
2897
|
-
onStateChange(state) {
|
|
2898
|
-
console.log(state.visibleCount, state.hiddenCount)
|
|
2899
|
-
},
|
|
2900
|
-
})
|
|
2901
|
-
```
|
|
4012
|
+
上例中的 `factoryImage` 是创建抽稀层前已加载完成的 `Image`。`pulse` 使用与普通 Marker 相同的参数,只为抽稀后实际保留的点创建;点被替换、移出视野、隐藏、清空或删除时,扩散圈会随图标一起回收。
|
|
2902
4013
|
|
|
2903
4014
|
### 点位数据格式
|
|
2904
4015
|
|
|
@@ -3044,7 +4155,7 @@ density.destroy()
|
|
|
3044
4155
|
| `priorityKey` | 否 | - | 同一网格内点位优先级字段,值越大越优先显示。 |
|
|
3045
4156
|
| `priorityCallback` | 否 | - | 自定义优先级函数,返回值越大越优先显示。 |
|
|
3046
4157
|
| `image` / `icon` / `iconUrl` | 否 | - | 默认图标地址。 |
|
|
3047
|
-
| `imageCallback` | 否 | - |
|
|
4158
|
+
| `imageCallback` | 否 | - | 图标生成函数;配置对象可附带 `pulse` 告警扩散参数。 |
|
|
3048
4159
|
| `width` | 否 | `32` | 图标宽度,单位像素。 |
|
|
3049
4160
|
| `height` | 否 | `32` | 图标高度,单位像素。 |
|
|
3050
4161
|
| `throttleTime` | 否 | `120` | 地图移动、缩放后刷新抽稀的节流时间,单位毫秒。 |
|
|
@@ -3088,7 +4199,7 @@ console.log(state)
|
|
|
3088
4199
|
|
|
3089
4200
|
## 等值线与中心标注能力选择
|
|
3090
4201
|
|
|
3091
|
-
|
|
4202
|
+
已有线坐标或中心坐标时用 `ContourLayerController`,输入栅格时用 `RasterContourController`。线值标签与中心标注均使用通用 Contour 渲染配置。
|
|
3092
4203
|
|
|
3093
4204
|
| 手里的数据 / 目标 | 使用入口 | 负责内容 |
|
|
3094
4205
|
| --- | --- | --- |
|
|
@@ -3384,7 +4495,7 @@ await rasterContour.loadGrid({
|
|
|
3384
4495
|
| `minimumLinePoints` | `number` | 否 | `3` | 最短线点数,用于过滤栅格四角的两点补边。 |
|
|
3385
4496
|
| `coordinatePrecision` | `number` | 否 | `6` | 输出经纬度小数位数。 |
|
|
3386
4497
|
| `visible` | `boolean` | 否 | `true` | 初始显隐。 |
|
|
3387
|
-
| 其他渲染参数 | - | 否 | - | 复用 [`ContourLayerController` 核心参数](#contour-layer-parameters),如 `color/
|
|
4498
|
+
| 其他渲染参数 | - | 否 | - | 复用 [`ContourLayerController` 核心参数](#contour-layer-parameters),如 `color/weight/styleCallback/showLabel/labelViewportPadding`;顶层 `width/height` 为栅格尺寸,线宽请用 `weight` 或 `styleCallback` 返回的 `width/weight`。 |
|
|
3388
4499
|
|
|
3389
4500
|
级别选择优先级为 `thresholds` → `interval` → `thresholdCount`。显式传入 `thresholds` 时,只保留实际值域内的级别。
|
|
3390
4501
|
|
|
@@ -3506,10 +4617,14 @@ await pressureContour.load({
|
|
|
3506
4617
|
|
|
3507
4618
|
<a id="wind-field-methods"></a>
|
|
3508
4619
|
|
|
3509
|
-
## WindFieldMethods
|
|
4620
|
+
## Canvas 风场(WindFieldMethods)
|
|
3510
4621
|
|
|
3511
4622
|
用于叠加 Canvas 风场粒子动画。它通过 `BaseGIS` 获取容器、投影、视野范围和视图变化事件,不直接依赖某个引擎。
|
|
3512
4623
|
|
|
4624
|
+
与 `upsertWindLayer()` 不同,该控制器在两个引擎中都使用 Canvas,可叠加风速底图,但不参与 BaseGIS 托管恢复。切换引擎时先清理旧控制器,再在新地图初始化后重新挂载并加载数据。
|
|
4625
|
+
|
|
4626
|
+
Leaflet 的统一风场入口使用的是另一套 Canvas 渲染器。本节控制器使用 `particleCount / velocityScale` 等参数,不能直接套用统一入口的 `maxParticles / speedFactor`。
|
|
4627
|
+
|
|
3513
4628
|
```js
|
|
3514
4629
|
import { WindFieldMethods } from '@3clear/basegis/methods'
|
|
3515
4630
|
|
|
@@ -3519,9 +4634,9 @@ wind.addWindField({
|
|
|
3519
4634
|
id: 'wind-main',
|
|
3520
4635
|
data: windData,
|
|
3521
4636
|
particleCount: 3000,
|
|
3522
|
-
velocityScale: 0.01,
|
|
3523
4637
|
lineWidth: 1,
|
|
3524
|
-
|
|
4638
|
+
// 单色粒子用一档色标;不传则使用内置风速分级色标。
|
|
4639
|
+
particleColorScale: [{ value: 0, color: '#50b4ff' }],
|
|
3525
4640
|
})
|
|
3526
4641
|
|
|
3527
4642
|
wind.updateWindField({
|
|
@@ -3561,11 +4676,9 @@ const wind = new WindFieldMethods({ mapCore })
|
|
|
3561
4676
|
```js
|
|
3562
4677
|
const windData = {
|
|
3563
4678
|
// [经度最小值, 纬度最小值, 经向网格数, 纬向网格数, 经度跨度, 纬度跨度, 数值缩放]
|
|
3564
|
-
Bound: [
|
|
4679
|
+
Bound: [100, 10, 2, 2, 10, 10, 10],
|
|
3565
4680
|
// 从左下角开始,按行平铺;每个格点两个值:[u, v]
|
|
3566
|
-
DataAry: [
|
|
3567
|
-
// u0, v0, u1, v1, ...
|
|
3568
|
-
],
|
|
4681
|
+
DataAry: [30, 10, 40, 15, 20, 10, 35, 5],
|
|
3569
4682
|
}
|
|
3570
4683
|
```
|
|
3571
4684
|
|
|
@@ -3606,12 +4719,12 @@ const windData = {
|
|
|
3606
4719
|
| `particleCount` | `number` | `1400` | 粒子总数。数值越大越密,渲染开销越高。 |
|
|
3607
4720
|
| `maxFrameParticles` | `number` | `1200` | 单帧最多推进和绘制的粒子数。 |
|
|
3608
4721
|
| `frameParticleLimit` | `number` | `1200` | `maxFrameParticles` 的别名。 |
|
|
3609
|
-
| `sceneModeMaxFrameParticles` | `number` | `0` |
|
|
4722
|
+
| `sceneModeMaxFrameParticles` | `number` | `0` | 大于 `0` 时进一步限制 2D / 2.5D 场景每帧推进的粒子数,且不超过 `maxFrameParticles`。 |
|
|
3610
4723
|
| `maxAge` | `number` | `58` | 粒子最大生命周期,超过后重新随机出生。 |
|
|
3611
4724
|
| `frameRate` | `number` | `30` | 粒子动画目标帧率,内部限制在 `1 ~ 60`。 |
|
|
3612
4725
|
| `velocityScale` | `number` | `900` | 风速到粒子位移的缩放系数。数值越大粒子移动越快。 |
|
|
3613
4726
|
| `lineWidth` | `number` | `0.85` | 粒子轨迹基础线宽。 |
|
|
3614
|
-
| `color` | `string` | `rgba(230, 248, 255, 0.52)` |
|
|
4727
|
+
| `color` | `string` | `rgba(230, 248, 255, 0.52)` | 粒子兜底颜色;默认已有 `particleColorScale`,单色效果请使用一档粒子色标。 |
|
|
3615
4728
|
| `particleOpacity` | `number` | `0.58` | 粒子轨迹透明度。 |
|
|
3616
4729
|
| `fadeOpacity` | `number` | `0.86` | 拖尾淡出强度,越接近 `1` 轨迹残留越长。 |
|
|
3617
4730
|
| `blendMode` | `string` | `lighter` | Canvas 合成模式,例如 `source-over`、`lighter`。 |
|
|
@@ -3670,70 +4783,6 @@ const windData = {
|
|
|
3670
4783
|
| `bounds` | 风场数据范围 `{ west, south, east, north }`。 |
|
|
3671
4784
|
| `center` | 风场中心 `{ lon, lat }`。 |
|
|
3672
4785
|
|
|
3673
|
-
## 在 Vue 中封装 Hook
|
|
3674
|
-
|
|
3675
|
-
推荐页面用 hook 管理生命周期,组件只处理 UI。
|
|
3676
|
-
|
|
3677
|
-
```js
|
|
3678
|
-
import { onBeforeUnmount, onMounted, shallowRef } from 'vue'
|
|
3679
|
-
import { BaseGIS } from '@3clear/basegis'
|
|
3680
|
-
|
|
3681
|
-
export function useBaseGIS(options = {}) {
|
|
3682
|
-
const mapCore = shallowRef(null)
|
|
3683
|
-
|
|
3684
|
-
onMounted(() => {
|
|
3685
|
-
mapCore.value = new BaseGIS(options)
|
|
3686
|
-
mapCore.value.init()
|
|
3687
|
-
})
|
|
3688
|
-
|
|
3689
|
-
onBeforeUnmount(() => {
|
|
3690
|
-
mapCore.value?.destroy()
|
|
3691
|
-
mapCore.value = null
|
|
3692
|
-
})
|
|
3693
|
-
|
|
3694
|
-
async function setEngine(engineType) {
|
|
3695
|
-
if (!mapCore.value || mapCore.value.getEngineType() === engineType) {
|
|
3696
|
-
return { success: true }
|
|
3697
|
-
}
|
|
3698
|
-
|
|
3699
|
-
return mapCore.value.setEngine(engineType, {
|
|
3700
|
-
...options,
|
|
3701
|
-
})
|
|
3702
|
-
}
|
|
3703
|
-
|
|
3704
|
-
return {
|
|
3705
|
-
mapCore,
|
|
3706
|
-
setEngine,
|
|
3707
|
-
}
|
|
3708
|
-
}
|
|
3709
|
-
```
|
|
3710
|
-
|
|
3711
|
-
使用:
|
|
3712
|
-
|
|
3713
|
-
```vue
|
|
3714
|
-
<template>
|
|
3715
|
-
<div id="map" class="map"></div>
|
|
3716
|
-
</template>
|
|
3717
|
-
|
|
3718
|
-
<script setup>
|
|
3719
|
-
import { useBaseGIS } from './useBaseGIS'
|
|
3720
|
-
|
|
3721
|
-
const { mapCore, setEngine } = useBaseGIS({
|
|
3722
|
-
engineType: 'cesium',
|
|
3723
|
-
containerId: 'map',
|
|
3724
|
-
})
|
|
3725
|
-
</script>
|
|
3726
|
-
```
|
|
3727
|
-
|
|
3728
|
-
BaseGIS 托管图层会自动恢复,页面不需要重新请求数据:
|
|
3729
|
-
|
|
3730
|
-
```js
|
|
3731
|
-
const result = await setEngine('leaflet')
|
|
3732
|
-
console.log(result.data?.restore)
|
|
3733
|
-
```
|
|
3734
|
-
|
|
3735
|
-
只有 GPU 专用风场、剖面、一次性绘制对象或页面直接创建的底层引擎对象需要在切换成功后自行恢复。
|
|
3736
|
-
|
|
3737
4786
|
## 能力支持说明
|
|
3738
4787
|
|
|
3739
4788
|
| 能力 | Cesium | Leaflet |
|
|
@@ -3741,20 +4790,29 @@ console.log(result.data?.restore)
|
|
|
3741
4790
|
| 2D 地图 | 支持 | 支持 |
|
|
3742
4791
|
| 2.5D / 3D 场景 | 支持 | 不支持 |
|
|
3743
4792
|
| 放大、缩小、重置 | 支持 | 支持 |
|
|
4793
|
+
| 多地图视角联动 | 支持 | 支持 |
|
|
4794
|
+
| 地图截图与 PNG 导出 | 支持 | 支持 |
|
|
3744
4795
|
| 底图切换 | 支持 | 支持 |
|
|
3745
4796
|
| 点线面文字 | 支持 | 支持 |
|
|
4797
|
+
| Canvas 数据图标与扩散 Marker | 支持 | 支持 |
|
|
4798
|
+
| GeoJSON 图层 | 支持 | 支持 |
|
|
3746
4799
|
| 独立线、虚线、渐变与沿线动画 | 支持 | 支持 |
|
|
4800
|
+
| 逐顶点色与路线时间裁剪 | 支持 | 支持 |
|
|
4801
|
+
| 台风路径与播放 | 支持 | 支持 |
|
|
3747
4802
|
| 图片覆盖层 | 支持 | 支持 |
|
|
3748
4803
|
| 网格 / TIF | 支持 | 支持 |
|
|
3749
4804
|
| 海量点 | 支持 | 支持 |
|
|
3750
4805
|
| 点位聚合 | 支持 | 支持 |
|
|
3751
4806
|
| 点位密度抽稀 | 支持 | 支持 |
|
|
3752
4807
|
| 等值线 | 支持 | 支持 |
|
|
3753
|
-
|
|
|
3754
|
-
|
|
|
3755
|
-
|
|
|
4808
|
+
| 等值线标签与 H/L 中心标注 | 支持 | 支持 |
|
|
4809
|
+
| 统一风场 `upsertWindLayer` | GPU | Canvas |
|
|
4810
|
+
| 独立 Canvas 风场 `WindFieldMethods` | 支持 | 支持 |
|
|
4811
|
+
| GPU 专用风场 `upsertGpuWindLayer` | 支持 | 不支持 |
|
|
4812
|
+
| 源解析弧线、灰色烟羽点云与目标汇聚体 | 支持 | 不支持 |
|
|
4813
|
+
| 三维体渲染、更新与取值 | 支持 | 不支持 |
|
|
3756
4814
|
| 三维切片 / 剖面渲染 | 支持 | 不支持 |
|
|
3757
|
-
| DEM
|
|
4815
|
+
| DEM 地形与夸张 | 支持 | 不支持 |
|
|
3758
4816
|
|
|
3759
4817
|
## 第三方许可
|
|
3760
4818
|
|
|
@@ -3786,14 +4844,15 @@ SOFTWARE.
|
|
|
3786
4844
|
|
|
3787
4845
|
## 本地开发与打包
|
|
3788
4846
|
|
|
3789
|
-
|
|
4847
|
+
包源码来自仓库 `src/gis`;`packages/basegis` 负责构建与发布配置。安装仓库依赖后,在仓库根目录执行:
|
|
3790
4848
|
|
|
3791
4849
|
```bash
|
|
3792
4850
|
npm run build:basegis
|
|
4851
|
+
npm run test:basegis
|
|
3793
4852
|
npm run pack:basegis
|
|
3794
4853
|
```
|
|
3795
4854
|
|
|
3796
|
-
`build:basegis`
|
|
4855
|
+
`build:basegis` 生成以下入口,以及它们依赖的共享、异步代码块:
|
|
3797
4856
|
|
|
3798
4857
|
```text
|
|
3799
4858
|
packages/basegis/dist/basegis.js
|
|
@@ -3803,23 +4862,27 @@ packages/basegis/dist/assets.js
|
|
|
3803
4862
|
packages/basegis/dist/style.css
|
|
3804
4863
|
```
|
|
3805
4864
|
|
|
3806
|
-
`pack:basegis`
|
|
4865
|
+
分发时必须保留完整 `packages/basegis/dist`,不能只复制上述入口文件。`pack:basegis` 不会自动构建,修改源码后应先执行 `build:basegis`。
|
|
4866
|
+
|
|
4867
|
+
`test:basegis` 会先构建包,再检查 Leaflet JS / CSS 外部依赖及样式产物边界,防止包重新内嵌一份官方 CSS。
|
|
4868
|
+
|
|
4869
|
+
当前包版本为 `0.1.4`,`pack:basegis` 会在仓库根目录生成以下文件;后续以 `packages/basegis/package.json` 中的版本及实际输出为准:
|
|
3807
4870
|
|
|
3808
4871
|
```text
|
|
3809
|
-
3clear-basegis-0.1.
|
|
4872
|
+
3clear-basegis-0.1.4.tgz
|
|
3810
4873
|
```
|
|
3811
4874
|
|
|
3812
4875
|
其他项目本地安装:
|
|
3813
4876
|
|
|
3814
4877
|
```bash
|
|
3815
|
-
npm install ./3clear-basegis-0.1.
|
|
4878
|
+
npm install ./3clear-basegis-0.1.4.tgz
|
|
3816
4879
|
```
|
|
3817
4880
|
|
|
3818
4881
|
## 发布到 npm
|
|
3819
4882
|
|
|
3820
4883
|
只发布 `packages/basegis`,不要在项目根目录执行 `npm publish`,否则会把整个业务项目上传到 npm。
|
|
3821
4884
|
|
|
3822
|
-
|
|
4885
|
+
更新包版本并重新构建后,先检查包内容:
|
|
3823
4886
|
|
|
3824
4887
|
```bash
|
|
3825
4888
|
npm pack --dry-run ./packages/basegis
|
|
@@ -3831,47 +4894,39 @@ npm pack --dry-run ./packages/basegis
|
|
|
3831
4894
|
npm publish ./packages/basegis --access public
|
|
3832
4895
|
```
|
|
3833
4896
|
|
|
3834
|
-
|
|
3835
|
-
|
|
3836
|
-
```json
|
|
3837
|
-
{
|
|
3838
|
-
"publishConfig": {
|
|
3839
|
-
"access": "restricted"
|
|
3840
|
-
}
|
|
3841
|
-
}
|
|
3842
|
-
```
|
|
3843
|
-
|
|
3844
|
-
如果希望公开发布,需要改为:
|
|
3845
|
-
|
|
3846
|
-
```json
|
|
3847
|
-
{
|
|
3848
|
-
"publishConfig": {
|
|
3849
|
-
"access": "public"
|
|
3850
|
-
}
|
|
3851
|
-
}
|
|
3852
|
-
```
|
|
4897
|
+
包已配置 `publishConfig.access: 'public'`,发布内容为完整 `dist`、README 和 npm 自动附带的包元信息,不包含测试页面、mock 数据和 Cesium 静态资源。
|
|
3853
4898
|
|
|
3854
4899
|
## 常见问题
|
|
3855
4900
|
|
|
3856
4901
|
### Cesium 地图不显示
|
|
3857
4902
|
|
|
3858
|
-
|
|
3859
|
-
|
|
3860
|
-
```text
|
|
3861
|
-
public/lib/Cesium/Cesium.js
|
|
3862
|
-
public/lib/Cesium/Widgets/widgets.css
|
|
3863
|
-
```
|
|
3864
|
-
|
|
3865
|
-
并确认页面初始化前能访问 `window.Cesium`。
|
|
4903
|
+
按[安装](#安装)章节加载 Cesium 脚本、样式及完整静态资源,确认初始化前存在 `window.Cesium`,并确保地图容器有实际宽高。部署在子路径时还要检查 `CESIUM_BASE_URL`。
|
|
3866
4904
|
|
|
3867
4905
|
### Leaflet 样式异常
|
|
3868
4906
|
|
|
3869
|
-
|
|
4907
|
+
BaseGIS JS 会导入宿主的 Leaflet 官方 CSS;使用 npm 包时还需引入自有样式。也可以在应用入口显式统一加载两者:
|
|
3870
4908
|
|
|
3871
4909
|
```js
|
|
4910
|
+
import 'leaflet/dist/leaflet.css'
|
|
3872
4911
|
import '@3clear/basegis/style.css'
|
|
3873
4912
|
```
|
|
3874
4913
|
|
|
4914
|
+
### 全局同时引入 BaseGIS 和原生 Leaflet 会覆盖吗
|
|
4915
|
+
|
|
4916
|
+
按[安装](#安装)中的共同使用示例引入,并确保解析到同一份 Leaflet。包不再把官方 CSS 复制进 `style.css`,宿主可复用对 `leaflet/dist/leaflet.css` 的引用;不要再叠加 CDN 或其他版本的 Leaflet。
|
|
4917
|
+
|
|
4918
|
+
这解决的是重复打包,不会隔离 CSS 的全局作用域。业务直接修改 `.leaflet-*` 仍会影响所有匹配的地图;页面定制应限定在自己的容器内,例如:
|
|
4919
|
+
|
|
4920
|
+
```vue
|
|
4921
|
+
<style scoped lang="scss">
|
|
4922
|
+
.native-map-page {
|
|
4923
|
+
:deep(.leaflet-popup-content) {
|
|
4924
|
+
color: #333;
|
|
4925
|
+
}
|
|
4926
|
+
}
|
|
4927
|
+
</style>
|
|
4928
|
+
```
|
|
4929
|
+
|
|
3875
4930
|
### 调用方法返回 NOT_INITIALIZED
|
|
3876
4931
|
|
|
3877
4932
|
说明地图还没有初始化成功。先执行:
|
|
@@ -3883,18 +4938,21 @@ console.log(result.success, result.message)
|
|
|
3883
4938
|
|
|
3884
4939
|
### 切换配置后地图没有变化
|
|
3885
4940
|
|
|
3886
|
-
`setConfig()`
|
|
4941
|
+
`setConfig()` 不会更新当前 adapter;需要再次 `init()` 才会按新配置重建地图。不要先手动 `destroy()`,以免清空托管图层快照:
|
|
3887
4942
|
|
|
3888
4943
|
```js
|
|
3889
4944
|
mapCore.setConfig(nextConfig)
|
|
3890
|
-
mapCore.init()
|
|
4945
|
+
const result = mapCore.init()
|
|
4946
|
+
if (result.success) await mapCore.whenReady()
|
|
3891
4947
|
```
|
|
3892
4948
|
|
|
3893
4949
|
`init()` 内部会先销毁旧适配器,再创建新实例。
|
|
3894
4950
|
|
|
4951
|
+
完整的配置项、生效时机和实时操作 API 对照见[地图初始化与运行时配置](#map-init-config)。
|
|
4952
|
+
|
|
3895
4953
|
### 切换引擎后图层没了
|
|
3896
4954
|
|
|
3897
|
-
|
|
4955
|
+
先确认通过 `setEngine()` 切换且没有提前 `destroy()`,再查看恢复结果:
|
|
3898
4956
|
|
|
3899
4957
|
```js
|
|
3900
4958
|
const result = await mapCore.setEngine('leaflet')
|
|
@@ -3903,4 +4961,4 @@ console.log(result.data?.restore?.restored)
|
|
|
3903
4961
|
console.log(result.data?.restore?.failed)
|
|
3904
4962
|
```
|
|
3905
4963
|
|
|
3906
|
-
|
|
4964
|
+
自动恢复与手动恢复范围见[切换后的图层处理](#managed-layer-restore)。GeoJSON、基础绘制、独立 Canvas/GPU 风场、剖面和页面监听需重新加载或绑定;使用多地图联动时还需调用 `viewLinks.refreshMap(id)`。
|