import { SItemFactory, SParser } from "@saga-web/big/lib"; // @ts-ignore import fengmap from "fengmap"; import { Space } from "@saga-web/big/lib/types/floor/Space"; import { Column } from "@saga-web/big/lib/types/floor/Column"; import { VirtualWall } from "@saga-web/big/lib/types/floor/VirtualWall"; import { Wall } from "@saga-web/big/lib/types/floor/Wall"; import Axios from "axios"; /** * 蜂鸟数据解析器 * */ export class SFengParser extends SParser { /** typeId对应的类型 */ static typeIdMap = { 100000: "Pavement", 200000: "FrontagePavement", 900000: "AuxiliarySurface", 300000: "SolidWall", 300001: "GlassWall", 300003: "PartitionWall", 300002: "BearingColumn", 800000: "ParkingSpace", 200004: "StraightLadder", 200003: "Escalator", 200103: "UplinkOnly", 200203: "DownOnly", 200005: "Stairs", 200002: "Toilet", 200001: "EntranceAndExit", 200006: "Cashier", 200007: "ATM", 200017: "AlarmPoint", 200018: "DressModification", 200019: "JewelryRepair", 200020: "Checkroom", 200014: "InformationDesk", 200009: "PublicPhone", 200008: "ServiceCentre", 200010: "Exit", 200011: "CargoLift", 200012: "Lounge", 200013: "CarPark", 200015: "MotherBabyRoom", 200016: "VIP", 200021: "WheelchairAccessible", 170006: "StraightLadder", 170008: "UpEscalator", 170007: "DownEscalator", 170003: "Escalator", 170001: "Stairs", 110001: "EntranceAndExit", 100001: "Restroom", 100004: "MenRestroom", 100005: "WomenRestroom", 100007: "AccessibleToilet", 140002: "ServiceCentre", 170002: "CargoLift", 150010: "Lounge", 100003: "MotherBabyRoom", 140004: "VIP", 170005: "WheelchairAccessible", 120001: "CarPark", 120008: "ParkingExit", 120009: "ParkingEntrance", 120010: "ParkingExitAndEntrance", 300005: "SwitchingStation", 300006: "DistributionRoom", 300007: "StrongElectricWell", 300008: "WeakCurrentWell", 300009: "AirConditionerEngineRoom", 300010: "RefrigerationRoom", 300011: "FreshAirRoom", 300012: "CompressorRoom", 300013: "HeatSourceMachineRoom", 300014: "DomesticWaterPumpHouse", 300015: "HighLevelWaterTankRoom", 300016: "SewageTreatmentRoom", 300017: "FirePumpHouse", 300018: "WetAlarmValveChamber", 300019: "PreActionAlarmValveChamber", 300020: "AirSupplyRoom", 300021: "ExhaustFanRoom", 300022: "MakeUpAirRoom", 300023: "BusinessManagementOffice", 300024: "NetworkRoom", 300025: "Substation", 300026: "GeneratorRoom", 300027: "TrusteeshipRoom", 300028: "HuiyunMachineRoom", 300029: "AlarmValveChamber", 300030: "ReclaimedWaterMachineRoom", 300031: "FireControlRoom", 300032: "OilSeparator", 300033: "GasBoilerRoom", 300034: "GasMeterRoom", 300035: "ElevatorMachineRoom", 300036: "StaffRestaurant", 300037: "DryGarbageRoom", 300038: "WetGarbageRoom", 300039: "ExpansionWaterTankRoom", 200023: "MensBathroom", 200022: "WomensToilet" }; /** 蜂鸟:底图应用名称 */ appName: string = ""; /** 当前蜂鸟map的id */ mapId: string = ""; /** 蜂鸟map绑定dom的id */ domId: string = ""; /** 蜂鸟:底图应用秘钥 */ key: string = ""; /** 底图服务器地址 */ serverUrl: string = "./data/"; /** 蜂鸟图 */ private readonly fmap: fengmap.FMMap; /** 属于空间类型typeid */ spaceType: number[] = [ 100000, 200000, 900000, 800000, 200004, 200003, 200103, 200203, 200005, 200002, 200006, 200007, 200017, 200018, 200019, 200020, 200014, 200009, 200008, 200011, 200012, 200013, 200015, 200016, 200021, 170006, 170008, 170007, 170003, 170001, 100001, 100004, 100005, 100007, 140002, 170002, 150010, 100003, 140004, 170005, 120001, 300005, 300006, 300007, 300008, 300009, 300010, 300011, 300012, 300013, 300014, 300015, 300016, 300017, 300018, 300019, 300020, 300021, 300022, 300023, 300024, 300025, 300026, 300027, 300028, 300029, 300030, 300031, 300032, 300033, 300034, 300035, 300036, 300037, 300038, 300039, 200023, 200022 ]; /** 属于柱子类型的typeid */ columnType: number[] = [300002]; /** 属于墙类型的typeid */ wallType: number[] = [300000, 300001]; /** 属于虚拟墙类型的typeid */ virtualWallType: number[] = [ 200001, 110001, 200010, 120008, 120009, 120010 ]; /** 当前地图的楼层list */ gnameToGid = {}; /** 当前底图的主题数据 */ mapTheme: any; /** 底图版本号 */ version: number | null = null; /** 顶楼地址img */ frImg: string = ""; /** 构造体 */ constructor( domId: string, mapServerURL: string, key: string, appName: string, factory: SItemFactory ) { super(factory); this.domId = domId; this.key = key; this.serverUrl = mapServerURL; this.appName = appName; this.fmap = new fengmap.FMMap({ container: document.getElementById(this.domId), mapServerURL: this.serverUrl, appName: this.appName, key: this.key }); } // Constructor /** * 解析数据 * * @param groupId 当前楼层((前台传入为gname)) * @param _fn 查询成功回调函数(返回参数为FloorData) * */ parseData(groupId: string, _fn: Function): void { let obj = {}; // 切换至当前楼层才可查询 this.fmap.focusGroupID = groupId; // 创建搜索分析对象 let searchAnalyser = new fengmap.FMSearchAnalyser(this.fmap); // 创建搜索请求体对象 let searchReq = new fengmap.FMSearchRequest(); searchReq.groupID = groupId; searchReq.type = "Model"; searchAnalyser.query(searchReq, (result: any) => { let spaces: Space[] = [], columns: Column[] = [], walls: Wall[] = [], virtualWall: VirtualWall[] = []; result = result .map((t: any) => { if (t.target && t.target._data && t.target._data.vertices) { let arr = t.target._data.vertices, type = t.typeID, outline = []; for (let i = 0; i < arr.length - 1; i += 2) { outline.push({ X: arr[i] - 12982584.99, Y: arr[i + 1] - 4911901.56 }); } if (this.spaceType.indexOf(type) > -1) { spaces.push({ // @ts-ignore OutLine: [outline], Name: t.target.name, Location: { // @ts-ignore Points: [this.getAverageVal([outline])] }, Type: t.typeID, // @ts-ignore Tag: SFengParser.typeIdMap[t.typeID], SourceId: t.FID }); } else if (this.columnType.indexOf(type) > -1) { // @ts-ignore columns.push({ OutLine: [outline] }); } else if (this.wallType.indexOf(type) > -1) { // @ts-ignore walls.push({ OutLine: [outline] }); } else if (this.virtualWallType.indexOf(type) > -1) { // @ts-ignore virtualWall.push({ OutLine: [outline] }); } } }) .filter((item: any) => item); obj = { Spaces: spaces, Columns: columns, Walls: walls, VirtualWalls: virtualWall }; _fn(obj); }); } /** * 加载底图 * * @param mapId 蜂鸟地图id * @param _fn load成功回调 * */ loadMap(mapId: string, _fn: Function): void { this.fmap.openMapById(mapId, (err: any): void => { console.log("错误信息", err); }); this.fmap.on("loadComplete", (): void => { if (this.mapId != mapId) { this.mapId = mapId; this.gnameToGid = {}; // @ts-ignore this.fmap.listGroups.forEach(t => { // @ts-ignore this.gnameToGid[t.gname] = t.gid; }); } _fn(this.gnameToGid); }); } // Function loadMap() /** * 加载主题文件 * * @param url 主题文件url * @return promise promise对象 * */ loadTheme(url: string): Promise { return new Promise((resolve, reject): void => { Axios({ method: "get", url: url }) .then((res: any) => { this.mapTheme = res.data; let data = res.data.storetheme; this.frImg = data[data.length - 1].image; // @ts-ignore resolve(this.frImg); }) .catch((res: any) => { console.log(res); }); }); } // Function loadTheme() /** * 计算平均值 * * @param Outline 轮廓线束 * @return object {X:X,Y:Y}x的平均值,y的平均值 * */ private getAverageVal(Outline: { X: number; Y: number }[][]): object { let X = 0, Y = 0, len = Outline[0].length; Outline[0].map(item => { X += item.X; Y += item.Y; }); X = Number((X / len).toFixed(2)); Y = Number((Y / len).toFixed(2)); return { X: X, Y: Y }; } } // class SEquipParser