Browse Source

'统一多边形折线删除点方法'

zhangyu 5 years ago
parent
commit
0c17c33bd7
2 changed files with 23 additions and 29 deletions
  1. 19 25
      saga-web-big/src/items/SLineItem.ts
  2. 4 4
      saga-web-big/src/items/SPolylineItem.ts

+ 19 - 25
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()
 
@@ -203,7 +200,7 @@ export class SLineItem extends SGraphItem {
         this.curPoint = null;
         if (event.buttons == SMouseButton.LeftButton) {
             if (this.status == SItemStatus.Normal) {
-                return super.onMouseDown(event);
+                return false;
             } else if (this.status == SItemStatus.Edit) {
                 // 判断是否点击到端点上(获取端点索引值)
                 this.findNearestPoint(new SPoint(event.x, event.y));
@@ -212,7 +209,7 @@ export class SLineItem extends SGraphItem {
                 return true;
             }
         }
-        return super.onMouseDown(event);
+        return true;
     } // Function onMouseDown()
 
     /**
@@ -258,7 +255,7 @@ export class SLineItem extends SGraphItem {
                 this.line[this.curIndex].y = event.y;
             }
         } else {
-            return super.onMouseMove(event);
+            return false;
         }
         this.update();
         return true;
@@ -281,10 +278,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()

+ 4 - 4
saga-web-big/src/items/SPolylineItem.ts

@@ -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;
@@ -281,7 +281,7 @@ export class SPolylineItem extends SGraphItem {
         }
         // delete删除点
         if (event.keyCode == SKeyCode.Delete && this.status == SItemStatus.Edit) {
-            this.delPoint(this.curIndex);
+            this.deletePoint(this.curIndex);
         }
     } // Function onKeyUp()