import { Injectable } from '@angular/core'; import {ReplaySubject} from 'rxjs'; import { Observable } from 'rxjs'; import { GameMode } from './working-area/model/gameMode'; @Injectable({ providedIn: 'root' }) export class CanvasShareDataService { constructor() { } private _sendMessage: ReplaySubject = new ReplaySubject(1); GameMode: any; isChange = false; // 数据 是否改动 selectTemplateData: any; // 选择当前 模板数据 // 总平面图/建筑 楼层 selectStorey: any = {area: '', details: ''}; // 选择当前 楼层 数据 originalcompanyBuildingData: any; // 单位/建筑 数据 originaleveryStoreyData: any; // 总平面图/楼层/区域 楼层数据 // 总平面图/建筑 楼层 // 处置 节点 allDisposalNode: any = []; // 所有 处置节点 allNodeMarkers: any; // 灾情 标签信息 selectPanelPoint: DisposalNodeData = new DisposalNodeData(); selectPanelPointBaseData: any = {description: '', notes: '', weather: '', airTemperature: '', windDirection: '', windScale: ''}; // 当前 数据节点 所对应的 天气,详情 数据节点 // 处置 节点 /** * 游戏模式 */ gameMode: GameMode = GameMode.Assignment; facilityAssetsName = new Map([ [ '消防水池', '消防水池'], [ '疏散楼梯', '疏散楼梯'], [ '消防电梯', '消防电梯'], [ '避难区域', '避难区域'], [ '安全出口', '安全出口'], [ '地上消火栓', '室外消火栓' ], [ '地下消火栓', '室外消火栓' ], [ '室内消火栓', '室内消火栓' ], [ '供水管网', '供水管网'], [ '湿式自动喷淋系统', '湿式自动喷淋系统'], [ '水幕系统', '水幕系统' ], [ '消防泵房', '消防泵房'], [ '水泵接合器(地上)', '水泵接合器'], [ '水泵接合器(地下)', '水泵接合器'], [ '水泵接合器(墙壁)', '水泵接合器'], [ '消防水泵房', '消防水泵房'], [ '箱式消火栓', '箱式消火栓'], [ '固定水炮', '消防水炮' ], [ '消防水罐', '储水罐'], [ '消防水罐2', '储水罐'], [ '卧式水罐', '储水罐'], [ '消防泵', '水泵' ], [ '泡沫泵', '水泵' ], [ '泡沫泵房', '泡沫站'], [ '泡沫栓', '泡沫栓' ], [ '泡沫枪', '泡沫枪'], [ '泡沫发生器', '泡沫发生器' ], [ '消防管网', '消防管网'], [ 'DCS控制室', 'DCS控制室'] ]); /** * 向其他组件发送信息 * * @param message 需要发送的信息 * @returns {Observavle} */ public sendMessage(message: any) { this._sendMessage.next(message); } public getMessage(): Observable { return this._sendMessage.asObservable(); } // 处置节点 筛选出 匹配数据 匹配不到 return undefined findDisposalNode(parentId: string= null, name: string= null) { if (parentId && name) { // 匹配 父id, name const returnData = this.allDisposalNode.find(item => item.parentId === parentId && item.name === name); return returnData; } else { // 匹配 id const returnData = this.allDisposalNode.find(item => item.id === parentId); return returnData; } } /** * 获取单位毗邻信息 */ public getCompanyAdjoinInfo(): CompanyAdjoinInfo[] { const list: CompanyAdjoinInfo[] = []; Object.keys(this.originalcompanyBuildingData.data).forEach((key) => { const item = this.originalcompanyBuildingData.data[key]; if (item.Name === '毗邻') { const adjoin = new CompanyAdjoinInfo(); adjoin.AssetId = item.Id; adjoin.Id = ''; adjoin.ImageUrls = []; adjoin.CompanyId = sessionStorage.getItem('companyId'); item.PropertyInfos.forEach(element => { if (element.PropertyName === '方向') { adjoin.Direction = Number(element.PropertyValue); } else if (element.PropertyName === '名称/编号') { adjoin.Name = element.PropertyValue; } else if (element.PropertyType === PropertyType.Image) { adjoin.ImageUrls.push(element.PropertyValue); } }); list.push(adjoin); } }); return list; } /** * 获取建筑毗邻信息 */ public getBuildingAdjoinInfo(): BuildingAdjoinInfo[] { const list: BuildingAdjoinInfo[] = []; Object.keys(this.originalcompanyBuildingData.data).forEach((key) => { const item = this.originalcompanyBuildingData.data[key]; if (item.Name === '毗邻') { const adjoin = new BuildingAdjoinInfo(); adjoin.AssetId = item.Id; adjoin.Id = ''; adjoin.BuildingId = this.selectStorey.buildingId; adjoin.ImageUrls = []; item.PropertyInfos.forEach(element => { if (element.PropertyName === '方向') { adjoin.Direction = Number(element.PropertyValue); } else if (element.PropertyName === '名称/编号') { adjoin.Name = element.PropertyValue; } else if (element.PropertyType === PropertyType.Image) { adjoin.ImageUrls.push(element.PropertyValue); } }); list.push(adjoin); } }); return list; } /** * 获取单位重点部位 */ public getCompanyImportantLocations(): CompanyImportantLocationInfo[] { const list: CompanyImportantLocationInfo[] = []; Object.keys(this.originalcompanyBuildingData.data).forEach((key) => { const item = this.originalcompanyBuildingData.data[key]; if (item.Name === '重点部位') { const important = new CompanyImportantLocationInfo(); important.AssetId = item.Id; important.Id = ''; important.ImageUrls = []; important.CompanyId = sessionStorage.getItem('companyId'); item.PropertyInfos.forEach(element => { if (element.PropertyName === '名称/编号') { important.Name = element.PropertyValue; } else if (element.PropertyType === PropertyType.Image) { important.ImageUrls.push(element.PropertyValue); } else if (element.PropertyName === '主要危险性') { important.Hazards = element.PropertyValue; } else if (element.PropertyName === '使用性质') { important.Nature = element.PropertyValue; } else if (element.PropertyName === '所在位置') { important.Position = element.PropertyValue; } else if (element.PropertyName === '建筑结构') { important.Structure = element.PropertyValue; } }); list.push(important); } }); return list; } /** * 获取建筑重点部位 */ public getBuildingImportantLocations(): BuildingImportantLocationInfo[] { const list: BuildingImportantLocationInfo[] = []; Object.keys(this.originalcompanyBuildingData.data).forEach((key) => { const item = this.originalcompanyBuildingData.data[key]; if (item.Name === '重点部位') { const important = new BuildingImportantLocationInfo(); important.AssetId = item.Id; important.Id = ''; important.ImageUrls = []; important.BuildingId = this.selectStorey.buildingId; item.PropertyInfos.forEach(element => { if (element.PropertyName === '名称/编号') { important.Name = element.PropertyValue; } else if (element.PropertyType === PropertyType.Image) { important.ImageUrls.push(element.PropertyValue); } else if (element.PropertyName === '主要危险性') { important.Hazards = element.PropertyValue; } else if (element.PropertyName === '使用性质') { important.Nature = element.PropertyValue; } else if (element.PropertyName === '所在位置') { important.Position = element.PropertyValue; } else if (element.PropertyName === '建筑结构') { important.Structure = element.PropertyValue; } }); list.push(important); } }); return list; } /** * 获取单位消防设施 */ public getAllCompanyFacilityAssetInfo(): CompanyFacilityAssetInfo[] { const list: CompanyFacilityAssetInfo[] = []; Object.keys(this.originalcompanyBuildingData.data).forEach((key) => { const item = this.originalcompanyBuildingData.data[key]; if (this.facilityAssetsName.has(item.Name)) { const facility = new CompanyFacilityAssetInfo(); facility.CompanyId = sessionStorage.getItem('companyId'); facility.AssetId = item.Id; facility.Id = ''; facility.Name = this.facilityAssetsName.get(item.Name); facility.AssetName = item.Name; facility.PropertyInfos = item.PropertyInfos; facility.SitePlanId = item.FloorId; list.push(facility); } }); return list; } /** * 获取建筑消防设施 */ public getAllBuildingFacilityAssetInfo(): BuildingFacilityAssetInfo[] { const list: BuildingFacilityAssetInfo[] = []; Object.keys(this.originalcompanyBuildingData.data).forEach((key) => { const item = this.originalcompanyBuildingData.data[key]; if (this.facilityAssetsName.has(item.Name)) { const facility = new BuildingFacilityAssetInfo(); facility.BuildingId = this.selectStorey.buildingId; facility.AssetId = item.Id; facility.Id = ''; facility.Name = this.facilityAssetsName.get(item.Name); facility.AssetName = item.Name; facility.PropertyInfos = item.PropertyInfos; facility.BuildingAreaId = item.FloorId; list.push(facility); } }); return list; } /** * 反序列化对象 * @param json 字符串 */ public deserialize(json: any): T { const obj: T = JSON.parse( json, (_, val) => { if (val === null) { return null; } if (Array.isArray(val) || typeof val !== 'object') { return val; } return Object.entries(val).reduce((a, [key, val]) => { const count = key.length; if (count > 1) { a[key[0].toUpperCase() + key.substring(1, count)] = val; } else { a[key] = val; } return a; }, {}); } ); return obj; } } /** * 单位毗邻 */ export class CompanyAdjoinInfo { public CompanyId: string; public Id: string; public Name: string; public Direction: number; public ImageUrls: string[] = []; public AssetId: string; } /** * 建筑毗邻 */ export class BuildingAdjoinInfo { public BuildingId: string; public Id: string; public Name: string; public Direction: number; public ImageUrls: string[]; public AssetId: string; } /** * 建筑重点部位 */ export class BuildingImportantLocationInfo { public BuildingId: string; public Id: string; public Name: string; public Position: string; public Structure: string; public Nature: string; public Hazards: string; public ImageUrls: string[]; public AssetId: string; } /** * 单位重点部位 */ export class CompanyImportantLocationInfo { public CompanyId: string; public Id: string; public Name: string; public Position: string; public Structure: string; public Nature: string; public Hazards: string; public ImageUrls: string[]; public AssetId: string; } /** * 单位消防素材信息 */ export class CompanyFacilityAssetInfo { public Id: string; public Name: string; public AssetName: string; public PropertyInfos: string; public AssetId: string; public CompanyId: string; public SitePlanId: string; } /** * 建筑消防素材信息 */ export class BuildingFacilityAssetInfo { public Id: string; public Name: string; public AssetName: string; public PropertyInfos: string; public AssetId: string; public BuildingId: string; public BuildingAreaId: string; } /** * 属性 */ export class PropertyInfo { // 标记位 public Tag: string; // 属性书序 public Order: number; // 是否启用 public Enabled: boolean; // 是否可见 public Visible: boolean; // 必填 public Required: boolean; // 验证规则名称 public RuleName: string; // 验证规则值 public RuleValue: string; // 物理单位 public PhysicalUnit: string; // 属性名称 public PropertyName: string; // 属性类型 public PropertyType: PropertyType; // 属性值 public PropertyValue: string; } /** * 属性类型。 */ export enum PropertyType { // 单行文本。 SingleText, // 多行文本。 MultipleText, // 数值。 Numeric, // 图片。 Image, // 图片数值,专用于描述图片数量。 ImageNumeric, // 方向 Direction, // 布尔类型。 Boolean, // 供给区域 SupplyArea, // 供给类型 SupplyType } /** * 处置节点 */ export class DisposalNode { /** * 编号 */ public Id: string; /** * 名称 */ public Name: string; /** * 等级 */ public Level: number; /** * 排序 */ public Order: number; /** * 详情 */ public Description: string; /** * 注意事项 */ public Notes: string; /** * 天气 */ public Weather: string; /** * 气温 */ public AirTemperature?: number; /** * 风向 */ public WindDirection: Direction; /** * 风力等级 */ public WindScale: WindScale; /** * 图片名称 */ public ImageNames: string[]; /** * 图片地址 */ public ImageUrls: string[]; /** * 父节点编号 */ public ParentId: string; /** * 灾情编号 */ public DisasterId: string; /** * 预案组件编号 */ public PlanComponentId: string; /** * 单位编号 */ public CompanyId: string; /** * 总平面图编号 */ public SitePlanId: string; /** * 建筑编号 */ public BuildingId: string; /** * 建筑区域编号 */ public BuildingAreaId: string; } /** * 方向。 */ export enum Direction { /** * 东 */ East, /** * 西 */ West, /** * 南 */ South, /** * 北 */ North, /** * 东南 */ Southeast, /** * 西南 */ Southwest, /** * 东北 */ Northeast, /** * 西北 */ Northwest } /** * 风力等级 */ export enum WindScale { WS0, WS1, WS2, WS3, WS4, WS5, WS6, WS7, WS8, WS9, WS10, WS11, WS12, WS13, WS14, WS15, WS16, WS17, WS18 } /** * 处置节点数据 */ export class DisposalNodeData { /** * 编号 */ public Id: string; /** * 数据 */ public Data: any; /** * 版本号 */ public Version: string; /** * 处置节点编号 */ public DisposalNodeId: string; /** * 预案组件编号 */ public PlanComponentId: string; } /** * 楼层节点数据 */ export class FloorNodeData { /** * 存量 */ public Stock: Map = new Map(); /** * 增量 */ public Increment: Map = new Map(); /** * 用户定义的增量。 */ public DefinedIncrement: Map = new Map(); } /** * 素材数据 */ export class AssetData { /// /// 模板编号 /// public TemplateId: string; /// /// 编号 /// public Id: string; /// /// 名称 /// public Name: string; /// /// 角度 /// public Angle: number; /// /// 颜色 /// public Color: string; /// /// 坐标 /// public Point: PIXI.Point; /// /// 宽度 /// public Width: number; /// /// 高度 /// public Height: number; /// /// 是否启用 /// public Enabled: boolean; /// /// 填充方式 /// public FillMode: FillMode; /// /// 图片地址 /// public ImageUrl: string; /// /// 是否固定大小 /// public FixedSize: boolean; /// /// 点路径 /// public MultiPoint: PIXI.Point[]; /// /// 建筑ID /// public BuildingId: string; /// /// 单位ID /// public CompanyId: string; /// /// 楼层编号 /// public FloorId: string; /// /// 楼层名称 /// public FloorName: string; /// /// 消防要素编号 /// public FireElementId: string; /// /// 属性列表 /// public PropertyInfos: PropertyInfo[]; /// /// 交互方式 /// public InteractiveMode: InteractiveMode; /// /// 是否来自建筑 /// public IsFromBuilding: boolean; /// /// 渲染方式。 /// public DrawMode: ImageType; /// /// 9宫格边框数值。 /// public Border: Border; /// /// 厚度。 /// public Thickness: number; /// /// 素材类型 /// public GameMode: GameMode; } /** * 填充模式 */ export enum FillMode { Color, Image } /** * 交互方式 */ export enum InteractiveMode { /** * 单点。 */ Single, /** * 多点不闭合。 */ Multiple, /** * 多点闭合。 */ MultipleClosed } /** * 图片显示类型 */ export enum ImageType { Simple = 0, Sliced = 1, Tiled = 2, Filled = 3 } /** * 边框 */ export class Border { public x: number; public y: number; public z: number; public w: number; }