浏览代码

修复bug

xushiting 2 年之前
父节点
当前提交
296b4379ea

+ 1 - 1
src/graphic/History/HistoryUtil.js

@@ -948,7 +948,7 @@ export default class HistoryUtil {
     curveRoad.rightEdgeId = curveRoadInfo.rightEdgeId;
     for (let i = 0; i < curveRoadInfo.points.length; ++i) {
       curveRoad.points[i] = dataService.getCurveRoadPoint(
-        curveRoadInfo.points[i]
+        curveRoadInfo.points[i].vectorId
       );
     }
     //curveRoad.points = JSON.parse(JSON.stringify(curveRoadInfo.points));

+ 0 - 174
src/graphic/Layer.js

@@ -91,7 +91,6 @@ export default class Layer {
     this.canvas.addEventListener("mousewheel", this.onWheel.bind(this));
     this.canvas.addEventListener("DOMMouseScroll", this.onWheel.bind(this));
     this.canvas.addEventListener("resize", this.reSize.bind(this));
-    document.addEventListener("keydown", this.onKeydown.bind(this));
   }
 
   reSize = function () {
@@ -1238,179 +1237,6 @@ export default class Layer {
     }
   }
 
-  //测试用
-  onKeydown(e) {
-    let focusItem = stateService.getFocusItem();
-    let dir = "left";
-    if (focusItem) {
-      console.log("键盘(foucus有效):" + e.code);
-      if (e.code == "Delete") {
-        //删除
-        const road = dataService.getRoad(focusItem.vectorId);
-        roadService.subtraRoadFromIntersect(road.startId, focusItem.vectorId);
-        roadService.subtraRoadFromIntersect(road.endId, focusItem.vectorId);
-        //dataService.deleteCrossPoint()
-        dataService.deleteRoad(focusItem.vectorId);
-        this.renderer.autoRedraw();
-        this.history.save();
-      }
-      //加宽
-      else if (e.code == "KeyA") {
-        let road = dataService.getRoad(focusItem.vectorId);
-        if (road) {
-          roadService.updateForWidth(road.vectorId, road.leftWidth + 50, dir);
-        } else {
-          road = dataService.getCurveRoad(focusItem.vectorId);
-          curveRoadService.updateForWidth(
-            road.vectorId,
-            road.leftWidth + 50,
-            dir
-          );
-        }
-
-        this.renderer.autoRedraw();
-        this.history.save();
-      }
-      //变窄
-      else if (e.code == "KeyB") {
-        let road = dataService.getRoad(focusItem.vectorId);
-        if (road) {
-          roadService.updateForWidth(road.vectorId, road.leftWidth - 25, dir);
-        } else {
-          road = dataService.getCurveRoad(focusItem.vectorId);
-          curveRoadService.updateForWidth(
-            road.vectorId,
-            road.leftWidth - 25,
-            dir
-          );
-        }
-        this.renderer.autoRedraw();
-        this.history.save();
-      }
-      //添加左车道
-      else if (e.code == "KeyQ") {
-        let road = dataService.getRoad(focusItem.vectorId);
-        if (road) {
-          roadService.updateForAddSubtractLanesCount(
-            focusItem.vectorId,
-            road.leftDrivewayCount + 1,
-            "left"
-          );
-        } else {
-          road = dataService.getCurveRoad(focusItem.vectorId);
-          curveRoadService.updateForAddSubtractLanesCount(
-            road,
-            road.leftDrivewayCount + 1, //rightDrivewayCount
-            "left"
-          );
-        }
-        this.renderer.autoRedraw();
-        this.history.save();
-      }
-      //减少左车道
-      else if (e.code == "KeyW") {
-        let road = dataService.getRoad(focusItem.vectorId);
-        if (road) {
-          roadService.updateForAddSubtractLanesCount(
-            focusItem.vectorId,
-            road.leftDrivewayCount - 1,
-            "left"
-          );
-        } else {
-          road = dataService.getCurveRoad(focusItem.vectorId);
-          curveRoadService.updateForAddSubtractLanesCount(
-            road,
-            road.leftDrivewayCount - 1, //rightDrivewayCount
-            "left"
-          );
-        }
-        this.renderer.autoRedraw();
-        this.history.save();
-      }
-      //添加右车道
-      else if (e.code == "KeyE") {
-        let road = dataService.getRoad(focusItem.vectorId);
-        if (road) {
-          roadService.updateForAddSubtractLanesCount(
-            focusItem.vectorId,
-            road.rightDrivewayCount + 1,
-            "right"
-          );
-        } else {
-          road = dataService.getCurveRoad(focusItem.vectorId);
-          curveRoadService.updateForAddSubtractLanesCount(
-            road,
-            road.rightDrivewayCount + 1, //rightDrivewayCount
-            "right"
-          );
-        }
-        this.renderer.autoRedraw();
-        this.history.save();
-      }
-      //减少右车道
-      else if (e.code == "KeyR") {
-        let road = dataService.getRoad(focusItem.vectorId);
-        if (road) {
-          roadService.updateForAddSubtractLanesCount(
-            focusItem.vectorId,
-            road.rightDrivewayCount - 1,
-            "right"
-          );
-        } else {
-          road = dataService.getCurveRoad(focusItem.vectorId);
-          curveRoadService.updateForAddSubtractLanesCount(
-            road,
-            road.rightDrivewayCount - 1, //rightDrivewayCount
-            "right"
-          );
-        }
-        this.renderer.autoRedraw();
-        this.history.save();
-      }
-      //弯路添加控制点
-      else if (e.code == "KeyT") {
-        const curveRoad = dataService.getCurveRoad(focusItem.vectorId);
-        let index = mathUtil.getIndexForCurvesPoints(
-          this.mousePosition,
-          curveRoad.points
-        );
-        if (index != -1) {
-          curveRoadService.addCPoint(curveRoad, this.mousePosition, index);
-        } else {
-          const dis1 = mathUtil.getDistance(
-            curveRoad.points[0],
-            this.mousePosition
-          );
-          const dis2 = mathUtil.getDistance(
-            curveRoad.points[curveRoad.points.length - 1],
-            this.mousePosition
-          );
-          if (dis1 > dis2) {
-            curveRoadService.addCPoint(
-              curveRoad,
-              this.mousePosition,
-              curveRoad.points.length - 2
-            );
-          } else {
-            curveRoadService.addCPoint(curveRoad, this.mousePosition, 1);
-          }
-        }
-        this.renderer.autoRedraw();
-        this.history.save();
-      }
-      //弯路删除控制点
-      else if (e.code == "KeyY") {
-        const curvePoint = dataService.getCurveRoadPoint(focusItem.vectorId);
-        const curveRoad = dataService.getCurveRoad(curvePoint.parent);
-        curveRoadService.subCPoint(curveRoad, curvePoint.getIndex());
-        this.renderer.autoRedraw();
-        this.history.save();
-      }
-    } else {
-      console.log("键盘(foucus无效):" + e.code);
-    }
-  }
-
   setEventName(eventType) {
     let eventName = stateService.getEventName();
 

+ 30 - 23
src/graphic/ListenLayer.js

@@ -227,11 +227,11 @@ export default class ListenLayer {
         continue;
       }
       const point = dataService.getPoint(pointId);
-  
+
       if (point.getCategory() == VectorCategory.Point.TestBasePoint) {
         continue;
       }
-   
+
       const distance = this.getDistance(position, point);
       if (distance < Constant.minAdsorbPix) {
         if (pointInfo.pointId == null) {
@@ -267,8 +267,8 @@ export default class ListenLayer {
       pointInfo.x = linkedPoint.x;
       pointInfo.y = linkedPoint.y;
       //判断当时基准点则要高亮
-      if(linkedPoint.getCategory() ==VectorCategory.Point.BasePoint ){
-        Settings.selectBasePointId = linkedPoint.vectorId
+      if (linkedPoint.getCategory() == VectorCategory.Point.BasePoint) {
+        Settings.selectBasePointId = linkedPoint.vectorId;
       }
     } else {
       if (seqInfo.hasOwnProperty("linkedPointIdX")) {
@@ -287,7 +287,6 @@ export default class ListenLayer {
       }
     }
 
-
     return pointInfo;
   }
 
@@ -730,16 +729,7 @@ export default class ListenLayer {
         curveRoad.curves,
         Constant.minAdsorbPix
       );
-      //选中了路
-      if (joinInfo.distance < Constant.minAdsorbPix) {
-        curveRoadInfo = {
-          curveRoadId: curveRoadId,
-          type: VectorType.CurveRoad,
-          distance: joinInfo.distance,
-          x: joinInfo.position.x,
-          y: joinInfo.position.y,
-        };
-      }
+
       //检查edge
       const leftCurveEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
       const leftJoinInfo = this.distanceForBezier(
@@ -756,15 +746,32 @@ export default class ListenLayer {
         rightCurveEdge.curves,
         Constant.minAdsorbPix
       );
-      if (curveRoadInfo.curveRoadId) {
-        if (
-          mathUtil.getDistance(position, leftJoinInfo.position) >
-          mathUtil.getDistance(position, rightJoinInfo.position)
-        ) {
-          curveRoadInfo.dir = "right";
-        } else {
-          curveRoadInfo.dir = "left";
+
+      if (
+        mathUtil.getDistance(position, leftJoinInfo.position) >
+        mathUtil.getDistance(position, rightJoinInfo.position)
+      ) {
+        if (joinInfo.distance < curveRoad.rightWidth) {
+          curveRoadInfo = {
+            curveRoadId: curveRoadId,
+            type: VectorType.CurveRoad,
+            distance: joinInfo.distance,
+            x: joinInfo.position.x,
+            y: joinInfo.position.y,
+          };
+        }
+        curveRoadInfo.dir = "right";
+      } else {
+        if (joinInfo.distance < curveRoad.leftWidth) {
+          curveRoadInfo = {
+            curveRoadId: curveRoadId,
+            type: VectorType.CurveRoad,
+            distance: joinInfo.distance,
+            x: joinInfo.position.x,
+            y: joinInfo.position.y,
+          };
         }
+        curveRoadInfo.dir = "left";
       }
 
       if (leftJoinInfo.distance < Constant.minAdsorbPix) {

+ 6 - 5
src/graphic/Service/CurveRoadService.js

@@ -459,12 +459,13 @@ export default class CurveRoadService extends RoadService {
   }
 
   //删除或者减少车道
-  updateForAddSubtractLanesCount(curveRoad, newCount, dir) {
+  updateForAddSubtractLanesCount(curveRoadId, newCount, dir) {
+    let curveRoad = dataService.getCurveRoad(curveRoadId);
     let curveEdge, oldCount, lanes;
     const leftCurveEdge = dataService.getCurveRoadEdge(curveRoad.leftEdgeId);
     const rightCurveEdge = dataService.getCurveRoadEdge(curveRoad.rightEdgeId);
-    if (newCount < 0) {
-      newCount = 0;
+    if (newCount < 1) {
+      return;
     }
 
     let ratio = null;
@@ -584,10 +585,10 @@ export default class CurveRoadService extends RoadService {
   //多车道转单车道
   mulToSinglelane(curveRoad) {
     if (curveRoad.leftDrivewayCount > 0) {
-      this.updateForAddSubtractLanesCount(curveRoad, 1, "left");
+      this.updateForAddSubtractLanesCount(curveRoad.vectorId, 1, "left");
     }
     if (curveRoad.rightDrivewayCount > 0) {
-      this.updateForAddSubtractLanesCount(curveRoad, 1, "right");
+      this.updateForAddSubtractLanesCount(curveRoad.vectorId, 1, "right");
     }
     curveRoad.leftDrivewayCount = 0;
     curveRoad.rightDrivewayCount = 0;

+ 6 - 6
src/graphic/Service/DataService.js

@@ -30,8 +30,8 @@ export class DataService {
 
   initGrid() {
     this.grid = {
-      defalutstep1: 50 * coordinate.ratio,
-      defalutstep2: 250 * coordinate.ratio,
+      defalutstep1: 25 * coordinate.ratio,
+      defalutstep2: 125 * coordinate.ratio,
       display: true,
     };
     this.grid.start = JSON.parse(JSON.stringify(coordinate.center));
@@ -134,11 +134,11 @@ export class DataService {
 
   deleteLine(lineId) {
     let line = this.getLine(lineId);
-    if(!line){
-      return
+    if (!line) {
+      return;
     }
     let start = this.getPoint(line.startId);
-    if (start  && start.getCategory()!= VectorCategory.Point.BasePoint) {
+    if (start && start.getCategory() != VectorCategory.Point.BasePoint) {
       let startParent = start.getParent();
       delete startParent[lineId];
       if (
@@ -153,7 +153,7 @@ export class DataService {
     if (end) {
       let endParent = end.getParent();
       delete endParent[lineId];
-      
+
       if (
         Object.keys(endParent).length == 0 &&
         end.getCategory() != VectorCategory.Point.BasePoint

+ 2 - 2
src/graphic/Service/RoadService.js

@@ -1264,8 +1264,8 @@ export default class RoadService {
       middy2;
     let road = dataService.getRoad(roadId);
 
-    if (newCount < 0) {
-      newCount = 0;
+    if (newCount < 1) {
+      return;
     }
 
     let startPoint = dataService.getRoadPoint(road.startId);