FloorplanService.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. import { floorplanData } from '../FloorplanData'
  2. import { coordinate } from '../Coordinate.js'
  3. import Constant from '../Constant'
  4. import Title from '../Geometry/Title.js'
  5. import BgImage from '../Geometry/BgImage.js'
  6. import Compass from '../Geometry/Compass.js'
  7. export class FloorplanService {
  8. constructor() {
  9. this.currentId = 0 // 当前可用id
  10. this.currentFloor = 0 // 当前楼层,第一层是0
  11. this.angle = 0 //旋转角度
  12. }
  13. setCurrentId(id) {
  14. this.currentId = id
  15. }
  16. getCurrentId() {
  17. return this.currentId
  18. }
  19. updateCurrentId() {
  20. ++this.currentId
  21. }
  22. setCurrentFloor(floor) {
  23. if (floorplanData.floors.length == 1) {
  24. this.currentFloor = 0
  25. } else {
  26. this.currentFloor = floor
  27. }
  28. }
  29. getCurrentFloor() {
  30. return this.currentFloor
  31. }
  32. getFloorNum() {
  33. return floorplanData.floors.length
  34. }
  35. initFloor(floorNum) {
  36. floorplanData.initFloor(floorNum)
  37. }
  38. getFloors() {
  39. return floorplanData.floors
  40. }
  41. getPoint(pointId, floor) {
  42. if (floor == null || typeof floor == 'undefined') {
  43. floor = this.currentFloor
  44. }
  45. return floorplanData.floors[floor].points[pointId]
  46. }
  47. deletePoint(pointId, wallId, floor) {
  48. if (floor == null || typeof floor == 'undefined') {
  49. floor = this.currentFloor
  50. }
  51. let point = this.getPoint(pointId)
  52. //有可能先删除墙,导致点没了
  53. if (point) {
  54. if (Object.keys(point.parent).length == 0) {
  55. point = null
  56. delete floorplanData.floors[floor].points[pointId]
  57. } else if (Object.keys(point.parent).length == 1 && !wallId) {
  58. delete floorplanData.floors[floor].points[pointId]
  59. } else if (Object.keys(point.parent).length == 1 && point.parent[wallId]) {
  60. delete floorplanData.floors[floor].points[pointId]
  61. } else if (Object.keys(point.parent).length == 1 && !point.parent[wallId]) {
  62. return
  63. } else {
  64. delete point.parent[wallId]
  65. }
  66. }
  67. }
  68. getWall(wallId, floor) {
  69. if (floor == null || typeof floor == 'undefined') {
  70. floor = this.currentFloor
  71. }
  72. return floorplanData.floors[floor].walls[wallId]
  73. }
  74. deleteWall(wallId, floor) {
  75. if (floor == null || typeof floor == 'undefined') {
  76. floor = this.currentFloor
  77. }
  78. let wall = this.getWall(wallId, floor)
  79. this.deletePoint(wall.start, wallId, floor)
  80. this.deletePoint(wall.end, wallId, floor)
  81. delete floorplanData.floors[floor].walls[wallId]
  82. }
  83. getAngle() {
  84. return this.angle
  85. }
  86. setAngle(angle) {
  87. this.angle = angle
  88. }
  89. getFloorData(floor) {
  90. if (floor == null || typeof floor == 'undefined') {
  91. floor = this.currentFloor
  92. }
  93. return floorplanData.floors[floor]
  94. }
  95. getWalls(floor) {
  96. if (floor == null || typeof floor == 'undefined') {
  97. floor = this.currentFloor
  98. }
  99. return floorplanData.floors[floor].walls
  100. }
  101. getPoints(floor) {
  102. if (floor == null || typeof floor == 'undefined') {
  103. floor = this.currentFloor
  104. }
  105. return floorplanData.floors[floor].points
  106. }
  107. addWall(wall, floor) {
  108. if (floor == null || typeof floor == 'undefined') {
  109. floor = this.currentFloor
  110. }
  111. floorplanData.floors[floor].walls[wall.vectorId] = wall
  112. }
  113. addPoint(point, floor) {
  114. if (floor == null || typeof floor == 'undefined') {
  115. floor = this.currentFloor
  116. }
  117. floorplanData.floors[floor].points[point.vectorId] = point
  118. }
  119. addRectangle(rectangle,floor){
  120. if (floor == null || typeof floor == 'undefined') {
  121. floor = this.currentFloor
  122. }
  123. floorplanData.floors[floor].rectangles[rectangle.vectorId] = rectangle
  124. }
  125. getRectangle(rectangleId, floor) {
  126. if (floor == null || typeof floor == 'undefined') {
  127. floor = this.currentFloor
  128. }
  129. return floorplanData.floors[floor].rectangles[rectangleId]
  130. }
  131. deleteRectangle(rectangleId, floor){
  132. if (floor == null || typeof floor == 'undefined') {
  133. floor = this.currentFloor
  134. }
  135. let rectangle = this.getRectangle(rectangleId, floor)
  136. rectangle = null
  137. delete floorplanData.floors[floor].rectangles[rectangleId]
  138. }
  139. addCircle(circle,floor){
  140. if (floor == null || typeof floor == 'undefined') {
  141. floor = this.currentFloor
  142. }
  143. floorplanData.floors[floor].circles[circle.vectorId] = circle
  144. }
  145. getCircle(circleId, floor) {
  146. if (floor == null || typeof floor == 'undefined') {
  147. floor = this.currentFloor
  148. }
  149. return floorplanData.floors[floor].circles[circleId]
  150. }
  151. deleteCircle(circleId, floor){
  152. if (floor == null || typeof floor == 'undefined') {
  153. floor = this.currentFloor
  154. }
  155. let circle = this.getCircle(circleId, floor)
  156. circle = null
  157. delete floorplanData.floors[floor].circles[circleId]
  158. }
  159. addArrow(arrow,floor){
  160. if (floor == null || typeof floor == 'undefined') {
  161. floor = this.currentFloor
  162. }
  163. floorplanData.floors[floor].arrows[arrow.vectorId] = arrow
  164. }
  165. getArrow(arrowId, floor) {
  166. if (floor == null || typeof floor == 'undefined') {
  167. floor = this.currentFloor
  168. }
  169. return floorplanData.floors[floor].arrows[arrowId]
  170. }
  171. deleteArrow(arrowId, floor){
  172. if (floor == null || typeof floor == 'undefined') {
  173. floor = this.currentFloor
  174. }
  175. let arrow = this.getArrow(arrowId, floor)
  176. arrow = null
  177. delete floorplanData.floors[floor].arrows[arrowId]
  178. }
  179. addIcon(icon,floor){
  180. if (floor == null || typeof floor == 'undefined') {
  181. floor = this.currentFloor
  182. }
  183. floorplanData.floors[floor].icons[icon.vectorId] = icon
  184. }
  185. getIcon(iconId, floor) {
  186. if (floor == null || typeof floor == 'undefined') {
  187. floor = this.currentFloor
  188. }
  189. return floorplanData.floors[floor].icons[iconId]
  190. }
  191. deleteIcon(iconId, floor){
  192. if (floor == null || typeof floor == 'undefined') {
  193. floor = this.currentFloor
  194. }
  195. let icon = this.getIcon(iconId, floor)
  196. icon = null
  197. delete floorplanData.floors[floor].icons[iconId]
  198. }
  199. addSign(sign, floor) {
  200. if (floor == null || typeof floor == 'undefined') {
  201. floor = this.currentFloor
  202. }
  203. floorplanData.floors[floor].signs[sign.vectorId] = sign
  204. }
  205. getSign(signId, floor) {
  206. if (floor == null || typeof floor == 'undefined') {
  207. floor = this.currentFloor
  208. }
  209. return floorplanData.floors[floor].signs[signId]
  210. }
  211. deleteSign(signId, floor) {
  212. if (floor == null || typeof floor == 'undefined') {
  213. floor = this.currentFloor
  214. }
  215. let sign = this.getSign(signId, floor)
  216. sign = null
  217. delete floorplanData.floors[floor].signs[signId]
  218. }
  219. addTag(tag, floor) {
  220. if (floor == null || typeof floor == 'undefined') {
  221. floor = this.currentFloor
  222. }
  223. floorplanData.floors[floor].tags[tag.vectorId] = tag
  224. }
  225. getTag(tagId, floor) {
  226. if (floor == null || typeof floor == 'undefined') {
  227. floor = this.currentFloor
  228. }
  229. return floorplanData.floors[floor].tags[tagId]
  230. }
  231. deleteTag(tagId, floor) {
  232. if (floor == null || typeof floor == 'undefined') {
  233. floor = this.currentFloor
  234. }
  235. let tag = this.getTag(tagId, floor)
  236. tag = null
  237. delete floorplanData.floors[floor].tags[tagId]
  238. }
  239. getTags(floor) {
  240. if (floor == null || typeof floor == 'undefined') {
  241. floor = this.currentFloor
  242. }
  243. return floorplanData.floors[floor].tags
  244. }
  245. addTable(table, floor) {
  246. if (floor == null || typeof floor == 'undefined') {
  247. floor = this.currentFloor
  248. }
  249. floorplanData.floors[floor].tables[table.vectorId] = table
  250. }
  251. getTable(tableId, floor) {
  252. if (floor == null || typeof floor == 'undefined') {
  253. floor = this.currentFloor
  254. }
  255. return floorplanData.floors[floor].tables[tableId]
  256. }
  257. deleteTable(tableId, floor) {
  258. if (floor == null || typeof floor == 'undefined') {
  259. floor = this.currentFloor
  260. }
  261. let table = this.getTable(tableId, floor)
  262. table = null
  263. delete floorplanData.floors[floor].tables[tableId]
  264. }
  265. getTables(floor) {
  266. if (floor == null || typeof floor == 'undefined') {
  267. floor = this.currentFloor
  268. }
  269. return floorplanData.floors[floor].tables
  270. }
  271. addCell(cell, floor) {
  272. if (floor == null || typeof floor == 'undefined') {
  273. floor = this.currentFloor
  274. }
  275. floorplanData.floors[floor].cells[cell.vectorId] = cell
  276. }
  277. getCell(cellId, floor) {
  278. if (floor == null || typeof floor == 'undefined') {
  279. floor = this.currentFloor
  280. }
  281. return floorplanData.floors[floor].cells[cellId]
  282. }
  283. deleteCell(cellId, floor) {
  284. if (floor == null || typeof floor == 'undefined') {
  285. floor = this.currentFloor
  286. }
  287. let cell = this.getCell(cellId, floor)
  288. cell = null
  289. delete floorplanData.floors[floor].cells[cellId]
  290. }
  291. getCells(floor) {
  292. if (floor == null || typeof floor == 'undefined') {
  293. floor = this.currentFloor
  294. }
  295. return floorplanData.floors[floor].cells
  296. }
  297. getRectangles(floor) {
  298. if (floor == null || typeof floor == 'undefined') {
  299. floor = this.currentFloor
  300. }
  301. return floorplanData.floors[floor].rectangles
  302. }
  303. getCircles(floor) {
  304. if (floor == null || typeof floor == 'undefined') {
  305. floor = this.currentFloor
  306. }
  307. return floorplanData.floors[floor].circles
  308. }
  309. getArrows(floor) {
  310. if (floor == null || typeof floor == 'undefined') {
  311. floor = this.currentFloor
  312. }
  313. return floorplanData.floors[floor].arrows
  314. }
  315. getIcons(floor) {
  316. if (floor == null || typeof floor == 'undefined') {
  317. floor = this.currentFloor
  318. }
  319. return floorplanData.floors[floor].icons
  320. }
  321. getSigns(floor) {
  322. if (floor == null || typeof floor == 'undefined') {
  323. floor = this.currentFloor
  324. }
  325. return floorplanData.floors[floor].signs
  326. }
  327. clear() {
  328. if (floorplanData.floors[this.currentFloor]) {
  329. floorplanData.floors[this.currentFloor].points = {}
  330. floorplanData.floors[this.currentFloor].walls = {}
  331. floorplanData.floors[this.currentFloor].rectangles = {}
  332. floorplanData.floors[this.currentFloor].circles = {}
  333. floorplanData.floors[this.currentFloor].tags = {}
  334. floorplanData.floors[this.currentFloor].tables = {}
  335. floorplanData.floors[this.currentFloor].cells = {}
  336. floorplanData.floors[this.currentFloor].signs = {}
  337. floorplanData.floors[this.currentFloor].arrows = {}
  338. floorplanData.floors[this.currentFloor].icons = []
  339. }
  340. }
  341. deleteFloorData() {
  342. floorplanData.floors = []
  343. }
  344. createTitle(value,vectorId,floor){
  345. if (floor == null || typeof floor == 'undefined') {
  346. floor = this.currentFloor
  347. }
  348. const title = new Title(value,vectorId,floor)
  349. return title
  350. }
  351. addTitle(title, floor) {
  352. if (floor == null || typeof floor == 'undefined') {
  353. floor = this.currentFloor
  354. }
  355. floorplanData.floors[floor].title = title
  356. }
  357. updateTitle(value,floor){
  358. if (floor == null || typeof floor == 'undefined') {
  359. floor = this.currentFloor
  360. }
  361. const title = floorplanData.floors[floor].title
  362. title.setValue(value)
  363. }
  364. getTitle(floor) {
  365. if (floor == null || typeof floor == 'undefined') {
  366. floor = this.currentFloor
  367. }
  368. return floorplanData.floors[floor].title
  369. }
  370. createBgImage(value,vectorId,floor){
  371. if (floor == null || typeof floor == 'undefined') {
  372. floor = this.currentFloor
  373. }
  374. const image = new BgImage(value,vectorId,floor)
  375. return image
  376. }
  377. addBgImage(image, floor) {
  378. if (floor == null || typeof floor == 'undefined') {
  379. floor = this.currentFloor
  380. }
  381. floorplanData.floors[floor].image = image
  382. }
  383. updateBgImage(value,floor){
  384. if (floor == null || typeof floor == 'undefined') {
  385. floor = this.currentFloor
  386. }
  387. const img = floorplanData.floors[floor].image
  388. img.setSrc(value)
  389. }
  390. getBgImage(floor) {
  391. if (floor == null || typeof floor == 'undefined') {
  392. floor = this.currentFloor
  393. }
  394. return floorplanData.floors[floor].image
  395. }
  396. createCompass(value,vectorId,floor){
  397. if (floor == null || typeof floor == 'undefined') {
  398. floor = this.currentFloor
  399. }
  400. const compass = new Compass(value,vectorId,floor)
  401. return compass
  402. }
  403. addCompass(compass, floor) {
  404. if (floor == null || typeof floor == 'undefined') {
  405. floor = this.currentFloor
  406. }
  407. floorplanData.floors[floor].compass = compass
  408. }
  409. updateCompass(value,floor){
  410. if (floor == null || typeof floor == 'undefined') {
  411. floor = this.currentFloor
  412. }
  413. const compass = floorplanData.floors[floor].compass
  414. compass.setAngle(value)
  415. }
  416. // eslint-disable-next-line no-dupe-class-members
  417. getCompass(floor) {
  418. if (floor == null || typeof floor == 'undefined') {
  419. floor = this.currentFloor
  420. }
  421. return floorplanData.floors[floor].compass
  422. }
  423. }
  424. const floorplanService = new FloorplanService()
  425. export { floorplanService }