ZoneItem.ts 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. /*
  2. * *********************************************************************************************************************
  3. *
  4. * !!
  5. * .F88X
  6. * X8888Y
  7. * .}888888N;
  8. * i888888N; .:! .I$WI:
  9. * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8&
  10. * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I
  11. * +888888N; .8888888Y "&&8Y.}8,
  12. * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i
  13. * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$*
  14. * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I
  15. * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~
  16. * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi'
  17. * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I
  18. * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/
  19. * .:R888888I
  20. * .&888888I Copyright (c) 2016-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import {
  27. SColor,
  28. SPainter,
  29. SPath2D,
  30. SPoint,
  31. SPolygonUtil,
  32. SRect
  33. } from "@persagy-web/draw/lib";
  34. import { SMouseEvent } from "@persagy-web/base/lib";
  35. import { Zone } from "../../types/floor/Zone";
  36. import { ItemColor, ItemOrder, Transparency } from "../..";
  37. import { SGraphItem } from "@persagy-web/graph/lib";
  38. /**
  39. * 业务空间item
  40. *
  41. * @author 郝建龙
  42. */
  43. export class SZoneItem extends SGraphItem {
  44. /** 空间所有数据 */
  45. data: Zone;
  46. /** 空间轮廓线坐标list */
  47. readonly pointArr: SPoint[][][] = [];
  48. /** X坐标最小值 */
  49. private minX = Number.MAX_SAFE_INTEGER;
  50. /** X坐标最大值 */
  51. private maxX = Number.MIN_SAFE_INTEGER;
  52. /** Y坐标最小值 */
  53. private minY = Number.MAX_SAFE_INTEGER;
  54. /** Y坐标最大值 */
  55. private maxY = Number.MIN_SAFE_INTEGER;
  56. /** path */
  57. private pathList: SPath2D[] = [];
  58. /** 点击位置坐标 */
  59. private clickPoint: SPoint | undefined;
  60. /** 选中时的颜色 */
  61. private selectColor: SColor = ItemColor.selectColor;
  62. /** 不可选时的颜色 */
  63. private unselectColor: SColor = ItemColor.zoneUnselectColor;
  64. /** 高亮状态 */
  65. private _highLightFlag: boolean = false;
  66. get highLightFlag(): boolean {
  67. return this._highLightFlag;
  68. } // Get highLightFlag
  69. set highLightFlag(value: boolean) {
  70. this._highLightFlag = value;
  71. this.update();
  72. } // Set highLightFlag
  73. /** 透明度 */
  74. _transparency: number = 20;
  75. get transparency(): number {
  76. return this._transparency;
  77. } // Get transparency
  78. set transparency(value: number) {
  79. this._transparency = value;
  80. this.update();
  81. } // Set transparency
  82. /** 受影响状态 */
  83. _isInfected: boolean = false;
  84. get isInfected(): boolean {
  85. return this._isInfected;
  86. } // Get isInfected
  87. set isInfected(value: boolean) {
  88. this._isInfected = value;
  89. this.update();
  90. } // Set isInfected
  91. /** 受影响的业务空间填充颜色 */
  92. private infectedColor: SColor = ItemColor.zoneInfectedColor;
  93. /** 受影响的业务空间边框颜色 */
  94. private infectedBorder: SColor = ItemColor.zoneInfectedBorder;
  95. /**
  96. * 构造函数
  97. *
  98. * @param parent 指向父对象
  99. * @param data 空间数据
  100. */
  101. constructor(parent: SGraphItem | null, data: Zone) {
  102. super(parent);
  103. this.data = data;
  104. this.zOrder = ItemOrder.zoneOrder;
  105. this.highLightFlag = data.HighLightFlag || false;
  106. this.transparency = data.Transparency || 20;
  107. this.isInfected = data.Infected || false;
  108. if (
  109. this.data.OutLine.length &&
  110. this.data.OutLine[0] &&
  111. this.data.OutLine[0].length
  112. ) {
  113. let tempArr = this.data.OutLine;
  114. this.minX = tempArr[0][0][0].X;
  115. this.maxX = this.minX;
  116. this.minY = -tempArr[0][0][0].Y;
  117. this.maxY = this.minY;
  118. // 处理轮廓点数组,同时计算最大最小值
  119. this.pointArr = tempArr.map((t): SPoint[][] => {
  120. let sPath = new SPath2D();
  121. let tempArr = t.map((it): SPoint[] => {
  122. let array = it.map(
  123. (item): SPoint => {
  124. let x = item.X,
  125. y = -item.Y;
  126. if (x < this.minX) {
  127. this.minX = x;
  128. }
  129. if (y < this.minY) {
  130. this.minY = y;
  131. }
  132. if (x > this.maxX) {
  133. this.maxX = x;
  134. }
  135. if (y > this.maxY) {
  136. this.maxY = y;
  137. }
  138. return new SPoint(x, y);
  139. }
  140. );
  141. sPath.polygon(array);
  142. return array;
  143. });
  144. this.pathList.push(sPath);
  145. return tempArr;
  146. });
  147. }
  148. } // Constructor
  149. /**
  150. * Item对象边界区域
  151. *
  152. * @return SRect
  153. */
  154. boundingRect(): SRect {
  155. return new SRect(
  156. this.minX,
  157. this.minY,
  158. this.maxX - this.minX,
  159. this.maxY - this.minY
  160. );
  161. } // Function boundingRect()
  162. /**
  163. * 鼠标单击事件
  164. *
  165. * @param event 事件参数
  166. * @return boolean
  167. */
  168. onMouseDown(event: SMouseEvent): boolean {
  169. if (this.selectable) {
  170. this.selected = !this.selected;
  171. this.clickPoint = new SPoint(event.x, event.y);
  172. }
  173. this.$emit("click", event);
  174. return true;
  175. } // Function onMouseDown()
  176. /**
  177. * 鼠标抬起事件
  178. *
  179. * @param event 事件参数
  180. * @return boolean
  181. */
  182. onMouseUp(event: SMouseEvent): boolean {
  183. return false;
  184. } // Function onMouseUp()
  185. /**
  186. * 判断点是否在区域内
  187. *
  188. * @param x
  189. * @param y
  190. */
  191. contains(x: number, y: number): boolean {
  192. // return true;
  193. for (let j = 0; j < this.pointArr.length; j++) {
  194. let arr = this.pointArr[j];
  195. if (arr.length < 1 || !SPolygonUtil.pointIn(x, y, arr[0])) {
  196. continue;
  197. }
  198. if (arr.length == 1) {
  199. return true;
  200. }
  201. let flag = false;
  202. for (let i = 1; i < arr.length; i++) {
  203. if (SPolygonUtil.pointIn(x, y, arr[i])) {
  204. flag = true;
  205. break;
  206. }
  207. }
  208. if (flag) {
  209. continue;
  210. }
  211. return true;
  212. }
  213. return false;
  214. } // Function contains()
  215. /**
  216. * Item绘制操作
  217. *
  218. * @param painter painter对象
  219. * @param rect 绘制区域
  220. */
  221. onDraw(painter: SPainter, rect?: SRect): void {
  222. painter.pen.color = SColor.Transparent;
  223. if (!this.selectable) {
  224. painter.brush.color = this.unselectColor;
  225. } else {
  226. if (this.selected) {
  227. painter.brush.color = this.selectColor;
  228. } else if (this.highLightFlag) {
  229. painter.brush.color = new SColor(this.data.Color);
  230. } else if (this.isInfected) {
  231. painter.brush.color = this.infectedColor;
  232. // painter.pen.color = this.infectedBorder;
  233. } else {
  234. painter.brush.color = new SColor(
  235. `${this.data.Color}${Transparency[this.transparency]}`
  236. );
  237. }
  238. }
  239. painter.pen.lineWidth = painter.toPx(1);
  240. this.pathList.forEach((t): void => {
  241. painter.drawPath(t);
  242. });
  243. painter.brush.color = SColor.Black;
  244. painter.font.size = painter.toPx(10);
  245. if (this.clickPoint) {
  246. painter.drawText(
  247. this.data.RoomLocalName,
  248. this.clickPoint.x,
  249. this.clickPoint.y
  250. );
  251. }
  252. } // Function onDraw()
  253. } // Class ZoneItem