From 1c31659852f8360cc0fdfac26aff51e54b8b8b67 Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期五, 27 十二月 2024 17:21:58 +0800
Subject: [PATCH] 添加排名展示;优化展示方式

---
 src/utils/map/grid.js |   94 +++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 94 insertions(+), 0 deletions(-)

diff --git a/src/utils/map/grid.js b/src/utils/map/grid.js
index e5d5273..df44cf7 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,7 +220,65 @@
     }
   },
 
+  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) {
+    // 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 } =

--
Gitblit v1.9.3