FloorScene.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. import { getJsonz, ItemColor } from "@persagy-web/big/lib";
  2. import { SColumnItem } from "@persagy-web/big/lib/items/floor/SColumnItem";
  3. import { SDoorItem } from "@persagy-web/big/lib/items/floor/SDoorItem";
  4. import { SSpaceItem } from "@persagy-web/big/lib/items/floor/SSpaceItem";
  5. import { SVirtualWallItem } from "@persagy-web/big/lib/items/floor/SVirtualWallItem";
  6. import { SWallItem } from "@persagy-web/big/lib/items/floor/SWallItem";
  7. import { SWindowItem } from "@persagy-web/big/lib/items/floor/SWindowItem";
  8. import { Casement } from "@persagy-web/big/lib/types/floor/Casement";
  9. import { Column } from "@persagy-web/big/lib/types/floor/Column";
  10. import { Door } from "@persagy-web/big/lib/types/floor/Door";
  11. import { Space } from "@persagy-web/big/lib/types/floor/Space";
  12. import { VirtualWall } from "@persagy-web/big/lib/types/floor/VirtualWall";
  13. import { Wall } from "@persagy-web/big/lib/types/floor/Wall";
  14. import { FloorData } from "@persagy-web/big/lib/types/FloorData";
  15. import { SGraphScene } from "@persagy-web/graph/lib";
  16. /**
  17. * 楼层平面图
  18. */
  19. export class FloorScene extends SGraphScene {
  20. /** json数据 */
  21. json: string | null = null;
  22. /** 墙list */
  23. wallList: SWallItem[] = [];
  24. /** 柱子list */
  25. columnList: SColumnItem[] = [];
  26. /** 门list */
  27. doorList: SDoorItem[] = [];
  28. /** 窗list */
  29. casementList: SWindowItem[] = [];
  30. /** 虚拟墙list */
  31. virtualWallList: SVirtualWallItem[] = [];
  32. /** 空间list */
  33. spaceList: SSpaceItem[] = [];
  34. /** 空间是否可选 */
  35. _isSpaceSelectable: boolean = true;
  36. get isSpaceSelectable(): boolean {
  37. return this._isSpaceSelectable;
  38. } // Get isSpaceSelectable
  39. set isSpaceSelectable(v: boolean) {
  40. if (this._isSpaceSelectable === v) {
  41. return;
  42. }
  43. this._isSpaceSelectable = v;
  44. this.spaceList.map(
  45. (t: SSpaceItem): SSpaceItem => {
  46. t.selectable = this._isSpaceSelectable;
  47. return t;
  48. }
  49. );
  50. } // Set isSpaceSelectable
  51. constructor() {
  52. super()
  53. // 设置始终不出现选择器
  54. this.selectContainer.showSelect = false;
  55. }
  56. /**
  57. * 获取底图压缩文件
  58. *
  59. * @param url 请求数据文件路径
  60. */
  61. loadUrl(url: string): Promise<void> {
  62. return getJsonz(url).then((res: any) => {
  63. this.addBaseMapItem(res)
  64. this.json = JSON.stringify(res);
  65. return res;
  66. })
  67. } // Function loadUrl()
  68. /**
  69. * 增添所有底图item;
  70. *
  71. * @param data itemList对象
  72. */
  73. private addBaseMapItem(data: FloorData): void {
  74. if (data.Walls) {
  75. data.Walls.forEach((t: Wall): void => {
  76. this.addWall(t);
  77. });
  78. }
  79. if (data.Columns) {
  80. data.Columns.forEach((t: Column): void => {
  81. this.addColumn(t);
  82. });
  83. }
  84. if (data.Windows) {
  85. data.Windows.forEach((t: Casement): void => {
  86. this.addCasement(t);
  87. });
  88. }
  89. if (data.VirtualWalls) {
  90. data.VirtualWalls.forEach((t: VirtualWall): void => {
  91. this.addVirtualWall(t);
  92. });
  93. }
  94. if (data.Doors) {
  95. data.Doors.forEach((t: Door): void => {
  96. this.addDoor(t);
  97. });
  98. }
  99. if (data.Spaces) {
  100. data.Spaces.forEach((t: Space): void => {
  101. this.addSpace(t);
  102. });
  103. }
  104. } // Function addBaseMapItem()
  105. /**
  106. * 添加空间到scene 中
  107. *
  108. * @param space 空间item
  109. */
  110. addSpace(space: Space): void {
  111. let item = new SSpaceItem(null, space);
  112. item.selectable = this.isSpaceSelectable;
  113. item.fillColor = ItemColor.spaceColor;
  114. item.strokeColor = ItemColor.spaceBorderColor;
  115. this.spaceList.push(item);
  116. this.addItem(item);
  117. } // Function addSpace()
  118. /**
  119. * 添加柱子到scene 中
  120. *
  121. * @param column 柱子item
  122. */
  123. addColumn(column: Column): void {
  124. let item = new SColumnItem(null, column);
  125. item.fillColor = ItemColor.columnColor;
  126. this.columnList.push(item);
  127. this.addItem(item);
  128. } // Function addColumn()
  129. /**
  130. * 添加墙到scene 中
  131. *
  132. * @param wall 墙item
  133. */
  134. addWall(wall: Wall): void {
  135. let item = new SWallItem(null, wall);
  136. item.fillColor = ItemColor.wallColor;
  137. this.wallList.push(item);
  138. this.addItem(item);
  139. } // Function addWall()
  140. /**
  141. * 添加所有虚拟墙到scene中
  142. *
  143. * @param virtualWall 虚拟墙item
  144. */
  145. addVirtualWall(virtualWall: VirtualWall): void {
  146. let item = new SVirtualWallItem(null, virtualWall);
  147. this.virtualWallList.push(item);
  148. this.addItem(item);
  149. } // Function addVirtualWall()
  150. /**
  151. * 添加门到scene 中
  152. *
  153. * @param door
  154. */
  155. addDoor(door: Door): void {
  156. let item = new SDoorItem(null, door);
  157. this.doorList.push(item);
  158. this.addItem(item);
  159. } // Function addDoor()
  160. /**
  161. * 添加窗户到scene 中
  162. *
  163. * @param casement
  164. */
  165. addCasement(casement: Casement): void {
  166. let item = new SWindowItem(null, casement);
  167. this.casementList.push(item);
  168. this.addItem(item);
  169. } // Function addCasement()
  170. }