From 4097cc9ad6c60bbb5e9864d3f54a37cfbb40026e Mon Sep 17 00:00:00 2001
From: riku <risaku@163.com>
Date: 星期三, 05 三月 2025 15:31:28 +0800
Subject: [PATCH] 临时:路网版本

---
 src/model/Legend.js        |   22 +++++++---
 src/utils/map/index_old.js |    2 
 index.html                 |    2 
 src/model/Factor.js        |    3 +
 src/utils/map/line.js      |   41 ++++++++------------
 src/views/HomePage.vue     |   42 ++++++++++++++++++++
 6 files changed, 76 insertions(+), 36 deletions(-)

diff --git a/index.html b/index.html
index 7708be1..760c1a3 100644
--- a/index.html
+++ b/index.html
@@ -16,7 +16,7 @@
     </script>
     <script
       type="text/javascript"
-      src="https://webapi.amap.com/maps?v=1.4.5&key=520c5e5cf44c7793104e500cbf0ed711&plugin=Map3D,ElasticMarker,AMap.ControlBar,AMap.Geocoder"
+      src="https://webapi.amap.com/maps?v=1.4.5&key=520c5e5cf44c7793104e500cbf0ed711&plugin=Map3D,ElasticMarker,AMap.ControlBar,AMap.Geocoder,AMap.DistrictSearch"
     ></script>
     <!-- <script src="/src/lib/jquery-3.5.1.min.js"></script> -->
     <script type="module" src="/src/main.js"></script>
diff --git a/src/model/Factor.js b/src/model/Factor.js
index 28d65ce..b9983b1 100644
--- a/src/model/Factor.js
+++ b/src/model/Factor.js
@@ -60,7 +60,8 @@
   this.standardMin = -1; //鐩戞祴鍥犲瓙绫诲瀷瀵瑰簲鐨勬爣鍑嗘渶灏忓��
   this.standardMax = -1; //鐩戞祴鍥犲瓙绫诲瀷瀵瑰簲鐨勬爣鍑嗘渶澶у��
 
-  this.legendType = Legend.S_TYPE; //鍥句緥妯″紡
+  // this.legendType = Legend.S_TYPE; //鍥句緥妯″紡
+  this.legendType = Legend.D_TYPE; //鍥句緥妯″紡
 
   if (options != undefined) {
     this.datas = options.datas;
diff --git a/src/model/Legend.js b/src/model/Legend.js
index 42abee3..9dfbcc4 100644
--- a/src/model/Legend.js
+++ b/src/model/Legend.js
@@ -142,13 +142,21 @@
     ]
   },
 
