// @ts-nocheck export class CollisionChecks { private treeData: any[]; private ISERVER_HOST: string; private viewer: any; private message: { warning: (msg: string) => void }; private intersectList: any[]; constructor( treeData: any[], ISERVER_HOST: string, viewer: any, message: { warning: (msg: string) => void } ) { this.treeData = treeData; this.ISERVER_HOST = ISERVER_HOST; this.viewer = viewer; this.message = message; this.intersectList = []; } // 循环选中数据并执行碰撞检查 async handleCollisionChecks( checkedOptions: any[], checkedOptionsSuffer: any[], programmeId: string ): Promise { for (const option of checkedOptions) { for (const suffer of checkedOptionsSuffer) { await this.processCollision(option, suffer, programmeId); } } } // 处理碰撞检查 private async processCollision( option: string, suffer: string, programmeId: string ): Promise { const optionNode = this.findNodeInTree(this.treeData, option); const sufferNode = this.findNodeInTree(this.treeData, suffer); if (!optionNode || !sufferNode) { console.error('未找到节点'); return; } const sqlParameter = { operateDataset: optionNode.title, operateDatasetFilter: { attributeFilter: '', ids: [] }, sourceDatasetFilter: { attributeFilter: '', ids: [] }, positionMode: 'INTERSECTS', }; const postUrl = `${this.ISERVER_HOST}iserver/services/spatialAnalysis-pengzhuangceshixiangmu/restjsr/spatialanalyst/datasets/${sufferNode.title}/spatialquery3d.rjson`; try { const response = await this.postRequest(postUrl, sqlParameter); this.handleCollisionSave(response, optionNode, sufferNode, programmeId); } catch (error) { console.error('碰撞检查请求出错:', error); } } // 处理完成后对模型染色并保存 private async handleCollisionSave( response: any, optionNode: any, sufferNode: any, programmeId: string ): Promise { if (!response.newResourceLocation) { console.error('响应中缺少 newResourceLocation'); return; } try { const res = await this.getRequest( `${response.newResourceLocation}.rjson` ); if (res.ids.length === 0) { this.message.warning('无碰撞关系'); return; } else { this.message.warning('有碰撞关系'); } this.intersectList = res.ids; const layerVariable = sufferNode.title; const layersHash = this.viewer.scene.layers._layers._hash; let targetLayerKey: string | null = null; for (const key in layersHash) { if (key.includes(layerVariable)) { targetLayerKey = key; break; } } if (targetLayerKey) { layersHash[targetLayerKey].setObjsColor( this.intersectList, Cesium.Color.fromCssColorString('#E74032') ); this.saveCollisionData( this.intersectList, optionNode, sufferNode, programmeId ); } else { console.error('未找到包含变量的图层'); } } catch (error) { console.error('处理碰撞染色时出错:', error); } } // 保存碰撞数据(可定制) private saveCollisionData( intersectList: any[], optionNode: any, sufferNode: any, programmeId: string ): void { console.log('保存碰撞数据:', { intersectList, optionNode, sufferNode, programmeId, }); } // 树结构节点查找 private findNodeInTree(tree: any[], key: string): any | null { for (const node of tree) { if (node.key === key) return node; if (node.children) { const found = this.findNodeInTree(node.children, key); if (found) return found; } } return null; } // 发起 POST 请求 private async postRequest(url: string, data: any): Promise { const response = await fetch(url, { method: 'POST', headers: { 'Content-Type': 'application/json', }, body: JSON.stringify(data), }); if (!response.ok) { throw new Error(`POST 请求失败: ${response.statusText}`); } return response.json(); } // 发起 GET 请求 private async getRequest(url: string): Promise { const response = await fetch(url, { method: 'GET', }); if (!response.ok) { throw new Error(`GET 请求失败: ${response.statusText}`); } return response.json(); } }