@realsee/dnalogel 2.0.0-alpha.12 → 2.0.0-alpha.13

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 (101) hide show
  1. package/dist/CSS3DRenderPlugin/index.js +17 -14
  2. package/dist/CameraMovementPlugin/index.js +40 -15
  3. package/dist/ModelChassisCompassPlugin/index.js +32 -6
  4. package/dist/ModelEntryDoorGuidePlugin/index.js +48 -18
  5. package/dist/ModelItemLabelPlugin/index.js +18 -17
  6. package/dist/ModelRoomLabelPlugin/index.js +67 -26
  7. package/dist/PanoCompassPlugin/index.js +311 -164
  8. package/dist/PanoCursorRaycasterPlugin/index.js +5 -3
  9. package/dist/PanoMeasurePlugin/index.js +1337 -583
  10. package/dist/PanoRulerPlugin/index.js +32 -5
  11. package/dist/PanoSpatialTagPlugin/index.js +64 -29
  12. package/dist/floorplan/ModelFloorplanPlugin/index.js +586 -362
  13. package/dist/floorplan/PanoFloorplanRadarPlugin/index.js +164 -72
  14. package/dist/floorplan/TopviewFloorplanPlugin/index.js +311 -153
  15. package/dist/index.es.js +2663 -1341
  16. package/dist/index.js +2667 -1345
  17. package/dist/index.umd.js +2667 -1345
  18. package/docs/assets/main.js +1 -1
  19. package/docs/classes/ModelRoomLabelController.html +6 -6
  20. package/docs/enums/FLOOR_PLAN_ATTACHED_TO.html +1 -1
  21. package/docs/enums/ModelFloorplanErrorType.html +1 -1
  22. package/docs/interfaces/LineJson.html +1 -1
  23. package/docs/interfaces/ModelChassisCompassPluginData.html +1 -1
  24. package/docs/interfaces/ModelChassisCompassPluginExportType.html +1 -1
  25. package/docs/interfaces/ModelChassisCompassPluginParameterType.html +1 -1
  26. package/docs/interfaces/ModelEntryDoorGuidePluginData.html +1 -1
  27. package/docs/interfaces/ModelEntryDoorGuidePluginExportType.html +1 -1
  28. package/docs/interfaces/ModelFloorplanParameterType.html +1 -1
  29. package/docs/interfaces/ModelFloorplanViewEvent.html +2 -2
  30. package/docs/interfaces/ModelRoomLabelPluginData.html +1 -1
  31. package/docs/interfaces/PanoCompassPluginData.html +1 -1
  32. package/docs/interfaces/PanoCompassPluginParameterType.html +1 -1
  33. package/docs/interfaces/PanoCursorRaycasterPluginExportType.html +6 -6
  34. package/docs/interfaces/PanoRulerPluginExportType.html +1 -1
  35. package/docs/interfaces/PanoRulerPluginOptions.html +1 -1
  36. package/docs/interfaces/PanoRulerPluginParameterType.html +1 -1
  37. package/docs/interfaces/PanoSpatialTagPluginData.html +1 -1
  38. package/docs/interfaces/PanoSpatialTagPluginExportType.html +1 -1
  39. package/docs/interfaces/PanoSpatialTagPluginParameterType.html +1 -1
  40. package/docs/interfaces/PointJson.html +1 -1
  41. package/docs/interfaces/RoomLabel.html +7 -7
  42. package/docs/interfaces/TopviewFloorplanPluginParameterType.html +1 -1
  43. package/docs/modules.html +12 -12
  44. package/libs/CSS3DRenderPlugin/index.js +16 -13
  45. package/libs/CameraMovementPlugin/index.js +24 -15
  46. package/libs/ModelChassisCompassPlugin/index.js +14 -5
  47. package/libs/ModelEntryDoorGuidePlugin/index.js +24 -12
  48. package/libs/ModelItemLabelPlugin/ItemLabelComponent.js +12 -10
  49. package/libs/ModelItemLabelPlugin/index.js +5 -3
  50. package/libs/ModelItemLabelPlugin/utils/parseData.js +1 -4
  51. package/libs/ModelRoomLabelPlugin/Controller.js +64 -23
  52. package/libs/ModelRoomLabelPlugin/RoomLabelItems.js +3 -3
  53. package/libs/PanoCompassPlugin/index.js +225 -128
  54. package/libs/PanoCursorRaycasterPlugin/index.js +5 -3
  55. package/libs/PanoMeasurePlugin/Controller/BaseController.js +68 -13
  56. package/libs/PanoMeasurePlugin/Controller/EditController.js +267 -154
  57. package/libs/PanoMeasurePlugin/Controller/ShortcutKeyController.js +40 -20
  58. package/libs/PanoMeasurePlugin/Controller/WatchController.js +234 -152
  59. package/libs/PanoMeasurePlugin/Controller/index.js +131 -47
  60. package/libs/PanoMeasurePlugin/Model/index.js +30 -5
  61. package/libs/PanoMeasurePlugin/Model/line.js +60 -10
  62. package/libs/PanoMeasurePlugin/Model/point.js +24 -4
  63. package/libs/PanoMeasurePlugin/Model/polyline.js +20 -3
  64. package/libs/PanoMeasurePlugin/Modules/DeleteDom/index.js +59 -14
  65. package/libs/PanoMeasurePlugin/Modules/FiveHelper.js +23 -8
  66. package/libs/PanoMeasurePlugin/Modules/GuideController.js +61 -26
  67. package/libs/PanoMeasurePlugin/Modules/Magnifier.js +60 -10
  68. package/libs/PanoMeasurePlugin/Modules/UIController/MainBtnController.js +83 -37
  69. package/libs/PanoMeasurePlugin/Modules/UIController/Revoke/index.js +52 -17
  70. package/libs/PanoMeasurePlugin/Modules/UIController/index.js +61 -30
  71. package/libs/PanoMeasurePlugin/utils/distanceDom.js +3 -2
  72. package/libs/PanoMeasurePlugin/utils/line.js +8 -7
  73. package/libs/PanoRulerPlugin/index.js +16 -5
  74. package/libs/PanoSpatialTagPlugin/index.js +11 -9
  75. package/libs/floorplan/Components/BaseImage.js +10 -5
  76. package/libs/floorplan/Components/RoomHighlight/RoomHighlight.js +3 -1
  77. package/libs/floorplan/Components/RoomMaterials/RoomMaterial.js +5 -6
  78. package/libs/floorplan/ModelFloorplanPlugin/Components/Compass.js +7 -2
  79. package/libs/floorplan/ModelFloorplanPlugin/Components/RoomLabels/RoomLabel.js +3 -1
  80. package/libs/floorplan/ModelFloorplanPlugin/Controller.js +456 -273
  81. package/libs/floorplan/ModelFloorplanPlugin/utils/correctFiveState.js +33 -22
  82. package/libs/floorplan/PanoFloorplanRadarPlugin/Components/CurrentFloor/CurrentFloor.js +3 -1
  83. package/libs/floorplan/PanoFloorplanRadarPlugin/Controller.js +97 -36
  84. package/libs/floorplan/TopviewFloorplanPlugin/Controller.js +231 -108
  85. package/libs/floorplan/utils/formatData.js +43 -28
  86. package/libs/floorplan/utils/formatPosition.js +1 -1
  87. package/libs/shared-utils/Subscribe.js +8 -1
  88. package/libs/shared-utils/animationFrame/BetterTween.js +47 -18
  89. package/libs/shared-utils/createCanvasTextTexture.js +6 -5
  90. package/libs/shared-utils/five/changeMode.js +23 -12
  91. package/libs/shared-utils/getPxmm.js +1 -1
  92. package/libs/shared-utils/math/evenNumber.js +1 -1
  93. package/libs/shared-utils/three/loadFbxObj.js +20 -9
  94. package/libs/shared-utils/three/loadTexture.js +17 -6
  95. package/libs/shared-utils/three/transfromToMeshBasicMaterial.js +2 -1
  96. package/libs/shared-utils/tinyEJSrender.js +36 -6
  97. package/libs/shared-utils/to.js +21 -10
  98. package/libs/shared-utils/useDebounce.js +1 -1
  99. package/libs/shared-utils/useThrottle.js +2 -1
  100. package/package.json +1 -1
  101. package/CHANGELOG.md +0 -41
