Procházet zdrojové kódy

'完善派生多边形item'

zhangyu před 4 roky
rodič
revize
22c72f418b

+ 6 - 2
src/components/mapClass/SPolygonItem.ts

@@ -347,12 +347,16 @@ export class SPolygonItem extends SGraphItem {
                         }
                     }
                 }
-                // 如果再线上则为新增
+                // 判断是否有
                 if (len.Point) {
+                    console.log(index,len.Point);
+                    // 点在了多边形的边上
                     if (len.MinDis <= this.scenceLen) {
                         this.pointList.splice(index + 1, 0, len.Point);
                         // 记录新增顶点操作记录压入堆栈
-                        this.recordAction(SGraphPointListInsert, [this.pointList, len.Point, index + 1])
+                        this.recordAction(SGraphPointListInsert, [this.pointList, len.Point, index + 1]);
+                    } else { //没点在多边形边上也没点在多边形顶点上
+                        super.onMouseDown(event);
                     }
                 }
             } else {

+ 39 - 13
src/lib/items/SZoneLegendItem.ts

@@ -46,24 +46,28 @@ export class SZoneLegendItem extends SPolygonItem {
         this._status = value;
         // 如果状态为show则需清栈
         if (value == SItemStatus.Normal) {
-            // 计算文本位置
-            let x: number = this.getPointList.reduce((pre, cur, index, arr) => {
-                                return pre + (cur.x / arr.length)
-                            }, 0),
-                y: number = this.getPointList.reduce((pre, cur, index, arr) => {
-                                return pre + (cur.y / arr.length)
-                            }, 0);
-            this.textItem.moveTo(x, y);
+            // 切换显示状态显示文本
             this.showText = true;
+            // 切换显示状态不可移动文本
+            this.textItem.moveable = false;
+
             if (this.undoStack) {
                 this.undoStack.clear();
             }
         } else if (value == SItemStatus.Edit) {
+            // 切换编辑状态显示文本
             this.showText = true;
+            // 切换编辑状态可移动文本
+            this.textItem.moveable = true;
         } else if (value == SItemStatus.Create) {
+            // 切换创建状态不显示文本
             this.showText = false;
+            // 切换创建状态不可移动文本
+            this.textItem.moveable = false;
         }
         this.update();
+        console.log("多边形item", this);
+        console.log("文本item", this.textItem);
     };
 
     /** 是否显示文字  */
@@ -99,10 +103,10 @@ export class SZoneLegendItem extends SPolygonItem {
             this.setPointList = [];
             let setPointList: SPoint[];
             if (data.OutLine) {
-                if (data.OutLine[0][0] instanceof SPoint) {
-                    this.setPointList = data.OutLine[0];
+                if (data.OutLine[0] instanceof SPoint) {
+                    this.setPointList = data.OutLine;
                 } else {
-                    setPointList = data.OutLine[0].map(i => {
+                    setPointList = data.OutLine.map(i => {
                         return (new SPoint(i.X, i.Y))
                     })
                     this.setPointList = setPointList;
@@ -121,17 +125,39 @@ export class SZoneLegendItem extends SPolygonItem {
             if (data.Properties.fillColor) {
                 this.fillColor = data.Properties.fillColor.includes('#') ? new SColor(data.Properties.fillColor) : new SColor(hexify(data.Properties.fillColor))
             }
+            if (data.Properties.TextPos) {
+                this.textItem.moveTo(data.Properties.TextPos.x, data.Properties.TextPos.y);
+            }
             //    if( data.Properties.LineDash){
             //     this.LineDash =this._legend.Properties.LineDash
             //    }
-            console.log(this);
         }
+        // 监听多边形创建完成事件,并动态计算文本位置
+        this.connect("finishCreated",this, () => {
+            // 计算文本位置
+            let x: number = this.getPointList.reduce((pre, cur, index, arr) => {
+                                return pre + (cur.x / arr.length)
+                            }, 0),
+                y: number = this.getPointList.reduce((pre, cur, index, arr) => {
+                                return pre + (cur.y / arr.length)
+                            }, 0);
+            this.textItem.moveTo(x, y);
+        })
     }
+
     toData(): any {
+        this.data.Pos = {X: this.x, Y: this.y};
+        this.data.Properties.Text = this.text;
         this.data.Properties.fillColor = this.fillColor.value;
         this.data.Properties.strokeColor = this.strokeColor.value;
         this.data.Properties.lineWidth = this.lineWidth;
-        this.data.OutLine = [this.getPointList];
+        this.data.OutLine = this.getPointList.map(pos => {
+            return {
+                X: pos.x,
+                Y: pos.y
+            }
+        });
+        this.data.Properties.TextPos = this.textItem.pos;
         return this.data;
     }
 

+ 1 - 1
src/lib/types/Legend.ts

@@ -53,7 +53,7 @@ export interface Legend {
     /** 锚点List  */
     AnchorList?: Anchor[];
     /** 轮廓线  */
-    OutLine?: Point[][];
+    OutLine?: Point[];
     /** 由应用自己定义  */
     Properties?: any;
 } // Interface Legend