ZoneItem.ts 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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) 2009-2020. 博锐尚格科技股份有限公司
  21. * ~8888'
  22. * .!88~ All rights reserved.
  23. *
  24. * *********************************************************************************************************************
  25. */
  26. import { SColor, SPainter, SPoint, SRect } from "@persagy-web/draw";
  27. import { SMouseEvent } from "@persagy-web/base";
  28. import { Zone } from "../../types/floor/Zone";
  29. import { ItemColor, ItemOrder, Transparency } from "../..";
  30. import { Point, SGraphAreaGroupItem, SGraphItem } from "@persagy-web/graph";
  31. /**
  32. * 业务空间 item
  33. *
  34. * @author 郝建龙 <haojianlong@sagacloud.cn>
  35. */
  36. export class SZoneItem extends SGraphAreaGroupItem {
  37. /** 空间所有数据 */
  38. data: Zone;
  39. /** 点击位置坐标 */
  40. private clickPoint: SPoint | undefined;
  41. /** 高亮状态 */
  42. private _highLightFlag: boolean = false;
  43. get highLightFlag(): boolean {
  44. return this._highLightFlag;
  45. } // Get highLightFlag
  46. set highLightFlag(value: boolean) {
  47. this._highLightFlag = value;
  48. this.update();
  49. } // Set highLightFlag
  50. /** 透明度 */
  51. _transparency: number = 20;
  52. get transparency(): number {
  53. return this._transparency;
  54. } // Get transparency
  55. set transparency(value: number) {
  56. this._transparency = value;
  57. this.update();
  58. } // Set transparency
  59. /** 受影响状态 */
  60. _isInfected: boolean = false;
  61. get isInfected(): boolean {
  62. return this._isInfected;
  63. } // Get isInfected
  64. set isInfected(value: boolean) {
  65. this._isInfected = value;
  66. this.update();
  67. } // Set isInfected
  68. /**
  69. * 构造函数
  70. *
  71. * @param parent 指向父对象
  72. * @param data 空间数据
  73. */
  74. constructor(parent: SGraphItem | null, data: Zone) {
  75. super(parent, {
  76. outline: data.OutLine.map((t): Point[][] => {
  77. return t.map((it): Point[] => {
  78. return it.map(
  79. (item): Point => {
  80. return { x: item.X, y: -item.Y };
  81. }
  82. );
  83. });
  84. }),
  85. style: {
  86. default: {
  87. stroke: "#00000000",
  88. fill: "#ffee2280",
  89. lineWidth: 1,
  90. effect: {}
  91. },
  92. selected: {
  93. stroke: "#00000000",
  94. fill: "#1abc9c",
  95. lineWidth: 1,
  96. effect: {}
  97. },
  98. highlight: {
  99. stroke: "#00000000",
  100. fill: data.Color || "#fbb029",
  101. lineWidth: 1,
  102. effect: {}
  103. },
  104. unselect: {
  105. stroke: "#00000000",
  106. fill: "#cecece",
  107. lineWidth: 1,
  108. effect: {}
  109. },
  110. infected: {
  111. stroke: "#00000000",
  112. fill: "#ff0000",
  113. lineWidth: 1,
  114. effect: {}
  115. }
  116. }
  117. });
  118. this.data = data;
  119. this.zOrder = ItemOrder.zoneOrder;
  120. this.highLightFlag = data.HighLightFlag || false;
  121. this.transparency = data.Transparency || 20;
  122. this.isInfected = data.Infected || false;
  123. } // Constructor
  124. /**
  125. * 鼠标单击事件
  126. *
  127. * @param event 事件参数
  128. * @return 是否处理事件
  129. */
  130. onMouseDown(event: SMouseEvent): boolean {
  131. if (this.selectable) {
  132. this.selected = !this.selected;
  133. this.clickPoint = new SPoint(event.x, event.y);
  134. }
  135. this.$emit("click", event);
  136. return true;
  137. } // Function onMouseDown()
  138. /**
  139. * 鼠标抬起事件
  140. *
  141. * @param event 事件参数
  142. * @return 是否处理事件
  143. */
  144. onMouseUp(event: SMouseEvent): boolean {
  145. return false;
  146. } // Function onMouseUp()
  147. /**
  148. * 绘制前设置绘制样式
  149. *
  150. * @return 当前状态
  151. */
  152. setStyle(): string {
  153. let status = "default";
  154. if (this.style) {
  155. if (!this.selectable) {
  156. status = "unselect";
  157. } else {
  158. if (this.selected) {
  159. status = "selected";
  160. } else if (this.highLightFlag) {
  161. status = "highlight";
  162. } else if (this.isInfected) {
  163. status = "infected";
  164. } else {
  165. status = "default";
  166. if (this.data.Color) {
  167. this.style.default.fill = `${this.data.Color}${
  168. Transparency[this.transparency]
  169. }`;
  170. }
  171. }
  172. }
  173. }
  174. return status;
  175. } // Function setStyle()
  176. /**
  177. * Item 绘制操作
  178. *
  179. * @param painter 绘制对象
  180. */
  181. onDraw(painter: SPainter): void {
  182. super.onDraw(painter);
  183. painter.brush.color = SColor.Black;
  184. painter.font.size = painter.toPx(10);
  185. if (this.clickPoint) {
  186. painter.drawText(
  187. this.data.RoomLocalName,
  188. this.clickPoint.x,
  189. this.clickPoint.y
  190. );
  191. }
  192. } // Function onDraw()
  193. } // Class ZoneItem