国家/城市标签开启深度测试,背面不渲染
This commit is contained in:
+15
-11
@@ -414,6 +414,10 @@ export class CesiumGlobe {
|
|||||||
const textGold = Cesium.Color.fromCssColorString('#e0c46a');
|
const textGold = Cesium.Color.fromCssColorString('#e0c46a');
|
||||||
const black = Cesium.Color.fromCssColorString('#14100d');
|
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 = [];
|
const lines = [];
|
||||||
for (const feature of geojson.features || []) {
|
for (const feature of geojson.features || []) {
|
||||||
const props = feature.properties || {};
|
const props = feature.properties || {};
|
||||||
@@ -427,18 +431,17 @@ export class CesiumGlobe {
|
|||||||
if (cname === '中华民国') cname = '中国台湾';
|
if (cname === '中华民国') cname = '中国台湾';
|
||||||
if (cname && props.LABEL_X != null && props.LABEL_Y != null) {
|
if (cname && props.LABEL_X != null && props.LABEL_Y != null) {
|
||||||
const fontSize = areaKm2 > 5e6 ? 30 : areaKm2 > 1.5e6 ? 19 : areaKm2 > 3e5 ? 15 : 12;
|
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),
|
position: Cesium.Cartesian3.fromDegrees(props.LABEL_X, props.LABEL_Y),
|
||||||
label: {
|
text: cname,
|
||||||
text: cname,
|
font: `bold ${fontSize}px "Noto Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif`,
|
||||||
font: `bold ${fontSize}px "Noto Serif SC", "Songti SC", "STSong", "SimSun", Georgia, serif`,
|
fillColor: black,
|
||||||
fillColor: black,
|
style: Cesium.LabelStyle.FILL,
|
||||||
style: Cesium.LabelStyle.FILL,
|
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
disableDepthTestDistance: 0, // 背面(视野外)不渲染
|
||||||
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1e6, 1e7),
|
distanceDisplayCondition: new Cesium.DistanceDisplayCondition(1e6, 1e7),
|
||||||
scaleByDistance: new Cesium.NearFarScalar(1e4, 20 / 15, 6e6, 1.0),
|
scaleByDistance: new Cesium.NearFarScalar(1e4, 20 / 15, 6e6, 1.0),
|
||||||
translucencyByDistance: new Cesium.NearFarScalar(9e6, 1.0, 1e7, 0.0),
|
translucencyByDistance: new Cesium.NearFarScalar(9e6, 1.0, 1e7, 0.0),
|
||||||
},
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -517,6 +520,7 @@ export class CesiumGlobe {
|
|||||||
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
|
||||||
pixelOffset: new Cesium.Cartesian2(0, -6),
|
pixelOffset: new Cesium.Cartesian2(0, -6),
|
||||||
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND,
|
||||||
|
disableDepthTestDistance: 0, // 背面(视野外)不渲染
|
||||||
distanceDisplayCondition: ddc,
|
distanceDisplayCondition: ddc,
|
||||||
translucencyByDistance: tdc,
|
translucencyByDistance: tdc,
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user