Cesium最新基础教程系列5—鼠标事件获取当前坐标点(经度、维度、地形高度)

话不多说,直接上核心代码:

var terrain = new Cesium.CesiumTerrainProvider({
    url:"http://192.168.0.1:9000/MapData/Terrain/aa/"
});

var handler = new Cesium.ScreenSpaceEventHandler(scene.canvas);
handler.setInputAction(function (click) {
    var ray = viewer.scene.camera.getPickRay(click.position);
    var cartesian = viewer.scene.globe.pick(ray,viewer.scene);
    if (cartesian) {
        var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
        var lon = Cesium.Math.toDegrees(cartographic.longitude);
        var lat = Cesium.Math.toDegrees(cartographic.latitude);
        var positions = [Cesium.Cartographic.fromDegrees(lon,lat)]
        Cesium.when(new Cesium.sampleTerrain(terrain,7,positions),function (updatedPositions) { 

                 var dxgd = updatedPositions[0].height;
                 var pp1 = new Cesium.Cartographic(lon,lat, dxgd);
                 console.log(pp1);


        });
    }

}, Cesium.ScreenSpaceEventType.LEFT_CLICK);

你可能感兴趣的:(Cesium系列)