guonan
9 天以前 6958d50ab485cb42a99c0a410b40d45ee9ee9856
避险场所
已修改3个文件
88 ■■■■ 文件已修改
src/api/hpApi.js 7 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/Home.vue 47 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/mnfz.vue 34 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/api/hpApi.js
@@ -248,14 +248,17 @@
}
// 查询孙胡沟避险场所
export async function getSafePoint() {
export async function getSafePoint(data) {
  const response = await axios.get("/hp/safeHavenLocation/getDataSelect", {
    params: {
      divisionId: 110116110218
      divisionId: data
    }
  });
  return response.data;
}
// 110116110218
// 查询北京市
export async function getAllCode() {
src/views/Home.vue
@@ -60,7 +60,7 @@
import { showDeviceDetail } from "@/store";
import { setupTokenRefresh, getDangerPoint, getAllCode } from "@/api/hpApi.js";
import { convertToWKT } from "@/utils/wktUtils";
import { getDeviceInfoSHG, getSafePoint } from "@/api/hpApi";
import { getDeviceInfoSHG, getWeather } from "@/api/hpApi";
const route = useRoute();
const simStore = useSimStore();
@@ -100,35 +100,52 @@
// 计算属性
const showDetail = computed(() => showDeviceDetail.value);
function extractAllChildrenInfoUnique(dataArray) {
  const map = new Map();
function groupTopWithLeafNodes(dataArray) {
  const result = {};
  function traverse(nodes) {
  function traverse(nodes, topLevelName = null) {
    if (!Array.isArray(nodes)) return;
    for (const node of nodes) {
      const key = node.code;
      const isLeaf = !node.children || node.children.length === 0;
      // 检查是否是最后一层(没有子节点或子节点为空数组)
      if (!node.children || node.children.length === 0) {
        if (key && !map.has(key)) {
          map.set(key, { name: node.nameChn, code: key });
      // 如果是顶层节点,记录它的名字作为 key
      if (!topLevelName && !isLeaf) {
        topLevelName = node.nameChn;
        if (!result[topLevelName]) {
          result[topLevelName] = [];
        }
      } else {
        // 如果有子节点,继续递归遍历
        traverse(node.children);
      }
      // 如果是叶子节点,加入对应数组
      if (isLeaf && topLevelName) {
        result[topLevelName].push({
          name: node.nameChn,
          code: node.code,
        });
      }
      // 继续递归子节点(保持当前顶层名称)
      if (node.children && node.children.length > 0) {
        traverse(node.children, topLevelName);
      }
    }
  }
  traverse(dataArray);
  return Array.from(map.values());
  // 遍历整个大数组中的每一项(即每一个区域)
  for (const item of dataArray) {
    if (item && item.children && Array.isArray(item.children)) {
      traverse([item]); // 把当前项包装成数组,方便统一处理
    }
}
  return result;
}
onMounted(async () => {
  getAllCode().then((res) => {
    // 北京市所有村以及街道code
    simStore.townCodeAll = extractAllChildrenInfoUnique(res.data[0].children);
    simStore.townCodeAll = groupTopWithLeafNodes(res.data[0].children);
    console.log(simStore.townCodeAll, "aaaaaaaaaaaaaaaaaaa");
  });
  setupTokenRefresh(); // 获取宏图token
  // getSimData(); //测试tr后端
src/views/mnfz.vue
@@ -142,21 +142,48 @@
  });
  dataSources.length = 0;
}
// 避险场所,绿色富文本
async function addTetrahedron(visible) {
  const emergencyAreaList = [];
  try {
    const res = await getSafePoint();
    let codesToFetch = [];
    const geoJsonData = convertToGeoJson(res.data);
    // 判断当前选择区域是否为“区”
    if (simStore.selectedScheme.areaName.includes("区")) {
      // 从 simStore.townCodeAll 中拿到该区下的所有乡镇 code
      const townList = simStore.townCodeAll[simStore.selectedScheme.areaName];
      // 假设 townList 是一个数组,里面每个元素有 .code 字段
      if (Array.isArray(townList)) {
        codesToFetch = townList.map((item) => item.code);
      } else {
        console.warn("未找到对应的乡镇列表");
        return;
      }
    } else {
      // 不是“区”,就使用默认 code
      codesToFetch = ["110116110218"];
    }
    // 并发请求所有 code 的避险点数据
    const allRes = await Promise.all(
      codesToFetch.map((code) => getSafePoint(code))
    );
    // 合并结果(假设每个 res.data 是一个数组)
    const allSafePoints = allRes.flatMap((res) => res.data);
    // 转换为 GeoJSON(如果每个 data 都需要单独处理)
    const geoJsonData = convertToGeoJson(allSafePoints);
    // 加载底层面片(多边形)
    const polygonEntities = await loadAreaPolygon(geoJsonData, true);
    emergencyAreaList.push(...polygonEntities);
    // 添加绿色富文本标注
    const textPromises = res.data.map(async (item) => {
    const textPromises = allSafePoints.map(async (item) => {
      const point = earthCtrl.factory.createRichTextPoint(
        "避险场所",
        [item.lon , item.lat , 540],
@@ -179,6 +206,7 @@
    console.error("加载避险场所失败:", error);
  }
}
// 删除避险场所的富文本实体
function removeEmergencyPoints() {
  const emergencyAreaList = treeMap.get("避险场所"); // 获取存储的避险场所实体列表