forked from drone/command-center-dashboard

罗广辉
2025-04-03 1ed21bc95127812b77ef48b12e34e7046dc5b33a
fix: 点击聚合事件未触发
1 files modified
41 ■■■■■ changed files
src/views/Home/useMapAggregation/useMapAggregation.js 41 ●●●●● patch | view | raw | blame | history
src/views/Home/useMapAggregation/useMapAggregation.js
@@ -71,6 +71,7 @@
    }
  };
  // 转换为目录结构, 返回数组,
  function convertToHierarchy(code) {
    const codeStr = code.toString();
    const provinceCode = codeStr.slice(0, 2) + '0000';
@@ -83,18 +84,20 @@
    return [provinceCode, cityCode, code];
  }
  // 获取设备聚合
  function getDeviceCount(areaCode) {
    return getDeviceRegionCount({ areaCode }).then(res => {
      return (res?.data?.data || []).map(i=>({...i,type:'deviceAggregation'}));
      return (res?.data?.data || [])
    });
  }
  // 获取设备散点
  function getDeviceList(areaCode) {
    return getDeviceRegion({ areaCode }).then(res => {
      return (res?.data?.data || []).map(i =>({...i,type}));
    });
  }
  // 事件散点
  let eventList = []
  function processChildren(childrens) {
    return (childrens || []).map(item => {
@@ -106,7 +109,6 @@
        total_device_count: item.number,
        region_code: item.id,
        region_name: item.name,
        type:'eventAggregation'
      };
      if (arr.length !== 0) {
        returnObj.childrens = arr;
@@ -115,6 +117,7 @@
    });
  }
  // 获取事件聚合
  function getMapEventCount(areaCode) {
    return getMapEvents({ areaCode }).then(res => {
      const resData= res?.data?.data
@@ -145,7 +148,10 @@
  const injectData = (gJson, dataList) => {
    return {
      ...gJson,
      features: gJson.features.map(item => ({ ...item, data: dataList.find(item1 => findFun(item1, item)) })),
      features: gJson.features.map(item => {
        const findData = dataList.find(item1 => findFun(item1, item))
        return { ...item, data: {...findData,type: type + 'Aggregation'} }
      }),
    };
  };
@@ -172,13 +178,15 @@
    if (hierarchy.length === 1) {
      const gJson1 = await getFiler(`${defaultDir}${jsonPath}/indexDistrict.json`);
      const gJson2 = await getFiler(`${defaultDir}${jsonPath}/index.json`);
      scalingJudgment[1].gJson = {
        ...gJson1,
        features: gJson1.features.map(item => ({
          ...item,
          data: list.flatMap(item => item.childrens || []).find(item1 => findFun(item1, item)),
        })),
        features: gJson1.features.map(item => {
          const findData = list.flatMap(item => item.childrens || []).find(item1 => findFun(item1, item))
          return { ...item, data: {...findData,type: type + 'Aggregation'} }
        }),
      };
      console.log(injectData(gJson2, list));
      scalingJudgment[2].gJson = injectData(gJson2, list);
      const { lng, lat } = getCenterPoint(gJson2.features.map(item => item.properties.center));
      flyTo({ longitude: lng, latitude: lat }, 0, scalingJudgment[2].height);
@@ -273,12 +281,15 @@
  // 聚合机巢
  const aggregation = (item, flyTo) => {
    if (!item.gJson) return;
    const featuresList = item.gJson.features.map(item => ({
      name: item.properties.name,
      position: item.properties.center,
      data: item.data,
      id: item.region_code,
    }));
    const featuresList = item.gJson.features.map(item1 => {
      // const {lng,lat} = getCenterPoint(item1.geometry.coordinates[0][0])
      return {
        name: item.properties.name,
        position: item.properties.center,
        data: item.data,
        id: item.region_code,
      }
    });
    // 遍历特征并添加实体
    featuresList.forEach(feature => {
      if (!feature.position) return;
@@ -382,7 +393,7 @@
      if (!positionC3) return;
      removeLabel();
      const customData = entity.properties.customData._value.data;
      console.log('customData', customData);
      switch (customData.type) {
        case 'deviceAggregation':
          viewer.scene.postRender.addEventListener(labelBoxRender);