VirtualWallItem.ts 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /*
  2. * ********************************************************************************************************************
  3. *
  4. * :*$@@%$*: ;: ;; ;;
  5. * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
  6. * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
  7. * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
  8. * =@* %! @ $= % %@= =%@! %=
  9. * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
  10. * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
  11. * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
  12. * $@* ;@@@%=!: *@*
  13. * =@$ ;;;!=%@@@@=! =@!
  14. * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司
  15. * ;%@@$=$@@%* *@@@$=%@@%;
  16. * ::;:: ::;:: All rights reserved.
  17. *
  18. * ********************************************************************************************************************
  19. */
  20. import { SGraphyItem } from "@saga-web/graphy/lib";
  21. import { SPainter, SPoint, SRect } from "@saga-web/draw/lib";
  22. import { VirtualWall } from "../types/VirtualWall";
  23. import { Opt } from "../types/Opt";
  24. import { ItemOrder } from "../types/ItemOrder";
  25. /**
  26. * 墙item
  27. *
  28. * @author 郝建龙
  29. */
  30. export class VirtualWallItem extends SGraphyItem {
  31. /** 虚拟墙数据 */
  32. data: VirtualWall;
  33. /** X坐标最小值 */
  34. private minX = 0;
  35. /** X坐标最大值 */
  36. private maxX = 0;
  37. /** Y坐标最小值 */
  38. private minY = 0;
  39. /** Y坐标最大值 */
  40. private maxY = 0;
  41. /** 虚拟墙轮廓线坐标list */
  42. private readonly pointArr: SPoint[][] = [];
  43. /**
  44. * 构造函数
  45. *
  46. * @param parent 指向父对象
  47. * @param data 虚拟墙数据
  48. */
  49. constructor(parent: SGraphyItem | null, data: VirtualWall) {
  50. super(parent);
  51. this.data = data;
  52. this.zOrder = ItemOrder.virtualWallOrder;
  53. let tempArr = this.data.OutLine;
  54. if (tempArr && tempArr.length) {
  55. this.minX = tempArr[0][0].X;
  56. this.maxX = this.minX;
  57. this.minY = -tempArr[0][0].Y;
  58. this.maxY = this.minY;
  59. this.pointArr = tempArr.map((t): SPoint[] => {
  60. return t.map(
  61. (it): SPoint => {
  62. let x = it.X,
  63. y = -it.Y;
  64. if (x < this.minX) {
  65. this.minX = x;
  66. }
  67. if (y < this.minY) {
  68. this.minY = y;
  69. }
  70. if (x > this.maxX) {
  71. this.maxX = x;
  72. }
  73. if (y > this.maxY) {
  74. this.maxY = y;
  75. }
  76. return new SPoint(x, y);
  77. }
  78. );
  79. });
  80. }
  81. } // Constructor
  82. /**
  83. * Item对象边界区域
  84. *
  85. * @return SRect
  86. */
  87. boundingRect(): SRect {
  88. return new SRect(
  89. this.minX,
  90. this.minY,
  91. this.maxX - this.minX,
  92. this.maxY - this.minY
  93. );
  94. } // Function boundingRect()
  95. /**
  96. * Item绘制操作
  97. *
  98. * @param painter painter对象
  99. */
  100. onDraw(painter: SPainter): void {
  101. painter.pen.lineWidth = 100;
  102. painter.pen.color = Opt.virtualWallColor;
  103. painter.pen.lineDash = [200, 200];
  104. this.pointArr.forEach((t): void => {
  105. painter.drawPolyline(t);
  106. });
  107. } // Function onDraw()
  108. } // Class VirtualWall