From 419fe50acad4674f50c6639b3ec7ccbcaf2cbf44 Mon Sep 17 00:00:00 2001
From: feiyu02 <risaku@163.com>
Date: 星期四, 20 三月 2025 17:43:49 +0800
Subject: [PATCH] 走航融合(待完成)

---
 src/model/SatelliteGrid.js |  365 ++++++++++++++++++++++++++++++---------------------
 1 files changed, 215 insertions(+), 150 deletions(-)

diff --git a/src/model/SatelliteGrid.js b/src/model/SatelliteGrid.js
index 4bc2504..dad244c 100644
--- a/src/model/SatelliteGrid.js
+++ b/src/model/SatelliteGrid.js
@@ -10,15 +10,22 @@
   constructor(name) {
     this.name = name;
   }
-
-  // 鍦板浘缃戞牸鐩稿叧瀵硅薄
+  // 榛樿鍦板浘缃戞牸鐩稿叧瀵硅薄
   mapViews;
 
-  mapViewsList = [];
+  gridDataDetail;
 
+  infoMap = new Map();
+
+  // 鍦板浘缃戞牸瀵硅薄Map缁撴瀯锛屽瓨鍌ㄥ搴攌ey涓嬬殑缃戞牸瀵硅薄銆佺綉鏍煎潗鏍囦俊鎭�
   mapViewsMap = new Map();
 
+  // 缃戞牸鏁版嵁Map缁撴瀯锛屽瓨鍌ㄥ搴攌ey涓嬬殑缃戞牸鐩戞祴鏁版嵁淇℃伅
+  gridDataDetailMap = new Map();
+
   districtPolygon;
+
+  firstEvent;
 
   events = new Map();
 
@@ -83,8 +90,6 @@
       }
     }
   }
-
-  firstEvent;
 
   // 缁樺埗缃戞牸绾�
   drawPolyline(gridInfo, event) {
@@ -166,14 +171,16 @@
     points,
     gridDataDetail,
     lastGridViews,
-    opacity,
-    zIndex,
-    customColor
+    customColor,
+    style
   }) {
     // 鏍规嵁鏁版嵁绛涢�夋湁鏁版嵁鐨勭綉鏍�
     const res = [];
     // 浠ュ強瀵瑰簲鐨勪腑蹇冪偣鍧愭爣
     const pointsRes = [];
+    // 缃戞牸鎸夌収鍏剁紪鍙峰崌搴忔帓鍒楋紝鐒跺悗璁$畻缂栧彿鍜屼笅琛ㄧ殑鍋忓樊鍊�
+    const offset = gridViews[0].getExtData().gridCell.cellIndex - 0;
+
     gridDataDetail.forEach((d) => {
       // 鏍规嵁鏁版嵁鍏宠仈鐨勭綉鏍肩紪鍙凤紝鎵惧埌瀵瑰簲缃戞牸
       const cellId = d.cellId;
@@ -182,8 +189,8 @@
           '閬ユ祴鏁版嵁鐨勭綉鏍肩储寮曠紪鍙疯秴鍑虹綉鏍肩粍鑼冨洿锛屾暟鎹拰缃戞牸缁勫彲鑳戒笉瀵瑰簲'
         );
       }
-      res.push(gridViews[cellId - 1]);
-      pointsRes.push(points[cellId - 1]);
+      res.push(gridViews[cellId - offset]);
+      pointsRes.push(points[cellId - offset]);
     });
 
     // 鏍规嵁缁樺埗棰滆壊鏂瑰紡缁樺埗缃戞牸
@@ -192,16 +199,14 @@
       resGridViews = gridMapUtil.drawGridColorCustom(
         res,
         gridDataDetail,
-        opacity,
-        zIndex
+        style.opacity
       );
     } else {
       resGridViews = gridMapUtil.drawGridColor(
         res,
         gridDataDetail,
         'PM25',
-        opacity,
-        zIndex
+        style
       );
     }
 
