From cf7752d995e09d48eca9a1ca5634a9e71ae46553 Mon Sep 17 00:00:00 2001
From: wangjuncheng <1>
Date: 星期二, 22 七月 2025 16:19:06 +0800
Subject: [PATCH] 透明度0 修改模型数据路径

---
 src/components/tools/LayerTree.vue |  143 ++++++++++++++++++++++++++++++++++-------------
 1 files changed, 102 insertions(+), 41 deletions(-)

diff --git a/src/components/tools/LayerTree.vue b/src/components/tools/LayerTree.vue
index e29ab66..c217cd7 100644
--- a/src/components/tools/LayerTree.vue
+++ b/src/components/tools/LayerTree.vue
@@ -14,13 +14,23 @@
 
 <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();
@@ -181,7 +191,8 @@
 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);
@@ -229,37 +240,75 @@
  * 娓呴櫎鍥惧眰瀹炰綋
  * @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 == "瀛欒儭娌熼殣鎮g偣") {
+//         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 === "瀛欒儭娌熼殣鎮g偣") {
+          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);
@@ -268,28 +317,35 @@
 });
 
 // 鐩戞帶闅愭偅鐐瑰紑鍏冲彉鍖�
-watchEffect(() => {
+watchEffect(async () => {
   clearLayerEntities("瀛欒儭娌熼殣鎮g偣");
 
   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("瀛欒儭娌熼殣鎮g偣", dangerPoints);
+    try {
+      const resolvedPoints = await Promise.all(dangerPointPromises);
+
+      if (resolvedPoints.length) {
+        treeMap.set("瀛欒儭娌熼殣鎮g偣", resolvedPoints);
+      }
+    } catch (error) {
+      console.error("鍒涘缓闅愭偅鐐规椂鍙戠敓閿欒:", error);
     }
   }
 });
@@ -319,9 +375,13 @@
  * 娣诲姞閬块櫓鍦烘墍鏁版嵁
  */
 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);
+    });
   });
 }
 
@@ -350,6 +410,7 @@
     const defaultKeys = [...defaultSelectedKeys.value];
     const checkedKeys =
       {
+        // 椤甸潰榛樿鍕鹃�夋樉绀哄湪姝ゅ
         "/yhgl": [...defaultKeys, "瀛欒儭娌熼殣鎮g偣"],
         "/zhjc": [...defaultKeys, "缁煎悎鐩戞祴璁惧淇℃伅"],
         // "/mnfz": [...defaultKeys, "瀛欒儭娌熸柇闈�"],

--
Gitblit v1.9.3