|
@@ -24,6 +24,7 @@ import {
|
|
|
SPainter,
|
|
|
SPath2D,
|
|
|
SPoint,
|
|
|
+ SPolygonUtil,
|
|
|
SRect
|
|
|
} from "@sybotan-web/draw/lib";
|
|
|
import { Opt } from "../types/Opt";
|
|
@@ -109,6 +110,19 @@ export class ZoneItem extends SGraphyItem {
|
|
|
);
|
|
|
} // Function boundingRect()
|
|
|
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 鼠标单击事件
|
|
|
+ *
|
|
|
+ * @param event 事件参数
|
|
|
+ * @return boolean
|
|
|
+ */
|
|
|
+ onClick(event: SMouseEvent): boolean {
|
|
|
+ this.selectable = !this.selectable;
|
|
|
+ this.$emit("click", event);
|
|
|
+ return true;
|
|
|
+ } // Function onClick()
|
|
|
+
|
|
|
/**
|
|
|
* 判断点是否在区域内
|
|
|
*
|
|
@@ -116,38 +130,25 @@ export class ZoneItem extends SGraphyItem {
|
|
|
* @param y
|
|
|
*/
|
|
|
contains(x: number, y: number): boolean {
|
|
|
- if (this.data.OutLine.length) {
|
|
|
- let nCross = 0,
|
|
|
- point = [x, y],
|
|
|
- APoints = this.data.OutLine[0][0],
|
|
|
- length = APoints.length,
|
|
|
- p1,
|
|
|
- p2,
|
|
|
- i,
|
|
|
- xinters;
|
|
|
- p1 = APoints[0];
|
|
|
- for (i = 1; i <= length; i++) {
|
|
|
- p2 = APoints[i % length];
|
|
|
- if (
|
|
|
- point[0] > Math.min(p1.X, p2.X) &&
|
|
|
- point[0] <= Math.max(p1.X, p2.X)
|
|
|
- ) {
|
|
|
- if (point[1] <= Math.max(p1.Y, p2.Y)) {
|
|
|
- if (p1.X != p2.X) {
|
|
|
- //计算位置信息
|
|
|
- xinters =
|
|
|
- ((point[0] - p1.X) * (p2.Y - p1.Y)) /
|
|
|
- (p2.X - p1.X) +
|
|
|
- p1.Y;
|
|
|
- if (p1.Y == p2.Y || point[1] <= xinters) {
|
|
|
- nCross++;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ for (let j = 0; j < this.pointArr.length; j++) {
|
|
|
+ let arr = this.pointArr[j];
|
|
|
+ if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ if (arr.length == 1) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ let flag = false;
|
|
|
+ for (let i = 1; i < arr.length; i++) {
|
|
|
+ if (SPolygonUtil.pointIn(x, y, arr[i])) {
|
|
|
+ flag = true;
|
|
|
+ break;
|
|
|
}
|
|
|
- p1 = p2;
|
|
|
}
|
|
|
- return nCross % 2 === 1;
|
|
|
+ if (flag) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ return true;
|
|
|
}
|
|
|
return false;
|
|
|
} // Function contains()
|