Selaa lähdekoodia

继续搭建绘图程序

xushiting 2 vuotta sitten
vanhempi
commit
50bc30cf3e

+ 1 - 1
src/graphic/Controls/MoveRoad.js

@@ -1044,7 +1044,7 @@ export default class MoveRoad {
     for (const roadId1 in parent1) {
       const road1 = dataService.getRoad(roadId1);
       const otherPointId = road1.getOtherPointId(pointId1);
-      const _roadId = dataService.getRoadId(otherPointId, pointId2);
+      const _roadId = roadService.getRoadId(otherPointId, pointId2);
       if (_roadId != null) {
         return false;
       }

+ 1 - 1
src/graphic/Layer.js

@@ -331,7 +331,7 @@ export default class Layer {
             stateService.setSelectItem(
               tag.vectorId,
               VectorType.Tag,
-              SelectState.All
+              SelectState.Select
             );
             stateService.setDraggingItem(stateService.selectItem);
           }

+ 265 - 126
src/graphic/ListenLayer.js

@@ -57,17 +57,24 @@ export default class ListenLayer {
     exceptCurveRoadId
   ) {
     let isSame = false;
-    this.modifyPoint = null;
+    this.clear();
     let curveRoadInfo = this.isSelectCurveRoad(position, exceptCurveRoadId);
     let roadInfo = this.isSelectRoad(position, exceptRoadIds);
     let curvePointInfo = this.isSelectCurvePoint(position, exceptCurvePointId);
     let pointInfo = this.isSelectPoint(position, exceptPointId);
-
-    let flag1 = this.equalAndClone(this.curveRoadInfo, curveRoadInfo);
-    let flag2 = this.equalAndClone(this.roadInfo, roadInfo);
-    let flag3 = this.equalAndClone(this.curvePointInfo, curvePointInfo);
-    let flag4 = this.equalAndClone(this.pointInfo, pointInfo);
-    isSame = this.updateSelectItem(flag1, flag2, flag3, flag4);
+    this.setModifyPoint(
+      position,
+      pointInfo,
+      curvePointInfo,
+      roadInfo,
+      curveRoadInfo
+    );
+    // let flag1 = this.equalAndClone(this.curveRoadInfo, curveRoadInfo);
+    // let flag2 = this.equalAndClone(this.roadInfo, roadInfo);
+    // let flag3 = this.equalAndClone(this.curvePointInfo, curvePointInfo);
+    // let flag4 = this.equalAndClone(this.pointInfo, pointInfo);
+    // isSame = this.updateSelectItem(flag1, flag2, flag3, flag4);
+    isSame = this.updateSelectItem();
     return !isSame;
   }
 
@@ -75,7 +82,7 @@ export default class ListenLayer {
     let pointInfo = {
       pointId: null,
       type: null,
-      state: null,
+      distance: null,
     };
 
     let seqInfo = {};
@@ -85,50 +92,58 @@ export default class ListenLayer {
         continue;
       }
       const point = dataService.getPoint(pointId);
-      if (mathUtil.getDistance(position, point) < Constant.minAdsorbPix) {
+      const distance = mathUtil.getDistance(position, point);
+      if (distance < Constant.minAdsorbPix) {
         if (pointInfo.pointId == null) {
           pointInfo = {
             pointId: pointId,
             type: VectorType.Point,
-            state: SelectState.Select,
+            distance: distance,
           };
         } else if (pointInfo.pointId != null) {
-          let oldPoint = dataService.getPoint(pointInfo.pointId);
-          if (
-            mathUtil.getDistance(position, point) <
-            mathUtil.getDistance(position, oldPoint)
-          ) {
+          if (distance < pointInfo.distance) {
             pointInfo = {
               pointId: pointId,
               type: VectorType.Point,
-              state: SelectState.Select,
+              distance: distance,
             };
           }
         }
-      } else if (Math.abs(position.x - point.x) < Constant.minAdsorbPix) {
-        seqInfo.linkedPointIdX = pointId;
-        seqInfo.x = point.x;
-      } else if (Math.abs(position.y - point.y) < Constant.minAdsorbPix) {
-        seqInfo.linkedPointIdY = pointId;
-        seqInfo.y = point.y;
+      } else {
+        if (Math.abs(position.x - point.x) < Constant.minAdsorbPix) {
+          seqInfo.linkedPointIdX = pointId;
+          seqInfo.x = point.x;
+        } else if (Math.abs(position.y - point.y) < Constant.minAdsorbPix) {
+          seqInfo.linkedPointIdY = pointId;
+          seqInfo.y = point.y;
+        }
       }
     }
 
     if (pointInfo.pointId) {
-      this.modifyPoint = {};
-      this.modifyPoint.linkedPointId = pointInfo.pointId;
-      if (pointInfo.pointId) {
-        const linkedPoint = dataService.getPoint(pointInfo.pointId);
-        this.modifyPoint.x = linkedPoint.x;
-        this.modifyPoint.y = linkedPoint.y;
-      } else if (seqInfo.hasOwnProperty("linkedPointIdX")) {
-        this.modifyPoint.linkedPointIdX = seqInfo.linkedPointIdX;
-        this.modifyPoint.x = seqInfo.x;
-      } else if (seqInfo.hasOwnProperty("linkedPointIdY")) {
-        this.modifyPoint.linkedPointIdY = seqInfo.linkedPointIdY;
-        this.modifyPoint.y = seqInfo.y;
+      const linkedPoint = dataService.getPoint(pointInfo.pointId);
+      pointInfo.x = linkedPoint.x;
+      pointInfo.y = linkedPoint.y;
+    }
+    //因为这种纠正的权限最低
+    else {
+      if (seqInfo.hasOwnProperty("linkedPointIdX")) {
+        pointInfo.linkedPointIdX = seqInfo.linkedPointIdX;
+        pointInfo.x = seqInfo.x;
+      }
+      if (seqInfo.hasOwnProperty("linkedPointIdY")) {
+        pointInfo.linkedPointIdY = seqInfo.linkedPointIdY;
+        pointInfo.y = seqInfo.y;
+      }
+
+      if (pointInfo.hasOwnProperty("y") && !pointInfo.hasOwnProperty("x")) {
+        pointInfo.x = position.x;
+      }
+      if (pointInfo.hasOwnProperty("x") && !pointInfo.hasOwnProperty("y")) {
+        pointInfo.y = position.y;
       }
     }
+
     return pointInfo;
   }
 
@@ -136,7 +151,7 @@ export default class ListenLayer {
     let curvePointInfo = {
       curvePointId: null,
       type: null,
-      state: null,
+      distance: null,
     };
 
     let seqInfo = {};
@@ -146,52 +161,62 @@ export default class ListenLayer {
         continue;
       }
       const curvePoint = dataService.getCurvePoint(curvePointId);
-      if (mathUtil.getDistance(position, curvePoint) < Constant.minAdsorbPix) {
+      const distance = mathUtil.getDistance(position, curvePoint);
+      if (distance < Constant.minAdsorbPix) {
         if (curvePointInfo.curvePointId == null) {
           curvePointInfo = {
             curvePointId: curvePointId,
             type: VectorType.CurvePoint,
-            state: SelectState.Select,
+            distance: distance,
           };
         } else if (curvePointInfo.pointId != null) {
-          let oldCurvePoint = dataService.getCurvePoint(
-            curvePointInfo.curvePointId
-          );
-          if (
-            mathUtil.getDistance(position, curvePoint) <
-            mathUtil.getDistance(position, oldCurvePoint)
-          ) {
+          if (distance < curvePointInfo.distance) {
             curvePointInfo = {
               curvePointId: curvePointId,
               type: VectorType.CurvePoint,
-              state: SelectState.Select,
+              distance: distance,
             };
           }
         }
-      } else if (Math.abs(position.x - curvePoint.x) < Constant.minAdsorbPix) {
-        seqInfo.linkedPointIdX = curvePointId;
-        seqInfo.x = curvePoint.x;
-      } else if (Math.abs(position.y - curvePoint.y) < Constant.minAdsorbPix) {
-        seqInfo.linkedPointIdY = curvePointId;
-        seqInfo.y = curvePoint.y;
+      } else {
+        if (Math.abs(position.x - curvePoint.x) < Constant.minAdsorbPix) {
+          seqInfo.linkedPointIdX = curvePointId;
+          seqInfo.x = curvePoint.x;
+        } else if (
+          Math.abs(position.y - curvePoint.y) < Constant.minAdsorbPix
+        ) {
+          seqInfo.linkedPointIdY = curvePointId;
+          seqInfo.y = curvePoint.y;
+        }
       }
     }
 
     if (curvePointInfo.curvePointId) {
-      this.modifyPoint = {};
-      this.modifyPoint.linkedCurvePointId = curvePointInfo.curvePointId;
-      if (curvePointInfo.curvePointId) {
-        const linkedCurvePoint = dataService.getCurvePoint(
-          curvePointInfo.curvePointId
-        );
-        this.modifyPoint.x = linkedCurvePoint.x;
-        this.modifyPoint.y = linkedCurvePoint.y;
-      } else if (seqInfo.hasOwnProperty("linkedPointIdX")) {
-        this.modifyPoint.linkedPointIdX = seqInfo.linkedPointIdX;
-        this.modifyPoint.x = seqInfo.x;
+      curvePointInfo.linkedCurvePointId = curvePointInfo.curvePointId;
+      const linkedCurvePoint = dataService.getCurvePoint(
+        curvePointInfo.curvePointId
+      );
+      curvePointInfo.x = linkedCurvePoint.x;
+      curvePointInfo.y = linkedCurvePoint.y;
+    } else {
+      if (seqInfo.hasOwnProperty("linkedPointIdX")) {
+        curvePointInfo.linkedPointIdX = seqInfo.linkedPointIdX;
+        curvePointInfo.x = seqInfo.x;
       } else if (seqInfo.hasOwnProperty("linkedPointIdY")) {
-        this.modifyPoint.linkedPointIdY = seqInfo.linkedPointIdY;
-        this.modifyPoint.y = seqInfo.y;
+        curvePointInfo.linkedPointIdY = seqInfo.linkedPointIdY;
+        curvePointInfo.y = seqInfo.y;
+      }
+      if (
+        curvePointInfo.hasOwnProperty("y") &&
+        !curvePointInfo.hasOwnProperty("x")
+      ) {
+        curvePointInfo.x = position.x;
+      }
+      if (
+        curvePointInfo.hasOwnProperty("x") &&
+        !curvePointInfo.hasOwnProperty("y")
+      ) {
+        curvePointInfo.y = position.y;
       }
     }
     return curvePointInfo;
@@ -201,7 +226,7 @@ export default class ListenLayer {
     let roadInfo = {
       roadId: null,
       type: null,
-      state: null,
+      distance: null,
     };
     const roads = dataService.getRoads();
     for (const roadId in roads) {
@@ -209,27 +234,28 @@ export default class ListenLayer {
         continue;
       }
       const road = dataService.getRoad(roadId);
+      let startPoint = dataService.getPoint(road.startId);
+      let endPoint = dataService.getPoint(road.endId);
       const roadLine = roadService.getMidLine(road);
-      const distance = mathUtil.getDisForPoinLine(position, roadLine);
+      const join = mathUtil.getJoinLinePoint(position, roadLine);
+      const distance = mathUtil.getDistance(position, join);
 
-      if (distance < road.width / 2) {
+      if (
+        distance < road.width / 2 &&
+        mathUtil.isContainForSegment(join, startPoint, endPoint)
+      ) {
         if (roadInfo.roadId == null) {
           roadInfo = {
             roadId: roadId,
             type: VectorType.Road,
-            state: SelectState.Select,
+            distance: distance,
           };
-        } else if (roadInfo.pointId != null) {
-          let oldRoad = dataService.getRoad(roadInfo.roadId);
-          const oldRoadLine = roadService.getMidLine(oldRoad);
-          if (
-            mathUtil.getDisForPoinLine(position, roadLine) <
-            mathUtil.getDisForPoinLine(position, oldRoadLine)
-          ) {
+        } else if (roadInfo.roadId != null) {
+          if (distance < roadInfo.distance) {
             roadInfo = {
               roadId: roadId,
               type: VectorType.Road,
-              state: SelectState.Select,
+              distance: mathUtil.getDisForPoinLine(position, roadLine),
             };
           }
         }
@@ -237,16 +263,14 @@ export default class ListenLayer {
     }
 
     if (roadInfo.roadId) {
-      this.modifyPoint = {};
-      this.modifyPoint.linkedRoadId = roadInfo.roadId;
-      const linkedRoad = dataService.getRoad(this.modifyPoint.linkedRoadId);
+      const linkedRoad = dataService.getRoad(roadInfo.roadId);
       const linkedRoadLine = roadService.getMidLine(linkedRoad);
       const linkedPosition = mathUtil.getJoinLinePoint(
         position,
         linkedRoadLine
       );
-      this.modifyPoint.x = linkedPosition.x;
-      this.modifyPoint.y = linkedPosition.y;
+      roadInfo.x = linkedPosition.x;
+      roadInfo.y = linkedPosition.y;
     }
     return roadInfo;
   }
@@ -255,7 +279,7 @@ export default class ListenLayer {
     let curveRoadInfo = {
       curveRoadId: null,
       type: null,
-      state: null,
+      distance: null,
     };
 
     const curveRoads = dataService.getCurveRoads();
@@ -264,64 +288,177 @@ export default class ListenLayer {
         continue;
       }
       const curveRoad = dataService.getCurveRoad(curveRoadId);
-      let flag = this.isHitForBezier(position, curveRoad.curves);
-      if (flag) {
+      let joinInfo = this.distanceForBezier(position, curveRoad.curves);
+      if (joinInfo.distance < Constant.minAdsorbPix) {
         curveRoadInfo = {
           curveRoadId: curveRoadId,
           type: VectorType.CurveRoad,
-          state: SelectState.Select,
+          distance: joinInfo.distance,
+          x: joinInfo.position.x,
+          y: joinInfo.position.y,
         };
       }
     }
 
-    if (curveRoadInfo.curveRoadId) {
+    return curveRoadInfo;
+  }
+
+  setModifyPoint(position, pointInfo, curvePointInfo, roadInfo, curveRoadInfo) {
+    //优先级最高
+    if (pointInfo.pointId || curvePointInfo.curvePointId) {
       this.modifyPoint = {};
-      this.modifyPoint.linkedCurveRoadId = curveRoadInfo.curveRoadId;
+      if (pointInfo.pointId && curvePointInfo.curvePointId) {
+        if (pointInfo.distance < curvePointInfo.distance) {
+          this.modifyPoint.linkedPointId = pointInfo.pointId;
+          this.modifyPoint.x = pointInfo.x;
+          this.modifyPoint.y = pointInfo.y;
+        } else {
+          this.modifyPoint.linkedCurvePointId = curvePointInfo.curvePointId;
+          this.modifyPoint.x = curvePointInfo.x;
+          this.modifyPoint.y = curvePointInfo.y;
+        }
+      } else if (pointInfo.pointId) {
+        this.modifyPoint.linkedPointId = pointInfo.pointId;
+        this.modifyPoint.x = pointInfo.x;
+        this.modifyPoint.y = pointInfo.y;
+      } else if (curvePointInfo.curvePointId) {
+        this.modifyPoint.linkedCurvePointId = curvePointInfo.curvePointId;
+        this.modifyPoint.x = curvePointInfo.x;
+        this.modifyPoint.y = curvePointInfo.y;
+      }
+    } else if (roadInfo.roadId || curveRoadInfo.curveRoadId) {
+      this.modifyPoint = {};
+      if (roadInfo.roadId && curveRoadInfo.curveRoadId) {
+        if (roadInfo.distance < curveRoadInfo.distance) {
+          this.modifyPoint.linkedRoadId = roadInfo.roadId;
+          this.modifyPoint.x = roadInfo.x;
+          this.modifyPoint.y = roadInfo.y;
+        } else {
+          this.modifyPoint.linkedCurveRoadId = curveRoadInfo.curveRoadId;
+          this.modifyPoint.x = curveRoadInfo.x;
+          this.modifyPoint.y = curveRoadInfo.y;
+        }
+      } else if (roadInfo.roadId) {
+        this.modifyPoint.linkedRoadId = roadInfo.roadId;
+        this.modifyPoint.x = roadInfo.x;
+        this.modifyPoint.y = roadInfo.y;
+      } else if (curveRoadInfo.curveRoadId) {
+        this.modifyPoint.linkedCurveRoadId = curveRoadInfo.curveRoadId;
+        this.modifyPoint.x = curveRoadInfo.x;
+        this.modifyPoint.y = curveRoadInfo.y;
+      }
+    } else if (pointInfo.linkedPointIdX) {
+      this.modifyPoint = {};
+      this.modifyPoint.linkedPointIdX = pointInfo.linkedPointIdX;
+      this.modifyPoint.x = pointInfo.x;
+      this.modifyPoint.y = position.y;
+    } else if (pointInfo.linkedPointIdY) {
+      this.modifyPoint = {};
+      this.modifyPoint.linkedPointIdY = pointInfo.linkedPointIdY;
+      this.modifyPoint.y = pointInfo.y;
+      this.modifyPoint.x = position.x;
+    } else if (curvePointInfo.linkedPointIdX) {
+      this.modifyPoint = {};
+      this.modifyPoint.linkedPointIdX = curvePointInfo.linkedPointIdX;
+      this.modifyPoint.x = curvePointInfo.x;
+      this.modifyPoint.y = position.y;
+    } else if (curvePointInfo.linkedPointIdY) {
+      this.modifyPoint = {};
+      this.modifyPoint.linkedPointIdY = curvePointInfo.linkedPointIdY;
+      this.modifyPoint.y = curvePointInfo.y;
+      this.modifyPoint.x = position.x;
+    } else {
+      this.modifyPoint = null;
     }
-    return curveRoadInfo;
   }
 
-  updateSelectItem(flag1, flag2, flag3, flag4) {
-    if (!flag1) {
+  updateSelectItem() {
+    let selectItem = stateService.getSelectItem();
+    if (this.modifyPoint == null) {
+      if (selectItem != null) {
+        stateService.clearSelectItem();
+        return true;
+      } else {
+        return false;
+      }
+    } else if (this.modifyPoint.linkedPointId) {
       stateService.setSelectItem(
-        this.curveRoadInfo.curveRoadId,
-        this.curveRoadInfo.type,
-        this.curveRoadInfo.state
+        this.modifyPoint.linkedPointId,
+        VectorType.Point,
+        SelectState.Select
       );
-    }
-
-    if (!flag2) {
+    } else if (this.modifyPoint.linkedCurvePointId) {
       stateService.setSelectItem(
-        this.roadInfo.roadId,
-        this.roadInfo.type,
-        this.roadInfo.state
+        this.modifyPoint.linkedCurvePointId,
+        VectorType.CurvePoint,
+        SelectState.Select
       );
-    }
-
-    if (!flag3) {
+    } else if (this.modifyPoint.linkedRoadId) {
       stateService.setSelectItem(
-        this.curvePointInfo.curvePointId,
-        this.curvePointInfo.type,
-        this.curvePointInfo.state
+        this.modifyPoint.linkedRoadId,
+        VectorType.Road,
+        SelectState.Select
       );
-    }
-
-    if (!flag4) {
+    } else if (this.modifyPoint.linkedCurveRoadId) {
       stateService.setSelectItem(
-        this.pointInfo.pointId,
-        this.pointInfo.type,
-        this.pointInfo.state
+        this.modifyPoint.linkedCurveRoadId,
+        VectorType.CurveRoad,
+        SelectState.Select
       );
     }
-    let selectItem = stateService.getSelectItem();
-    if (selectItem != null) {
-      console.log("监听:" + JSON.stringify(selectItem));
-    }
 
-    return flag1 && flag2 && flag3 && flag4;
+    let newSelectItem = stateService.getSelectItem();
+    if (selectItem == null && newSelectItem == null) {
+      return false;
+    } else if (selectItem == null && newSelectItem != null) {
+      return true;
+    } else if (selectItem != null && newSelectItem == null) {
+      return true;
+    } else if (selectItem.vectorId == newSelectItem.vectorId) {
+      return false;
+    } else {
+      return true;
+    }
+    // if (!flag1) {
+    //   stateService.setSelectItem(
+    //     this.curveRoadInfo.curveRoadId,
+    //     this.curveRoadInfo.type,
+    //     this.curveRoadInfo.state
+    //   );
+    // }
+    // if (!flag2) {
+    //   stateService.setSelectItem(
+    //     this.roadInfo.roadId,
+    //     this.roadInfo.type,
+    //     this.roadInfo.state
+    //   );
+    // }
+    // if (!flag3) {
+    //   stateService.setSelectItem(
+    //     this.curvePointInfo.curvePointId,
+    //     this.curvePointInfo.type,
+    //     this.curvePointInfo.state
+    //   );
+    // }
+    // if (!flag4) {
+    //   stateService.setSelectItem(
+    //     this.pointInfo.pointId,
+    //     this.pointInfo.type,
+    //     this.pointInfo.state
+    //   );
+    // }
+    // let selectItem = stateService.getSelectItem();
+    // if (selectItem != null) {
+    //   console.log("监听:" + JSON.stringify(selectItem));
+    // }
+    // return flag1 && flag2 && flag3 && flag4;
   }
 
-  isHitForBezier(position, curves) {
+  distanceForBezier(position, curves) {
+    let joinInfo = {
+      position: null,
+      distance: null,
+    };
     for (let i = 0; i < curves.length; ++i) {
       const curve = curves[i];
       let bezierData = [];
@@ -333,23 +470,25 @@ export default class ListenLayer {
       bezierData.push(curve.end.y);
       const { isHit, getInfo } = bezierUtil.measureBezier(...bezierData);
       const { point } = getInfo(position);
-      // this.testStart = position;
-      // this.testEnd = {
-      //   x: point[0],
-      //   y: point[1],
-      // };
-      // this.testHit = false;
 
       if (
+        joinInfo.distance == null ||
         mathUtil.getDistance(position, {
           x: point[0],
           y: point[1],
-        }) < Constant.minAdsorbPix
+        }) < joinInfo.distance
       ) {
-        return true;
+        joinInfo.distance = mathUtil.getDistance(position, {
+          x: point[0],
+          y: point[1],
+        });
+        joinInfo.position = {
+          x: point[0],
+          y: point[1],
+        };
       }
     }
-    return false;
+    return joinInfo;
   }
 
   equalAndClone(info1, info2) {

+ 1 - 0
src/graphic/Renderer/Render.js

@@ -97,6 +97,7 @@ export default class Render {
   }
 
   autoRedraw() {
+    console.log("重绘");
     draw.clear();
 
     this.drawGeometry(dataService.getBackgroundImg());

+ 38 - 33
src/graphic/Service/EdgeService.js

@@ -21,7 +21,7 @@ export default class EdgeService {
 
   //计算默认的edge
   computerDefaultEdge(roadId) {
-    console.log("开始执行computerDefaultEdge");
+    // console.log("开始执行computerDefaultEdge");
     let road = dataService.getRoad(roadId);
     let line = roadService.getMidLine(road);
 
@@ -72,7 +72,7 @@ export default class EdgeService {
   //单独的墙的一端
   updateDefaultEdge(roadId, dir) {
     //console.log('计算'+roadId+' '+dir+'方向的默认Edge端点');
-    console.log("开始执行updateDefaultEdge");
+    // console.log("开始执行updateDefaultEdge");
 
     let road = dataService.getRoad(roadId);
     let startPoint = dataService.getPoint(road.startId);
@@ -110,7 +110,7 @@ export default class EdgeService {
   //不纠正edge与墙的中心线平行
   updateEdgeForTwoRoad(roadId1, roadId2) {
     //console.log('计算'+roadId1+'和'+roadId2+'相交的edge交点');
-    console.log("开始执行updateEdgeForTwoRoad");
+    // console.log("开始执行updateEdgeForTwoRoad");
 
     let road1 = dataService.getRoad(roadId1);
     let startPoint1 = dataService.getPoint(road1.startId);
@@ -144,7 +144,7 @@ export default class EdgeService {
     //left-right,right-left
     if (road1.startId == road2.startId) {
       //如果墙的角度过大,不能计算edge对应的line的交点
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(startPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(startPoint1, lineRight1);
       } else {
@@ -158,7 +158,7 @@ export default class EdgeService {
       mathUtil.clonePoint(rightEdge2.start, newEdgePoint1);
       mathUtil.clonePoint(leftEdge2.start, newEdgePoint2);
 
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         //要删除控制点
         dataService.deleteControlPoint(leftEdge1.vectorId, rightEdge2.vectorId);
         dataService.deleteControlPoint(rightEdge1.vectorId, leftEdge2.vectorId);
@@ -214,7 +214,7 @@ export default class EdgeService {
     //start-end
     //left-left,right-right
     else if (road1.startId == road2.endId) {
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(startPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(startPoint1, lineRight1);
       } else {
@@ -228,7 +228,7 @@ export default class EdgeService {
       mathUtil.clonePoint(leftEdge2.end, newEdgePoint1);
       mathUtil.clonePoint(rightEdge2.end, newEdgePoint2);
 
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         //要删除控制点
         dataService.deleteControlPoint(leftEdge1.vectorId, leftEdge2.vectorId);
         dataService.deleteControlPoint(
@@ -286,19 +286,24 @@ export default class EdgeService {
     //end-start
     //left-left,right-right
     else if (road1.endId == road2.startId) {
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(endPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(endPoint1, lineRight1);
       } else {
         newEdgePoint1 = mathUtil.getIntersectionPoint(lineLeft1, lineLeft2);
         newEdgePoint2 = mathUtil.getIntersectionPoint(lineRight1, lineRight2);
       }
+
+      if (newEdgePoint1 == null || newEdgePoint2 == null) {
+        debugger;
+      }
+
       mathUtil.clonePoint(leftEdge1.end, newEdgePoint1);
       mathUtil.clonePoint(rightEdge1.end, newEdgePoint2);
 
       mathUtil.clonePoint(leftEdge2.start, newEdgePoint1);
       mathUtil.clonePoint(rightEdge2.start, newEdgePoint2);
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         //要删除控制点
         dataService.deleteControlPoint(leftEdge1.vectorId, leftEdge2.vectorId);
         dataService.deleteControlPoint(
@@ -356,7 +361,7 @@ export default class EdgeService {
     //end-end
     //left-right,right-left
     else if (road1.endId == road2.endId) {
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(endPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(endPoint1, lineRight1);
       } else {
@@ -369,7 +374,7 @@ export default class EdgeService {
       mathUtil.clonePoint(rightEdge2.end, newEdgePoint1);
       mathUtil.clonePoint(leftEdge2.end, newEdgePoint2);
 
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         //要删除控制点
         dataService.deleteControlPoint(leftEdge1.vectorId, rightEdge2.vectorId);
         dataService.deleteControlPoint(rightEdge1.vectorId, leftEdge2.vectorId);
@@ -436,7 +441,7 @@ export default class EdgeService {
   //主要用于多个road相交,计算相邻的road之间的edge
   updateSingleEdgeForTwoRoad(roadId1, roadId2) {
     //console.log('更新'+roadId1+'和'+roadId2+'一侧相交的edge交点');
-    console.log("开始执行updateSingleEdgeForTwoRoad");
+    // console.log("开始执行updateSingleEdgeForTwoRoad");
     const road1 = dataService.getRoad(roadId1);
     const startPoint1 = dataService.getPoint(road1.startId);
     const endPoint1 = dataService.getPoint(road1.endId);
@@ -479,7 +484,7 @@ export default class EdgeService {
       lineRight2 = mathUtil.createLine3(line2, rightEdge2.end);
 
       // 如果墙的角度过大,不能计算edge对应的line的交点
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(startPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(startPoint1, lineRight1);
       } else {
@@ -489,7 +494,7 @@ export default class EdgeService {
 
       points[2] = newEdgePoint1;
       if (mathUtil.isClockwise(points)) {
-        console.log("情况1");
+        // console.log("情况1");
         mathUtil.clonePoint(leftEdge1.start, newEdgePoint1);
         mathUtil.clonePoint(rightEdge2.start, newEdgePoint1);
         //要删除控制点
@@ -497,7 +502,7 @@ export default class EdgeService {
         //不能按照下面的方式计算,因为一个edge可以属于两个控制点,毕竟有两个端点
         // dataService.deleteControlPointForEdge(leftEdge1.vectorId);
         // dataService.deleteControlPointForEdge(rightEdge2.vectorId);
-        if (angle > Constant.maxAngle) {
+        if (angle > Constant.maxAngle || angle < Constant.minAngle) {
           //要删除控制点
           dataService.deleteControlPoint(
             leftEdge1.vectorId,
@@ -518,14 +523,14 @@ export default class EdgeService {
           //需要删除之前的控制点,包含:leftEdge1.vectorId和rightEdge2.vectorId
         }
       } else {
-        console.log("情况2");
+        // console.log("情况2");
         mathUtil.clonePoint(rightEdge1.start, newEdgePoint2);
         mathUtil.clonePoint(leftEdge2.start, newEdgePoint2);
         //要删除控制点
         dataService.deleteControlPoint(leftEdge2.vectorId, rightEdge1.vectorId);
         // dataService.deleteControlPointForEdge(leftEdge2.vectorId);
         // dataService.deleteControlPointForEdge(rightEdge1.vectorId);
-        if (angle > Constant.maxAngle) {
+        if (angle > Constant.maxAngle || angle < Constant.minAngle) {
           //要删除控制点
           dataService.deleteControlPoint(
             leftEdge2.vectorId,
@@ -557,7 +562,7 @@ export default class EdgeService {
       lineLeft2 = mathUtil.createLine3(line2, leftEdge2.start);
       lineRight2 = mathUtil.createLine3(line2, rightEdge2.start);
 
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(startPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(startPoint1, lineRight1);
       } else {
@@ -566,14 +571,14 @@ export default class EdgeService {
       }
       points[2] = newEdgePoint1;
       if (mathUtil.isClockwise(points)) {
-        console.log("情况3");
+        //console.log("情况3");
         mathUtil.clonePoint(leftEdge1.start, newEdgePoint1);
         mathUtil.clonePoint(leftEdge2.end, newEdgePoint1);
         //要删除控制点
         dataService.deleteControlPoint(leftEdge1.vectorId, leftEdge2.vectorId);
         // dataService.deleteControlPointForEdge(leftEdge1.vectorId);
         // dataService.deleteControlPointForEdge(leftEdge2.vectorId);
-        if (angle > Constant.maxAngle) {
+        if (angle > Constant.maxAngle || angle < Constant.minAngle) {
           //要删除控制点
           dataService.deleteControlPoint(
             leftEdge1.vectorId,
@@ -592,7 +597,7 @@ export default class EdgeService {
           );
         }
       } else {
-        console.log("情况4");
+        //console.log("情况4");
         mathUtil.clonePoint(rightEdge1.start, newEdgePoint2);
         mathUtil.clonePoint(rightEdge2.end, newEdgePoint2);
         //要删除控制点
@@ -602,7 +607,7 @@ export default class EdgeService {
         );
         // dataService.deleteControlPointForEdge(rightEdge1.vectorId);
         // dataService.deleteControlPointForEdge(rightEdge2.vectorId);
-        if (angle > Constant.maxAngle) {
+        if (angle > Constant.maxAngle || angle < Constant.minAngle) {
           //要删除控制点
           dataService.deleteControlPoint(
             rightEdge1.vectorId,
@@ -634,7 +639,7 @@ export default class EdgeService {
       lineLeft2 = mathUtil.createLine3(line2, leftEdge2.end);
       lineRight2 = mathUtil.createLine3(line2, rightEdge2.end);
 
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(endPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(endPoint1, lineRight1);
       } else {
@@ -643,14 +648,14 @@ export default class EdgeService {
       }
       points[2] = newEdgePoint1;
       if (mathUtil.isClockwise(points)) {
-        console.log("情况5");
+        //console.log("情况5");
         mathUtil.clonePoint(leftEdge1.end, newEdgePoint1);
         mathUtil.clonePoint(leftEdge2.start, newEdgePoint1);
         //要删除控制点
         dataService.deleteControlPoint(leftEdge1.vectorId, leftEdge2.vectorId);
         // dataService.deleteControlPointForEdge(leftEdge1.vectorId);
         // dataService.deleteControlPointForEdge(leftEdge2.vectorId);
-        if (angle > Constant.maxAngle) {
+        if (angle > Constant.maxAngle || angle < Constant.minAngle) {
           //要删除控制点
           dataService.deleteControlPoint(
             leftEdge1.vectorId,
@@ -669,7 +674,7 @@ export default class EdgeService {
           );
         }
       } else {
-        console.log("情况6");
+        //console.log("情况6");
         mathUtil.clonePoint(rightEdge1.end, newEdgePoint2);
         mathUtil.clonePoint(rightEdge2.start, newEdgePoint2);
         //要删除控制点
@@ -679,7 +684,7 @@ export default class EdgeService {
         );
         // dataService.deleteControlPointForEdge(rightEdge1.vectorId);
         // dataService.deleteControlPointForEdge(rightEdge2.vectorId);
-        if (angle > Constant.maxAngle) {
+        if (angle > Constant.maxAngle || angle < Constant.minAngle) {
           //要删除控制点
           dataService.deleteControlPoint(
             rightEdge1.vectorId,
@@ -711,7 +716,7 @@ export default class EdgeService {
       lineLeft2 = mathUtil.createLine3(line2, leftEdge2.start);
       lineRight2 = mathUtil.createLine3(line2, rightEdge2.start);
 
-      if (angle > Constant.maxAngle) {
+      if (angle > Constant.maxAngle || angle < Constant.minAngle) {
         newEdgePoint1 = mathUtil.getJoinLinePoint(endPoint1, lineLeft1);
         newEdgePoint2 = mathUtil.getJoinLinePoint(endPoint1, lineRight1);
       } else {
@@ -720,14 +725,14 @@ export default class EdgeService {
       }
       points[2] = newEdgePoint1;
       if (mathUtil.isClockwise(points)) {
-        console.log("情况7");
+        //console.log("情况7");
         mathUtil.clonePoint(leftEdge1.end, newEdgePoint1);
         mathUtil.clonePoint(rightEdge2.end, newEdgePoint1);
         //要删除控制点
         dataService.deleteControlPoint(leftEdge1.vectorId, leftEdge2.vectorId);
         // dataService.deleteControlPointForEdge(leftEdge1.vectorId);
         // dataService.deleteControlPointForEdge(leftEdge2.vectorId);
-        if (angle > Constant.maxAngle) {
+        if (angle > Constant.maxAngle || angle < Constant.minAngle) {
           //要删除控制点
           dataService.deleteControlPoint(
             leftEdge1.vectorId,
@@ -746,14 +751,14 @@ export default class EdgeService {
           );
         }
       } else {
-        console.log("情况8");
+        //console.log("情况8");
         mathUtil.clonePoint(rightEdge1.end, newEdgePoint2);
         mathUtil.clonePoint(leftEdge2.end, newEdgePoint2);
         //要删除控制点
         dataService.deleteControlPoint(rightEdge1.vectorId, leftEdge2.vectorId);
         // dataService.deleteControlPointForEdge(leftEdge2.vectorId);
         // dataService.deleteControlPointForEdge(rightEdge1.vectorId);
-        if (angle > Constant.maxAngle) {
+        if (angle > Constant.maxAngle || angle < Constant.minAngle) {
           //要删除控制点
           dataService.deleteControlPoint(
             rightEdge1.vectorId,
@@ -785,7 +790,7 @@ export default class EdgeService {
   //更新pointId对应的全部edge端点
   updateEdgeForMulRoad(pointId) {
     //console.log('更新 '+pointId+' 那一圈的edge端点');
-    console.log("开始执行updateEdgeForMulRoad");
+    //console.log("开始执行updateEdgeForMulRoad");
     let point = dataService.getPoint(pointId);
     let parent = point.getParent();
 

+ 1 - 0
src/graphic/Service/ElementService.js

@@ -317,4 +317,5 @@ export class ElementService {
 }
 
 const elementService = new ElementService();
+window.elementService = elementService;
 export { elementService };

+ 72 - 64
src/graphic/Service/RoadService.js

@@ -832,89 +832,97 @@ export default class RoadService {
     let endPoint = dataService.getPoint(road.endId);
     let leftEdge = dataService.getEdge(road.leftEdgeId);
     let rightEdge = dataService.getEdge(road.rightEdgeId);
-    const leftCount = road.leftDrivewayCount;
-    const rightCount = road.rightDrivewayCount;
-
-    let midPoint = {
-      x: (startPoint.x + endPoint.x) / 2,
-      y: (startPoint.y + endPoint.y) / 2,
-    };
-    let line = this.getMidLine(road);
-    let point1 = mathUtil.getJoinLinePoint(leftEdge.start, line);
-    let _point1 = mathUtil.getJoinLinePoint(rightEdge.start, line);
-    if (
-      mathUtil.getDistance(point1, midPoint) >
-      mathUtil.getDistance(_point1, midPoint)
-    ) {
-      point1 = _point1;
-    }
-
-    let point2 = mathUtil.getJoinLinePoint(leftEdge.end, line);
-    let _point2 = mathUtil.getJoinLinePoint(rightEdge.end, line);
-    if (
-      mathUtil.getDistance(point2, midPoint) >
-      mathUtil.getDistance(_point2, midPoint)
-    ) {
-      point2 = _point2;
-    }
-
-    road.midDivide = {
-      start: point1,
-      end: point2,
-      display: true,
-    };
-
-    let leftdx1 = leftEdge.start.x - point1.x;
+    const leftCount = road.leftDrivewayCount + 1;
+    const rightCount = road.rightDrivewayCount + 1;
+
+    // let midPoint = {
+    //   x: (startPoint.x + endPoint.x) / 2,
+    //   y: (startPoint.y + endPoint.y) / 2,
+    // };
+    // let line = this.getMidLine(road);
+    // let point1 = mathUtil.getJoinLinePoint(leftEdge.start, line);
+    // let _point1 = mathUtil.getJoinLinePoint(rightEdge.start, line);
+    // if (
+    //   mathUtil.getDistance(point1, midPoint) >
+    //   mathUtil.getDistance(_point1, midPoint)
+    // ) {
+    //   point1 = _point1;
+    // }
+
+    // let point2 = mathUtil.getJoinLinePoint(leftEdge.end, line);
+    // let _point2 = mathUtil.getJoinLinePoint(rightEdge.end, line);
+    // if (
+    //   mathUtil.getDistance(point2, midPoint) >
+    //   mathUtil.getDistance(_point2, midPoint)
+    // ) {
+    //   point2 = _point2;
+    // }
+
+    // road.midDivide = {
+    //   start: point1,
+    //   end: point2,
+    //   display: true,
+    // };
+
+    let leftdx1 = leftEdge.start.x - startPoint.x;
     leftdx1 = leftdx1 / leftCount;
 
-    let leftdy1 = leftEdge.start.y - point1.y;
+    let leftdy1 = leftEdge.start.y - startPoint.y;
     leftdy1 = leftdy1 / leftCount;
 
-    let leftdx2 = leftEdge.end.x - point2.x;
+    let leftdx2 = leftEdge.end.x - endPoint.x;
     leftdx2 = leftdx2 / leftCount;
 
-    let leftdy2 = leftEdge.end.y - point2.y;
+    let leftdy2 = leftEdge.end.y - endPoint.y;
     leftdy2 = leftdy2 / leftCount;
 
-    let rightdx1 = rightEdge.start.x - point1.x;
+    let rightdx1 = rightEdge.start.x - startPoint.x;
     rightdx1 = rightdx1 / rightCount;
 
-    let rightdy1 = rightEdge.start.y - point1.y;
+    let rightdy1 = rightEdge.start.y - startPoint.y;
     rightdy1 = rightdy1 / rightCount;
 
-    let rightdx2 = rightEdge.end.x - point2.x;
+    let rightdx2 = rightEdge.end.x - endPoint.x;
     rightdx2 = rightdx2 / rightCount;
 
-    let rightdy2 = rightEdge.end.y - point2.y;
+    let rightdy2 = rightEdge.end.y - endPoint.y;
     rightdy2 = rightdy2 / rightCount;
 
-    for (let i = 1; i < leftCount; ++i) {
-      if (!dir) {
-        road.leftLanes[i] = {};
-      }
-      if (dir == "start" || !dir) {
-        road.leftLanes[i].start = {};
-        road.leftLanes[i].start.x = point1.x + leftdx1 * i;
-        road.leftLanes[i].start.y = point1.y + leftdy1 * i;
-      } else if (dir == "end" || !dir) {
-        road.leftLanes[i].end = {};
-        road.leftLanes[i].end.x = point2.x + leftdx2 * i;
-        road.leftLanes[i].end.y = point2.y + leftdy2 * i;
+    if (road.leftDrivewayCount == 0) {
+      road.leftLanes = [];
+    } else {
+      for (let i = 1; i < leftCount; ++i) {
+        if (!dir) {
+          road.leftLanes[i] = {};
+        }
+        if (dir == "start" || !dir) {
+          road.leftLanes[i].start = {};
+          road.leftLanes[i].start.x = startPoint.x + leftdx1 * i;
+          road.leftLanes[i].start.y = startPoint.y + leftdy1 * i;
+        } else if (dir == "end" || !dir) {
+          road.leftLanes[i].end = {};
+          road.leftLanes[i].end.x = endPoint.x + leftdx2 * i;
+          road.leftLanes[i].end.y = endPoint.y + leftdy2 * i;
+        }
       }
     }
 
-    for (let i = 1; i < rightCount; ++i) {
-      if (!dir) {
-        road.rightLanes[i] = {};
-      }
-      if (dir == "start" || !dir) {
-        road.rightLanes[i].start = {};
-        road.rightLanes[i].start.x = point1.x + leftdx1 * i;
-        road.rightLanes[i].start.y = point1.y + leftdy1 * i;
-      } else if (dir == "end" || !dir) {
-        road.rightLanes[i].end = {};
-        road.rightLanes[i].end.x = point2.x + leftdx2 * i;
-        road.rightLanes[i].end.y = point2.y + leftdy2 * i;
+    if (road.rightDrivewayCount == 0) {
+      road.rightLanes = [];
+    } else {
+      for (let i = 1; i < rightCount; ++i) {
+        if (!dir) {
+          road.rightLanes[i] = {};
+        }
+        if (dir == "start" || !dir) {
+          road.rightLanes[i].start = {};
+          road.rightLanes[i].start.x = startPoint.x + leftdx1 * i;
+          road.rightLanes[i].start.y = startPoint.y + leftdy1 * i;
+        } else if (dir == "end" || !dir) {
+          road.rightLanes[i].end = {};
+          road.rightLanes[i].end.x = endPoint.x + leftdx2 * i;
+          road.rightLanes[i].end.y = endPoint.y + leftdy2 * i;
+        }
       }
     }
   }

+ 1 - 1
src/graphic/Service/StateService.js

@@ -29,7 +29,7 @@ export default class StateService {
 
     if (type == VectorType.Tag) {
       if (state == SelectState.Select) {
-        this.selectItem.selectIndex = SelectState.All;
+        this.selectItem.selectIndex = SelectState.Select;
       } else {
         this.selectItem.selectIndex = state;
       }

+ 0 - 1
src/graphic/enum/SelectState.js

@@ -1,5 +1,4 @@
 const SelectState = {
-  All: "all",
   Select: "select",
   /*,
     focus: "focus",