// @ts-nocheck import { Enviroment } from "../../Enviroment"; import { PositebleElement } from "../BaseElement"; import { ElementOperator, type PositeInfo } from "../Common"; export type ImageInfo = PositeInfo & { imgUrl?: string; } export type ImageDes = { show: boolean, // 显示图片 size: Cesium.Cartesian2, // 大小 color?: Cesium.Color, // 颜色 offset?: Cesium.Cartesian2, // 偏移 - 右下为正 scaleByDistance?: Cesium.NearFarScalar, // 距离 - 缩放 distanceDisplayCondition?: Cesium.DistanceDisplayCondition,// 距离 - 显隐 } export class ImageEle extends PositebleElement{ static create(id: string, position: Cesium.Cartesian3, imgUrl: string, des?: ImageDes): ImageEle { return new ImageEle(id, { position: position, imgUrl: imgUrl }, des); } protected createDes(): ImageDes { return ImageEle.defaultDes(); } static defaultDes(): ImageDes { return { show: true, size: new Cesium.Cartesian2(16, 16), }; } init(): ImageEle { this.operator = new ImageOperator(this.id, this, this.info, this.des); return this; } /** * 重置图片数据 * @param url 图片路径 * */ resetImg(url: string): ImageEle { this.info.imgUrl = url; return this; } } export class ImageOperator extends ElementOperator { private billboard?: Cesium.Billboard = undefined; inflate(): void { if (this.billboard != undefined) { return; } this.billboard = Enviroment.billboards.add({ id: this.id, position: this.info.position, width: this.des.size?.x, height: this.des.size?.y, image: this.info.imgUrl, pixelOffset: this.getOffset(), disableDepthTestDistance: Number.POSITIVE_INFINITY, // 禁用深度测试 scaleByDistance: this.des.scaleByDistance, distanceDisplayCondition: this.des.distanceDisplayCondition, show: this.isVisible() }); } isVisible(): boolean { return (this.info.imgUrl != undefined && this.info.imgUrl != '' && this.stateble.isVisible() && this.des.show) } remove(): void { if (this.billboard == undefined) { return; } Enviroment.billboards.remove(this.billboard); this.billboard = undefined; } refresh(): void { if (this.billboard == undefined || this.info.imgUrl == undefined) { return; } this.billboard.width = this.des.size.x; this.billboard.height = this.des.size.y; this.billboard.image = this.info.imgUrl; this.billboard.pixelOffset = this.getOffset(); this.billboard.scaleByDistance = this.des.scaleByDistance; this.billboard.distanceDisplayCondition = this.des.distanceDisplayCondition; this.billboard.show = this.isVisible(); } reposite(): void { if (this.billboard == undefined) { return; } this.billboard.position = this.info.position; } protected getOffset(): Cesium.Cartesian2 { return this.des.offset; } }