소스 검색

修复了ControlPoint的bug

xushiting 2 년 전
부모
커밋
e1012b67e1

+ 20 - 14
src/graphic/Geometry/ControlPoint.js

@@ -44,33 +44,39 @@ export default class ControlPoint extends Geometry {
   setExtremePoint() {
   setExtremePoint() {
     let points = [];
     let points = [];
     let edge1 = dataService.getRoadEdge(this.edgeInfo1.id);
     let edge1 = dataService.getRoadEdge(this.edgeInfo1.id);
+    let curve = {};
     if (this.edgeInfo1.dir == "start") {
     if (this.edgeInfo1.dir == "start") {
-      points[0] = edge1.start;
+      curve.start = {};
+      mathUtil.clonePoint(curve.start, edge1.start);
     } else if (this.edgeInfo1.dir == "end") {
     } else if (this.edgeInfo1.dir == "end") {
-      points[0] = edge1.end;
+      curve.start = {};
+      mathUtil.clonePoint(curve.start, edge1.end);
     }
     }
-    points[1] = {
+    curve.controls = [];
+    curve.controls.push({
       x: this.x,
       x: this.x,
       y: this.y,
       y: this.y,
-    };
+    });
     let edge2 = dataService.getRoadEdge(this.edgeInfo2.id);
     let edge2 = dataService.getRoadEdge(this.edgeInfo2.id);
     if (this.edgeInfo2.dir == "start") {
     if (this.edgeInfo2.dir == "start") {
-      points[2] = edge2.start;
+      curve.end = {};
+      mathUtil.clonePoint(curve.end, edge2.start);
     } else if (this.edgeInfo2.dir == "end") {
     } else if (this.edgeInfo2.dir == "end") {
-      points[2] = edge2.end;
+      curve.end = {};
+      mathUtil.clonePoint(curve.end, edge2.end);
     }
     }
-    let curves = mathUtil.getCurvesByPoints(points);
-    let joinInfo = mathUtil.getHitInfoForCurves(
-      points[1],
-      curves,
+
+    let joinInfo = mathUtil.getHitInfoForCurve(
+      curve.controls[0],
+      curve,
       Constant.defaultRoadWidth
       Constant.defaultRoadWidth
     );
     );
     this.extremePoint = {};
     this.extremePoint = {};
     mathUtil.clonePoint(this.extremePoint, joinInfo.position);
     mathUtil.clonePoint(this.extremePoint, joinInfo.position);
     this.curves = mathUtil.getCurvesByPoints([
     this.curves = mathUtil.getCurvesByPoints([
-      points[0],
+      curve.start,
       this.extremePoint,
       this.extremePoint,
-      points[2],
+      curve.end,
     ]);
     ]);
   }
   }
 
 
@@ -83,8 +89,8 @@ export default class ControlPoint extends Geometry {
       points[0] = edge1.end;
       points[0] = edge1.end;
     }
     }
     points[1] = {
     points[1] = {
-      x: this.x,
-      y: this.y,
+      x: this.extremePoint.x,
+      y: this.extremePoint.y,
     };
     };
     let edge2 = dataService.getRoadEdge(this.edgeInfo2.id);
     let edge2 = dataService.getRoadEdge(this.edgeInfo2.id);
     if (this.edgeInfo2.dir == "start") {
     if (this.edgeInfo2.dir == "start") {

+ 42 - 26
src/graphic/ListenLayer.js

@@ -531,44 +531,60 @@ export default class ListenLayer {
       const rightEdge = dataService.getRoadEdge(road.rightEdgeId);
       const rightEdge = dataService.getRoadEdge(road.rightEdgeId);
       const roadLine = roadService.getMidLine(road);
       const roadLine = roadService.getMidLine(road);
       let join = mathUtil.getJoinLinePoint(position, roadLine);
       let join = mathUtil.getJoinLinePoint(position, roadLine);
-      const distance = mathUtil.getDistance(position, join);
-      if (!mathUtil.isContainForSegment(join, startPoint, endPoint)) {
-        continue;
-      }
-      if (distance < Constant.minAdsorbPix) {
-        roadInfo = {
-          roadId: roadId,
-          type: VectorType.Road,
-          distance: distance,
-        };
+      let distance = mathUtil.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,
+          };
+        }
       }
       }
+
       //检查edge
       //检查edge
