@realsee/dnalogel 2.0.0-alpha.35 → 2.0.0-alpha.36

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (211) hide show
  1. package/dist/ItemLabelPlugin/index.js +21 -41
  2. package/dist/ModelItemLabelPlugin/index.js +16 -36
  3. package/dist/PanoMeasurePlugin/Modules/DeleteDom/_Assets/delete_hover_bg.png.d.ts +1 -1
  4. package/dist/PanoMeasurePlugin/Modules/UIController/HTML.d.ts +0 -4
  5. package/dist/PanoMeasurePlugin/Modules/UIController/MainBtnController.d.ts +0 -3
  6. package/dist/PanoMeasurePlugin/Modules/UIController/mobileHTML.d.ts +2 -0
  7. package/dist/PanoMeasurePlugin/Modules/UIController/{NewMainBtnController.d.ts → mobileMainBtnController.d.ts} +1 -1
  8. package/dist/PanoMeasurePlugin/Modules/UIController/style.d.ts +0 -3
  9. package/dist/PanoMeasurePlugin/Modules/rangePiece/html.d.ts +1 -1
  10. package/dist/PanoMeasurePlugin/Modules/rangePiece/index.d.ts +2 -0
  11. package/dist/PanoMeasurePlugin/index.js +298 -331
  12. package/dist/PanoMeasurePlugin/typings/data.d.ts +5 -0
  13. package/dist/PanoMeasurePlugin/utils/mouseGroup.d.ts +6 -1
  14. package/dist/base/BasePlugin.d.ts +100 -0
  15. package/dist/base/BasePluginWithData.d.ts +34 -0
  16. package/dist/floorplan/ModelFloorplanPlugin/Controller.d.ts +70 -78
  17. package/dist/floorplan/ModelFloorplanPlugin/index.d.ts +5 -7
  18. package/dist/floorplan/ModelFloorplanPlugin/index.js +1059 -569
  19. package/dist/floorplan/ModelFloorplanPlugin/typing.d.ts +107 -0
  20. package/dist/floorplan/PanoFloorplanRadarPlugin/Controller.d.ts +23 -14
  21. package/dist/floorplan/PanoFloorplanRadarPlugin/index.d.ts +5 -6
  22. package/dist/floorplan/PanoFloorplanRadarPlugin/index.js +489 -129
  23. package/dist/floorplan/PanoFloorplanRadarPlugin/typing.d.ts +52 -0
  24. package/dist/floorplan/TopviewFloorplanPlugin/Controller.d.ts +50 -58
  25. package/dist/floorplan/TopviewFloorplanPlugin/index.d.ts +5 -3
  26. package/dist/floorplan/TopviewFloorplanPlugin/index.js +1031 -443
  27. package/dist/floorplan/TopviewFloorplanPlugin/typing.d.ts +86 -0
  28. package/{libs/floorplan/ModelFloorplanPlugin → dist/floorplan}/utils/constant.d.ts +10 -3
  29. package/{libs/floorplan/ModelFloorplanPlugin → dist/floorplan}/utils/correctFiveState.d.ts +2 -1
  30. package/dist/index.es.js +2184 -1411
  31. package/dist/index.js +2188 -1415
  32. package/dist/index.umd.js +2142 -1369
  33. package/dist/shared-utils/five/changeMode.d.ts +4 -1
  34. package/dist/shared-utils/getPxmm.d.ts +8 -0
  35. package/docs/assets/search.js +1 -1
  36. package/docs/classes/Magnifier.html +4 -4
  37. package/docs/classes/ModelRoomLabelController.html +4 -4
  38. package/docs/enums/CameraMovementEffect.html +2 -2
  39. package/docs/enums/DIRECTION.html +1 -1
  40. package/docs/enums/DISPLAY_STRATEGY_TYPE.html +1 -1
  41. package/docs/enums/FLOOR_PLAN_ATTACHED_TO.html +1 -1
  42. package/docs/enums/ITEM_LABEL_PLUGIN_DISPLAY_STRATEGY_TYPE.html +1 -1
  43. package/docs/enums/Rotation.html +2 -2
  44. package/docs/index.html +2 -2
  45. package/docs/interfaces/CSS3DRenderPluginExportType.html +2 -2
  46. package/docs/interfaces/CameraMovementPluginExportType.html +2 -2
  47. package/docs/interfaces/FloorplanBounding.html +4 -4
  48. package/docs/interfaces/FloorplanData.html +2 -2
  49. package/docs/interfaces/FloorplanEntrance.html +7 -7
  50. package/docs/interfaces/FloorplanExtraObject.html +3 -3
  51. package/docs/interfaces/FloorplanExtraObject3D.html +2 -2
  52. package/docs/interfaces/FloorplanFloorData.html +2 -2
  53. package/docs/interfaces/FloorplanImagePosition.html +2 -2
  54. package/docs/interfaces/FloorplanObserver.html +2 -2
  55. package/docs/interfaces/FloorplanOutlineItem.html +2 -2
  56. package/docs/interfaces/FloorplanPosition.html +2 -2
  57. package/docs/interfaces/FloorplanRoomItem.html +6 -6
  58. package/docs/interfaces/FloorplanRoomLabelItem.html +3 -3
  59. package/docs/interfaces/FloorplanServerBounding.html +4 -4
  60. package/docs/interfaces/FloorplanServerComputedData.html +1 -1
  61. package/docs/interfaces/FloorplanServerData.html +2 -2
  62. package/docs/interfaces/FloorplanServerEntrance.html +7 -7
  63. package/docs/interfaces/FloorplanServerFloorData.html +2 -2
  64. package/docs/interfaces/FloorplanServerImagePosition.html +2 -2
  65. package/docs/interfaces/FloorplanServerObserver.html +2 -2
  66. package/docs/interfaces/FloorplanServerOutlineItem.html +2 -2
  67. package/docs/interfaces/FloorplanServerPosition.html +2 -2
  68. package/docs/interfaces/FloorplanServerRoomItem.html +7 -7
  69. package/docs/interfaces/FloorplanServerRoomLabelItem.html +3 -3
  70. package/docs/interfaces/ItemLabelPluginData.html +1 -1
  71. package/docs/interfaces/ItemLabelPluginExportReturnsType.html +1 -1
  72. package/docs/interfaces/ItemLabelPluginParametersType.html +1 -1
  73. package/docs/interfaces/LineJson.html +1 -1
  74. package/docs/interfaces/ModelChassisCompassPluginData.html +1 -1
  75. package/docs/interfaces/ModelChassisCompassPluginExportType.html +1 -1
  76. package/docs/interfaces/ModelChassisCompassPluginParameterType.html +1 -1
  77. package/docs/interfaces/ModelEntryDoorGuidePluginData.html +1 -1
  78. package/docs/interfaces/ModelEntryDoorGuidePluginExportType.html +1 -1
  79. package/docs/interfaces/ModelItemLabelPluginData.html +1 -1
  80. package/docs/interfaces/ModelItemLabelPluginExportReturnsType.html +1 -1
  81. package/docs/interfaces/ModelItemLabelPluginParametersType.html +1 -1
  82. package/docs/interfaces/ModelRoomLabelPluginData.html +1 -1
  83. package/docs/interfaces/ModelTVVideoPluginData.html +1 -1
  84. package/docs/interfaces/ModelTVVideoPluginExportType.html +1 -1
  85. package/docs/interfaces/ModelTVVideoPluginParameterType.html +1 -1
  86. package/docs/interfaces/ModelViewPluginExportType.html +1 -1
  87. package/docs/interfaces/OpenParameter.html +2 -2
  88. package/docs/interfaces/PanoCompassPluginData.html +1 -1
  89. package/docs/interfaces/PanoCompassPluginParameterType.html +1 -1
  90. package/docs/interfaces/PanoCursorRaycasterPluginExportType.html +6 -6
  91. package/docs/interfaces/PanoCursorRaycasterPluginParameterType.html +1 -1
  92. package/docs/interfaces/PanoMeasureParameterType.html +1 -1
  93. package/docs/interfaces/PanoRulerPluginExportType.html +1 -1
  94. package/docs/interfaces/PanoRulerPluginOptions.html +1 -1
  95. package/docs/interfaces/PanoRulerPluginParameterType.html +1 -1
  96. package/docs/interfaces/PanoSpatialTagPluginContentEvent.html +1 -1
  97. package/docs/interfaces/PanoSpatialTagPluginContentReplacement.html +1 -1
  98. package/docs/interfaces/PanoSpatialTagPluginData.html +1 -1
  99. package/docs/interfaces/PanoSpatialTagPluginDataElement.html +1 -1
  100. package/docs/interfaces/PanoSpatialTagPluginExportType.html +1 -1
  101. package/docs/interfaces/PanoSpatialTagPluginOriginElement.html +1 -1
  102. package/docs/interfaces/PanoSpatialTagPluginParameterType.html +1 -1
  103. package/docs/interfaces/PanoSpatialTagPluginPointElement.html +1 -1
  104. package/docs/interfaces/PanoSpatialTagPluginTagElement.html +1 -1
  105. package/docs/interfaces/Point.html +1 -1
  106. package/docs/interfaces/PointJson.html +1 -1
  107. package/docs/interfaces/Room.html +1 -1
  108. package/docs/interfaces/RoomInfo.html +1 -1
  109. package/docs/interfaces/RoomLabel.html +7 -7
  110. package/docs/interfaces/RoomRules.html +1 -1
  111. package/docs/interfaces/Rooms.html +1 -1
  112. package/docs/modules.html +17 -27
  113. package/libs/ItemLabelPlugin/ItemLabelComponent.js +21 -41
  114. package/libs/ModelItemLabelPlugin/ItemLabelComponent.js +16 -36
  115. package/libs/PanoMeasurePlugin/Controller/index.js +4 -2
  116. package/libs/PanoMeasurePlugin/Modules/DeleteDom/_Assets/delete_hover_bg.png.d.ts +1 -1
  117. package/libs/PanoMeasurePlugin/Modules/DeleteDom/_Assets/delete_hover_bg.png.js +1 -1
  118. package/libs/PanoMeasurePlugin/Modules/GuideController.js +2 -2
  119. package/libs/PanoMeasurePlugin/Modules/UIController/HTML.d.ts +0 -4
  120. package/libs/PanoMeasurePlugin/Modules/UIController/HTML.js +66 -55
  121. package/libs/PanoMeasurePlugin/Modules/UIController/MainBtnController.d.ts +0 -3
  122. package/libs/PanoMeasurePlugin/Modules/UIController/MainBtnController.js +51 -73
  123. package/libs/PanoMeasurePlugin/Modules/UIController/Revoke/index.js +7 -4
  124. package/libs/PanoMeasurePlugin/Modules/UIController/index.js +10 -12
  125. package/libs/PanoMeasurePlugin/Modules/UIController/mobileHTML.d.ts +2 -0
  126. package/libs/PanoMeasurePlugin/Modules/UIController/mobileHTML.js +2 -2
  127. package/libs/PanoMeasurePlugin/Modules/UIController/{NewMainBtnController.d.ts → mobileMainBtnController.d.ts} +1 -1
  128. package/libs/PanoMeasurePlugin/Modules/UIController/{NewMainBtnController.js → mobileMainBtnController.js} +4 -4
  129. package/libs/PanoMeasurePlugin/Modules/UIController/style.d.ts +0 -3
  130. package/libs/PanoMeasurePlugin/Modules/UIController/style.js +7 -24
  131. package/libs/PanoMeasurePlugin/Modules/rangePiece/html.d.ts +1 -1
  132. package/libs/PanoMeasurePlugin/Modules/rangePiece/html.js +1 -1
  133. package/libs/PanoMeasurePlugin/Modules/rangePiece/index.d.ts +2 -0
  134. package/libs/PanoMeasurePlugin/Modules/rangePiece/index.js +1 -2
  135. package/libs/PanoMeasurePlugin/typings/data.d.ts +5 -0
  136. package/libs/PanoMeasurePlugin/utils/mouseGroup.d.ts +6 -1
  137. package/libs/PanoMeasurePlugin/utils/mouseGroup.js +55 -7
  138. package/libs/base/BasePlugin.d.ts +100 -0
  139. package/libs/base/BasePlugin.js +31 -0
  140. package/libs/base/BasePluginWithData.d.ts +34 -0
  141. package/libs/base/BasePluginWithData.js +4 -0
  142. package/libs/floorplan/Components/Compass.js +11 -11
  143. package/libs/floorplan/Components/CurrentFloor.js +24 -11
  144. package/libs/floorplan/Components/Main.js +21 -15
  145. package/libs/floorplan/Components/RoomHighlight/Room.js +44 -5
  146. package/libs/floorplan/Components/RoomHighlight/RoomHighlight.js +29 -12
  147. package/libs/floorplan/Components/RoomLabels/RoomLabel.js +164 -15
  148. package/libs/floorplan/Components/RoomLabels/RoomLabels.js +68 -24
  149. package/libs/floorplan/Components/RoomMaterials/RoomMaterial_1.js +1 -0
  150. package/libs/floorplan/Components/RoomMaterials/RoomMaterial_2.js +11 -9
  151. package/libs/floorplan/Components/RuleLabels/RuleItem.js +2 -2
  152. package/libs/floorplan/ModelFloorplanPlugin/Controller.d.ts +70 -78
  153. package/libs/floorplan/ModelFloorplanPlugin/Controller.js +434 -274
  154. package/libs/floorplan/ModelFloorplanPlugin/index.d.ts +5 -7
  155. package/libs/floorplan/ModelFloorplanPlugin/index.js +2 -2
  156. package/libs/floorplan/ModelFloorplanPlugin/typing.d.ts +107 -0
  157. package/libs/floorplan/ModelFloorplanPlugin/{typings/events.type.js → typing.js} +0 -0
  158. package/libs/floorplan/PanoFloorplanRadarPlugin/Components/Camera.js +5 -5
  159. package/libs/floorplan/PanoFloorplanRadarPlugin/Components/Main.js +114 -53
  160. package/libs/floorplan/PanoFloorplanRadarPlugin/Controller.d.ts +23 -14
  161. package/libs/floorplan/PanoFloorplanRadarPlugin/Controller.js +162 -52
  162. package/libs/floorplan/PanoFloorplanRadarPlugin/index.d.ts +5 -6
  163. package/libs/floorplan/PanoFloorplanRadarPlugin/index.js +2 -2
  164. package/libs/floorplan/PanoFloorplanRadarPlugin/typing.d.ts +52 -0
  165. package/libs/floorplan/PanoFloorplanRadarPlugin/typing.js +1 -0
  166. package/libs/floorplan/TopviewFloorplanPlugin/Controller.d.ts +50 -58
  167. package/libs/floorplan/TopviewFloorplanPlugin/Controller.js +320 -174
  168. package/libs/floorplan/TopviewFloorplanPlugin/index.d.ts +5 -3
  169. package/libs/floorplan/TopviewFloorplanPlugin/index.js +2 -2
  170. package/libs/floorplan/TopviewFloorplanPlugin/style.js +1 -1
  171. package/libs/floorplan/TopviewFloorplanPlugin/typing.d.ts +86 -0
  172. package/libs/floorplan/TopviewFloorplanPlugin/typing.js +1 -0
  173. package/{dist/floorplan/ModelFloorplanPlugin → libs/floorplan}/utils/constant.d.ts +10 -3
  174. package/libs/floorplan/{ModelFloorplanPlugin/utils → utils}/constant.js +9 -2
  175. package/{dist/floorplan/ModelFloorplanPlugin → libs/floorplan}/utils/correctFiveState.d.ts +2 -1
  176. package/libs/floorplan/{ModelFloorplanPlugin/utils → utils}/correctFiveState.js +16 -16
  177. package/libs/shared-utils/five/changeMode.d.ts +4 -1
  178. package/libs/shared-utils/five/changeMode.js +34 -13
  179. package/libs/shared-utils/getPxmm.d.ts +8 -0
  180. package/libs/shared-utils/getPxmm.js +25 -20
  181. package/package.json +2 -2
  182. package/dist/floorplan/ModelFloorplanPlugin/typings/events.type.d.ts +0 -23
  183. package/docs/classes/PanoFloorplanRadarPluginController.html +0 -3
  184. package/docs/enums/ModelFloorplanErrorType.html +0 -1
  185. package/docs/interfaces/ModelFloorplanParameterType.html +0 -1
  186. package/docs/interfaces/ModelFloorplanViewEvent.html +0 -5
  187. package/docs/interfaces/PanoFloorplanRadarPluginControllerParameter.html +0 -1
  188. package/docs/interfaces/TopviewFloorplanPluginParameterType.html +0 -19
  189. package/libs/ModelSimulationPlugin/index.d.ts +0 -33
  190. package/libs/ModelSimulationPlugin/index.js +0 -166
  191. package/libs/ModelSimulationPlugin/shaders/fragment.d.ts +0 -2
  192. package/libs/ModelSimulationPlugin/shaders/fragment.js +0 -96
  193. package/libs/ModelSimulationPlugin/shaders/vertex.d.ts +0 -2
  194. package/libs/ModelSimulationPlugin/shaders/vertex.js +0 -23
  195. package/libs/floorplan/ModelFloorplanPlugin/Assets/compass.d.ts +0 -1
  196. package/libs/floorplan/ModelFloorplanPlugin/Assets/compass.js +0 -1
  197. package/libs/floorplan/ModelFloorplanPlugin/Components/Camera.js +0 -120
  198. package/libs/floorplan/ModelFloorplanPlugin/Components/Compass.js +0 -106
  199. package/libs/floorplan/ModelFloorplanPlugin/Components/CurrentFloor/CurrentFloor.js +0 -463
  200. package/libs/floorplan/ModelFloorplanPlugin/Components/Main.js +0 -375
  201. package/libs/floorplan/ModelFloorplanPlugin/Components/RoomLabels/RoomLabel.js +0 -171
  202. package/libs/floorplan/ModelFloorplanPlugin/Components/RoomLabels/RoomLabels.js +0 -265
  203. package/libs/floorplan/ModelFloorplanPlugin/Components/RuleLabels/RuleItem.js +0 -301
  204. package/libs/floorplan/ModelFloorplanPlugin/Components/RuleLabels/RuleLabels.js +0 -219
  205. package/libs/floorplan/ModelFloorplanPlugin/typings/events.type.d.ts +0 -23
  206. package/libs/shared-utils/five/useFivePlugin.d.ts +0 -1
  207. package/libs/shared-utils/five/useFivePlugin.js +0 -8
  208. package/libs/shared-utils/useDebounce.d.ts +0 -8
  209. package/libs/shared-utils/useDebounce.js +0 -22
  210. package/libs/shared-utils/useThrottle.d.ts +0 -8
  211. package/libs/shared-utils/useThrottle.js +0 -25
