From 7b1293cec33b47680f08756bd1f8518d3cb1a729 Mon Sep 17 00:00:00 2001
From: Riku <risaku@163.com>
Date: 星期三, 01 一月 2025 22:33:32 +0800
Subject: [PATCH] 新增对比色

---
 src/utils/map/grid.js |   50 +++++++++++++++++++++++++++++---------------------
 1 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/src/utils/map/grid.js b/src/utils/map/grid.js
index df44cf7..7fec60a 100644
--- a/src/utils/map/grid.js
+++ b/src/utils/map/grid.js
@@ -259,26 +259,6 @@
   },
 
   drawGridColor(gridViews, texts, factorName) {
-    // new Promise((resolve, reject) => {
-    //   gridViews.forEach((g, i) => {
-    //     const data = parseFloat(texts[i]);
-    //     const { color, nextColor, range, nextRange } =
-    //       Legend.getStandardColorAndNext(factorName, data);
-    //     const ratio = (data - range) / (nextRange - range);
-    //     const _color = getColorBetweenTwoColors(
-    //       color.map((v) => v * 255),
-    //       nextColor.map((v) => v * 255),
-    //       ratio
-    //     );
-    //     resolve({ g, _color, color });
-    //   });
-    // }).then((res) => {
-    //   const { g, _color, color } = res;
-    //   g.setOptions({
-    //     fillColor: _color,
-    //     fillOpacity: color[3]
-    //   });
-    // });
     gridViews.forEach((g, i) => {
       const data = parseFloat(texts[i]);
       const { color, nextColor, range, nextRange } =
@@ -294,5 +274,33 @@
         fillOpacity: color[3]
       });
     });
-  }
+  },
+
+  drawGridColorCustom(gridViews, texts) {
+    var max,min
+    texts.forEach(t => {
+      if (!max || t > max) {
+        max = t
+      }
+      if (!min || t < min) {
+        min = t
+      }
+    });
+    gridViews.forEach((g, i) => {
+      const data = parseFloat(texts[i]);
+      const { color, nextColor, range, nextRange } =
+        Legend.getCustomColorAndNext(data, min, max);
+      const ratio = (data - range) / (nextRange - range);
+      
+      const _color = getColorBetweenTwoColors(
+        color.map((v) => v * 255),
+        nextColor.map((v) => v * 255),
+        ratio
+      );
+      g.setOptions({
+        fillColor: _color,
+        fillOpacity: color[3]
+      });
+    });
+  },
 };

--
Gitblit v1.9.3