xushiting 2 years ago
parent
commit
73d034ae40

+ 0 - 1
src/graphic/Controls/MoveText.js

@@ -6,7 +6,6 @@ export default class MoveText {
   moveFullText(position, textId) {
     let text = dataService.getText(textId);
     mathUtil.clonePoint(text.center, position);
-    text.setPoints2d();
   }
 }
 

+ 7 - 103
src/graphic/Geometry/Text.js

@@ -9,115 +9,19 @@ export default class Text extends Geometry {
   constructor(center, vectorId) {
     super();
     this.center = center;
-    this.points2d = [];
-    this.title = "";
-    this.des = ""; //面积
-    this.unit = "m"; //或者ft
-    this.name = "标注";
-    this.adding = true;
-
-    this.sideWidth = 30; //像素
-    this.sideThickness = 30; //像素
-
+    this.value = "";
     this.geoType = VectorType.Text;
     this.setId(vectorId);
   }
 
-  isContain(position) {
-    let points = [];
-    points.push(this.points2d[0]);
-    points.push(this.points2d[1]);
-    points.push(this.points2d[2]);
-    points.push(this.points2d[3]);
-    return mathUtil.isPointInPoly(position, points);
-  }
-
-  setPoints2d() {
-    this.points2d = [];
-    const minX =
-      this.center.x -
-      ((this.sideWidth / coordinate.res) * coordinate.defaultZoom) /
-        coordinate.zoom /
-        2;
-    const minY =
-      this.center.y -
-      ((this.sideThickness / coordinate.res) * coordinate.defaultZoom) /
-        coordinate.zoom /
-        2;
-    const maxX =
-      this.center.x +
-      ((this.sideWidth / coordinate.res) * coordinate.defaultZoom) /
-        coordinate.zoom /
-        2;
-    const maxY =
-      this.center.y +
-      ((this.sideThickness / coordinate.res) * coordinate.defaultZoom) /
-        coordinate.zoom /
-        2;
-
-    const point1 = {
-      x: minX,
-      y: maxY,
-    };
-
-    const point2 = {
-      x: maxX,
-      y: maxY,
-    };
-
-    const point3 = {
-      x: maxX,
-      y: minY,
-    };
-
-    const point4 = {
-      x: minX,
-      y: minY,
+  setCenter(center) {
+    this.center = {
+      x: center.x,
+      y: center.y,
     };
-
-    this.points2d.push(point1);
-    this.points2d.push(point2);
-    this.points2d.push(point3);
-    this.points2d.push(point4);
-
-    //-
-    let dx = (point1.x - this.center.x) / 2;
-    //+
-    let dy = (point1.y - this.center.y) / 2;
-
-    this.points2d.push({
-      x: point1.x - dx,
-      y: point1.y - dy,
-    });
-
-    this.points2d.push({
-      x: point2.x + dx,
-      y: point1.y - dy,
-    });
-
-    this.points2d.push({
-      x: this.center.x,
-      y: point1.y - dy,
-    });
-
-    this.points2d.push({
-      x: this.center.x,
-      y: point3.y + dy,
-    });
-  }
-
-  setTitle(title) {
-    this.title = title;
-  }
-
-  setDes(des) {
-    this.des = des;
-  }
-  setUnit(unit) {
-    this.unit = unit;
   }
 
-  setAdding(flag) {
-    this.adding = flag;
+  setValue(value) {
+    this.value = value;
   }
 }

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

@@ -171,7 +171,7 @@ export default class History {
       if (item.handle == HistoryEvents.AddText) {
         dataService.deleteText(item.text.id);
       } else if (item.handle == HistoryEvents.DeleteText) {
-        let newText = textService.createText(item.text.center, item.text.id);
+        let newText = textService.create(item.text.center, item.text.id);
         historyUtil.assignTextFromText(newText, item.text);
       } else if (item.handle == HistoryEvents.ModifyText) {
         const preText = item.preText;
@@ -244,7 +244,7 @@ export default class History {
     for (let i = 0; i < itemForTexts.length; ++i) {
       const item = itemForTexts[i];
       if (item.handle == HistoryEvents.AddText) {
-        let vText = textService.createText(item.text.center, item.text.id);
+        let vText = textService.create(item.text.center, item.text.id);
         historyUtil.assignTextFromText(vText, item.text);
       } else if (item.handle == HistoryEvents.DeleteText) {
         dataService.deleteText(item.text.id);

+ 4 - 9
src/graphic/History/HistoryUtil.js

@@ -51,7 +51,7 @@ export default class HistoryUtil {
   isDifferentForTexts(text1, text2) {
     if (
       mathUtil.equalPoint(text1.center, text2.center) &&
-      text1.des == text2.des
+      text1.value == text2.value
     ) {
       return false;
     } else {
@@ -96,10 +96,8 @@ export default class HistoryUtil {
   assignTextFromText(text1, text2) {
     const textInfo = {};
     textInfo.vectorId = text1.vectorId;
-    textInfo.des = text2.des;
+    textInfo.value = text2.value;
     textInfo.center = JSON.parse(JSON.stringify(text2.center));
-    textInfo.points2d = JSON.parse(JSON.stringify(text2.points));
-    textInfo.adding = false;
     this.setTextInfo(textInfo);
   }
 
@@ -137,8 +135,7 @@ export default class HistoryUtil {
     data.type = text.geoType;
     data.center = {};
     mathUtil.clonePoint(data.center, text.center);
-    data.points = [].concat(text.points2d);
-    data.des = text.des;
+    data.value = text.value;
     return data;
   }
 
@@ -175,9 +172,7 @@ export default class HistoryUtil {
     let text = dataService.getText(textInfo.vectorId);
     text.vectorId = textInfo.vectorId;
     text.center = JSON.parse(JSON.stringify(textInfo.center));
-    text.points2d = JSON.parse(JSON.stringify(textInfo.points2d));
-    text.des = textInfo.des;
-    text.adding = textInfo.adding;
+    text.value = textInfo.value;
   }
 }
 

+ 1 - 1
src/graphic/Layer.js

@@ -458,7 +458,7 @@ export default class Layer {
       case LayerEvents.AddText:
         needAutoRedraw = true;
         if (draggingItem == null) {
-          const text = textService.createText(position);
+          const text = textService.create(position);
           if (text.vectorId) {
             stateService.setSelectItem(
               text.vectorId,

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

@@ -6,10 +6,9 @@ export default class TextService {
   constructor() {}
 
   // 新建text
-  createText(position, textId, floor) {
+  create(position, textId) {
     let text = new Text(position, textId);
-    text.setPoints2d();
-    dataService.addText(text, floor);
+    dataService.addText(text);
     return text;
   }
 }