ソースを参照

TrunkCoordination、SpecialSituationMonitoring三个页面的handleFolderClick方法统一替换原随机localStorage取点逻辑,改为递归收集子区下属路口坐标计算平均经纬度,根据路口数量自适应缩放级别移动地图居中

画安 2 週間 前
コミット
c25913d9c1
共有2 個のファイルを変更した34 個の追加14 個の削除を含む
  1. 17 7
      src/views/SpecialSituationMonitoring.vue
  2. 17 7
      src/views/TrunkCoordination.vue

+ 17 - 7
src/views/SpecialSituationMonitoring.vue

@@ -295,15 +295,25 @@ export default {
             this.crossingSelections = [];
             this.showTopChartDalogs(); // 根据当前Tab显示对应的顶部常驻图表
         },
-        // 处理菜单folder标题点击
+        // 处理菜单folder标题点击:计算子区路口中心坐标,移动地图
         handleFolderClick(nodeData) {
             console.log('父组件接收到了文件夹点击事件:', nodeData);
-            // 临时逻辑,有真实接口后可以删除
-            const index = Math.floor(Math.random() * 10);
-            const position = localStorage.getItem(`pos${index + 1}`).split(',');
-
-            // 地图联动
-            this.$refs.trafficMapRef.focusByLocation([Number(position[0]), Number(position[1])]);
+            const leaves = [];
+            const collect = (nodes) => {
+                if (!Array.isArray(nodes)) return;
+                for (const n of nodes) {
+                    if (n.children) collect(n.children);
+                    else if (n.lng && n.lat) leaves.push(n);
+                }
+            };
+            collect(nodeData.children || []);
+            if (leaves.length === 0 || !this.$refs.trafficMapRef) return;
+
+            const avgLng = leaves.reduce((s, n) => s + n.lng, 0) / leaves.length;
+            const avgLat = leaves.reduce((s, n) => s + n.lat, 0) / leaves.length;
+            const zoom = leaves.length <= 6 ? 15 : 14;
+            const map = this.$refs.trafficMapRef.map;
+            if (map) map.setZoomAndCenter(zoom, [avgLng, avgLat], false, 500);
         },
         // 处理菜单点击
         handleMenuClick(nodeData) {

+ 17 - 7
src/views/TrunkCoordination.vue

@@ -295,15 +295,25 @@ export default {
             this.crossingSelections = [];
             this.showTopChartDalogs(); // 根据当前Tab显示对应的顶部常驻图表
         },
-        // 处理菜单folder标题点击
+        // 处理菜单folder标题点击:计算子区路口中心坐标,移动地图
         handleFolderClick(nodeData) {
             console.log('父组件接收到了文件夹点击事件:', nodeData);
-            // 临时逻辑,有真实接口后可以删除
-            const index = Math.floor(Math.random() * 10);
-            const position = localStorage.getItem(`pos${index + 1}`).split(',');
-
-            // 地图联动
-            this.$refs.trafficMapRef.focusByLocation([Number(position[0]), Number(position[1])]);
+            const leaves = [];
+            const collect = (nodes) => {
+                if (!Array.isArray(nodes)) return;
+                for (const n of nodes) {
+                    if (n.children) collect(n.children);
+                    else if (n.lng && n.lat) leaves.push(n);
+                }
+            };
+            collect(nodeData.children || []);
+            if (leaves.length === 0 || !this.$refs.trafficMapRef) return;
+
+            const avgLng = leaves.reduce((s, n) => s + n.lng, 0) / leaves.length;
+            const avgLat = leaves.reduce((s, n) => s + n.lat, 0) / leaves.length;
+            const zoom = leaves.length <= 6 ? 15 : 14;
+            const map = this.$refs.trafficMapRef.map;
+            if (map) map.setZoomAndCenter(zoom, [avgLng, avgLat], false, 500);
         },
         // 处理菜单点击
         handleMenuClick(nodeData) {