// @ts-nocheck import Utils from '../../Utils' import { Axis } from '../../Common' import { MeasureDrawer, type MeasureHolder } from './MeasureDrawer' import { ModuleCode } from '../../Module'; import { Authorize } from '../../Authorize'; export class AngleHelper extends MeasureDrawer { constructor(id: string) { super(id); Authorize.check(ModuleCode.AngleMeasure); } init(): AngleHelper { if(Authorize.without(ModuleCode.AngleMeasure)){ return this; } return super.init(); } active(): AngleHelper { if(Authorize.without(ModuleCode.AngleMeasure)){ return this; } return super.active(); } protected leftTapCheck(): string | undefined { if (this.holder.markerList.length == 3) { return '角度测量仅可添加三个点'; } } protected rightTapCheck(): string | undefined { if (this.holder.markerList.length != 3) { return '角度测量需要三个点'; } } protected onEditFinish(): void { if (this.holder.markerList.length != 3) { return; } const marker = this.holder.markerList[1]; const cp = marker.info.position; const lp = this.holder.markerList[0].info.position; const np = this.holder.markerList[2].info.position; const v_1 = Utils.Vector.create(cp, lp); const v_2 = Utils.Vector.create(cp, np); const angle = Utils.Vector.angle_3D(v_1, v_2).toFixed(2); marker.resetText(angle + '度').refreshGeo(); } protected refreshLineData(): void { const positionList: Cesium.Cartesian3 = []; this.holder.markerList.forEach(marker => { positionList.push(marker.info.position.clone()); }) this.holder.line.repositeArea(positionList); } } export class MultyHelper extends MeasureDrawer { constructor(id: string) { super(id); Authorize.check(ModuleCode.MultyMeasure); } protected createHolder(): MeasureHolder { this.editorDes.line.close = true; return super.createHolder(); } init(): MultyHelper { if(Authorize.without(ModuleCode.MultyMeasure)){ return this; } return super.init(); } active(): MultyHelper { if(Authorize.without(ModuleCode.MultyMeasure)){ return this; } return super.active(); } protected leftTapCheck(): string | undefined { if (this.holder.markerList.length == 2) { return '综合测量仅可添加两个点'; } } protected rightTapCheck(): string | undefined { if (this.holder.markerList.length != 2) { return '综合测量需要两个点'; } } protected onEditFinish(): void { const positionList = this.holder.line.info.positionList; const p_0 = positionList[0]; const p_1 = positionList[1]; const p_2 = positionList[2]; // 长度 const d_01 = Cesium.Cartesian3.distance(p_0, p_1).toFixed(2) + '米'; const d_12 = Cesium.Cartesian3.distance(p_1, p_2).toFixed(2) + '米'; const d_20 = Cesium.Cartesian3.distance(p_2, p_0).toFixed(2) + '米'; // 中点 const c_01 = Utils.Position.center(p_0, p_1); const c_12 = Utils.Position.center(p_1, p_2); const c_20 = Utils.Position.center(p_2, p_0); // 长度标签 if (this.holder.labelList.length > 0) { this.holder.labelList[0].reposite(c_01).resetText(d_01).refreshGeo(); this.holder.labelList[1].reposite(c_12).resetText(d_12).refreshGeo(); this.holder.labelList[2].reposite(c_20).resetText(d_20).refreshGeo(); } else { this.newLabel(c_01).resetText(d_01).inflate(); this.newLabel(c_12).resetText(d_12).inflate(); this.newLabel(c_20).resetText(d_20).inflate(); } // 夹角向量 const v_01 = Utils.Vector.create(p_0, p_1); const v_02 = Utils.Vector.create(p_0, p_2); // 夹角 const a_0 = Utils.Vector.angle_3D(v_01, v_02).toFixed(2); const a_1 = (90 - parseFloat(a_0)).toFixed(2); // 夹角标签 this.holder.markerList[0].resetText(a_0 + '度').refreshGeo(); this.holder.markerList[1].resetText(a_1 + '度').refreshGeo(); } private calculateThirdPosition(): Cesium.Cartesian3 { const axis = Axis.create(this.holder.markerList[0].info.position); const lp = axis.toLocal(this.holder.markerList[1].info.position); const third_lp = new Cesium.Cartesian3(lp.x, lp.y, 0); return axis.toWorld(third_lp); } protected refreshLineData(): void { const positionList: Cesium.Cartesian3 = []; this.holder.markerList.forEach(marker => { positionList.push(marker.info.position.clone()); }) if (this.holder.markerList.length == 2) { positionList.push(this.calculateThirdPosition()); } this.holder.line.repositeArea(positionList); } }