guonan
2025-06-10 f0a0f01ca70e852caf0300fd47d1840799c4d65d
src/components/tools/LayerTree.vue
@@ -13,18 +13,26 @@
</template>
<script setup>
import { ref, onMounted, watch, nextTick, onUnmounted } from "vue";
import {
  ref,
  onMounted,
  watch,
  nextTick,
  onUnmounted,
  computed,
  watchEffect,
} from "vue";
import { createPoint, removeEntities, addTileset } from "@/utils/map";
import { deviceDictList, getDictName } from "@/constant/dict.js";
import { useRoute } from "vue-router";
import { loadAreaPolygon, clearAreaPolygon } from "@/utils/area";
import { checkedKeys } from "@/store/index";
import {
  getDuanMainData,
  getDevicetListData,
  getDistrictListData,
} from "@/api/index.js";
import { init } from "echarts";
import { getDuanMainData, getDistrictListData } from "@/api/index.js";
import { getDeviceInfoShg, getDangerPoint } from "@/api/hpApi";
import { useSimStore } from "@/store/simulation";
const simStore = useSimStore();
const route = useRoute();
@@ -34,7 +42,7 @@
    label: "三维服务",
    children: [
      { label: "模型数据" },
      { label: "地形数据" },
      { label: "地形数据" },
      { label: "影像数据" },
    ],
  },
@@ -45,7 +53,7 @@
      { label: "孙胡沟隐患点" },
      { label: "综合监测设备信息" },
      { label: "孙胡沟断面" },
      { label: "避险点" },
      { label: "避险场所" },
    ],
  },
]);
@@ -86,7 +94,6 @@
//   // treeMap.set("影像数据", ImageryLayer);
// }
// 地形数据
let TerrainLayer = null;
async function initMap() {
@@ -94,7 +101,9 @@
    // 初始化地形数据(使用await等待Promise解析)
    TerrainLayer = await earthCtrl.factory.createTerrainLayer({
      sourceType: "ctb",
      url: "http://106.120.22.26:9103/gisserver/ctsserver/sungugoudem",
      url: "http://106.120.22.26:9103/gisserver/ctsserver/sunhugoudem",
      // url: "https://tiles1.geovisearth.com/base/v1/terrain?token=486dac3bec56d7d7c2a581c150be2bd937462f1e8f3bc9c78b5658b396122405",
      requestVertexNormals: true,
    });
    treeMap.set("地形数据", TerrainLayer);
@@ -177,6 +186,30 @@
    }
    return;
  }
  if (label === "综合监测设备信息") {
    simStore.DeviceShowSwitch = checked;
    if (checked) {
      if (!treeMap.get("综合监测设备信息")) {
      } else {
        toggleLayerVisible("综合监测设备信息", true);
      }
    } else {
      toggleLayerVisible("综合监测设备信息", false);
    }
    return;
  }
  if (label === "孙胡沟隐患点") {
    simStore.DangerShowSwitch = checked;
    if (checked) {
      if (!treeMap.get("孙胡沟隐患点")) {
      } else {
        toggleLayerVisible("孙胡沟隐患点", true);
      }
    } else {
      toggleLayerVisible("孙胡沟隐患点", false);
    }
    return;
  }
  // 其他图层的处理逻辑
  const list = treeMap.get(label);
@@ -193,7 +226,7 @@
    case "泥石流隐患点面数据":
    case "综合监测设备信息":
    case "孙胡沟断面":
    case "避险点":
    case "避险场所":
      console.log(label, checked, indeterminate);
      break;
  }
@@ -204,41 +237,35 @@
 */
