ZoneItem.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SZoneItem = void 0;
  4. const lib_1 = require("@persagy-web/draw/lib");
  5. const __1 = require("../..");
  6. const lib_2 = require("@persagy-web/graph/lib");
  7. class SZoneItem extends lib_2.SGraphItem {
  8. constructor(parent, data) {
  9. super(parent);
  10. this.pointArr = [];
  11. this.minX = Number.MAX_SAFE_INTEGER;
  12. this.maxX = Number.MIN_SAFE_INTEGER;
  13. this.minY = Number.MAX_SAFE_INTEGER;
  14. this.maxY = Number.MIN_SAFE_INTEGER;
  15. this.pathList = [];
  16. this.selectColor = __1.ItemColor.selectColor;
  17. this.unselectColor = __1.ItemColor.zoneUnselectColor;
  18. this._highLightFlag = false;
  19. this._transparency = 20;
  20. this._isInfected = false;
  21. this.infectedColor = __1.ItemColor.zoneInfectedColor;
  22. this.infectedBorder = __1.ItemColor.zoneInfectedBorder;
  23. this.data = data;
  24. this.zOrder = __1.ItemOrder.zoneOrder;
  25. this.highLightFlag = data.HighLightFlag || false;
  26. this.transparency = data.Transparency || 20;
  27. this.isInfected = data.Infected || false;
  28. if (this.data.OutLine.length &&
  29. this.data.OutLine[0] &&
  30. this.data.OutLine[0].length) {
  31. let tempArr = this.data.OutLine;
  32. this.minX = tempArr[0][0][0].X;
  33. this.maxX = this.minX;
  34. this.minY = -tempArr[0][0][0].Y;
  35. this.maxY = this.minY;
  36. this.pointArr = tempArr.map((t) => {
  37. let sPath = new lib_1.SPath2D();
  38. let tempArr = t.map((it) => {
  39. let array = it.map((item) => {
  40. let x = item.X, y = -item.Y;
  41. if (x < this.minX) {
  42. this.minX = x;
  43. }
  44. if (y < this.minY) {
  45. this.minY = y;
  46. }
  47. if (x > this.maxX) {
  48. this.maxX = x;
  49. }
  50. if (y > this.maxY) {
  51. this.maxY = y;
  52. }
  53. return new lib_1.SPoint(x, y);
  54. });
  55. sPath.polygon(array);
  56. return array;
  57. });
  58. this.pathList.push(sPath);
  59. return tempArr;
  60. });
  61. }
  62. }
  63. get highLightFlag() {
  64. return this._highLightFlag;
  65. }
  66. set highLightFlag(value) {
  67. this._highLightFlag = value;
  68. this.update();
  69. }
  70. get transparency() {
  71. return this._transparency;
  72. }
  73. set transparency(value) {
  74. this._transparency = value;
  75. this.update();
  76. }
  77. get isInfected() {
  78. return this._isInfected;
  79. }
  80. set isInfected(value) {
  81. this._isInfected = value;
  82. this.update();
  83. }
  84. boundingRect() {
  85. return new lib_1.SRect(this.minX, this.minY, this.maxX - this.minX, this.maxY - this.minY);
  86. }
  87. onMouseDown(event) {
  88. if (this.selectable) {
  89. this.selected = !this.selected;
  90. this.clickPoint = new lib_1.SPoint(event.x, event.y);
  91. }
  92. this.$emit("click", event);
  93. return true;
  94. }
  95. onMouseUp(event) {
  96. return false;
  97. }
  98. contains(x, y) {
  99. for (let j = 0; j < this.pointArr.length; j++) {
  100. let arr = this.pointArr[j];
  101. if (arr.length < 1 || !lib_1.SPolygonUtil.pointIn(x, y, arr[0])) {
  102. continue;
  103. }
  104. if (arr.length == 1) {
  105. return true;
  106. }
  107. let flag = false;
  108. for (let i = 1; i < arr.length; i++) {
  109. if (lib_1.SPolygonUtil.pointIn(x, y, arr[i])) {
  110. flag = true;
  111. break;
  112. }
  113. }
  114. if (flag) {
  115. continue;
  116. }
  117. return true;
  118. }
  119. return false;
  120. }
  121. onDraw(painter, rect) {
  122. painter.pen.color = lib_1.SColor.Transparent;
  123. if (!this.selectable) {
  124. painter.brush.color = this.unselectColor;
  125. }
  126. else {
  127. if (this.selected) {
  128. painter.brush.color = this.selectColor;
  129. }
  130. else if (this.highLightFlag) {
  131. painter.brush.color = new lib_1.SColor(this.data.Color);
  132. }
  133. else if (this.isInfected) {
  134. painter.brush.color = this.infectedColor;
  135. }
  136. else {
  137. painter.brush.color = new lib_1.SColor(`${this.data.Color}${__1.Transparency[this.transparency]}`);
  138. }
  139. }
  140. painter.pen.lineWidth = painter.toPx(1);
  141. this.pathList.forEach((t) => {
  142. painter.drawPath(t);
  143. });
  144. painter.brush.color = lib_1.SColor.Black;
  145. painter.font.size = painter.toPx(10);
  146. if (this.clickPoint) {
  147. painter.drawText(this.data.RoomLocalName, this.clickPoint.x, this.clickPoint.y);
  148. }
  149. }
  150. }
  151. exports.SZoneItem = SZoneItem;