SFengParser.ts 11 KB

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