123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457 |
- /*
- * ********************************************************************************************************************
- *
- * :*$@@%$*: ;: ;; ;;
- * :@@%! :!@@%: %! ;%%@@%$ =@@@@@@@%; @%@@@%%%%@@@@@
- * :@%; :$= %%$$$%$$ ;$$ ;$@= !@$
- * =@! %! @ $=;% !@@@%: !$$$$$$$$$$$$$$=
- * =@* %! @ $= % %@= =%@! %=
- * *$%%! @@= ;=$%%%$*: %! @ $= % =%%%%%%@$ *%: =%
- * %@@!: !@@@%=$@@@@%! :*@@$: %! @ $= % $* ;@ @* :%*
- * ;@@! ;!!!;: ;@%: =======@%========* @ $$ % $%*****$@ :@$=*********=@$
- * $@* ;@@@%=!: *@*
- * =@$ ;;;!=%@@@@=! =@!
- * %@$: =@%: :*@@@* %@= 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;
- /** 是否显示空间 */
- 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;
- 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") {
- 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.zOrder = 2;
- 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.zOrder = 99;
- 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.zOrder = 1;
- item.visible = this.isShowWindow;
- this.casementList.push(item);
- this.addItem(item);
- } // Function addCasement
- /**
- * 扩大数组中相应字段一定倍数
- *
- * @param arr itemList
- * @param k 倍数
- * @param name 字段key值
- */
- changeMap(arr: any, k: any, name: any) {
- let data = arr.map((items: any) => {
- if (items[name] && items[name].length) {
- items[name].map((children: any) => {
- if (Array.isArray(children)) {
- return children.map(res => {
- res.Y = res.Y * k;
- return res;
- });
- } else {
- children.Y = children.Y * k;
- return children;
- }
- });
- }
- });
- return data;
- } // Function changeMap
- /**
- * 解压文件
- *
- * @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
|