瀏覽代碼

继续绘图

xushiting 2 年之前
父節點
當前提交
f0e72792b2

+ 3 - 0
src/graphic/Controls/MoveRoad.js

@@ -32,6 +32,9 @@ export default class MoveRoad {
       linkedPointId = modifyPoint.linkedPointId;
       linkedRoadId = modifyPoint.linkedRoadId;
     }
+    if (point.x == position.x && point.y == position.y) {
+      return false;
+    }
     this.adsorbPointRoads = {};
     this.splitRoadId = null;
     let flag = this.canMoveForPoint(

+ 0 - 1
src/graphic/Geometry/CurveRoad.js

@@ -9,7 +9,6 @@ export default class CurveRoad extends Road {
     this.points = []; //中心线上一系列控制点。数组是从start到end。
     this.leftLanesCurves = []; //左车道曲线
     this.rightLanesCurves = []; //左车道曲线
-    this.width = Constant.defaultRoadWidth; //默认宽度
     this.leftDrivewayCount = 2; //左边的车道个数
     this.rightDrivewayCount = 2; //右边的车道个数
     this.curves = [];

+ 8 - 3
src/graphic/Geometry/Road.js

@@ -15,12 +15,17 @@ export default class Road extends Geometry {
     this.leftDrivewayCount = 1; //左边的车道个数
     this.rightDrivewayCount = 1; //右边的车道个数
     this.geoType = VectorType.Road;
-    this.width = Constant.defaultRoadWidth; //默认宽度
+    this.leftWidth = Constant.defaultRoadWidth / 2;
+    this.rightWidth = Constant.defaultRoadWidth / 2;
     this.setId(vectorId);
   }
 
-  setWidth(value) {
-    this.width = value;
+  setWidth(value, dir) {
+    if (dir == "left") {
+      this.leftWidth = value;
+    } else if (dir == "right") {
+      this.rightWidth = value;
+    }
   }
 
   getOtherPointId(pointId) {

+ 21 - 17
src/graphic/Layer.js

@@ -414,6 +414,9 @@ export default class Layer {
         this.uiControl.currentUI = null;
         break;
       case LayerEvents.MoveRoadPoint:
+        if (!draggingItem || !draggingItem.vectorId) {
+          break;
+        }
         needAutoRedraw = true;
         elementService.hideAll();
         let point = dataService.getPoint(draggingItem.vectorId);
@@ -507,19 +510,19 @@ export default class Layer {
         }
         this.history.save();
         break;
-      case LayerEvents.AddTag:
-        needAutoRedraw = true;
-        let tag = dataService.getTag(draggingItem.vectorId);
-        tag.setAdding(false);
-        focusItem = {
-          vectorId: draggingItem.vectorId,
-          type: draggingItem.type,
-          cursor: { x: this.lastX, y: this.lastY },
-        };
-        stateService.setFocusItem(focusItem);
-        this.history.save();
-        this.uiControl.currentUI = focusItem.type;
-        break;
+      // case LayerEvents.AddTag:
+      //   needAutoRedraw = true;
+      //   let tag = dataService.getTag(draggingItem.vectorId);
+      //   tag.setAdding(false);
+      //   focusItem = {
+      //     vectorId: draggingItem.vectorId,
+      //     type: draggingItem.type,
+      //     cursor: { x: this.lastX, y: this.lastY },
+      //   };
+      //   stateService.setFocusItem(focusItem);
+      //   this.history.save();
+      //   this.uiControl.currentUI = focusItem.type;
+      //   break;
     }
 
     this.setEventName("mouseUp");
@@ -548,6 +551,7 @@ export default class Layer {
   //测试用
   onKeydown(e) {
     let focusItem = stateService.getFocusItem();
+    let dir = "left";
     if (focusItem) {
       console.log("键盘(foucus有效):" + e.code);
       if (e.code == "Delete") {
@@ -564,10 +568,10 @@ export default class Layer {
       else if (e.code == "KeyA") {
         let road = dataService.getRoad(focusItem.vectorId);
         if (road) {
-          roadService.updateForWidth(road.vectorId, road.width + 100);
+          roadService.updateForWidth(road.vectorId, road.width + 50, dir);
         } else {
           road = dataService.getCurveRoad(focusItem.vectorId);
-          curveRoadService.updateForWidth(road.vectorId, road.width + 100);
+          curveRoadService.updateForWidth(road.vectorId, road.width + 50, dir);
         }
 
         this.renderer.autoRedraw();
@@ -577,10 +581,10 @@ export default class Layer {
       else if (e.code == "KeyB") {
         let road = dataService.getRoad(focusItem.vectorId);
         if (road) {
-          roadService.updateForWidth(road.vectorId, road.width - 50);
+          roadService.updateForWidth(road.vectorId, road.width - 25, dir);
         } else {
           road = dataService.getCurveRoad(focusItem.vectorId);
-          curveRoadService.updateForWidth(road.vectorId, road.width - 50);
+          curveRoadService.updateForWidth(road.vectorId, road.width - 25, dir);
         }
         this.renderer.autoRedraw();
         this.history.save();

+ 21 - 5
src/graphic/ListenLayer.js

@@ -239,9 +239,13 @@ export default class ListenLayer {
       const roadLine = roadService.getMidLine(road);
       const join = mathUtil.getJoinLinePoint(position, roadLine);
       const distance = mathUtil.getDistance(position, join);
-
+      let width = road.rightWidth;
+      //逆时针的时候,position在左区域
+      if (distance > 1 && mathUtil.isClockwise(startPoint, join, position)) {
+        width = road.leftWidth;
+      }
       if (
-        distance < road.width / 2 &&
+        distance < width &&
         mathUtil.isContainForSegment(join, startPoint, endPoint)
       ) {
         if (roadInfo.roadId == null) {
@@ -288,13 +292,25 @@ export default class ListenLayer {
         continue;
       }
       const curveRoad = dataService.getCurveRoad(curveRoadId);
-      console.log("currentRoad", curveRoad.curves);
       let joinInfo = this.distanceForBezier(
         position,
         curveRoad.curves,
-        curveRoad.width
+        Math.max(curveRoad.leftWidth, curveRoad.rightWidth)
       );
-      if (joinInfo.distance < curveRoad.width / 2) {
+      if (
+        (mathUtil.isClockwise(
+          curveRoad.points[0],
+          joinInfo.position,
+          position
+        ) &&
+          joinInfo.distance < curveRoad.leftWidth) ||
+        (mathUtil.isClockwise(
+          curveRoad.points[curveRoad.points.length - 1],
+          joinInfo.position,
+          position
+        ) &&
+          joinInfo.distance < curveRoad.rightWidth)
+      ) {
         curveRoadInfo = {
           curveRoadId: curveRoadId,
           type: VectorType.CurveRoad,

+ 31 - 16
src/graphic/Service/CurveRoadService.js

@@ -26,7 +26,7 @@ export default class CurveRoadService extends RoadService {
     let edgePoints = mathUtil.RectangleVertex(
       startPoint,
       endPoint,
-      curveRoad.width
+      curveRoad.leftWidth + curveRoad.rightWidth
     );
     let leftEdge = curveEdgeService.create(
       edgePoints.leftEdgeStart,
@@ -374,7 +374,8 @@ export default class CurveRoadService extends RoadService {
     const rightCurveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
     const leftWidth = mathUtil.getDisForPoinLine(leftCurveEdge.start, line);
     const rightWidth = mathUtil.getDisForPoinLine(rightCurveEdge.start, line);
-    curveRoad.setWidth(leftWidth + rightWidth);
+    curveRoad.setWidth(leftWidth, "left");
+    curveRoad.setWidth(rightWidth, "right");
   }
 
   //单车道转多车道,默认是转换成左右两边各一个
@@ -579,27 +580,41 @@ export default class CurveRoadService extends RoadService {
   }
 
   //变宽或者变窄(车道数据不变)
-  updateForWidth(curveRoadId, newWidth) {
+  updateForWidth(curveRoadId, newWidth, dir) {
     let curveRoad = dataService.getCurveRoad(curveRoadId);
     let leftCurveEdge = dataService.getCurveEdge(curveRoad.leftEdgeId);
     let rightCurveEdge = dataService.getCurveEdge(curveRoad.rightEdgeId);
 
-    let ratio = newWidth / curveRoad.width;
+    let ratio = null;
+    let dx = null;
+    let dy = null;
+    if (dir == "left") {
+      ratio = newWidth / curveRoad.leftWidth;
+    } else if (dir == "right") {
+      ratio = newWidth / curveRoad.rightWidth;
+    }
+
     for (let i = 0; i < curveRoad.points.length; ++i) {
-      let dx = (leftCurveEdge.points[i].x - curveRoad.points[i].x) * ratio;
-      leftCurveEdge.points[i].x = curveRoad.points[i].x + dx;
-      let dy = (leftCurveEdge.points[i].y - curveRoad.points[i].y) * ratio;
-      leftCurveEdge.points[i].y = curveRoad.points[i].y + dy;
-      dx = (rightCurveEdge.points[i].x - curveRoad.points[i].x) * ratio;
-      rightCurveEdge.points[i].x = curveRoad.points[i].x + dx;
-      dy = (rightCurveEdge.points[i].y - curveRoad.points[i].y) * ratio;
-      rightCurveEdge.points[i].y = curveRoad.points[i].y + dy;
+      if (dir == "left") {
+        dx = (leftCurveEdge.points[i].x - curveRoad.points[i].x) * ratio;
+        leftCurveEdge.points[i].x = curveRoad.points[i].x + dx;
+        dy = (leftCurveEdge.points[i].y - curveRoad.points[i].y) * ratio;
+        leftCurveEdge.points[i].y = curveRoad.points[i].y + dy;
+      } else if (dir == "right") {
+        dx = (rightCurveEdge.points[i].x - curveRoad.points[i].x) * ratio;
+        rightCurveEdge.points[i].x = curveRoad.points[i].x + dx;
+        dy = (rightCurveEdge.points[i].y - curveRoad.points[i].y) * ratio;
+        rightCurveEdge.points[i].y = curveRoad.points[i].y + dy;
+      }
     }
 
-    curveEdgeService.setCurves(leftCurveEdge);
-    curveEdgeService.setCurves(rightCurveEdge);
-    this.setLanes(curveRoad);
-    curveRoad.setWidth(newWidth);
+    if (dir == "left") {
+      curveEdgeService.setCurves(leftCurveEdge);
+    } else if (dir == "right") {
+      curveEdgeService.setCurves(rightCurveEdge);
+    }
+    this.setLanes(curveRoad, dir);
+    curveRoad.setWidth(newWidth, dir);
   }
 
   setCurves(curveRoad) {

+ 6 - 56
src/graphic/Service/EdgeService.js

@@ -19,56 +19,6 @@ export default class EdgeService {
     return line;
   }
 
-  // //计算默认的edge
-  // computerDefaultEdge(roadId) {
-  //   // console.log("开始执行computerDefaultEdge");
-  //   let road = dataService.getRoad(roadId);
-  //   let line = roadService.getMidLine(road);
-
-  //   let lines = mathUtil.getParallelLineForDistance(line, road.width / 2);
-  //   let startPoint = dataService.getPoint(road.startId);
-  //   let endPoint = dataService.getPoint(road.endId);
-
-  //   let leftEdge = dataService.getEdge(road.leftEdgeId);
-  //   let rightEdge = dataService.getEdge(road.rightEdgeId);
-
-  //   let point = null;
-  //   let points = [];
-
-  //   //先计算start部分
-  //   point = startPoint;
-  //   points.push(endPoint);
-  //   points.push(startPoint);
-  //   let point1 = mathUtil.getJoinLinePoint(point, lines.line1);
-  //   let point2 = mathUtil.getJoinLinePoint(point, lines.line2);
-  //   points[2] = point1;
-
-  //   if (mathUtil.isClockwise(points)) {
-  //     mathUtil.clonePoint(rightEdge.start, point1);
-  //     mathUtil.clonePoint(leftEdge.start, point2);
-  //   } else {
-  //     mathUtil.clonePoint(leftEdge.start, point1);
-  //     mathUtil.clonePoint(rightEdge.start, point2);
-  //   }
-
-  //   //再计算end部分
-  //   points = [];
-  //   point = endPoint;
-  //   points.push(startPoint);
-  //   points.push(endPoint);
-  //   point1 = mathUtil.getJoinLinePoint(point, lines.line1);
-  //   point2 = mathUtil.getJoinLinePoint(point, lines.line2);
-  //   points[2] = point1;
-
-  //   if (mathUtil.isClockwise(points)) {
-  //     mathUtil.clonePoint(leftEdge.end, point1);
-  //     mathUtil.clonePoint(rightEdge.end, point2);
-  //   } else {
-  //     mathUtil.clonePoint(rightEdge.end, point1);
-  //     mathUtil.clonePoint(leftEdge.end, point2);
-  //   }
-  // }
-
   computerDefaultEdge(roadId) {
     let road = dataService.getRoad(roadId);
     let startPoint = dataService.getPoint(road.startId);
@@ -76,19 +26,19 @@ export default class EdgeService {
     let leftEdge = dataService.getEdge(road.leftEdgeId);
     let rightEdge = dataService.getEdge(road.rightEdgeId);
 
-    const line = roadService.getMidLine(road);
-    const leftWidth = mathUtil.getDisForPoinLine(leftEdge.start, line);
-    const rightWidth = mathUtil.getDisForPoinLine(rightEdge.start, line);
-
     let edgePoints = mathUtil.RectangleVertex(
       startPoint,
       endPoint,
-      leftWidth * 2
+      road.leftWidth * 2
     );
     mathUtil.clonePoint(leftEdge.start, edgePoints.leftEdgeStart);
     mathUtil.clonePoint(leftEdge.end, edgePoints.leftEdgeEnd);
 
-    edgePoints = mathUtil.RectangleVertex(startPoint, endPoint, rightWidth * 2);
+    edgePoints = mathUtil.RectangleVertex(
+      startPoint,
+      endPoint,
+      road.rightWidth * 2
+    );
     mathUtil.clonePoint(rightEdge.start, edgePoints.rightEdgeStart);
     mathUtil.clonePoint(rightEdge.end, edgePoints.rightEdgeEnd);
   }

+ 25 - 27
src/graphic/Service/RoadService.js

@@ -19,7 +19,11 @@ export default class RoadService {
     let endPoint = dataService.getPoint(endId);
     endPoint.setPointParent(road.vectorId, "end");
 
-    let edgePoints = mathUtil.RectangleVertex(startPoint, endPoint, road.width);
+    let edgePoints = mathUtil.RectangleVertex(
+      startPoint,
+      endPoint,
+      road.leftWidth + road.rightWidth
+    );
     let leftEdge = edgeService.create(
       edgePoints.leftEdgeStart,
       edgePoints.leftEdgeEnd,
@@ -475,7 +479,7 @@ export default class RoadService {
   isContain(road, point) {
     const startPoint = dataService.getPoint(road.startId);
     const endPoint = dataService.getPoint(road.endId);
-    const minDis = road.width / 2;
+    const minDis = Constant.minAdsorbPix / 2;
     return mathUtil.isContainForSegment(point, startPoint, endPoint, minDis);
   }
 
@@ -1109,45 +1113,39 @@ export default class RoadService {
       road.rightDrivewayCount = newCount;
     }
 
-    let join = mathUtil.getJoinLinePoint(
-      leftEdge.start,
-      mathUtil.createLine1(rightEdge.start, rightEdge.end)
-    );
-    road.setWidth(mathUtil.getDistance(leftEdge.start, join));
+    let line = roadService.getMidLine(road);
+    if (dir == "left") {
+      let join = mathUtil.getJoinLinePoint(leftEdge.start, line);
+      road.setWidth(mathUtil.getDistance(leftEdge.start, join), dir);
+    } else if (dir == "right") {
+      let join = mathUtil.getJoinLinePoint(rightEdge.start, line);
+      road.setWidth(mathUtil.getDistance(rightEdge.start, join), dir);
+    }
+
     edgeService.updateEdgeForMulRoad(road.startId);
     edgeService.updateEdgeForMulRoad(road.endId);
   }
 
   //变宽或者变窄(车道数据不变)
-  updateForWidth(roadId, newWidth) {
+  updateForWidth(roadId, newWidth, dir) {
     let road = dataService.getRoad(roadId);
     let startPoint = dataService.getPoint(road.startId);
     let endPoint = dataService.getPoint(road.endId);
     let leftEdge = dataService.getEdge(road.leftEdgeId);
     let rightEdge = dataService.getEdge(road.rightEdgeId);
 
-    const line = roadService.getMidLine(road);
-    let leftWidth = mathUtil.getDisForPoinLine(leftEdge.start, line);
-    let rightWidth = mathUtil.getDisForPoinLine(rightEdge.start, line);
-
-    leftWidth = (newWidth / road.width) * leftWidth;
-    rightWidth = (newWidth / road.width) * rightWidth;
-
-    let edgePoints = mathUtil.RectangleVertex(
-      startPoint,
-      endPoint,
-      leftWidth * 2
-    );
-    mathUtil.clonePoint(leftEdge.start, edgePoints.leftEdgeStart);
-    mathUtil.clonePoint(leftEdge.end, edgePoints.leftEdgeEnd);
-
-    edgePoints = mathUtil.RectangleVertex(startPoint, endPoint, rightWidth * 2);
-    mathUtil.clonePoint(rightEdge.start, edgePoints.rightEdgeStart);
-    mathUtil.clonePoint(rightEdge.end, edgePoints.rightEdgeEnd);
+    let edgePoints = mathUtil.RectangleVertex(startPoint, endPoint, newWidth);
+    if (dir == "left") {
+      mathUtil.clonePoint(leftEdge.start, edgePoints.leftEdgeStart);
+      mathUtil.clonePoint(leftEdge.end, edgePoints.leftEdgeEnd);
+    } else if (dir == "right") {
+      mathUtil.clonePoint(rightEdge.start, edgePoints.rightEdgeStart);
+      mathUtil.clonePoint(rightEdge.end, edgePoints.rightEdgeEnd);
+    }
 
     edgeService.updateEdgeForMovePoint(road.startId);
     edgeService.updateEdgeForMovePoint(road.endId);
-    roadService.setLanes(road.vectorId);
+    roadService.setLanes(road.vectorId, dir);
     roadService.setMidDivideForPointId(road.startId);
     roadService.setMidDivideForPointId(road.endId);
   }