|
|
@@ -301,15 +301,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) {
|