@@ -223,167 +228,86 @@
 
   // 缁樺埗缃戞牸閬ユ劅鏁版嵁鍊煎拰缃戞牸棰滆壊
   drawGrid({
-    gridDataDetail,
-    useCustomColor,
-    opacity,
-    zIndex,
-    showDataTxt,
-    showRankTxt,
-    useDataTxtColor,
-    mapViews
+    mapViews,
+    data,
+    grid = { useCustomColor: false, style: { opacity: 1, zIndex: 11 } },
+    dataTxt = { isShow: false, useCustomColor: false, useColor: false },
+    rankTxt = { isShow: false }
   }) {
     const _mapViews = mapViews ? mapViews : this.mapViews;
-    // SatelliteProxy.clearText(mapViews);
+    this.gridDataDetail = data;
     const { resGridViews, pointsRes } = this.drawColor({
       gridViews: _mapViews.gridViews,
       points: _mapViews.points,
-      gridDataDetail: gridDataDetail,
+      gridDataDetail: data,
       lastGridViews: _mapViews.lastGridViews,
-      customColor: useCustomColor,
-      opacity: opacity,
-      zIndex: zIndex
+      customColor: grid.useCustomColor,
+      style: grid.style
     });
     _mapViews.lastGridViews = resGridViews;
     _mapViews.lastPoints = pointsRes;
 
     // 鏁版嵁鏍囪
-    const { textViews: dataTxt, labelsLayer: dataLayer } = this.drawDataText(
+    const { textViews: dtv } = this.drawDataText(
       _mapViews.lastPoints,
-      gridDataDetail,
+      data,
       _mapViews.dataTxt,
-      useCustomColor,
-      useDataTxtColor
+      dataTxt.useCustomColor,
+      dataTxt.useColor
     );
-    _mapViews.dataTxt = dataTxt;
-    _mapViews.dataLayer = dataLayer;
+    _mapViews.dataTxt = dtv;
 
-    const { textViews: rankTxt, labelsLayer: rankLayer } = this.drawRankText(
+    const { textViews: rtv } = this.drawRankText(
       _mapViews.lastPoints,
-      gridDataDetail,
+      data,
       _mapViews.rankTxt,
       _mapViews.rankLayer
     );
-    _mapViews.rankTxt = rankTxt;
-    _mapViews.rankLayer = rankLayer;
+    _mapViews.rankTxt = rtv;
 
-    if (showDataTxt) {
+    if (dataTxt.isShow) {
       map.add(_mapViews.dataTxt);
     }
 
-    if (showRankTxt) {
+    if (rankTxt.isShow) {
       map.add(_mapViews.rankTxt);
     }
   }
 
-  //
-  drawGrids({
-    gridDataDetailList,
-    useCustomColor,
-    opacity,
-    zIndex,
-    showDataTxt,
-    showRankTxt
-  }) {
-    if (this.mapViewsList.length < gridDataDetailList.length) {
-      let index = this.mapViewsList.length;
-      while (index < gridDataDetailList.length) {
-        const newMapViews = {
-          gridViews: gridMapUtil.drawPolylines({
-            points: this.mapViews.gridPoints,
-            event: this.firstEvent
-          }),
-          gridPoints: JSON.parse(JSON.stringify(this.mapViews.gridPoints)),
-          points: JSON.parse(JSON.stringify(this.mapViews.points))
-        };
-        this.mapViewsList.push(newMapViews);
-      }
-    }
-
-    this.mapViewsList.forEach((m, i) => {
-      this.drawGrid({
-        gridDataDetail: gridDataDetailList[i],
-        useCustomColor,
-        opacity,
-        zIndex,
-        showDataTxt,
-        showRankTxt,
-        mapViews: m
-      });
-    });
-  }
-
-  drawNewGrid({
-    gridDataDetail,
-    useCustomColor,
-    opacity,
-    zIndex,
-    showDataTxt,
-    showRankTxt
-  }) {
-    const newMapViews = {
-      gridViews: gridMapUtil.drawPolylines({
-        points: this.mapViews.gridPoints,
-        event: this.firstEvent
-      }),
-      gridPoints: JSON.parse(JSON.stringify(this.mapViews.gridPoints)),
-      points: JSON.parse(JSON.stringify(this.mapViews.points))
-    };
-    this.mapViewsList.push(newMapViews);
-    this.drawGrid({
-      gridDataDetail,
-      useCustomColor,
-      opacity,
-      zIndex,
-      showDataTxt,
-      showRankTxt,
-      mapViews: newMapViews
-    });
-  }
-  drawTagGrid({
-    tag,
-    gridDataDetail,
-    useCustomColor,
-    opacity,
-    zIndex,
-    showDataTxt,
-    showRankTxt
-  }) {
+  /**
+   * 鏍规嵁tag鏍囩锛屽睍绀哄凡鏈夌殑缃戞牸鎴栫粯鍒朵竴缁勬柊鐨勭綉鏍�
+   * @param {Object} param0 {
+   * tag, 鏍囩
+   * gridDataDetail, 缃戞牸鏁版嵁鏁扮粍
+   * useCustomColor, 鏄惁浣跨敤瀵规瘮鑹�
+   * opacity, 閫忔槑搴︼紝鍙栧�糩0, 1]
+   * zIndex, 鍦板浘鏄剧ず灞傜骇
+   * showDataTxt, 鏄惁鏄剧ず鏁版嵁鏂囨湰
+   * showRankTxt, 鏄惁鏄剧ず鎺掑悕鏂囨湰
+   * extData, 鑷畾涔夐澶栦俊鎭璞�
+   * }
+   */
+  drawTagGrid({ tag, data, grid, dataTxt, rankTxt, extData }) {
     if (!this.mapViewsMap.has(tag)) {
-      const newMapViews = {
-        gridViews: gridMapUtil.drawPolylines({
-          points: this.mapViews.gridPoints,
-          event: this.firstEvent
-        }),
-        gridPoints: JSON.parse(JSON.stringify(this.mapViews.gridPoints)),
-        points: JSON.parse(JSON.stringify(this.mapViews.points))
-      };
+      const newMapViews = this._createNewMapViews({ extData });
+      this.infoMap.set(tag, extData);
       this.mapViewsMap.set(tag, newMapViews);
+      this.gridDataDetailMap.set(tag, data);
     }
     const _mapViews = this.mapViewsMap.get(tag);
     this.drawGrid({
-      gridDataDetail,
-      useCustomColor,
-      opacity,
-      zIndex,
-      showDataTxt,
-      showRankTxt,
-      mapViews: _mapViews
+      mapViews: _mapViews,
+      data,
+      grid,
+      dataTxt,
+      rankTxt
     });
   }
 
   // 璋冩暣鍚勭被鍦板浘瑕嗙洊鐗╃殑鍙鎬�
-  changeVisibility({ tag, showGridViews, showDataTxt, showRankTxt }) {
-    let _mapViewsList = [];
-    if (this.mapViews) {
-      _mapViewsList.push(this.mapViews);
-    }
-    if (tag && this.mapViewsMap.has(tag)) {
-      _mapViewsList.push(this.mapViewsMap.get(tag));
-    } else {
-      this.mapViewsMap.forEach((v) => {
-        _mapViewsList.push(v);
-      });
-    }
+  changeVisibility({ tags = [], showGridViews, showDataTxt, showRankTxt }) {
+    let { _mapViewsList } = this._getMapViews(...tags);
+
     if (showGridViews != undefined) {
       if (showGridViews) {
         // map.add(this.mapViews.lastGridViews);
@@ -426,17 +350,8 @@
   }
 
   changeGridOpacity({ tag, isOpacity, opacityValue }) {
-    let _mapViewsList = [];
-    if (this.mapViews) {
-      _mapViewsList.push(this.mapViews);
-    }
-    if (tag && this.mapViewsMap.has(tag)) {
-      _mapViewsList.push(this.mapViewsMap.get(tag));
-    } else {
-      this.mapViewsMap.forEach((v) => {
-        _mapViewsList.push(v);
-      });
-    }
+    let { _mapViewsList } = tag ? this._getMapViews(tag) : this._getMapViews();
+
     _mapViewsList.forEach((v) => {
       if (v.lastGridViews) {
         v.lastGridViews.forEach((e) => {
@@ -451,6 +366,37 @@
         });
       }
     });
+  }
+
+  changeGridColor({
+    tag,
+    useCustomColor,
+    opacity,
+    zIndex,
+    isMixGridHighlight
+  }) {
+    let { _mapViewsList, _gridDataDetailList } = this._getMapViews(tag);
+    if (_mapViewsList.length == _gridDataDetailList.length) {
+      _mapViewsList.forEach((v, i) => {
+        if (v.lastGridViews) {
+          const lastGridDataDetail = _gridDataDetailList[i];
+          if (useCustomColor) {
+            gridMapUtil.drawGridColorCustom(
+              v.lastGridViews,
+              lastGridDataDetail,
+              { opacity, zIndex }
+            );
+          } else {
+            gridMapUtil.drawGridColor(
+              v.lastGridViews,
+              lastGridDataDetail,
+              'PM25',
+              { opacity, zIndex, isMixGridHighlight }
+            );
+          }
+        }
+      });
+    }
   }
 
   setGridEvent(name, event) {
@@ -485,4 +431,123 @@
       });
     }
   }
+
+  /**
+   * 灏嗗缁勭綉鏍艰繘琛岃瀺鍚�
+   * 閲嶅彔鐨勭綉鏍艰繘琛岀洃娴嬫暟鎹潎鍊艰绠楀苟閲嶆柊璁$畻瀵瑰簲棰滆壊锛屽舰鎴愭柊鐨勪竴缁勮瀺鍚堢綉鏍�
+   * @param {...String} tags 闇�瑕佽瀺鍚堢殑缃戞牸鏍囩锛屽綋涓虹┖鏃讹紝榛樿铻嶅悎鎵�鏈夌綉鏍�
+   */
+  mixGrid(tags) {
+    tags.sort((a, b) => {
+      return a < b ? -1 : 1;
+    });
+    const mixTag = tags.join('-');
+    if (this.mapViewsMap.has(mixTag)) {
+      this.changeVisibility({
+        tag: mixTag,
+        showGridViews: true
+      });
+    } else {
+      // const mixMapViews = this._createNewMapViews();
+      // 鏍规嵁鏍囩tag锛岃幏鍙栧搴斿缁勭綉鏍兼暟鎹�
+      let { _gridDataDetailList } = this._getMapViews(...tags);
+      const _dataMap = new Map();
+      // 灏嗘瘡缁勬瘡涓綉鏍兼暟鎹寜鐓х綉鏍肩紪鍙疯繘琛屽垎绫伙紝鐩稿悓缃戞牸鐨勬暟缁勫綊闆嗚嚦涓�璧�
+      _gridDataDetailList.forEach((list) => {
+        list.forEach((gdd) => {
+          if (!_dataMap.has(gdd.cellId)) {
+            _dataMap.set(gdd.cellId, {
+              source: [],
+              res: {}
+            });
+          }
+          _dataMap.get(gdd.cellId).source.push(gdd);
+        });
+      });
+      // 璁$畻姣忎釜缃戞牸涓嬬殑鏁版嵁鍧囧��
+      const resGridDataDetail = [];
+      _dataMap.forEach((v, k) => {
+        let total = 0,
+          count = v.source.length;
+        v.source.forEach((s) => {
+          total += s.pm25;
+        });
+        v.res = {
+          isMixData: true,
+          groupId: v.source[0].groupId,
+          cellId: v.source[0].cellId,
+          pm25: count == 0 ? null : Math.round((total / count) * 10) / 10,
+          originData: v.source
+        };
+        // 鏁版嵁閲忚秴杩�1涓椂锛岃〃鏄庤缃戞牸鏁版嵁鏄瀺鍚堢殑锛屽睍绀洪珮浜殑鏍峰紡
+        if (count > 1) {
+          v.res.gridStyle = {
+            strokeWeight: 2,
+            strokeColor: 'blue'
+          };
+        }
+        resGridDataDetail.push(v.res);
+      });
+      // 閲嶆柊鎸夌収鐩戞祴鏁版嵁鎺掑簭骞舵爣璁版帓鍚�
+      resGridDataDetail.sort((a, b) => {
+        return b.pm25 - a.pm25;
+      });
+      resGridDataDetail.forEach((gdd, i) => {
+        gdd.rank = i + 1;
+      });
+
+      this.drawTagGrid({
+        tag: mixTag,
+        data: resGridDataDetail,
+        grid: {
+          style: {
+            isMixGridHighlight: true
+          }
+        },
+        extData: {
+          name: `璧拌埅铻嶅悎 - ${mixTag}`
+        }
+      });
+    }
+
+    return mixTag;
+  }
+
+  _getMapViews(...tags) {
+    let _mapViewsList = [],
+      _gridDataDetailList = [];
+    if (tags.length > 0) {
+      tags.forEach((tag) => {
+        if (this.mapViewsMap.has(tag) && this.gridDataDetailMap.has(tag)) {
+          _mapViewsList.push(this.mapViewsMap.get(tag));
+          _gridDataDetailList.push(this.gridDataDetailMap.get(tag));
+        }
+      });
+    } else {
+      this.mapViewsMap.forEach((v) => {
+        _mapViewsList.push(v);
+      });
+      this.gridDataDetailMap.forEach((v) => {
+        _gridDataDetailList.push(v);
+      });
+      if (this.mapViews && this.gridDataDetail) {
+        _mapViewsList.push(this.mapViews);
+        _gridDataDetailList.push(this.gridDataDetail);
+      }
+    }
+
+    return { _mapViewsList, _gridDataDetailList };
+  }
+
+  _createNewMapViews({ extData }) {
+    return {
+      gridViews: gridMapUtil.drawPolylines({
+        points: this.mapViews.gridPoints,
+        event: this.firstEvent
+      }),
+      gridPoints: JSON.parse(JSON.stringify(this.mapViews.gridPoints)),
+      points: JSON.parse(JSON.stringify(this.mapViews.points)),
+      extData
+    };
+  }
 }

--
Gitblit v1.9.3