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, });