Kaynağa Gözat

修复bug。补充连续操作的需求

xushiting 2 yıl önce
ebeveyn
işleme
266992caf0

+ 0 - 1
src/graphic/Controls/AddPoint.js

@@ -37,7 +37,6 @@ export default class AddPoint {
       newPoint.linkedTextId = textVector.vectorId;
       textVector.linkedPointId = newPoint.vectorId;
     }
-    uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
     listenLayer.clear();
     return newPoint;
   }

+ 8 - 4
src/graphic/Controls/MovePoint.js

@@ -21,10 +21,14 @@ export default class MovePoint {
       point.x = position.x;
       point.y = position.y;
       let parent = point.getParent();
-      let line = dataService.getLine(Object.keys(parent)[0]);
-      if (line.getCategory() == VectorCategory.Line.BaseLine) {
-        if (uiService.getSelectLocationMode() == Constant.angleLocationMode) {
-          locationModeControl.setAngle();
+      for (let key in parent) {
+        let line = dataService.getLine(key);
+        if (line.getCategory() == VectorCategory.Line.BaseLine) {
+          if (uiService.getSelectLocationMode() == Constant.angleLocationMode) {
+            locationModeControl.setAngle();
+          }
+        } else {
+          line.setValue(null);
         }
       }
     }

+ 19 - 11
src/graphic/Controls/UIControl.js

@@ -72,10 +72,22 @@ export default class UIControl {
   }
 
   clearUI() {
-    this.currentUI = null;
+    this.clearCurrentUI();
+    this.clearSelectUI();
+  }
+
+  clearFocusVector() {
+    this.focusVector = null;
+  }
+
+  clearSelectUI() {
     this.selectUI = null;
   }
 
+  clearCurrentUI() {
+    this.currentUI = null;
+  }
+
   //点击左侧栏后,更新事件
   updateEventNameForSelectUI(selectUI) {
     console.log(this.selectUI, selectUI);
@@ -409,7 +421,7 @@ export default class UIControl {
     this.layer.exit();
     uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
     uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
-    this.focusVector = null;
+    this.clearFocusVector();
   }
 
   //复制按钮
@@ -592,26 +604,22 @@ export default class UIControl {
   }
   confirmEntry() {
     console.log("确认");
-    Settings.selectLocationMode = null;
     this.graphicStateUI.continuedMode = false;
     this.layer.exit();
-    uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
-    uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
-    addPoint.resetTestPoints(); //重置testPoints数组
     this.layer.history.save();
     this.layer.renderer.autoRedraw();
+    uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
+    uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
   }
   confirmCancel() {
     console.log("取消");
-    Settings.selectLocationMode = null;
     this.graphicStateUI.continuedMode = false;
-    addPoint.deleteTestPoints();
-    addLine.deleteTestLines();
     this.layer.exit();
-    uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
-    uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
     this.layer.history.save();
+    this.layer.history.handleUndo();
     this.layer.renderer.autoRedraw();
+    uiService.setSelectPointCategory(VectorCategory.Point.NormalPoint);
+    uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
   }
 
   // 设置默认设置

+ 78 - 90
src/graphic/Layer.js

@@ -132,6 +132,9 @@ export default class Layer {
     listenLayer.start(position);
     let selectItem = stateService.getSelectItem();
     let focusItem = stateService.getFocusItem();
+    if (selectItem && focusItem && selectItem.vectorId != focusItem.vectorId) {
+      stateService.clearFocusItem();
+    }
 
     this.setEventName("mouseDown");
     const eventName = stateService.getEventName();
@@ -161,7 +164,6 @@ export default class Layer {
             VectorType.Point,
             SelectState.Select
           );
-          this.history.save();
           this.renderer.autoRedraw();
         } else {
           if (Settings.basePointIds.length > 1) {
@@ -207,9 +209,11 @@ export default class Layer {
         addMagnifier.clear();
         break;
       case VectorEvents.AddLane:
+        let selectAddLaneFlag = false;
         if (selectItem && selectItem.dir && selectItem.vectorId) {
           let road = dataService.getRoad(selectItem.vectorId);
           if (road) {
+            selectAddLaneFlag = true;
             let roadLanCount = road.getLanesCount(selectItem.dir);
             if (selectItem.dir == "left") {
               roadService.updateForAddSubtractLanesCount(
@@ -226,30 +230,37 @@ export default class Layer {
             }
           } else {
             road = dataService.getCurveRoad(selectItem.vectorId);
-            let curveRoadLanCount = road.getLanesCount(selectItem.dir);
-            if (selectItem.dir == "left") {
-              curveRoadService.updateForAddSubtractLanesCount(
-                road.vectorId,
-                curveRoadLanCount + 1,
-                selectItem.dir
-              );
-            } else {
-              curveRoadService.updateForAddSubtractLanesCount(
-                road.vectorId,
-                curveRoadLanCount + 1,
-                selectItem.dir
-              );
+            if (road) {
+              selectAddLaneFlag = true;
+              let curveRoadLanCount = road.getLanesCount(selectItem.dir);
+              if (selectItem.dir == "left") {
+                curveRoadService.updateForAddSubtractLanesCount(
+                  road.vectorId,
+                  curveRoadLanCount + 1,
+                  selectItem.dir
+                );
+              } else {
+                curveRoadService.updateForAddSubtractLanesCount(
+                  road.vectorId,
+                  curveRoadLanCount + 1,
+                  selectItem.dir
+                );
+              }
             }
           }
-          stateService.clearEventName();
           this.history.save();
           this.renderer.autoRedraw();
         }
+        if (!selectAddLaneFlag) {
+          stateService.clearEventName();
+        }
         break;
       case VectorEvents.DelLane:
+        let selectDelLaneFlag = false;
         if (selectItem && selectItem.dir && selectItem.vectorId) {
           let road = dataService.getRoad(selectItem.vectorId);
           if (road) {
+            selectDelLaneFlag = true;
             let roadLanCount = road.getLanesCount(selectItem.dir);
             if (selectItem.dir == "left") {
               roadService.updateForAddSubtractLanesCount(
@@ -266,25 +277,30 @@ export default class Layer {
             }
           } else {
             road = dataService.getCurveRoad(selectItem.vectorId);
-            let curveRoadLanCount = road.getLanesCount(selectItem.dir);
-            if (selectItem.dir == "left") {
-              curveRoadService.updateForAddSubtractLanesCount(
-                road.vectorId,
-                curveRoadLanCount - 1,
-                selectItem.dir
-              );
-            } else {
-              curveRoadService.updateForAddSubtractLanesCount(
-                road.vectorId,
-                curveRoadLanCount - 1,
-                selectItem.dir
-              );
+            if (road) {
+              selectDelLaneFlag = true;
+              let curveRoadLanCount = road.getLanesCount(selectItem.dir);
+              if (selectItem.dir == "left") {
+                curveRoadService.updateForAddSubtractLanesCount(
+                  road.vectorId,
+                  curveRoadLanCount - 1,
+                  selectItem.dir
+                );
+              } else {
+                curveRoadService.updateForAddSubtractLanesCount(
+                  road.vectorId,
+                  curveRoadLanCount - 1,
+                  selectItem.dir
+                );
+              }
             }
           }
-          stateService.clearEventName();
           this.history.save();
           this.renderer.autoRedraw();
         }
+        if (!selectDelLaneFlag) {
+          stateService.clearEventName();
+        }
         break;
       case VectorEvents.AddCrossPoint:
         if (focusItem && focusItem.vectorId) {
@@ -373,7 +389,14 @@ export default class Layer {
     selectItem = stateService.getSelectItem();
     stateService.setDraggingItem(selectItem);
     stateService.clearFocusItem();
-    this.uiControl.focusVector = null;
+    if (
+      selectItem &&
+      selectItem.vectorId == this.uiControl.focusVector.vectorId
+    ) {
+    } else {
+      this.uiControl.clearFocusVector();
+    }
+
     // 清除上一个状态
     // 设置当前事件名称
     e.preventDefault();
@@ -454,7 +477,7 @@ export default class Layer {
         ) {
         } else {
           stateService.clearFocusItem();
-          this.uiControl.focusVector = null;
+          this.uiControl.clearFocusVector();
         }
       }
     }
@@ -994,7 +1017,7 @@ export default class Layer {
       this.uiControl.focusVector = focusItem;
       stateService.clearDraggingItem();
     } else {
-      this.uiControl.focusVector = null;
+      this.uiControl.clearFocusVector();
     }
     this.dragging = false;
     let position = coordinate.getXYFromScreen({
@@ -1007,15 +1030,15 @@ export default class Layer {
         if (e instanceof TouchEvent) {
           stateService.clearSelectItem();
           stateService.clearDraggingItem();
-          this.uiControl.focusVector = null;
+          this.uiControl.clearFocusVector();
           this.renderer.autoRedraw();
         }
         return;
       case LayerEvents.PanBackGround:
         needAutoRedraw = true;
         stateService.clearFocusItem();
-        this.uiControl.focusVector = null;
-        this.uiControl.currentUI = null;
+        this.uiControl.clearFocusVector();
+        this.uiControl.clearCurrentUI();
         Settings.selectBasePointId = null;
         break;
       case LayerEvents.MoveRoadPoint:
@@ -1082,22 +1105,20 @@ export default class Layer {
         needAutoRedraw = true;
         if (addRoad.canAdd) {
           addRoad.buildRoad();
-          this.history.save();
           elementService.hideAll();
         }
         break;
       case LayerEvents.AddingLine:
-        if (Settings.selectLocationMode == Constant.freeLocationMode) {
-          this.uiControl.showConfirm();
-        }
-
         needAutoRedraw = true;
         addLine.finish(position);
         this.updateForLocation();
+        //绘制的是基准线
+        if (Settings.baseLineId == addLine.newLine.vectorId) {
+          stateService.clearEventName();
+          this.history.save();
+        }
         addLine.clearVectorData();
-        this.history.save();
         elementService.hideAll();
-
         break;
       case LayerEvents.AddingCurveLine:
         needAutoRedraw = true;
@@ -1147,7 +1168,6 @@ export default class Layer {
         needAutoRedraw = true;
         if (addRoad.canAdd) {
           addRoad.buildCurveRoad();
-          this.history.save();
           elementService.hideAll();
         }
         break;
@@ -1207,7 +1227,6 @@ export default class Layer {
         }
         this.history.save();
         elementService.hideAll();
-
         break;
       case LayerEvents.MoveCurvePoint:
         needAutoRedraw = true;
@@ -1241,17 +1260,9 @@ export default class Layer {
         this.history.save();
         break;
       case LayerEvents.AddPoint:
-        if (
-          (Settings.selectBasePointId != null &&
-            (Settings.selectLocationMode == Constant.angleLocationMode ||
-              Settings.selectLocationMode == Constant.allLocationMode)) ||
-          (Settings.baseLineId != null &&
-            Settings.selectLocationMode == Constant.normalLocationMode)
-        ) {
-          this.uiControl.showConfirm();
-          needAutoRedraw = true;
-          elementService.hideAll();
-        }
+        this.uiControl.showConfirm();
+        needAutoRedraw = true;
+        elementService.hideAll();
         break;
       case LayerEvents.AddRoadTemplate:
         addCrossRoad.build(position);
@@ -1259,9 +1270,9 @@ export default class Layer {
         this.renderer.autoRedraw();
         break;
     }
-
     this.setEventName("mouseUp");
     stateService.clearDraggingItem();
+    stateService.clearSelectItem();
     if (needAutoRedraw) {
       this.renderer.autoRedraw();
     }
@@ -1350,42 +1361,19 @@ export default class Layer {
       }
     } else if (eventType == "mouseUp") {
       if (eventName == LayerEvents.AddingRoad) {
-        if (Settings.isMobile) {
-          stateService.clearEventName();
-          this.exit();
-        } else {
-          stateService.setEventName(LayerEvents.AddRoad);
-        }
+        this.uiControl.showConfirm();
+        stateService.setEventName(LayerEvents.AddRoad);
       } else if (eventName == LayerEvents.AddingLine) {
-        if (Settings.isMobile) {
-          if (Settings.selectLocationMode == Constant.freeLocationMode) {
-            stateService.setEventName(LayerEvents.AddLine);
-          } else {
-            stateService.clearEventName();
-            this.exit();
-            uiService.setSelectLineCategory(VectorCategory.Line.NormalLine);
-          }
-        } else {
-          stateService.setEventName(LayerEvents.AddLine);
-        }
+        this.uiControl.showConfirm();
+        stateService.setEventName(LayerEvents.AddLine);
       } else if (eventName == LayerEvents.AddingCurveRoad) {
-        if (Settings.isMobile) {
-          stateService.clearEventName();
-          this.exit();
-        } else {
-          stateService.setEventName(LayerEvents.AddCurveRoad);
-        }
+        this.uiControl.showConfirm();
+        stateService.setEventName(LayerEvents.AddCurveRoad);
       } else if (eventName == LayerEvents.AddLine) {
         stateService.setEventName(LayerEvents.AddingLine);
-      } else if (
-        (eventName == LayerEvents.AddPoint &&
-          Settings.selectBasePointId != null &&
-          (Settings.selectLocationMode == Constant.angleLocationMode ||
-            Settings.selectLocationMode == Constant.allLocationMode)) ||
-        (eventName == LayerEvents.AddPoint &&
-          Settings.baseLineId != null &&
-          Settings.selectLocationMode == Constant.normalLocationMode)
-      ) {
+      } else if (eventName == LayerEvents.AddPoint) {
+      } else if (eventName == VectorEvents.AddLane) {
+      } else if (eventName == VectorEvents.DelLane) {
       } else {
         stateService.clearEventName();
       }
@@ -1395,8 +1383,8 @@ export default class Layer {
   exit() {
     stateService.clear();
     this.uiControl.clearUI();
-    this.uiControl.focusVector = null;
-    this.uiControl.currentUI = null;
+    this.uiControl.clearFocusVector();
+    this.uiControl.clearCurrentUI();
   }
 
   stopAddVector() {

+ 13 - 26
src/graphic/ListenLayer.js

@@ -638,19 +638,6 @@ export default class ListenLayer {
       let rightLine = mathUtil.createLine1(rightEdge.start, rightEdge.end);
       let rightJoin = mathUtil.getJoinLinePoint(position, rightLine);
 
-      // let distance = this.getDistance(position, join);
-      // if (
-      //   mathUtil.isContainForSegment(join, startPoint, endPoint) &&
-      //   distance < Constant.minAdsorbPix
-      // ) {
-      //   if (!roadInfo.roadId || distance < roadInfo.distance) {
-      //     roadInfo = {
-      //       roadId: roadId,
-      //       type: VectorType.Road,
-      //       distance: distance,
-      //     };
-      //   }
-      // }
       let distance = this.getDistance(position, join);
       if (
         mathUtil.isContainForSegment(join, startPoint, endPoint) &&
@@ -664,6 +651,19 @@ export default class ListenLayer {
             distance: distance,
           };
         }
+
+        if (roadInfo.roadId) {
+          const join1 = mathUtil.getJoinLinePoint(position, leftLine);
+          const join2 = mathUtil.getJoinLinePoint(position, rightLine);
+          if (
+            mathUtil.getDistance(join1, position) >
+            mathUtil.getDistance(join2, position)
+          ) {
+            roadInfo.dir = "right";
+          } else {
+            roadInfo.dir = "left";
+          }
+        }
       }
 
       //检查edge
@@ -700,19 +700,6 @@ export default class ListenLayer {
           };
         }
       }
-
-      if (roadInfo.roadId && !edgeInfo.edgeId) {
-        const join1 = mathUtil.getJoinLinePoint(position, leftLine);
-        const join2 = mathUtil.getJoinLinePoint(position, rightLine);
-        if (
-          mathUtil.getDistance(join1, position) >
-          mathUtil.getDistance(join2, position)
-        ) {
-          roadInfo.dir = "right";
-        } else {
-          roadInfo.dir = "left";
-        }
-      }
     }
 
     if (

+ 10 - 19
src/graphic/Service/StateService.js

@@ -1,7 +1,7 @@
-import VectorType from '../enum/VectorType.js';
-import SelectState from '../enum/SelectState.js';
-import VectorCategory from '../enum/VectorCategory.js';
-import { dataService } from './DataService.js';
+import VectorType from "../enum/VectorType.js";
+import SelectState from "../enum/SelectState.js";
+import VectorCategory from "../enum/VectorCategory.js";
+import { dataService } from "./DataService.js";
 
 export default class StateService {
   constructor() {
@@ -38,7 +38,7 @@ export default class StateService {
       const point = dataService.getPoint(vectorId);
       this.selectItem.category = point.getCategory();
     }
-    console.log('选中的元素:' + JSON.stringify(this.selectItem));
+    console.log("选中的元素:" + JSON.stringify(this.selectItem));
   }
   setSelectState(state) {
     if (!state || !this.selectItem) {
@@ -65,8 +65,8 @@ export default class StateService {
       return;
     } else if (this.draggingItem.type == VectorType.Line) {
       const line = dataService.getLine(this.draggingItem.vectorId);
-      if(!line){
-        return 
+      if (!line) {
+        return;
       }
       this.draggingItem.category = line.getCategory();
     } else if (this.draggingItem.type == VectorType.Point) {
@@ -84,18 +84,9 @@ export default class StateService {
   }
 
   setFocusItem(focusItem) {
-    this.focusItem = focusItem;
-    if (this.focusItem == null) {
-      return;
-    } else if (this.focusItem.type == VectorType.Line) {
-      const line = dataService.getLine(this.focusItem.vectorId);
-      if(!line){
-        return
-      }
-      this.focusItem.category = line.getCategory();
-    } else if (this.focusItem.type == VectorType.Point) {
-      const point = dataService.getPoint(this.focusItem.vectorId);
-      this.focusItem.category = point.getCategory();
+    this.focusItem = {};
+    for (let key in focusItem) {
+      this.focusItem[key] = focusItem[key];
     }
   }