其一:求出地形高度
const getTerrain = async position => {
let positionArray = []
position.forEach(item => {
positionArray.push(Cesium.Cartographic.fromDegrees(item[0], item[1]))
})
let updatedPositions = await Cesium.sampleTerrainMostDetailed(
window.cesium?.viewer?.terrainProvider,
positionArray,
)
if (updatedPositions.length == 1) {
return updatedPositions[0]
} else {
return updatedPositions
}
}
其二:创建线
const createLines = (pointData,id)=> {
let positions = []
pointData.forEach(item => {
positions.push([item.longitude, item.latitude])
})
getTerrain(positions).then(res => {
const arrs = []
res.forEach((item, index) => {
arrs.push(
pointData[index].longitude,
pointData[index].latitude,
item.height,
)
})
window.cesium.entity.trends.lines.entities.add({
type: `line`,
id: Id+'_line',
polyline: {
positions: Cesium.Cartesian3.fromDegreesArrayHeights(arrs),
width: 1,
material: Cesium.Color.YELLOW.withAlpha(0.5),
//material: lineBgColor.withAlpha(lineOpacity),//可以自定义颜色和透明度
},
})
})
}