-      else {
-        let leftLine = mathUtil.createLine1(leftEdge.start, leftEdge.end);
-        join = mathUtil.getJoinLinePoint(position, leftLine);
-        if (distance < Constant.minAdsorbPix) {
+      let leftLine = mathUtil.createLine1(leftEdge.start, leftEdge.end);
+      join = mathUtil.getJoinLinePoint(position, leftLine);
+      distance = mathUtil.getDistance(position, join);
+      if (
+        mathUtil.isContainForSegment(join, leftEdge.start, leftEdge.end) &&
+        distance < Constant.minAdsorbPix
+      ) {
+        if (!edgeInfo.edgeId || distance < edgeInfo.distance) {
           edgeInfo = {
           edgeInfo = {
             edgeId: road.leftEdgeId,
             edgeId: road.leftEdgeId,
             type: VectorType.RoadEdge,
             type: VectorType.RoadEdge,
             distance: distance,
             distance: distance,
             dir: "left",
             dir: "left",
           };
           };
-        } else {
-          let rightLine = mathUtil.createLine1(rightEdge.start, rightEdge.end);
-          join = mathUtil.getJoinLinePoint(position, rightLine);
-          if (distance < Constant.minAdsorbPix) {
-            edgeInfo = {
-              edgeId: road.rightEdgeId,
-              type: VectorType.RoadEdge,
-              distance: distance,
-              dir: "right",
-            };
-          }
+        }
+      }
+
+      let rightLine = mathUtil.createLine1(rightEdge.start, rightEdge.end);
+      join = mathUtil.getJoinLinePoint(position, rightLine);
+      distance = mathUtil.getDistance(position, join);
+      if (
+        mathUtil.isContainForSegment(join, rightEdge.start, rightEdge.end) &&
+        distance < Constant.minAdsorbPix
+      ) {
+        if (!edgeInfo.edgeId || distance < edgeInfo.distance) {
+          edgeInfo = {
+            edgeId: road.rightEdgeId,
+            type: VectorType.RoadEdge,
+            distance: distance,
+            dir: "right",
+          };
         }
         }
       }
       }
     }
     }
 
 
