| | |
| | | |
| | | <script setup> |
| | | import { ref, onMounted, watch, nextTick, onUnmounted, watchEffect } from "vue"; |
| | | import { createPoint, removeEntities, addTileset } from "@/utils/map"; |
| | | import { |
| | | createPoint, |
| | | removeEntities, |
| | | addTileset, |
| | | clearAllPoints, |
| | | } from "@/utils/map"; |
| | | import { deviceDictList, getDictName } from "@/constant/dict.js"; |
| | | import { useRoute } from "vue-router"; |
| | | import { loadAreaPolygon, clearAreaPolygon } from "@/utils/area"; |
| | | import { |
| | | loadAreaPolygon, |
| | | convertToGeoJson, |
| | | clearAreaPolygon, |
| | | } from "@/utils/area"; |
| | | import { checkedKeys } from "@/store/index"; |
| | | import { getDuanMainData } from "@/api/index.js"; |
| | | import { useSimStore } from "@/store/simulation"; |
| | | import { getSafePoint } from "@/api/hpApi"; |
| | | |
| | | const simStore = useSimStore(); |
| | | const route = useRoute(); |
| | |
| | | function handleModelLayer(checked) { |
| | | if (checked) { |
| | | addTileset( |
| | | "http://106.120.22.26:9103/gisserver/c3dserver/sunhugou3d/tileset.json" |
| | | // "http://106.120.22.26:9103/gisserver/c3dserver/sunhugou3d/tileset.json" |
| | | "http://192.168.37.61:9004/tile/model/service/Iakp0nhx/tileset.json?labtoken=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzdWIiOiItMSxUaHUgQXByIDE4IDE1OjMwOjU3IENTVCAyMDI0In0.j_YKsCRsIQtpgOWfFvMwAP65Rlx9uXyVte_xkE95Vdo" |
| | | ) |
| | | .then((model) => { |
| | | treeMap.set("模型数据", model); |
| | |
| | | * 清除图层实体 |
| | | * @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) => { |
| | | if (viewer.entities.contains(entity)) { |
| | | viewer.entities.remove(entity); |
| | | 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((item) => { |
| | | const entity = createPoint({ |
| | | ...item, |
| | | type: getDictName(deviceDictList, item.dictDeviceType), |
| | | name: item.deviceName.split("孙胡沟")[1], |
| | | id: item.deviceId, |
| | | className: "device", |
| | | showLabel: true, |
| | | }); |
| | | entity.show = true; |
| | | return entity; |
| | | .map(async (item) => { |
| | | const entity = viewer.entities.getById(item.deviceId); |
| | | item.type = getDictName(deviceDictList, item.dictDeviceType); |
| | | item.name = item.deviceName.split("孙胡沟")[1]; |
| | | item.id = item.deviceId; |
| | | item.className = "device"; |
| | | item.showLabel = true; |
| | | 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((item) => { |
| | | const entity = createPoint({ |
| | | id: item.hdId, |
| | | name: item.hdName, |
| | | latitude: item.lat, |
| | | longitude: item.lon, |
| | | showBillboard: true, |
| | | type: item.disasterType, |
| | | className: "district", |
| | | }); |
| | | entity.show = true; |
| | | return entity; |
| | | ); |
| | | |
| | | const dangerPointPromises = filteredPoints.map(async (item) => { |
| | | const entity = viewer.entities.getById(item.hdId); |
| | | item.id = item.hdId; |
| | | item.name = item.hdName; |
| | | item.latitude = item.lat; |
| | | item.longitude = item.lon; |
| | | item.showBillboard = true; |
| | | item.type = item.disasterType; |
| | | item.className = "district"; |
| | | 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); |
| | | } |
| | | } |
| | | }); |
| | |
| | | * 添加避险场所数据 |
| | | */ |
| | | function addTetrahedron() { |
| | | loadAreaPolygon("/json/emergency_area.geojson", true).then((entities) => { |
| | | entities.forEach((entity) => (entity.show = false)); |
| | | treeMap.set("避险场所", entities); |
| | | getSafePoint(110116110218).then((res) => { |
| | | const geoJsonData = convertToGeoJson(res.data); // 转换为 GeoJSON |
| | | // 加载 GeoJSON 数据到地图 |
| | | loadAreaPolygon(geoJsonData, true).then((entities) => { |
| | | entities.forEach((entity) => (entity.show = false)); |
| | | treeMap.set("避险场所", entities); |
| | | }); |
| | | }); |
| | | } |
| | | |
| | |
| | | const defaultKeys = [...defaultSelectedKeys.value]; |
| | | const checkedKeys = |
| | | { |
| | | // 页面默认勾选显示在此处 |
| | | "/yhgl": [...defaultKeys, "孙胡沟隐患点"], |
| | | "/zhjc": [...defaultKeys, "综合监测设备信息"], |
| | | // "/mnfz": [...defaultKeys, "孙胡沟断面"], |