xushiting 2 年之前
父节点
当前提交
1075faf51e

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

@@ -76,6 +76,8 @@ export default class UIControl {
           stateService.setEventName(LayerEvents.AddCircle);
           stateService.setEventName(LayerEvents.AddCircle);
         } else if (selectUI == UIEvents.Text) {
         } else if (selectUI == UIEvents.Text) {
           stateService.setEventName(LayerEvents.AddText);
           stateService.setEventName(LayerEvents.AddText);
+        } else if (selectUI == UIEvents.SVG) {
+          stateService.setEventName(LayerEvents.AddSVG);
         } else if (selectUI == UIEvents.Img) {
         } else if (selectUI == UIEvents.Img) {
           stateService.setEventName(LayerEvents.Img);
           stateService.setEventName(LayerEvents.Img);
         }
         }

+ 42 - 0
src/graphic/History/Change.js

@@ -23,6 +23,8 @@ export default class Change {
     this.lastData.circles = JSON.parse(
     this.lastData.circles = JSON.parse(
       JSON.stringify(dataService.getCircles())
       JSON.stringify(dataService.getCircles())
     );
     );
+    this.lastData.texts = JSON.parse(JSON.stringify(dataService.getTexts()));
+    this.lastData.svgs = JSON.parse(JSON.stringify(dataService.getSVGs()));
   }
   }
 
 
   operate() {
   operate() {
@@ -243,6 +245,46 @@ export default class Change {
       this.currentData.circles.push(item);
       this.currentData.circles.push(item);
     }
     }
   }
   }
+
+  compareSVGs() {
+    this.currentData.svgs = [];
+    const svgs = dataService.getSVGs();
+
+    for (const key in svgs) {
+      const svg = svgs[key];
+      const lastSVG = this.lastData.svgs[key];
+
+      // 不存在意味着增加
+      if (!lastSVG) {
+        const item = {
+          handle: HistoryEvents.AddSVG,
+          svg: historyUtil.getDataForSVG(svg),
+        };
+        this.currentData.svgs.push(item);
+      } else {
+        if (!historyUtil.isDifferentForSVGs(svg, lastSVG)) {
+          delete this.lastData.svgs[key];
+          continue;
+        } else {
+          const item = {
+            handle: HistoryEvents.ModifySVG,
+            preSVG: historyUtil.getDataForSVG(lastSVG),
+            curSVG: historyUtil.getDataForSVG(svg),
+          };
+          this.currentData.svgs.push(item);
+        }
+      }
+      delete this.lastData.svgs[key];
+    }
+
+    for (const key in this.lastData.svgs) {
+      const item = {
+        handle: HistoryEvents.DeleteSVG,
+        svg: historyUtil.getDataForSVG(this.lastData.svgs[key]),
+      };
+      this.currentData.svgs.push(item);
+    }
+  }
 }
 }
 
 
 const change = new Change();
 const change = new Change();

+ 35 - 1
src/graphic/History/History.js

@@ -6,6 +6,7 @@ import HistoryEvents from "../enum/HistoryEvents";
 import { historyService } from "../Service/HistoryService";
 import { historyService } from "../Service/HistoryService";
 import { textService } from "../Service/TextService";
 import { textService } from "../Service/TextService";
 import { roadService } from "../Service/RoadService";
 import { roadService } from "../Service/RoadService";
+import { svgService } from "../Service/SVGService";
 import { roadPointService } from "../Service/RoadPointService";
 import { roadPointService } from "../Service/RoadPointService";
 import { lineService } from "../Service/LineService";
 import { lineService } from "../Service/LineService";
 import { circleService } from "../Service/CircleService";
 import { circleService } from "../Service/CircleService";
