cesium中绘制带边框的多边形并设置与模型贴地后,边框不展示
按照文档说,需要设置高度,但是设置了高度后heightReference:只能设置为Cesium.HeightReference.NONE 或 0,贴地效果没了,绘制的图像会因为高度的原因,出现被遮挡的情况,
const entity = new Cesium.Entity({
id: id,
polygon: {
hierarchy: new Cesium.CallbackProperty(() => {
return new Cesium.PolygonHierarchy(positions);
}, false),
outline: true,
outlineColor: Cesium.Color.YELLOW,
material: Cesium.Color.YELLOW.withAlpha(0.5),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
}
});
viewer.value.entities.add(entity)
解决方案:在绘制不规则面时,也绘制一个相同坐标的不规则线条,在线条的末尾动态插入起始的坐标,以展示为闭合的效果。如下:
const entity = new Cesium.Entity({
id: id,
polygon: {
hierarchy: new Cesium.CallbackProperty(() => {
return new Cesium.PolygonHierarchy(positions);
}, false),
outline: true,
outlineColor: Cesium.Color.YELLOW,
material: Cesium.Color.YELLOW.withAlpha(0.5),
heightReference: Cesium.HeightReference.CLAMP_TO_GROUND
},
polyline: {
positions: new Cesium.CallbackProperty(() => {
const pos = [...positions, positions[0]]
return pos;
}, false),
width: 3,
clampToGround: true, // 确保边框也贴地
material: Cesium.Color.RED
}
});
viewer.value.entities.add(entity)