Browse Source

修复bug

xushiting 2 years ago
parent
commit
656b09dfd3

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

@@ -1024,6 +1024,14 @@ export default class MoveRoad {
       rightCurveEdge.points[i].x += dx;
       rightCurveEdge.points[i].y += dy;
     }
+    leftCurveEdge.start.x += dx;
+    leftCurveEdge.start.y += dy;
+    leftCurveEdge.end.x += dx;
+    leftCurveEdge.end.y += dy;
+    rightCurveEdge.start.x += dx;
+    rightCurveEdge.start.y += dy;
+    rightCurveEdge.end.x += dx;
+    rightCurveEdge.end.y += dy;
     curveRoad.curves = mathUtil.getCurvesByPoints(curveRoad.points);
     leftCurveEdge.curves = mathUtil.getCurvesByPoints(leftCurveEdge.points);
     rightCurveEdge.curves = mathUtil.getCurvesByPoints(rightCurveEdge.points);

+ 8 - 0
src/graphic/Controls/UIControl.js

@@ -378,6 +378,14 @@ export default class UIControl {
       case VectorType.Road:
         roadService.deleteRoadForLinked(vectorId);
         break;
+      case VectorType.RoadPoint:
+        const roadPoint = dataService.getRoadPoint(vectorId);
+        const roadPointParent = roadPoint.getParent();
+        for (let key in roadPointParent) {
+          roadService.deleteRoadForLinked(key);
+        }
+
+        break;
       case VectorType.CurveRoadPoint:
         curveRoadPointService.deleteCurveRoadPoint(vectorId);
         break;

+ 35 - 6
src/graphic/Geometry/Road.js

@@ -3,7 +3,7 @@ import Geometry from "./Geometry.js";
 import Settings from "../Settings";
 import Constant from "../Constant";
 
-import {coordinate} from '../Coordinate.js'
+import { coordinate } from "../Coordinate.js";
 
 export default class Road extends Geometry {
   constructor(startId, endId, vectorId) {
@@ -27,16 +27,33 @@ export default class Road extends Geometry {
     this.rightDrivewayCount = Settings.roadRightDrivewayCount; //右边的车道个数
     this.geoType = VectorType.Road;
 
-    
-    this.leftWidth = (Settings.roadLeftDrivewayCount * Settings.singleLaneWidth) * window.coordinate.ratio;
+    this.leftWidth =
+      Settings.roadLeftDrivewayCount *
+      Settings.singleLaneWidth *
+      window.coordinate.ratio;
     this.rightWidth =
-      Settings.roadRightDrivewayCount * Settings.singleLaneWidth* window.coordinate.ratio;
+      Settings.roadRightDrivewayCount *
+      Settings.singleLaneWidth *
+      window.coordinate.ratio;
     this.singleRoadDrivewayCount = Settings.singleRoadDrivewayCount;
     this.singleRoadWidth =
-      Settings.singleRoadDrivewayCount * Settings.singleLaneWidth* window.coordinate.ratio;
+      Settings.singleRoadDrivewayCount *
+      Settings.singleLaneWidth *
+      window.coordinate.ratio;
     this.way = Settings.wayType;
     this.setId(vectorId);
-    
+  }
+
+  setMidDivide(midDivideData) {
+    this.midDivide = JSON.parse(JSON.stringify(midDivideData));
+  }
+
+  setLeftEdgeId(value) {
+    this.leftEdgeId = value;
+  }
+
+  setRightEdgeId(value) {
+    this.rightEdgeId = value;
   }
 
   setWidth(value, dir) {
@@ -106,4 +123,16 @@ export default class Road extends Geometry {
       }
     }
   }
+
+  setLeftLanes(leftLanes) {
+    this.leftLanes = JSON.parse(JSON.stringify(leftLanes));
+  }
+
+  setRightLanes(rightLanes) {
+    this.rightLanes = JSON.parse(JSON.stringify(rightLanes));
+  }
+
+  setSingleLanes(singleLanes) {
+    this.singleLanes = JSON.parse(JSON.stringify(singleLanes));
+  }
 }

+ 5 - 1
src/graphic/Geometry/RoadEdge.js

@@ -12,7 +12,7 @@ export default class RoadEdge extends Geometry {
     this.vectorId = null;
     this.style = null;
     this.geoType = VectorType.RoadEdge;
-    this.lineWidth = 4
+    this.lineWidth = 4;
     this.setId(vectorId);
     this.setPositions(start, end);
   }
@@ -33,6 +33,10 @@ export default class RoadEdge extends Geometry {
     }
   }
 
