/* * ******************************************************************************************************************** * * :*$@@%$*: ;: ;; ;; * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@ * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$ * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$= * =@* %! @ $= % %@= =%@! %= * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =% * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%* * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$ * $@* ;@@@%=!: *@* * =@$ ;;;!=%@@@@=! =@! * %@$: =@%: :*@@@* %@= Copyright (c) 2016-2019. 北京上格云技术有限公司 * ;%@@$=$@@%* *@@@$=%@@%; * ::;:: ::;:: All rights reserved. * * ******************************************************************************************************************** */ import { SGraphyScene } from "@saga-web/graphy/lib"; // @ts-ignore import pako from "pako"; import { FloorData } from "./types/FloorData"; import { Space } from "./types/Space"; import { Column } from "./types/Column"; import { Wall } from "./types/Wall"; import { VirtualWall } from "./types/VirtualWall"; import { Door } from "./types/Door"; import { Casement } from "./types/Casement"; import Axios from "axios"; import { SpaceItem } from "./items/SpaceItem"; import { WallItem } from "./items/WallItem"; import { ColumnItem } from "./items/ColumnItem"; import { VirtualWallItem } from "./items/VirtualWallItem"; import { DoorItem } from "./items/DoorItem"; import { WindowItem } from "./items/WindowItem"; /** * 楼层场景 * * @author 郝建龙 */ export class FloorScene extends SGraphyScene { /** item数据 */ data: FloorData | null = null; /** json数据 */ json: string | null = null; /** 是否显示空间 */ private _isShowSpace: boolean = true; get isShowSpace(): boolean { return this._isShowSpace; } // Get isShowSpace set isShowSpace(v: boolean) { if (this._isShowSpace === v) { return; } this._isShowSpace = v; this.spaceList.map((t: SpaceItem) => { t.visible = this._isShowSpace; return t; }); } // Set isShowSpace /** 是否显示柱子 */ private _isShowColumn: boolean = true; get isShowColumn(): boolean { return this._isShowColumn; } // Get isShowColumn set isShowColumn(v: boolean) { if (this._isShowColumn === v) { return; } this._isShowColumn = v; this.columnList.map((t: ColumnItem) => { t.visible = this._isShowColumn; return t; }); } // Set isShowColumn /** 是否展示墙体 */ private _isShowWall: boolean = true; get isShowWall(): boolean { return this._isShowWall; } // Get isShowWall set isShowWall(v: boolean) { if (this._isShowWall === v) { return; } this._isShowWall = v; this.wallList.map((t: WallItem) => { t.visible = this._isShowWall; return t; }); } // Set isShowWall /** 是否展示虚拟墙 */ _isShowVirtualWall: boolean = true; get isShowVirtualWall(): boolean { return this._isShowVirtualWall; } // Get isShowVrtualWall set isShowVirtualWall(v: boolean) { if (this._isShowVirtualWall === v) { return; } this._isShowVirtualWall = v; this.virtualWallList.map((t: VirtualWallItem) => { t.visible = this._isShowVirtualWall; return t; }); } // Set isShowVrtualWall /** 是否展示门 */ _isShowDoor: boolean = true; get isShowDoor(): boolean { return this._isShowDoor; } // Get isShowDoor set isShowDoor(v: boolean) { if (this._isShowDoor === v) { return; } this._isShowDoor = v; this.doorList.map((t: DoorItem) => { t.visible = this._isShowDoor; return t; }); } // Set isShowDoor /** 是否展示窗户 */ _isShowWindow: boolean = true; get isShowWindow(): boolean { return this._isShowWindow; } // Get isShowWindow set isShowWindow(v: boolean) { if (this._isShowWindow === v) { return; } this._isShowWindow = v; this.casementList.map((t: WindowItem) => { t.visible = this._isShowWindow; return t; }); } // Set isShowWindow /** 空间是否可选 */ _isSpaceSelectable: boolean = true; get isSpaceSelectable(): boolean { return this._isSpaceSelectable; } // Get isSpaceSelectable set isSpaceSelectable(v: boolean) { if (this._isSpaceSelectable === v) { return; } this._isSpaceSelectable = v; this.spaceList.map((t: SpaceItem) => { t.selectable = this._isSpaceSelectable; return t; }); } // Set isSpaceSelectable /** 墙list */ wallList: WallItem[] = []; /** 柱子list */ columnList: ColumnItem[] = []; /** 门list */ doorList: DoorItem[] = []; /** 窗list */ casementList: WindowItem[] = []; /** 虚拟墙list */ virtualWallList: VirtualWallItem[] = []; /** 空间list */ spaceList: SpaceItem[] = []; /** * @param data 绘制空间地图得所有参数 */ constructor() { super(); } // Constructor() /** * 获取底图压缩文件 * * @param url 请求数据文件路径 */ loadUrl(url: string) { let that = this; return new Promise((relove, reject) => { Axios({ method: "get", url: url, data: {}, responseType: "blob" }) .then((res: any) => { let blob = res.data; this.unzip(blob) .then((jsonData: any) => { that.addBaseMapItem(jsonData); relove(jsonData); }) .catch((error: any) => { console.log(error); }); }) .catch((res: any) => { console.log(res); }); }); } // Function loadUrl /** * 解压数据 * * @param blob 文件 */ private unzip(blob: any): any { let reader = new FileReader(); reader.readAsBinaryString(blob); let that = this; return new Promise(resolve => { reader.onload = (readerEvt: any) => { let binaryString = readerEvt.target.result; //解压数据 let base64Data = btoa(binaryString); let unGzipData = that.unzipBase64(base64Data); try { that.data = unGzipData.entityList ? unGzipData.entityList[0].Elements : unGzipData.EntityList[0].Elements; this.json = JSON.stringify(unGzipData); resolve(that.data); } catch (e) { console.log(e); console.log(unGzipData); resolve("error"); } }; }); } // Function unzip /** * 获取楼层未压缩数据 * * @param url 请求路径 */ getFloorData(url: string, data: { ModelId: string }) { let that = this; return new Promise((resolve, reject) => { Axios({ method: "post", url: url, data: data }) .then((res: any) => { if (res.data.Result == "success") { this.json = JSON.stringify(res); let floordata = res.data.EntityList[0].Elements; that.data = floordata; that.addBaseMapItem(floordata); } resolve(res.data); }) .catch((err: any) => { console.log(err); }); }); } // Function getFloorData /** * 增添所有底图item; * * @param data itemList对象 */ private addBaseMapItem(data: FloorData) { if (data.Walls) { data.Walls.map((t: Wall) => { this.addWall(t); }); } if (data.Columns) { data.Columns.map((t: Column) => { this.addColumn(t); }); } if (data.Windows) { data.Windows.map((t: Casement) => { this.addCasement(t); }); } if (data.VirtualWalls) { data.VirtualWalls.map((t: VirtualWall) => { this.addVirtualWall(t); }); } if (data.Doors) { data.Doors.map((t: Door) => { this.addDoor(t); }); } if (data.Spaces) { data.Spaces.map((t: Space) => { this.addSpace(t); }); } } // Function addBaseMapItem /** * 添加空间到scene 中 * * @param space 空间item */ addSpace(space: Space): void { let item = new SpaceItem(null, space); item.visible = this.isShowSpace; item.selectable = this.isSpaceSelectable; this.spaceList.push(item); this.addItem(item); } // Function addSpace /** * 添加柱子到scene 中 * * @param column 柱子item */ addColumn(column: Column): void { let item = new ColumnItem(null, column); item.visible = this.isShowColumn; this.columnList.push(item); this.addItem(item); } // Function addColumn /** * 添加墙到scene 中 * * @param wall 墙item */ addWall(wall: Wall): void { let item = new WallItem(null, wall); item.visible = this.isShowWall; this.wallList.push(item); this.addItem(item); } // Function addWall /** * 添加所有虚拟墙到scene中 * * @param virtualWall 虚拟墙item */ addVirtualWall(virtualWall: VirtualWall): void { let item = new VirtualWallItem(null, virtualWall); item.visible = this.isShowVirtualWall; this.virtualWallList.push(item); this.addItem(item); } // Function addVirtualWall /** * 添加门到scene 中 * * @param doors 门item */ addDoor(door: Door): void { let item = new DoorItem(null, door); item.visible = this.isShowDoor; this.doorList.push(item); this.addItem(item); } // Function addDoor /** * 添加窗户到scene 中 * * @param windows 窗户item */ addCasement(casement: Casement): void { let item = new WindowItem(null, casement); item.visible = this.isShowWindow; this.casementList.push(item); this.addItem(item); } // Function addCasement /** * 解压文件 * * @param b64Data base64数据 */ private unzipBase64(b64Data: any) { let strData = atob(b64Data); let charData = strData.split("").map(function(x) { return x.charCodeAt(0); }); let binData = new Uint8Array(charData); let data = pako.inflate(binData, { to: "string" }); return eval("(" + data + ")"); } // Function unzipBase64 /** * 压缩文件 * * @param str 被压缩的数据 */ private zip(str: any) { //escape(str) --->压缩前编码,防止中午乱码 let binaryString = pako.gzip(escape(str), { to: "string" }); return binaryString; } // Function zip /** * 获取选中空间的列表 * * @return 被选中的空间列表 */ getSelectedSpaces(): SpaceItem[] { let arr: SpaceItem[] = []; this.spaceList.map(sp => { if (sp.selected) { arr.push(sp); } }); return arr; } // Function getSelectedSpaces /** * 清除选中的空间 * */ clearSelectedSpaces(): void { this.spaceList.map(sp => { sp.selected = false; return sp; }); } // Function clearSelectedSpaces } // Class FloorScene