1、如图所示

2、封装代码
drawPointLine() {
this.isDrawPointLine = !this.isDrawPointLine;
let that = this;
let handler = new Cesium.ScreenSpaceEventHandler(this.viewer.scene.canvas);
handler.setInputAction((e) => {
if(this.isDrawPointLine == false){
handler.removeInputAction(Cesium.ScreenSpaceEventType.LEFT_CLICK);
return;
}
let ray = that.viewer.camera.getPickRay(e.position);
let position = that.viewer.scene.globe.pick(ray, that.viewer.scene);
let cartographic = Cesium.Cartographic.fromCartesian(position);
let lon = Cesium.Math.toDegrees(cartographic.longitude);
let lat = Cesium.Math.toDegrees(cartographic.latitude);
console.log(lon,lat)
let pointPrimitives = null;
pointPrimitives = that.viewer.scene.primitives.add(new Cesium.PointPrimitiveCollection());
pointPrimitives.add({
pixelSize: 10,
color: Cesium.Color['RED'],
position: Cesium.Cartesian3.fromDegrees(lon, lat),
});
that.drawPointLonLats.push(lon);
that.drawPointLonLats.push(lat);
that.viewer.entities.add({
name: 'line',
polyline: {
positions: Cesium.Cartesian3.fromDegreesArray(that.drawPointLonLats),
width: 2,
material: Cesium.Color.YELLOW,
clampToGround: true
}
})
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
},