@@ -96,7 +97,7 @@ export default class History {
       this.goPreForLines(item.lines);
       this.goPreForLines(item.lines);
       this.goPreForCircles(item.circles);
       this.goPreForCircles(item.circles);
       this.goPreForTexts(item.texts);
       this.goPreForTexts(item.texts);
-
+      this.goPreForSVGs(item.svgs);
       historyService.undoHistoryRecord();
       historyService.undoHistoryRecord();
       change.saveCurrentInfo();
       change.saveCurrentInfo();
       this.setState();
       this.setState();
@@ -181,6 +182,22 @@ export default class History {
     }
     }
   }
   }
 
 
+  goPreForSVGs(itemForSVGs) {
+    for (let i = 0; i < itemForSVGs.length; ++i) {
+      const item = itemForSVGs[i];
+      if (item.handle == HistoryEvents.AddSVG) {
+        dataService.deleteSVG(item.svg.id);
+      } else if (item.handle == HistoryEvents.DeleteSVG) {
+        let newSVG = svgService.create(item.svg.center, item.svg.id);
+        historyUtil.assignSVGFromSVG(newSVG, item.svg);
+      } else if (item.handle == HistoryEvents.ModifySVG) {
+        const preSVG = item.preSVG;
+        let currentSVG = dataService.getSVG(item.curSVG.id);
+        historyUtil.assignSVGFromSVG(currentSVG, preSVG);
+      }
+    }
+  }
+
   goNextForPoints(itemForPoints) {
   goNextForPoints(itemForPoints) {
     for (let i = 0; i < itemForPoints.length; ++i) {
     for (let i = 0; i < itemForPoints.length; ++i) {
       const item = itemForPoints[i];
       const item = itemForPoints[i];
@@ -256,6 +273,22 @@ export default class History {
     }
     }
   }
   }
 
 
+  goNextForSVGs(itemForSVGs) {
+    for (let i = 0; i < itemForSVGs.length; ++i) {
+      const item = itemForSVGs[i];
+      if (item.handle == HistoryEvents.AddSVG) {
+        let vSVG = svgService.create(item.svg.center, item.svg.id);
+        historyUtil.assignSVGFromSVG(vSVG, item.svg);
+      } else if (item.handle == HistoryEvents.DeleteSVG) {
+        dataService.deleteSVG(item.svg.id);
+      } else if (item.handle == HistoryEvents.ModifySVG) {
+        const currentSVG = item.curSVG;
+        let preSVG = dataService.getSVG(item.curSVG.id);
+        historyUtil.assignSVGFromSVG(preSVG, currentSVG);
+      }
+    }
+  }
+
   // 恢复
   // 恢复
   goNextState() {
   goNextState() {
     historyService.redoHistoryRecord();
     historyService.redoHistoryRecord();
@@ -267,6 +300,7 @@ export default class History {
       this.goNextForLines(item.lines);
       this.goNextForLines(item.lines);
       this.goNextForCircles(item.circles);
       this.goNextForCircles(item.circles);
       this.goNextForTexts(item.texts);
       this.goNextForTexts(item.texts);
+      this.goNextForSVGs(item.svgs);
       change.saveCurrentInfo();
       change.saveCurrentInfo();
       this.setState();
       this.setState();
     } else {
     } else {

+ 0 - 6
src/graphic/History/HistoryUI.js

@@ -1,6 +0,0 @@
-export default class HistoryUI {
-  constructor() {}
-}
-
-const historyUI = new HistoryUI();
-export { historyUI };

+ 36 - 0
src/graphic/History/HistoryUtil.js

@@ -59,6 +59,17 @@ export default class HistoryUtil {
     }
     }
   }
   }
 
 
+  isDifferentForSVGs(svg1, svg2) {
+    if (
+      mathUtil.equalPoint(svg1.center, svg2.center) &&
+      svg1.name == svg2.name
+    ) {
+      return false;
+    } else {
+      return true;
+    }
+  }
+
   // // road2赋值给road1
   // // road2赋值给road1
   // assignRoadFromRoad(road1, road2) {
   // assignRoadFromRoad(road1, road2) {
   //   const roadInfo = {};
   //   const roadInfo = {};
@@ -101,6 +112,14 @@ export default class HistoryUtil {
     this.setTextInfo(textInfo);
     this.setTextInfo(textInfo);
   }
   }
 
 
