首先要确定四个点,这四个点分别在两条线上。所以,这四个点可以分别是两条线的首尾端点。
然后使用turf.js来计算交叉点位置。然后使用Cesium的地形高度查询,得到高度。
let line1 = turf.lineString([[p1.lon,p1.lat], [p2.lon, p2.lat]]);
let line2 = turf.lineString([[p3.lon,p3.lat], [p4.lon, p4.lat]]);
let intersects = turf.lineIntersect(line1, line2);
let coords = intersects.features[0].geometry.coordinates
let cpHeightPromise = Cesium.sampleTerrainMostDetailed(this.viewer.terrainProvider, [Cesium.Cartographic.fromDegrees(coords[0],coords[1])]);
cpHeightPromise.then(positions=> {
if (positions.length > 0) {
let coordsHeight = positions[0].height
let cartesian3 = Cesium.Cartesian3.fromDegrees(coords[0],coords[1],coordsHeight)
} else {
console.log('No elevation data available for this location.');
}
})
},