// @ts-nocheck import Utils from "../../Utils"; import { Enviroment } from "../../Enviroment" import { AreableElement } from "../BaseElement" import { type AreaInfo, ElementOperator, LineType } from '../Common' export type LineDes = { width: number, color: Cesium.Color, editColor: Cesium.Color, // 编辑时颜色 close: boolean, type: LineType, distanceDisplayCondition?: Cesium.DistanceDisplayCondition;// 距离 - 显隐 } export abstract class LineEle> extends AreableElement> { protected createDes(): LineDes { return LineEle.defaultDes(); } static defaultDes(): LineDes { return { width: 2, color: Cesium.Color.RED, editColor: Cesium.Color.YELLOW, close: false, type: LineType.Simple, }; } repositeArea(positionList: Array): LineEle { this.info.positionList = positionList; this.repositeGeo(); return this.asType(); } } export class SimpleLineEle extends LineEle { static create(id: string, positionList: Array, des?: LineDes): SimpleLineEle { return new SimpleLineEle(id, { positionList: positionList }, des); } init(): SimpleLineEle { this.operator = new SimpleLineOperator(this.id, this, this.info, this.des); return this; } } class SimpleLineOperator extends ElementOperator{ private line?: Cesium.Polyline = undefined; inflate(): void { if (this.line != undefined) { return; } this.line = Enviroment.lines.add({ id: this.id, positions: this.info.positionList, width: this.des.width, loop: this.des.close, material: this.getMaterial(), disableDepthTestDistance: Number.POSITIVE_INFINITY, // 禁用深度测试 distanceDisplayCondition: this.des.distanceDisplayCondition, show: this.stateble.isVisible() }); } remove(): void { if (this.line == undefined) { return; } Enviroment.lines.remove(this.line); this.line = undefined; } refresh(): void { if (this.line == undefined) { return; } this.line.width = this.des.width; this.line.material = this.getMaterial(); this.line.distanceDisplayCondition = this.des.distanceDisplayCondition; this.line.show = this.stateble.isVisible(); } reposite(): void { if (this.line == undefined) { return; } this.line.positions = this.info.positionList; } private getMaterial(): Cesium.Material { return new Cesium.Material.fromType( this.des.type, { color: (this.stateble.isEditing() ? this.des.editColor : this.des.color) } ); } } export class GroundLineEle extends LineEle { static create(id: string, positionList: Array, des?: LineDes): GroundLineEle { return new GroundLineEle(id, { positionList: positionList }, des); } init(): GroundLineEle { this.operator = new GroundLineOperator(this.id, this, this.info, this.des); return this; } _answerDrag(): boolean { return false; } } class GroundLineOperator extends ElementOperator{ private line?: Cesium.Primitive = undefined; inflate(): void { if (this.line != undefined) { return; } const num = this.info.positionList.length; if (num < 2) { return; } // 复制数据,避免数据污染 const positionList = Utils.Position.copyList(this.info.positionList); const primitive = new Cesium.GroundPolylinePrimitive({ geometryInstances: new Cesium.GeometryInstance({ id: this.id, geometry: new Cesium.GroundPolylineGeometry({ positions: positionList, width: this.des.width, loop: this.des.close, vertexFormat: Cesium.EllipsoidSurfaceAppearance.VERTEXT_FORMAT, }) }), appearance: new Cesium.EllipsoidSurfaceAppearance({ flat: true, material: this.getMaterial() }), asynchronous: false, show: this.stateble.isVisible() }); this.line = Enviroment.primitives.add(primitive); } remove(): void { if (this.line == undefined) { return; } Enviroment.primitives.remove(this.line); this.line.destroy(); this.line = undefined; } refresh(): void { if (this.line == undefined) { return; } this.line.show = this.stateble.isVisible(); this.line.appearance.material = this.getMaterial(); } reposite(): void { this.remove(); this.inflate(); } private getMaterial(): Cesium.Material { return new Cesium.Material.fromType( this.des.type, { color: (this.stateble.isEditing() ? this.des.editColor : this.des.color) } ); } }