* 增量更新 Cesium 场景:对新增节点执行 add、对已有节点仅更新 position, * 对消失节点执行 remove,避免每次刷新调用 removeAll 导致的闪烁与卡顿。 * * 索引表: * _entityIndex { id -> Entity } 管理卫星、地面站、GEO 中继节点 * _linkIndex { linkKey -> Entity } 管理链路 polyline,按请求 id + 端点复用
()
| 611 | * _linkIndex { linkKey -> Entity } 管理链路 polyline,按请求 id + 端点复用 |
| 612 | */ |
| 613 | updateScene() { |
| 614 | if (!this.viewer || !this.cesiumReady || !window.Cesium) return; |
| 615 | |
| 616 | const satColor = Cesium.Color.fromCssColorString('#c47b10'); |
| 617 | const gsColor = Cesium.Color.fromCssColorString('#007f78'); |
| 618 | const geoColor = Cesium.Color.fromCssColorString('#2e6fa3'); |
| 619 | const linkColor = Cesium.Color.fromCssColorString('#f0c76b'); |
| 620 | |
| 621 | // 收集本轮所有节点 id,用于事后清理已消失实体 |
| 622 | const liveNodeIds = new Set(); |
| 623 | const satMap = new Map(); |
| 624 | const gsMap = new Map(); |
| 625 | const geoMap = new Map(); |
| 626 | |
| 627 | // ── 地面站 ────────────────────────────────────────────────── |
| 628 | this.groundStations.forEach((station) => { |
| 629 | const eid = `gs-${station.id}`; |
| 630 | liveNodeIds.add(eid); |
| 631 | gsMap.set(station.id, station); |
| 632 | const pos = this.toCartesian(station.lon, station.lat, 0); |
| 633 | |
| 634 | if (this._entityIndex[eid]) { |
| 635 | // 仅更新位置,保留其他属性引用 |
| 636 | this._entityIndex[eid].position = pos; |
| 637 | } else { |
| 638 | const entity = this.viewer.entities.add({ |
| 639 | id: eid, |
| 640 | position: pos, |
| 641 | point: { |
| 642 | pixelSize: 8, |
| 643 | color: gsColor, |
| 644 | outlineColor: Cesium.Color.WHITE, |
| 645 | outlineWidth: 1, |
| 646 | }, |
| 647 | label: this.makeLabel(station.name, '#e7fff7', 16), |
| 648 | }); |
| 649 | this._entityIndex[eid] = entity; |
| 650 | } |
| 651 | }); |
| 652 | |
| 653 | // ── GEO 中继 ──────────────────────────────────────────────── |
| 654 | this.geoRelays.forEach((relay) => { |
| 655 | const eid = `geo-${relay.id}`; |
| 656 | liveNodeIds.add(eid); |
| 657 | geoMap.set(relay.id, relay); |
| 658 | const pos = this.toCartesian(relay.lon, relay.lat, relay.alt); |
| 659 | |
| 660 | if (this._entityIndex[eid]) { |
| 661 | this._entityIndex[eid].position = pos; |
| 662 | } else { |
| 663 | const entity = this.viewer.entities.add({ |
| 664 | id: eid, |
| 665 | position: pos, |
| 666 | point: { |
| 667 | pixelSize: 11, |
| 668 | color: geoColor, |
| 669 | outlineColor: Cesium.Color.WHITE, |
| 670 | outlineWidth: 1, |