// @ts-nocheck import Utils from '../../Utils' import { PositebleElement } from '../BaseElement' import { ElementOperator, type Stateble } from '../Common' import { PointEle, type PointDes, PointOperator } from './Point'; import { LabelEle, type LabelDes, type LabelInfo, LabelOperator } from './Label'; import { ImageEle, type ImageDes, type ImageInfo, ImageOperator } from './Image'; export type MarkerInfo = LabelInfo & ImageInfo; export type MarkerDes = { point: PointDes, label: LabelDes, image: ImageDes } export class MarkerEle extends PositebleElement{ static create(id: string, position: Cesium.Cartesian3, text?: string, imgUrl?: string, des?: MarkerDes): MarkerEle { return new MarkerEle(id, { position: position, text: text, imgUrl: imgUrl }, des); } protected createDes(): MarkerDes { return MarkerEle.defaultDes(); } static defaultDes(): MarkerDes { return { point: PointEle.defaultDes(), label: LabelEle.defaultDes(), image: ImageEle.defaultDes() }; } init(havePoint: boolean = true, haveLabel: boolean = true, haveImg: boolean = true): MarkerEle { this.operator = new MarkerOperator(this.id, this, havePoint, haveLabel, haveImg); return this; } /** * 重置文本数据 * @param text 标签文本 * */ resetText(text: string): MarkerEle { this.info.text = text; return this; } /** * 重置图片数据 * @param url 图片路径 * */ resetImg(url: string): MarkerEle { this.info.imgUrl = url; return this; } } class MarkerOperator extends ElementOperator { readonly pointOperator: MarkerPointOperator | undefined; readonly labelOperator: MarkerLabelOperator | undefined; readonly imgOperator: MarkerImageOperator | undefined; constructor(id: string, element: MarkerEle, havePoint: boolean, haveLabel: boolean, haveImg: boolean) { super(id, element, element.info, element.des); if (havePoint) { const id = MarkerPointOperator.getId(this.id); this.pointOperator = new MarkerPointOperator(id, this.stateble, this.info, this.des.point); } else { this.pointOperator = undefined; } if (haveLabel) { const id = MarkerLabelOperator.getId(this.id); this.labelOperator = new MarkerLabelOperator(id, this.stateble, this.info, this.des.label, this); } else { this.labelOperator = undefined; } if (haveImg) { const id = MarkerImageOperator.getId(this.id); this.imgOperator = new MarkerImageOperator(id, this.stateble, this.info, this.des.image, this); } else { this.imgOperator = undefined; } } inflate(): void { this.pointOperator?.inflate(); this.labelOperator?.inflate(); this.imgOperator?.inflate(); } remove(): void { this.pointOperator?.remove(); this.labelOperator?.remove(); this.imgOperator?.remove(); } reposite(): void { this.pointOperator?.reposite(); this.labelOperator?.reposite(); this.imgOperator?.reposite(); } refresh(): void { this.pointOperator?.refresh(); this.labelOperator?.refresh(); this.imgOperator?.refresh(); } _showPoint(): boolean { return ( this.pointOperator != undefined && this.pointOperator.isVisible() ); } _showLabel(): boolean { return ( this.labelOperator != undefined && this.labelOperator.isVisible() ); } _showImg(): boolean { return ( this.imgOperator != undefined && this.imgOperator.isVisible() ); } _getLabelOffset(): Cesium.Cartesian2 { if (this.des.label.offset != undefined) { return this.des.label.offset; } if (this._showImg() && this.des.image.offset != undefined) { const length = this.des.image.offset.y; return new Cesium.Cartesian2(0, -length - 2); } const diff_P = this._showPoint() ? this.des.point.pixelSize / 2 : 0; const diff_I = this._showImg() ? this.des.image.size.y + 2 : 0; const diff = -diff_P - diff_I - 6; return new Cesium.Cartesian2(0, diff); } _getImgOffset(): Cesium.Cartesian2 { if (this.des.image.offset != undefined) { return this.des.image.offset; } const diff_P = this._showPoint() ? this.des.point.pixelSize / 2 : 0; const diff_I = this.des.image.size.y / 2; const diff = -diff_P - diff_I - 2; return new Cesium.Cartesian2(0, diff); } } class MarkerPointOperator extends PointOperator { static getId(pid: string) { return Utils.IdGroup.serialize(pid, 'point'); } } class MarkerLabelOperator extends LabelOperator { readonly parentOperator: MarkerOperator; static getId(pid: string) { return Utils.IdGroup.serialize(pid, 'label'); } constructor(id: string, stateble: Stateble, info: MarkerInfo, des: LabelDes, parentOperator: MarkerOperator) { super(id, stateble, info, des); this.parentOperator = parentOperator; } protected getOffset(): Cesium.Cartesian2 { return this.parentOperator._getLabelOffset(); } } class MarkerImageOperator extends ImageOperator { readonly parentOperator: MarkerOperator; static getId(pid: string) { return Utils.IdGroup.serialize(pid, 'img'); } constructor(id: string, stateble: Stateble, info: MarkerInfo, des: ImageDes, parentOperator: MarkerOperator) { super(id, stateble, info, des); this.parentOperator = parentOperator; } protected getOffset(): Cesium.Cartesian2 { return this.parentOperator._getImgOffset(); } }