let arr: any[] = [];
let new_arr: any[] = [];
this.polygon = null;
handler.setInputAction((movement: Cesium.MoveEvent) =>{
let position = this.viewer.camera.pickEllipsoid(movement.endPosition,this.viewer.scene.globe.ellipsoid)
if(!Cesium.defined(position)){ //跳出地球异常
return;
}
if(arr.length >= 2){
if(!Cesium.defined(this.polygon)){
this.polygon = this.drawPolygon(arr) as IPolygon;
}else{
arr.pop();
arr.push(position);
}
}
}, Cesium.ScreenSpaceEventType.MOUSE_MOVE);
handler.setInputAction((movement: Cesium.PositionedEvent) =>{
let position = this.viewer.camera.pickEllipsoid(movement.position,this.viewer.scene.globe.ellipsoid)
if(!Cesium.defined(position)){ //跳出地球异常
return;
}
if(arr.length == 0){
arr.push(position.clone());
}
arr.push(position)
let ellipsoid=this.viewer.scene.globe.ellipsoid;
let cartographic=ellipsoid.cartesianToCartographic(position);
let lat=Cesium.Math.toDegrees(cartographic.latitude);
let lon=Cesium.Math.toDegrees(cartographic.longitude);
let alt = cartographic.height;
new_arr.push([lon,lat,alt]);
}, Cesium.ScreenSpaceEventType.LEFT_CLICK);
handler.setInputAction(v=> {
arr.pop();
handler.destroy();
arr = [];
this.end = true;
console.log("polygon: ", this.polygon)
this.pointService.savePlot(this.polygon,'polygon',new_arr,this.end);
},Cesium.ScreenSpaceEventType.RIGHT_CLICK)
drawPolygon(positions){
let namecount = this.pointService.test1.points.source.length + 1;
let polygonGeometry = this.viewer.entities.add({
name: `面${namecount}`,
polygon: {
hierarchy: new Cesium.CallbackProperty(() =>{
return {positions}
}, false),
perPositionHeight: true,
material: Cesium.Color.GREENYELLOW.withAlpha(.5)
}
});
return polygonGeometry;
}