xushiting 2 éve
szülő
commit
328a07138f

+ 2 - 2
src/graphic/History/History.js

@@ -110,7 +110,7 @@ export default class History {
     for (let i = 0; i < itemForPoints.length; ++i) {
       const item = itemForPoints[i];
       if (item.handle == HistoryEvents.AddPoint) {
-        historyUtil.deletePoint(item.point.id);
+        dataService.deletePoint(item.point.id);
       } else if (item.handle == HistoryEvents.DeletePoint) {
         let point = roadPointService.create(item.point, item.point.id);
         point.parent = JSON.parse(JSON.stringify(item.point.parent));
@@ -218,7 +218,7 @@ export default class History {
         let newPoint = roadPointService.create(item.point, item.point.id);
         historyUtil.assignPointFromPoint(newPoint, item.point);
       } else if (item.handle == HistoryEvents.DeletePoint) {
-        historyUtil.deletePoint(item.point.id);
+        dataService.deletePoint(item.point.id);
       } else if (item.handle == HistoryEvents.ModifyPoint) {
         const currentPoint = item.curPoint;
         let prePoint = dataService.getRoadPoint(item.curPoint.id);

+ 86 - 32
src/graphic/History/HistoryUtil.js

@@ -66,14 +66,14 @@ export default class HistoryUtil {
     }
   }
 
-  // road2赋值给road1
-  assignRoadFromRoad(road1, road2) {
-    const roadInfo = {};
-    roadInfo.vectorId = road1.vectorId;
-    roadInfo.start = road2.startId;
-    roadInfo.end = road2.endId;
-    this.setRoadInfo(roadInfo);
-  }
+  // // road2赋值给road1
+  // assignRoadFromRoad(road1, road2) {
+  //   const roadInfo = {};
+  //   roadInfo.vectorId = road1.vectorId;
+  //   roadInfo.start = road2.startId;
+  //   roadInfo.end = road2.endId;
+  //   this.setRoadInfo(roadInfo);
+  // }
 
   assignPointFromPoint(point1, point2) {
     const pointInfo = {};
@@ -83,6 +83,30 @@ export default class HistoryUtil {
     this.setPointInfo(pointInfo);
   }
 
+  assignLineFromLine(line1, line2) {
+    const lineInfo = {};
+    lineInfo.vectorId = line1.vectorId;
+    lineInfo.start = line2.startId;
+    lineInfo.end = line2.endId;
+    this.setLineInfo(lineInfo);
+  }
+
+  assignSimpleLineFromSimpleLine(simpleLine1, simpleLine2) {
+    const simpleLineInfo = {};
+    simpleLineInfo.vectorId = simpleLine1.vectorId;
+    simpleLineInfo.start = simpleLine2.start;
+    simpleLineInfo.end = simpleLine2.end;
+    this.setSimpleLineInfo(simpleLineInfo);
+  }
+
+  assignLineFromLine(line1, line2) {
+    const lineInfo = {};
+    lineInfo.vectorId = line1.vectorId;
+    lineInfo.start = line2.startId;
+    lineInfo.end = line2.endId;
+    this.setLineInfo(lineInfo);
+  }
+
   assignTextFromText(text1, text2) {
     const textInfo = {};
     textInfo.vectorId = text1.vectorId;
@@ -93,14 +117,6 @@ export default class HistoryUtil {
     this.setTextInfo(textInfo);
   }
 
-  deletePoint(pointId) {
-    const point = dataService.getRoadPoint(pointId);
-    const parent = point.parent;
-    for (const key in parent) {
-      dataService.deleteRoadPoint(pointId, key);
-    }
-  }
-
   getDataForPoint(point) {
     const data = {};
     data.id = point.vectorId;
@@ -110,12 +126,33 @@ export default class HistoryUtil {
     return data;
   }
 
-  getDataForRoad(road) {
+  getDataForLine(line) {
+    const data = {};
+    data.id = line.vectorId;
+    data.start = line.startId;
+    data.end = line.endId;
+    data.type = line.geoType;
+    return data;
+  }
+
+  getDataForSimpleLine(simpleLine) {
     const data = {};
-    data.id = road.vectorId;
-    data.start = road.startId;
-    data.end = road.endId;
-    data.type = road.geoType;
+    data.id = simpleLine.vectorId;
+    data.start = {};
+    mathUtil.clonePoint(data.start, simpleLine.start);
+    data.end = {};
+    mathUtil.clonePoint(data.end, simpleLine.end);
+    data.type = simpleLine.geoType;
+    return data;
+  }
+
+  getDataForCircle(circle) {
+    const data = {};
+    data.id = circle.vectorId;
+    data.center = {};
+    mathUtil.clonePoint(data.center, circle.center);
+    data.radius = circle.radius;
+    data.type = circle.geoType;
     return data;
   }
 
@@ -130,24 +167,41 @@ export default class HistoryUtil {
     return data;
   }
 
-  getDataForRes(res) {
-    return res;
-  }
-
-  setRoadInfo(roadInfo) {
-    let road = dataService.getRoad(roadInfo.vectorId);
-    road.start = roadInfo.start;
-    road.end = roadInfo.end;
-    return road;
-  }
+  // setRoadInfo(roadInfo) {
+  //   let road = dataService.getRoad(roadInfo.vectorId);
+  //   road.start = roadInfo.start;
+  //   road.end = roadInfo.end;
+  //   return road;
+  // }
 
   setPointInfo(pointInfo) {
-    let point = dataService.getRoadPoint(pointInfo.vectorId);
+    let point = dataService.getPoint(pointInfo.vectorId);
     mathUtil.clonePoint(point, pointInfo.position);
     point.parent = JSON.parse(JSON.stringify(pointInfo.parent));
     return point;
   }
 
+  setLineInfo(lineInfo) {
+    let line = dataService.getLine(lineInfo.vectorId);
+    line.startId = lineInfo.start;
+    line.endId = lineInfo.end;
+    return line;
+  }
+
+  setSimpleLineInfo(simpleLineInfo) {
+    let simpleLine = dataService.getSimpleLine(simpleLineInfo.vectorId);
+    simpleLine.start = simpleLineInfo.start;
+    simpleLine.end = simpleLineInfo.end;
+    return simpleLine;
+  }
+
+  setCircleInfo(circleInfo) {
+    let circle = dataService.getCircle(circleInfo.vectorId);
+    circle.center = circleInfo.center;
+    circle.radius = circleInfo.radius;
+    return circle;
+  }
+
   setTextInfo(textInfo) {
     let text = dataService.getText(textInfo.vectorId);
     text.vectorId = textInfo.vectorId;

+ 34 - 1
src/graphic/Service/DataService.js

@@ -149,8 +149,41 @@ export class DataService {
     this.vectorData.points[point.vectorId] = point;
   }
 
+  // deletePoint(pointId) {
+  //   delete this.vectorData.points[pointId];
+  // }
+
+  deletePoint(pointId, lineId) {
+    let point = this.getPoint(pointId);
+    //有可能先删除墙,导致点没了
+    if (point) {
+      if (Object.keys(point.parent).length == 0) {
+        point = null;
+        delete this.vectorData.points[pointId];
+      } else if (Object.keys(point.parent).length == 1 && !lineId) {
+        delete this.vectorData.points[pointId];
+      } else if (
+        Object.keys(point.parent).length == 1 &&
+        point.parent[lineId]
+      ) {
+        delete this.vectorData.points[pointId];
+      } else if (
+        Object.keys(point.parent).length == 1 &&
+        !point.parent[lineId]
+      ) {
+        return;
+      } else {
+        delete point.parent[lineId];
+      }
+    }
+  }
+
   deletePoint(pointId) {
-    delete this.vectorData.points[pointId];
+    const point = dataService.getRoadPoint(pointId);
+    const parent = point.parent;
+    for (const key in parent) {
+      dataService.deleteRoadPoint(pointId, key);
+    }
   }
 
   //圆圈

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

@@ -848,7 +848,7 @@ export default class RoadService {
       x: (startPoint.x + endPoint.x) / 2,
       y: (startPoint.y + endPoint.y) / 2,
     };
-    const line = this.getMidLine(road);
+    let line = this.getMidLine(road);
     const startJoin1 = mathUtil.getJoinLinePoint(leftEdge.start, line);
     const startJoin2 = mathUtil.getJoinLinePoint(rightEdge.start, line);
     const distance1 = mathUtil.getDistance(startJoin1, mid);