//移动事件,即时画直线
var linePrimitive;
handler.setInputAction(movement=>{
if(isclick==false){
return;
}
var feature = viewer.scene.pick(movement.endPosition);
if (!Cesium.defined(feature)) {
console.log("未选中3dtiles");
return;
}
var cartesian;
var height;
if (scene.pickPositionSupported) {
cartesian = scene.pickPosition(movement.endPosition);
if (Cesium.defined(cartesian)) {
var cartographic = Cesium.Cartographic.fromCartesian(cartesian);
height = cartographic.height;
console.log(height);
}
}
var tempLength=Cesium.Cartesian3.distance(pointArr[pointIndex-1],cartesian);
this.length=tempLength.toFixed(2);
//this.height=cartesian-heightArr[pointIndex-1];
var temp=heightArr[pointIndex-1];
var tempHeight=height.toFixed(2)-temp.toFixed(2);
this.height=Number(tempHeight.toFixed(2));
//var moveCartesian=viewer.scene.globe.pick(viewer.camera.getPickRay(movement.endPosition),viewer.scene);//移动时的坐标转换成世界坐标;
//不能removeAll,方法会删除模型
scene.primitives.remove(linePrimitive);//清除上一次画的图形
linePrimitive = new Cesium.Primitive({
geometryInstances : new Cesium.GeometryInstance({
geometry : new Cesium.PolylineGeometry({
//positions : Cesium.Cartesian3.fromArray(pointArr[0],moveCartesian),
positions : [pointArr[pointIndex-1],cartesian],
width : 5,//线宽
vertexFormat : Cesium.PolylineColorAppearance.VERTEX_FORMAT
}),
attributes : {
color : Cesium.ColorGeometryInstanceAttribute.fromColor(Cesium.Color.CORNFLOWERBLUE),//color 必须设置 不然没有效果
}
}),
appearance : new Cesium.PolylineColorAppearance({
translucent : false
})
});
scene.primitives.add(linePrimitive);
},Cesium.ScreenSpaceEventType.MOUSE_MOVE);