yunxing 4 years ago
parent
commit
f57e034cce
2 changed files with 29 additions and 15 deletions
  1. 2 1
      src/components/mapClass/EditScence.ts
  2. 27 14
      src/lib/items/SEquipmentItem.ts

+ 2 - 1
src/components/mapClass/EditScence.ts

@@ -1110,8 +1110,9 @@ export class EditScence extends SGraphScene {
      * @param
      */
     addEquipment(event: SMouseEvent): void {
-        let equipmentItem = new SEquipmentItem(null, event, { a: 1, b: 2 });
+        let equipmentItem = new SEquipmentItem(null, { 名称: "设备1", 温度: "25℃" });
         // equipmentItem.moveable = true;
+        equipmentItem.moveTo(event.x, event.y);
         this.addItem(equipmentItem);
         this.grabItem = equipmentItem;
         this.focusItem = equipmentItem;

+ 27 - 14
src/lib/items/SEquipmentItem.ts

@@ -5,13 +5,13 @@ import { SMouseEvent } from "@saga-web/base/lib";
 export class SEquipmentItem extends SObjectItem {
     // img对象
     img: SImageItem = new SImageItem(this);
-    textObj: STextItem[] = [];
+    textArr: STextItem[] = [];
     /**
      *
      * @param parent 父类
      * @param textInfo  需要展示的节点信息
      */
-    constructor(parent: SGraphItem | null, event: SMouseEvent, textInfo?: object) {
+    constructor(parent: SGraphItem | null, textInfo?: object) {
         super(parent);
         console.log(textInfo);
         // this.img.url = `http://adm.sagacloud.cn:8080/doc/assets/img/logo.png`;
@@ -20,19 +20,25 @@ export class SEquipmentItem extends SObjectItem {
         this.img.height = 50;
         this.width = 100;
         this.height = 100;
-        this.moveTo(event.x, event.y);
+
         this.moveable = false;
         this.zOrder = ItemOrder.textOrder;
-        this.textObj = [];
-        // 有信息点信息,绘制信息点信息
+        this.textArr = [];
+        // 有信息点信息,绘制信息点信息
         if (textInfo) {
+            let index = 0;
             for (let key in textInfo) {
-                let text = new STextItem(this);
-                text.moveable = true;
-                text.backgroundColor = SColor.White;
-                text.font.size = 18;
-                text.text = `${key}:${textInfo[key]}`;
-                this.textObj.push(text);
+                let textItem = new STextItem(this);
+                textItem.moveable = true;
+                textItem.backgroundColor = SColor.White;
+                textItem.font.size = 14;
+                // 偏移二分之一文本高度
+                // textItem.moveTo(17, -(textItem.height * 0.5));
+                textItem.moveTo(17, index * 20 - 10);
+                // @ts-ignore
+                textItem.text = `${key} : ${textInfo[key]}`;
+                this.textArr.push(textItem);
+                index++;
             }
         }
     }
@@ -43,7 +49,14 @@ export class SEquipmentItem extends SObjectItem {
      * @return  SRect   所有子对象的并集
      * */
     boundingRect(): SRect {
-        return new SRect(-this.width / 2, -this.height / 2, this.width, this.height);
+        //  return new SRect(-this.width / 2, -this.height / 2, this.width, this.height);
+        let rect = this.img.boundingRect().adjusted(this.img.pos.x, this.img.pos.y, 0, 0);
+        if (this.textArr.length) {
+            for (let text of this.textArr) {
+                rect = rect.unioned(text.boundingRect().adjusted(text.pos.x, text.pos.y, 0, 0));
+            }
+        }
+        return rect.adjusted(-5, -5, 10, 10);
     } // Function boundingRect()
 
     /**
@@ -54,7 +67,7 @@ export class SEquipmentItem extends SObjectItem {
     onDraw(painter: SPainter): void {
         painter.pen.lineWidth = painter.toPx(1);
         painter.pen.color = SColor.Black;
-        painter.brush.color = SColor.Transparent;
-        // painter.drawRect(this.boundingRect());
+        painter.brush.color = SColor.White;
+        painter.drawRect(this.boundingRect());
     } // Function onDraw()
 }