@@ -1,3 +1,12 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
1
10
  import Main from './Components/Main';
2
11
  import to from '../../shared-utils/to';
3
12
  import formatData from '../utils/formatData';
@@ -10,35 +19,446 @@ import { Subscribe } from '@realsee/five';
10
19
  import { FloorplanErrorType, FIVE_CAMERA_DEFAULT_FOV, SHOW_ANIME_DURATION } from './utils/constant';
11
20
  export const MODEL_FLOORPLAN_PLUGIN_NAME = 'modelFloorplanPlugin';
12
21
  export default class ModelFloorplanPluginController {
13
- name = MODEL_FLOORPLAN_PLUGIN_NAME;
14
- /** 用于绑定事件钩子 */
15
- hooks;
16
- /** 展示状态 */
17
- visible = false;
18
- /** 户型图大小 */
19
- size = { width: 0, height: 0 };
20
- app = undefined;
21
- pxmm = 0;
22
- five;
23
- panoIndex = 0;
24
- floorIndex = 0;
25
- configs = {};
26
- lastPanoramaLongitude = 0;
27
- selector;
28
- floorplanData;
29
- wrapper;
30
- container = document.createElement('div');
31
- showState;
32
- /** 记录上次 show 的参数,如果不一致,需要 reject 掉正在进行的 showPromise */
33
- ModelFloorplanPluginsShowOpts;
34
- showPromise;
35
- showRejection;
36
22
  constructor(five, params) {
23
+ var _a;
24
+ Object.defineProperty(this, "name", {
25
+ enumerable: true,
26
+ configurable: true,
27
+ writable: true,
28
+ value: MODEL_FLOORPLAN_PLUGIN_NAME
29
+ });
30
+ /** 用于绑定事件钩子 */
31
+ Object.defineProperty(this, "hooks", {
32
+ enumerable: true,
33
+ configurable: true,
34
+ writable: true,
35
+ value: void 0
36
+ });
37
+ /** 展示状态 */
38
+ Object.defineProperty(this, "visible", {
39
+ enumerable: true,
40
+ configurable: true,
41
+ writable: true,
42
+ value: false
43
+ });
44
+ /** 户型图大小 */
45
+ Object.defineProperty(this, "size", {
46
+ enumerable: true,
47
+ configurable: true,
48
+ writable: true,
49
+ value: { width: 0, height: 0 }
50
+ });
51
+ Object.defineProperty(this, "app", {
52
+ enumerable: true,
53
+ configurable: true,
54
+ writable: true,
55
+ value: undefined
56
+ });
57
+ Object.defineProperty(this, "pxmm", {
58
+ enumerable: true,
59
+ configurable: true,
60
+ writable: true,
61
+ value: 0
62
+ });
63
+ Object.defineProperty(this, "five", {
64
+ enumerable: true,
65
+ configurable: true,
66
+ writable: true,
67
+ value: void 0
68
+ });
69
+ Object.defineProperty(this, "panoIndex", {
70
+ enumerable: true,
71
+ configurable: true,
72
+ writable: true,
73
+ value: 0
74
+ });
75
+ Object.defineProperty(this, "floorIndex", {
76
+ enumerable: true,
77
+ configurable: true,
78
+ writable: true,
79
+ value: 0
80
+ });
81
+ Object.defineProperty(this, "configs", {
82
+ enumerable: true,
83
+ configurable: true,
84
+ writable: true,
85
+ value: {}
86
+ });
87
+ Object.defineProperty(this, "lastPanoramaLongitude", {
88
+ enumerable: true,
89
+ configurable: true,
90
+ writable: true,
91
+ value: 0
92
+ });
93
+ Object.defineProperty(this, "selector", {
94
+ enumerable: true,
95
+ configurable: true,
96
+ writable: true,
97
+ value: void 0
98
+ });
99
+ Object.defineProperty(this, "floorplanData", {
100
+ enumerable: true,
101
+ configurable: true,
102
+ writable: true,
103
+ value: void 0
104
+ });
105
+ Object.defineProperty(this, "wrapper", {
106
+ enumerable: true,
107
+ configurable: true,
108
+ writable: true,
109
+ value: void 0
110
+ });
111
+ Object.defineProperty(this, "container", {
112
+ enumerable: true,
113
+ configurable: true,
114
+ writable: true,
115
+ value: document.createElement('div')
116
+ });
117
+ Object.defineProperty(this, "showState", {
118
+ enumerable: true,
119
+ configurable: true,
120
+ writable: true,
121
+ value: void 0
122
+ });
123
+ /** 记录上次 show 的参数,如果不一致,需要 reject 掉正在进行的 showPromise */
124
+ Object.defineProperty(this, "ModelFloorplanPluginsShowOpts", {
125
+ enumerable: true,
126
+ configurable: true,
127
+ writable: true,
128
+ value: void 0
129
+ });
130
+ Object.defineProperty(this, "showPromise", {
131
+ enumerable: true,
132
+ configurable: true,
133
+ writable: true,
134
+ value: void 0
135
+ });
136
+ Object.defineProperty(this, "showRejection", {
137
+ enumerable: true,
138
+ configurable: true,
139
+ writable: true,
140
+ value: void 0
141
+ });
142
+ Object.defineProperty(this, "dispose", {
143
+ enumerable: true,
144
+ configurable: true,
145
+ writable: true,
146
+ value: () => {
147
+ var _a, _b;
148
+ const five = this.five;
149
+ this.hide();
150
+ (_a = this.app) === null || _a === void 0 ? void 0 : _a.$destroy();
151
+ (_b = this.container) === null || _b === void 0 ? void 0 : _b.remove();
152
+ five.off('modelLoaded', this.handleModelLoaded);
153
+ five.off('modeChange', this.handleModeChange);
154
+ five.off('panGesture', this.handlePanGesture);
155
+ five.off('panoArrived', this.handlePanoArrived);
156
+ five.off('wantsChangeMode', this.handleWantsChangeMode);
157
+ five.off('wantsInteriaPan', this.handleWantsInteriaPan);
158
+ five.off('wantsTapGesture', this.handleWantsTapGesture);
159
+ five.off('modelShownFloorChange', this.onModelShownFloorChange);
160
+ }
161
+ });
162
+ /** 更新户型图大小 */
163
+ Object.defineProperty(this, "updateSize", {
164
+ enumerable: true,
165
+ configurable: true,
166
+ writable: true,
167
+ value: () => {
168
+ if (!this.floorplanData)
169
+ return;
170
+ if (!checkShowState(this.five, this.showState))
171
+ return;
172
+ if (!this.container || !this.wrapper)
173
+ return;
174
+ // 计算户型图展示大小
175
+ const { min, max } = this.floorplanData.bounding;
176
+ const width = max.x - min.x;
177
+ const height = max.y - min.y;
178
+ // 每毫米对应的 px 值
179
+ const options = this.configs.attachedTo ? { attachedTo: this.configs.attachedTo } : undefined;
180
+ const pxmm = getPxmm(this.five, this.wrapper, this.floorIndex, options);
181
+ const _width = Math.ceil(width * pxmm);
182
+ const _height = Math.ceil(height * pxmm);
183
+ if (this.size.width === _width && this.size.height === _height)
184
+ return;
185
+ this.pxmm = pxmm;
186
+ this.size = { width: _width, height: _height };
187
+ this.container.style.width = _width + 'px';
188
+ this.container.style.height = _height + 'px';
189
+ }
190
+ });
191
+ /** 展示户型图
192
+ * 1. show 函数大部分情况下需要耗时
193
+ * 2. 如果当前已经在展示中,将不会触发任何事件
194
+ * 3. 如果展示过程被中断,将抛出错误
195
+ * 4. 多次调用 show 方法,只会触发一次 showAnimationEnded 事件,但是展示结果会取决于最后一次调用参数
196
+ * 5. 如果多次调用 show 方法,参数与上次参数不一致时,上次 show Promise 会被 reject
197
+ * @param opts.floorIndex 楼层
198
+ * @param opts.modelOpacity 模型透明度
199
+ * @param opts.immediately 是否立即展示
200
+ * @param opts.isAutoShow 是否是自动展示
201
+ */
202
+ Object.defineProperty(this, "show", {
203
+ enumerable: true,
204
+ configurable: true,
205
+ writable: true,
206
+ value: (opts) => __awaiter(this, void 0, void 0, function* () {
207
+ var _b, _c;
208
+ // 已经在展示中了
209
+ if (!this.showPromise && this.visible)
210
+ return true;
211
+ if (!((_b = this.five.model) === null || _b === void 0 ? void 0 : _b.loaded))
212
+ throw new Error(FloorplanErrorType.ModelNotLoaded);
213
+ if (!this.floorplanData)
214
+ throw new Error(FloorplanErrorType.DataNotLoaded);
215
+ this.visible = true;
216
+ if (this.showPromise) {
217
+ const sameWithLastOpts = equal(opts, this.ModelFloorplanPluginsShowOpts, { deep: false });
218
+ if (!!this.showPromise && sameWithLastOpts)
219
+ return this.showPromise;
220
+ if (!!this.showPromise && !sameWithLastOpts)
221
+ (_c = this.showRejection) === null || _c === void 0 ? void 0 : _c.call(this, FloorplanErrorType.DifferentShowParams);
222
+ }
223
+ this.ModelFloorplanPluginsShowOpts = opts;
224
+ const getShowPromise = () => __awaiter(this, void 0, void 0, function* () {
225
+ var _d, _e;
226
+ let hasRejected = false;
227
+ let externalErrorMsg;
228
+ this.showRejection = (errorMsg) => {
229
+ hasRejected = true;
230
+ externalErrorMsg = errorMsg;
231
+ };
232
+ const [correctError] = yield to(correctFiveState(this.five, this.showState, opts === null || opts === void 0 ? void 0 : opts.userAction));
233
+ if (correctError)
234
+ throw correctError;
235
+ // 异步结束要判断当前是不是被中断了,是不是调用了隐藏
236
+ if (hasRejected)
237
+ throw externalErrorMsg ? new Error(externalErrorMsg) : new Error(FloorplanErrorType.UnknownError);
238
+ if (!this.visible)
239
+ throw new Error(FloorplanErrorType.UnknownError);
240
+ // 更新户型图状态
241
+ this.visible = true;
242
+ // 更新户型图大小
243
+ this.updateSize();
244
+ // 高亮当前楼层,有两个目的
245
+ // 1. 点击模型时,可以跳转到当前楼层的点位上
246
+ // 2. 当前楼层比较小时,户型图也比较小,如果展示全部楼层,会展示户型图外有一圈模型
247
+ if (opts === null || opts === void 0 ? void 0 : opts.floorIndex)
248
+ this.floorIndex = opts.floorIndex;
249
+ this.five.model.show(this.floorIndex);
250
+ // 模型消失, 渲染户型图
251
+ const modelOpacity = (_e = (_d = opts === null || opts === void 0 ? void 0 : opts.modelOpacity) !== null && _d !== void 0 ? _d : this.configs.modelOpacity) !== null && _e !== void 0 ? _e : 1;
252
+ const renderDuration = (opts === null || opts === void 0 ? void 0 : opts.immediately) ? 0 : SHOW_ANIME_DURATION;
253
+ changeModelCanvasOpacity(this.five, modelOpacity, renderDuration);
254
+ this.render(renderDuration);
255
+ // 展示之后的事件监听
256
+ this.five.on('wantsGesture', this.handleWantsGesture);
257
+ this.five.on('wantsTapGesture', this.handleWantsTapGesture);
258
+ return true;
259
+ });
260
+ const showPromise = getShowPromise()
261
+ .then(() => {
262
+ var _a;
263
+ 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 });
264
+ return true;
265
+ })
266
+ .catch((error) => {
267
+ // 自动展示的报错内部处理
268
+ if (opts === null || opts === void 0 ? void 0 : opts.isAutoShow)
269
+ return false;
270
+ if (!(error instanceof Error))
271
+ return false;
272
+ // 非自动展示的报错继续向外抛出
273
+ throw error;
274
+ })
275
+ .finally(() => {
276
+ this.showPromise = undefined;
277
+ this.showRejection = undefined;
278
+ });
279
+ this.showPromise = showPromise;
280
+ return showPromise;
281
+ })
282
+ });
283
+ /** 隐藏户型图 */
284
+ Object.defineProperty(this, "hide", {
285
+ enumerable: true,
286
+ configurable: true,
287
+ writable: true,
288
+ value: (options) => {
289
+ var _a, _b;
290
+ if (this.size.width === 0)
291
+ return true;
292
+ if (this.visible === false)
293
+ return true;
294
+ const isAutoHide = !!(options === null || options === void 0 ? void 0 : options.isAutoHide);
295
+ this.five.off('wantsGesture', this.handleWantsGesture);
296
+ this.five.off('wantsTapGesture', this.handleWantsTapGesture);
297
+ this.visible = false;
298
+ (_a = this.showRejection) === null || _a === void 0 ? void 0 : _a.call(this, FloorplanErrorType.BreakOffByHide);
299
+ changeModelCanvasOpacity(this.five, 1, 0);
300
+ this.render();
301
+ this.hooks.emit('hide', { auto: isAutoHide, userAction: (_b = options === null || options === void 0 ? void 0 : options.userAction) !== null && _b !== void 0 ? _b : true });
302
+ return true;
303
+ }
304
+ });
305
+ /** 模型楼层高亮改变时,自动进行楼层切换 */
306
+ Object.defineProperty(this, "onModelShownFloorChange", {
307
+ enumerable: true,
308
+ configurable: true,
309
+ writable: true,
310
+ value: (shownFloor) => {
311
+ if (shownFloor === null)
312
+ return;
313
+ this.floorIndex = shownFloor;
314
+ this.updateSize();
315
+ this.render();
316
+ }
317
+ });
318
+ Object.defineProperty(this, "handleModelLoaded", {
319
+ enumerable: true,
320
+ configurable: true,
321
+ writable: true,
322
+ value: () => {
323
+ if (this.wrapper)
324
+ return;
325
+ if (!this.selector)
326
+ return;
327
+ const wrapper = this.selector instanceof Element ? this.selector : document.querySelector(this.selector);
328
+ if (!wrapper)
329
+ throw new Error('不正确的父容器选择器');
330
+ this.wrapper = wrapper;
331
+ wrapper.append(this.container);
332
+ }
333
+ });
334
+ Object.defineProperty(this, "handleClick", {
335
+ enumerable: true,
336
+ configurable: true,
337
+ writable: true,
338
+ value: () => {
339
+ if (!this.visible)
340
+ return;
341
+ const prevented = this.hooks.emit('click');
342
+ if (prevented)
343
+ return false;
344
+ }
345
+ });
346
+ Object.defineProperty(this, "handleWantsTapGesture", {
347
+ enumerable: true,
348
+ configurable: true,
349
+ writable: true,
350
+ value: () => this.handleClick()
351
+ });
352
+ /** 从 Panorama 切换到其他模态时,记录当前的相机水平视角 */
353
+ Object.defineProperty(this, "handleWantsChangeMode", {
354
+ enumerable: true,
355
+ configurable: true,
356
+ writable: true,
357
+ value: (mode) => {
358
+ if (mode !== 'Panorama') {
359
+ this.lastPanoramaLongitude = this.five.getCurrentState().longitude;
360
+ }
361
+ if (mode !== 'Floorplan')
362
+ this.hide();
363
+ }
364
+ });
365
+ /** 监听模型态变化,只有在模型态才进行手势动作监听 */
366
+ Object.defineProperty(this, "handleModeChange", {
367
+ enumerable: true,
368
+ configurable: true,
369
+ writable: true,
370
+ value: (mode) => {
371
+ if (mode === 'Floorplan') {
372
+ this.five.on('panGesture', this.handlePanGesture);
373
+ }
374
+ else {
375
+ this.hide();
376
+ this.five.off('panGesture', this.handlePanGesture);
377
+ }
378
+ }
379
+ });
380
+ /** panoIndex 改变时,更新 floorIndex */
381
+ Object.defineProperty(this, "handlePanoArrived", {
382
+ enumerable: true,
383
+ configurable: true,
384
+ writable: true,
385
+ value: (index) => {
386
+ var _a;
387
+ if (!((_a = this.five) === null || _a === void 0 ? void 0 : _a.work))
388
+ return;
389
+ this.panoIndex = index;
390
+ this.floorIndex = this.five.work.observers[index].floorIndex;
391
+ }
392
+ });
393
+ /** 当户型图正在展示中的时候禁用惯性 */
394
+ Object.defineProperty(this, "handleWantsInteriaPan", {
395
+ enumerable: true,
396
+ configurable: true,
397
+ writable: true,
398
+ value: () => {
399
+ if (this.visible)
400
+ return false;
401
+ }
402
+ });
403
+ /** 在户型图展示时阻止多指操作, 阻止鼠标放大 */
404
+ Object.defineProperty(this, "handleWantsGesture", {
405
+ enumerable: true,
406
+ configurable: true,
407
+ writable: true,
408
+ value: (type, pointers) => {
409
+ if (!this.visible)
410
+ return;
411
+ if (pointers.length > 1)
412
+ return false;
413
+ if (type === 'mouseWheel')
414
+ return false;
415
+ }
416
+ });
417
+ /** 监听三维模型滑动
418
+ * 1. 在三维模型转动结束时,如果达到设置的阈值,会自动切换到户型图
419
+ * 2. 如何户型图已经展示,滑动时关闭户型图
420
+ */
421
+ Object.defineProperty(this, "handlePanGesture", {
422
+ enumerable: true,
423
+ configurable: true,
424
+ writable: true,
425
+ value: ({ latitude, longitude }, isFinal) => __awaiter(this, void 0, void 0, function* () {
426
+ if (this.configs.autoShowEnable === false)
427
+ return;
428
+ // 如果操作结束后,户型图还在展示中,初始化模型状态
429
+ if (isFinal && this.visible)
430
+ return this.five.setState(this.showState, true);
431
+ // 满足消失的条件:
432
+ // 水平旋转角大于正负 5 度 || 俯仰角度大于 5 度
433
+ const latitudeHide = Math.abs(latitude - Math.PI / 2) > (5 * Math.PI) / 180;
434
+ const longitudeHide = longitude > 5 * (Math.PI / 180) && longitude < 355 * (Math.PI / 180);
435
+ const canHide = latitudeHide || longitudeHide;
436
+ if (this.visible && canHide)
437
+ return this.hide({ isAutoHide: true });
438
+ if (this.five.camera.fov / FIVE_CAMERA_DEFAULT_FOV < 0.8)
439
+ return;
440
+ // 户型图展示条件:
441
+ // 水平旋转角正负 30 度 && 俯仰角度小于 10 度
442
+ const latitudeVisible = Math.abs(latitude - Math.PI / 2) < (10 * Math.PI) / 180;
443
+ const longitudeVisible = longitude < 30 * (Math.PI / 180) || longitude > 330 * (Math.PI / 180);
444
+ if (isFinal && !this.visible && latitudeVisible && longitudeVisible) {
445
+ // 当手指离开时需要等惯性结束之后在进行判断
446
+ const handleInteriaPan = (any, isFinal) => __awaiter(this, void 0, void 0, function* () {
447
+ if (!isFinal)
448
+ return;
449
+ this.five.off('interiaPan', handleInteriaPan);
450
+ yield this.show({ isAutoShow: true });
451
+ });
452
+ this.five.on('interiaPan', handleInteriaPan);
453
+ return;
454
+ }
455
+ })
456
+ });
37
457
  this.five = five;
