FloorScene.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  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 { SGraphyClockItem, SGraphyScene } from "@sybotan-web/graphy/lib";
  21. // @ts-ignore
  22. import pako from "pako";
  23. import { FloorData } from "./types/FloorData";
  24. import { Space } from "./types/Space";
  25. import { Column } from "./types/Column";
  26. import { Wall } from "./types/Wall";
  27. import { VirtualWall } from "./types/VirtualWall";
  28. import { Door } from "./types/Door";
  29. import { Casement } from "./types/Casement";
  30. import Axios from "axios";
  31. import { SpaceItem } from "./items/SpaceItem";
  32. import { WallItem } from "./items/WallItem";
  33. import { ColumnItem } from "./items/ColumnItem";
  34. import { VirtualWallItem } from "./items/VirtualWallItem";
  35. import { DoorItem } from "./items/DoorItem";
  36. import { WindowItem } from "./items/WindowItem";
  37. /**
  38. * 楼层场景
  39. *
  40. * @author 郝建龙
  41. */
  42. export class FloorScene extends SGraphyScene {
  43. /** item数据 */
  44. data: FloorData | null = null;
  45. /** 是否显示空间 */
  46. private _isShowSpace: boolean = true;
  47. get isShowSpace(): boolean {
  48. return this._isShowSpace;
  49. } // Get isShowSpace
  50. set isShowSpace(v: boolean) {
  51. if (this._isShowSpace === v) {
  52. return;
  53. }
  54. this._isShowSpace = v;
  55. this.spaceList.map((t: SpaceItem) => {
  56. t.visible = this._isShowSpace;
  57. return t;
  58. });
  59. } // Set isShowSpace
  60. /** 是否显示柱子 */
  61. private _isShowColumn: boolean = true;
  62. get isShowColumn(): boolean {
  63. return this._isShowColumn;
  64. } // Get isShowColumn
  65. set isShowColumn(v: boolean) {
  66. if (this._isShowColumn === v) {
  67. return;
  68. }
  69. this._isShowColumn = v;
  70. this.columnList.map((t: ColumnItem) => {
  71. t.visible = this._isShowColumn;
  72. return t;
  73. });
  74. } // Set isShowColumn
  75. /** 是否展示墙体 */
  76. private _isShowWall: boolean = true;
  77. get isShowWall(): boolean {
  78. return this._isShowWall;
  79. } // Get isShowWall
  80. set isShowWall(v: boolean) {
  81. if (this._isShowWall === v) {
  82. return;
  83. }
  84. this._isShowWall = v;
  85. this.wallList.map((t: WallItem) => {
  86. t.visible = this._isShowWall;
  87. return t;
  88. });
  89. } // Set isShowWall
  90. /** 是否展示虚拟墙 */
  91. _isShowVirtualWall: boolean = true;
  92. get isShowVirtualWall(): boolean {
  93. return this._isShowVirtualWall;
  94. } // Get isShowVrtualWall
  95. set isShowVirtualWall(v: boolean) {
  96. if (this._isShowVirtualWall === v) {
  97. return;
  98. }
  99. this._isShowVirtualWall = v;
  100. this.virtualWallList.map((t: VirtualWallItem) => {
  101. t.visible = this._isShowVirtualWall;
  102. return t;
  103. });
  104. } // Set isShowVrtualWall
  105. /** 是否展示门 */
  106. _isShowDoor: boolean = true;
  107. get isShowDoor(): boolean {
  108. return this._isShowDoor;
  109. } // Get isShowDoor
  110. set isShowDoor(v: boolean) {
  111. if (this._isShowDoor === v) {
  112. return;
  113. }
  114. this._isShowDoor = v;
  115. this.doorList.map((t: DoorItem) => {
  116. t.visible = this._isShowDoor;
  117. return t;
  118. });
  119. } // Set isShowDoor
  120. /** 是否展示窗户 */
  121. _isShowWindow: boolean = true;
  122. get isShowWindow(): boolean {
  123. return this._isShowWindow;
  124. } // Get isShowWindow
  125. set isShowWindow(v: boolean) {
  126. if (this._isShowWindow === v) {
  127. return;
  128. }
  129. this._isShowWindow = v;
  130. this.casementList.map((t: WindowItem) => {
  131. t.visible = this._isShowWindow;
  132. return t;
  133. });
  134. } // Set isShowWindow
  135. /** 墙list */
  136. wallList: WallItem[] = [];
  137. /** 柱子list */
  138. columnList: ColumnItem[] = [];
  139. /** 门list */
  140. doorList: DoorItem[] = [];
  141. /** 窗list */
  142. casementList: WindowItem[] = [];
  143. /** 虚拟墙list */
  144. virtualWallList: VirtualWallItem[] = [];
  145. /** 空间list */
  146. spaceList: SpaceItem[] = [];
  147. /**
  148. * @param data 绘制空间地图得所有参数
  149. */
  150. constructor() {
  151. super();
  152. } // Constructor()
  153. /**
  154. * 获取底图压缩文件
  155. *
  156. * @param url 请求数据文件路径
  157. */
  158. loadUrl(url: string) {
  159. let that = this;
  160. return new Promise((relove, reject) => {
  161. Axios({
  162. method: "get",
  163. url: url,
  164. data: {},
  165. responseType: "blob"
  166. })
  167. .then((res: any) => {
  168. let blob = res.data;
  169. this.unzip(blob)
  170. .then((jsonData: any) => {
  171. that.addBaseMapItem(jsonData);
  172. relove();
  173. })
  174. .catch((error: any) => {
  175. console.log(error);
  176. });
  177. })
  178. .catch((res: any) => {
  179. console.log(res);
  180. });
  181. });
  182. } // Function loadUrl
  183. /**
  184. * 解压数据
  185. *
  186. * @param blob 文件
  187. */
  188. private unzip(blob: any): any {
  189. let reader = new FileReader();
  190. reader.readAsBinaryString(blob);
  191. let that = this;
  192. return new Promise(resolve => {
  193. reader.onload = (readerEvt: any) => {
  194. let binaryString = readerEvt.target.result;
  195. //解压数据
  196. let base64Data = btoa(binaryString);
  197. let unGzipData = pako.unzip(base64Data);
  198. that.data = unGzipData.EntityList[0].Elements;
  199. resolve(unGzipData);
  200. };
  201. });
  202. } // Function unzip
  203. /**
  204. * 获取楼层未压缩数据
  205. *
  206. * @param url 请求路径
  207. */
  208. getFloorData(url: string, data: { ModelId: string }) {
  209. let that = this;
  210. return new Promise((resolve, reject) => {
  211. Axios({
  212. method: "post",
  213. url: url,
  214. data: data
  215. })
  216. .then((res: any) => {
  217. let floordata = res.data.EntityList[0].Elements;
  218. that.addBaseMapItem(floordata);
  219. resolve(res.data);
  220. })
  221. .catch((res: any) => {
  222. console.log(res);
  223. });
  224. });
  225. } // Function getFloorData
  226. /**
  227. * 增添所有底图item;
  228. *
  229. * @param data itemList对象
  230. */
  231. private addBaseMapItem(data: FloorData) {
  232. data.Walls.map((t: Wall) => {
  233. this.addWall(t);
  234. });
  235. data.Columns.map((t: Column) => {
  236. this.addColumn(t);
  237. });
  238. data.Windows.map((t: Casement) => {
  239. this.addCasement(t);
  240. });
  241. data.VirtualWalls.map((t: VirtualWall) => {
  242. this.addVirtualWall(t);
  243. });
  244. data.Doors.map((t: Door) => {
  245. this.addDoor(t);
  246. });
  247. data.Spaces.map((t: Space) => {
  248. this.addSpace(t);
  249. });
  250. } // Function addBaseMapItem
  251. /**
  252. * 添加所有空间到scene 中
  253. *
  254. * @param space 空间list
  255. */
  256. addSpace(space: Space): void {
  257. let item = new SpaceItem(space);
  258. item.zOrder = 2;
  259. item.visible = this.isShowSpace;
  260. this.spaceList.push(item);
  261. this.addItem(item);
  262. } // Function addSpace
  263. /**
  264. * 添加所有设备到scene 中
  265. *
  266. * @param column 柱子list
  267. */
  268. addColumn(column: Column): void {
  269. let item = new ColumnItem(column);
  270. item.visible = this.isShowColumn;
  271. this.columnList.push(item);
  272. this.addItem(item);
  273. } // Function addColumn
  274. /**
  275. * 添加所有设备到scene 中
  276. *
  277. * @param wall 墙list
  278. */
  279. addWall(wall: Wall): void {
  280. let item = new WallItem(wall);
  281. item.visible = this.isShowWall;
  282. this.wallList.push(item);
  283. this.addItem(item);
  284. } // Function addWall
  285. /**
  286. * 添加所有虚拟墙到scene 中
  287. *
  288. * @param virtualWall 虚拟墙list
  289. */
  290. addVirtualWall(virtualWall: VirtualWall): void {
  291. let item = new VirtualWallItem(virtualWall);
  292. item.visible = this.isShowVirtualWall;
  293. this.virtualWallList.push(item);
  294. this.addItem(item);
  295. } // Function addVirtualWall
  296. /**
  297. * 添加所有位置标签到scene 中
  298. *
  299. * @param doors 门list
  300. */
  301. addDoor(door: Door): void {
  302. let item = new DoorItem(door);
  303. item.zOrder = 1;
  304. item.visible = this.isShowDoor;
  305. this.doorList.push(item);
  306. this.addItem(item);
  307. } // Function addDoor
  308. /**
  309. * 添加所有位置标签到scene 中
  310. *
  311. * @param windows 窗户list
  312. */
  313. addCasement(casement: Casement): void {
  314. let item = new WindowItem(casement);
  315. item.zOrder = 1;
  316. item.visible = this.isShowWindow;
  317. this.casementList.push(item);
  318. this.addItem(item);
  319. } // Function addCasement
  320. /**
  321. * 扩大数组中相应字段一定倍数
  322. *
  323. * @param arr itemList
  324. * @param k 倍数
  325. * @param name 字段key值
  326. */
  327. changeMap(arr: any, k: any, name: any) {
  328. let data = arr.map((items: any) => {
  329. if (items[name] && items[name].length) {
  330. items[name].map((children: any) => {
  331. if (Array.isArray(children)) {
  332. return children.map(res => {
  333. res.Y = res.Y * k;
  334. return res;
  335. });
  336. } else {
  337. children.Y = children.Y * k;
  338. return children;
  339. }
  340. });
  341. }
  342. });
  343. return data;
  344. } // Function changeMap
  345. } // Class FloorScene