|
@@ -0,0 +1,133 @@
|
|
|
+/*
|
|
|
+ * ********************************************************************************************************************
|
|
|
+ *
|
|
|
+ * :*$@@%$*: ;: ;; ;;
|
|
|
+ * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
|
|
|
+ * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
|
|
|
+ * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
|
|
|
+ * =@* %! @ $= % %@= =%@! %=
|
|
|
+ * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
|
|
|
+ * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
|
|
|
+ * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
|
|
|
+ * $@* ;@@@%=!: *@*
|
|
|
+ * =@$ ;;;!=%@@@@=! =@!
|
|
|
+ * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
|
|
|
+ * ;%@@$=$@@%* *@@@$=%@@%;
|
|
|
+ * ::;:: ::;:: All rights reserved.
|
|
|
+ *
|
|
|
+ * ********************************************************************************************************************
|
|
|
+ */
|
|
|
+
|
|
|
+import { SGraphyItem, SMouseEvent } from "@sybotan-web/graphy/lib";
|
|
|
+import { SColor, SPainter, SPoint, SRect } from "@sybotan-web/draw/lib";
|
|
|
+
|
|
|
+/**
|
|
|
+ * 标志item
|
|
|
+ *
|
|
|
+ * @author 郝建龙
|
|
|
+ */
|
|
|
+export class UserMark extends SGraphyItem {
|
|
|
+ /** 标志宽度 */
|
|
|
+ private width: number = 10;
|
|
|
+ /** 标志高度 */
|
|
|
+ private height: number = 10;
|
|
|
+ //轮廓线坐标
|
|
|
+ outLine: SPoint[] = [];
|
|
|
+ /** 是否闭合 */
|
|
|
+ closeFlag = false;
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param parent 指向父对象
|
|
|
+ * @param data 标志数据
|
|
|
+ */
|
|
|
+ constructor(parent: SGraphyItem | null, data: SPoint) {
|
|
|
+ super(parent);
|
|
|
+ this.outLine.push(data);
|
|
|
+ } // Constructor
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Item对象边界区域
|
|
|
+ *
|
|
|
+ * @return SRect
|
|
|
+ */
|
|
|
+ boundingRect(): SRect {
|
|
|
+ return new SRect(0, 0, this.width, this.height);
|
|
|
+ } // Function boundingRect()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标按下事件
|
|
|
+ *
|
|
|
+ * @param event 事件参数
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ onMouseDown(event: SMouseEvent): boolean {
|
|
|
+ if (!this.closeFlag) {
|
|
|
+ console.log("mouseDown");
|
|
|
+ let newPoint = this.outLine[this.outLine.length - 1];
|
|
|
+ if (
|
|
|
+ newPoint.x == this.outLine[0].x &&
|
|
|
+ newPoint.y == this.outLine[0].y
|
|
|
+ ) {
|
|
|
+ this.closeFlag = true;
|
|
|
+ } else {
|
|
|
+ newPoint = new SPoint(event.x, event.y);
|
|
|
+ console.log(newPoint);
|
|
|
+ this.outLine.push(newPoint);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } // Function onMouseDown()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标移动事件
|
|
|
+ *
|
|
|
+ * @param event 事件参数
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ onMouseMove(event: SMouseEvent): boolean {
|
|
|
+ console.log("mouseMove");
|
|
|
+ if (!this.closeFlag) {
|
|
|
+ let first, newLast;
|
|
|
+ if (this.outLine.length > 1) {
|
|
|
+ this.outLine.pop();
|
|
|
+ first = this.outLine[0];
|
|
|
+ }
|
|
|
+ newLast = new SPoint(event.x, event.y);
|
|
|
+ if (this.outLine.length > 2 && first) {
|
|
|
+ if (
|
|
|
+ event.x + 20 >= first.x &&
|
|
|
+ event.x - 20 <= first.x &&
|
|
|
+ event.y + 20 >= first.y &&
|
|
|
+ event.y - 20 <= first.y
|
|
|
+ ) {
|
|
|
+ newLast = first;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ this.outLine.push(newLast);
|
|
|
+ }
|
|
|
+ return true;
|
|
|
+ } // Function onMouseMove()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Item绘制操作
|
|
|
+ *
|
|
|
+ * @param painter painter对象
|
|
|
+ * @param rect 绘制区域
|
|
|
+ */
|
|
|
+ onDraw(painter: SPainter, rect?: SRect): void {
|
|
|
+ if (this.visible) {
|
|
|
+ painter.pen.color = new SColor("#00ff00");
|
|
|
+ painter.pen.lineWidth = 2;
|
|
|
+ if (this.closeFlag) {
|
|
|
+ painter.brush.color = new SColor("#00ff00");
|
|
|
+ } else {
|
|
|
+ painter.brush.color = new SColor("#ffffff80");
|
|
|
+ }
|
|
|
+ this.outLine.map(t => {
|
|
|
+ painter.drawRect(t.x - 4, t.y - 4, 8, 8);
|
|
|
+ });
|
|
|
+ painter.drawPolyline(this.outLine);
|
|
|
+ }
|
|
|
+ } // Function onDraw()
|
|
|
+} // Class UserMark
|