@mesh3d/cesium-vectortile-gl 0.4.5 → 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/Source/layers/visualizers/SymbolLayerVisualizer.js +67 -4
- package/dist/cvt-gl.js +798 -770
- 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/package.json +1 -1
|
@@ -17,6 +17,9 @@ let scratchDirectionToEye = null
|
|
|
17
17
|
/**@type {Cesium.Cartesian3} */
|
|
18
18
|
let scratchSurfaceNormal = null
|
|
19
19
|
|
|
20
|
+
/** 淡入淡出每帧向目标透明度的插值系数,约 0.10 时 ~10帧完成过渡,越小越慢 */
|
|
21
|
+
const FADE_SPEED = 0.1
|
|
22
|
+
|
|
20
23
|
export class SymbolLayerVisualizer extends ILayerVisualizer {
|
|
21
24
|
constructor(layers, tile) {
|
|
22
25
|
if (scratchDirectionToEye === null) {
|
|
@@ -85,7 +88,8 @@ export class SymbolLayerVisualizer extends ILayerVisualizer {
|
|
|
85
88
|
!Cesium.Rectangle.contains(
|
|
86
89
|
rectangle,
|
|
87
90
|
Cesium.Cartographic.fromDegrees(coord[0], coord[1])
|
|
88
|
-
)
|
|
91
|
+
) ||
|
|
92
|
+
!text
|
|
89
93
|
) {
|
|
90
94
|
return
|
|
91
95
|
}
|
|
@@ -106,6 +110,9 @@ export class SymbolLayerVisualizer extends ILayerVisualizer {
|
|
|
106
110
|
horizontalOrigin: textOrigin.horizontal,
|
|
107
111
|
verticalOrigin: textOrigin.vertical
|
|
108
112
|
})
|
|
113
|
+
label._baseFillColor = label.fillColor.clone()
|
|
114
|
+
label._baseOutlineColor = label.outlineColor.clone()
|
|
115
|
+
label.vtAlpha = 0
|
|
109
116
|
label.batchId = labels.length
|
|
110
117
|
labels.push(label)
|
|
111
118
|
layer.labels.push(label)
|
|
@@ -299,6 +306,9 @@ export class SymbolLayerVisualizer extends ILayerVisualizer {
|
|
|
299
306
|
horizontalOrigin: textOrigin.horizontal,
|
|
300
307
|
verticalOrigin: textOrigin.vertical
|
|
301
308
|
})
|
|
309
|
+
label._baseFillColor = label.fillColor.clone()
|
|
310
|
+
label._baseOutlineColor = label.outlineColor.clone()
|
|
311
|
+
label.vtAlpha = 0
|
|
302
312
|
label.batchId = labels.length
|
|
303
313
|
labels.push(label)
|
|
304
314
|
layer.labels.push(label)
|
|
@@ -344,6 +354,37 @@ export class SymbolLayerVisualizer extends ILayerVisualizer {
|
|
|
344
354
|
this.primitive.update(frameState)
|
|
345
355
|
frameState.commandList = preCommandList
|
|
346
356
|
|
|
357
|
+
//解决Cesium特殊字符支持问题:生成的字形图纹理宽高为0的情况下,dimensions的height或者width为NaN,
|
|
358
|
+
//导致drawCommand的boundingVolume.radius为NaN,
|
|
359
|
+
//进而引发 View.createPotentiallyVisibleSet drawCommand按视锥分组失败的致命问题
|
|
360
|
+
for (const label of this.labels) {
|
|
361
|
+
const glyphs = label._glyphs
|
|
362
|
+
if (glyphs) {
|
|
363
|
+
let text = label.text,
|
|
364
|
+
newGlyphs = [],
|
|
365
|
+
newText = [],
|
|
366
|
+
glyphsChanged = false
|
|
367
|
+
for (let glyphIndex = 0; glyphIndex < glyphs.length; glyphIndex++) {
|
|
368
|
+
const glyph = glyphs[glyphIndex]
|
|
369
|
+
const dimensions = glyph.dimensions
|
|
370
|
+
if (
|
|
371
|
+
dimensions &&
|
|
372
|
+
isFinite(dimensions.width) &&
|
|
373
|
+
isFinite(dimensions.height)
|
|
374
|
+
) {
|
|
375
|
+
newText.push(text[glyphIndex])
|
|
376
|
+
newGlyphs.push(glyph)
|
|
377
|
+
} else {
|
|
378
|
+
glyphsChanged = true
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
if (glyphsChanged) {
|
|
382
|
+
label._glyphs = newGlyphs
|
|
383
|
+
label.text = newText.join('')
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
|
|
347
388
|
if (this.state === 'none' && preCommandList.length > 0) {
|
|
348
389
|
this.setState('done')
|
|
349
390
|
}
|
|
@@ -373,9 +414,31 @@ export class SymbolLayerVisualizer extends ILayerVisualizer {
|
|
|
373
414
|
) {
|
|
374
415
|
layer.labels[i].show = false
|
|
375
416
|
} else {
|
|
376
|
-
//vtPlaceable
|
|
377
|
-
|
|
378
|
-
|
|
417
|
+
// 淡入淡出:根据 vtPlaceable 插值 vtAlpha,用 style 透明度控制,alpha 为 0 时才彻底隐藏
|
|
418
|
+
const label = layer.labels[i]
|
|
419
|
+
if (!label._baseFillColor) {
|
|
420
|
+
label._baseFillColor = label.fillColor.clone()
|
|
421
|
+
label._baseOutlineColor = label.outlineColor.clone()
|
|
422
|
+
if (label.vtAlpha == null) label.vtAlpha = label.vtPlaceable ? 1 : 0
|
|
423
|
+
}
|
|
424
|
+
const targetAlpha = label.vtPlaceable ? 1 : 0
|
|
425
|
+
label.vtAlpha = Cesium.Math.lerp(
|
|
426
|
+
label.vtAlpha ?? 0,
|
|
427
|
+
targetAlpha,
|
|
428
|
+
FADE_SPEED
|
|
429
|
+
)
|
|
430
|
+
if (label.vtAlpha < 0.001) {
|
|
431
|
+
label.vtAlpha = 0
|
|
432
|
+
label.show = false
|
|
433
|
+
} else {
|
|
434
|
+
label.show = true
|
|
435
|
+
label.fillColor = label._baseFillColor.withAlpha(
|
|
436
|
+
label._baseFillColor.alpha * label.vtAlpha
|
|
437
|
+
)
|
|
438
|
+
label.outlineColor = label._baseOutlineColor.withAlpha(
|
|
439
|
+
label._baseOutlineColor.alpha * label.vtAlpha
|
|
440
|
+
)
|
|
441
|
+
}
|
|
379
442
|
}
|
|
380
443
|
}
|
|
381
444
|
}
|