function toggleLayerVisible(name, checked) {
  const entityList = treeMap.get(name);
  console.log(`Toggling visibility for ${name}:`, checked);
  if (Array.isArray(entityList)) {
    entityList.forEach((entity) => {
      console.log(`Setting entity show to:`, checked);
      // console.log(`Setting entity show to:`, checked);
      entity.show = checked;
    });
  } else if (entityList && typeof entityList.show !== "undefined") {
    console.log(`Setting layer show to:`, checked);
    entityList.show = checked;
  } else {
    console.error(`无法设置图层 ${name} 的可见性`);
    // console.error(`无法设置图层 ${name} 的可见性`);
  }
}
// 设备列表
// 监测设备列表
const devicetList = ref([]);
/**
 * 获取设备列表并初始化设备点
 */
// 监测设备列表
const getDevicetList = async () => {
  await getDevicetListData().then((res) => {
    console.log(res.data, "devicetList.value2");
    devicetList.value = res.data;
  });
  const res = await getDeviceInfoShg(); // 调整getDeviceInfoShg以接受动态参数,如果需要的话
  devicetList.value = res.data.pageData.filter((item) =>
    item.deviceName?.includes("孙胡沟")
  );
};
// 默认加载部分已替换至Device.vue中,逻辑修改为根据当前选择地形切换设备点显示
async function initDevicePoint() {
  let list = [];
  await getDevicetList();
  devicetList.value.forEach((item) => {
    item.type = getDictName(deviceDictList, item.dictDeviceType);
    item.name = item.type;
    item.name = item.deviceName.split("孙胡沟")[1];
    item.id = item.deviceId;
    item.className = "device";
    item.showLabel = true;
@@ -250,34 +277,34 @@
  treeMap.set("综合监测设备信息", list);
}
// 区域列表
const districtList = ref([]);
// 隐患点列表
watchEffect(() => {
  const dangerPoints = simStore.DangerPoint.filter((item) =>
    item.position?.includes("孙胡沟")
  );
/**
 * 获取区域列表并初始化区域点
 */
const getDistrictList = async () => {
  await getDistrictListData().then((res) => {
    districtList.value = res.data;
  });
};
  if (dangerPoints && dangerPoints.length > 0) {
    const list = [];
async function initDistrictPoint() {
  let list = [];
  await getDistrictList();
  districtList.value.forEach((item) => {
    item.showBillboard = true;
    item.className = "district";
    item.type = "泥石流";
    const entity = createPoint(item);
    entity.show = false;
    list.push(entity);
  });
  treeMap.set("孙胡沟隐患点", list);
}
    dangerPoints.forEach((item) => {
      // console.log(item, "item");
      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";
      const entity = createPoint(item);
      entity.show = false;
      list.push(entity);
    });
    treeMap.set("孙胡沟隐患点", list);
  }
});
let divPointList = [];
/**
 * 初始化断面点
 */
@@ -302,21 +329,21 @@
}
/**
 * 添加避险点
 * 添加避险场所
 */
function addTetrahedron(visible) {
  const emergencyAreaList = [];
  // 加载避险点底层面片
  // 加载避险场所底层面片
  loadAreaPolygon("/json/emergency_area.geojson", true).then((entities) => {
    emergencyAreaList.push(...entities);
    // 默认隐藏避险点
    // 默认隐藏避险场所
    entities.forEach((entity) => {
      entity.show = false;
    });
    // 将避险点实体存储到 treeMap
    treeMap.set("避险点", entities);
    // 将避险场所实体存储到 treeMap
    treeMap.set("避险场所", entities);
  });
}
@@ -325,7 +352,7 @@
 */
function getData() {
  initDevicePoint();
  initDistrictPoint();
  // initDistrictPoint();
  initDuanmianPoint();
  addTetrahedron();
}
@@ -389,6 +416,7 @@
</script>
<style lang="less" scoped>
@import url("../../assets/css/infobox.css");
.layer-tree {
  background: url("@/assets/img/tools/plotting_new.png");
  width: 200px;
@@ -397,6 +425,6 @@
  overflow: hidden;
}
/deep/ .el-tree {
    overflow: hidden !important;
  overflow: hidden !important;
}
</style>