From 2fe14ae09f42c0824ea684bab0c7df7819dc21d6 Mon Sep 17 00:00:00 2001 From: fukunee Date: Sat, 19 Sep 2026 16:13:59 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9B=BD=E5=AE=B6/=E5=9F=8E=E5=B8=82=E6=A0=87?= =?UTF-8?q?=E7=AD=BE=E5=BC=80=E5=90=AF=E6=B7=B1=E5=BA=A6=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=EF=BC=8C=E8=83=8C=E9=9D=A2=E4=B8=8D=E6=B8=B2=E6=9F=93?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/scene/CesiumGlobe.js | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/src/scene/CesiumGlobe.js b/src/scene/CesiumGlobe.js index f8955a4..e723c26 100644 --- a/src/scene/CesiumGlobe.js +++ b/src/scene/CesiumGlobe.js @@ -414,6 +414,10 @@ export class CesiumGlobe { const textGold = Cesium.Color.fromCssColorString('#e0c46a'); const black = Cesium.Color.fromCssColorString('#14100d'); + // 国家名用 LabelCollection(避免大量 entity 开销) + const countryLabels = new Cesium.LabelCollection({ scene: this.viewer.scene }); + this.viewer.scene.primitives.add(countryLabels); + const lines = []; for (const feature of geojson.features || []) { const props = feature.properties || {}; @@ -427,18 +431,17 @@ export class CesiumGlobe { if (cname === '中华民国') cname = '中国台湾'; if (cname && props.LABEL_X != null && props.LABEL_Y != null) { const fontSize = areaKm2 > 5e6 ? 30 : areaKm2 > 1.5e6 ? 19 : areaKm2 > 3e5 ? 15 : 12; - this.viewer.entities.add({ + countryLabels.add({ position: Cesium.Cartesian3.fromDegrees(props.LABEL_X, props.LABEL_Y), - label: { - text: cname, - font: `bold ${fontSize}px "Noto Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif`, - fillColor: black, - style: Cesium.LabelStyle.FILL, - heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, - distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1e6, 1e7), - scaleByDistance: new Cesium.NearFarScalar(1e4, 20 / 15, 6e6, 1.0), - translucencyByDistance: new Cesium.NearFarScalar(9e6, 1.0, 1e7, 0.0), - }, + text: cname, + font: `bold ${fontSize}px "Noto Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif`, + fillColor: black, + style: Cesium.LabelStyle.FILL, + heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, + disableDepthTestDistance: 0, // 背面(视野外)不渲染 + distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1e6, 1e7), + scaleByDistance: new Cesium.NearFarScalar(1e4, 20 / 15, 6e6, 1.0), + translucencyByDistance: new Cesium.NearFarScalar(9e6, 1.0, 1e7, 0.0), }); } @@ -517,6 +520,7 @@ export class CesiumGlobe { verticalOrigin: Cesium.VerticalOrigin.BOTTOM, pixelOffset: new Cesium.Cartesian2(0, -6), heightReference: Cesium.HeightReference.CLAMP_TO_GROUND, + disableDepthTestDistance: 0, // 背面(视野外)不渲染 distanceDisplayCondition: ddc, translucencyByDistance: tdc, });