SGraphyPolygonItem.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. var __extends = (this && this.__extends) || (function () {
  2. var extendStatics = function (d, b) {
  3. extendStatics = Object.setPrototypeOf ||
  4. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  5. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  6. return extendStatics(d, b);
  7. };
  8. return function (d, b) {
  9. extendStatics(d, b);
  10. function __() { this.constructor = d; }
  11. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  12. };
  13. })();
  14. import { SGraphyItem } from '@sybotan-web/graphy';
  15. import { SRect, SPoint } from "@sybotan-web/base";
  16. import { SColor } from "@sybotan-web/draw";
  17. /**
  18. * 不规则多边形Item类
  19. *
  20. */
  21. var SGraphyPolygonItem = /** @class */ (function (_super) {
  22. __extends(SGraphyPolygonItem, _super);
  23. // actived: boolean = false; //是否激活
  24. /**
  25. * 构造函数
  26. *
  27. * @param pointArr 点坐标list
  28. * @param width 边框的宽度
  29. * @param color 边框的颜色
  30. * @param fillColor 多边形填充的颜色
  31. * @param businessId 空间id
  32. * @param businessName 空间名称
  33. * @param centerOfGravityPoint 中心点
  34. * @param isBusiness 状态
  35. * @param parent
  36. */
  37. function SGraphyPolygonItem(PolygonItemData) {
  38. var _this = _super.call(this, PolygonItemData.parent) || this;
  39. _this.fillColor = new SColor('#F2F6FC');
  40. _this.color = SColor.Black;
  41. _this.width = 0;
  42. _this.viewText = '111'; //绘出的文案
  43. _this.isBusiness = 1;
  44. _this.cacheColor = SColor.Black; //需要缓存的边框
  45. _this.cacheFillColor = new SColor('#F2F6FC'); //需要缓存的填充色
  46. _this.cacheWidth = 0;
  47. // 修改绘制路径格式
  48. var newSpacePaths = PolygonItemData.space.Paths[0].map(function (item) {
  49. return new SPoint(item.X, item.Y);
  50. });
  51. _this.pointArr = newSpacePaths;
  52. // // 填充色
  53. PolygonItemData.fillColor ? _this.fillColor = PolygonItemData.fillColor : _this.fillColor = new SColor('#F2F6FC');
  54. // 边框色
  55. PolygonItemData.color ? _this.color = PolygonItemData.color : _this.color = SColor.Black;
  56. //边框宽度
  57. PolygonItemData.width ? _this.width = PolygonItemData.width : _this.width = 0;
  58. //中心点
  59. _this.centerOfGravityPoint = {
  60. x: PolygonItemData.space.LocationPoint.X,
  61. y: PolygonItemData.space.LocationPoint.Y * (-1)
  62. };
  63. //业务空间类型
  64. _this.isBusiness = PolygonItemData.space.isBusiness ? PolygonItemData.space.isBusiness : _this.isBusiness = 1;
  65. //业务空间id
  66. PolygonItemData.businessId ? _this.businessId = PolygonItemData.businessId : _this.businessId = null;
  67. //业务空间名称
  68. _this.businessName = PolygonItemData.space.Name;
  69. _this.initName = PolygonItemData.space.Name;
  70. // 空间id
  71. _this.id = PolygonItemData.space.id;
  72. return _this;
  73. }
  74. /**
  75. * Item对象边界区域
  76. *
  77. * @return SRect
  78. */
  79. SGraphyPolygonItem.prototype.boundingRect = function () {
  80. var minX = this.pointArr[0].x;
  81. var maxX = minX;
  82. var minY = this.pointArr[0].y;
  83. var maxY = minY;
  84. for (var i = 1; i < this.pointArr.length; i++) {
  85. if (this.pointArr[i].x < minX) {
  86. minX = this.pointArr[i].x;
  87. }
  88. if (this.pointArr[i].y < minY) {
  89. minY = this.pointArr[i].y;
  90. }
  91. if (this.pointArr[i].x > maxX) {
  92. maxX = this.pointArr[i].x;
  93. }
  94. if (this.pointArr[i].y > maxY) {
  95. maxY = this.pointArr[i].y;
  96. }
  97. }
  98. return new SRect(minX, minY, maxX - minX, maxY - minY);
  99. }; // Function boundingRect()
  100. /**
  101. * 判断点是否在区域内
  102. *
  103. * @param x
  104. * @param y
  105. */
  106. SGraphyPolygonItem.prototype.contains = function (x, y) {
  107. var nCross = 0, point = [x, y], APoints = this.pointArr, length = APoints.length, p1, p2, i, xinters;
  108. p1 = APoints[0];
  109. for (i = 1; i <= length; i++) {
  110. p2 = APoints[i % length];
  111. if (point[0] > Math.min(p1.x, p2.x) &&
  112. point[0] <= Math.max(p1.x, p2.x)) {
  113. if (point[1] <= Math.max(p1.y, p2.y)) {
  114. if (p1.x != p2.x) {
  115. //计算位置信息
  116. xinters = (point[0] - p1.x) * (p2.y - p1.y) / (p2.x - p1.x) + p1.y;
  117. if (p1.y == p2.y || point[1] <= xinters) {
  118. nCross++;
  119. }
  120. }
  121. }
  122. }
  123. p1 = p2;
  124. }
  125. return nCross % 2 === 1;
  126. };
  127. /**
  128. * Item绘制操作
  129. *
  130. * @param painter painter对象
  131. * @param rect 绘制区域
  132. */
  133. SGraphyPolygonItem.prototype.onDraw = function (painter, rect) {
  134. if (this.pointArr.length) {
  135. painter.pen.color = this.color;
  136. painter.brush.color = this.fillColor;
  137. painter.pen.lineWidth = this.width;
  138. painter.drawPolygon(this.pointArr);
  139. painter.font.size = this.scale * 200;
  140. painter.brush.color = SColor.Black;
  141. painter.drawText(this.viewText, this.centerOfGravityPoint.x, this.centerOfGravityPoint.y);
  142. }
  143. };
  144. SGraphyPolygonItem.prototype.onClick = function (event) {
  145. this.$emit('click', { item: this, event: event });
  146. return true;
  147. }; // Function onClick()
  148. /**
  149. * 鼠标双击事件
  150. *
  151. * @param event 保存事件参数
  152. * @return boolean
  153. */
  154. SGraphyPolygonItem.prototype.onDoubleClick = function (event) {
  155. this.$emit('doubleClick', { item: this, event: event });
  156. return true;
  157. };
  158. /**
  159. * 鼠标按下事件
  160. *
  161. * @param event 保存事件参数
  162. * @return boolean
  163. */
  164. SGraphyPolygonItem.prototype.onMouseDown = function (event) {
  165. this.$emit('mouseDown', { item: this, event: event });
  166. return true;
  167. }; // Function onMouseDown()
  168. /**
  169. * 鼠标移动事件
  170. *
  171. * @param event 保存事件参数
  172. * @return boolean
  173. */
  174. SGraphyPolygonItem.prototype.onMouseMove = function (event) {
  175. this.$emit('mouseMove', { item: this, event: event });
  176. return true;
  177. }; // Function onMouseMove()
  178. /**
  179. * 释放鼠标事件
  180. *
  181. * @param event 保存事件参数
  182. * @return boolean
  183. */
  184. SGraphyPolygonItem.prototype.onMouseUp = function (event) {
  185. this.$emit('mouseUp', { item: this, event: event });
  186. return true;
  187. };
  188. return SGraphyPolygonItem;
  189. }(SGraphyItem)); // Class SGraphyPolygonItem
  190. export { SGraphyPolygonItem };