38
458
  this.hooks = new Subscribe();
39
459
  this.selector = params.selector;
40
460
  this.configs = omit(params, ['selector']);
41
- this.showState = { longitude: 0, latitude: Math.PI / 2, fov: FIVE_CAMERA_DEFAULT_FOV / (params?.scale ?? 1) };
461
+ 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) };
42
462
  // 设置 container 样式
43
463
  this.container.classList.add('floorplan-plugin');
44
464
  Object.assign(this.container.style, {
@@ -58,25 +478,13 @@ export default class ModelFloorplanPluginController {
58
478
  five.on('wantsInteriaPan', this.handleWantsInteriaPan);
59
479
  five.on('modelShownFloorChange', this.onModelShownFloorChange);
60
480
  }
61
- dispose = () => {
62
- const five = this.five;
63
- this.hide();
64
- this.app?.$destroy();
65
- this.container?.remove();
66
- five.off('modelLoaded', this.handleModelLoaded);
67
- five.off('modeChange', this.handleModeChange);
68
- five.off('panGesture', this.handlePanGesture);
69
- five.off('panoArrived', this.handlePanoArrived);
70
- five.off('wantsChangeMode', this.handleWantsChangeMode);
71
- five.off('wantsInteriaPan', this.handleWantsInteriaPan);
72
- five.off('wantsTapGesture', this.handleWantsTapGesture);
73
- five.off('modelShownFloorChange', this.onModelShownFloorChange);
74
- };
75
481
  /** 加载户型图数据 */
76
- async load(data) {
77
- const copyData = JSON.parse(JSON.stringify(data));
78
- this.floorplanData = await formatData(copyData);
79
- this.render();
482
+ load(data) {
483
+ return __awaiter(this, void 0, void 0, function* () {
484
+ const copyData = JSON.parse(JSON.stringify(data));
485
+ this.floorplanData = yield formatData(copyData);
486
+ this.render();
487
+ });
80
488
  }
81
489
  /** 把插件的渲染DOM插入到对应的容器中去 */
82
490
  appendTo(wrapper) {
@@ -84,130 +492,6 @@ export default class ModelFloorplanPluginController {
84
492
  wrapper.appendChild(this.container);
85
493
  return this;
86
494
  }
87
- /** 更新户型图大小 */
88
- updateSize = () => {
89
- if (!this.floorplanData)
90
- return;
91
- if (!checkShowState(this.five, this.showState))
92
- return;
93
- if (!this.container || !this.wrapper)
94
- return;
95
- // 计算户型图展示大小
96
- const { min, max } = this.floorplanData.bounding;
97
- const width = max.x - min.x;
98
- const height = max.y - min.y;
99
- // 每毫米对应的 px 值
100
- const options = this.configs.attachedTo ? { attachedTo: this.configs.attachedTo } : undefined;
101
- const pxmm = getPxmm(this.five, this.wrapper, this.floorIndex, options);
102
- const _width = Math.ceil(width * pxmm);
103
- const _height = Math.ceil(height * pxmm);
104
- if (this.size.width === _width && this.size.height === _height)
105
- return;
106
- this.pxmm = pxmm;
107
- this.size = { width: _width, height: _height };
108
- this.container.style.width = _width + 'px';
109
- this.container.style.height = _height + 'px';
110
- };
111
- /** 展示户型图
112
- * 1. show 函数大部分情况下需要耗时
113
- * 2. 如果当前已经在展示中,将不会触发任何事件
114
- * 3. 如果展示过程被中断,将抛出错误
115
- * 4. 多次调用 show 方法,只会触发一次 showAnimationEnded 事件,但是展示结果会取决于最后一次调用参数
116
- * 5. 如果多次调用 show 方法,参数与上次参数不一致时,上次 show Promise 会被 reject
117
- * @param opts.floorIndex 楼层
118
- * @param opts.modelOpacity 模型透明度
119
- * @param opts.immediately 是否立即展示
120
- * @param opts.isAutoShow 是否是自动展示
121
- */
122
- show = async (opts) => {
123
- // 已经在展示中了
124
- if (!this.showPromise && this.visible)
125
- return true;
126
- if (!this.five.model?.loaded)
127
- throw new Error(FloorplanErrorType.ModelNotLoaded);
128
- if (!this.floorplanData)
129
- throw new Error(FloorplanErrorType.DataNotLoaded);
130
- this.visible = true;
131
- if (this.showPromise) {
132
- const sameWithLastOpts = equal(opts, this.ModelFloorplanPluginsShowOpts, { deep: false });
133
- if (!!this.showPromise && sameWithLastOpts)
134
- return this.showPromise;
135
- if (!!this.showPromise && !sameWithLastOpts)
136
- this.showRejection?.(FloorplanErrorType.DifferentShowParams);
137
- }
138
- this.ModelFloorplanPluginsShowOpts = opts;
139
- const getShowPromise = async () => {
140
- let hasRejected = false;
141
- let externalErrorMsg;
142
- this.showRejection = (errorMsg) => {
143
- hasRejected = true;
144
- externalErrorMsg = errorMsg;
145
- };
146
- const [correctError] = await to(correctFiveState(this.five, this.showState, opts?.userAction));
147
- if (correctError)
148
- throw correctError;
149
- // 异步结束要判断当前是不是被中断了,是不是调用了隐藏
150
- if (hasRejected)
151
- throw externalErrorMsg ? new Error(externalErrorMsg) : new Error(FloorplanErrorType.UnknownError);
152
- if (!this.visible)
153
- throw new Error(FloorplanErrorType.UnknownError);
154
- // 更新户型图状态
155
- this.visible = true;
156
- // 更新户型图大小
157
- this.updateSize();
158
- // 高亮当前楼层,有两个目的
159
- // 1. 点击模型时,可以跳转到当前楼层的点位上
160
- // 2. 当前楼层比较小时,户型图也比较小,如果展示全部楼层,会展示户型图外有一圈模型
161
- if (opts?.floorIndex)
162
- this.floorIndex = opts.floorIndex;
163
- this.five.model.show(this.floorIndex);
164
- // 模型消失, 渲染户型图
165
- const modelOpacity = opts?.modelOpacity ?? this.configs.modelOpacity ?? 1;
166
- const renderDuration = opts?.immediately ? 0 : SHOW_ANIME_DURATION;
167
- changeModelCanvasOpacity(this.five, modelOpacity, renderDuration);
168
- this.render(renderDuration);
169
- // 展示之后的事件监听
170
- this.five.on('wantsGesture', this.handleWantsGesture);
171
- this.five.on('wantsTapGesture', this.handleWantsTapGesture);
172
- return true;
173
- };
174
- const showPromise = getShowPromise()
175
- .then(() => {
176
- this.hooks.emit('showAnimationEnded', { auto: !!opts?.isAutoShow, userAction: opts?.userAction ?? true });
177
- return true;
178
- })
179
- .catch((error) => {
180
- // 自动展示的报错内部处理
181
- if (opts?.isAutoShow)
182
- return false;
183
- if (!(error instanceof Error))
184
- return false;
185
- // 非自动展示的报错继续向外抛出
186
- throw error;
187
- })
188
- .finally(() => {
189
- this.showPromise = undefined;
190
- this.showRejection = undefined;
191
- });
192
- this.showPromise = showPromise;
193
- return showPromise;
194
- };
195
- /** 隐藏户型图 */
196
- hide = (options) => {
197
- if (this.size.width === 0)
198
- return true;
199
- if (this.visible === false)
200
- return true;
201
- const isAutoHide = !!options?.isAutoHide;
202
- this.five.off('wantsGesture', this.handleWantsGesture);
203
- this.five.off('wantsTapGesture', this.handleWantsTapGesture);
204
- this.visible = false;
205
- this.showRejection?.(FloorplanErrorType.BreakOffByHide);
206
- changeModelCanvasOpacity(this.five, 1, 0);
207
- this.render();
208
- this.hooks.emit('hide', { auto: isAutoHide, userAction: options?.userAction ?? true });
209
- return true;
210
- };
211
495
  /** 更改户型图楼层 */
212
496
  changeFloor(floorIndex) {
213
497
  this.five.model.show(floorIndex);
@@ -220,107 +504,6 @@ export default class ModelFloorplanPluginController {
220
504
  return;
221
505
  this.render();
222
506
  }
223
- /** 模型楼层高亮改变时,自动进行楼层切换 */
224
- onModelShownFloorChange = (shownFloor) => {
225
- if (shownFloor === null)
226
- return;
227
- this.floorIndex = shownFloor;
228
- this.updateSize();
229
- this.render();
230
- };
231
- handleModelLoaded = () => {
232
- if (this.wrapper)
233
- return;
234
- if (!this.selector)
235
- return;
236
- const wrapper = this.selector instanceof Element ? this.selector : document.querySelector(this.selector);
237
- if (!wrapper)
238
- throw new Error('不正确的父容器选择器');
239
- this.wrapper = wrapper;
240
- wrapper.append(this.container);
241
- };
242
- handleClick = () => {
243
- if (!this.visible)
244
- return;
245
- const prevented = this.hooks.emit('click');
246
- if (prevented)
247
- return false;
248
- };
249
- handleWantsTapGesture = () => this.handleClick();
250
- /** 从 Panorama 切换到其他模态时,记录当前的相机水平视角 */
251
- handleWantsChangeMode = (mode) => {
252
- if (mode !== 'Panorama') {
253
- this.lastPanoramaLongitude = this.five.getCurrentState().longitude;
254
- }
255
- if (mode !== 'Floorplan')
256
- this.hide();
257
- };
258
- /** 监听模型态变化,只有在模型态才进行手势动作监听 */
259
- handleModeChange = (mode) => {
260
- if (mode === 'Floorplan') {
261
- this.five.on('panGesture', this.handlePanGesture);
262
- }
263
- else {
264
- this.hide();
265
- this.five.off('panGesture', this.handlePanGesture);
266
- }
267
- };
268
- /** panoIndex 改变时,更新 floorIndex */
269
- handlePanoArrived = (index) => {
270
- if (!this.five?.work)
271
- return;
272
- this.panoIndex = index;
273
- this.floorIndex = this.five.work.observers[index].floorIndex;
274
- };
275
- /** 当户型图正在展示中的时候禁用惯性 */
276
- handleWantsInteriaPan = () => {
277
- if (this.visible)
278
- return false;
279
- };
280
- /** 在户型图展示时阻止多指操作, 阻止鼠标放大 */
281
- handleWantsGesture = (type, pointers) => {
282
- if (!this.visible)
283
- return;
284
- if (pointers.length > 1)
285
- return false;
286
- if (type === 'mouseWheel')
287
- return false;
288
- };
289
- /** 监听三维模型滑动
290
- * 1. 在三维模型转动结束时,如果达到设置的阈值,会自动切换到户型图
291
- * 2. 如何户型图已经展示,滑动时关闭户型图
292
- */
293
- handlePanGesture = async ({ latitude, longitude }, isFinal) => {
294
- if (this.configs.autoShowEnable === false)
295
- return;
296
- // 如果操作结束后,户型图还在展示中,初始化模型状态
297
- if (isFinal && this.visible)
298
- return this.five.setState(this.showState, true);
299
- // 满足消失的条件:
300
- // 水平旋转角大于正负 5 度 || 俯仰角度大于 5 度
301
- const latitudeHide = Math.abs(latitude - Math.PI / 2) > (5 * Math.PI) / 180;
302
- const longitudeHide = longitude > 5 * (Math.PI / 180) && longitude < 355 * (Math.PI / 180);
303
- const canHide = latitudeHide || longitudeHide;
304
- if (this.visible && canHide)
305
- return this.hide({ isAutoHide: true });
306
- if (this.five.camera.fov / FIVE_CAMERA_DEFAULT_FOV < 0.8)
307
- return;
308
- // 户型图展示条件:
309
- // 水平旋转角正负 30 度 && 俯仰角度小于 10 度
310
- const latitudeVisible = Math.abs(latitude - Math.PI / 2) < (10 * Math.PI) / 180;
311
- const longitudeVisible = longitude < 30 * (Math.PI / 180) || longitude > 330 * (Math.PI / 180);
312
- if (isFinal && !this.visible && latitudeVisible && longitudeVisible) {
313
- // 当手指离开时需要等惯性结束之后在进行判断
314
- const handleInteriaPan = async (any, isFinal) => {
315
- if (!isFinal)
316
- return;
317
- this.five.off('interiaPan', handleInteriaPan);
318
- await this.show({ isAutoShow: true });
319
- };
320
- this.five.on('interiaPan', handleInteriaPan);
321
- return;
322
- }
323
- };
324
507
  render(duration) {
325
508
  if (!this.container || !this.floorplanData)
326
509
  return;
@@ -328,19 +511,19 @@ export default class ModelFloorplanPluginController {
328
511
  return;
329
512
  const { northDesc, hoverEnable, cameraImageUrl, getLabelElement, roomLabelsEnable, compassEnable, ruleLabelsEnable } = this.configs;
330
513
  const props = {
331
- northDesc: northDesc ?? '北',
514
+ northDesc: northDesc !== null && northDesc !== void 0 ? northDesc : '北',
332
515
  five: this.five,
333
516
  pxmm: this.pxmm,
334
517
  cameraImageUrl,
335
518
  visible: this.visible,
336
- duration: duration ?? 0,
519
+ duration: duration !== null && duration !== void 0 ? duration : 0,
337
520
  panoIndex: this.panoIndex,
338
521
  floorIndex: this.floorIndex,
339
522
  floorplanData: this.floorplanData,
340
- hoverEnable: hoverEnable ?? false,
341
- compassEnable: compassEnable ?? true,
342
- ruleLabelsEnable: ruleLabelsEnable ?? true,
343
- roomLabelsEnable: roomLabelsEnable ?? true,
523
+ hoverEnable: hoverEnable !== null && hoverEnable !== void 0 ? hoverEnable : false,
524
+ compassEnable: compassEnable !== null && compassEnable !== void 0 ? compassEnable : true,
525
+ ruleLabelsEnable: ruleLabelsEnable !== null && ruleLabelsEnable !== void 0 ? ruleLabelsEnable : true,
526
+ roomLabelsEnable: roomLabelsEnable !== null && roomLabelsEnable !== void 0 ? roomLabelsEnable : true,
344
527
  lastPanoramaLongitude: this.lastPanoramaLongitude,
345
528
  getLabelElement,
346
529
  onRoomHeightClick: this.handleClick,