viewer.scene.globe.pick(ray, viewer.scene)
与viewer.scene.pickPosition(movement.position)
的关系如下:
代码如下:
// 添加摄像机拾取位置射线
createPickRay(windowPosition) {
let ray = viewer.camera.getPickRay(windowPosition);
var positionWC = viewer.scene.globe.pick(ray, viewer.scene);
var positionCamera = viewer.camera.positionWC; //摄像机位置
var direction = new Cesium.Cartesian3();
direction = Cesium.Cartesian3.subtract(
positionWC,
positionCamera,
direction
);
this.createPolyLine([positionCamera, positionWC]);
this.createPointLabel(
viewer,
positionCamera,
"刚才摄像机在这里",
Cesium.Color.YELLOW
);
},
// 创建并添加折线到球儿上
createPolyLine(positions) {
viewer.entities.add({
name: "drawpolyline",
polyline: {
positions: positions,
material: Cesium.Color.YELLOW,
arcType: Cesium.ArcType.NONE
}
});
},
// 创建并添加点到球上
createPointLabel(viewer, position, text, color) {
var oLabelEntity = {
name: "drawpolyline",
position: position,
clampToGround: true,
attachPolygon: true,
label: {
text: text,
font: "20px sans-serif",
fillColor: color || Cesium.Color.GOLD,
style: Cesium.LabelStyle.FILL_AND_OUTLINE,
outlineWidth: 2,
verticalOrigin: Cesium.VerticalOrigin.BOTTOM,
pixelOffset: new Cesium.Cartesian2(20, -20)
},
point: {
color: color || new Cesium.Color(1.0, 0.0, 0.0, 0.8),
pixelSize:15,
perPositionHeight: false,
disableDepthTestDistance: 1000000000
}
};
return viewer.entities.add(oLabelEntity);
}