xushiting 2 年之前
父节点
当前提交
111cbbf101
共有 3 个文件被更改,包括 86 次插入9 次删除
  1. 9 5
      src/graphic/Controls/UIControl.js
  2. 13 4
      src/graphic/Service/DataService.js
  3. 64 0
      src/graphic/Service/PointService.js

+ 9 - 5
src/graphic/Controls/UIControl.js

@@ -20,6 +20,7 @@ import { addLine } from "./AddLine.js";
 import VectorCategory from "../enum/VectorCategory.js";
 // import { floorplanData } from "../VectorData.js";
 import Message from "@/components/base/components/message/message.vue";
+import { pointService } from "../Service/PointService.js";
 
 export default class UIControl {
   constructor(layer, newsletter, graphicStateUI) {
@@ -123,6 +124,9 @@ export default class UIControl {
   //删除按钮
   deleteVector(vectorId, geoType) {
     switch (geoType) {
+      case VectorType.Point:
+        pointService.deletePoint(vectorId);
+        break;
       case VectorType.Line:
         dataService.deleteLine(vectorId);
         break;
@@ -282,15 +286,15 @@ export default class UIControl {
 
   // 进入持续添加出确认与取消框
   showConfirm() {
-    this.graphicStateUI.continuedMode = true
+    this.graphicStateUI.continuedMode = true;
   }
   confirmEntry() {
-    console.log("确认")
-    this.graphicStateUI.continuedMode = false
+    console.log("确认");
+    this.graphicStateUI.continuedMode = false;
   }
   confirmCancel() {
-    console.log("取消")
-    this.graphicStateUI.continuedMode = false
+    console.log("取消");
+    this.graphicStateUI.continuedMode = false;
   }
 
   hidePrompt() {

+ 13 - 4
src/graphic/Service/DataService.js

@@ -2,6 +2,7 @@ import Line from "../Geometry/Line.js";
 import CurveLine from "../Geometry/CurveLine.js";
 import VectorType from "../enum/VectorType.js";
 import { coordinate } from "../Coordinate.js";
+import VectorCategory from "../enum/VectorCategory.js";
 
 export class DataService {
   constructor() {
@@ -135,7 +136,10 @@ export class DataService {
     if (start) {
       let startParent = start.getParent();
       delete startParent[lineId];
-      if (Object.keys(startParent).length == 0) {
+      if (
+        Object.keys(startParent).length == 0 &&
+        start.getCategory() != VectorCategory.Point.BasePoint
+      ) {
         this.deletePoint(line.startId);
       }
     }
@@ -144,7 +148,10 @@ export class DataService {
     if (end) {
       let endParent = end.getParent();
       delete endParent[lineId];
-      if (Object.keys(endParent).length == 0) {
+      if (
+        Object.keys(endParent).length == 0 &&
+        end.getCategory() != VectorCategory.Point.BasePoint
+      ) {
         this.deletePoint(line.endId);
       }
     }
@@ -167,8 +174,10 @@ export class DataService {
 
   deletePoint(pointId) {
     let point = this.getPoint(pointId);
-    delete this.vectorData.points[pointId];
-    point = null;
+    if (point) {
+      delete this.vectorData.points[pointId];
+      point = null;
+    }
   }
 
   //圆圈

+ 64 - 0
src/graphic/Service/PointService.js

@@ -4,6 +4,7 @@ import { dataService } from "./DataService.js";
 import VectorCategory from "../enum/VectorCategory.js";
 import { mathUtil } from "../Util/MathUtil.js";
 import { lineService } from "./LineService.js";
+import Settings from "../Settings.js";
 export default class PointService {
   constructor() {}
 
@@ -41,6 +42,69 @@ export default class PointService {
       dataService.deletePoint(pointId1);
     }
   }
+
+  deletePoint(pointId) {
+    let point = dataService.getPoint(pointId);
+    const category = point.getCategory();
+    if (category == VectorCategory.Point.NormalPoint) {
+      dataService.deletePoint(pointId); //暂时简单粗暴
+    } else if (category == VectorCategory.Point.BasePoint) {
+      this.deleteBasePoint(pointId);
+    } else if (category == VectorCategory.Point.TestPoint) {
+      this.deleteTestPoint(pointId);
+    }
+  }
+
+  deleteBasePoint(basePointId) {
+    let points = dataService.getPoints();
+    let needDeletePointIds = [];
+    for (let key in points) {
+      let point = dataService.getPoint(key);
+      if (point.vectorId == basePointId) {
+        needDeletePointIds.push(basePointId);
+      } else if (point.linkedBasePointId == basePointId) {
+        needDeletePointIds.push(key);
+      }
+    }
+    let lines = dataService.getLines();
+    for (let key in lines) {
+      let line = dataService.getLine(key);
+      if (
+        needDeletePointIds.indexOf(line.startId) > -1 ||
+        needDeletePointIds.indexOf(line.endId) > -1
+      ) {
+        dataService.deleteLine(key);
+      }
+    }
+    dataService.deletePoint(basePointId);
+    if (Settings.selectBasePointId == basePointId) {
+      Settings.selectBasePointId = null;
+    }
+  }
+
+  deleteTestPoint(testPointId) {
+    let points = dataService.getPoints();
+    let needDeletePointIds = [];
+    for (let key in points) {
+      let point = dataService.getPoint(key);
+      if (point.vectorId == testPointId) {
+        needDeletePointIds.push(testPointId);
+      } else if (point.linkedTestPointId == testPointId) {
+        needDeletePointIds.push(key);
+      }
+    }
+    let lines = dataService.getLines();
+    for (let key in lines) {
+      let line = dataService.getLine(key);
+      if (
+        needDeletePointIds.indexOf(line.startId) > -1 ||
+        needDeletePointIds.indexOf(line.endId) > -1
+      ) {
+        dataService.deleteLine(key);
+      }
+    }
+    dataService.deletePoint(testPointId);
+  }
 }
 
 const pointService = new PointService();