http://cesium.coinidea.com/docs/Cartographic.html?classFilter=Cartographic 这个就是一个对象
new Cesium.Cartographic(longitude, latitude, height)
这样还是有点问题
因为这个对象带height了
而我们要去求
// var viewer = new Cesium.Viewer('cesiumContainer');
var viewer = new Cesium.Viewer('cesiumContainer', {
terrainProvider: Cesium.createWorldTerrain()
});
document.getElementById('btn').onclick = function () {
a();
};
function a() {
var terCartographic = new Cesium.Cartographic(1.98,0.6,0);
console.log(terCartographic);
//根据经纬度计算出地形高度。
var terHigh = viewer.scene.globe.getHeight(terCartographic);
console.log(terHigh);
}
像这样行吗?
var handler = new Cesium.ScreenSpaceEventHandler(viewer.canvas);
handler.setInputAction(function(event) {
var earthPosition = viewer.scene.pickPosition(event.position);
if(Cesium.defined(earthPosition)){
var cartographic = Cesium.Cartographic.fromCartesian(earthPosition);
var lon_f = Cesium.Math.toDegrees(cartographic.longitude); //lon
var lat_f = Cesium.Math.toDegrees(cartographic.latitude); //lat
var po_hig = cartographic.height;//这个就是获取的模型上的高度
}
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
请问一下您是怎么解决的,我通过鼠标事件能获取,但是我只传经纬度进去earthPosition是undefined,经纬度转成了窗口坐标 let canvasPosition=this.viewer.scene.cartesianToCanvasCoordinates(Cesium.Cartesian3.fromDegrees(101.11119, 30.0111111))
var earthPosition = this.viewer.scene.pickPosition(canvasPosition);
console.log(canvasPosition)
console.log(earthPosition)
if(Cesium.defined(earthPosition)){
var cartographic = Cesium.Cartographic.fromCartesian(earthPosition);
var lon_f = Cesium.Math.toDegrees(cartographic.longitude); //lon
var lat_f = Cesium.Math.toDegrees(cartographic.latitude); //lat
var po_hig = cartographic.height;//这个就是获取的模型上的高度
console.log(po_hig)
}
这样写有什么问题吗