|
@@ -0,0 +1,161 @@
|
|
|
+/*
|
|
|
+ * ********************************************************************************************************************
|
|
|
+ *
|
|
|
+ * :*$@@%$*: ;: ;; ;;
|
|
|
+ * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
|
|
|
+ * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
|
|
|
+ * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
|
|
|
+ * =@* %! @ $= % %@= =%@! %=
|
|
|
+ * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
|
|
|
+ * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
|
|
|
+ * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
|
|
|
+ * $@* ;@@@%=!: *@*
|
|
|
+ * =@$ ;;;!=%@@@@=! =@!
|
|
|
+ * %@$: =@%: :*@@@* %@= 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";
|
|
|
+import { Space } from "../types/Space";
|
|
|
+import { Opt } from "../types/Opt";
|
|
|
+import { Zone } from "../types/Zone";
|
|
|
+
|
|
|
+/**
|
|
|
+ * 业务空间item
|
|
|
+ *
|
|
|
+ * @author 郝建龙
|
|
|
+ */
|
|
|
+export class ZoneItem extends SGraphyItem {
|
|
|
+ /** 空间所有数据 */
|
|
|
+ data: Zone;
|
|
|
+ /** 空间轮廓线坐标list */
|
|
|
+ private readonly pointArr: SPoint[][] = [];
|
|
|
+ /** X坐标最小值 */
|
|
|
+ private minX = 0;
|
|
|
+ /** X坐标最大值 */
|
|
|
+ private maxX = 0;
|
|
|
+ /** Y坐标最小值 */
|
|
|
+ private minY = 0;
|
|
|
+ /** Y坐标最大值 */
|
|
|
+ private maxY = 0;
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param parent 指向父对象
|
|
|
+ * @param data 空间数据
|
|
|
+ */
|
|
|
+ constructor(parent: SGraphyItem | null, data: Space) {
|
|
|
+ super(parent);
|
|
|
+ this.data = data;
|
|
|
+ if (this.data.OutLine.length) {
|
|
|
+ let tempArr = this.data.OutLine;
|
|
|
+ this.minX = tempArr[0][0].X;
|
|
|
+ this.maxX = this.minX;
|
|
|
+ this.minY = -tempArr[0][0].Y;
|
|
|
+ this.maxY = this.minY;
|
|
|
+ // 处理轮廓点数组,同时计算最大最小值
|
|
|
+ this.pointArr = tempArr.map(t => {
|
|
|
+ let tempArr = t.map(it => {
|
|
|
+ let x = it.X,
|
|
|
+ y = -it.Y;
|
|
|
+ if (x < this.minX) {
|
|
|
+ this.minX = x;
|
|
|
+ }
|
|
|
+ if (y < this.minY) {
|
|
|
+ this.minY = y;
|
|
|
+ }
|
|
|
+ if (x > this.maxX) {
|
|
|
+ this.maxX = x;
|
|
|
+ }
|
|
|
+ if (y > this.maxY) {
|
|
|
+ this.maxY = y;
|
|
|
+ }
|
|
|
+ return new SPoint(x, y);
|
|
|
+ });
|
|
|
+ return tempArr;
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } // Constructor
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Item对象边界区域
|
|
|
+ *
|
|
|
+ * @return SRect
|
|
|
+ */
|
|
|
+ boundingRect(): SRect {
|
|
|
+ return new SRect(
|
|
|
+ this.minX,
|
|
|
+ this.minY,
|
|
|
+ this.maxX - this.minX,
|
|
|
+ this.maxY - this.minY
|
|
|
+ );
|
|
|
+ } // Function boundingRect()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断点是否在区域内
|
|
|
+ *
|
|
|
+ * @param x
|
|
|
+ * @param y
|
|
|
+ */
|
|
|
+ contains(x: number, y: number): boolean {
|
|
|
+ if (this.data.OutLine.length) {
|
|
|
+ let nCross = 0,
|
|
|
+ point = [x, y],
|
|
|
+ APoints = this.data.OutLine[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++;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ p1 = p2;
|
|
|
+ }
|
|
|
+ return nCross % 2 === 1;
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } // Function contains()
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Item绘制操作
|
|
|
+ *
|
|
|
+ * @param painter painter对象
|
|
|
+ * @param rect 绘制区域
|
|
|
+ */
|
|
|
+ onDraw(painter: SPainter, rect?: SRect): void {
|
|
|
+ if (this.visible) {
|
|
|
+ painter.pen.color = SColor.Transparent;
|
|
|
+ painter.brush.color = Opt.spaceColor;
|
|
|
+ // if (this.pointArr.length > 1) {
|
|
|
+ // painter.brush.color = new SColor("#00ff0080");
|
|
|
+ // }
|
|
|
+ painter.pen.lineWidth = 200;
|
|
|
+ this.pointArr.map(t => {
|
|
|
+ painter.drawPolygon(t);
|
|
|
+ });
|
|
|
+ }
|
|
|
+ } // Function onDraw()
|
|
|
+} // Class ZoneItem
|