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 | 129 ++++++++++++++++++++++++++++++------------- 1 files changed, 90 insertions(+), 39 deletions(-) diff --git a/src/components/tools/LayerTree.vue b/src/components/tools/LayerTree.vue index 425de2b..c217cd7 100644 --- a/src/components/tools/LayerTree.vue +++ b/src/components/tools/LayerTree.vue @@ -14,7 +14,12 @@ <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 { @@ -76,7 +81,7 @@ try { TerrainLayer = await earthCtrl.factory.createTerrainLayer({ sourceType: "ctb", - url: "http://106.120.22.26:9103/gisserver/ctsserver/sunhugoudem84", + url: "http://106.120.22.26:9103/gisserver/ctsserver/sunhugoudem", requestVertexNormals: true, }); treeMap.set("鍦板舰鏁版嵁", TerrainLayer); @@ -186,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); @@ -234,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); @@ -273,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); } } }); @@ -324,7 +375,7 @@ * 娣诲姞閬块櫓鍦烘墍鏁版嵁 */ function addTetrahedron() { - getSafePoint().then((res) => { + getSafePoint(110116110218).then((res) => { const geoJsonData = convertToGeoJson(res.data); // 杞崲涓� GeoJSON // 鍔犺浇 GeoJSON 鏁版嵁鍒板湴鍥� loadAreaPolygon(geoJsonData, true).then((entities) => { -- Gitblit v1.9.3