import {CssType, HtmlPanel} from '@deep/engine'; /** * 隧道数据接口 */ export interface ITunnelData { type: string; position: { x: number; y: number; z: number; }; depth: number; radius: number; } /** * 隧道面板类 */ export class TunnelHtmlPanel extends HtmlPanel { private tunnelData: ITunnelData; private onDeleteCallback: (() => void) | null = null; private uuid: string; /** * 构造函数 * @param data 隧道数据 * @param type CSS渲染类型 */ constructor(data: ITunnelData, type: CssType = CssType.CSS3DSprite) { super(type); this.tunnelData = data; this.uuid = this.getUniqueId(); this.initContent(); this.attachDeleteEvent(); } /** * 设置删除回调函数 * @param callback 删除时的回调函数 */ public onDelete(callback: () => void): void { this.onDeleteCallback = callback; } /** * 处理删除按钮点击 */ private handleDelete(): void { this.hide(); if (this.onDeleteCallback) { this.onDeleteCallback(); } } /** * 初始化内容结构 */ private initContent(): void { const content = `
🚇
${this.tunnelData.type}
隧道信息
坐标位置
X
${this.tunnelData.position.x.toFixed(2)}
Y
${this.tunnelData.position.y.toFixed(2)}
Z
${this.tunnelData.position.z.toFixed(2)}
隧道参数
深度 ${this.tunnelData.depth} m
半径 ${this.tunnelData.radius} m
`; this.updateContent(content); } /** * 附加删除按钮事件 */ private attachDeleteEvent(): void { setTimeout(() => { const deleteBtn = document.getElementById(`delete-btn-${this.uuid}`); if (deleteBtn) { deleteBtn.addEventListener('click', () => this.handleDelete()); } }, 0); } }