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 |  104 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 103 insertions(+), 1 deletions(-)

diff --git a/src/utils/map/grid.js b/src/utils/map/grid.js
index e5d5273..7fec60a 100644
--- a/src/utils/map/grid.js
+++ b/src/utils/map/grid.js
@@ -102,6 +102,42 @@
   });
 }
 
+/**
+ * 娴烽噺鏂囨湰鏍囨敞
+ */
+function textLabelMarker(position, text, direction) {
+  // eslint-disable-next-line no-undef
+  return new AMap.LabelMarker({
+    position: position,
+    zooms: [10, 20],
+    opacity: 1,
+    zIndex: 2,
+    // icon: {
+    //   image: 'https://a.amap.com/jsapi_demos/static/images/poi-marker.png',
+    //   anchor: 'bottom-center',
+    //   size: [25, 34],
+    //   clipOrigin: [459, 92],
+    //   clipSize: [50, 68]
+    // },
+    text: {
+      // 娉ㄦ剰鍐呭鏍煎紡蹇呴』鏄痵tring
+      content: text ? text + '' : '',
+      direction: direction ? direction : 'center',
+      style: {
+        fontSize: 12,
+        fillColor: '#fff',
+        // strokeColor: 'rgba(0, 0, 0, 0.5)',
+        // strokeWidth: 3,
+        backgroundColor: '#122b54a9'
+        // padding: [3, 10],
+        // backgroundColor: 'yellow',
+        // borderColor: '#ccc',
+        // borderWidth: 3
+      }
+    }
+  });
+}
+
 export default {
   parseGridPoint,
 
@@ -184,6 +220,44 @@
     }
   },
 
+  drawGridTextLabel(points, textViews, labelsLayer, direction) {
+    if (textViews) {
+      points.forEach((p, i) => {
+        textViews[i].setPosition(p.lnglat_GD);
+        textViews[i].setText({
+          content: p.data ? p.data + '' : ''
+        });
+      });
+      return { textViews, labelsLayer };
+    } else {
+      // 鍒涘缓涓�涓� LabelsLayer 瀹炰緥鏉ユ壙杞� LabelMarker锛孾LabelsLayer 鏂囨。](https://lbs.amap.com/api/jsapi-v2/documentation#labelslayer)
+      // eslint-disable-next-line no-undef
+      const labelsLayer = new AMap.LabelsLayer({
+        zooms: [12, 20],
+        zIndex: 1000,
+        // 寮�鍚爣娉ㄩ伩璁╋紝榛樿涓哄紑鍚紝v1.4.15 鏂板灞炴��
+        collision: false,
+        // 寮�鍚爣娉ㄦ贰鍏ュ姩鐢伙紝榛樿涓哄紑鍚紝v1.4.15 鏂板灞炴��
+        animation: false
+      });
+      const _textViews = [];
+      // const m = textLabelMarker([121.329723, 31.240625], 25);
+      // _textViews.push(m);
+      // labelsLayer.add(m);
+      points.forEach((p) => {
+        const m = textLabelMarker(p.lnglat_GD, p.data, direction);
+        _textViews.push(m);
+        // 灏� LabelMarker 瀹炰緥娣诲姞鍒� LabelsLayer 涓�
+        labelsLayer.add(m);
+      });
+      map.add(labelsLayer);
+      map.on('zoomend', () => {
+        console.log(map.getZoom());
+      });
+      return { textViews: _textViews, labelsLayer };
+    }
+  },
+
   drawGridColor(gridViews, texts, factorName) {
     gridViews.forEach((g, i) => {
       const data = parseFloat(texts[i]);
@@ -200,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