var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); import SGraphyPolygonItem from './newItems/SGraphyPolygonItem.js'; import { SGraphyImgItem } from './newItems/SGraphyImgItem.js'; import { SGraphyScene } from "@sybotan-web/graphy"; import Axios from 'axios'; import pako from "./until/pako.js"; import tools from "./until/tool.js"; /** * @name mainScene * @time 2019-07.07; * 添加所有item的场景到scene中 */ var mainScene = /** @class */ (function (_super) { __extends(mainScene, _super); /** * @param data 绘制空间地图得所有参数 */ function mainScene(data) { var _this_1 = _super.call(this) || this; _this_1._isShowSpace = true; // 是否显示空间; _this_1._isShowWallList = true; //是否展示墙体; _this_1._isShowEquipmentList = true; //是否展示设备; _this_1._isShowVrtualWallList = true; //是否展示虚拟墙 _this_1.data = data; if (_this_1.data != null) { _this_1.addAllItemList(_this_1.data); } return _this_1; } Object.defineProperty(mainScene.prototype, "isShowSpace", { // 设置是否显示空间 get: function () { return this._isShowSpace; }, set: function (b) { this._isShowSpace = b; }, enumerable: true, configurable: true }); Object.defineProperty(mainScene.prototype, "isShowWallList", { // 设置是否显示墙 get: function () { return this._isShowWallList; }, set: function (b) { this._isShowWallList = b; }, enumerable: true, configurable: true }); Object.defineProperty(mainScene.prototype, "isShowEquipmentList", { // 设置是否显示设备 get: function () { return this._isShowEquipmentList; }, set: function (b) { this._isShowEquipmentList = b; }, enumerable: true, configurable: true }); Object.defineProperty(mainScene.prototype, "isShowVrtualWallList", { // 设置是否显示虚拟墙 get: function () { return this._isShowVrtualWallList; }, set: function (b) { this._isShowVrtualWallList = b; }, enumerable: true, configurable: true }); //获取参数 mainScene.prototype.urlGetData = function (url) { var _this_1 = this; var that = this; return new Promise(function (relove, reject) { Axios({ method: 'get', url: url, data: {}, responseType: 'blob', }).then(function (res) { var blob = res.data; _this_1.zipToJson(blob).then(function (jsonData) { that.addAllItemList(jsonData); relove(); }).catch(function (error) { console.log(error); }); // console.log(reader) }).catch(function (res) { console.log(res); }); }); }; // 压缩包变为json格式数据 mainScene.prototype.zipToJson = function (blob) { var data = null; var reader = new FileReader(); reader.readAsBinaryString(blob); var _this = this; return new Promise(function (resolve) { reader.onload = function (readerEvt) { var binaryString = readerEvt.target.result; //解压数据 var base64Data = btoa(binaryString); var unGzipData = pako.unzip(base64Data); data = unGzipData; if (data.WallList && data.WallList.length) { tools.changeMap(data.WallList, -1, "PointList"); } if (data.SpaceList && data.SpaceList.length) { tools.changeMap(data.SpaceList, -1, "Paths"); } if (data.ColumnList && data.ColumnList.length) { tools.changeMap(data.ColumnList, -1, "Path"); } if (data.VirtualWallList && data.VirtualWallList.length) { tools.changeMap(data.VirtualWallList, -1, "PointList"); } if (data.EquipmentList && data.EquipmentList.length) { tools.changeMap(data.EquipmentList, -1, "PointList"); } resolve(data); }; }); }; // 以下是绘制方法 /** * 增添所有绘制item(地图); */ mainScene.prototype.addAllItemList = function (data) { var space = data.SpaceList; // let wall: this.addSpaceList(space); //绘制空间 this.addWallList(); //绘制墙 var images = data.images; this.addImageList(images); }; /** * 添加所有空间到scene 中 * @param space 空间list */ mainScene.prototype.addSpaceList = function (space) { if (space && space.length) { for (var i = 0; i < space.length; i++) { if (space[i].Paths[1] && space[i].Paths[1].length >= 2) { this.addItem(this.constructeItem({ parent: null, space: space[i], businessType: 'space' })); } } for (var i = 0; i < space.length; i++) { if (space[i].Paths[0] && space[i].Paths[0].length >= 2 && !space[i].Paths[1]) { this.addItem(this.constructeItem({ parent: null, space: space[i], businessType: 'space' })); } } } }; // 绘制墙体 mainScene.prototype.addWallList = function () { }; // 绘制设备 mainScene.prototype.addEquipmentList = function () { }; // 绘制柱体 mainScene.prototype.addColumnListList = function () { }; // 绘制虚拟墙 mainScene.prototype.addVrtualWallList = function () { }; // 绘制图片 mainScene.prototype.addImageList = function (imageList) { var _this_1 = this; if (imageList && imageList.length) { imageList.map(function (t) { _this_1.addItem(new SGraphyImgItem(null, t.img, t.X, t.Y, t.width, t.height)); }); } }; /** * 产生item实例 */ mainScene.prototype.constructeItem = function (PolygonItemInterfaceData) { return new SGraphyPolygonItem(PolygonItemInterfaceData); }; // 鼠标交互类事件 // 点击 mainScene.prototype.click = function (_this, fn) { this.root.children.forEach(function (item) { item.connect("click", _this, fn); }); }; // 双击 mainScene.prototype.dbclick = function (_this, fn) { this.root.children.forEach(function (item) { item.connect("doubleClick", _this, fn); }); }; // 按下 mainScene.prototype.mouseDown = function (_this, fn) { this.root.children.forEach(function (item) { item.connect("mouseDown", _this, fn); }); }; //移动 mainScene.prototype.mouseMove = function (_this, fn) { this.root.children.forEach(function (item) { item.connect("mouseMove", _this, fn); }); }; // 点解结束 mainScene.prototype.mouseUp = function (_this, fn) { this.root.children.forEach(function (item) { item.connect("mouseUp", _this, fn); }); }; return mainScene; }(SGraphyScene)); export default mainScene;