* 启动链路流动动画循环。 * 通过持续调用 requestRender 驱动 Cesium 在 requestRenderMode 下不断重绘, * 同时利用 PolylineGlowMaterialProperty 的自发光效果模拟数据流动感。 * 每帧递增 _linkAnimOffset 并对有速率信息的链路微调发光强度,产生脉冲效果。
()
| 878 | * 每帧递增 _linkAnimOffset 并对有速率信息的链路微调发光强度,产生脉冲效果。 |
| 879 | */ |
| 880 | _startLinkAnimation() { |
| 881 | if (this._linkAnimFrame !== null) return; // 已在运行 |
| 882 | if (!this.viewer || !this.cesiumReady) return; |
| 883 | |
| 884 | let lastTime = performance.now(); |
| 885 | const tick = (now) => { |
| 886 | const dt = Math.min((now - lastTime) / 1000, 0.1); // 单帧增量(秒),上限 100ms |
| 887 | lastTime = now; |
| 888 | |
| 889 | // 更新全局动画偏移(0–1 循环) |
| 890 | this._linkAnimOffset = (this._linkAnimOffset + dt * 0.5) % 1; |
| 891 | |
| 892 | // 对每条活跃链路:按速率调整发光强度,营造脉冲流动感 |
| 893 | if (window.Cesium) { |
| 894 | const t = this._linkAnimOffset; |
| 895 | for (const [lkey, info] of Object.entries(this._linkAnimRateMap)) { |
| 896 | const entity = this._linkIndex[lkey]; |
| 897 | if (!entity || !entity.polyline) continue; |
| 898 | // 速率越高脉冲越快;基础脉冲频率 1Hz,速率比例最高 3x |
| 899 | const freq = 1 + Math.min(2, (info.rate || 0) / 200); |
| 900 | const phase = (t * freq) % 1; |
| 901 | // 发光强度在 0.15–0.55 间脉冲 |
| 902 | const glow = 0.15 + 0.40 * Math.abs(Math.sin(phase * Math.PI)); |
| 903 | const baseColor = this._methodToLinkColor(info.method); |
| 904 | entity.polyline.material = new Cesium.PolylineGlowMaterialProperty({ |
| 905 | glowPower: glow, |
| 906 | taperPower: 0.9, |
| 907 | color: baseColor.withAlpha(0.85), |
| 908 | }); |
| 909 | } |
| 910 | } |
| 911 | |
| 912 | // 在 requestRenderMode 下触发重绘 |
| 913 | if (this.viewer && !this.viewer.isDestroyed()) { |
| 914 | this.viewer.scene.requestRender(); |
| 915 | } |
| 916 | |
| 917 | // 若仍有活跃链路则继续循环 |
| 918 | if (Object.keys(this._linkAnimRateMap).length > 0) { |
| 919 | this._linkAnimFrame = requestAnimationFrame(tick); |
| 920 | } else { |
| 921 | this._linkAnimFrame = null; |
| 922 | } |
| 923 | }; |
| 924 | |
| 925 | this._linkAnimFrame = requestAnimationFrame(tick); |
| 926 | }, |
| 927 | |
| 928 | /** |
| 929 | * 停止链路流动动画循环(当无活跃传输链路时调用)。 |
nothing calls this directly
no outgoing calls
no test coverage detected