const handler = new Cesium.ScreenSpaceEventHandler(viewer.scene.canvas);
添加model
handler.setInputAction((movement) => {//鼠标左键事件,点击地图,在点击位置添加模型
var cartesian = viewer.scene.globe.pick(viewer.camera.getPickRay(movement.position), viewer.scene);//获取地形上的点
const newHeading = Cesium.Math.toRadians(0); //初始heading值赋0
const newPitch = Cesium.Math.toRadians(0);
const newRoll = Cesium.Math.toRadians(0);
const headingPitchRoll = new Cesium.HeadingPitchRoll(newHeading, newPitch, newRoll);
const modelMatrix = Cesium.Transforms.headingPitchRollToFixedFrame(cartesian, headingPitchRoll, Cesium.Ellipsoid.WGS84, Cesium.Transforms.eastNorthUpToFixedFrame, new Cesium.Matrix4());
viewer.scene.primitives.add(Cesium.Model.fromGltf({
url, // 模型地址
modelMatrix,
}));
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);