-    if (roadInfo.roadId) {
+    if (
+      roadInfo.roadId &&
+      (!edgeInfo.edgeId || roadInfo.distance < edgeInfo.distance)
+    ) {
       const linkedRoad = dataService.getRoad(roadInfo.roadId);
       const linkedRoad = dataService.getRoad(roadInfo.roadId);
       const linkedRoadLine = roadService.getMidLine(linkedRoad);
       const linkedRoadLine = roadService.getMidLine(linkedRoad);
       const linkedPosition = mathUtil.getJoinLinePoint(
       const linkedPosition = mathUtil.getJoinLinePoint(

+ 21 - 14
src/graphic/Renderer/Draw.js

@@ -21,7 +21,7 @@ const help = {
       [stateService.getDraggingItem(), "Dragging"],
       [stateService.getDraggingItem(), "Dragging"],
       [stateService.getFocusItem(), "Focus"],
       [stateService.getFocusItem(), "Focus"],
     ];
     ];
-    let currentAttr
+    let currentAttr;
 
 
     return [
     return [
       itemsEntry.reduce((prev, [item, attr]) => {
       itemsEntry.reduce((prev, [item, attr]) => {
@@ -31,13 +31,13 @@ const help = {
           geoId === item.vectorId
           geoId === item.vectorId
         ) {
         ) {
           if (Style[attr] && Style[attr][geoType]) {
           if (Style[attr] && Style[attr][geoType]) {
-            currentAttr = attr
+            currentAttr = attr;
             return Style[attr][geoType];
             return Style[attr][geoType];
           }
           }
         }
         }
         return prev;
         return prev;
       }, Style[geoType]),
       }, Style[geoType]),
-      currentAttr
+      currentAttr,
     ];
     ];
   },
   },
   setVectorStyle(ctx, vector, geoType = vector.geoType) {
   setVectorStyle(ctx, vector, geoType = vector.geoType) {
@@ -305,6 +305,7 @@ export default class Draw {
     const extremePoint = coordinate.getScreenXY(vector.extremePoint);
     const extremePoint = coordinate.getScreenXY(vector.extremePoint);
     const ctx = this.context;
     const ctx = this.context;
     ctx.save();
     ctx.save();
+    ctx.strokeStyle = "red";
     ctx.beginPath();
     ctx.beginPath();
     ctx.arc(
     ctx.arc(
       // pt.x,
       // pt.x,
@@ -324,9 +325,11 @@ export default class Draw {
     ctx.beginPath();
     ctx.beginPath();
     help.setVectorStyle(ctx, null, "RoadEdge");
     help.setVectorStyle(ctx, null, "RoadEdge");
     //曲线
     //曲线
-    ctx.moveTo(start.x, start.y);
-    ctx.quadraticCurveTo(pt.x, pt.y, end.x, end.y);
-    ctx.stroke();
+    // ctx.moveTo(start.x, start.y);
+    // ctx.quadraticCurveTo(pt.x, pt.y, end.x, end.y);
+
+    const [coves] = help.transformCoves([vector.curves]);
+    help.drawCoves(ctx, coves);
     ctx.restore();
     ctx.restore();
   }
   }
 
 
@@ -409,9 +412,13 @@ export default class Draw {
     ctx.moveTo(start.x, start.y);
     ctx.moveTo(start.x, start.y);
     ctx.lineTo(end.x, end.y);
     ctx.lineTo(end.x, end.y);
 
 
-    const dires = vector.category === UIEvents.MeasureLine
-      ? [[start, end], [end, start]]
-      : [[start, end]]
+    const dires =
+      vector.category === UIEvents.MeasureLine
+        ? [
+            [start, end],
+            [end, start],
+          ]
+        : [[start, end]];
     for (let [start, end] of dires) {
     for (let [start, end] of dires) {
       const lines = mathUtil.getArrow(start, end);
       const lines = mathUtil.getArrow(start, end);
       ctx.moveTo(lines[0].x, lines[0].y);
       ctx.moveTo(lines[0].x, lines[0].y);
@@ -471,14 +478,14 @@ export default class Draw {
         const imgCenter = coordinate.getScreenXY(backImg.center);
         const imgCenter = coordinate.getScreenXY(backImg.center);
         const start = {
         const start = {
           x: imgCenter.x - help.getReal(img.width) / 2,
           x: imgCenter.x - help.getReal(img.width) / 2,
-          y: imgCenter.y - help.getReal(img.height) / 2 ,
+          y: imgCenter.y - help.getReal(img.height) / 2,
         };
         };
-        const ro = img.width / help.getReal(img.width)
+        const ro = img.width / help.getReal(img.width);
         imgBound = [
         imgBound = [
           (pt.x - start.x - size) * ro,
           (pt.x - start.x - size) * ro,
           (pt.y - start.y - size) * ro,
           (pt.y - start.y - size) * ro,
-          (size * 2) * ro,
-            (size * 2) * ro,
+          size * 2 * ro,
+          size * 2 * ro,
         ];
         ];
       }
       }
       const size = help.getReal(style.target.radius);
       const size = help.getReal(style.target.radius);
@@ -559,7 +566,7 @@ export default class Draw {
     this.context.font = `${vector.fontSize}px Microsoft YaHei`;
     this.context.font = `${vector.fontSize}px Microsoft YaHei`;
     this.drawTextByInfo(vector.center, vector.value, 0, false);
     this.drawTextByInfo(vector.center, vector.value, 0, false);
 
 
-    const ctx = this.context
+    const ctx = this.context;
     const pt = coordinate.getScreenXY(vector.center);
     const pt = coordinate.getScreenXY(vector.center);
     const text = ctx.measureText(vector.value);
     const text = ctx.measureText(vector.value);
     pt.x -= text.width / 2;
     pt.x -= text.width / 2;

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

@@ -512,8 +512,8 @@ export default class CurveRoadService extends RoadService {
     if (curveRoad.way == Constant.oneWay) {
     if (curveRoad.way == Constant.oneWay) {
       edgePoints = mathUtil.getOffset(
       edgePoints = mathUtil.getOffset(
         curveRoad.points,
         curveRoad.points,
-        curveRoad.leftWidth,
-        curveRoad.rightWidth
+        curveRoad.singleRoadWidth / 2,
+        curveRoad.singleRoadWidth / 2
       );
       );
     } else if (curveRoad.way == Constant.twoWay) {
     } else if (curveRoad.way == Constant.twoWay) {
       edgePoints = mathUtil.getOffset(
       edgePoints = mathUtil.getOffset(

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

@@ -30,7 +30,7 @@ export default class EdgeService {
       edgePoints = mathUtil.RectangleVertex(
       edgePoints = mathUtil.RectangleVertex(
         startPoint,
         startPoint,
         endPoint,
         endPoint,
-        road.leftWidth * 2
+        road.singleRoadWidth
       );
       );
     } else {
     } else {
       edgePoints = mathUtil.RectangleVertex(
       edgePoints = mathUtil.RectangleVertex(
@@ -43,11 +43,6 @@ export default class EdgeService {
     mathUtil.clonePoint(leftEdge.end, edgePoints.leftEdgeEnd);
     mathUtil.clonePoint(leftEdge.end, edgePoints.leftEdgeEnd);
 
 
     if (road.way == Constant.oneWay) {
     if (road.way == Constant.oneWay) {
-      edgePoints = mathUtil.RectangleVertex(
-        startPoint,
-        endPoint,
-        road.rightWidth * 2
-      );
     } else {
     } else {
       edgePoints = mathUtil.RectangleVertex(
       edgePoints = mathUtil.RectangleVertex(
         startPoint,
         startPoint,

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

@@ -180,10 +180,10 @@ export class ElementService {
       let edgePoints = null;
       let edgePoints = null;
       if (this.newRoad.way == Constant.oneWay) {
       if (this.newRoad.way == Constant.oneWay) {
         this.newRoad.singleRoadWidth = Settings.singleRoadWidth;
         this.newRoad.singleRoadWidth = Settings.singleRoadWidth;
-        this.newRoad.rightWidth = edgePoints = mathUtil.RectangleVertex(
+        edgePoints = mathUtil.RectangleVertex(
           point1,
           point1,
           point2,
           point2,
-          this.newRoad.rightWidth
+          this.newRoad.singleRoadWidth
         );
         );
       } else if (this.newRoad.way == Constant.twoWay) {
       } else if (this.newRoad.way == Constant.twoWay) {
         this.newRoad.leftWidth = Settings.leftRoadWidth;
         this.newRoad.leftWidth = Settings.leftRoadWidth;