+  assignSVGFromSVG(svg1, svg2) {
+    const svgInfo = {};
+    svgInfo.vectorId = svg1.vectorId;
+    svgInfo.name = svg2.name;
+    svgInfo.center = JSON.parse(JSON.stringify(svg2.center));
+    this.setSVGInfo(svgInfo);
+  }
+
   getDataForPoint(point) {
   getDataForPoint(point) {
     const data = {};
     const data = {};
     data.id = point.vectorId;
     data.id = point.vectorId;
@@ -139,6 +158,16 @@ export default class HistoryUtil {
     return data;
     return data;
   }
   }
 
 
+  getDataForSVG(svg) {
+    const data = {};
+    data.id = svg.vectorId;
+    data.type = svg.geoType;
+    data.center = {};
+    mathUtil.clonePoint(data.center, svg.center);
+    data.name = svg.name;
+    return data;
+  }
+
   // setRoadInfo(roadInfo) {
   // setRoadInfo(roadInfo) {
   //   let road = dataService.getRoad(roadInfo.vectorId);
   //   let road = dataService.getRoad(roadInfo.vectorId);
   //   road.start = roadInfo.start;
   //   road.start = roadInfo.start;
@@ -174,6 +203,13 @@ export default class HistoryUtil {
     text.center = JSON.parse(JSON.stringify(textInfo.center));
     text.center = JSON.parse(JSON.stringify(textInfo.center));
     text.value = textInfo.value;
     text.value = textInfo.value;
   }
   }
+
+  setSVGInfo(svgInfo) {
+    let svg = dataService.getSVG(svgInfo.vectorId);
+    svg.vectorId = svgInfo.vectorId;
+    svg.center = JSON.parse(JSON.stringify(svgInfo.center));
+    svg.name = svgInfo.name;
+  }
 }
 }
 
 
 const historyUtil = new HistoryUtil();
 const historyUtil = new HistoryUtil();

+ 0 - 2
src/graphic/Layer.js

@@ -932,8 +932,6 @@ export default class Layer {
     elementService.hideAll();
     elementService.hideAll();
   }
   }
 
 
-  update() {}
-
   revokeHistory() {
   revokeHistory() {
     this.history.goPreState();
     this.history.goPreState();
     this.renderer.autoRedraw();
     this.renderer.autoRedraw();

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

@@ -54,6 +54,7 @@ export class DataService {
     //基准点
     //基准点
     this.vectorData.basePointIds = [];
     this.vectorData.basePointIds = [];
     this.vectorData.texts = {};
     this.vectorData.texts = {};
+    this.vectorData.SVGs = {};
   }
   }
 
 
   //网格
   //网格

+ 4 - 0
src/graphic/enum/HistoryEvents.js

@@ -22,5 +22,9 @@ const HistoryEvents = {
   AddCircle: "addCircle",
   AddCircle: "addCircle",
   DeleteCirclee: "deleteCircle",
   DeleteCirclee: "deleteCircle",
   ModifyCircle: "modifyCircle",
   ModifyCircle: "modifyCircle",
+
+  AddSVG: "addSVG",
+  DeleteSVG: "deleteSVG",
+  ModifySVG: "modifySVG",
 };
 };
 export default HistoryEvents;
 export default HistoryEvents;

+ 2 - 0
src/graphic/enum/UIEvents.js

@@ -9,6 +9,8 @@ const UIEvents = {
   MeasureLine: "measure",
   MeasureLine: "measure",
   // 文字
   // 文字
   Text: "text", //这个是标注,暂时这样
   Text: "text", //这个是标注,暂时这样
+  //svg
+  SVG: "svg",
   // 放大镜
   // 放大镜
   magnifier: "magnifier",
   magnifier: "magnifier",