VirtualWallItem.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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. /**
  25. * 墙item
  26. *
  27. * @author 郝建龙
  28. */
  29. export class VirtualWallItem extends SGraphyItem {
  30. /** 虚拟墙数据 */
  31. data: VirtualWall;
  32. /** X坐标最小值 */
  33. private minX = 0;
  34. /** X坐标最大值 */
  35. private maxX = 0;
  36. /** Y坐标最小值 */
  37. private minY = 0;
  38. /** Y坐标最大值 */
  39. private maxY = 0;
  40. /** 虚拟墙轮廓线坐标list */
  41. private readonly pointArr: SPoint[][] = [];
  42. /**
  43. * 构造函数
  44. *
  45. * @param parent 指向父对象
  46. * @param data 虚拟墙数据
  47. */
  48. constructor(parent: SGraphyItem | null, data: VirtualWall) {
  49. super(parent);
  50. this.data = data;
  51. let tempArr = this.data.OutLine;
  52. if (tempArr && tempArr.length) {
  53. this.minX = tempArr[0][0].X;
  54. this.maxX = this.minX;
  55. this.minY = -tempArr[0][0].Y;
  56. this.maxY = this.minY;
  57. this.pointArr = tempArr.map(t => {
  58. let temp = t.map(it => {
  59. let x = it.X,
  60. y = -it.Y;
  61. if (x < this.minX) {
  62. this.minX = x;
  63. }
  64. if (y < this.minY) {
  65. this.minY = y;
  66. }
  67. if (x > this.maxX) {
  68. this.maxX = x;
  69. }
  70. if (y > this.maxY) {
  71. this.maxY = y;
  72. }
  73. return new SPoint(x, y);
  74. });
  75. return temp;
  76. });
  77. }
  78. } // Constructor
  79. /**
  80. * Item对象边界区域
  81. *
  82. * @return SRect
  83. */
  84. boundingRect(): SRect {
  85. return new SRect(
  86. this.minX,
  87. this.minY,
  88. this.maxX - this.minX,
  89. this.maxY - this.minY
  90. );
  91. } // Function boundingRect()
  92. /**
  93. * Item绘制操作
  94. *
  95. * @param painter painter对象
  96. * @param rect 绘制区域
  97. */
  98. onDraw(painter: SPainter): void {
  99. painter.pen.lineWidth = 100;
  100. painter.pen.color = Opt.virtualWallColor;
  101. painter.pen.lineDash = [200, 200];
  102. this.pointArr.map(t => {
  103. painter.drawPolyline(t);
  104. });
  105. } // Function onDraw()
  106. } // Class VirtualWall