需求如下:
由于id 单体化需要显示楼栋名称,所以采用在楼栋上方加label.发现label 会被建筑遮挡,如下
解决方法
在label 中加入 disableDepthTestDistance: Number.POSITIVE_INFINITY
完整代码如下:
viewer.entities.add({
position: Cesium.Cartesian3.fromDegrees(lon, lat, height),
name: 'label',
id: String(id),
label: {
id: String(id),
text: text, // 文本,支持换行符\n
verticalOrigin: Cesium.VerticalOrigin.TOP,
heightReference: Cesium.HeightReference.RELATIVE_TO_GROUND,
showBackground: true,
backgroundColor: Cesium.Color.fromCssColorString('rgba(0, 28, 55, 0.75)'), // 背景颜色
backgroundPadding: new Cesium.Cartesian2(30, 10),
fillColor: Cesium.Color.WHITE, // 字体颜色-白色
style: Cesium.LabelStyle.FILL,
font: '1vw sans-serif',
disableDepthTestDistance: Number.POSITIVE_INFINITY,
show: false
}
解决后效果
参考链接: