SFengParser.ts 10.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336
  1. import { SItemFactory, SParser } from "@saga-web/big/lib";
  2. // @ts-ignore
  3. import fengmap from "fengmap";
  4. import { Space } from "@saga-web/big/lib/types/floor/Space";
  5. import { Column } from "@saga-web/big/lib/types/floor/Column";
  6. import { VirtualWall } from "@saga-web/big/lib/types/floor/VirtualWall";
  7. import { Wall } from "@saga-web/big/lib/types/floor/Wall";
  8. /**
  9. * 蜂鸟数据解析器
  10. *
  11. */
  12. export class SFengParser extends SParser {
  13. /** typeId对应的类型 */
  14. static typeIdMap = {
  15. 100000: "Pavement",
  16. 200000: "FrontagePavement",
  17. 900000: "AuxiliarySurface",
  18. 300000: "SolidWall",
  19. 300001: "GlassWall",
  20. 300003: "PartitionWall",
  21. 300002: "BearingColumn",
  22. 800000: "ParkingSpace",
  23. 200004: "StraightLadder",
  24. 200003: "Escalator",
  25. 200103: "UplinkOnly",
  26. 200203: "DownOnly",
  27. 200005: "Stairs",
  28. 200002: "Toilet",
  29. 200001: "EntranceAndExit",
  30. 200006: "Cashier",
  31. 200007: "ATM",
  32. 200017: "AlarmPoint",
  33. 200018: "DressModification",
  34. 200019: "JewelryRepair",
  35. 200020: "Checkroom",
  36. 200014: "InformationDesk",
  37. 200009: "PublicPhone",
  38. 200008: "ServiceCentre",
  39. 200010: "Exit",
  40. 200011: "CargoLift",
  41. 200012: "Lounge",
  42. 200013: "CarPark",
  43. 200015: "MotherBabyRoom",
  44. 200016: "VIP",
  45. 200021: "WheelchairAccessible",
  46. 170006: "StraightLadder",
  47. 170008: "UpEscalator",
  48. 170007: "DownEscalator",
  49. 170003: "Escalator",
  50. 170001: "Stairs",
  51. 110001: "EntranceAndExit",
  52. 100001: "Restroom",
  53. 100004: "MenRestroom",
  54. 100005: "WomenRestroom",
  55. 100007: "AccessibleToilet",
  56. 140002: "ServiceCentre",
  57. 170002: "CargoLift",
  58. 150010: "Lounge",
  59. 100003: "MotherBabyRoom",
  60. 140004: "VIP",
  61. 170005: "WheelchairAccessible",
  62. 120001: "CarPark",
  63. 120008: "ParkingExit",
  64. 120009: "ParkingEntrance",
  65. 120010: "ParkingExitAndEntrance",
  66. 300005: "SwitchingStation",
  67. 300006: "DistributionRoom",
  68. 300007: "StrongElectricWell",
  69. 300008: "WeakCurrentWell",
  70. 300009: "AirConditionerEngineRoom",
  71. 300010: "RefrigerationRoom",
  72. 300011: "FreshAirRoom",
  73. 300012: "CompressorRoom",
  74. 300013: "HeatSourceMachineRoom",
  75. 300014: "DomesticWaterPumpHouse",
  76. 300015: "HighLevelWaterTankRoom",
  77. 300016: "SewageTreatmentRoom",
  78. 300017: "FirePumpHouse",
  79. 300018: "WetAlarmValveChamber",
  80. 300019: "PreActionAlarmValveChamber",
  81. 300020: "AirSupplyRoom",
  82. 300021: "ExhaustFanRoom",
  83. 300022: "MakeUpAirRoom",
  84. 300023: "BusinessManagementOffice",
  85. 300024: "NetworkRoom",
  86. 300025: "Substation",
  87. 300026: "GeneratorRoom",
  88. 300027: "TrusteeshipRoom",
  89. 300028: "HuiyunMachineRoom",
  90. 300029: "AlarmValveChamber",
  91. 300030: "ReclaimedWaterMachineRoom",
  92. 300031: "FireControlRoom",
  93. 300032: "OilSeparator",
  94. 300033: "GasBoilerRoom",
  95. 300034: "GasMeterRoom",
  96. 300035: "ElevatorMachineRoom",
  97. 300036: "StaffRestaurant",
  98. 300037: "DryGarbageRoom",
  99. 300038: "WetGarbageRoom",
  100. 300039: "ExpansionWaterTankRoom",
  101. 200023: "MensBathroom",
  102. 200022: "WomensToilet"
  103. };
  104. /** 蜂鸟:底图应用名称 */
  105. appName: string = "";
  106. /** 当前蜂鸟map的id */
  107. currentMapId: string = "";
  108. /** 蜂鸟map绑定dom的id */
  109. domId: string = "";
  110. /** 蜂鸟:底图应用秘钥 */
  111. key: string = "";
  112. /** 底图服务器地址 */
  113. serverUrl: string = "./data/";
  114. /** 蜂鸟图 */
  115. private readonly fmap: fengmap.FMMap;
  116. /** 属于空间类型typeid */
  117. spaceType: number[] = [
  118. 100000,
  119. 200000,
  120. 900000,
  121. 800000,
  122. 200004,
  123. 200003,
  124. 200103,
  125. 200203,
  126. 200005,
  127. 200002,
  128. 200006,
  129. 200007,
  130. 200017,
  131. 200018,
  132. 200019,
  133. 200020,
  134. 200014,
  135. 200009,
  136. 200008,
  137. 200011,
  138. 200012,
  139. 200013,
  140. 200015,
  141. 200016,
  142. 200021,
  143. 170006,
  144. 170008,
  145. 170007,
  146. 170003,
  147. 170001,
  148. 100001,
  149. 100004,
  150. 100005,
  151. 100007,
  152. 140002,
  153. 170002,
  154. 150010,
  155. 100003,
  156. 140004,
  157. 170005,
  158. 120001,
  159. 300005,
  160. 300006,
  161. 300007,
  162. 300008,
  163. 300009,
  164. 300010,
  165. 300011,
  166. 300012,
  167. 300013,
  168. 300014,
  169. 300015,
  170. 300016,
  171. 300017,
  172. 300018,
  173. 300019,
  174. 300020,
  175. 300021,
  176. 300022,
  177. 300023,
  178. 300024,
  179. 300025,
  180. 300026,
  181. 300027,
  182. 300028,
  183. 300029,
  184. 300030,
  185. 300031,
  186. 300032,
  187. 300033,
  188. 300034,
  189. 300035,
  190. 300036,
  191. 300037,
  192. 300038,
  193. 300039,
  194. 200023,
  195. 200022
  196. ];
  197. /** 属于柱子类型的typeid */
  198. columnType: number[] = [300002];
  199. /** 属于墙类型的typeid */
  200. wallType: number[] = [300000, 300001];
  201. /** 属于虚拟墙类型的typeid */
  202. virtualWallType: number[] = [
  203. 200001,
  204. 110001,
  205. 200010,
  206. 120008,
  207. 120009,
  208. 120010
  209. ];
  210. /** 构造体 */
  211. constructor(
  212. domId: string,
  213. mapServerURL: string,
  214. key: string,
  215. appName: string,
  216. factory: SItemFactory
  217. ) {
  218. super(factory);
  219. this.domId = domId;
  220. this.key = key;
  221. this.serverUrl = mapServerURL;
  222. this.appName = appName;
  223. this.fmap = new fengmap.FMMap({
  224. container: document.getElementById(this.domId),
  225. mapServerURL: this.serverUrl,
  226. appName: this.appName,
  227. key: this.key
  228. });
  229. } // Constructor
  230. /**
  231. * 解析数据
  232. *
  233. * @param currentMapId 当前模型id
  234. * @param groupId 当前楼层
  235. * @param _fn 查询成功回调函数(返回参数为FloorData)
  236. * */
  237. parseData(currentMapId: string, groupId: string, _fn: Function): void {
  238. this.fmap.openMapById(currentMapId, (err: any) => {
  239. console.log("错误信息", err);
  240. });
  241. this.fmap.on("loadComplete", () => {
  242. let obj = {};
  243. // 切换至当前楼层才可查询
  244. this.fmap.focusGroupID = groupId;
  245. // 创建搜索分析对象
  246. let searchAnalyser = new fengmap.FMSearchAnalyser(this.fmap);
  247. // 创建搜索请求体对象
  248. let searchReq = new fengmap.FMSearchRequest();
  249. searchReq.groupID = groupId;
  250. searchReq.type = "Model";
  251. searchAnalyser.query(searchReq, (result: any) => {
  252. let spaces: Space[] = [],
  253. columns: Column[] = [],
  254. walls: Wall[] = [],
  255. virtualWall: VirtualWall[] = [];
  256. result = result
  257. .map((t: any) => {
  258. if (
  259. t.target &&
  260. t.target._data &&
  261. t.target._data.vertices
  262. ) {
  263. let arr = t.target._data.vertices,
  264. type = t.typeID,
  265. outline = [];
  266. for (let i = 0; i < arr.length - 1; i += 2) {
  267. outline.push({
  268. X: arr[i] - 12982584.99,
  269. Y: arr[i + 1] - 4911901.56
  270. });
  271. }
  272. if (this.spaceType.indexOf(type) > -1) {
  273. spaces.push({
  274. // @ts-ignore
  275. OutLine: [outline],
  276. Name: t.target.name,
  277. Location: {
  278. // @ts-ignore
  279. Points: [this.getAverageVal([outline])]
  280. },
  281. Type: t.typeID,
  282. // @ts-ignore
  283. Tag: SFengParser.typeIdMap[t.typeID]
  284. });
  285. } else if (this.columnType.indexOf(type) > -1) {
  286. // @ts-ignore
  287. columns.push({ OutLine: [outline] });
  288. } else if (this.wallType.indexOf(type) > -1) {
  289. // @ts-ignore
  290. walls.push({ OutLine: [outline] });
  291. } else if (
  292. this.virtualWallType.indexOf(type) > -1
  293. ) {
  294. // @ts-ignore
  295. virtualWall.push({ OutLine: [outline] });
  296. }
  297. }
  298. })
  299. .filter((item: any) => item);
  300. obj = {
  301. Spaces: spaces,
  302. Columns: columns,
  303. Walls: walls,
  304. VirtualWalls: virtualWall
  305. };
  306. _fn(obj);
  307. });
  308. });
  309. }
  310. /**
  311. * 计算平均值
  312. *
  313. * @param Outline 轮廓线束
  314. * @return object {X:X,Y:Y}x的平均值,y的平均值
  315. * */
  316. private getAverageVal(Outline: { X: number; Y: number }[][]): object {
  317. let X = 0,
  318. Y = 0,
  319. len = Outline[0].length;
  320. Outline[0].map(item => {
  321. X += item.X;
  322. Y += item.Y;
  323. });
  324. X = Number((X / len).toFixed(2));
  325. Y = Number((Y / len).toFixed(2));
  326. return {
  327. X: X,
  328. Y: Y
  329. };
  330. }
  331. } // class SEquipParser