Cesium 获取鼠标当前位置的模型高度,地形高度,OSGB高度,及其经纬度。

let handlers = new Cesium.ScreenSpaceEventHandler(viewer.scene._imageryLayerCollection);
handlers.setInputAction(function (event) {
    //获取相机射线
    ray = viewer.scene.camera.getPickRay(event.endPosition);
    //根据射线和场景求出在球面中的笛卡尔坐标
    position1 = viewer.scene.globe.pick(ray,viewer.scene);
    //获取该浏览器坐标的顶部数据
    feature = viewer.scene.pick(event.endPosition);
    // console.log(feature);
    if (feature == undefined && position1) {
        cartographic1 = Cesium.Ellipsoid.WGS84.cartesianToCartographic(position1);
        lon = Cesium.Math.toDegrees(cartographic1.longitude);
        lat = Cesium.Math.toDegrees(cartographic1.latitude);
        MouseHeight = 0;
    }
    else{
        let cartesian = viewer.scene.pickPosition(event.endPosition);
        if (Cesium.defined(cartesian) ){
            //如果对象已定义,将度转为经纬度
            let cartographic = Cesium.Cartographic.fromCartesian(cartesian);
            lon = Cesium.Math.toDegrees(cartographic.longitude);
            lat = Cesium.Math.toDegrees(cartographic.latitude);
            MouseHeight = cartographic.height;//模型高度
        }
    }
    // console.log(A,B,MouseHeight)
} , Cesium.ScreenSpaceEventType.MOUSE_MOVE);

你可能感兴趣的:(javascript,开发语言,ecmascript)