소스 검색

Merge remote-tracking branch 'origin/master'

sybotan 5 년 전
부모
커밋
119ee6f1b2

+ 2 - 2
saga-web-big/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.44",
+    "version": "1.0.46",
     "description": "上格云建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -42,6 +42,6 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@saga-web/graph": "2.1.87"
+        "@saga-web/graph": "2.1.90"
     }
 }

+ 37 - 23
saga-web-big/src/items/SLineItem.ts

@@ -26,7 +26,7 @@ export class SLineItem extends SGraphItem {
     private maxY = Number.MIN_SAFE_INTEGER;
 
     /** 线段   */
-    _line: SPoint[] = [];
+    private _line: SPoint[] = [];
     get line(): SPoint[] {
         return this._line;
     }
@@ -36,7 +36,7 @@ export class SLineItem extends SGraphItem {
     }
 
     /** 是否完成绘制  */
-    _status: SItemStatus = SItemStatus.Normal;
+    private _status: SItemStatus = SItemStatus.Normal;
     get status(): SItemStatus {
         return this._status;
     }
@@ -46,7 +46,7 @@ export class SLineItem extends SGraphItem {
     }
 
     /** 线条颜色    */
-    _strokeColor: string = "#000000";
+    private _strokeColor: string = "#000000";
     get strokeColor(): string {
         return this._strokeColor;
     }
@@ -56,7 +56,7 @@ export class SLineItem extends SGraphItem {
     }
 
     /** 线条样式    */
-    _lineStyle: SLineStyle = SLineStyle.Soild;
+    private _lineStyle: SLineStyle = SLineStyle.Soild;
     get lineStyle(): SLineStyle {
         return this._lineStyle;
     }
@@ -66,7 +66,7 @@ export class SLineItem extends SGraphItem {
     }
 
     /** 端点填充色 */
-    _fillColor: string = "#ffffff";
+    private _fillColor: string = "#ffffff";
     get fillColor(): string {
         return this._fillColor;
     }
@@ -76,7 +76,7 @@ export class SLineItem extends SGraphItem {
     }
 
     /** 选中端点填充色 */
-    _activeFillColor: string = "#2196f3";
+    private _activeFillColor: string = "#2196f3";
     get activeFillColor(): string {
         return this._activeFillColor;
     }
@@ -86,7 +86,7 @@ export class SLineItem extends SGraphItem {
     }
 
     /** 线条宽度    */
-    _lineWidth: number = 1;
+    private _lineWidth: number = 1;
     get lineWidth(): number {
         return this._lineWidth;
     }
@@ -104,7 +104,7 @@ export class SLineItem extends SGraphItem {
     /** 当前点索引   */
     curIndex: number = -1;
 
-    /** 当前点索引   */
+    /** 当前点坐标   */
     private curPoint: SPoint | null = null;
 
     /** undo/redo堆栈 */
@@ -178,17 +178,14 @@ export class SLineItem extends SGraphItem {
      * @return	boolean
      */
     onDoubleClick(event: SMouseEvent): boolean {
-        // 判断是否点击到线上
-        if (this.contains(event.x, event.y)) {
-            if (this.status == SItemStatus.Normal) {
-                this.status = SItemStatus.Edit;
-                this.grabItem(this);
-            } else if (this.status == SItemStatus.Edit) {
-                this.status = SItemStatus.Normal;
-                this.releaseItem();
-            }
-            this.update();
+        if (this.status == SItemStatus.Normal) {
+            this.status = SItemStatus.Edit;
+            this.grabItem(this);
+        } else if (this.status == SItemStatus.Edit) {
+            this.status = SItemStatus.Normal;
+            this.releaseItem();
         }
+        this.update();
         return true;
     } // Function onDoubleClick()
 
@@ -212,7 +209,7 @@ export class SLineItem extends SGraphItem {
                 return true;
             }
         }
-        return super.onMouseDown(event);
+        return true;
     } // Function onMouseDown()
 
     /**
@@ -235,6 +232,9 @@ export class SLineItem extends SGraphItem {
                     this.curIndex
                 ]);
             }
+        } else if (this.status == SItemStatus.Normal) {
+            this.moveToOrigin(this.x, this.y);
+            return super.onMouseUp(event);
         }
         this.curIndex = -1;
         this.curPoint = null;
@@ -281,10 +281,7 @@ export class SLineItem extends SGraphItem {
             if (dis < len) {
                 len = dis;
                 this.curIndex = i;
-                this.curPoint = new SPoint(
-                    this.line[this.curIndex].x,
-                    this.line[this.curIndex].y
-                );
+                this.curPoint = this.line[this.curIndex];
             }
         }
     } // Function findNearestPoint()
@@ -304,6 +301,23 @@ export class SLineItem extends SGraphItem {
     } // Function recordAction()
 
     /**
+     * 移动后处理所有坐标,并肩原点置为场景原点
+     *
+     * @param   x   x坐标
+     * @param   y   y坐标
+     * */
+    moveToOrigin(x: number, y: number): void {
+        super.moveToOrigin(x, y);
+        this.line = this.line.map(t => {
+            t.x = t.x + x;
+            t.y = t.y + y;
+            return t;
+        });
+        this.x = 0;
+        this.y = 0;
+    } // Function moveToOrigin()
+
+    /**
      * 判断点是否在区域内
      *
      * @param   x

+ 146 - 95
saga-web-big/src/items/SPolygonItem.ts

@@ -1,13 +1,18 @@
-import { SGraphItem, SGraphPointListInsert, SGraphPointListDelete, SGraphPointListUpdate } from "@saga-web/graph/lib";
-import { SMouseEvent, SUndoStack, SKeyCode } from "@saga-web/base/";;
+import {
+    SGraphItem,
+    SGraphPointListDelete,
+    SGraphPointListInsert,
+    SGraphPointListUpdate
+} from "@saga-web/graph/lib";
+import { SKeyCode, SMouseEvent, SUndoStack } from "@saga-web/base/";
 import {
     SColor,
+    SLine,
     SLineCapStyle,
     SPainter,
     SPoint,
-    SRect,
-    SLine,
-    SPolygonUtil
+    SPolygonUtil,
+    SRect
 } from "@saga-web/draw";
 import { SItemStatus } from "..";
 import { SMathUtil } from "../utils/SMathUtil";
@@ -36,7 +41,7 @@ export class SPolygonItem extends SGraphItem {
     set setPointList(arr: SPoint[]) {
         this.pointList = arr;
         this.update();
-    };
+    }
     /** 是否闭合    */
     closeFlag: boolean = false;
     // 当前状态
@@ -55,41 +60,41 @@ export class SPolygonItem extends SGraphItem {
             }
         }
         this.update();
-    };
+    }
     data: any | null = null;
     /** 边框颜色 */
     _strokeColor: SColor = new SColor("#0091FF");
     /**  画笔颜色 */
     get strokeColor(): SColor {
-        return this._strokeColor
-    };
+        return this._strokeColor;
+    }
     set strokeColor(v: SColor) {
-        this._strokeColor = v
+        this._strokeColor = v;
     }
     /** 填充颜色 */
     _fillColor: SColor = new SColor("#1EE887");
     get fillColor(): SColor {
-        return this._fillColor
-    };
+        return this._fillColor;
+    }
     set fillColor(v: SColor) {
-        this._fillColor = v
+        this._fillColor = v;
     }
 
     /** 边框的宽 只可输入像素宽*/
     _lineWidth: number = 4;
     get lineWidth(): number {
-        return this._lineWidth
+        return this._lineWidth;
     }
     set lineWidth(v: number) {
         this._lineWidth = v;
         this.update();
-    };
+    }
     /** 鼠标移动点  */
     private lastPoint: SPoint | null = null;
     /** 当前鼠标获取顶点对应索引 */
     private curIndex: number = -1;
     /** 当前鼠标获取顶点对应坐标 */
