SFengParser.ts 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258
  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. };
  67. /** 蜂鸟:底图应用名称 */
  68. appName: string = "";
  69. /** 当前蜂鸟map的id */
  70. currentMapId: string = "";
  71. /** 蜂鸟map绑定dom的id */
  72. domId: string = "";
  73. /** 蜂鸟:底图应用秘钥 */
  74. key: string = "";
  75. /** 底图服务器地址 */
  76. serverUrl: string = "./data/";
  77. /** 蜂鸟图 */
  78. private readonly fmap: fengmap.FMMap;
  79. /** 属于空间类型typeid */
  80. spaceType: number[] = [
  81. 100000,
  82. 200000,
  83. 900000,
  84. 800000,
  85. 200004,
  86. 200003,
  87. 200103,
  88. 200203,
  89. 200005,
  90. 200002,
  91. 200006,
  92. 200007,
  93. 200017,
  94. 200018,
  95. 200019,
  96. 200020,
  97. 200014,
  98. 200009,
  99. 200008,
  100. 200011,
  101. 200012,
  102. 200013,
  103. 200015,
  104. 200016,
  105. 200021,
  106. 170006,
  107. 170008,
  108. 170007,
  109. 170003,
  110. 170001,
  111. 100001,
  112. 100004,
  113. 100005,
  114. 100007,
  115. 140002,
  116. 170002,
  117. 150010,
  118. 100003,
  119. 140004,
  120. 170005,
  121. 120001
  122. ];
  123. /** 属于柱子类型的typeid */
  124. columnType: number[] = [300002];
  125. /** 属于墙类型的typeid */
  126. wallType: number[] = [300000, 300001];
  127. /** 属于虚拟墙类型的typeid */
  128. virtualWallType: number[] = [
  129. 200001,
  130. 110001,
  131. 200010,
  132. 120008,
  133. 120009,
  134. 120010
  135. ];
  136. /** 构造体 */
  137. constructor(
  138. domId: string,
  139. mapServerURL: string,
  140. key: string,
  141. appName: string,
  142. factory: SItemFactory
  143. ) {
  144. super(factory);
  145. this.domId = domId;
  146. this.key = key;
  147. this.serverUrl = mapServerURL;
  148. this.appName = appName;
  149. this.fmap = new fengmap.FMMap({
  150. container: document.getElementById(this.domId),
  151. mapServerURL: this.serverUrl,
  152. appName: this.appName,
  153. key: this.key
  154. });
  155. } // Constructor
  156. /**
  157. * 解析数据
  158. *
  159. * @param currentMapId 当前模型id
  160. * @param groupId 当前楼层
  161. * @param _fn 查询成功回调函数(返回参数为FloorData)
  162. * */
  163. parseData(currentMapId: string, groupId: string, _fn: Function): void {
  164. this.fmap.openMapById(currentMapId, (err: any) => {
  165. console.log("错误信息", err);
  166. });
  167. this.fmap.on("loadComplete", () => {
  168. let obj = {};
  169. // 创建搜索分析对象
  170. let searchAnalyser = new fengmap.FMSearchAnalyser(this.fmap);
  171. // 创建搜索请求体对象
  172. let searchReq = new fengmap.FMSearchRequest();
  173. searchReq.groupID = groupId;
  174. searchReq.type = "Model";
  175. searchAnalyser.query(searchReq, (result: any) => {
  176. let spaces: Space[] = [],
  177. columns: Column[] = [],
  178. walls: Wall[] = [],
  179. virtualWall: VirtualWall[] = [];
  180. result = result
  181. .map((t: any) => {
  182. if (
  183. t.target &&
  184. t.target._data &&
  185. t.target._data.vertices
  186. ) {
  187. let arr = t.target._data.vertices,
  188. type = t.typeID,
  189. outline = [];
  190. for (let i = 0; i < arr.length - 1; i += 2) {
  191. outline.push({
  192. X: arr[i] - 12982584.99,
  193. Y: arr[i + 1] - 4911901.56
  194. });
  195. }
  196. if (this.spaceType.indexOf(type) > -1) {
  197. spaces.push({
  198. // @ts-ignore
  199. OutLine: [outline],
  200. Name: t.target.name,
  201. Location: {
  202. // @ts-ignore
  203. Points: [this.getAverageVal([outline])]
  204. },
  205. Type: t.typeID
  206. });
  207. } else if (this.columnType.indexOf(type) > -1) {
  208. // @ts-ignore
  209. columns.push({ OutLine: [outline] });
  210. } else if (this.wallType.indexOf(type) > -1) {
  211. // @ts-ignore
  212. walls.push({ OutLine: [outline] });
  213. } else if (
  214. this.virtualWallType.indexOf(type) > -1
  215. ) {
  216. // @ts-ignore
  217. virtualWall.push({ OutLine: [outline] });
  218. }
  219. }
  220. })
  221. .filter((item: any) => item);
  222. obj = {
  223. Spaces: spaces,
  224. Columns: columns,
  225. Walls: walls,
  226. VirtualWalls: virtualWall
  227. };
  228. _fn(obj);
  229. });
  230. });
  231. }
  232. /**
  233. * 计算平均值
  234. *
  235. * @param Outline 轮廓线束
  236. * @return object {X:X,Y:Y}x的平均值,y的平均值
  237. * */
  238. private getAverageVal(Outline: { X: number; Y: number }[][]): object {
  239. let X = 0,
  240. Y = 0,
  241. len = Outline[0].length;
  242. Outline[0].map(item => {
  243. X += item.X;
  244. Y += item.Y;
  245. });
  246. X = Number((X / len).toFixed(2));
  247. Y = Number((Y / len).toFixed(2));
  248. return {
  249. X: X,
  250. Y: Y
  251. };
  252. }
  253. } // class SEquipParser