国家/城市标签开启深度测试,背面不渲染

This commit is contained in:
2026-09-19 16:13:59 +08:00
parent 8ca2e9ebe3
commit 2fe14ae09f
+7 -3
View File
@@ -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,
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,
});