Bladeren bron

优化地图缩放和菜单点击性能,删除交管局菜单数据

  - zoomchange改为zoomend,避免缩放动画期间连续触发CSS变量更新导致卡顿
  - 新增markerById索引,创建标记时自动注册id映射,focusById从线性遍历改为O(1)查找
  - 删除tongzhouMenuTree中交管局(area_jgj)节点及其子节点
画安 1 week geleden
bovenliggende
commit
041695ff29
2 gewijzigde bestanden met toevoegingen van 9 en 1156 verwijderingen
  1. 9 16
      src/components/TongzhouTrafficMap.vue
  2. 0 1140
      src/mock/mock_data.json

+ 9 - 16
src/components/TongzhouTrafficMap.vue

@@ -85,6 +85,7 @@ export default {
       intersectionData: [],
       statusIntersections: {},
       currentZoomSize: 14, // 保存当前的动态尺寸
+      markerById: {}, // ID → marker 索引,加速 focusById 查找
     };
   },
   mounted() {
@@ -313,7 +314,7 @@ export default {
           }
         });
 
-        this.map.on('zoomchange', () => {
+        this.map.on('zoomend', () => {
           if (!this.isComponentDestroyed) {
             this.currentZoomSize = this.getDotSizeByZoom();
           }
@@ -1010,6 +1011,10 @@ export default {
           }
         });
 
+        // 建立 ID 索引
+        if (config.id) this.markerById[config.id] = marker;
+        if (config['路口编号']) this.markerById[config['路口编号']] = marker;
+
         marker.on('click', (e) => {
           if (this.isComponentDestroyed) return;
           const extData = e.target.getExtData();
@@ -1288,21 +1293,9 @@ export default {
     focusById(id) {
       if (!this.isMapReady() || !id) return null;
 
-      let bestMarker = null;
-      Object.values(this.routeGroups).forEach(group => {
-        if (!Array.isArray(group) || bestMarker) return;
-        group.forEach(item => {
-          if (bestMarker) return;
-          if (!(item instanceof this.AMap.Marker)) return;
-          const ext = item.getExtData();
-          if (ext.id === id || ext['路口编号'] === id) {
-            bestMarker = item;
-          }
-        });
-      });
-
-      if (bestMarker) {
-        const finalPos = bestMarker.getPosition();
+      const marker = this.markerById[id];
+      if (marker) {
+        const finalPos = marker.getPosition();
         this.map.setZoomAndCenter(17, finalPos, false, 500);
         return finalPos;
       }

File diff suppressed because it is too large
+ 0 - 1140
src/mock/mock_data.json