@mesh3d/cesium-vectortile-gl 0.4.4 → 0.4.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/.gitattributes +11 -0
- package/.gitconfig +3 -0
- package/.husky/pre-commit +1 -0
- package/.prettierignore +5 -0
- package/.vscode/settings.json +25 -0
- package/LICENSE.md +203 -203
- package/README.md +202 -167
- package/Source/Cesium.d.ts +2692 -2691
- package/Source/VectorTileLOD.js +720 -532
- package/Source/VectorTileRenderList.js +70 -70
- package/Source/VectorTileset.js +473 -447
- package/Source/layers/BackgroundRenderLayer.js +91 -89
- package/Source/layers/FillRenderLayer.js +18 -18
- package/Source/layers/IRenderLayer.js +160 -152
- package/Source/layers/LineRenderLayer.js +104 -94
- package/Source/layers/SymbolRenderLayer.js +30 -31
- package/Source/layers/index.js +23 -16
- package/Source/layers/registerRenderLayer.js +24 -24
- package/Source/layers/visualizers/FillLayerVisualizer.js +542 -426
- package/Source/layers/visualizers/ILayerVisualizer.js +90 -94
- package/Source/layers/visualizers/LineLayerVisualizer.js +702 -571
- package/Source/layers/visualizers/SymbolLayerVisualizer.js +514 -244
- package/Source/sources/GeoJSONSource.js +53 -46
- package/Source/sources/ISource.js +39 -39
- package/Source/sources/VectorSource.js +94 -52
- package/Source/sources/granularitySettings.js +23 -20
- package/Source/sources/index.js +6 -11
- package/Source/sources/registerSource.js +17 -19
- package/Source/style/StyleLayer.js +43 -43
- package/Source/style/StyleLayerProperties.js +44 -43
- package/Source/style/index.js +2 -2
- package/Source/symbol/SymbolPlacements.js +117 -88
- package/Source/workers/VectorTileWorker.js +41 -0
- package/Source/workers/ellipsoid.js +47 -0
- package/Source/workers/processTileTask.js +329 -0
- package/Source/workers/styleEvaluator.js +168 -0
- package/benchmark.html +148 -0
- package/dist/cvt-gl-worker.js +9274 -0
- package/dist/cvt-gl-worker.js.map +1 -0
- package/dist/cvt-gl.js +2570 -2001
- package/dist/cvt-gl.js.map +1 -1
- package/dist/cvt-gl.min.js +3 -3
- package/dist/cvt-gl.min.js.map +1 -1
- package/eslint.config.mjs +58 -0
- package/index.js +9 -6
- package/mlt.html +26 -25
- package/package.json +64 -41
- package/prettier.config.mjs +30 -0
- package/vite.config.mjs +43 -0
- package/vite.worker.config.mjs +31 -0
- package/worker.html +26 -0
package/Source/VectorTileLOD.js
CHANGED
|
@@ -1,532 +1,720 @@
|
|
|
1
|
-
import { VectorTileset } from
|
|
2
|
-
import * as MVT from '@mapbox/vector-tile'
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
1
|
+
import { VectorTileset } from './VectorTileset'
|
|
2
|
+
import * as MVT from '@mapbox/vector-tile'
|
|
3
|
+
import {
|
|
4
|
+
IRenderLayer,
|
|
5
|
+
ILayerVisualizer,
|
|
6
|
+
RenderLayers,
|
|
7
|
+
LayerVisualizers
|
|
8
|
+
} from './layers'
|
|
9
|
+
import { VectorTileRenderList } from './VectorTileRenderList'
|
|
10
|
+
import { ISource } from './sources/ISource'
|
|
11
|
+
import { EXTENT } from 'maplibre-gl/src/data/extent'
|
|
12
|
+
import Point from '@mapbox/point-geometry'
|
|
13
|
+
import { subdivideVertexLine } from 'maplibre-gl/src/render/subdivision'
|
|
14
|
+
import { granularitySettings } from './sources/granularitySettings'
|
|
15
|
+
import { warnOnce } from 'maplibre-gl/src/util/util'
|
|
16
|
+
|
|
17
|
+
let tileDepthRenderSate = null
|
|
18
|
+
let nextTileKey = 0
|
|
19
|
+
let levelZeroMaximumGeometricError = null
|
|
20
|
+
/**
|
|
21
|
+
* 计算指定LOD层级的最大几何误差,相当于动态计算3DTiles中geometricError,只是形瓦片的几何误差是一个层级的所有瓦片都相同(rectangle大小都一样)
|
|
22
|
+
* @param {number} z 瓦片层级(整数,不是地图的缩放级别)
|
|
23
|
+
* @param {Cesium.TilingScheme} tilingScheme
|
|
24
|
+
* @returns
|
|
25
|
+
*/
|
|
26
|
+
function getLevelMaximumGeometricError(z, tilingScheme) {
|
|
27
|
+
if (levelZeroMaximumGeometricError === null) {
|
|
28
|
+
levelZeroMaximumGeometricError =
|
|
29
|
+
Cesium.TerrainProvider.getEstimatedLevelZeroGeometricErrorForAHeightmap(
|
|
30
|
+
tilingScheme.ellipsoid,
|
|
31
|
+
128,
|
|
32
|
+
tilingScheme.getNumberOfXTilesAtLevel(0)
|
|
33
|
+
)
|
|
34
|
+
}
|
|
35
|
+
return levelZeroMaximumGeometricError / (1 << z)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* LOD调度重要参数SSE的计算函数,从Cesium地形调度模块中提取出来的代码,调度逻辑和地形瓦片的一致
|
|
40
|
+
* @param {Cesium.FrameState} frameState
|
|
41
|
+
* @param {VectorTileLOD} tile
|
|
42
|
+
* @returns
|
|
43
|
+
*/
|
|
44
|
+
function screenSpaceError(frameState, tile) {
|
|
45
|
+
const maxGeometricError = getLevelMaximumGeometricError(
|
|
46
|
+
tile.z,
|
|
47
|
+
tile.tilingScheme
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
const distance2 = tile.distanceToCamera
|
|
51
|
+
const height = frameState.context.drawingBufferHeight
|
|
52
|
+
const sseDenominator = frameState.camera.frustum.sseDenominator
|
|
53
|
+
let error = (maxGeometricError * height) / (distance2 * sseDenominator)
|
|
54
|
+
if (frameState.fog.enabled) {
|
|
55
|
+
error -=
|
|
56
|
+
Cesium.Math.fog(distance2, frameState.fog.density) * frameState.fog.sse
|
|
57
|
+
}
|
|
58
|
+
error /= frameState.pixelRatio
|
|
59
|
+
return error
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function initConstants() {
|
|
63
|
+
if (tileDepthRenderSate !== null) return
|
|
64
|
+
|
|
65
|
+
tileDepthRenderSate = Cesium.RenderState.fromCache({
|
|
66
|
+
id: 'vt_tile-depth',
|
|
67
|
+
blending: Cesium.BlendingState.DISABLED,
|
|
68
|
+
depthTest: {
|
|
69
|
+
enabled: true
|
|
70
|
+
},
|
|
71
|
+
depthMask: true,
|
|
72
|
+
cull: {
|
|
73
|
+
enabled: true
|
|
74
|
+
},
|
|
75
|
+
stencilMask: Cesium.StencilConstants.CESIUM_3D_TILE_MASK,
|
|
76
|
+
stencilTest: {
|
|
77
|
+
backFunction: 519,
|
|
78
|
+
backOperation: { fail: 7680, zFail: 7680, zPass: 7681 },
|
|
79
|
+
enabled: true,
|
|
80
|
+
frontFunction: 519,
|
|
81
|
+
frontOperation: { fail: 7680, zFail: 7680, zPass: 7681 },
|
|
82
|
+
mask: 128,
|
|
83
|
+
reference: 128
|
|
84
|
+
},
|
|
85
|
+
colorMask: {
|
|
86
|
+
red: false,
|
|
87
|
+
green: false,
|
|
88
|
+
blue: false,
|
|
89
|
+
alpha: false
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export class VectorTileLOD {
|
|
95
|
+
constructor(options) {
|
|
96
|
+
initConstants()
|
|
97
|
+
|
|
98
|
+
this.x = options.x
|
|
99
|
+
this.y = options.y
|
|
100
|
+
this.z = options.z
|
|
101
|
+
/**暂时用不到,但是还是记录父级瓦片 */
|
|
102
|
+
this.parent = options.parent
|
|
103
|
+
this.children = []
|
|
104
|
+
|
|
105
|
+
/**@type {Cesium.TilingScheme} */
|
|
106
|
+
this.tilingScheme = options.tilingScheme
|
|
107
|
+
this.rectangle = this.tilingScheme.tileXYToRectangle(this.x, this.y, this.z)
|
|
108
|
+
/**
|
|
109
|
+
* Cesium.TileBoundingRegion 不是公开的API,但是可以从Cesium地形调度相关模块源码学习,
|
|
110
|
+
*/
|
|
111
|
+
this.tileBoundingRegion = new Cesium.TileBoundingRegion({
|
|
112
|
+
rectangle: this.rectangle,
|
|
113
|
+
minimumHeight: 0,
|
|
114
|
+
maximumHeight: 0,
|
|
115
|
+
ellipsoid: this.tilingScheme.ellipsoid,
|
|
116
|
+
computeBoundingVolumes: true
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
/**@type {IRenderLayer[]} */
|
|
120
|
+
this.layers = []
|
|
121
|
+
/**@type {ILayerVisualizer[]} */
|
|
122
|
+
this.visualizers = []
|
|
123
|
+
/**
|
|
124
|
+
* 保存pbf/mvt文件解析结果,准备创建图层(要素过滤)时候进一步读取要素,创建图层渲染对象时读取要素几何数据
|
|
125
|
+
* @type {Record<string,MVT.VectorTile>}
|
|
126
|
+
*/
|
|
127
|
+
this.sources = {}
|
|
128
|
+
|
|
129
|
+
this.tileId = null
|
|
130
|
+
/**
|
|
131
|
+
* 记录最近一次访问时间(用渲染帧数表示),用于筛选过期瓦片
|
|
132
|
+
*/
|
|
133
|
+
this.lastVisitTime = 0
|
|
134
|
+
/**
|
|
135
|
+
* 瓦片调度状态
|
|
136
|
+
* @type {'none'|'loading'|'loaded'|'ready'|'error'}
|
|
137
|
+
*/
|
|
138
|
+
this.state = 'none'
|
|
139
|
+
this.renderable = false
|
|
140
|
+
|
|
141
|
+
this.tileId = {
|
|
142
|
+
x: this.x,
|
|
143
|
+
y: this.y,
|
|
144
|
+
z: this.z,
|
|
145
|
+
key: nextTileKey++,
|
|
146
|
+
color: Cesium.Color.fromRgba(nextTileKey - 1),
|
|
147
|
+
tileColor: Cesium.Color.fromRandom({
|
|
148
|
+
alpha: 1
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
const size = EXTENT * Math.pow(2, this.z),
|
|
153
|
+
x0 = EXTENT * this.x,
|
|
154
|
+
y0 = EXTENT * this.y
|
|
155
|
+
this.transformPoint = function (x, y, lonlat) {
|
|
156
|
+
lonlat[0] = ((x + x0) * 360) / size - 180
|
|
157
|
+
lonlat[1] =
|
|
158
|
+
(360 / Math.PI) *
|
|
159
|
+
Math.atan(Math.exp((1 - ((y + y0) * 2) / size) * Math.PI)) -
|
|
160
|
+
90
|
|
161
|
+
return lonlat //[x, y]
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
createChildren() {
|
|
166
|
+
var tiles = [
|
|
167
|
+
{
|
|
168
|
+
x: this.x * 2,
|
|
169
|
+
y: this.y * 2 + 1,
|
|
170
|
+
z: this.z + 1
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
x: this.x * 2 + 1,
|
|
174
|
+
y: this.y * 2 + 1,
|
|
175
|
+
z: this.z + 1
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
x: this.x * 2,
|
|
179
|
+
y: this.y * 2,
|
|
180
|
+
z: this.z + 1
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
x: this.x * 2 + 1,
|
|
184
|
+
y: this.y * 2,
|
|
185
|
+
z: this.z + 1
|
|
186
|
+
}
|
|
187
|
+
]
|
|
188
|
+
|
|
189
|
+
for (const { x, y, z } of tiles) {
|
|
190
|
+
var child = new VectorTileLOD({
|
|
191
|
+
x,
|
|
192
|
+
y,
|
|
193
|
+
z,
|
|
194
|
+
tilingScheme: this.tilingScheme,
|
|
195
|
+
parent: this
|
|
196
|
+
})
|
|
197
|
+
this.children.push(child)
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* @param {Cesium.FrameState} frameState
|
|
203
|
+
* @param {{visitChildren(child:VectorTileLOD):void;accept(tile:VectorTileLOD):void}} visitor
|
|
204
|
+
* @returns
|
|
205
|
+
*/
|
|
206
|
+
visit(frameState, visitor) {
|
|
207
|
+
const tileBoundingRegion = this.tileBoundingRegion
|
|
208
|
+
|
|
209
|
+
//相机视锥剔除
|
|
210
|
+
this.distanceToCamera = tileBoundingRegion.distanceToCamera(frameState)
|
|
211
|
+
this.visibility =
|
|
212
|
+
frameState.cullingVolume.computeVisibility(tileBoundingRegion)
|
|
213
|
+
if (this.visibility == Cesium.Intersect.OUTSIDE) {
|
|
214
|
+
return
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
//性能优化:还可以进行地平线剔除更多被地球完全遮挡的瓦片
|
|
218
|
+
|
|
219
|
+
const maxSSE = frameState.maximumScreenSpaceError
|
|
220
|
+
const sse = screenSpaceError(frameState, this)
|
|
221
|
+
if (sse >= maxSSE) {
|
|
222
|
+
//继续遍历子级瓦片
|
|
223
|
+
visitor.visitChildren(this)
|
|
224
|
+
} else {
|
|
225
|
+
//使用当前瓦片渲染
|
|
226
|
+
visitor.accept(this)
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @param {VectorTileset} tileset
|
|
232
|
+
*/
|
|
233
|
+
async getSources(tileset) {
|
|
234
|
+
/**@type {Record<string,ISource>} */
|
|
235
|
+
const sourcesToLoad = {}
|
|
236
|
+
const style = tileset._styleJson
|
|
237
|
+
|
|
238
|
+
for (const styleLayer of style.layers) {
|
|
239
|
+
const sourceId = styleLayer.source
|
|
240
|
+
const source = tileset.sources[sourceId]
|
|
241
|
+
if (source && !sourcesToLoad[sourceId]) {
|
|
242
|
+
sourcesToLoad[sourceId] = source
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const useWorker =
|
|
247
|
+
tileset._taskProcessor &&
|
|
248
|
+
Object.values(sourcesToLoad).every(s => s.type === 'vector')
|
|
249
|
+
|
|
250
|
+
if (useWorker) {
|
|
251
|
+
for (const sourceId in sourcesToLoad) {
|
|
252
|
+
const source = sourcesToLoad[sourceId]
|
|
253
|
+
try {
|
|
254
|
+
const data = await source.requestTileBuffer(
|
|
255
|
+
this.x,
|
|
256
|
+
this.y,
|
|
257
|
+
this.z,
|
|
258
|
+
tileset
|
|
259
|
+
)
|
|
260
|
+
if (data && data.buffer) {
|
|
261
|
+
this.sources[sourceId] = data
|
|
262
|
+
}
|
|
263
|
+
} catch (err) {}
|
|
264
|
+
}
|
|
265
|
+
this._workerBuffers = true
|
|
266
|
+
} else {
|
|
267
|
+
for (const sourceId in sourcesToLoad) {
|
|
268
|
+
const source = sourcesToLoad[sourceId]
|
|
269
|
+
try {
|
|
270
|
+
const tileData = await source.requestTile(
|
|
271
|
+
this.x,
|
|
272
|
+
this.y,
|
|
273
|
+
this.z,
|
|
274
|
+
tileset
|
|
275
|
+
)
|
|
276
|
+
if (tileData) {
|
|
277
|
+
this.sources[sourceId] = tileData
|
|
278
|
+
}
|
|
279
|
+
} catch (err) {}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
tileset.numLoading--
|
|
284
|
+
this.state = 'loaded'
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/**
|
|
288
|
+
* @param {Cesium.FrameRateMonitor} frameState
|
|
289
|
+
* @param {VectorTileset} tileset
|
|
290
|
+
*/
|
|
291
|
+
async createRenderLayers(frameState, tileset) {
|
|
292
|
+
const sources = this.sources
|
|
293
|
+
const styleLayers = tileset._styleLayers
|
|
294
|
+
const renderLayers = this.layers
|
|
295
|
+
const visualizers = this.visualizers
|
|
296
|
+
/**@type {Record<string,ILayerVisualizer>} */
|
|
297
|
+
const visualizerMap = {}
|
|
298
|
+
|
|
299
|
+
for (const styleLayer of styleLayers) {
|
|
300
|
+
const sourceVectorTile = sources[styleLayer.source]
|
|
301
|
+
/**
|
|
302
|
+
* 按图层类型获取对应的渲染图层类
|
|
303
|
+
* @type {typeof IRenderLayer}
|
|
304
|
+
*/
|
|
305
|
+
const RenderLayer = RenderLayers[styleLayer.type]
|
|
306
|
+
const LayerVisualizer = LayerVisualizers[styleLayer.type]
|
|
307
|
+
const isBackgroundLayer = styleLayer.type === 'background'
|
|
308
|
+
if (!RenderLayer) {
|
|
309
|
+
warnOnce('不支持图层类型' + styleLayer.type)
|
|
310
|
+
}
|
|
311
|
+
if ((!isBackgroundLayer && !sourceVectorTile) || !RenderLayer) continue
|
|
312
|
+
|
|
313
|
+
const features = []
|
|
314
|
+
if (!isBackgroundLayer) {
|
|
315
|
+
const sourceType =
|
|
316
|
+
styleLayer.source && tileset.sources[styleLayer.source].type
|
|
317
|
+
const sourceLayer =
|
|
318
|
+
sourceType == 'geojson' ? '_geojsonTileLayer' : styleLayer.sourceLayer
|
|
319
|
+
const vectorTileLayer = sourceVectorTile.layers[sourceLayer]
|
|
320
|
+
if (!vectorTileLayer) continue
|
|
321
|
+
|
|
322
|
+
//读取要素,并根据图层样式filter表达式进行过滤
|
|
323
|
+
//性能优化:同一帧读取和过滤大量要素,耗时较长,应该将其移到Web Worker
|
|
324
|
+
const featureCount = vectorTileLayer.length
|
|
325
|
+
for (let i = 0; i < featureCount; i++) {
|
|
326
|
+
//读取要素
|
|
327
|
+
const feature = vectorTileLayer.feature(i)
|
|
328
|
+
//过滤要素
|
|
329
|
+
if (
|
|
330
|
+
styleLayer.filter &&
|
|
331
|
+
!styleLayer.filter.filter({ zoom: this.z }, feature)
|
|
332
|
+
) {
|
|
333
|
+
continue
|
|
334
|
+
}
|
|
335
|
+
//MLT的Feature类没有实现toGeoJSON方法,直接使用MVT的方法
|
|
336
|
+
if (!feature.toGeoJSON) {
|
|
337
|
+
feature.toGeoJSON = MVT.VectorTileFeature.prototype.toGeoJSON
|
|
338
|
+
}
|
|
339
|
+
features.push(feature)
|
|
340
|
+
}
|
|
341
|
+
if (!features.length) continue
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
//创建渲染图层
|
|
345
|
+
const renderLayer = new RenderLayer(features, styleLayer, this)
|
|
346
|
+
renderLayers.push(renderLayer)
|
|
347
|
+
|
|
348
|
+
//将渲染图层分配到对应类型的图层渲染器,图层渲染器应实现如下功能,以提升渲染性能:
|
|
349
|
+
//1、合批创建几何体、批次表和 DrawCommand;
|
|
350
|
+
//2、克隆合批DrwaCommand,创建副本,通过offset和count指定图层的绘制范围。
|
|
351
|
+
if (LayerVisualizer) {
|
|
352
|
+
let visualizer = visualizerMap[styleLayer.type]
|
|
353
|
+
if (!visualizer) {
|
|
354
|
+
visualizer = new LayerVisualizer(this)
|
|
355
|
+
visualizerMap[styleLayer.type] = visualizer
|
|
356
|
+
visualizers.push(visualizer)
|
|
357
|
+
}
|
|
358
|
+
visualizer.addLayer(features, renderLayer, frameState, tileset)
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
this.state = 'ready'
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* 从 Web Worker 结果创建渲染图层与 Visualizer(仅几何数据来自 Worker)
|
|
367
|
+
* @param {object} result - Worker 返回的 { fill, line, symbol }
|
|
368
|
+
* @param {Cesium.FrameState} frameState
|
|
369
|
+
* @param {VectorTileset} tileset
|
|
370
|
+
*/
|
|
371
|
+
createRenderLayersFromWorkerResult(result, frameState, tileset) {
|
|
372
|
+
if (result.error) {
|
|
373
|
+
this.state = 'error'
|
|
374
|
+
return
|
|
375
|
+
}
|
|
376
|
+
const styleLayers = tileset._styleLayers
|
|
377
|
+
const renderLayers = this.layers
|
|
378
|
+
const visualizers = this.visualizers
|
|
379
|
+
/**@type {Record<string,ILayerVisualizer>} */
|
|
380
|
+
const visualizerMap = {}
|
|
381
|
+
|
|
382
|
+
for (const item of result.fill || []) {
|
|
383
|
+
const styleLayer = styleLayers.find(l => l.id === item.layerId)
|
|
384
|
+
if (!styleLayer) continue
|
|
385
|
+
const RenderLayer = RenderLayers.fill
|
|
386
|
+
const LayerVisualizer = LayerVisualizers.fill
|
|
387
|
+
const renderLayer = new RenderLayer([], styleLayer, this)
|
|
388
|
+
renderLayers.push(renderLayer)
|
|
389
|
+
let visualizer = visualizerMap.fill
|
|
390
|
+
if (!visualizer) {
|
|
391
|
+
visualizer = new LayerVisualizer(this)
|
|
392
|
+
visualizerMap.fill = visualizer
|
|
393
|
+
visualizers.push(visualizer)
|
|
394
|
+
}
|
|
395
|
+
visualizer.addLayerFromWorkerResult(
|
|
396
|
+
item,
|
|
397
|
+
renderLayer,
|
|
398
|
+
frameState,
|
|
399
|
+
tileset
|
|
400
|
+
)
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
for (const item of result.line || []) {
|
|
404
|
+
const styleLayer = styleLayers.find(l => l.id === item.layerId)
|
|
405
|
+
if (!styleLayer) continue
|
|
406
|
+
const RenderLayer = RenderLayers.line
|
|
407
|
+
const LayerVisualizer = LayerVisualizers.line
|
|
408
|
+
const renderLayer = new RenderLayer([], styleLayer, this)
|
|
409
|
+
renderLayers.push(renderLayer)
|
|
410
|
+
let visualizer = visualizerMap.line
|
|
411
|
+
if (!visualizer) {
|
|
412
|
+
visualizer = new LayerVisualizer(this)
|
|
413
|
+
visualizerMap.line = visualizer
|
|
414
|
+
visualizers.push(visualizer)
|
|
415
|
+
}
|
|
416
|
+
visualizer.addLayerFromWorkerResult(
|
|
417
|
+
item,
|
|
418
|
+
renderLayer,
|
|
419
|
+
frameState,
|
|
420
|
+
tileset
|
|
421
|
+
)
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
for (const item of result.symbol || []) {
|
|
425
|
+
const styleLayer = styleLayers.find(l => l.id === item.layerId)
|
|
426
|
+
if (!styleLayer) continue
|
|
427
|
+
const RenderLayer = RenderLayers.symbol
|
|
428
|
+
const LayerVisualizer = LayerVisualizers.symbol
|
|
429
|
+
const renderLayer = new RenderLayer([], styleLayer, this)
|
|
430
|
+
renderLayers.push(renderLayer)
|
|
431
|
+
let visualizer = visualizerMap.symbol
|
|
432
|
+
if (!visualizer) {
|
|
433
|
+
visualizer = new LayerVisualizer(this)
|
|
434
|
+
visualizerMap.symbol = visualizer
|
|
435
|
+
visualizers.push(visualizer)
|
|
436
|
+
}
|
|
437
|
+
visualizer.addLayerFromWorkerResult(
|
|
438
|
+
item,
|
|
439
|
+
renderLayer,
|
|
440
|
+
frameState,
|
|
441
|
+
tileset
|
|
442
|
+
)
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
this.state = 'ready'
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* @param {Cesium.FrameState} frameState
|
|
450
|
+
* @param {VectorTileRenderList} renderList
|
|
451
|
+
* @param {VectorTileset} tileset
|
|
452
|
+
*/
|
|
453
|
+
update(frameState, renderList, tileset) {
|
|
454
|
+
// 这里构建的 primitive 有如下用途:
|
|
455
|
+
// 1. showTileColor 设置为 true 时,展示瓦片范围,验证LOD调度效果
|
|
456
|
+
// 2. 生成绘制瓦片 id 的 DrawCommand,在 VectorTileset 中实时更新瓦片id纹理,实现瓦片边界精准裁剪
|
|
457
|
+
|
|
458
|
+
if (!this.primitive) {
|
|
459
|
+
this.primitive = new Cesium.Primitive({
|
|
460
|
+
geometryInstances: new Cesium.GeometryInstance({
|
|
461
|
+
geometry: new Cesium.RectangleGeometry({
|
|
462
|
+
rectangle: this.rectangle
|
|
463
|
+
})
|
|
464
|
+
}),
|
|
465
|
+
compressVertices: false,
|
|
466
|
+
asynchronous: false,
|
|
467
|
+
appearance: new Cesium.MaterialAppearance({
|
|
468
|
+
flat: true,
|
|
469
|
+
translucent: false,
|
|
470
|
+
material: Cesium.Material.fromType('Color', {
|
|
471
|
+
color: Cesium.Color.fromAlpha(this.tileId.tileColor, 0.25)
|
|
472
|
+
}),
|
|
473
|
+
renderState: {
|
|
474
|
+
blending: Cesium.BlendingState.ALPHA_BLEND,
|
|
475
|
+
depthMask: false,
|
|
476
|
+
depthTest: {
|
|
477
|
+
enabled: true
|
|
478
|
+
},
|
|
479
|
+
cull: {
|
|
480
|
+
enabled: false
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
})
|
|
484
|
+
})
|
|
485
|
+
this.primitive.name = '_tile-color_'
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
const tileComandList = this.commandList || []
|
|
489
|
+
const tileIdCommands = this.tileIdCommands || []
|
|
490
|
+
const tileDepthCommands = this.tileDepthCommands || []
|
|
491
|
+
|
|
492
|
+
if (!tileComandList.length) {
|
|
493
|
+
const preCommandList = frameState.commandList
|
|
494
|
+
frameState.commandList = tileComandList
|
|
495
|
+
|
|
496
|
+
this.primitive.update(frameState)
|
|
497
|
+
|
|
498
|
+
if (tileComandList.length) {
|
|
499
|
+
const tileIdColor = this.tileId.color
|
|
500
|
+
for (const tileComand of tileComandList) {
|
|
501
|
+
tileComand.pass = Cesium.Pass.CESIUM_3D_TILE
|
|
502
|
+
|
|
503
|
+
const tileIdCommand = Cesium.DrawCommand.shallowClone(tileComand)
|
|
504
|
+
tileIdCommand.renderState = Cesium.RenderState.fromCache({
|
|
505
|
+
id: 'tileId',
|
|
506
|
+
blending: {
|
|
507
|
+
enabled: false
|
|
508
|
+
},
|
|
509
|
+
depthTest: {
|
|
510
|
+
enabled: false
|
|
511
|
+
},
|
|
512
|
+
depthMask: true,
|
|
513
|
+
cull: {
|
|
514
|
+
enabled: true
|
|
515
|
+
}
|
|
516
|
+
})
|
|
517
|
+
tileIdCommand.layerType = 'tile-id'
|
|
518
|
+
tileIdCommand.uniformMap = {
|
|
519
|
+
...tileComand.uniformMap
|
|
520
|
+
}
|
|
521
|
+
tileIdCommand.uniformMap.color_0 = function () {
|
|
522
|
+
return tileIdColor
|
|
523
|
+
}
|
|
524
|
+
tileIdCommands.push(tileIdCommand)
|
|
525
|
+
// 浅克隆一个副本,renderState替换成只写入深度和开启模板测试的版本,以支持Entity和GroundPrimitive等贴地对象
|
|
526
|
+
const tileDepthCommand = Cesium.DrawCommand.shallowClone(tileComand)
|
|
527
|
+
tileDepthCommand.pass = Cesium.Pass.CESIUM_3D_TILE
|
|
528
|
+
tileDepthCommand.renderState = tileDepthRenderSate
|
|
529
|
+
tileDepthCommands.layerType = 'tile-depth'
|
|
530
|
+
tileDepthCommands.push(tileDepthCommand)
|
|
531
|
+
}
|
|
532
|
+
this.tileIdCommands = tileIdCommands
|
|
533
|
+
this.tileDepthCommands = tileDepthCommands
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
this.commandList = tileComandList
|
|
537
|
+
frameState.commandList = preCommandList
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
//瓦片范围
|
|
541
|
+
if (tileset.showTileColor && tileComandList.length) {
|
|
542
|
+
renderList.tileCommands.push(...tileComandList)
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
//更新瓦片状态,根据状态执行不同的处理过程
|
|
546
|
+
|
|
547
|
+
//请求瓦片数据,解析pbf/mvt文件
|
|
548
|
+
if (this.state == 'none' && tileset.numLoading <= tileset.maxLoading) {
|
|
549
|
+
tileset.numLoading++
|
|
550
|
+
this.state = 'loading'
|
|
551
|
+
this.getSources(tileset)
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
//创建渲染图层实例(主线程或 Worker 路径)
|
|
555
|
+
if (
|
|
556
|
+
this.state === 'loaded' &&
|
|
557
|
+
tileset.numInitializing < tileset.maxInitializing
|
|
558
|
+
) {
|
|
559
|
+
if (this._workerBuffers && tileset._taskProcessor) {
|
|
560
|
+
const parameters = {
|
|
561
|
+
sources: {},
|
|
562
|
+
x: this.x,
|
|
563
|
+
y: this.y,
|
|
564
|
+
z: this.z,
|
|
565
|
+
extent: EXTENT,
|
|
566
|
+
styleLayers: tileset._styleLayers.map(sl => ({
|
|
567
|
+
id: sl.id,
|
|
568
|
+
type: sl.type,
|
|
569
|
+
source: sl.source,
|
|
570
|
+
sourceLayer: sl.sourceLayer ?? sl.data['source-layer'],
|
|
571
|
+
filter: sl.data.filter,
|
|
572
|
+
paint: sl.data.paint,
|
|
573
|
+
layout: sl.data.layout
|
|
574
|
+
}))
|
|
575
|
+
}
|
|
576
|
+
const transferableObjects = []
|
|
577
|
+
for (const sourceId in this.sources) {
|
|
578
|
+
const data = this.sources[sourceId]
|
|
579
|
+
if (data && data.buffer) {
|
|
580
|
+
parameters.sources[sourceId] = {
|
|
581
|
+
buffer: data.buffer,
|
|
582
|
+
encoding: data.encoding || 'mvt'
|
|
583
|
+
}
|
|
584
|
+
transferableObjects.push(data.buffer)
|
|
585
|
+
}
|
|
586
|
+
}
|
|
587
|
+
const promise = tileset._taskProcessor.scheduleTask(
|
|
588
|
+
parameters,
|
|
589
|
+
transferableObjects
|
|
590
|
+
)
|
|
591
|
+
if (Cesium.defined(promise)) {
|
|
592
|
+
this.state = 'initializing'
|
|
593
|
+
tileset.numInitializing++
|
|
594
|
+
promise
|
|
595
|
+
.then(result => {
|
|
596
|
+
this.createRenderLayersFromWorkerResult(
|
|
597
|
+
result,
|
|
598
|
+
frameState,
|
|
599
|
+
tileset
|
|
600
|
+
)
|
|
601
|
+
})
|
|
602
|
+
.catch(() => {
|
|
603
|
+
this.state = 'error'
|
|
604
|
+
})
|
|
605
|
+
}
|
|
606
|
+
} else {
|
|
607
|
+
this.state = 'initializing'
|
|
608
|
+
tileset.numInitializing++
|
|
609
|
+
this.createRenderLayers(frameState, tileset)
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
if (this.state === 'ready') {
|
|
614
|
+
let visualizerReady = true,
|
|
615
|
+
layersReady = true
|
|
616
|
+
//更新图层渲染器
|
|
617
|
+
for (const visualizer of this.visualizers) {
|
|
618
|
+
visualizer.update(frameState, tileset)
|
|
619
|
+
if (visualizer.state === 'none') {
|
|
620
|
+
visualizerReady = false
|
|
621
|
+
}
|
|
622
|
+
}
|
|
623
|
+
for (const layer of this.layers) {
|
|
624
|
+
layer.update(frameState, tileset)
|
|
625
|
+
if (layer.visibility != 'none' && layer.state == 'none') {
|
|
626
|
+
layersReady = false
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
//标记瓦片是否可渲染
|
|
630
|
+
this.renderable = visualizerReady && layersReady
|
|
631
|
+
}
|
|
632
|
+
}
|
|
633
|
+
|
|
634
|
+
render(frameState, renderList, tileset) {
|
|
635
|
+
if (!this.renderable) {
|
|
636
|
+
return
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
const tileComandList = this.commandList
|
|
640
|
+
const tileIdCommands = this.tileIdCommands
|
|
641
|
+
const tileDepthCommands = this.tileDepthCommands
|
|
642
|
+
|
|
643
|
+
//将渲染图层追加到相应的渲染队列(渲染队列内部按图层id分组,确保不同瓦片的同一个id图层都在一组内,然后按图层顺序逐组渲染)
|
|
644
|
+
for (const layer of this.layers) {
|
|
645
|
+
renderList.push(layer)
|
|
646
|
+
}
|
|
647
|
+
|
|
648
|
+
for (const visualizer of this.visualizers) {
|
|
649
|
+
renderList.visualizers.push(visualizer)
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
//瓦片id纹理
|
|
653
|
+
for (const tileIdCommand of tileIdCommands) {
|
|
654
|
+
renderList.tileIdCommands.push(tileIdCommand)
|
|
655
|
+
}
|
|
656
|
+
|
|
657
|
+
//最后将瓦片深度写入主深度缓冲区,这样才能使Entity和GroundPrimitive等贴地对象能贴合瓦片内的矢量要素
|
|
658
|
+
if (tileDepthCommands.length) {
|
|
659
|
+
renderList.tileCommands.push(...tileDepthCommands)
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
|
|
663
|
+
/**
|
|
664
|
+
* 卸载瓦片,当瓦片过期(不可见,且符合其他过期规则)时,释放pbf/mvt解析数据、图层渲染对象等资源,重置瓦片状态
|
|
665
|
+
*/
|
|
666
|
+
unload() {
|
|
667
|
+
//释放用于展示瓦片范围的primitive
|
|
668
|
+
if (this.primitive) {
|
|
669
|
+
this.primitive.destroy()
|
|
670
|
+
this.primitive = null
|
|
671
|
+
}
|
|
672
|
+
this.tileGeometry = null
|
|
673
|
+
|
|
674
|
+
//清空瓦片克隆的 DrawCommand,不需要手动释放,相关资源在 primitive.destroy 执行时已经释放
|
|
675
|
+
if (this.commandList) {
|
|
676
|
+
this.commandList.length = 0
|
|
677
|
+
}
|
|
678
|
+
if (this.tileIdCommands) {
|
|
679
|
+
this.tileIdCommands.length = 0
|
|
680
|
+
}
|
|
681
|
+
if (this.tileDepthCommands) {
|
|
682
|
+
this.tileDepthCommands.length = 0
|
|
683
|
+
}
|
|
684
|
+
|
|
685
|
+
//销毁渲染图层,释放图层渲染资源
|
|
686
|
+
for (const visualizer of this.visualizers) {
|
|
687
|
+
visualizer.destroy()
|
|
688
|
+
}
|
|
689
|
+
this.visualizers.length = 0
|
|
690
|
+
|
|
691
|
+
for (const layer of this.layers) {
|
|
692
|
+
layer.destroy()
|
|
693
|
+
}
|
|
694
|
+
this.layers.length = 0
|
|
695
|
+
|
|
696
|
+
//释放pbf/mvt解析数据
|
|
697
|
+
this.sources = {}
|
|
698
|
+
|
|
699
|
+
//重置瓦片状态
|
|
700
|
+
this.state = 'none'
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* 销毁瓦片,释放所有资源
|
|
705
|
+
*/
|
|
706
|
+
destroy() {
|
|
707
|
+
this.unload()
|
|
708
|
+
|
|
709
|
+
this.tileId = null
|
|
710
|
+
this.tilingScheme = null
|
|
711
|
+
this.parent = null
|
|
712
|
+
if (this.children) {
|
|
713
|
+
for (const child of this.children) {
|
|
714
|
+
child.destroy()
|
|
715
|
+
}
|
|
716
|
+
this.children.length = 0
|
|
717
|
+
this.children = null
|
|
718
|
+
}
|
|
719
|
+
}
|
|
720
|
+
}
|