SFengParser.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  1. import { SParser } from "@persagy-web/big/lib";
  2. import fengmap from "fengmap";
  3. import Axios from "axios";
  4. export class SFengParser extends SParser {
  5. constructor(domId, mapServerURL, key, appName, factory, mapThemeURL) {
  6. super(factory);
  7. this.appName = "";
  8. this.mapId = "1000423_";
  9. this.domId = "";
  10. this.key = "";
  11. this.serverUrl = "./data/";
  12. this.mapThemeURL = "./";
  13. this.spaceType = [
  14. 100000,
  15. 200000,
  16. 900000,
  17. 800000,
  18. 200004,
  19. 200003,
  20. 200103,
  21. 200203,
  22. 200005,
  23. 200002,
  24. 200006,
  25. 200007,
  26. 200017,
  27. 200018,
  28. 200019,
  29. 200020,
  30. 200014,
  31. 200009,
  32. 200008,
  33. 200011,
  34. 200012,
  35. 200013,
  36. 200015,
  37. 200016,
  38. 200021,
  39. 300004,
  40. 300005,
  41. 300006,
  42. 300007,
  43. 300008,
  44. 300009,
  45. 300010,
  46. 300011,
  47. 300012,
  48. 300013,
  49. 300014,
  50. 300015,
  51. 300016,
  52. 300017,
  53. 300018,
  54. 300019,
  55. 300020,
  56. 300021,
  57. 300022,
  58. 300023,
  59. 300024,
  60. 300025,
  61. 300026,
  62. 300027,
  63. 300028,
  64. 300029,
  65. 300030,
  66. 300031,
  67. 300032,
  68. 300033,
  69. 300034,
  70. 300035,
  71. 300036,
  72. 300037,
  73. 300038,
  74. 300039,
  75. 200023,
  76. 200022
  77. ];
  78. this.columnType = [300002];
  79. this.wallType = [300000, 300001];
  80. this.virtualWallType = [200001, 110001, 200010];
  81. this.poiList = [
  82. 170006,
  83. 170008,
  84. 170007,
  85. 170003,
  86. 170001,
  87. 100001,
  88. 100004,
  89. 100005,
  90. 100007,
  91. 140002,
  92. 170002,
  93. 150010,
  94. 100003,
  95. 140004,
  96. 170005,
  97. 120001,
  98. 120008,
  99. 120009,
  100. 120010
  101. ];
  102. this.gnameToGid = {};
  103. this.floorList = [];
  104. this.version = null;
  105. this.frImg = "";
  106. this.domId = domId;
  107. this.key = key;
  108. this.serverUrl = mapServerURL;
  109. this.mapThemeURL = mapThemeURL;
  110. this.appName = appName;
  111. }
  112. parseData(groupId, _fn) {
  113. let obj = {};
  114. this.fmap.focusGroupID = groupId;
  115. let searchAnalyser = new fengmap.FMSearchAnalyser(this.fmap);
  116. let searchReq = new fengmap.FMSearchRequest();
  117. const minx = this.fmap.minX;
  118. const maxy = this.fmap.maxY;
  119. searchReq.groupID = groupId;
  120. searchReq.type = "Model";
  121. searchAnalyser.query(searchReq, (result) => {
  122. let spaces = [], columns = [], walls = [], virtualWall = [], pList = [];
  123. result.forEach((t) => {
  124. if (t.target) {
  125. let type = t.typeID;
  126. if (t.target._data && t.target._data.vertices) {
  127. let arr = t.target._data.vertices, outline = [];
  128. for (let i = 0; i < arr.length - 1; i += 2) {
  129. outline.push({
  130. X: arr[i] - minx,
  131. Y: arr[i + 1] - maxy
  132. });
  133. }
  134. if (this.spaceType.indexOf(type) > -1) {
  135. spaces.push({
  136. OutLine: [outline],
  137. Name: t.target.name,
  138. Location: {
  139. Points: [this.getAverageVal([outline])]
  140. },
  141. Type: t.typeID,
  142. Tag: SFengParser.typeIdMap[t.typeID],
  143. SourceId: t.FID,
  144. Height: t.target.height
  145. });
  146. }
  147. else if (this.columnType.indexOf(type) > -1) {
  148. columns.push({ OutLine: [outline] });
  149. }
  150. else if (this.wallType.indexOf(type) > -1) {
  151. const hasHole = t.target._data.holes &&
  152. t.target._data.holes.length;
  153. let holes = [];
  154. if (hasHole) {
  155. let tempArr = t.target._data.holes;
  156. for (let j = 0; j < tempArr.length; j++) {
  157. let holeChild = [];
  158. for (let i = 0; i < tempArr[j].length - 1; i += 2) {
  159. holeChild.push({
  160. X: tempArr[j][i] - minx,
  161. Y: tempArr[j][i + 1] - maxy
  162. });
  163. }
  164. holes.push(holeChild);
  165. }
  166. }
  167. walls.push({ OutLine: [outline], HasHole: hasHole, Holes: holes });
  168. }
  169. else if (this.virtualWallType.indexOf(type) > -1) {
  170. virtualWall.push({ OutLine: [outline] });
  171. }
  172. }
  173. if (this.poiList.indexOf(type) > -1) {
  174. pList.push({
  175. Name: t.target.name,
  176. Pos: {
  177. X: t.mapCoord.x - minx,
  178. Y: t.mapCoord.y - maxy
  179. },
  180. Type: t.typeID,
  181. Tag: SFengParser.typeIdMap[t.typeID],
  182. Height: t.target.height,
  183. SourceId: t.ID
  184. });
  185. }
  186. }
  187. });
  188. obj = {
  189. Spaces: spaces,
  190. Columns: columns,
  191. Walls: walls,
  192. VirtualWalls: virtualWall,
  193. PList: pList
  194. };
  195. _fn(obj);
  196. });
  197. }
  198. loadMap(mapId, _fn) {
  199. this.fmap = new fengmap.FMMap({
  200. container: document.getElementById(this.domId),
  201. mapServerURL: this.serverUrl,
  202. appName: this.appName,
  203. key: this.key,
  204. mapThemeURL: this.mapThemeURL,
  205. defaultThemeName: mapId
  206. });
  207. this.fmap.openMapById(mapId, (err) => {
  208. console.log("错误信息", err);
  209. });
  210. this.fmap.on("loadComplete", () => {
  211. if (this.mapId != mapId) {
  212. this.mapId = mapId;
  213. this.gnameToGid = {};
  214. this.floorList = [];
  215. this.fmap.listGroups.forEach(t => {
  216. this.gnameToGid[t.gname] = t.gid;
  217. this.floorList.push(t);
  218. });
  219. }
  220. _fn(this.gnameToGid, this.floorList);
  221. });
  222. }
  223. loadTheme(url) {
  224. return new Promise((resolve, reject) => {
  225. Axios({
  226. method: "get",
  227. url: url
  228. })
  229. .then((res) => {
  230. this.mapTheme = res.data;
  231. let data = res.data.storetheme;
  232. this.frImg = data[data.length - 1].image;
  233. resolve(this.frImg);
  234. })
  235. .catch((res) => {
  236. console.log(res);
  237. });
  238. });
  239. }
  240. loadFloor(groupId, _fn) {
  241. const minx = this.fmap.minX;
  242. const maxy = this.fmap.maxY;
  243. this.fmap.getDatasByAlias(Number(groupId), "extent", (res) => {
  244. let index = res.gdata.geo.indexOf("(");
  245. let str = res.gdata.geo.substring(index);
  246. str = str.replace(/\(/g, "[");
  247. str = str.replace(/\)/g, "]");
  248. str = str.replace(/\s/g, ",");
  249. const arr = JSON.parse(str);
  250. const aaa = [];
  251. for (let i = 0; i < arr.length; i++) {
  252. let a = arr[i];
  253. const bbb = [];
  254. for (let j = 0; j < a.length; j++) {
  255. let b = a[j];
  256. const ccc = [];
  257. for (let k = 0; k < b.length - 1; k += 2) {
  258. ccc.push({
  259. X: b[k] - minx,
  260. Y: b[k + 1] - maxy
  261. });
  262. }
  263. bbb.push(ccc);
  264. }
  265. aaa.push(bbb);
  266. }
  267. _fn({ OutLine: aaa });
  268. });
  269. }
  270. getAverageVal(Outline) {
  271. let X = 0, Y = 0, len = Outline[0].length;
  272. Outline[0].map(item => {
  273. X += item.X;
  274. Y += item.Y;
  275. });
  276. X = Number((X / len).toFixed(2));
  277. Y = Number((Y / len).toFixed(2));
  278. return {
  279. X: X,
  280. Y: Y
  281. };
  282. }
  283. }
  284. SFengParser.typeIdMap = {
  285. 100000: "Pavement",
  286. 200000: "FrontagePavement",
  287. 900000: "AuxiliarySurface",
  288. 300000: "SolidWall",
  289. 300001: "GlassWall",
  290. 300003: "PartitionWall",
  291. 300002: "BearingColumn",
  292. 800000: "ParkingSpace",
  293. 200004: "StraightLadder",
  294. 200003: "Escalator",
  295. 200103: "UplinkOnly",
  296. 200203: "DownOnly",
  297. 200005: "Stairs",
  298. 200002: "Toilet",
  299. 200001: "EntranceAndExit",
  300. 200006: "Cashier",
  301. 200007: "ATM",
  302. 200017: "AlarmPoint",
  303. 200018: "DressModification",
  304. 200019: "JewelryRepair",
  305. 200020: "Checkroom",
  306. 200014: "InformationDesk",
  307. 200009: "PublicPhone",
  308. 200008: "ServiceCentre",
  309. 200010: "Exit",
  310. 200011: "CargoLift",
  311. 200012: "Lounge",
  312. 200013: "CarPark",
  313. 200015: "MotherBabyRoom",
  314. 200016: "VIP",
  315. 200021: "WheelchairAccessible",
  316. 170006: "StraightLadder",
  317. 170008: "UpEscalator",
  318. 170007: "DownEscalator",
  319. 170003: "Escalator",
  320. 170001: "Stairs",
  321. 110001: "EntranceAndExit",
  322. 100001: "Restroom",
  323. 100004: "MenRestroom",
  324. 100005: "WomenRestroom",
  325. 100007: "AccessibleToilet",
  326. 140002: "ServiceCentre",
  327. 170002: "CargoLift",
  328. 150010: "Lounge",
  329. 100003: "MotherBabyRoom",
  330. 140004: "VIP",
  331. 170005: "WheelchairAccessible",
  332. 120001: "CarPark",
  333. 120008: "ParkingExit",
  334. 120009: "ParkingEntrance",
  335. 120010: "ParkingExitAndEntrance",
  336. 300005: "SwitchingStation",
  337. 300006: "DistributionRoom",
  338. 300007: "StrongElectricWell",
  339. 300008: "WeakCurrentWell",
  340. 300009: "AirConditionerEngineRoom",
  341. 300010: "RefrigerationRoom",
  342. 300011: "FreshAirRoom",
  343. 300012: "CompressorRoom",
  344. 300013: "HeatSourceMachineRoom",
  345. 300014: "DomesticWaterPumpHouse",
  346. 300015: "HighLevelWaterTankRoom",
  347. 300016: "SewageTreatmentRoom",
  348. 300017: "FirePumpHouse",
  349. 300018: "WetAlarmValveChamber",
  350. 300019: "PreActionAlarmValveChamber",
  351. 300020: "AirSupplyRoom",
  352. 300021: "ExhaustFanRoom",
  353. 300022: "MakeUpAirRoom",
  354. 300023: "BusinessManagementOffice",
  355. 300024: "NetworkRoom",
  356. 300025: "Substation",
  357. 300026: "GeneratorRoom",
  358. 300027: "TrusteeshipRoom",
  359. 300028: "HuiyunMachineRoom",
  360. 300029: "AlarmValveChamber",
  361. 300030: "ReclaimedWaterMachineRoom",
  362. 300031: "FireControlRoom",
  363. 300032: "OilSeparator",
  364. 300033: "GasBoilerRoom",
  365. 300034: "GasMeterRoom",
  366. 300035: "ElevatorMachineRoom",
  367. 300036: "StaffRestaurant",
  368. 300037: "DryGarbageRoom",
  369. 300038: "WetGarbageRoom",
  370. 300039: "ExpansionWaterTankRoom",
  371. 200023: "MensBathroom",
  372. 200022: "WomensToilet"
  373. };