/* * ********************************************************************************************************************* * * !! * .F88X * X8888Y * .}888888N; * i888888N; .:! .I$WI: * R888888I .'N88~ i8}+8Y&8"l8i$8>8W~'>W8}8]KW+8IIN"8& * .R888888I .;N8888~ .X8' "8I.!,/8" !%NY8`"8I8~~8>,88I * +888888N; .8888888Y "&&8Y.}8, * ./888888N; .R888888Y .'}~ .>}'.`+> i}! "i' +/' .'i~ !11,.:">, .~]! .i}i * ~888888%: .I888888l .]88~`1/iY88Ii+1'.R$8$8]"888888888> Y8$ W8E X8E W8888'188Il}Y88$* * 18888888 E8888881 .]W%8$`R8X'&8%++N8i,8N%N8+l8%` .}8N:.R$RE%N88N%N$K$R 188,FE$8%~Y88I * .E888888I .i8888888' .:$8I;88+`E8R:/8N,.>881.`$8E/1/]N8X.Y8N`"KF&&FK!'88*."88K./$88%RN888+~ * 8888888I .,N888888~ ~88i"8W,!N8*.I88.}888%F,i$88"F88" 888:E8X.>88!i88>`888*.}Fl1]*}1YKi' * i888888N' I888Y ]88;/EX*IFKFK88X K8R .l8W 88Y ~88}'88E&%8W.X8N``]88!.$8K .:W8I * .i888888N; I8Y .&8$ .X88! i881.:%888>I88 ;88] +88+.';;;;:.Y88X 18N.,88l .+88/ * .:R888888I * .&888888I Copyright (c) 2009-2020. 博锐尚格科技股份有限公司 * ~8888' * .!88~ All rights reserved. * * ********************************************************************************************************************* */ import { SItemFactory, SParser } from "@persagy-web/big/lib"; // @ts-ignore import fengmap from "fengmap"; import { Space } from "@persagy-web/big/lib/types/floor/Space"; import { Column } from "@persagy-web/big/lib/types/floor/Column"; import { VirtualWall } from "@persagy-web/big/lib/types/floor/VirtualWall"; import { Wall } from "@persagy-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 = "1000423_"; /** 蜂鸟 map 绑定 dom 的 id */ domId: string = ""; /** 蜂鸟:底图应用秘钥 */ key: string = ""; /** 底图服务器地址 */ serverUrl: string = "./data/"; /** 底图主题 */ mapThemeURL: string = "./"; /** 蜂鸟图 */ private 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, 300004, 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]; /** poi 类型 */ poiList: number[] = [ 170006, 170008, 170007, 170003, 170001, 100001, 100004, 100005, 100007, 140002, 170002, 150010, 100003, 140004, 170005, 120001, 120008, 120009, 120010 ]; /** 当前地图的楼层 list(gname to gid映射关系) */ gnameToGid = {}; /** 当前地图的楼层 list */ floorList = []; /** 当前底图的主题数据 */ mapTheme: any; /** 底图版本号 */ version: number | null = null; /** 顶楼地址 img */ frImg: string = ""; /** 构造体 */ constructor( domId: string, mapServerURL: string, key: string, appName: string, factory: SItemFactory, mapThemeURL: string ) { super(factory); this.domId = domId; this.key = key; this.serverUrl = mapServerURL; this.mapThemeURL = mapThemeURL; this.appName = appName; } // 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(); const minx = this.fmap.minX; const maxy = this.fmap.maxY; searchReq.groupID = groupId; searchReq.type = "Model"; searchAnalyser.query(searchReq, (result: any) => { let spaces: Space[] = [], columns: Column[] = [], walls: Wall[] = [], virtualWall: VirtualWall[] = [], pList: any[] = []; result.forEach((t: any) => { if (t.target) { let type = t.typeID; if (t.target._data && t.target._data.vertices) { let arr = t.target._data.vertices, outline = []; for (let i = 0; i < arr.length - 1; i += 2) { outline.push({ X: arr[i] - minx, Y: arr[i + 1] - maxy }); } 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, Height: t.target.height }); } else if (this.columnType.indexOf(type) > -1) { // @ts-ignore columns.push({ OutLine: [outline] }); } else if (this.wallType.indexOf(type) > -1) { const hasHole = t.target._data.holes && t.target._data.holes.length; let holes = []; if (hasHole) { let tempArr = t.target._data.holes; for (let j = 0; j < tempArr.length; j++) { let holeChild = []; for ( let i = 0; i < tempArr[j].length - 1; i += 2 ) { holeChild.push({ X: tempArr[j][i] - minx, Y: tempArr[j][i + 1] - maxy }); } holes.push(holeChild); } } // @ts-ignore walls.push({ OutLine: [outline], HasHole: hasHole, Holes: holes }); } else if (this.virtualWallType.indexOf(type) > -1) { // @ts-ignore virtualWall.push({ OutLine: [outline] }); } } if (this.poiList.indexOf(type) > -1) { pList.push({ Name: t.target.name, Pos: { X: t.mapCoord.x - minx, Y: t.mapCoord.y - maxy }, Type: t.typeID, // @ts-ignore Tag: SFengParser.typeIdMap[t.typeID], Height: t.target.height, SourceId: t.ID }); } } }); obj = { Spaces: spaces, Columns: columns, Walls: walls, VirtualWalls: virtualWall, PList: pList }; _fn(obj); }); } // Function parseData() /** * 加载底图 * * @param mapId 蜂鸟地图 id * @param _fn load 成功回调 */ loadMap(mapId: string, _fn: Function): void { this.fmap = new fengmap.FMMap({ container: document.getElementById(this.domId), mapServerURL: this.serverUrl, appName: this.appName, key: this.key, mapThemeURL: this.mapThemeURL, defaultThemeName: mapId }); this.fmap.openMapById(mapId, (err: any): void => { console.log("错误信息", err); }); this.fmap.on("loadComplete", (): void => { if (this.mapId != mapId) { this.mapId = mapId; this.gnameToGid = {}; this.floorList = []; // @ts-ignore this.fmap.listGroups.forEach(t => { // @ts-ignore this.gnameToGid[t.gname] = t.gid; // @ts-ignore this.floorList.push(t); }); } _fn(this.gnameToGid, this.floorList); }); } // 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 groupId * @param _fn */ loadFloor(groupId: string, _fn: Function): any { const minx = this.fmap.minX; const maxy = this.fmap.maxY; this.fmap.getDatasByAlias(Number(groupId), "extent", (res: any) => { let index = res.gdata.geo.indexOf("("); let str = res.gdata.geo.substring(index); str = str.replace(/\(/g, "["); str = str.replace(/\)/g, "]"); str = str.replace(/\s/g, ","); const arr = JSON.parse(str); const aaa = []; for (let i = 0; i < arr.length; i++) { let a = arr[i]; const bbb = []; for (let j = 0; j < a.length; j++) { let b = a[j]; const ccc = []; for (let k = 0; k < b.length - 1; k += 2) { ccc.push({ X: b[k] - minx, Y: b[k + 1] - maxy }); } bbb.push(ccc); } aaa.push(bbb); } _fn({ OutLine: aaa }); }); } // Function loadFloor() /** * 计算平均值 * * @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 }; } }