+  setLineWidth(value) {
+    this.lineWidth = value;
+  }
+
   getPosition(dir) {
     if (dir == "start") {
       return this.start;

+ 95 - 57
src/graphic/Load.js

@@ -3,7 +3,7 @@ import { lineService } from "./Service/LineService.js";
 import { roadService } from "./Service/RoadService.js";
 import { curveRoadService } from "./Service/CurveRoadService.js";
 import { pointService } from "./Service/PointService.js";
-import {curveRoadPointService } from "./Service/CurveRoadPointService.js";
+import { curveRoadPointService } from "./Service/CurveRoadPointService.js";
 import { roadPointService } from "./Service/RoadPointService.js";
 import { imageService } from "./Service/ImageService.js";
 import VectorCategory from "./enum/VectorCategory.js";
@@ -16,6 +16,10 @@ import { svgService } from "./Service/SVGService.js";
 import { mathUtil } from "./Util/MathUtil.js";
 import { historyService } from "./Service/HistoryService.js";
 import { uiService } from "./Service/UIService";
+import { crossPointService } from "./Service/CrossPointService.js";
+import Road from "./Geometry/Road.js";
+import { edgeService } from "./Service/EdgeService.js";
+
 export default class Load {
   constructor(layer) {
     this.layer = layer;
@@ -27,9 +31,9 @@ export default class Load {
   async load(dataLocal, data3d) {
     this.layer.initLocation();
     if (dataLocal) {
-      if(dataLocal.Settings){
-        for(let key in dataLocal.Settings){
-          Settings[key] = dataLocal.Settings[key]
+      if (dataLocal.Settings) {
+        for (let key in dataLocal.Settings) {
+          Settings[key] = dataLocal.Settings[key];
         }
       }
       if (dataLocal.backgroundImg) {
@@ -39,7 +43,7 @@ export default class Load {
         );
         bgImg.setCenter(dataLocal.backgroundImg.center);
         // bgImg.setDisplay(dataLocal.backgroundImg.display);
-        bgImg.setDisplay(true);//背景图始终显示
+        bgImg.setDisplay(true); //背景图始终显示
         bgImg.setAngle(dataLocal.backgroundImg.angle);
         try {
           if (dataLocal.backgroundImg.src) {
@@ -63,7 +67,6 @@ export default class Load {
         }
       }
       if (dataLocal.magnifiers) {
-
         for (let key in dataLocal.magnifiers) {
           let magnifier = magnifierService.create(
             dataLocal.magnifiers[key].position,
@@ -72,7 +75,7 @@ export default class Load {
           magnifier.setSrc(dataLocal.magnifiers[key].photoUrl);
           magnifier.setDisplay(dataLocal.magnifiers[key].display);
 
-          magnifier.setPopPosition(null,dataLocal.magnifiers[key].popPosition)
+          magnifier.setPopPosition(null, dataLocal.magnifiers[key].popPosition);
 
           try {
             if (dataLocal.magnifiers[key].photoUrl) {
@@ -96,10 +99,10 @@ export default class Load {
 
         // let points = dataService.vectorData.points;
         let points = dataLocal.points;
-        Settings.basePointIds =[]
+        Settings.basePointIds = [];
         for (let key in points) {
           if (points[key].category == VectorCategory.Point.BasePoint) {
-            Settings.basePointIds.push(points[key].vectorId)
+            Settings.basePointIds.push(points[key].vectorId);
           }
         }
         // if(  Settings.basePointIds.length==1){
@@ -157,17 +160,17 @@ export default class Load {
       //     let startPosition = null;
       //     let endPosition = null ;
       //     if(dataLocal.curvePoints){
-      //       startPosition ={ 
+      //       startPosition ={
       //         x:dataLocal.curvePoints[startPointId].x,
       //         y:dataLocal.curvePoints[startPointId].y,
       //       }
-      //       endPosition ={ 
+      //       endPosition ={
       //         x:dataLocal.curvePoints[endPointId].x,
       //         y:dataLocal.curvePoints[endPointId].y,
       //       }
 
       //     }
-         
+
       //     let curveline = lineService.createCurveLine(
       //       startPosition,
       //       endPosition,
@@ -195,72 +198,107 @@ export default class Load {
       //     }
       //   }
       // }
-      if(dataLocal.roadPoints){
-
+      if (dataLocal.roadPoints) {
         for (let key in dataLocal.roadPoints) {
-          let roadPoint = roadPointService.create(
+          roadPointService.create(
             dataLocal.roadPoints[key],
-            dataLocal.roadPoints[key].vectorId,
+            dataLocal.roadPoints[key].vectorId
           );
         }
       }
-      if(dataLocal.roads){
+
+      if (dataLocal.roads) {
         for (let key in dataLocal.roads) {
           uiService.setWayType(dataLocal.roads[key].way);
-          uiService.setSingleRoadDrivewayCount( dataLocal.roads[key].singleRoadDrivewayCount)
-          let road = roadService.create(
+          uiService.setSingleRoadDrivewayCount(
+            dataLocal.roads[key].singleRoadDrivewayCount
+          );
+          uiService.setRoadLeftDrivewayCount(
+            dataLocal.roads[key].leftDrivewayCount
+          );
+          uiService.setRoadRightDrivewayCount(
+            dataLocal.roads[key].rightDrivewayCount
+          );
+          let road = new Road(
             dataLocal.roads[key].startId,
             dataLocal.roads[key].endId,
-            dataLocal.roads[key].vectorId,
+            dataLocal.roads[key].vectorId
           );
-          if(dataLocal.roadEdges){ //当roadEdge有样式的时候需要设置
-            for(let edgeKey in dataLocal.roadEdges){
-              let roadId = dataLocal.roadEdges[edgeKey].parent
-              if(roadId == key ){
-                for(let roadKey in dataLocal.roads[key]){
-                  if( roadKey == 'leftEdgeId' && dataLocal.roads[key][roadKey] == dataLocal.roadEdges[edgeKey].vectorId){
-                    let leftEdge = dataService.getRoadEdge(road.leftEdgeId);
-                    if(dataLocal.roadEdges[edgeKey].style){
-                      leftEdge.setStyle(dataLocal.roadEdges[edgeKey].style)
-                    }
-                    if(dataLocal.roadEdges[edgeKey].weight){
-                      leftEdge.setWeight(dataLocal.roadEdges[edgeKey].weight)
-                    }
-                  }else if(roadKey == 'rightEdgeId' && dataLocal.roads[key][roadKey] == dataLocal.roadEdges[edgeKey].vectorId){
-                    let rightEdge = dataService.getRoadEdge(road.rightEdgeId);
-                    if(dataLocal.roadEdges[edgeKey].style){
-                      rightEdge.setStyle(dataLocal.roadEdges[edgeKey].style)
-                    }
-                    if(dataLocal.roadEdges[edgeKey].weight){
-                      rightEdge.setWeight(dataLocal.roadEdges[edgeKey].weight)
-                    }
-                  }
-                }
-              }
-            }
+          dataService.addRoad(road);
+          road.setWidth(dataLocal.roads[key].leftWidth, "left");
+          road.setWidth(dataLocal.roads[key].rightWidth, "right");
+          road.setWidth(dataLocal.roads[key].singleRoadWidth);
+          road.setMidDivide(dataLocal.roads[key].midDivide);
+          road.setLeftEdgeId(dataLocal.roads[key].leftEdgeId);
+          road.setRightEdgeId(dataLocal.roads[key].rightEdgeId);
+          road.setLeftLanes(dataLocal.roads[key].leftLanes);
+          road.setRightLanes(dataLocal.roads[key].rightLanes);
+          road.setSingleLanes(dataLocal.roads[key].singleLanes);
+        }
+      }
+
+      if (dataLocal.roadEdges) {
+        //当roadEdge有样式的时候需要设置
+        for (let edgeKey in dataLocal.roadEdges) {
+          let edge = dataLocal.roadEdges[edgeKey];
+          let newEdge = edgeService.create(
+            edge.start,
+            edge.end,
+            edge.vectorId,
+            edge.parent
+          );
+
+          if (edge.style) {
+            newEdge.setStyle(edge.style);
+          }
+          if (edge.weight) {
+            newEdge.setWeight(edge.weight);
           }
+          newEdge.setLineWidth(edge.lineWidth);
         }
       }
-      if(dataLocal.curveRoadPoints){
+
+      if (dataLocal.curveRoadPoints) {
         for (let key in dataLocal.curveRoadPoints) {
           let curveRoadPoint = curveRoadPointService.create(
             dataLocal.curveRoadPoints[key],
-            dataLocal.curveRoadPoints[key].vectorId,
+            dataLocal.curveRoadPoints[key].vectorId
           );
         }
       }
-      if(dataLocal.curveRoads){
+      if (dataLocal.curveRoads) {
         for (let key in dataLocal.curveRoads) {
-          console.log(dataLocal.curveRoads[key].points)
-          console.log(mathUtil.getCurvesByPoints(dataLocal.curveRoads[key].points, 0.2))
+          console.log(dataLocal.curveRoads[key].points);
+          console.log(
+            mathUtil.getCurvesByPoints(dataLocal.curveRoads[key].points, 0.2)
+          );
           let curveRoad = curveRoadService.create(
             dataLocal.curveRoads[key].startId,
             dataLocal.curveRoads[key].endId,
-            dataLocal.curveRoads[key].vectorId,
+            dataLocal.curveRoads[key].vectorId
           );
-    
         }
       }
+
+      if (dataLocal.crossPoints) {
+        for (let key in dataLocal.crossPoints) {
+          let crossPointData = dataLocal.crossPoints[key];
+          let crossPoint = crossPointService.createByVectorId(
+            { x: crossPointData.x, y: crossPointData.y },
+            crossPointData.edgeInfo1.id,
+            crossPointData.edgeInfo2.id,
+            crossPointData.edgeInfo1.dir,
+            crossPointData.edgeInfo2.dir,
+            crossPointData.vectorId
+          );
+          crossPoint.curves = JSON.parse(JSON.stringify(crossPointData.curves));
+          crossPoint.extremePoint = JSON.parse(
+            JSON.stringify(crossPointData.extremePoint)
+          );
+          dataService.addCrossPoint(crossPoint);
+        }
+      }
+
       if (dataLocal.texts) {
         for (let key in dataLocal.texts) {
           let text = textService.create(dataLocal.texts[key].center, key);
@@ -328,7 +366,7 @@ export default class Load {
               this.getXY(width, height, data3d.measures[i].pos[1]),
               VectorCategory.Line.MeasureLine
             );
-            if(data3d.measures[i].dis){
+            if (data3d.measures[i].dis) {
               line.value = data3d.measures[i].dis;
             }
           }
@@ -361,7 +399,7 @@ export default class Load {
             );
             text.setValue(data3d.fixPoints[i].text);
             text.setAngle(angle);
-            text.setDisplayPoint (true);
+            text.setDisplayPoint(true);
           }
         }
       }
@@ -387,13 +425,13 @@ export default class Load {
 
     const scale = res / (coordinate.zoom / coordinate.defaultZoom);
     dataService.setScale(scale);
-    console.log({...dataService.vectorData,Settings})
-    return {...dataService.vectorData,Settings};
+    console.log({ ...dataService.vectorData, Settings });
+    return { ...dataService.vectorData, Settings };
   }
 
   // 退出页面清除缓存及其他操作
   clear() {
-    console.error("clear")
+    console.error("clear");
     this.layer.uiControl.menu_clear(true);
     console.warn("clear");
   }

+ 6 - 0
src/graphic/Service/CrossPointService.js

@@ -13,6 +13,12 @@ export default class CrossPointService {
     return crossPoint;
   }
 
+  createByVectorId(position, edgeId1, edgeId2, dir1, dir2, vectorId) {
+    let crossPoint = this.create(position, vectorId);
+    crossPoint.setEdgeInfo(edgeId1, dir1, edgeId2, dir2);
+    return crossPoint;
+  }
+
   update(realRosition, point1, point2, edge1, edge2, dir1, dir2) {
     let crossPoint = dataService.getCrossPoint(edge1.vectorId, edge2.vectorId);
     const line1 = edgeService.getLine(edge1);

+ 30 - 0
src/graphic/Service/CurveRoadPointService.js

@@ -3,6 +3,10 @@ import { dataService } from "./DataService.js";
 import { mathUtil } from "../Util/MathUtil.js";
 import { curveRoadService } from "./CurveRoadService.js";
 import { curveEdgeService } from "./CurveEdgeService.js";
+import { roadService } from "./RoadService.js";
+import { roadPointService } from "./RoadPointService.js";
+import { uiService } from "./UIService.js";
+import { edgeService } from "./EdgeService.js";
 
 export default class CurveRoadPointService {
   constructor() {}
@@ -77,8 +81,34 @@ export default class CurveRoadPointService {
     }
     dataService.deleteCurveRoadPoint(curveRoadPointId);
     curveRoadService.setLanes(curveRoadId);
+    curveRoadService.setCurves(curveRoad);
     curveEdgeService.setCurves(leftCurveRoadEdge);
     curveEdgeService.setCurves(rightCurveRoadEdge);
+
+    //需要变成直路
+    if (curveRoad.points.length == 2) {
+      let roadPointStart = roadPointService.create(curveRoad.points[0]);
+      let roadPointEnd = roadPointService.create(curveRoad.points[1]);
+      uiService.setWayType(curveRoad.way);
+      uiService.setSingleRoadDrivewayCount(curveRoad.singleRoadDrivewayCount);
+      uiService.setRoadLeftDrivewayCount(curveRoad.leftDrivewayCount);
+      uiService.setRoadRightDrivewayCount(curveRoad.rightDrivewayCount);
+      let road = roadService.create(
+        roadPointStart.vectorId,
+        roadPointEnd.vectorId
+      );
+      road.setWidth(curveRoad.leftWidth, "left");
+      road.setWidth(curveRoad.rightWidth, "right");
+      road.setWidth(curveRoad.singleRoadWidth);
+      // road.setMidDivide(curveRoad.midDivide);
+      // road.setLeftLanes(curveRoad.leftLanes);
+      // road.setRightLanes(curveRoad.rightLanes);
+      // road.setSingleLanes(curveRoad.singleLanes);
+      dataService.addRoad(road);
+      edgeService.computerDefaultEdge(road.vectorId);
+      roadService.setLanes(road.vectorId);
+      dataService.deleteCurveRoad(curveRoad.vectorId);
+    }
   }
 }
 

+ 5 - 5
src/graphic/Service/LineService.js

@@ -160,12 +160,12 @@ export default class LineService {
       curvePoints[curvePoints.length - 1].vectorId,
       vectorId
     );
-    curveLine.points = JSON.parse(JSON.stringify(curvePoints));
-    for (let i = 0; i < curveLine.points.length; ++i) {
-      curveLine.points[i].setIndex(i);
-      curveLine.points[i].setPointParent(curveLine.vectorId);
+    curveLine.points = curvePoints;
+    for (let i = 0; i < curvePoints.length; ++i) {
+      curvePoints[i].setIndex(i);
+      curvePoints[i].setPointParent(curveLine.vectorId);
     }
-    curveLine.curves = mathUtil.getCurvesByPoints(curveLine.points);
+    curveLine.curves = mathUtil.getCurvesByPoints(curvePoints);
     dataService.addCurveLine(curveLine);
     return curveLine;
   }