-    private curPoint: null | SPoint = null
+    private curPoint: null | SPoint = null;
     /** 灵敏像素 */
     private len: number = 10;
     /** 场景像素 内部将灵敏像素换算为场景实际距离  */
@@ -100,11 +105,11 @@ export class SPolygonItem extends SGraphItem {
     protected undoStack: SUndoStack | null = new SUndoStack();
 
     /**
-    * 构造函数
-    *
-    * @param parent    指向父对象
-    * @param data      PolygonData数据
-    */
+     * 构造函数
+     *
+     * @param parent    指向父对象
+     * @param data      PolygonData数据
+     */
     constructor(parent: SGraphItem | null) {
         super(parent);
     }
@@ -123,12 +128,12 @@ export class SPolygonItem extends SGraphItem {
     insertPoint(x: number, y: number, i: number | null = null): SPoint {
         const point = new SPoint(x, y);
         if (i == null) {
-            this.pointList.push(point)
+            this.pointList.push(point);
         } else {
             this.pointList.splice(i, 0, point);
         }
-        this.update()
-        return point
+        this.update();
+        return point;
     }
 
     /**
@@ -140,8 +145,8 @@ export class SPolygonItem extends SGraphItem {
     deletePoint(i: number | null = null): SPoint | null {
         let point = null;
         if (i != null) {
-            if (i >= (this.pointList.length) || i < 0) {
-                point = null
+            if (i >= this.pointList.length || i < 0) {
+                point = null;
             } else {
                 point = new SPoint(this.pointList[i].x, this.pointList[i].y);
                 this.pointList.splice(i, 1);
@@ -151,13 +156,13 @@ export class SPolygonItem extends SGraphItem {
                 point = this.pointList[this.pointList.length - 1];
                 this.pointList.pop();
             } else {
-                point = null
+                point = null;
             }
         }
         this.curIndex = -1;
         this.curPoint = null;
-        this.update()
-        return point
+        this.update();
+        return point;
     }
 
     /**
@@ -168,17 +173,17 @@ export class SPolygonItem extends SGraphItem {
      * @param i   点位得i坐标
      * @return    移动对应得点。如果索引无法找到移动顶点,则返回null
      */
-    movePoint(x: number, y: number, i: number, ): SPoint | null {
+    movePoint(x: number, y: number, i: number): SPoint | null {
         let point = null;
-        if (i >= (this.pointList.length) || i < 0) {
-            return null
+        if (i >= this.pointList.length || i < 0) {
+            return null;
         }
         if (this.pointList.length) {
             this.pointList[i].x = x;
             this.pointList[i].y = y;
         }
         point = this.pointList[i];
-        return point
+        return point;
     }
 
     /**
@@ -187,7 +192,7 @@ export class SPolygonItem extends SGraphItem {
      * @return  顶点数组
      */
     PrintPointList(): SPoint[] {
-        return this.pointList
+        return this.pointList;
     }
 
     ////////////
@@ -217,7 +222,6 @@ export class SPolygonItem extends SGraphItem {
         painter.restore();
     }
 
-
     /**
      * 创建状态 --绘制多边形数组
      *
@@ -229,32 +233,47 @@ export class SPolygonItem extends SGraphItem {
         painter.pen.color = this._strokeColor;
         painter.pen.lineWidth = painter.toPx(this._lineWidth);
         if (this.lastPoint && pointList.length) {
-            painter.drawLine(pointList[pointList.length - 1].x, pointList[pointList.length - 1].y, this.lastPoint.x, this.lastPoint.y);
+            painter.drawLine(
+                pointList[pointList.length - 1].x,
+                pointList[pointList.length - 1].y,
+                this.lastPoint.x,
+                this.lastPoint.y
+            );
         }
         painter.drawPolyline(pointList);
         painter.pen.color = SColor.Transparent;
         painter.brush.color = new SColor(this._fillColor.value + "80");
         painter.pen.lineWidth = painter.toPx(this._lineWidth);
-        
+
         if (this.lastPoint) {
             painter.drawPolygon([...pointList, this.lastPoint]);
             // 绘制顶点块
             painter.pen.color = SColor.Black;
             painter.brush.color = SColor.White;
             pointList.forEach((item, index) => {
-                painter.drawCircle(item.x, item.y, painter.toPx(this.len / 2))
+                painter.drawCircle(item.x, item.y, painter.toPx(this.len / 2));
             });
             // 如果最后一个点在第一个点的灵敏度范围内,第一个点填充变红
-            if (SMathUtil.pointDistance(this.lastPoint.x, this.lastPoint.y, this.pointList[0].x, this.pointList[0].y) < this.scenceLen) {
+            if (
+                SMathUtil.pointDistance(
+                    this.lastPoint.x,
+                    this.lastPoint.y,
+                    this.pointList[0].x,
+                    this.pointList[0].y
+                ) < this.scenceLen
+            ) {
                 // 绘制第一个点的顶点块
                 painter.pen.color = SColor.Black;
                 painter.brush.color = SColor.Red;
-                painter.drawCircle(this.pointList[0].x, this.pointList[0].y, painter.toPx(this.len / 2))
+                painter.drawCircle(
+                    this.pointList[0].x,
+                    this.pointList[0].y,
+                    painter.toPx(this.len / 2)
+                );
             }
         } else {
             painter.drawPolygon(pointList);
         }
-
     }
 
     /**
@@ -279,8 +298,8 @@ export class SPolygonItem extends SGraphItem {
             if (index == this.curIndex) {
                 painter.brush.color = new SColor(this.fillColor);
             }
-            painter.drawCircle(item.x, item.y, painter.toPx(this.len / 2))
-        })
+            painter.drawCircle(item.x, item.y, painter.toPx(this.len / 2));
+        });
     }
 
     /**
@@ -294,7 +313,7 @@ export class SPolygonItem extends SGraphItem {
         //  判断是否为删除状态 isAlt = true为删除状态
         if (this.isAlt) {
             // 1 判断是否点击在多边形顶点
-            let lenIndex = -1;  // 当前点击到的点位索引;
+            let lenIndex = -1; // 当前点击到的点位索引;
             let curenLen = this.scenceLen; // 当前的灵敏度
             this.pointList.forEach((item, index) => {
                 let dis = SMathUtil.pointDistance(
@@ -311,18 +330,25 @@ export class SPolygonItem extends SGraphItem {
             // 若点击到,对该索引对应的点做删除
             if (lenIndex != -1) {
                 if (this.pointList.length <= 3) {
-                    return
+                    return;
                 }
-                const delePoint = new SPoint(this.pointList[lenIndex].x, this.pointList[lenIndex].y)
+                const delePoint = new SPoint(
+                    this.pointList[lenIndex].x,
+                    this.pointList[lenIndex].y
+                );
                 this.deletePoint(lenIndex);
                 // 记录顶点操作记录压入堆栈
-                this.recordAction(SGraphPointListDelete, [this.pointList, delePoint, lenIndex]);
+                this.recordAction(SGraphPointListDelete, [
+                    this.pointList,
+                    delePoint,
+                    lenIndex
+                ]);
             }
         } else {
             // 1 判断是否点击在多边形顶点
             this.curIndex = -1;
             this.curPoint = null;
-            let lenIndex = -1;  // 当前点击到的点位索引;
+            let lenIndex = -1; // 当前点击到的点位索引;
             let curenLen = this.scenceLen; // 当前的灵敏度
             this.pointList.forEach((item, index) => {
                 let dis = SMathUtil.pointDistance(
@@ -340,9 +366,9 @@ export class SPolygonItem extends SGraphItem {
             // 2判断是否点击在多边形得边上
             if (-1 == lenIndex) {
                 let len = SMathUtil.pointToLine(
-                    new SPoint(event.x, event.y),
-                    new SLine(this.pointList[0], this.pointList[1])
-                ),
+                        new SPoint(event.x, event.y),
+                        new SLine(this.pointList[0], this.pointList[1])
+                    ),
                     index = 0;
                 if (this.pointList.length > 2) {
                     for (let i = 1; i < this.pointList.length; i++) {
@@ -350,7 +376,7 @@ export class SPolygonItem extends SGraphItem {
                             new SPoint(event.x, event.y),
                             new SLine(this.pointList[i], this.pointList[i + 1])
                         );
-                        if ((i + 1) == this.pointList.length) {
+                        if (i + 1 == this.pointList.length) {
                             dis = SMathUtil.pointToLine(
                                 new SPoint(event.x, event.y),
                                 new SLine(this.pointList[i], this.pointList[0])
@@ -364,24 +390,30 @@ 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]);
-                    } else { //没点在多边形边上也没点在多边形顶点上
+                        this.recordAction(SGraphPointListInsert, [
+                            this.pointList,
+                            len.Point,
+                            index + 1
+                        ]);
+                    } else {
+                        //没点在多边形边上也没点在多边形顶点上
                         super.onMouseDown(event);
                     }
                 }
             } else {
                 // 当捕捉到顶点后 ,记录当前点的xy坐标,用于undo、redo操作
-                this.curPoint = new SPoint(this.pointList[this.curIndex].x, this.pointList[this.curIndex].y);
+                this.curPoint = new SPoint(
+                    this.pointList[this.curIndex].x,
+                    this.pointList[this.curIndex].y
+                );
             }
             // 刷新视图
             this.update();
         }
-
     }
 
     /////////////////////
@@ -405,7 +437,7 @@ export class SPolygonItem extends SGraphItem {
      */
     undo(): void {
         if (this.status == SItemStatus.Normal) {
-            return
+            return;
         }
         if (this.undoStack) {
             this.undoStack.undo();
@@ -417,7 +449,7 @@ export class SPolygonItem extends SGraphItem {
      */
     redo(): void {
         if (this.status == SItemStatus.Normal) {
-            return
+            return;
         }
         if (this.undoStack) {
             this.undoStack.redo();
@@ -442,14 +474,13 @@ export class SPolygonItem extends SGraphItem {
             this.status = SItemStatus.Normal;
             this.releaseItem();
             if (this.undoStack) {
-                this.undoStack.clear()
+                this.undoStack.clear();
             }
         }
-        this.update()
+        this.update();
         return true;
     } // Function onDoubleClick()
 
-
     /**
      * 键盘事件
      *
@@ -461,12 +492,12 @@ export class SPolygonItem extends SGraphItem {
         if (this.status == SItemStatus.Normal) {
             return false;
         } else if (this.status == SItemStatus.Create) {
-            if (event.code == 'Enter') {
+            if (event.code == "Enter") {
                 // 当顶点大于二个时才又条件执行闭合操作并清空堆栈
                 if (this.pointList.length > 2) {
                     this.status = SItemStatus.Normal;
                     //3 传递完成事件状态
-                    this.$emit('finishCreated')
+                    this.$emit("finishCreated");
                     //1 grabItem 置为null
                     this.releaseItem();
                     //2 清空undo
@@ -476,7 +507,7 @@ export class SPolygonItem extends SGraphItem {
                 }
             }
         } else if (this.status == SItemStatus.Edit) {
-            if (event.key == 'Alt') {
+            if (event.key == "Alt") {
                 this.isAlt = true;
             }
         }
@@ -484,7 +515,6 @@ export class SPolygonItem extends SGraphItem {
         return true;
     } // Function onKeyDown()
 
-
     /**
      * 键盘键抬起事件
      *
@@ -493,13 +523,13 @@ export class SPolygonItem extends SGraphItem {
      */
     onKeyUp(event: KeyboardEvent): void {
         if (this.status == SItemStatus.Edit) {
-            if (event.key == 'Alt') {
+            if (event.key == "Alt") {
                 this.isAlt = false;
             } else if (event.keyCode == SKeyCode.Delete) {
                 this.deletePoint(this.curIndex);
             }
         }
-        this.update()
+        this.update();
     } // Function onKeyUp()
 
     /**
@@ -512,11 +542,16 @@ export class SPolygonItem extends SGraphItem {
         // 如果状态为编辑状态则添加点
         if (this.status == SItemStatus.Create) {
             // 新增顶点
-            let len = SMathUtil.pointDistance(event.x, event.y, this.pointList[0].x, this.pointList[0].y);
+            let len = SMathUtil.pointDistance(
+                event.x,
+                event.y,
+                this.pointList[0].x,
+                this.pointList[0].y
+            );
             if (this.pointList.length > 2 && len < this.scenceLen) {
                 this.status = SItemStatus.Normal;
                 //3 传递完成事件状态
-                this.$emit('finishCreated')
+                this.$emit("finishCreated");
                 //1 grabItem 置为null
                 this.releaseItem();
                 //2 清空undo
@@ -533,10 +568,9 @@ export class SPolygonItem extends SGraphItem {
             // 对多边形数组做编辑操作
             this.editPolygonPoint(event);
         } else {
-            return super.onMouseDown(event)
+            return super.onMouseDown(event);
         }
         return true;
-
     } // Function onMouseDown()
 
     /**
@@ -549,7 +583,6 @@ export class SPolygonItem extends SGraphItem {
         return true;
     } // Function onMouseEnter()
 
-
     /**
      * 鼠标移出事件
      *
@@ -570,7 +603,7 @@ export class SPolygonItem extends SGraphItem {
 
     onMouseMove(event: SMouseEvent): boolean {
         if (this.status == SItemStatus.Create) {
-            this.lastPoint = new SPoint
+            this.lastPoint = new SPoint();
             this.lastPoint.x = event.x;
             this.lastPoint.y = event.y;
             this.update();
@@ -581,15 +614,13 @@ export class SPolygonItem extends SGraphItem {
                     this.pointList[this.curIndex].y = event.y;
                 }
             }
-            this.update()
+            this.update();
         } else {
-            // return super.onMouseMove(event)
+            return super.onMouseMove(event);
         }
-
         return true;
     } // Function onMouseMove()
 
-
     /**
      * 鼠标抬起事件
      *
@@ -599,24 +630,47 @@ export class SPolygonItem extends SGraphItem {
     onMouseUp(event: SMouseEvent): boolean {
         if (this.status == SItemStatus.Edit) {
             if (-1 != this.curIndex) {
-                const pos = new SPoint(this.pointList[this.curIndex].x, this.pointList[this.curIndex].y)
-                this.recordAction(SGraphPointListUpdate, [this.pointList, this.curPoint, pos, this.curIndex])
+                const pos = new SPoint(
+                    this.pointList[this.curIndex].x,
+                    this.pointList[this.curIndex].y
+                );
+                this.recordAction(SGraphPointListUpdate, [
+                    this.pointList,
+                    this.curPoint,
+                    pos,
+                    this.curIndex
+                ]);
             }
-            // this.curIndex = -1;
-            // this.curPoint = null;
-        } else {
-            // return super.onMouseUp(event)
+        } else if (this.status == SItemStatus.Normal) {
+            this.moveToOrigin(this.x, this.y);
+            return super.onMouseUp(event);
         }
         return true;
     } // Function onMouseUp()
 
     /**
+     * 移动后处理所有坐标,并肩原点置为场景原点
+     *
+     * @param   x   x坐标
+     * @param   y   y坐标
+     * */
+    moveToOrigin(x: number, y: number): void {
+        super.moveToOrigin(x, y);
+        this.pointList = this.pointList.map(t => {
+            t.x = t.x + x;
+            t.y = t.y + y;
+            return t;
+        });
+        this.x = 0;
+        this.y = 0;
+    } // Function moveToOrigin()
+
+    /**
      * 适配事件
      *
      * @param	event         事件参数
      * @return	boolean
      */
-
     onResize(event: SMouseEvent): boolean {
         return true;
     } // Function onResize()
@@ -624,18 +678,17 @@ export class SPolygonItem extends SGraphItem {
     /**
      * 取消操作
      *
-     * @param   painter       painter对象
      */
     cancelOperate(): void {
         // 当状态为展示状态
         if (this.status == SItemStatus.Create) {
             // 闭合多边形
-            this.parent = null
+            this.parent = null;
         } else if (this.status == SItemStatus.Edit) {
             // 编辑状态
-            this.status = SItemStatus.Normal
+            this.status = SItemStatus.Normal;
         }
-        this.update()
+        this.update();
     } // Function cancelOperate()
 
     /**
@@ -665,7 +718,7 @@ export class SPolygonItem extends SGraphItem {
                     this.maxY = y;
                 }
             });
-        };
+        }
         return new SRect(
             this.minX,
             this.minY,
@@ -694,19 +747,17 @@ export class SPolygonItem extends SGraphItem {
      * @param   painter       painter对象
      */
     onDraw(painter: SPainter): void {
-        this.scenceLen = painter.toPx(this.len)
+        this.scenceLen = painter.toPx(this.len);
         // 当状态为展示状态
         if (this.status == SItemStatus.Normal) {
             // 闭合多边形
             this.drawShowPolygon(painter, this.pointList);
         } else if (this.status == SItemStatus.Create) {
             // 创建状态
-            this.drawCreatePolygon(painter, this.pointList)
+            this.drawCreatePolygon(painter, this.pointList);
         } else {
             // 编辑状态
             this.drawEditPolygon(painter, this.pointList);
         }
     } // Function onDraw()
-
-
-}
+}

+ 29 - 8
saga-web-big/src/items/SPolylineItem.ts

@@ -1,5 +1,5 @@
 import { SColor, SLine, SPainter, SPoint, SRect } from "@saga-web/draw";
-import { SMouseEvent, SUndoStack, SKeyCode } from "@saga-web/base";
+import { SKeyCode, SMouseEvent, SUndoStack } from "@saga-web/base";
 import { SItemStatus } from "..";
 import { SMathUtil } from "../utils/SMathUtil";
 import {
@@ -141,7 +141,7 @@ export class SPolylineItem extends SGraphItem {
      *
      * @param   index   删除点
      * */
-    private delPoint(index: number): void {
+    deletePoint(index: number): void {
         if (this.canHandle(index) && this.pointList.length > 2) {
             const p = new SPoint(
                 this.pointList[this.curIndex].x,
@@ -157,7 +157,7 @@ export class SPolylineItem extends SGraphItem {
             this.curPoint = null;
             this.update();
         }
-    } // Function delPoint
+    } // Function deletePoint
 
     /**
      * 鼠标按下事件
@@ -181,7 +181,7 @@ export class SPolylineItem extends SGraphItem {
                 }
                 // 删除点
                 if (event.altKey && this.canHandle(this.curIndex)) {
-                    this.delPoint(this.curIndex);
+                    this.deletePoint(this.curIndex);
                 }
                 this.update();
                 return true;
@@ -242,9 +242,10 @@ export class SPolylineItem extends SGraphItem {
                     this.curIndex
                 ]);
             }
+        } else if (this.status == SItemStatus.Normal) {
+            this.moveToOrigin(this.x, this.y);
+            return super.onMouseUp(event);
         }
-        // this.curIndex = -1;
-        // this.curPoint = null;
         return true;
     } // Function onMouseMove()
 
@@ -280,12 +281,32 @@ export class SPolylineItem extends SGraphItem {
             this.$emit("finishCreated");
         }
         // delete删除点
-        if (event.keyCode == SKeyCode.Delete && this.status == SItemStatus.Edit) {
-            this.delPoint(this.curIndex);
+        if (
+            event.keyCode == SKeyCode.Delete &&
+            this.status == SItemStatus.Edit
+        ) {
+            this.deletePoint(this.curIndex);
         }
     } // Function onKeyUp()
 
     /**
+     * 移动后处理所有坐标,并肩原点置为场景原点
+     *
+     * @param   x   x坐标
+     * @param   y   y坐标
+     * */
+    moveToOrigin(x: number, y: number): void {
+        super.moveToOrigin(x, y);
+        this.pointList = this.pointList.map(t => {
+            t.x = t.x + x;
+            t.y = t.y + y;
+            return t;
+        });
+        this.x = 0;
+        this.y = 0;
+    } // Function moveToOrigin()
+
+    /**
      * 获取点击点与点集中距离最近点
      *
      * @param   p   鼠标点击点

+ 1 - 1
saga-web-graph/package.json

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/graph",
-    "version": "2.1.87",
+    "version": "2.1.90",
     "description": "上格云二维图形引擎。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",

+ 14 - 0
saga-web-graph/src/SGraphItem.ts

@@ -546,6 +546,20 @@ export class SGraphItem extends SObject {
         return null;
     } // Function toData()
 
+    /**
+     * 移动item后的处理,计算其他信息,将原点置为场景原点
+     *
+     * @param   x   x坐标
+     * @param   y   y坐标
+     * */
+    moveToOrigin(x: number, y: number): void {
+        if (this.children && this.children.length) {
+            this.children.forEach(it => {
+                it.moveToOrigin(x, y);
+            });
+        }
+    } // Function moveToOrigin()
+
     // =================================================================================================================
     // 私有方法
     /**

+ 13 - 7
saga-web-graph/src/items/STextItem.ts

@@ -7,11 +7,6 @@ import { SGraphItem } from "../SGraphItem";
  *
  * @author  张宇(taohuzy@163.com)
  */
-/**
- * 文本item
- *
- * @author  张宇(taohuzy@163.com)
- */
 export class STextItem extends SObjectItem {
     /** 记录painter */
     private _painter: SPainter | null = null;
@@ -110,6 +105,16 @@ export class STextItem extends SObjectItem {
     } // Function boundingRect()
 
     /**
+     * 移动后处理所有坐标,并肩原点置为场景原点
+     *
+     * @param   x   x坐标
+     * @param   y   y坐标
+     * */
+    moveToOrigin(x: number, y: number): void {
+        this.moveTo(this.x + x, this.y + y);
+    } // Function moveToOrigin()
+
+    /**
      * 绘制显示状态文本Item
      *
      * @param painter    绘制类
@@ -138,14 +143,15 @@ export class STextItem extends SObjectItem {
     /**
      * 根据换行切割文本,绘制多行并计算外轮廓宽高
      *
-     * @param painter    绘制类
      */
     protected drawFormatText(): void {
         if (this._painter instanceof SPainter) {
             let textMaxWidth = 0;
             let textHeight: number = this.font.size;
             this._textArr.forEach((text: string, index: number) => {
-                let textWidth: number = this._painter?this._painter.textWidth(text)+4:4;
+                let textWidth: number = this._painter
+                    ? this._painter.textWidth(text) + 4
+                    : 4;
                 if (textWidth > textMaxWidth) {
                     textMaxWidth = textWidth;
                 }