今天在写label的时候,发现高度为0时,label显示不全,影响用户体验,代码如下:
window.labelEntity = viewer.entities.add({label: {show: false,showBackground: true,font: "14px monospace",horizontalOrigin: Cesium.HorizontalOrigin.LEFT,verticalOrigin: Cesium.VerticalOrigin.TOP,pixelOffset: new Cesium.Cartesian2(15, 0),},});
要解决这个问题,需要给label增加一行属性设置代码:
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
全部代码如下:
window.labelEntity = viewer.entities.add({label: {show: false,showBackground: true,font: "14px monospace",horizontalOrigin: Cesium.HorizontalOrigin.LEFT,verticalOrigin: Cesium.VerticalOrigin.TOP,pixelOffset: new Cesium.Cartesian2(15, 0),heightReference: Cesium.HeightReference.CLAMP_TO_GROUND},});
解决问题后,label就能够完整显示了