浏览代码

绘图模块:撤销和恢复已完成。

xushiting 2 年之前
父节点
当前提交
b652ddcf40
共有 5 个文件被更改,包括 31 次插入17 次删除
  1. 18 10
      src/graphic/History/History.js
  2. 8 3
      src/graphic/History/HistoryUtil.js
  3. 1 1
      src/graphic/Layer.js
  4. 1 1
      src/graphic/Load.js
  5. 3 2
      src/graphic/Service/PointService.js

+ 18 - 10
src/graphic/History/History.js

@@ -10,6 +10,7 @@ import { svgService } from "../Service/SVGService";
 import { roadPointService } from "../Service/RoadPointService";
 import { lineService } from "../Service/LineService";
 import { circleService } from "../Service/CircleService";
+import { pointService } from "../Service/PointService";
 
 export default class History {
   constructor(layer) {
@@ -110,11 +111,15 @@ export default class History {
       if (item.handle == HistoryEvents.AddPoint) {
         dataService.deletePoint(item.point.id);
       } else if (item.handle == HistoryEvents.DeletePoint) {
-        let point = roadPointService.create(item.point, item.point.id);
+        let point = pointService.create(
+          item.point,
+          item.category,
+          item.point.id
+        );
         point.parent = JSON.parse(JSON.stringify(item.point.parent));
       } else if (item.handle == HistoryEvents.ModifyPoint) {
         const prePoint = item.prePoint;
-        let currentPoint = dataService.getRoadPoint(item.curPoint.id);
+        let currentPoint = dataService.getPoint(item.curPoint.id);
         historyUtil.assignPointFromPoint(currentPoint, prePoint);
       }
     }
@@ -127,7 +132,7 @@ export default class History {
         dataService.deleteLine(item.line.id);
       } else if (item.handle == HistoryEvents.DeleteLine) {
         const preLine = item.line;
-        let newLine = lineService.create(
+        let newLine = lineService.createByPointId(
           preLine.start,
           preLine.end,
           preLine.category,
@@ -149,10 +154,9 @@ export default class History {
         dataService.deleteCircle(item.circle.id);
       } else if (item.handle == HistoryEvents.DeleteCircle) {
         const preCircle = item.circle;
-        let newCircle = lineService.createCircle(
-          preCircle.start,
-          preCircle.end,
-          preCircle.category,
+        let newCircle = circleService.create(
+          preCircle.center,
+          preCircle.radius,
           preCircle.id
         );
         historyUtil.assignCircleFromCircle(newCircle, preCircle);
@@ -200,13 +204,17 @@ export default class History {
     for (let i = 0; i < itemForPoints.length; ++i) {
       const item = itemForPoints[i];
       if (item.handle == HistoryEvents.AddPoint) {
-        let newPoint = roadPointService.create(item.point, item.point.id);
+        let newPoint = pointService.create(
+          item.point,
+          item.category,
+          item.point.id
+        );
         historyUtil.assignPointFromPoint(newPoint, item.point);
       } else if (item.handle == HistoryEvents.DeletePoint) {
         dataService.deletePoint(item.point.id);
       } else if (item.handle == HistoryEvents.ModifyPoint) {
         const currentPoint = item.curPoint;
-        let prePoint = dataService.getRoadPoint(item.curPoint.id);
+        let prePoint = dataService.getPoint(item.curPoint.id);
         historyUtil.assignPointFromPoint(prePoint, currentPoint);
       }
     }
@@ -217,7 +225,7 @@ export default class History {
       const item = itemForLines[i];
       if (item.handle == HistoryEvents.AddLine) {
         const preLine = item.line;
-        let newLine = lineService.create(
+        let newLine = lineService.createByPointId(
           preLine.start,
           preLine.end,
           preLine.category,

+ 8 - 3
src/graphic/History/HistoryUtil.js

@@ -17,7 +17,8 @@ export default class HistoryUtil {
     if (
       point1.x == point2.x &&
       point1.y == point2.y &&
-      JSON.stringify(point1.parent) == JSON.stringify(point2.parent)
+      JSON.stringify(point1.parent) == JSON.stringify(point2.parent) &&
+      point1.category == point2.category
     ) {
       return false;
     } else {
@@ -84,14 +85,15 @@ export default class HistoryUtil {
     pointInfo.vectorId = point1.vectorId;
     pointInfo.position = { x: point2.x, y: point2.y };
     pointInfo.parent = JSON.parse(JSON.stringify(point2.parent));
+    pointInfo.category = point2.category;
     this.setPointInfo(pointInfo);
   }
 
   assignLineFromLine(line1, line2) {
     const lineInfo = {};
     lineInfo.vectorId = line1.vectorId;
-    lineInfo.start = line2.startId;
-    lineInfo.end = line2.endId;
+    lineInfo.start = line2.start;
+    lineInfo.end = line2.end;
     lineInfo.category = line2.category;
     this.setLineInfo(lineInfo);
   }
@@ -125,6 +127,7 @@ export default class HistoryUtil {
     data.id = point.vectorId;
     mathUtil.clonePoint(data, point);
     data.parent = JSON.parse(JSON.stringify(point.parent));
+    data.category = point.category;
     data.type = point.geoType;
     return data;
   }
@@ -134,6 +137,7 @@ export default class HistoryUtil {
     data.id = line.vectorId;
     data.start = line.startId;
     data.end = line.endId;
+    data.category = line.category;
     data.type = line.geoType;
     return data;
   }
@@ -179,6 +183,7 @@ export default class HistoryUtil {
     let point = dataService.getPoint(pointInfo.vectorId);
     mathUtil.clonePoint(point, pointInfo.position);
     point.parent = JSON.parse(JSON.stringify(pointInfo.parent));
+    point.category = pointInfo.category;
     return point;
   }
 

+ 1 - 1
src/graphic/Layer.js

@@ -58,7 +58,7 @@ export default class Layer {
       this.canvas.height = this.canvas.clientHeight;
       coordinate.init(this.canvas);
       draw.initContext(this.canvas);
-      this.history.init();
+      dataService.initVectorData();
       this.bindEvents();
     }
 

+ 1 - 1
src/graphic/Load.js

@@ -13,7 +13,6 @@ export default class Load {
   }
 
   load(dataLocal, data3d) {
-    dataService.initVectorData();
     if (dataLocal) {
       dataService.vectorData = JSON.parse(JSON.stringify(dataLocal));
     }
@@ -58,6 +57,7 @@ export default class Load {
         }
       }
     }
+    this.layer.history.init();
   }
 
   save() {

+ 3 - 2
src/graphic/Service/PointService.js

@@ -6,10 +6,11 @@ import { mathUtil } from "../Util/MathUtil.js";
 export default class PointService {
   constructor() {}
 
-  create(position, categoryType) {
-    let point = new Point(position);
+  create(position, categoryType, vectorId) {
+    let point = new Point(position, vectorId);
     point.setCategory(categoryType);
     dataService.addPoint(point);
+    return point;
   }
 }