mainScene.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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 SGraphyPolygonItem from './newItems/SGraphyPolygonItem.js';
  15. import { SGraphyImgItem } from './newItems/SGraphyImgItem.js';
  16. import { SGraphyScene } from "@sybotan-web/graphy";
  17. import Axios from 'axios';
  18. import pako from "./until/pako.js";
  19. import tools from "./until/tool.js";
  20. /**
  21. * @name mainScene
  22. * @time 2019-07.07;
  23. * 添加所有item的场景到scene中
  24. */
  25. var mainScene = /** @class */ (function (_super) {
  26. __extends(mainScene, _super);
  27. /**
  28. * @param data 绘制空间地图得所有参数
  29. */
  30. function mainScene(data) {
  31. var _this_1 = _super.call(this) || this;
  32. _this_1._isShowSpace = true; // 是否显示空间;
  33. _this_1._isShowWallList = true; //是否展示墙体;
  34. _this_1._isShowEquipmentList = true; //是否展示设备;
  35. _this_1._isShowVrtualWallList = true; //是否展示虚拟墙
  36. _this_1.data = data;
  37. if (_this_1.data != null) {
  38. _this_1.addAllItemList(_this_1.data);
  39. }
  40. return _this_1;
  41. }
  42. Object.defineProperty(mainScene.prototype, "isShowSpace", {
  43. // 设置是否显示空间
  44. get: function () {
  45. return this._isShowSpace;
  46. },
  47. set: function (b) {
  48. this._isShowSpace = b;
  49. },
  50. enumerable: true,
  51. configurable: true
  52. });
  53. Object.defineProperty(mainScene.prototype, "isShowWallList", {
  54. // 设置是否显示墙
  55. get: function () {
  56. return this._isShowWallList;
  57. },
  58. set: function (b) {
  59. this._isShowWallList = b;
  60. },
  61. enumerable: true,
  62. configurable: true
  63. });
  64. Object.defineProperty(mainScene.prototype, "isShowEquipmentList", {
  65. // 设置是否显示设备
  66. get: function () {
  67. return this._isShowEquipmentList;
  68. },
  69. set: function (b) {
  70. this._isShowEquipmentList = b;
  71. },
  72. enumerable: true,
  73. configurable: true
  74. });
  75. Object.defineProperty(mainScene.prototype, "isShowVrtualWallList", {
  76. // 设置是否显示虚拟墙
  77. get: function () {
  78. return this._isShowVrtualWallList;
  79. },
  80. set: function (b) {
  81. this._isShowVrtualWallList = b;
  82. },
  83. enumerable: true,
  84. configurable: true
  85. });
  86. //获取参数
  87. mainScene.prototype.urlGetData = function (url) {
  88. var _this_1 = this;
  89. var that = this;
  90. return new Promise(function (relove, reject) {
  91. Axios({
  92. method: 'get',
  93. url: url,
  94. data: {},
  95. responseType: 'blob',
  96. }).then(function (res) {
  97. var blob = res.data;
  98. _this_1.zipToJson(blob).then(function (jsonData) {
  99. that.addAllItemList(jsonData);
  100. relove();
  101. }).catch(function (error) {
  102. console.log(error);
  103. });
  104. // console.log(reader)
  105. }).catch(function (res) {
  106. console.log(res);
  107. });
  108. });
  109. };
  110. // 压缩包变为json格式数据
  111. mainScene.prototype.zipToJson = function (blob) {
  112. var data = null;
  113. var reader = new FileReader();
  114. reader.readAsBinaryString(blob);
  115. var _this = this;
  116. return new Promise(function (resolve) {
  117. reader.onload = function (readerEvt) {
  118. var binaryString = readerEvt.target.result;
  119. //解压数据
  120. var base64Data = btoa(binaryString);
  121. var unGzipData = pako.unzip(base64Data);
  122. data = unGzipData;
  123. if (data.WallList && data.WallList.length) {
  124. tools.changeMap(data.WallList, -1, "PointList");
  125. }
  126. if (data.SpaceList && data.SpaceList.length) {
  127. tools.changeMap(data.SpaceList, -1, "Paths");
  128. }
  129. if (data.ColumnList && data.ColumnList.length) {
  130. tools.changeMap(data.ColumnList, -1, "Path");
  131. }
  132. if (data.VirtualWallList && data.VirtualWallList.length) {
  133. tools.changeMap(data.VirtualWallList, -1, "PointList");
  134. }
  135. if (data.EquipmentList && data.EquipmentList.length) {
  136. tools.changeMap(data.EquipmentList, -1, "PointList");
  137. }
  138. resolve(data);
  139. };
  140. });
  141. };
  142. // 以下是绘制方法
  143. /**
  144. * 增添所有绘制item(地图);
  145. */
  146. mainScene.prototype.addAllItemList = function (data) {
  147. var space = data.SpaceList;
  148. // let wall:
  149. this.addSpaceList(space); //绘制空间
  150. this.addWallList(); //绘制墙
  151. var images = data.images;
  152. this.addImageList(images);
  153. };
  154. /**
  155. * 添加所有空间到scene 中
  156. * @param space 空间list
  157. */
  158. mainScene.prototype.addSpaceList = function (space) {
  159. if (space && space.length) {
  160. for (var i = 0; i < space.length; i++) {
  161. if (space[i].Paths[1] && space[i].Paths[1].length >= 2) {
  162. this.addItem(this.constructeItem({
  163. parent: null,
  164. space: space[i],
  165. businessType: 'space'
  166. }));
  167. }
  168. }
  169. for (var i = 0; i < space.length; i++) {
  170. if (space[i].Paths[0] && space[i].Paths[0].length >= 2 && !space[i].Paths[1]) {
  171. this.addItem(this.constructeItem({
  172. parent: null,
  173. space: space[i],
  174. businessType: 'space'
  175. }));
  176. }
  177. }
  178. }
  179. };
  180. // 绘制墙体
  181. mainScene.prototype.addWallList = function () {
  182. };
  183. // 绘制设备
  184. mainScene.prototype.addEquipmentList = function () {
  185. };
  186. // 绘制柱体
  187. mainScene.prototype.addColumnListList = function () {
  188. };
  189. // 绘制虚拟墙
  190. mainScene.prototype.addVrtualWallList = function () {
  191. };
  192. // 绘制图片
  193. mainScene.prototype.addImageList = function (imageList) {
  194. var _this_1 = this;
  195. if (imageList && imageList.length) {
  196. imageList.map(function (t) {
  197. _this_1.addItem(new SGraphyImgItem(null, t.img, t.X, t.Y, t.width, t.height));
  198. });
  199. }
  200. };
  201. /**
  202. * 产生item实例
  203. */
  204. mainScene.prototype.constructeItem = function (PolygonItemInterfaceData) {
  205. return new SGraphyPolygonItem(PolygonItemInterfaceData);
  206. };
  207. // 鼠标交互类事件
  208. // 点击
  209. mainScene.prototype.click = function (_this, fn) {
  210. this.root.children.forEach(function (item) {
  211. item.connect("click", _this, fn);
  212. });
  213. };
  214. // 双击
  215. mainScene.prototype.dbclick = function (_this, fn) {
  216. this.root.children.forEach(function (item) {
  217. item.connect("doubleClick", _this, fn);
  218. });
  219. };
  220. // 按下
  221. mainScene.prototype.mouseDown = function (_this, fn) {
  222. this.root.children.forEach(function (item) {
  223. item.connect("mouseDown", _this, fn);
  224. });
  225. };
  226. //移动
  227. mainScene.prototype.mouseMove = function (_this, fn) {
  228. this.root.children.forEach(function (item) {
  229. item.connect("mouseMove", _this, fn);
  230. });
  231. };
  232. // 点解结束
  233. mainScene.prototype.mouseUp = function (_this, fn) {
  234. this.root.children.forEach(function (item) {
  235. item.connect("mouseUp", _this, fn);
  236. });
  237. };
  238. return mainScene;
  239. }(SGraphyScene));
  240. export default mainScene;