| | |
| | | * 清除图层实体 |
| | | * @param {String} layerName - 图层名称 |
| | | */ |
| | | function clearLayerEntities(layerName) { |
| | | // 暂且保留 |
| | | // async function clearLayerEntities(layerName) { |
| | | // const list = treeMap.get(layerName); |
| | | // if (list && Array.isArray(list)) { |
| | | // for (const item of list) { |
| | | // const entity = await item; |
| | | // if (layerName == "综合监测设备信息") { |
| | | // removeEntities(entity.deviceId); |
| | | // } else if (layerName == "孙胡沟隐患点") { |
| | | // removeEntities(entity.hdId); |
| | | // } |
| | | // } |
| | | // } |
| | | // treeMap.delete(layerName); |
| | | // } |
| | | |
| | | /** |
| | | * 清除图层实体 |
| | | * @param {String} layerName - 图层名称 |
| | | */ |
| | | // 此函数优化了在模拟仿真页面,如果点击目录树选中取消,泥位计仍显示 |
| | | async function clearLayerEntities(layerName) { |
| | | const isMnfzPage = route.path === "/mnfz"; // 判断是否为 /mnfz 页面 |
| | | |
| | | const list = treeMap.get(layerName); |
| | | if (list && Array.isArray(list)) { |
| | | list.forEach((entity) => { |
| | | clearAllPoints(); |
| | | }); |
| | | for (const item of list) { |
| | | const entity = await item; |
| | | |
| | | let shouldRemove = true; // 默认要删除 |
| | | |
| | | // 如果是 /mnfz 页面,并且是“泥位计”,则不删除 |
| | | if (isMnfzPage && entity.type === "泥位计") { |
| | | shouldRemove = false; |
| | | } |
| | | |
| | | if (shouldRemove) { |
| | | if (layerName === "综合监测设备信息") { |
| | | removeEntities(entity.deviceId); |
| | | } else if (layerName === "孙胡沟隐患点") { |
| | | removeEntities(entity.hdId); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | treeMap.delete(layerName); |
| | | } |
| | | |
| | | // 监控设备开关变化 |
| | | watchEffect(() => { |
| | | watchEffect(async () => { |
| | | clearLayerEntities("综合监测设备信息"); |
| | | |
| | | if (simStore.DeviceShowSwitch) { |
| | | const deviceList = simStore.devices |
| | | // 使用 Promise.all 等待所有异步操作完成 |
| | | const deviceListPromises = simStore.devices |
| | | .filter((item) => item.deviceName?.includes("孙胡沟")) |
| | | .map(async (item) => { |
| | | const entity = viewer.entities.getById(item.deviceId); |
| | |
| | | item.id = item.deviceId; |
| | | item.className = "device"; |
| | | item.showLabel = true; |
| | | await createPoint(item); |
| | | await createPoint(item); // 确保 createPoint 返回一个 Promise 或者本身就是异步函数 |
| | | return item; // 返回处理后的 item |
| | | }); |
| | | |
| | | // 等待所有异步操作完成 |
| | | const deviceList = await Promise.all(deviceListPromises); |
| | | |
| | | if (deviceList.length) { |
| | | treeMap.set("综合监测设备信息", deviceList); |
| | |
| | | }); |
| | | |
| | | // 监控隐患点开关变化 |
| | | watchEffect(() => { |
| | | watchEffect(async () => { |
| | | clearLayerEntities("孙胡沟隐患点"); |
| | | |
| | | if (simStore.DangerShowSwitch) { |
| | | const dangerPoints = simStore.DangerPoint.filter((item) => |
| | | const filteredPoints = simStore.DangerPoint.filter((item) => |
| | | item.position?.includes("孙胡沟") |
| | | ).map(async (item) => { |
| | | ); |
| | | |
| | | const dangerPointPromises = filteredPoints.map(async (item) => { |
| | | const entity = viewer.entities.getById(item.hdId); |
| | | item.id = item.hdId; |
| | | item.name = item.hdName; |
| | |
| | | item.showBillboard = true; |
| | | item.type = item.disasterType; |
| | | item.className = "district"; |
| | | await createPoint(item); |
| | | await createPoint(item); // 确保 createPoint 是异步函数 |
| | | return item; // 返回处理好的 item |
| | | }); |
| | | |
| | | if (dangerPoints.length) { |
| | | treeMap.set("孙胡沟隐患点", dangerPoints); |
| | | try { |
| | | const resolvedPoints = await Promise.all(dangerPointPromises); |
| | | |
| | | if (resolvedPoints.length) { |
| | | treeMap.set("孙胡沟隐患点", resolvedPoints); |
| | | } |
| | | } catch (error) { |
| | | console.error("创建隐患点时发生错误:", error); |
| | | } |
| | | } |
| | | }); |