@@ -1,61 +1,80 @@
1
- import { omit } from '../../shared-utils/filter';
2
- import { Subscribe } from '@realsee/five';
3
- import { FloorplanErrorType, FIVE_CAMERA_DEFAULT_FOV, SHOW_ANIME_DURATION } from './utils/constant';
4
1
  import to from '../../shared-utils/to';
2
+ import equal from '../../shared-utils/equal';
5
3
  import Main from '../Components/Main';
6
4
  import formatData from '../utils/formatData';
7
- import equal from '../../shared-utils/equal';
5
+ import { CAMERA_IMAGE } from '../Assets/camera';
6
+ import { omit } from '../../shared-utils/filter';
8
7
  import getPxmm from '../../shared-utils/getPxmm';
9
- import correctFiveState, { checkShowState } from './utils/correctFiveState';
8
+ import { FLOOR_PLAN_ATTACHED_TO } from '../constant';
9
+ import * as BasePlugin from '../../base/BasePluginWithData';
10
+ import correctFiveState, { checkShowState } from '../utils/correctFiveState';
10
11
  import changeModelCanvasOpacity from '../../shared-utils/changeModelCanvasOpacity';
11
- export const MODEL_FLOORPLAN_PLUGIN_NAME = 'modelFloorplanPlugin';
12
- export default class ModelFloorplanPluginController {
12
+ import { FloorplanErrorType, FIVE_CAMERA_DEFAULT_FOV, SHOW_ANIME_DURATION } from '../utils/constant';
13
+ /** 当前 five 的相机视角是否满足户型图自动隐藏条件
14
+ *
15
+ * @description 水平旋转角大于正负 5 度 || 俯仰角度大于 5 度
16
+ *
17
+ */
18
+ function shouldFloorplanHideWithPose(pose) {
19
+ const { latitude, longitude } = pose;
20
+ const latitudeHide = Math.abs(latitude - Math.PI / 2) > (5 * Math.PI) / 180;
21
+ const longitudeHide = longitude > 5 * (Math.PI / 180) && longitude < 355 * (Math.PI / 180);
22
+ return latitudeHide || longitudeHide;
23
+ }
24
+ /** 当前 five 的相机视角是否满足户型图自动展示隐藏条件
25
+ *
26
+ * @description 水平旋转角正负 30 度 && 俯仰角度小于 10 度
27
+ *
28
+ */
29
+ function shouldFloorplanShowWithPose(pose) {
30
+ const { latitude, longitude } = pose;
31
+ const latitudeVisible = Math.abs(latitude - Math.PI / 2) < (10 * Math.PI) / 180;
32
+ const longitudeVisible = longitude < 30 * (Math.PI / 180) || longitude > 330 * (Math.PI / 180);
33
+ return latitudeVisible && longitudeVisible;
34
+ }
35
+ export class Controller extends BasePlugin.Controller {
13
36
  constructor(five, params) {
14
37
  var _a;
38
+ super(five);
39
+ // =============== public properties =================
15
40
  Object.defineProperty(this, "name", {
16
41
  enumerable: true,
17
42
  configurable: true,
18
43
  writable: true,
19
- value: MODEL_FLOORPLAN_PLUGIN_NAME
44
+ value: 'modelFloorplanPlugin'
20
45
  });
21
- /** 用于绑定事件钩子 */
22
- Object.defineProperty(this, "hooks", {
46
+ Object.defineProperty(this, "state", {
23
47
  enumerable: true,
24
48
  configurable: true,
25
49
  writable: true,
26
50
  value: void 0
27
51
  });
28
- /** 展示状态 */
29
- Object.defineProperty(this, "visible", {
52
+ // =============== private properties =================
53
+ Object.defineProperty(this, "data", {
30
54
  enumerable: true,
31
55
  configurable: true,
32
56
  writable: true,
33
- value: false
34
- });
35
- /** 户型图大小 */
36
- Object.defineProperty(this, "size", {
37
- enumerable: true,
38
- configurable: true,
39
- writable: true,
40
- value: { width: 0, height: 0 }
57
+ value: void 0
41
58
  });
42
- Object.defineProperty(this, "app", {
59
+ /** 展示户型图时,需要正确的状态 */
60
+ Object.defineProperty(this, "showState", {
43
61
  enumerable: true,
44
62
  configurable: true,
45
63
  writable: true,
46
- value: undefined
64
+ value: void 0
47
65
  });
48
- Object.defineProperty(this, "pxmm", {
66
+ /** show 动画的公共 Promise */
67
+ Object.defineProperty(this, "showPromise", {
49
68
  enumerable: true,
50
69
  configurable: true,
51
70
  writable: true,
52
- value: 0
71
+ value: void 0
53
72
  });
54
- Object.defineProperty(this, "five", {
73
+ Object.defineProperty(this, "app", {
55
74
  enumerable: true,
56
75
  configurable: true,
57
76
  writable: true,
58
- value: void 0
77
+ value: undefined
59
78
  });
60
79
  Object.defineProperty(this, "panoIndex", {
61
80
  enumerable: true,
@@ -69,85 +88,118 @@ export default class ModelFloorplanPluginController {
69
88
  writable: true,
70
89
  value: 0
71
90
  });
72
- Object.defineProperty(this, "configs", {
73
- enumerable: true,
74
- configurable: true,
75
- writable: true,
76
- value: {}
77
- });
78
- Object.defineProperty(this, "lastPanoramaLongitude", {
79
- enumerable: true,
80
- configurable: true,
81
- writable: true,
82
- value: 0
83
- });
84
91
  Object.defineProperty(this, "selector", {
85
92
  enumerable: true,
86
93
  configurable: true,
87
94
  writable: true,
88
95
  value: void 0
89
96
  });
90
- Object.defineProperty(this, "floorplanData", {
97
+ /** 公共 Promise 的 reject 方法 */
98
+ Object.defineProperty(this, "showRejection", {
91
99
  enumerable: true,
92
100
  configurable: true,
93
101
  writable: true,
94
102
  value: void 0
95
103
  });
104
+ /** 户型图父容器 */
96
105
  Object.defineProperty(this, "wrapper", {
97
106
  enumerable: true,
98
107
  configurable: true,
99
108
  writable: true,
100
109
  value: void 0
101
110
  });
111
+ /** 户型图主容器 */
102
112
  Object.defineProperty(this, "container", {
103
113
  enumerable: true,
104
114
  configurable: true,
105
115
  writable: true,
106
116
  value: document.createElement('div')
107
117
  });
108
- Object.defineProperty(this, "showState", {
118
+ /** 展示户型图图前,Five 的 Panorama Longitude */
119
+ Object.defineProperty(this, "lastPanoramaLongitude", {
109
120
  enumerable: true,
110
121
  configurable: true,
111
122
  writable: true,
112
- value: void 0
123
+ value: 0
113
124
  });
114
- /** 记录上次 show 的参数,如果不一致,需要 reject 掉正在进行的 showPromise */
115
- Object.defineProperty(this, "ModelFloorplanPluginsShowOpts", {
125
+ /** 户型图大小 */
126
+ Object.defineProperty(this, "size", {
116
127
  enumerable: true,
117
128
  configurable: true,
118
129
  writable: true,
119
- value: void 0
130
+ value: { width: 0, height: 0 }
120
131
  });
121
- Object.defineProperty(this, "showPromise", {
132
+ /** 是否已经执行过事件监听 */
133
+ Object.defineProperty(this, "hasAddedEventListener", {
122
134
  enumerable: true,
123
135
  configurable: true,
124
136
  writable: true,
125
- value: void 0
137
+ value: false
126
138
  });
127
- Object.defineProperty(this, "showRejection", {
139
+ /** 上一次隐藏是否是用户调用了 hide 导致的 */
140
+ Object.defineProperty(this, "isHiddenByHideFunc", {
128
141
  enumerable: true,
129
142
  configurable: true,
130
143
  writable: true,
131
- value: void 0
144
+ value: false
132
145
  });
146
+ /** 销毁插件 */
133
147
  Object.defineProperty(this, "dispose", {
134
148
  enumerable: true,
135
149
  configurable: true,
136
150
  writable: true,
137
151
  value: () => {
138
152
  var _a, _b;
139
- const five = this.five;
140
- this.hide();
153
+ this.removeEventListener();
141
154
  (_a = this.app) === null || _a === void 0 ? void 0 : _a.$destroy();
155
+ this.app = undefined;
142
156
  (_b = this.container) === null || _b === void 0 ? void 0 : _b.remove();
143
- five.off('modelLoaded', this.handleModelLoaded);
144
- five.off('modeChange', this.handleModeChange);
145
- five.off('panGesture', this.handlePanGesture);
146
- five.off('panoArrived', this.handlePanoArrived);
147
- five.off('wantsChangeMode', this.handleWantsChangeMode);
148
- five.off('wantsInteriaPan', this.handleWantsInteriaPan);
149
- five.off('wantsTapGesture', this.handleWantsTapGesture);
150
- five.off('modelShownFloorChange', this.onModelShownFloorChange);
157
+ this.data = undefined;
158
+ this.wrapper = undefined;
159
+ this.selector = undefined;
160
+ this.hooks.emit('dispose');
161
+ }
162
+ });
163
+ /** 展示户型图
164
+ * 1. show 函数大部分情况下需要耗时
165
+ * 2. 如果当前已经在展示中,将不会触发任何事件
166
+ * 3. 如果展示过程被中断,将抛出错误
167
+ * 4. 多次调用 show 方法,只会触发一次 showAnimationEnded 事件,但是展示结果会取决于最后一次调用参数
168
+ * 5. 如果多次调用 show 方法,参数与上次参数不一致时,上次 show Promise 会被 reject
169
+ * @param opts.floorIndex 楼层
170
+ * @param opts.modelOpacity 模型透明度
171
+ * @param opts.immediately 是否立即展示
172
+ * @param opts.isAutoShow 是否是自动展示
173
+ * @param opts.userAction 是否是用户行为
174
+ */
175
+ Object.defineProperty(this, "show", {
176
+ enumerable: true,
177
+ configurable: true,
178
+ writable: true,
179
+ value: async (options = {}) => {
180
+ if (!this.state.enabled)
181
+ return;
182
+ // 已经展示完成了,不做任何操作
183
+ if (!this.showPromise && this.state.visible)
184
+ return;
185
+ const userAction = options.userAction !== undefined ? options.userAction : true;
186
+ this.updateState({ visible: true }, userAction);
187
+ this._show(options);
188
+ }
189
+ });
190
+ /** 隐藏户型图 */
191
+ Object.defineProperty(this, "hide", {
192
+ enumerable: true,
193
+ configurable: true,
194
+ writable: true,
195
+ value: async (options = {}) => {
196
+ if (!this.state.enabled)
197
+ return;
198
+ this.isHiddenByHideFunc = true;
199
+ if (this.state.visible === false)
200
+ return;
201
+ this.updateState({ visible: false }, options.userAction || true);
202
+ this._hide(options);
151
203
  }
152
204
  });
153
205
  /** 更新户型图大小 */
@@ -156,166 +208,172 @@ export default class ModelFloorplanPluginController {
156
208
  configurable: true,
157
209
  writable: true,
158
210
  value: () => {
159
- if (!this.floorplanData)
211
+ if (!this.data)
160
212
  return;
161
213
  if (!checkShowState(this.five, this.showState))
162
214
  return;
163
215
  if (!this.container || !this.wrapper)
164
216
  return;
165
217
  // 计算户型图展示大小
166
- const { min, max } = this.floorplanData.bounding;
218
+ const { min, max } = this.data.bounding;
167
219
  const width = max.x - min.x;
168
220
  const height = max.y - min.y;
169
221
  // 每毫米对应的 px 值
170
- const options = this.configs.attachedTo ? { attachedTo: this.configs.attachedTo } : undefined;
222
+ const options = this.state.config.attachedTo ? { attachedTo: this.state.config.attachedTo } : undefined;
171
223
  const pxmm = getPxmm(this.five, this.wrapper, this.floorIndex, options);
172
224
  const _width = Math.ceil(width * pxmm);
173
225
  const _height = Math.ceil(height * pxmm);
174
226
  if (this.size.width === _width && this.size.height === _height)
175
227
  return;
176
- this.pxmm = pxmm;
177
- this.size = { width: _width, height: _height };
178
228
  this.container.style.width = _width + 'px';
179
229
  this.container.style.height = _height + 'px';
230
+ this.size = { width: _width, height: _height };
180
231
  }
181
232
  });
182
- /** 展示户型图
183
- * 1. show 函数大部分情况下需要耗时
184
- * 2. 如果当前已经在展示中,将不会触发任何事件
185
- * 3. 如果展示过程被中断,将抛出错误
186
- * 4. 多次调用 show 方法,只会触发一次 showAnimationEnded 事件,但是展示结果会取决于最后一次调用参数
187
- * 5. 如果多次调用 show 方法,参数与上次参数不一致时,上次 show Promise 会被 reject
188
- * @param opts.floorIndex 楼层
189
- * @param opts.modelOpacity 模型透明度
190
- * @param opts.immediately 是否立即展示
191
- * @param opts.isAutoShow 是否是自动展示
192
- */
193
- Object.defineProperty(this, "show", {
233
+ Object.defineProperty(this, "_disable", {
194
234
  enumerable: true,
195
235
  configurable: true,
196
236
  writable: true,
197
- value: async (opts) => {
198
- var _a, _b;
199
- // 已经在展示中了
200
- if (!this.showPromise && this.visible)
201
- return true;
237
+ value: (options) => {
238
+ var _a, _b, _c;
239
+ const { userAction } = options;
240
+ this.hooks.emit('disable', { userAction });
241
+ // ===== 处理展示过程中 disable =====
242
+ (_a = this.showRejection) === null || _a === void 0 ? void 0 : _a.call(this, FloorplanErrorType.BreakOffByDisable);
243
+ this.showPromise = undefined;
244
+ (_b = this.app) === null || _b === void 0 ? void 0 : _b.$destroy();
245
+ this.app = undefined;
246
+ (_c = this.container) === null || _c === void 0 ? void 0 : _c.remove();
247
+ this.removeEventListener();
248
+ }
249
+ });
250
+ Object.defineProperty(this, "_enable", {
251
+ enumerable: true,
252
+ configurable: true,
253
+ writable: true,
254
+ value: (options) => {
255
+ const { userAction } = options;
256
+ this.addEventListener();
257
+ if (!this.wrapper)
258
+ return;
259
+ this.wrapper.append(this.container);
260
+ this.hooks.emit('enable', { userAction });
261
+ if (this.state.visible)
262
+ this._show({ userAction });
263
+ }
264
+ });
265
+ Object.defineProperty(this, "_show", {
266
+ enumerable: true,
267
+ configurable: true,
268
+ writable: true,
269
+ value: async (options) => {
270
+ var _a;
271
+ if (!this.state.enabled)
272
+ return;
202
273
  if (!((_a = this.five.model) === null || _a === void 0 ? void 0 : _a.loaded))
203
274
  throw new Error(FloorplanErrorType.ModelNotLoaded);
204
- if (!this.floorplanData)
275
+ if (!this.data)
205
276
  throw new Error(FloorplanErrorType.DataNotLoaded);
206
- this.visible = true;
207
- if (this.showPromise) {
208
- const sameWithLastOpts = equal(opts, this.ModelFloorplanPluginsShowOpts, { deep: false });
209
- if (!!this.showPromise && sameWithLastOpts)
210
- return this.showPromise;
211
- if (!!this.showPromise && !sameWithLastOpts)
212
- (_b = this.showRejection) === null || _b === void 0 ? void 0 : _b.call(this, FloorplanErrorType.DifferentShowParams);
213
- }
214
- this.ModelFloorplanPluginsShowOpts = opts;
277
+ this.isHiddenByHideFunc = false;
278
+ // ===== 参数合并 =====
279
+ const baseShowOpts = {
280
+ floorIndex: this.floorIndex,
281
+ modelOpacity: this.state.config.modelOpacity,
282
+ immediately: false,
283
+ isAutoShow: false,
284
+ userAction: true,
285
+ };
286
+ const mergedOptions = Object.assign(Object.assign({}, baseShowOpts), options);
215
287
  const getShowPromise = async () => {
216
- var _a, _b;
288
+ this.hooks.emit('show', { userAction: mergedOptions.userAction, auto: mergedOptions.isAutoShow });
217
289
  let hasRejected = false;
218
290
  let externalErrorMsg;
219
291
  this.showRejection = (errorMsg) => {
220
292
  hasRejected = true;
221
293
  externalErrorMsg = errorMsg;
222
294
  };
223
- const [correctError] = await to(correctFiveState(this.five, this.showState, opts === null || opts === void 0 ? void 0 : opts.userAction));
295
+ const [correctError] = await to(correctFiveState(this.five, this.showState, mergedOptions.userAction));
224
296
  if (correctError)
225
297
  throw correctError;
226
- // 异步结束要判断当前是不是被中断了,是不是调用了隐藏
298
+ // 异步结束要判断当前是不是被中断了
227
299
  if (hasRejected)
228
300
  throw externalErrorMsg ? new Error(externalErrorMsg) : new Error(FloorplanErrorType.UnknownError);
229
- if (!this.visible)
230
- throw new Error(FloorplanErrorType.UnknownError);
231
- // 更新户型图状态
232
- this.visible = true;
233
301
  // 更新户型图大小
234
302
  this.updateSize();
235
303
  // 高亮当前楼层,有两个目的
236
304
  // 1. 点击模型时,可以跳转到当前楼层的点位上
237
305
  // 2. 当前楼层比较小时,户型图也比较小,如果展示全部楼层,会展示户型图外有一圈模型
238
- if (opts === null || opts === void 0 ? void 0 : opts.floorIndex)
239
- this.floorIndex = opts.floorIndex;
306
+ this.floorIndex = mergedOptions.floorIndex;
240
307
  this.five.model.show(this.floorIndex);
241
308
  // 模型消失, 渲染户型图
242
- const modelOpacity = (_b = (_a = opts === null || opts === void 0 ? void 0 : opts.modelOpacity) !== null && _a !== void 0 ? _a : this.configs.modelOpacity) !== null && _b !== void 0 ? _b : 1;
243
- const renderDuration = (opts === null || opts === void 0 ? void 0 : opts.immediately) ? 0 : SHOW_ANIME_DURATION;
309
+ const modelOpacity = mergedOptions.modelOpacity;
310
+ const renderDuration = mergedOptions.immediately ? 0 : SHOW_ANIME_DURATION;
244
311
  changeModelCanvasOpacity(this.five, modelOpacity, renderDuration);
245
312
  this.render(renderDuration);
246
- // 展示之后的事件监听
247
- this.five.on('wantsGesture', this.handleWantsGesture);
248
- this.five.on('wantsTapGesture', this.handleWantsTapGesture);
249
- return true;
250
313
  };
251
- const showPromise = getShowPromise()
314
+ this.showPromise = getShowPromise()
252
315
  .then(() => {
253
- var _a;
254
- this.hooks.emit('showAnimationEnded', { auto: !!(opts === null || opts === void 0 ? void 0 : opts.isAutoShow), userAction: (_a = opts === null || opts === void 0 ? void 0 : opts.userAction) !== null && _a !== void 0 ? _a : true });
255
- return true;
316
+ this.hooks.emit('showAnimationEnded', {
317
+ auto: mergedOptions.isAutoShow,
318
+ userAction: mergedOptions.userAction,
319
+ });
256
320
  })
257
321
  .catch((error) => {
322
+ this.updateState({ visible: false }, mergedOptions.userAction);
258
323
  // 自动展示的报错内部处理
259
- if (opts === null || opts === void 0 ? void 0 : opts.isAutoShow)
260
- return false;
261
- if (!(error instanceof Error))
262
- return false;
324
+ if (mergedOptions.isAutoShow)
325
+ return;
263
326
  // 非自动展示的报错继续向外抛出
264
- throw error;
327
+ if (error instanceof Error)
328
+ throw error;
265
329
  })
266
330
  .finally(() => {
267
331
  this.showPromise = undefined;
268
332
  this.showRejection = undefined;
269
333
  });
270
- this.showPromise = showPromise;
271
- return showPromise;
334
+ return this.showPromise;
272
335
  }
273
336
  });
274
- /** 隐藏户型图 */
275
- Object.defineProperty(this, "hide", {
337
+ Object.defineProperty(this, "_hide", {
276
338
  enumerable: true,
277
339
  configurable: true,
278
340
  writable: true,
279
341
  value: (options) => {
280
- var _a, _b;
281
- if (this.size.width === 0)
282
- return true;
283
- if (this.visible === false)
284
- return true;
285
- const isAutoHide = !!(options === null || options === void 0 ? void 0 : options.isAutoHide);
286
- this.five.off('wantsGesture', this.handleWantsGesture);
287
- this.five.off('wantsTapGesture', this.handleWantsTapGesture);
288
- this.visible = false;
342
+ var _a;
343
+ // ===== 处理展示过程中 hide =====
289
344
  (_a = this.showRejection) === null || _a === void 0 ? void 0 : _a.call(this, FloorplanErrorType.BreakOffByHide);
345
+ this.showPromise = undefined;
346
+ // ===== 合并参数 =====
347
+ const baseOptions = {
348
+ userAction: true,
349
+ isAutoHide: false,
350
+ };
351
+ const mergedOptions = Object.assign(Object.assign({}, baseOptions), options);
290
352
  changeModelCanvasOpacity(this.five, 1, 0);
353
+ this.hooks.emit('hide', { auto: mergedOptions.isAutoHide, userAction: mergedOptions.userAction });
291
354
  this.render();
292
- this.hooks.emit('hide', { auto: isAutoHide, userAction: (_b = options === null || options === void 0 ? void 0 : options.userAction) !== null && _b !== void 0 ? _b : true });
293
- return true;
294
355
  }
295
356
  });
296
- /** 模型楼层高亮改变时,自动进行楼层切换 */
297
- Object.defineProperty(this, "onModelShownFloorChange", {
357
+ Object.defineProperty(this, "handleClick", {
298
358
  enumerable: true,
299
359
  configurable: true,
300
360
  writable: true,
301
- value: (shownFloor) => {
302
- if (this.floorIndex === shownFloor)
303
- return;
304
- if (shownFloor === null) {
305
- const panoIndex = this.five.getCurrentState().panoIndex;
306
- this.floorIndex = this.five.work.observers[panoIndex].floorIndex;
361
+ value: () => {
362
+ if (!this.state.visible)
307
363
  return;
308
- }
309
- this.floorIndex = shownFloor;
310
- this.updateSize();
311
- this.render();
364
+ const preventDefault = this.hooks.emit('click');
365
+ if (preventDefault)
366
+ return false;
312
367
  }
313
368
  });
314
- Object.defineProperty(this, "handleModelLoaded", {
369
+ /** modelLoaded 之后自动执行 append container 操作 */
370
+ Object.defineProperty(this, "onFiveModelLoaded", {
315
371
  enumerable: true,
316
372
  configurable: true,
317
373
  writable: true,
318
374
  value: () => {
375
+ if (this.state.enabled === false)
376
+ return;
319
377
  if (this.wrapper)
320
378
  return;
321
379
  if (!this.selector)
@@ -327,54 +385,45 @@ export default class ModelFloorplanPluginController {
327
385
  wrapper.append(this.container);
328
386
  }
329
387
  });
330
- Object.defineProperty(this, "handleClick", {
331
- enumerable: true,
332
- configurable: true,
333
- writable: true,
334
- value: () => {
335
- if (!this.visible)
336
- return;
337
- const prevented = this.hooks.emit('click');
338
- if (prevented)
339
- return false;
340
- }
341
- });
342
- Object.defineProperty(this, "handleWantsTapGesture", {
343
- enumerable: true,
344
- configurable: true,
345
- writable: true,
346
- value: () => this.handleClick()
347
- });
348
- /** 从 Panorama 切换到其他模态时,记录当前的相机水平视角 */
349
- Object.defineProperty(this, "handleWantsChangeMode", {
388
+ /** 更改模型时,自动隐藏户型图 */
389
+ Object.defineProperty(this, "onFiveModeChange", {
350
390
  enumerable: true,
351
391
  configurable: true,
352
392
  writable: true,
353
393
  value: (mode) => {
354
- if (mode !== 'Panorama') {
355
- this.lastPanoramaLongitude = this.five.getCurrentState().longitude;
394
+ // 目前 Five modeChange 事件没有暴露 userAction,先拿 false 苟着
395
+ if (mode !== this.showState.mode) {
396
+ this.updateState({ visible: false }, false);
397
+ this._hide({ userAction: false });
356
398
  }
357
- if (mode !== 'Floorplan')
358
- this.hide();
359
399
  }
360
400
  });
361
- /** 监听模型态变化,只有在模型态才进行手势动作监听 */
362
- Object.defineProperty(this, "handleModeChange", {
401
+ /** 惯性结束后,判断能否自动展示户型图 */
402
+ Object.defineProperty(this, "onFiveInteriaPan", {
363
403
  enumerable: true,
364
404
  configurable: true,
365
405
  writable: true,
366
- value: (mode) => {
367
- if (mode === 'Floorplan') {
368
- this.five.on('panGesture', this.handlePanGesture);
369
- }
370
- else {
371
- this.hide();
372
- this.five.off('panGesture', this.handlePanGesture);
406
+ value: (_, isFinal) => {
407
+ if (!isFinal)
408
+ return;
409
+ if (this.state.config.autoShowEnable === false)
410
+ return;
411
+ // 如果用户调用 hide 方法手动隐藏户型图,则不允许自动展示
412
+ if (this.isHiddenByHideFunc)
413
+ return;
414
+ const fiveCurrentState = this.five.getCurrentState();
415
+ if (fiveCurrentState.mode !== 'Floorplan')
416
+ return;
417
+ if (this.state.visible)
418
+ return;
419
+ if (shouldFloorplanShowWithPose(fiveCurrentState)) {
420
+ this.updateState({ visible: true }, true);
421
+ this._show({ isAutoShow: true });
373
422
  }
374
423
  }
375
424
  });
376
425
  /** panoIndex 改变时,更新 floorIndex */
377
- Object.defineProperty(this, "handlePanoArrived", {
426
+ Object.defineProperty(this, "onFivePanoArrived", {
378
427
  enumerable: true,
379
428
  configurable: true,
380
429
  writable: true,
@@ -386,149 +435,260 @@ export default class ModelFloorplanPluginController {
386
435
  this.floorIndex = this.five.work.observers[index].floorIndex;
387
436
  }
388
437
  });
389
- /** 当户型图正在展示中的时候禁用惯性 */
390
- Object.defineProperty(this, "handleWantsInteriaPan", {
438
+ /** cameraUpdate 时判断户型图是否应该自动隐藏 */
439
+ Object.defineProperty(this, "onFiveCameraUpdate", {
391
440
  enumerable: true,
392
441
  configurable: true,
393
442
  writable: true,
394
- value: () => {
395
- if (this.visible)
396
- return false;
443
+ value: (_, userAction) => {
444
+ if (!this.state.visible)
445
+ return;
446
+ // 展示过程中不处理自动隐藏逻辑
447
+ if (this.showPromise)
448
+ return;
449
+ const fiveCurrentState = this.five.getCurrentState();
450
+ if (shouldFloorplanHideWithPose(fiveCurrentState)) {
451
+ this.updateState({ visible: false }, userAction);
452
+ this._hide({ userAction });
453
+ }
397
454
  }
398
455
  });
399
456
  /** 在户型图展示时阻止多指操作, 阻止鼠标放大 */
400
- Object.defineProperty(this, "handleWantsGesture", {
457
+ Object.defineProperty(this, "onFiveWantsGesture", {
401
458
  enumerable: true,
402
459
  configurable: true,
403
460
  writable: true,
404
461
  value: (type, pointers) => {
405
- if (!this.visible)
462
+ if (!this.state.visible)
406
463
  return;
464
+ // 阻止多指操作
407
465
  if (pointers.length > 1)
408
466
  return false;
467
+ // 阻止鼠标滚轮行为
409
468
  if (type === 'mouseWheel')
410
469
  return false;
411
470
  }
412
471
  });
413
- /** 监听三维模型滑动
414
- * 1. 在三维模型转动结束时,如果达到设置的阈值,会自动切换到户型图
415
- * 2. 如何户型图已经展示,滑动时关闭户型图
416
- */
417
- Object.defineProperty(this, "handlePanGesture", {
472
+ /** 户型图展示中,转动三维模型,结束时应该自动修复模型状态 */
473
+ Object.defineProperty(this, "onFiveWantsPanGesture", {
418
474
  enumerable: true,
419
475
  configurable: true,
420
476
  writable: true,
421
- value: async ({ latitude, longitude }, isFinal) => {
477
+ value: (_, isFinal) => {
422
478
  if (this.five.getCurrentState().mode !== 'Floorplan')
423
479
  return;
424
- if (this.configs.autoShowEnable === false)
480
+ if (this.state.config.autoShowEnable === false)
425
481
  return;
426
- // 如果操作结束后,户型图还在展示中,初始化模型状态
427
- if (isFinal && this.visible)
428
- return this.five.setState(this.showState, true);
429
- // 满足消失的条件:
430
- // 水平旋转角大于正负 5 度 || 俯仰角度大于 5 度
431
- const latitudeHide = Math.abs(latitude - Math.PI / 2) > (5 * Math.PI) / 180;
432
- const longitudeHide = longitude > 5 * (Math.PI / 180) && longitude < 355 * (Math.PI / 180);
433
- const canHide = latitudeHide || longitudeHide;
434
- if (this.visible && canHide)
435
- return this.hide({ isAutoHide: true });
436
- if (this.five.camera.fov / FIVE_CAMERA_DEFAULT_FOV < 0.8)
482
+ if (isFinal && this.state.visible) {
483
+ this.five.updateCamera(this.showState, 0);
484
+ // 禁用掉 isFinal 的 panGesture 行为
485
+ // 因为 panGesture 中包含对相机的处理,会跟回调事件中的处理逻辑冲突
486
+ // 此行为也会禁用 pan 结束后的惯性处理
487
+ return false;
488
+ }
489
+ }
490
+ });
491
+ /** 阻止点击分间走点 */
492
+ Object.defineProperty(this, "onFiveWantsTapGesture", {
493
+ enumerable: true,
494
+ configurable: true,
495
+ writable: true,
496
+ value: () => this.handleClick()
497
+ });
498
+ /** 从 Panorama 切换到其他模态时,记录当前的相机水平视角 */
499
+ Object.defineProperty(this, "onFiveWantsChangeMode", {
500
+ enumerable: true,
501
+ configurable: true,
502
+ writable: true,
503
+ value: (mode, prevMode) => {
504
+ if (prevMode === 'Panorama' && mode === 'Floorplan') {
505
+ this.lastPanoramaLongitude = this.five.getCurrentState().longitude;
506
+ }
507
+ // if (mode !== 'Floorplan') this.hide()
508
+ }
509
+ });
510
+ /** 模型楼层高亮改变时,自动进行楼层切换 */
511
+ Object.defineProperty(this, "onModelShownFloorChange", {
512
+ enumerable: true,
513
+ configurable: true,
514
+ writable: true,
515
+ value: (shownFloor) => {
516
+ if (this.floorIndex === shownFloor)
437
517
  return;
438
- // 户型图展示条件:
439
- // 水平旋转角正负 30 度 && 俯仰角度小于 10 度
440
- const latitudeVisible = Math.abs(latitude - Math.PI / 2) < (10 * Math.PI) / 180;
441
- const longitudeVisible = longitude < 30 * (Math.PI / 180) || longitude > 330 * (Math.PI / 180);
442
- if (isFinal && !this.visible && latitudeVisible && longitudeVisible) {
443
- // 当手指离开时需要等惯性结束之后在进行判断
444
- const handleInteriaPan = async (any, isFinal) => {
445
- if (!isFinal)
446
- return;
447
- this.five.off('interiaPan', handleInteriaPan);
448
- await this.show({ isAutoShow: true });
449
- };
450
- this.five.on('interiaPan', handleInteriaPan);
518
+ if (shownFloor === null) {
519
+ const panoIndex = this.five.getCurrentState().panoIndex;
520
+ this.floorIndex = this.five.work.observers[panoIndex].floorIndex;
451
521
  return;
452
522
  }
523
+ this.floorIndex = shownFloor;
524
+ this.updateSize();
525
+ this.render();
453
526
  }
454
527
  });
455
- this.five = five;
456
- this.hooks = new Subscribe();
457
- this.selector = params.selector;
458
- this.configs = omit(params, ['selector']);
459
- this.showState = { longitude: 0, latitude: Math.PI / 2, fov: FIVE_CAMERA_DEFAULT_FOV / ((_a = params === null || params === void 0 ? void 0 : params.scale) !== null && _a !== void 0 ? _a : 1) };
460
- // 设置 container 样式
461
- this.container.classList.add('floorplan-plugin');
462
- Object.assign(this.container.style, {
463
- position: 'absolute',
464
- left: '50%',
465
- top: '50%',
466
- transform: 'translate(-50%, -50%)',
467
- zIndex: 10,
468
- pointerEvents: 'none'
469
- });
470
- this.five.addExtraElement(this.container);
528
+ if (params === null || params === void 0 ? void 0 : params.selector) {
529
+ this.selector = params.selector;
530
+ console.warn('不推荐继续使用 params.selector 配置父容器,请使用 appendTo 方法');
531
+ }
532
+ // =============== init Show State ===============
533
+ this.showState = {
534
+ mode: 'Floorplan',
535
+ longitude: 0,
536
+ latitude: Math.PI / 2,
537
+ fov: FIVE_CAMERA_DEFAULT_FOV / ((_a = params === null || params === void 0 ? void 0 : params.scale) !== null && _a !== void 0 ? _a : 1),
538
+ };
539
+ // =============== init State ===============
540
+ const baseConfig = {
541
+ northDesc: '',
542
+ modelOpacity: 1,
543
+ hoverEnable: true,
544
+ compassEnable: true,
545
+ autoShowEnable: true,
546
+ ruleLabelsEnable: true,
547
+ roomLabelsEnable: true,
548
+ cameraImageUrl: CAMERA_IMAGE,
549
+ attachedTo: FLOOR_PLAN_ATTACHED_TO.BOUNDING_CENTER,
550
+ getLabelElement: undefined,
551
+ adaptiveRoomLabelVisibleEnable: true,
552
+ };
553
+ const paramsConfig = params ? omit(params, ['selector', 'scale']) : {};
554
+ const config = Object.assign(Object.assign({}, baseConfig), paramsConfig);
555
+ this.state = {
556
+ enabled: true,
557
+ visible: false,
558
+ config,
559
+ };
560
+ // =============== init Container ===============
561
+ this.initContainer();
562
+ // =============== init Listener ===============
563
+ // 注意插件声明周期内只监听一次的事件不放在 addEventListener 里面
471
564
  // 如果初始化的时候模型已经加载完毕了,就不用再等 modelLoaded
472
- this.five.model.loaded ? this.handleModelLoaded() : five.once('modelLoaded', this.handleModelLoaded);
565
+ five.model.loaded ? this.onFiveModelLoaded() : five.once('modelLoaded', this.onFiveModelLoaded);
473
566
  five.once('dispose', this.dispose);
474
- five.on('modeChange', this.handleModeChange);
475
- five.on('panoArrived', this.handlePanoArrived);
476
- five.on('wantsChangeMode', this.handleWantsChangeMode);
477
- five.on('wantsInteriaPan', this.handleWantsInteriaPan);
478
- five.on('modelShownFloorChange', this.onModelShownFloorChange);
567
+ this.addEventListener();
479
568
  }
480
- /** 加载户型图数据 */
481
- async load(data) {
482
- const copyData = JSON.parse(JSON.stringify(data));
483
- this.floorplanData = await formatData(copyData);
569
+ async load(serverData, state, userAction = true) {
570
+ function isPluginServerData(serverData) {
571
+ return Object.prototype.hasOwnProperty.apply(serverData, ['version']);
572
+ }
573
+ const _data = serverData;
574
+ if (_data && !_data.version)
575
+ console.warn('传入 serverData.data 的方式后续可能不再支持,请把 serverData 整体传入 load 函数');
576
+ const copyData = JSON.parse(JSON.stringify(serverData));
577
+ const _serverData = isPluginServerData(copyData) ? copyData.data : copyData;
578
+ const prevData = this.data;
579
+ this.data = await formatData(_serverData);
580
+ this.hooks.emit('dataLoaded', this.data);
581
+ this.hooks.emit('dataChange', this.data, prevData);
582
+ if (state)
583
+ this.updateState(state, userAction);
484
584
  this.render();
485
585
  }
486
586
  /** 把插件的渲染DOM插入到对应的容器中去 */
487
587
  appendTo(wrapper) {
488
588
  this.wrapper = wrapper;
589
+ // 插件 disabled 时,只是不执行副作用,但是 wrapper 还是要赋值的,不然 enable 的时候找不到父容器
590
+ if (!this.state.enabled)
591
+ return;
489
592
  wrapper.appendChild(this.container);
593
+ this.render();
490
594
  return this;
491
595
  }
492
- /** 更改户型图楼层 */
493
- changeFloor(floorIndex) {
494
- this.five.model.show(floorIndex);
596
+ /** 启用插件 */
597
+ enable(options = {}) {
598
+ if (this.state.enabled)
599
+ return;
600
+ const userAction = options.userAction !== undefined ? options.userAction : true;
601
+ this.updateState({ enabled: true }, options.userAction || userAction);
602
+ this._enable({ userAction });
495
603
  }
496
- changeConfigs(params) {
497
- Object.assign(this.configs, params);
498
- if (!this.container)
604
+ /** 禁用插件 */
605
+ disable(options = {}) {
606
+ if (!this.state.enabled)
499
607
  return;
500
- this.render();
608
+ const userAction = options.userAction !== undefined ? options.userAction : true;
609
+ this.updateState({ enabled: false }, options.userAction || userAction);
610
+ this._disable({ userAction });
611
+ }
612
+ /** 更改插件 State */
613
+ setState(state, options = {}) {
614
+ const prevState = this.state;
615
+ const userAction = options.userAction !== undefined ? options.userAction : true;
616
+ this.updateState(state, userAction);
617
+ if (state.enabled !== undefined && prevState.enabled !== state.enabled) {
618
+ state.enabled ? this._enable({ userAction }) : this._disable({ userAction });
619
+ }
620
+ if (state.visible !== undefined && prevState.visible !== state.visible) {
621
+ const options = { userAction };
622
+ state.visible ? this._show(options) : this._hide(options);
623
+ }
624
+ }
625
+ async formatData(serverData) {
626
+ return await formatData(serverData.data);
627
+ }
628
+ updateState(state, userAction) {
629
+ const prevState = this.state;
630
+ this.state = Object.assign(Object.assign({}, this.state), state);
631
+ if (equal(this.state, prevState, { deep: true }))
632
+ return;
633
+ this.hooks.emit('stateChange', { state: this.state, prevState, userAction });
634
+ }
635
+ /** 如果用户是通过 selector 设置父容器,需要在 modelLoaded 之后把 container 自动放到父容器里
636
+ *
637
+ * - TODO: 等 selector 功能下掉之后删除这个逻辑
638
+ */
639
+ initContainer() {
640
+ this.container.classList.add('floorplan-plugin');
641
+ Object.assign(this.container.style, {
642
+ position: 'absolute',
643
+ left: '50%',
644
+ top: '50%',
645
+ transform: 'translate(-50%, -50%)',
646
+ zIndex: 10,
647
+ pointerEvents: 'none',
648
+ });
649
+ this.five.addExtraElement(this.container);
650
+ }
651
+ addEventListener() {
652
+ if (!this.state.enabled)
653
+ return;
654
+ if (this.hasAddedEventListener)
655
+ return;
656
+ const five = this.five;
657
+ five.on('modeChange', this.onFiveModeChange);
658
+ five.on('interiaPan', this.onFiveInteriaPan);
659
+ five.on('panoArrived', this.onFivePanoArrived);
660
+ five.on('cameraUpdate', this.onFiveCameraUpdate);
661
+ five.on('wantsGesture', this.onFiveWantsGesture);
662
+ five.on('wantsPanGesture', this.onFiveWantsPanGesture);
663
+ five.on('wantsTapGesture', this.onFiveWantsTapGesture);
664
+ five.on('wantsChangeMode', this.onFiveWantsChangeMode);
665
+ five.on('modelShownFloorChange', this.onModelShownFloorChange);
666
+ }
667
+ removeEventListener() {
668
+ const five = this.five;
669
+ this.hasAddedEventListener = false;
670
+ // 注意这里并没有消除 dispose 的监听
671
+ five.off('modelLoaded', this.onFiveModelLoaded);
672
+ five.off('modeChange', this.onFiveModeChange);
673
+ five.off('interiaPan', this.onFiveInteriaPan);
674
+ five.off('panoArrived', this.onFivePanoArrived);
675
+ five.off('cameraUpdate', this.onFiveCameraUpdate);
676
+ five.off('wantsGesture', this.onFiveWantsGesture);
677
+ five.off('wantsPanGesture', this.onFiveWantsPanGesture);
678
+ five.off('wantsTapGesture', this.onFiveWantsTapGesture);
679
+ five.off('wantsChangeMode', this.onFiveWantsChangeMode);
680
+ five.off('modelShownFloorChange', this.onModelShownFloorChange);
501
681
  }
502
682
  render(duration) {
503
- if (!this.container || !this.floorplanData)
683
+ if (!this.state.enabled)
684
+ return;
685
+ if (!this.container || !this.data)
504
686
  return;
505
687
  if (this.size.width === 0)
506
688
  return;
507
- const { northDesc, hoverEnable, cameraImageUrl, getLabelElement, roomLabelsEnable, compassEnable, ruleLabelsEnable } = this.configs;
508
- const props = {
509
- cameraImageUrl,
510
- getLabelElement,
511
- northDesc: northDesc !== null && northDesc !== void 0 ? northDesc : '北',
512
- visible: this.visible,
513
- duration: duration !== null && duration !== void 0 ? duration : 0,
514
- panoIndex: this.panoIndex,
515
- floorIndex: this.floorIndex,
516
- floorplanData: this.floorplanData,
517
- hoverEnable: hoverEnable !== null && hoverEnable !== void 0 ? hoverEnable : false,
518
- compassEnable: compassEnable !== null && compassEnable !== void 0 ? compassEnable : true,
519
- ruleLabelsEnable: ruleLabelsEnable !== null && ruleLabelsEnable !== void 0 ? ruleLabelsEnable : true,
520
- roomLabelsEnable: roomLabelsEnable !== null && roomLabelsEnable !== void 0 ? roomLabelsEnable : true,
521
- lastPanoramaLongitude: this.lastPanoramaLongitude,
522
- };
523
- if (!this.app) {
524
- this.app = new Main({
525
- target: this.container,
526
- intro: true,
527
- props,
528
- });
529
- }
530
- else {
531
- this.app.$set(props);
532
- }
689
+ const props = Object.assign(Object.assign({}, this.state.config), { visible: this.state.visible, duration: duration !== null && duration !== void 0 ? duration : 0, panoIndex: this.panoIndex, floorIndex: this.floorIndex, floorplanData: this.data, lastPanoramaLongitude: this.lastPanoramaLongitude });
690
+ if (this.app)
691
+ return this.app.$set(props);
692
+ this.app = new Main({ target: this.container, intro: true, props });
533
693
  }
534
694
  }