Browse Source

更新包

haojianlong 5 năm trước cách đây
mục cha
commit
4a403e9a58

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

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/big",
-    "version": "1.0.8",
+    "version": "1.0.9",
     "description": "上格云建筑信息化库",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -42,6 +42,6 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@saga-web/graphy": "2.1.53"
+        "@saga-web/graphy": "2.1.54"
     }
 }

+ 3 - 1
saga-web-big/src/enums/SRelationState.ts

@@ -9,5 +9,7 @@ export enum SRelationState {
     /** 动画撞他    */
     Animation,
     /** 编辑状态    */
-    Edit
+    Edit,
+    /** 创建态 */
+    Create
 } // Enum SRelationState

+ 2 - 2
saga-web-big/src/items/SLineItem.ts

@@ -16,7 +16,7 @@ export class SLineItem extends SGraphyItem {
     /** 是否完成绘制  */
     private isFinish: boolean = true;
     /** 拖动灵敏度   */
-    dis: number = 5;
+    dis: number = 10;
 
     /**
      * 构造函数
@@ -67,7 +67,7 @@ export class SLineItem extends SGraphyItem {
      * @return  是否处理事件
      * */
     onMouseMove(event: SMouseEvent): boolean {
-        if (this.isFinish) {
+        if (!this.isFinish) {
             if (!this.p2) {
                 this.p2 = new SPoint(event.x, event.y);
             } else {

+ 230 - 2
saga-web-big/src/items/SPolylineItem.ts

@@ -1,6 +1,7 @@
 import { SGraphyItem } from "@saga-web/graphy/lib";
-import { SLine, SPainter, SPoint } from "@saga-web/draw/lib";
+import { SColor, SLine, SPainter, SPoint } from "@saga-web/draw/lib";
 import { SMouseEvent } from "@saga-web/base";
+import { SRelationState } from "../enums/SRelationState";
 import { SMathUtil } from "../utils/SMathUtil";
 
 /**
@@ -8,4 +9,231 @@ import { SMathUtil } from "../utils/SMathUtil";
  *
  * */
 
-export class SPolylineItem extends SGraphyItem {} // Class SPolylineItem
+export class SPolylineItem extends SGraphyItem {
+    /** 折点信息    */
+    pointList: SPoint[] = [];
+    /** 是否绘制完成  */
+    status: SRelationState = SRelationState.Create;
+    /** 鼠标移动时的点 */
+    lastPoint: SPoint | null = null;
+    /** 线条颜色    */
+    _strokeColor: string = "#000000";
+    get strokeColor(): string {
+        return this._strokeColor;
+    }
+    set strokeColor(v: string) {
+        this._strokeColor = v;
+        this.update();
+    }
+    /** 填充色 */
+    _fillColor: string = "#ffffff";
+    get fillColor(): string {
+        return this._fillColor;
+    }
+    set fillColor(v: string) {
+        this._fillColor = v;
+    }
+    /** 线条宽度    */
+    _lineWidth: number = 1;
+    get lineWidth(): number {
+        return this._lineWidth;
+    }
+    set lineWidth(v: number) {
+        this._lineWidth = v;
+        this.update();
+    }
+    /** 全局灵敏度   */
+    dis: number = 10;
+    /** 灵敏度转换为场景长度  */
+    sceneDis: number = 10;
+    /** 当前点索引   */
+    curIndex: number = -1;
+
+    /**
+     * 构造函数
+     *
+     * @param   parent  父级
+     * @param   list    坐标集合
+     * */
+    constructor(parent: null | SGraphyItem, list: SPoint[]);
+
+    /**
+     * 构造函数
+     *
+     * @param   parent  父级
+     * @param   list    第一个坐标
+     * */
+    constructor(parent: null | SGraphyItem, list: SPoint);
+
+    /**
+     * 构造函数
+     *
+     * @param   parent  父级
+     * @param   list    第一个坐标|坐标集合
+     * */
+    constructor(parent: null | SGraphyItem, list: SPoint | SPoint[]) {
+        super(parent);
+        if (list instanceof SPoint) {
+            this.pointList.push(list);
+        } else {
+            this.pointList = list;
+        }
+    } // Constructor
+
+    /**
+     * 添加点至数组中
+     *
+     * @param   p       添加的点
+     * @param   index   添加到的索引
+     * */
+    private addPoint(p: SPoint, index?: number): void {
+        if (index && this.canHandle(index)) {
+            this.pointList.splice(index, 0, p);
+        } else {
+            this.pointList.push(p);
+        }
+    } // Function addPoint()
+
+    /**
+     * 是否可以添加点到数组中
+     *
+     * @param   index   要添加到的索引
+     * @return  boolean 是否可添加
+     * */
+    private canHandle(index: number): boolean {
+        return index >= 0 && index <= this.pointList.length;
+    } // Function canHandle()
+
+    /**
+     * 添加点至数组中
+     *
+     * @param   index   添加到的索引
+     * */
+    private delPoint(index: number): void {
+        if (this.canHandle(index)) {
+            this.pointList.splice(index, 0);
+        }
+    } // Function delPoint
+
+    /**
+     * 鼠标按下事件
+     *
+     * @param   event   鼠标事件
+     * @return  boolean 是否处理事件
+     * */
+    onMouseDown(event: SMouseEvent): boolean {
+        if (event.buttons == 1) {
+            if (this.status == SRelationState.Create) {
+                this.addPoint(new SPoint(event.x, event.y));
+                return true;
+            } else {
+                //拖动点
+            }
+        }
+        return super.onMouseDown(event);
+    } // Function onMouseDown()
+
+    /**
+     * 鼠标移动事件
+     *
+     * @param   event   鼠标事件
+     * @return  boolean 是否处理事件
+     * */
+    onMouseMove(event: SMouseEvent): boolean {
+        if (event.buttons == 1) {
+            if (this.status == SRelationState.Create) {
+                if (this.lastPoint) {
+                    this.lastPoint.x = event.x;
+                    this.lastPoint.y = event.y;
+                } else {
+                    this.lastPoint = new SPoint(event.x, event.y);
+                }
+                return true;
+            } else {
+                return super.onMouseMove(event);
+            }
+        } else {
+            return super.onMouseMove(event);
+        }
+    } // Function onMouseMove()
+
+    /**
+     * 鼠标双击事件
+     *
+     * @param	event         事件参数
+     * @return	boolean
+     */
+    onDoubleClick(event: SMouseEvent): boolean {
+        if (this.status == SRelationState.Create) {
+            this.status = SRelationState.Normal;
+        }
+        return true;
+    } // Function onDoubleClick()
+
+    /***
+     * 键盘按键弹起事件
+     *
+     * @param	event         事件参数
+     */
+    onKeyUp(event: KeyboardEvent): void {
+        if (event.keyCode == 13) {
+            this.status = SRelationState.Normal;
+        }
+    } // Function onKeyUp()
+
+    /**
+     * 判断点是否在区域内
+     *
+     * @param   x
+     * @param   y
+     * @return  true-是
+     */
+    contains(x: number, y: number): boolean {
+        let p = new SPoint(x, y);
+        for (let i = 1; i < this.pointList.length; i++) {
+            let PTL = SMathUtil.pointToLine(
+                p,
+                new SLine(
+                    this.pointList[i - 1].x,
+                    this.pointList[i - 1].y,
+                    this.pointList[i].x,
+                    this.pointList[i].y
+                )
+            );
+            if (PTL.MinDis < this.sceneDis) {
+                return true;
+            }
+        }
+        return false;
+    } // Function contains()
+
+    /**
+     * Item绘制操作
+     *
+     * @param   painter painter对象
+     */
+    onDraw(painter: SPainter): void {
+        // 缓存场景长度
+        this.sceneDis = painter.toPx(this.dis);
+        // 绘制基本图形
+        painter.pen.lineWidth = painter.toPx(this.lineWidth);
+        painter.pen.color = new SColor(this.strokeColor);
+        painter.drawPolyline(this.pointList);
+        // 创建状态
+        if (this.status == SRelationState.Create && this.lastPoint) {
+            painter.drawLine(
+                this.pointList[this.pointList.length - 1],
+                this.lastPoint
+            );
+        } else if (this.status == SRelationState.Edit) {
+            // 编辑状态
+            this.pointList.forEach((t, i): void => {
+                painter.brush.color = SColor.White;
+                if (i == this.curIndex) {
+                    painter.brush.color = new SColor(this.fillColor);
+                }
+                painter.drawCircle(t.x, t.y, painter.toPx(5));
+            });
+        }
+    } // Function onDraw()
+} // Class SPolylineItem

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

@@ -1,6 +1,6 @@
 {
     "name": "@saga-web/feng-map",
-    "version": "1.0.5",
+    "version": "1.0.6",
     "description": "上格云Web平面图。",
     "main": "lib/index.js",
     "types": "lib/index.d.js",
@@ -32,6 +32,6 @@
         "typescript": "^3.9.3"
     },
     "dependencies": {
-        "@saga-web/big": "1.0.6"
+        "@saga-web/big": "1.0.9"
     }
 }