+  // _custom: [
+  //   [0.05, 0.9, 0.03, 0.75],
+  //   [0.3, 0.65, 0.02, 0.75],
+  //   [0.87, 0.92, 0.03, 0.75],
+  //   [0.8, 0.67, 0.04, 0.75],
+  //   [0.92, 0.28, 0.07, 0.75],
+  //   [0.6, 0.05, 0.05, 0.75]
+  // ],
   _custom: [
-    [0.05, 0.9, 0.03, 0.75],
-    [0.3, 0.65, 0.02, 0.75],
-    [0.87, 0.92, 0.03, 0.75],
-    [0.8, 0.67, 0.04, 0.75],
-    [0.92, 0.28, 0.07, 0.75],
-    [0.6, 0.05, 0.05, 0.75]
+    [0, 0.89, 0, 0.75],
+    [1, 1, 0, 0.75],
+    [1, 0.49, 0, 0.75],
+    [1, 0, 0, 0.75],
+    [0.6, 0, 0.3, 0.75],
+    [0.49, 0, 0.14, 0.75]
   ],
 
   getStandardRange: function (name) {
@@ -241,7 +249,7 @@
 
   getCustomColor: function (data, min, max) {
     var per = (max - min) / this._custom.length;
-    var i = parseInt(data / per);
+    var i = parseInt((data - min) / per);
     if (i >= this._custom.length) {
       i = this._custom.length - 1;
     }
diff --git a/src/utils/map/index_old.js b/src/utils/map/index_old.js
index c296864..77cc81e 100644
--- a/src/utils/map/index_old.js
+++ b/src/utils/map/index_old.js
@@ -47,7 +47,7 @@
     alwaysRender: false,
     showLabel: true,
     showBuildingBlock: true,
-    mapStyle: 'amap://styles/e1e78509de64ddcd2efb4cb34c6fae2a',
+    // mapStyle: 'amap://styles/e1e78509de64ddcd2efb4cb34c6fae2a',
     features: ['bg', 'road'],
     pitch: 45, // 鍦板浘淇话瑙掑害锛屾湁鏁堣寖鍥� 0 搴�- 83 搴�
     viewMode: '3D', // 鍦板浘妯″紡
diff --git a/src/utils/map/line.js b/src/utils/map/line.js
index 6c72bb5..d2211a5 100644
--- a/src/utils/map/line.js
+++ b/src/utils/map/line.js
@@ -40,40 +40,31 @@
       const lastC = colors[i - 1];
       if (distance > 500 || c != lastC) {
         let _path, _color;
+        _path = path.slice(sIndex, i);
+        _color = getHexColor(
+          lastC.map((v, index) => {
+            if (index < lastC.length - 1) {
+              return v * 255;
+            } else {
+              return v;
+            }
+          })
+        );
         // 褰撲袱鐐硅窛绂昏秴杩�500鏃讹紝璁や负涓ょ偣涓嶈繛缁紝涓嶇粯鍒惰繛绾�
         if (distance > 500) {
-          _path = path.slice(sIndex, i);
-          _color = getHexColor(
-            lastC.map((v, index) => {
-              if (index < lastC.length - 1) {
-                return v * 255;
-              } else {
-                return v;
-              }
-            })
-          );
+          sIndex = i;
         } else {
-          _path = path.slice(sIndex, i + 1);
-          _color = getHexColor(
-            c.map((v, index) => {
-              if (index < c.length - 1) {
-                return v * 255;
-              } else {
-                return v;
-              }
-            })
-          );
+          sIndex = i - 1;
         }
 
         // 鍒涘缓鎶樼嚎瀹炰緥
         const polyline = newPolyline(_path, _color);
         _polylineArr.push(polyline);
-
-        sIndex = i;
       }
     }
-    if (sIndex == 0) {
-      const c = colors[sIndex];
+    if (sIndex < path.length - 1) {
+      const c = colors[path.length - 1];
+      const _path = path.slice(sIndex, path.length);
       const _color = getHexColor(
         c.map((v, index) => {
           if (index < c.length - 1) {
@@ -83,7 +74,7 @@
           }
         })
       );
-      const polyline = newPolyline(path, _color);
+      const polyline = newPolyline(_path, _color);
       _polylineArr.push(polyline);
     }
     // 灏嗘姌绾挎坊鍔犺嚦鍦板浘瀹炰緥
diff --git a/src/views/HomePage.vue b/src/views/HomePage.vue
index 6e0f275..0d22cf3 100644
--- a/src/views/HomePage.vue
+++ b/src/views/HomePage.vue
@@ -17,7 +17,47 @@
 </template>
 
 <script setup>
-import SatelliteTelemetry from '@/views/satellitetelemetry/SatelliteTelemetry.vue';
+import { map, onMapMounted } from '@/utils/map/index_old';
+
+let districtPolygon;
+// 缁樺埗鍖哄幙杈圭晫
+function drawDistrict(districtName, isNew) {
+  onMapMounted(() => {
+    if (districtPolygon && !isNew) {
+      map.remove(districtPolygon);
+      map.add(districtPolygon);
+    } else {
+      // eslint-disable-next-line no-undef
+      var district = new AMap.DistrictSearch({
+        extensions: 'all', //杩斿洖琛屾斂鍖鸿竟鐣屽潗鏍囩瓑鍏蜂綋淇℃伅
+        level: 'district' //璁剧疆鏌ヨ琛屾斂鍖虹骇鍒负鍖�
+      });
+      district.search(districtName, function (status, result) {
+        var bounds = result.districtList[0].boundaries; //鑾峰彇鏈濋槼鍖虹殑杈圭晫淇℃伅
+        if (bounds) {
+          for (var i = 0; i < bounds.length; i++) {
+            //鐢熸垚琛屾斂鍖哄垝 polygon
+            // eslint-disable-next-line no-undef
+            districtPolygon = new AMap.Polygon({
+              map: map, //鏄剧ず璇ヨ鐩栫墿鐨勫湴鍥惧璞�
+              strokeWeight: 1, //杞粨绾垮搴�
+              path: bounds[i], //澶氳竟褰㈣疆寤撶嚎鐨勮妭鐐瑰潗鏍囨暟缁�
+              fillOpacity: 0.6, //澶氳竟褰㈠~鍏呴�忔槑搴�
+              // fillColor: '#CCF3FF', //澶氳竟褰㈠~鍏呴鑹�
+              fillColor: '#0077ff',
+              // strokeColor: '#ffffff' //绾挎潯棰滆壊
+              strokeColor: 'white', //绾挎潯棰滆壊
+              zIndex: 9
+            });
+          }
+          map.setFitView(); //灏嗚鐩栫墿璋冩暣鍒板悎閫傝閲�
+        }
+      });
+    }
+  });
+}
+
+drawDistrict('闀垮畞鍖�');
 </script>
 
 <style scoped>

--
Gitblit v1.9.3