@itwin/imodel-components-react 3.0.0-extension.1 → 3.0.2

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 (118) hide show
  1. package/CHANGELOG.md +51 -0
  2. package/LICENSE.md +1 -1
  3. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.d.ts +3 -2
  4. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.d.ts.map +1 -1
  5. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js +17 -4
  6. package/lib/cjs/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  7. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.d.ts +2 -2
  8. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.d.ts.map +1 -1
  9. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.js +1 -1
  10. package/lib/cjs/imodel-components-react/color/ColorPickerPanel.js.map +1 -1
  11. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.d.ts +4 -3
  12. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.d.ts.map +1 -1
  13. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js +41 -22
  14. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  15. package/lib/cjs/imodel-components-react/color/ColorPickerPopup.scss +12 -2
  16. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.d.ts.map +1 -1
  17. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js +3 -2
  18. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  19. package/lib/cjs/imodel-components-react/inputs/QuantityNumberInput.scss +19 -1
  20. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js +1 -1
  21. package/lib/cjs/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  22. package/lib/cjs/imodel-components-react/quantityformat/FormatType.js +1 -1
  23. package/lib/cjs/imodel-components-react/quantityformat/FormatType.js.map +1 -1
  24. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js +1 -1
  25. package/lib/cjs/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  26. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js +1 -1
  27. package/lib/cjs/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  28. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts.map +1 -1
  29. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.js +1 -1
  30. package/lib/cjs/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  31. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.js +1 -1
  32. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalPrecision.js.map +1 -1
  33. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.js +1 -1
  34. package/lib/cjs/imodel-components-react/quantityformat/misc/DecimalSeparator.js.map +1 -1
  35. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.js +1 -1
  36. package/lib/cjs/imodel-components-react/quantityformat/misc/FractionPrecision.js.map +1 -1
  37. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.js +1 -1
  38. package/lib/cjs/imodel-components-react/quantityformat/misc/ScientificType.js.map +1 -1
  39. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.js +1 -1
  40. package/lib/cjs/imodel-components-react/quantityformat/misc/SignOption.js.map +1 -1
  41. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +1 -1
  42. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  43. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.js +1 -1
  44. package/lib/cjs/imodel-components-react/quantityformat/misc/StationSizeSelector.js.map +1 -1
  45. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js +1 -1
  46. package/lib/cjs/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  47. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js +2 -2
  48. package/lib/cjs/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  49. package/lib/cjs/imodel-components-react/timeline/InlineEdit.d.ts.map +1 -1
  50. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js +1 -1
  51. package/lib/cjs/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  52. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.d.ts +1 -25
  53. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.d.ts.map +1 -1
  54. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js +201 -186
  55. package/lib/cjs/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  56. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.d.ts +1 -1
  57. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.d.ts.map +1 -1
  58. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js +8 -7
  59. package/lib/cjs/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  60. package/lib/esm/imodel-components-react/color/ColorPickerDialog.d.ts +3 -2
  61. package/lib/esm/imodel-components-react/color/ColorPickerDialog.d.ts.map +1 -1
  62. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js +17 -4
  63. package/lib/esm/imodel-components-react/color/ColorPickerDialog.js.map +1 -1
  64. package/lib/esm/imodel-components-react/color/ColorPickerPanel.d.ts +2 -2
  65. package/lib/esm/imodel-components-react/color/ColorPickerPanel.d.ts.map +1 -1
  66. package/lib/esm/imodel-components-react/color/ColorPickerPanel.js +1 -1
  67. package/lib/esm/imodel-components-react/color/ColorPickerPanel.js.map +1 -1
  68. package/lib/esm/imodel-components-react/color/ColorPickerPopup.d.ts +4 -3
  69. package/lib/esm/imodel-components-react/color/ColorPickerPopup.d.ts.map +1 -1
  70. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js +41 -22
  71. package/lib/esm/imodel-components-react/color/ColorPickerPopup.js.map +1 -1
  72. package/lib/esm/imodel-components-react/color/ColorPickerPopup.scss +12 -2
  73. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.d.ts.map +1 -1
  74. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js +3 -2
  75. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.js.map +1 -1
  76. package/lib/esm/imodel-components-react/inputs/QuantityNumberInput.scss +19 -1
  77. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js +1 -1
  78. package/lib/esm/imodel-components-react/quantityformat/FormatSample.js.map +1 -1
  79. package/lib/esm/imodel-components-react/quantityformat/FormatType.js +1 -1
  80. package/lib/esm/imodel-components-react/quantityformat/FormatType.js.map +1 -1
  81. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js +1 -1
  82. package/lib/esm/imodel-components-react/quantityformat/FormatUnitLabel.js.map +1 -1
  83. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js +1 -1
  84. package/lib/esm/imodel-components-react/quantityformat/FormatUnits.js.map +1 -1
  85. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.d.ts.map +1 -1
  86. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js +1 -1
  87. package/lib/esm/imodel-components-react/quantityformat/QuantityFormatPanel.js.map +1 -1
  88. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.js +1 -1
  89. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalPrecision.js.map +1 -1
  90. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.js +1 -1
  91. package/lib/esm/imodel-components-react/quantityformat/misc/DecimalSeparator.js.map +1 -1
  92. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.js +1 -1
  93. package/lib/esm/imodel-components-react/quantityformat/misc/FractionPrecision.js.map +1 -1
  94. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.js +1 -1
  95. package/lib/esm/imodel-components-react/quantityformat/misc/ScientificType.js.map +1 -1
  96. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.js +1 -1
  97. package/lib/esm/imodel-components-react/quantityformat/misc/SignOption.js.map +1 -1
  98. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js +1 -1
  99. package/lib/esm/imodel-components-react/quantityformat/misc/StationSeparatorSelector.js.map +1 -1
  100. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.js +1 -1
  101. package/lib/esm/imodel-components-react/quantityformat/misc/StationSizeSelector.js.map +1 -1
  102. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js +1 -1
  103. package/lib/esm/imodel-components-react/quantityformat/misc/ThousandsSelector.js.map +1 -1
  104. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js +2 -2
  105. package/lib/esm/imodel-components-react/quantityformat/misc/UnitDescr.js.map +1 -1
  106. package/lib/esm/imodel-components-react/timeline/InlineEdit.d.ts.map +1 -1
  107. package/lib/esm/imodel-components-react/timeline/InlineEdit.js +1 -1
  108. package/lib/esm/imodel-components-react/timeline/InlineEdit.js.map +1 -1
  109. package/lib/esm/imodel-components-react/viewport/ViewportComponent.d.ts +1 -25
  110. package/lib/esm/imodel-components-react/viewport/ViewportComponent.d.ts.map +1 -1
  111. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js +201 -186
  112. package/lib/esm/imodel-components-react/viewport/ViewportComponent.js.map +1 -1
  113. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.d.ts +1 -1
  114. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.d.ts.map +1 -1
  115. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js +2 -1
  116. package/lib/esm/imodel-components-react/viewport/ViewportComponentEvents.js.map +1 -1
  117. package/lib/public/locales/en/UiIModelComponents.json +3 -1
  118. package/package.json +27 -29
@@ -32,186 +32,68 @@ const core_bentley_1 = require("@itwin/core-bentley");
32
32
  const core_geometry_1 = require("@itwin/core-geometry");
33
33
  const core_common_1 = require("@itwin/core-common");
34
34
  const core_frontend_1 = require("@itwin/core-frontend");
35
- const UiIModelComponents_1 = require("../UiIModelComponents");
36
35
  const ViewportComponentEvents_1 = require("./ViewportComponentEvents");
37
36
  /**
38
37
  * A viewport React component that creates a ScreenViewport.
39
38
  * @public
40
39
  */
41
- class ViewportComponent extends React.Component {
42
- constructor(props) {
43
- super(props);
44
- this._viewClassFullName = "";
45
- this._mounted = false;
46
- this._handleDisconnectFromViewManager = () => {
47
- const screenViewport = this._vp;
48
- const parentDiv = this._viewportDiv.current;
49
- if (screenViewport) {
50
- const viewManager = core_frontend_1.IModelApp.viewManager;
51
- viewManager.dropViewport(screenViewport, true);
52
- screenViewport.onViewChanged.removeListener(this._handleViewChanged);
53
- this._vp = undefined;
54
- }
55
- // istanbul ignore else
56
- if (parentDiv) {
57
- const parentWindow = parentDiv.ownerDocument.defaultView;
58
- parentWindow.removeEventListener("beforeunload", this._handleDisconnectFromViewManager, false);
59
- }
60
- };
61
- this._handleDrawingViewportChangeEvent = (args) => {
62
- const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.viewManager;
63
- /* istanbul ignore else */
64
- if (this._vp && viewManager.selectedView === this._vp) {
65
- this._vp.view.setOrigin(args.origin);
66
- this._vp.view.setRotation(args.rotation);
67
- this._vp.synchWithView({ noSaveInUndo: args.complete !== true });
68
- }
69
- };
70
- this._handleCubeRotationChangeEvent = (args) => {
71
- const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.viewManager;
72
- /* istanbul ignore else */
73
- if (this._vp && viewManager.selectedView === this._vp) {
74
- const rotMatrix = args.rotMatrix;
75
- /* istanbul ignore else */
76
- if (this._vp.rotation !== rotMatrix) {
77
- const inverse = rotMatrix.transpose(); // rotation is from current nav cube state...
78
- const center = this._getRotatePoint(this._vp);
79
- const targetMatrix = inverse.multiplyMatrixMatrix(this._vp.view.getRotation());
80
- const worldTransform = core_geometry_1.Transform.createFixedPointAndMatrix(center, targetMatrix);
81
- const frustum = this._vp.getWorldFrustum();
82
- frustum.multiply(worldTransform);
83
- this._vp.view.setupFromFrustum(frustum);
84
- this._vp.synchWithView({ noSaveInUndo: !args.complete });
85
- }
86
- }
87
- };
88
- this._handleStandardRotationChangeEvent = (args) => {
89
- const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.viewManager;
90
- /* istanbul ignore else */
91
- if (this._vp && viewManager.selectedView === this._vp) {
92
- // this._vp.view.setStandardRotation(args.standardRotation);
93
- this._vp.view.setRotationAboutPoint(core_frontend_1.ViewState.getStandardViewMatrix(args.standardRotation));
94
- this._vp.synchWithView();
95
- }
96
- };
97
- this._handleViewChanged = (vp) => {
98
- ViewportComponentEvents_1.ViewportComponentEvents.setViewMatrix(vp);
99
- /* istanbul ignore else */
100
- if (this._viewClassFullName !== vp.view.classFullName) {
101
- setTimeout(() => {
102
- ViewportComponentEvents_1.ViewportComponentEvents.onViewClassFullNameChangedEvent.emit({ viewport: vp, oldName: this._viewClassFullName, newName: vp.view.classFullName });
103
- this._viewClassFullName = vp.view.classFullName;
104
- });
105
- }
106
- /* istanbul ignore else */
107
- if (this.state.viewId !== vp.view.id) {
108
- setTimeout(() => {
109
- ViewportComponentEvents_1.ViewportComponentEvents.onViewIdChangedEvent.emit({ viewport: vp, oldId: this.state.viewId, newId: vp.view.id });
110
- /* istanbul ignore next - flaky mounted condition in the setTimeout */
111
- if (this._mounted)
112
- this.setState({ viewId: vp.view.id });
113
- });
114
- }
115
- };
116
- this._handleContextMenu = (e) => {
117
- e.preventDefault();
118
- if (this.props.onContextMenu)
119
- this.props.onContextMenu(e);
120
- return false;
121
- };
122
- this._viewportDiv = React.createRef();
123
- this.state = {
124
- viewId: "",
125
- };
126
- }
127
- async componentDidMount() {
128
- this._mounted = true;
40
+ function ViewportComponent(props) {
41
+ const { viewState, imodel, viewDefinitionId, getViewOverlay, viewManagerOverride, tentativePointOverride, onContextMenu, style, className, screenViewportOverride, controlId, viewportRef } = props;
42
+ // istanbul ignore next
43
+ const viewManagerRef = React.useRef(viewManagerOverride !== null && viewManagerOverride !== void 0 ? viewManagerOverride : core_frontend_1.IModelApp.viewManager);
44
+ const tentativePointOverrideRef = React.useRef(tentativePointOverride);
45
+ const screenViewportCreated = React.useRef(false);
46
+ const viewportDiv = React.useRef(null);
47
+ const screenViewportRef = React.useRef(null);
48
+ const isMounted = React.useRef(false);
49
+ const viewClassFullName = React.useRef("");
50
+ const viewId = React.useRef("0");
51
+ // istanbul ignore next
52
+ const handleViewChanged = (vp) => {
129
53
  // istanbul ignore next
130
- if (!this._viewportDiv.current) {
131
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `Parent <div> failed to load`);
54
+ if (!(vp.iModel.isOpen || vp.iModel.isBlank))
132
55
  return;
56
+ ViewportComponentEvents_1.ViewportComponentEvents.setViewMatrix(vp);
57
+ if (viewClassFullName.current !== vp.view.classFullName) {
58
+ setTimeout(() => {
59
+ ViewportComponentEvents_1.ViewportComponentEvents.onViewClassFullNameChangedEvent.emit({ viewport: vp, oldName: viewClassFullName.current, newName: vp.view.classFullName });
60
+ viewClassFullName.current = vp.view.classFullName;
61
+ });
133
62
  }
134
- const viewState = await this.getViewState();
135
- if (viewState === undefined) {
136
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `Failed to obtain ViewState`);
137
- return;
63
+ if (viewId.current !== vp.view.id) {
64
+ setTimeout(() => {
65
+ ViewportComponentEvents_1.ViewportComponentEvents.onViewIdChangedEvent.emit({ viewport: vp, oldId: viewId.current, newId: vp.view.id });
66
+ viewId.current = vp.view.id;
67
+ });
138
68
  }
139
- /* istanbul ignore next */
140
- if (!this._mounted)
141
- return;
142
- const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.viewManager;
143
- const screenViewportFactory = this.props.screenViewportOverride ? this.props.screenViewportOverride : /* istanbul ignore next */ core_frontend_1.ScreenViewport;
144
- const parentDiv = this._viewportDiv.current;
145
- const screenViewport = screenViewportFactory.create(parentDiv, viewState);
146
- this._vp = screenViewport;
147
- viewManager.addViewport(this._vp);
148
- const parentWindow = parentDiv.ownerDocument.defaultView;
149
- parentWindow.addEventListener("beforeunload", this._handleDisconnectFromViewManager, false);
150
- ViewportComponentEvents_1.ViewportComponentEvents.initialize();
151
- ViewportComponentEvents_1.ViewportComponentEvents.onDrawingViewportChangeEvent.addListener(this._handleDrawingViewportChangeEvent);
152
- ViewportComponentEvents_1.ViewportComponentEvents.onCubeRotationChangeEvent.addListener(this._handleCubeRotationChangeEvent);
153
- ViewportComponentEvents_1.ViewportComponentEvents.onStandardRotationChangeEvent.addListener(this._handleStandardRotationChangeEvent);
154
- this._vp.onViewChanged.addListener(this._handleViewChanged);
155
- this._viewClassFullName = this._vp.view.classFullName;
156
- this.setState({ viewId: this._vp.view.id });
157
- /* istanbul ignore else */
158
- if (this.props.viewportRef)
159
- this.props.viewportRef(this._vp);
160
- }
161
- componentWillUnmount() {
162
- this._mounted = false;
163
- this._handleDisconnectFromViewManager();
164
- ViewportComponentEvents_1.ViewportComponentEvents.onDrawingViewportChangeEvent.removeListener(this._handleDrawingViewportChangeEvent);
165
- ViewportComponentEvents_1.ViewportComponentEvents.onCubeRotationChangeEvent.removeListener(this._handleCubeRotationChangeEvent);
166
- ViewportComponentEvents_1.ViewportComponentEvents.onStandardRotationChangeEvent.removeListener(this._handleStandardRotationChangeEvent);
167
- }
168
- async componentDidUpdate(prevProps) {
169
- if (this.props.imodel === prevProps.imodel &&
170
- this.props.viewState === prevProps.viewState &&
171
- this.props.viewDefinitionId === prevProps.viewDefinitionId)
172
- return;
173
- /* istanbul ignore else */
174
- if (this._vp) {
175
- const viewState = await this.getViewState();
176
- if (viewState === undefined) {
177
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `Failed to obtain ViewState`);
178
- return;
179
- }
180
- this._vp.changeView(viewState);
181
- /* istanbul ignore else */
182
- if (this._mounted)
183
- this.setState({ viewId: this._vp.view.id });
184
- }
185
- }
186
- async getViewState() {
187
- let viewState;
188
- if (this.props.viewState) {
189
- if (typeof this.props.viewState === "function")
190
- viewState = this.props.viewState();
191
- else
192
- viewState = this.props.viewState;
69
+ };
70
+ const handleStandardRotationChangeEvent = (args) => {
71
+ const viewManager = viewManagerRef.current;
72
+ const currentScreenViewport = screenViewportRef.current;
73
+ if (currentScreenViewport && viewManager.selectedView === currentScreenViewport) {
74
+ currentScreenViewport.view.setRotationAboutPoint(core_frontend_1.ViewState.getStandardViewMatrix(args.standardRotation));
75
+ currentScreenViewport.synchWithView();
193
76
  }
194
- else if (this.props.viewDefinitionId) {
195
- viewState = await this.props.imodel.views.load(this.props.viewDefinitionId);
196
- if (!viewState) {
197
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `View state failed to load`);
198
- return undefined;
199
- }
200
- else {
201
- return viewState;
202
- }
77
+ };
78
+ const handleDrawingViewportChangeEvent = (args) => {
79
+ const viewManager = viewManagerRef.current;
80
+ const currentScreenViewport = screenViewportRef.current;
81
+ if (currentScreenViewport && viewManager.selectedView === currentScreenViewport) {
82
+ currentScreenViewport.view.setOrigin(args.origin);
83
+ currentScreenViewport.view.setRotation(args.rotation);
84
+ currentScreenViewport.synchWithView({ noSaveInUndo: args.complete !== true });
203
85
  }
204
- else {
205
- core_bentley_1.Logger.logError(UiIModelComponents_1.UiIModelComponents.loggerCategory(this), `Either viewDefinitionId or viewState must be provided as a ViewportComponent Prop`);
206
- return undefined;
207
- }
208
- return viewState.clone();
209
- }
210
- _getRotatePoint(vp) {
211
- const tentativePoint = this.props.tentativePointOverride ? this.props.tentativePointOverride : /* istanbul ignore next */ core_frontend_1.IModelApp.tentativePoint;
86
+ };
87
+ const targetPoint = React.useRef(null);
88
+ const getRotatePoint = (vp) => {
89
+ var _a, _b;
90
+ const lastTargetPoint = targetPoint.current;
91
+ // istanbul ignore next
92
+ const tentativePoint = (_a = tentativePointOverrideRef.current) !== null && _a !== void 0 ? _a : core_frontend_1.IModelApp.tentativePoint;
93
+ // istanbul ignore else
212
94
  if (tentativePoint.isActive)
213
95
  return tentativePoint.getPoint();
214
- /* istanbul ignore else */
96
+ // istanbul ignore else
215
97
  if (undefined !== vp.viewCmdTargetCenter) {
216
98
  const testPt = vp.worldToView(vp.viewCmdTargetCenter);
217
99
  const viewRect = vp.viewRect;
@@ -219,32 +101,165 @@ class ViewportComponent extends React.Component {
219
101
  return vp.viewCmdTargetCenter;
220
102
  vp.viewCmdTargetCenter = undefined;
221
103
  }
222
- if (undefined !== this._lastTargetPoint) {
223
- const testPt = vp.worldToView(this._lastTargetPoint);
104
+ // istanbul ignore else
105
+ if (null !== lastTargetPoint) {
106
+ const testPt = vp.worldToView(lastTargetPoint);
224
107
  const viewRect = vp.viewRect.clone();
225
108
  viewRect.scaleAboutCenter(0.25, 0.25);
226
109
  // istanbul ignore next hard to reach because of mocks
227
110
  if (viewRect.containsPoint(testPt))
228
- return this._lastTargetPoint;
229
- this._lastTargetPoint = undefined;
111
+ return lastTargetPoint;
112
+ targetPoint.current = null;
230
113
  }
231
114
  const visiblePoint = vp.pickNearestVisibleGeometry(vp.npcToWorld(core_common_1.NpcCenter), vp.pixelsFromInches(core_frontend_1.ToolSettings.viewToolPickRadiusInches));
232
- this._lastTargetPoint = (undefined !== visiblePoint ? visiblePoint : vp.view.getTargetPoint());
233
- return this._lastTargetPoint;
234
- }
235
- render() {
236
- const viewOverlay = this._vp && this.props.getViewOverlay ? this.props.getViewOverlay(this._vp) : null;
237
- const parentDivStyle = {
238
- height: "100%", width: "100%", position: "relative",
239
- };
240
- const viewportDivStyle = {
241
- height: "100%", width: "100%",
242
- ...this.props.style,
115
+ targetPoint.current = (undefined !== visiblePoint ? visiblePoint : vp.view.getTargetPoint());
116
+ // istanbul ignore next
117
+ return (_b = targetPoint.current) !== null && _b !== void 0 ? _b : vp.view.getCenter();
118
+ };
119
+ const handleCubeRotationChangeEvent = (args) => {
120
+ const viewManager = viewManagerRef.current;
121
+ const currentScreenViewport = screenViewportRef.current;
122
+ // istanbul ignore else
123
+ if (currentScreenViewport && viewManager.selectedView === currentScreenViewport) {
124
+ const rotMatrix = args.rotMatrix;
125
+ // istanbul ignore else
126
+ if (currentScreenViewport.rotation !== rotMatrix) {
127
+ const inverse = rotMatrix.transpose(); // rotation is from current nav cube state...
128
+ const center = getRotatePoint(currentScreenViewport);
129
+ const targetMatrix = inverse.multiplyMatrixMatrix(currentScreenViewport.view.getRotation());
130
+ const worldTransform = core_geometry_1.Transform.createFixedPointAndMatrix(center, targetMatrix);
131
+ const frustum = currentScreenViewport.getWorldFrustum();
132
+ frustum.multiply(worldTransform);
133
+ currentScreenViewport.view.setupFromFrustum(frustum);
134
+ currentScreenViewport.synchWithView({ noSaveInUndo: !args.complete });
135
+ }
136
+ }
137
+ };
138
+ const handleDisconnectFromViewManager = () => {
139
+ const screenViewport = screenViewportRef.current;
140
+ if (screenViewport) {
141
+ const viewManager = core_frontend_1.IModelApp.viewManager;
142
+ screenViewport.onViewChanged.removeListener(handleViewChanged);
143
+ screenViewportRef.current = null;
144
+ screenViewportCreated.current = false;
145
+ ViewportComponentEvents_1.ViewportComponentEvents.onDrawingViewportChangeEvent.removeListener(handleDrawingViewportChangeEvent);
146
+ ViewportComponentEvents_1.ViewportComponentEvents.onCubeRotationChangeEvent.removeListener(handleCubeRotationChangeEvent);
147
+ ViewportComponentEvents_1.ViewportComponentEvents.onStandardRotationChangeEvent.removeListener(handleStandardRotationChangeEvent);
148
+ viewManager.dropViewport(screenViewport, true);
149
+ }
150
+ };
151
+ const getScreenViewport = (parentDiv, inViewState) => {
152
+ // istanbul ignore next
153
+ const screenViewportFactory = screenViewportOverride ? screenViewportOverride : core_frontend_1.ScreenViewport;
154
+ const parentWindow = parentDiv.ownerDocument.defaultView;
155
+ parentWindow.addEventListener("beforeunload", handleDisconnectFromViewManager, true); // listener clear after being called
156
+ ViewportComponentEvents_1.ViewportComponentEvents.initialize();
157
+ ViewportComponentEvents_1.ViewportComponentEvents.onDrawingViewportChangeEvent.addListener(handleDrawingViewportChangeEvent);
158
+ ViewportComponentEvents_1.ViewportComponentEvents.onCubeRotationChangeEvent.addListener(handleCubeRotationChangeEvent);
159
+ ViewportComponentEvents_1.ViewportComponentEvents.onStandardRotationChangeEvent.addListener(handleStandardRotationChangeEvent);
160
+ const screenViewport = screenViewportFactory.create(parentDiv, inViewState);
161
+ screenViewportCreated.current = true;
162
+ viewClassFullName.current = screenViewport.view.classFullName;
163
+ viewId.current = screenViewport.view.id;
164
+ screenViewport.onViewChanged.addListener(handleViewChanged);
165
+ return screenViewport;
166
+ };
167
+ React.useEffect(() => {
168
+ isMounted.current = true;
169
+ core_bentley_1.Logger.logInfo("ViewportComponent", `mounting ViewportComponent for controlId=${controlId}`);
170
+ return () => {
171
+ isMounted.current = false;
172
+ core_bentley_1.Logger.logInfo("ViewportComponent", `un-mounting ViewportComponent for controlId=${controlId}`);
173
+ handleDisconnectFromViewManager();
243
174
  };
244
- return (React.createElement("div", { style: parentDivStyle },
245
- React.createElement("div", { ref: this._viewportDiv, "data-testid": "viewport-component", className: this.props.className, style: viewportDivStyle, onContextMenu: this._handleContextMenu }),
246
- viewOverlay));
247
- }
175
+ // eslint-disable-next-line react-hooks/exhaustive-deps
176
+ }, []);
177
+ const [initialViewState, setInitialViewState] = React.useState(() => {
178
+ if (viewState) {
179
+ if (typeof viewState === "function")
180
+ return viewState().clone();
181
+ else
182
+ return viewState.clone();
183
+ }
184
+ return undefined;
185
+ });
186
+ React.useEffect(() => {
187
+ setInitialViewState(undefined);
188
+ }, [viewDefinitionId, viewState]);
189
+ React.useEffect(() => {
190
+ async function fetchInitialViewstate() {
191
+ let currentViewState;
192
+ if (viewState) {
193
+ if (typeof viewState === "function")
194
+ currentViewState = viewState();
195
+ else
196
+ currentViewState = viewState;
197
+ }
198
+ else if (viewDefinitionId && imodel) {
199
+ try {
200
+ currentViewState = await imodel.views.load(viewDefinitionId);
201
+ // istanbul ignore next
202
+ if (!currentViewState) {
203
+ core_bentley_1.Logger.logError("ViewportComponent", `Viewstate failed to load`);
204
+ }
205
+ }
206
+ catch (_e) {
207
+ // istanbul ignore next
208
+ core_bentley_1.Logger.logError("ViewportComponent", `Viewstate failed to load`);
209
+ }
210
+ }
211
+ else {
212
+ core_bentley_1.Logger.logError("ViewportComponent", `A Viewstate or a viewId and imodel must be provided`);
213
+ }
214
+ // istanbul ignore next
215
+ if (isMounted.current && ((currentViewState === null || currentViewState === void 0 ? void 0 : currentViewState.iModel.isOpen) || (currentViewState === null || currentViewState === void 0 ? void 0 : currentViewState.iModel.isBlank))) {
216
+ setInitialViewState(currentViewState === null || currentViewState === void 0 ? void 0 : currentViewState.clone());
217
+ }
218
+ }
219
+ if (undefined === initialViewState)
220
+ fetchInitialViewstate(); // eslint-disable-line @typescript-eslint/no-floating-promises
221
+ }, [imodel, initialViewState, viewDefinitionId, viewState]);
222
+ const [viewOverlay, setViewOverlay] = React.useState(null);
223
+ // This useEffect connects to ViewManger as soon as initialViewState is available once component is mounted.
224
+ React.useEffect(() => {
225
+ var _a;
226
+ const parentDiv = viewportDiv.current;
227
+ const viewManager = viewManagerRef.current;
228
+ // istanbul ignore next
229
+ if (parentDiv && initialViewState && ((initialViewState === null || initialViewState === void 0 ? void 0 : initialViewState.iModel.isOpen) || (initialViewState === null || initialViewState === void 0 ? void 0 : initialViewState.iModel.isBlank))) {
230
+ if (!screenViewportCreated.current) {
231
+ const screenViewport = getScreenViewport(parentDiv, initialViewState);
232
+ screenViewportRef.current = screenViewport;
233
+ if (viewportRef)
234
+ viewportRef(screenViewport);
235
+ core_bentley_1.Logger.logInfo("ViewportComponent", `processing viewManager.addViewport for controlId=${controlId}`);
236
+ viewManager.addViewport(screenViewport);
237
+ // overlay component is set up once a ScreenViewport is available. The overlay component must handle any view changes itself.
238
+ setViewOverlay(getViewOverlay ? getViewOverlay(screenViewport) : null);
239
+ }
240
+ else {
241
+ // istanbul ignore next
242
+ (_a = screenViewportRef.current) === null || _a === void 0 ? void 0 : _a.changeView(initialViewState);
243
+ }
244
+ }
245
+ // eslint-disable-next-line react-hooks/exhaustive-deps
246
+ }, [controlId, initialViewState, viewportRef]);
247
+ const handleContextMenu = React.useCallback((e) => {
248
+ e.preventDefault();
249
+ if (onContextMenu)
250
+ onContextMenu(e);
251
+ }, [onContextMenu]);
252
+ const parentDivStyle = {
253
+ height: "100%", width: "100%", position: "relative",
254
+ };
255
+ const viewportDivStyle = {
256
+ ...style,
257
+ height: "100%", width: "100%",
258
+ };
259
+ return (React.createElement("div", { style: parentDivStyle, "data-item-id": controlId },
260
+ React.createElement(React.Fragment, null,
261
+ React.createElement("div", { ref: viewportDiv, "data-testid": "viewport-component", className: className, style: viewportDivStyle, onContextMenu: handleContextMenu }),
262
+ viewOverlay)));
248
263
  }
249
264
  exports.ViewportComponent = ViewportComponent;
250
265
  //# sourceMappingURL=ViewportComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"ViewportComponent.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/viewport/ViewportComponent.tsx"],"names":[],"mappings":";AAAA;;;+FAG+F;AAC/F;;GAEG;;;;;;;;;;;;;;;;;;;;;;AAEH,6CAA+B;AAC/B,sDAAyD;AACzD,wDAA0D;AAC1D,oDAA+C;AAC/C,wDAI8B;AAG9B,8DAA2D;AAC3D,uEAEmC;AAuCnC;;;GAGG;AACH,MAAa,iBAAkB,SAAQ,KAAK,CAAC,SAAuC;IAQlF,YAAmB,KAAoB;QACrC,KAAK,CAAC,KAAK,CAAC,CAAC;QALP,uBAAkB,GAAW,EAAE,CAAC;QAEhC,aAAQ,GAAY,KAAK,CAAC;QAU1B,qCAAgC,GAAG,GAAG,EAAE;YAC9C,MAAM,cAAc,GAAG,IAAI,CAAC,GAAG,CAAC;YAChC,MAAM,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CAAC,KAAK,CAAC,KAAK;SACpB,CAAC;QAEF,OAAO,CACL,6BAAK,KAAK,EAAE,cAAc;YACxB,6BACE,GAAG,EAAE,IAAI,CAAC,YAAY,iBACV,oBAAoB,EAChC,SAAS,EAAE,IAAI,CAAC,KAAK,CAAC,SAAS,EAC/B,KAAK,EAAE,gBAAgB,EACvB,aAAa,EAAE,IAAI,CAAC,kBAAkB,GACtC;YACD,WAAW,CACR,CACP,CAAC;IACJ,CAAC;CACF;AAjQD,8CAiQC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Viewport\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport { Id64String, Logger } from \"@itwin/core-bentley\";\r\nimport { Point3d, Transform } from \"@itwin/core-geometry\";\r\nimport { NpcCenter } from \"@itwin/core-common\";\r\nimport {\r\n IModelApp, IModelConnection, ScreenViewport,\r\n TentativePoint, ToolSettings, ViewManager,\r\n Viewport, ViewState,\r\n} from \"@itwin/core-frontend\";\r\n\r\nimport { CommonProps } from \"@itwin/core-react\";\r\nimport { UiIModelComponents } from \"../UiIModelComponents\";\r\nimport {\r\n CubeRotationChangeEventArgs, DrawingViewportChangeEventArgs, StandardRotationChangeEventArgs, ViewportComponentEvents,\r\n} from \"./ViewportComponentEvents\";\r\n\r\n/** Type for a ViewState prop\r\n * @public\r\n */\r\nexport type ViewStateProp = ViewState | (() => ViewState);\r\n\r\n/**\r\n * Properties for [[ViewportComponent]] component.\r\n * @public\r\n */\r\nexport interface ViewportProps extends CommonProps {\r\n /** IModel to display */\r\n imodel: IModelConnection;\r\n /** Id of a default view definition to load as a starting point */\r\n viewDefinitionId?: Id64String;\r\n /** ViewState to use as a starting point */\r\n viewState?: ViewStateProp;\r\n /** Function to get a reference to the ScreenViewport */\r\n viewportRef?: (v: ScreenViewport) => void;\r\n /** controlId for this content component @internal */\r\n controlId?: string;\r\n /** @internal */\r\n onContextMenu?: (e: React.MouseEvent) => boolean;\r\n /** @internal */\r\n getViewOverlay?: (viewport: ScreenViewport) => React.ReactNode;\r\n /** @internal used only for testing */\r\n viewManagerOverride?: ViewManager;\r\n /** @internal used only for testing */\r\n screenViewportOverride?: typeof ScreenViewport;\r\n /** @internal used only for testing */\r\n tentativePointOverride?: TentativePoint;\r\n}\r\n\r\n/** @internal */\r\ninterface ViewportState {\r\n viewId: string;\r\n}\r\n\r\n/**\r\n * A viewport React component that creates a ScreenViewport.\r\n * @public\r\n */\r\nexport class ViewportComponent extends React.Component<ViewportProps, ViewportState> {\r\n\r\n private _viewportDiv: React.RefObject<HTMLDivElement>;\r\n private _vp?: ScreenViewport;\r\n private _viewClassFullName: string = \"\";\r\n private _lastTargetPoint?: Point3d;\r\n private _mounted: boolean = false;\r\n\r\n public constructor(props: ViewportProps) {\r\n super(props);\r\n this._viewportDiv = React.createRef<HTMLDivElement>();\r\n this.state = {\r\n viewId: \"\",\r\n };\r\n }\r\n\r\n private _handleDisconnectFromViewManager = () => {\r\n const screenViewport = this._vp;\r\n const parentDiv = this._viewportDiv.current;\r\n\r\n if (screenViewport) {\r\n const viewManager = IModelApp.viewManager;\r\n viewManager.dropViewport(screenViewport, true);\r\n screenViewport.onViewChanged.removeListener(this._handleViewChanged);\r\n this._vp = undefined;\r\n }\r\n // istanbul ignore else\r\n if (parentDiv) {\r\n const parentWindow = parentDiv.ownerDocument.defaultView as Window;\r\n parentWindow.removeEventListener(\"beforeunload\", this._handleDisconnectFromViewManager, false);\r\n }\r\n };\r\n\r\n public override async componentDidMount() {\r\n this._mounted = true;\r\n\r\n // istanbul ignore next\r\n if (!this._viewportDiv.current) {\r\n Logger.logError(UiIModelComponents.loggerCategory(this), `Parent <div> failed to load`);\r\n return;\r\n }\r\n\r\n const viewState = await this.getViewState();\r\n if (viewState === undefined) {\r\n Logger.logError(UiIModelComponents.loggerCategory(this), `Failed to obtain ViewState`);\r\n return;\r\n }\r\n\r\n /* istanbul ignore next */\r\n if (!this._mounted)\r\n return;\r\n\r\n const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ IModelApp.viewManager;\r\n const screenViewportFactory = this.props.screenViewportOverride ? this.props.screenViewportOverride : /* istanbul ignore next */ ScreenViewport;\r\n const parentDiv = this._viewportDiv.current;\r\n const screenViewport = screenViewportFactory.create(parentDiv, viewState);\r\n this._vp = screenViewport;\r\n viewManager.addViewport(this._vp);\r\n\r\n const parentWindow = parentDiv.ownerDocument.defaultView as Window;\r\n parentWindow.addEventListener(\"beforeunload\", this._handleDisconnectFromViewManager, false);\r\n\r\n ViewportComponentEvents.initialize();\r\n ViewportComponentEvents.onDrawingViewportChangeEvent.addListener(this._handleDrawingViewportChangeEvent);\r\n ViewportComponentEvents.onCubeRotationChangeEvent.addListener(this._handleCubeRotationChangeEvent);\r\n ViewportComponentEvents.onStandardRotationChangeEvent.addListener(this._handleStandardRotationChangeEvent);\r\n\r\n this._vp.onViewChanged.addListener(this._handleViewChanged);\r\n this._viewClassFullName = this._vp.view.classFullName;\r\n this.setState({ viewId: this._vp.view.id });\r\n\r\n /* istanbul ignore else */\r\n if (this.props.viewportRef)\r\n this.props.viewportRef(this._vp);\r\n }\r\n\r\n public override componentWillUnmount() {\r\n this._mounted = false;\r\n this._handleDisconnectFromViewManager();\r\n ViewportComponentEvents.onDrawingViewportChangeEvent.removeListener(this._handleDrawingViewportChangeEvent);\r\n ViewportComponentEvents.onCubeRotationChangeEvent.removeListener(this._handleCubeRotationChangeEvent);\r\n ViewportComponentEvents.onStandardRotationChangeEvent.removeListener(this._handleStandardRotationChangeEvent);\r\n }\r\n\r\n public override async componentDidUpdate(prevProps: ViewportProps) {\r\n if (this.props.imodel === prevProps.imodel &&\r\n this.props.viewState === prevProps.viewState &&\r\n this.props.viewDefinitionId === prevProps.viewDefinitionId)\r\n return;\r\n\r\n /* istanbul ignore else */\r\n if (this._vp) {\r\n const viewState = await this.getViewState();\r\n if (viewState === undefined) {\r\n Logger.logError(UiIModelComponents.loggerCategory(this), `Failed to obtain ViewState`);\r\n return;\r\n }\r\n\r\n this._vp.changeView(viewState);\r\n\r\n /* istanbul ignore else */\r\n if (this._mounted)\r\n this.setState({ viewId: this._vp.view.id });\r\n }\r\n }\r\n\r\n private async getViewState(): Promise<ViewState | undefined> {\r\n let viewState: ViewState;\r\n\r\n if (this.props.viewState) {\r\n if (typeof this.props.viewState === \"function\")\r\n viewState = this.props.viewState();\r\n else\r\n viewState = this.props.viewState;\r\n } else if (this.props.viewDefinitionId) {\r\n viewState = await this.props.imodel.views.load(this.props.viewDefinitionId);\r\n if (!viewState) {\r\n Logger.logError(UiIModelComponents.loggerCategory(this), `View state failed to load`);\r\n return undefined;\r\n } else {\r\n return viewState;\r\n }\r\n } else {\r\n Logger.logError(UiIModelComponents.loggerCategory(this), `Either viewDefinitionId or viewState must be provided as a ViewportComponent Prop`);\r\n return undefined;\r\n }\r\n\r\n return viewState.clone();\r\n }\r\n\r\n private _handleDrawingViewportChangeEvent = (args: DrawingViewportChangeEventArgs) => {\r\n const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ IModelApp.viewManager;\r\n\r\n /* istanbul ignore else */\r\n if (this._vp && viewManager.selectedView === this._vp) {\r\n this._vp.view.setOrigin(args.origin);\r\n this._vp.view.setRotation(args.rotation);\r\n this._vp.synchWithView({ noSaveInUndo: args.complete !== true });\r\n }\r\n };\r\n\r\n private _getRotatePoint(vp: ScreenViewport): Point3d {\r\n const tentativePoint = this.props.tentativePointOverride ? this.props.tentativePointOverride : /* istanbul ignore next */ IModelApp.tentativePoint;\r\n if (tentativePoint.isActive)\r\n return tentativePoint.getPoint();\r\n\r\n /* istanbul ignore else */\r\n if (undefined !== vp.viewCmdTargetCenter) {\r\n const testPt = vp.worldToView(vp.viewCmdTargetCenter);\r\n const viewRect = vp.viewRect;\r\n if (viewRect.containsPoint(testPt))\r\n return vp.viewCmdTargetCenter;\r\n vp.viewCmdTargetCenter = undefined;\r\n }\r\n\r\n if (undefined !== this._lastTargetPoint) {\r\n const testPt = vp.worldToView(this._lastTargetPoint);\r\n const viewRect = vp.viewRect.clone();\r\n viewRect.scaleAboutCenter(0.25, 0.25);\r\n // istanbul ignore next hard to reach because of mocks\r\n if (viewRect.containsPoint(testPt))\r\n return this._lastTargetPoint;\r\n this._lastTargetPoint = undefined;\r\n }\r\n\r\n const visiblePoint = vp.pickNearestVisibleGeometry(vp.npcToWorld(NpcCenter), vp.pixelsFromInches(ToolSettings.viewToolPickRadiusInches));\r\n this._lastTargetPoint = (undefined !== visiblePoint ? visiblePoint : vp.view.getTargetPoint());\r\n return this._lastTargetPoint;\r\n }\r\n\r\n private _handleCubeRotationChangeEvent = (args: CubeRotationChangeEventArgs) => {\r\n const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ IModelApp.viewManager;\r\n\r\n /* istanbul ignore else */\r\n if (this._vp && viewManager.selectedView === this._vp) {\r\n const rotMatrix = args.rotMatrix;\r\n\r\n /* istanbul ignore else */\r\n if (this._vp.rotation !== rotMatrix) {\r\n const inverse = rotMatrix.transpose(); // rotation is from current nav cube state...\r\n const center = this._getRotatePoint(this._vp);\r\n const targetMatrix = inverse.multiplyMatrixMatrix(this._vp.view.getRotation());\r\n const worldTransform = Transform.createFixedPointAndMatrix(center, targetMatrix);\r\n const frustum = this._vp.getWorldFrustum();\r\n frustum.multiply(worldTransform);\r\n this._vp.view.setupFromFrustum(frustum);\r\n this._vp.synchWithView({ noSaveInUndo: !args.complete });\r\n }\r\n }\r\n };\r\n\r\n private _handleStandardRotationChangeEvent = (args: StandardRotationChangeEventArgs) => {\r\n const viewManager = this.props.viewManagerOverride ? this.props.viewManagerOverride : /* istanbul ignore next */ IModelApp.viewManager;\r\n\r\n /* istanbul ignore else */\r\n if (this._vp && viewManager.selectedView === this._vp) {\r\n // this._vp.view.setStandardRotation(args.standardRotation);\r\n this._vp.view.setRotationAboutPoint(ViewState.getStandardViewMatrix(args.standardRotation));\r\n this._vp.synchWithView();\r\n }\r\n };\r\n\r\n private _handleViewChanged = (vp: Viewport) => {\r\n ViewportComponentEvents.setViewMatrix(vp);\r\n\r\n /* istanbul ignore else */\r\n if (this._viewClassFullName !== vp.view.classFullName) {\r\n setTimeout(() => {\r\n ViewportComponentEvents.onViewClassFullNameChangedEvent.emit({ viewport: vp, oldName: this._viewClassFullName, newName: vp.view.classFullName });\r\n this._viewClassFullName = vp.view.classFullName;\r\n });\r\n }\r\n\r\n /* istanbul ignore else */\r\n if (this.state.viewId !== vp.view.id) {\r\n setTimeout(() => {\r\n ViewportComponentEvents.onViewIdChangedEvent.emit({ viewport: vp, oldId: this.state.viewId, newId: vp.view.id });\r\n\r\n /* istanbul ignore next - flaky mounted condition in the setTimeout */\r\n if (this._mounted)\r\n this.setState({ viewId: vp.view.id });\r\n });\r\n }\r\n };\r\n\r\n private _handleContextMenu = (e: React.MouseEvent): boolean => {\r\n e.preventDefault();\r\n if (this.props.onContextMenu)\r\n this.props.onContextMenu(e);\r\n return false;\r\n };\r\n\r\n public override render() {\r\n const viewOverlay = this._vp && this.props.getViewOverlay ? this.props.getViewOverlay(this._vp) : null;\r\n\r\n const parentDivStyle: React.CSSProperties = {\r\n height: \"100%\", width: \"100%\", position: \"relative\",\r\n };\r\n\r\n const viewportDivStyle: React.CSSProperties = {\r\n height: \"100%\", width: \"100%\",\r\n ...this.props.style,\r\n };\r\n\r\n return (\r\n <div style={parentDivStyle}>\r\n <div\r\n ref={this._viewportDiv}\r\n data-testid=\"viewport-component\"\r\n className={this.props.className}\r\n style={viewportDivStyle}\r\n onContextMenu={this._handleContextMenu}\r\n />\r\n {viewOverlay}\r\n </div>\r\n );\r\n }\r\n}\r\n"]}
1
+ {"version":3,"file":"ViewportComponent.js","sourceRoot":"","sources":["../../../../src/imodel-components-react/viewport/ViewportComponent.tsx"],"names":[],"mappings":";AAAA;;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AC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;aACxE;iBAAM;gBACL,uBAAuB;gBACvB,MAAA,iBAAiB,CAAC,OAAO,0CAAE,UAAU,CAAC,gBAAgB,CAAC,CAAC;aACzD;SACF;QACD,uDAAuD;IACzD,CAAC,EAAE,CAAC,SAAS,EAAE,gBAAgB,EAAE,WAAW,CAAC,CAAC,CAAC;IAE/C,MAAM,iBAAiB,GAAG,KAAK,CAAC,WAAW,CAAC,CAAC,CAAmB,EAAE,EAAE;QAClE,CAAC,CAAC,cAAc,EAAE,CAAC;QACnB,IAAI,aAAa;YACf,aAAa,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC,EAAE,CAAC,aAAa,CAAC,CAAC,CAAC;IAEpB,MAAM,cAAc,GAAwB;QAC1C,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,UAAU;KACpD,CAAC;IAEF,MAAM,gBAAgB,GAAwB;QAC5C,GAAG,KAAK;QACR,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;KAC9B,CAAC;IAEF,OAAO,CACL,6BAAK,KAAK,EAAE,cAAc,kBAAgB,SAAS;QAEjD;YACE,6BACE,GAAG,EAAE,WAAW,iBACJ,oBAAoB,EAChC,SAAS,EAAE,SAAS,EACpB,KAAK,EAAE,gBAAgB,EACvB,aAAa,EAAE,iBAAiB,GAChC;YACD,WAAW,CACX,CACC,CACP,CAAC;AACJ,CAAC;AA9PD,8CA8PC","sourcesContent":["/*---------------------------------------------------------------------------------------------\r\n* Copyright (c) Bentley Systems, Incorporated. All rights reserved.\r\n* See LICENSE.md in the project root for license terms and full copyright notice.\r\n*--------------------------------------------------------------------------------------------*/\r\n/** @packageDocumentation\r\n * @module Viewport\r\n */\r\n\r\nimport * as React from \"react\";\r\nimport { Id64String, Logger } from \"@itwin/core-bentley\";\r\nimport { Point3d, Transform } from \"@itwin/core-geometry\";\r\nimport { NpcCenter } from \"@itwin/core-common\";\r\nimport {\r\n IModelApp, IModelConnection, ScreenViewport,\r\n TentativePoint, ToolSettings, ViewManager,\r\n Viewport, ViewState,\r\n} from \"@itwin/core-frontend\";\r\n\r\nimport { CommonProps } from \"@itwin/core-react\";\r\nimport {\r\n CubeRotationChangeEventArgs, DrawingViewportChangeEventArgs, StandardRotationChangeEventArgs, ViewportComponentEvents,\r\n} from \"./ViewportComponentEvents\";\r\n\r\n/** Type for a ViewState prop\r\n * @public\r\n */\r\nexport type ViewStateProp = ViewState | (() => ViewState);\r\n\r\n/**\r\n * Properties for [[ViewportComponent]] component.\r\n * @public\r\n */\r\nexport interface ViewportProps extends CommonProps {\r\n /** IModel to display */\r\n imodel: IModelConnection;\r\n /** Id of a default view definition to load as a starting point */\r\n viewDefinitionId?: Id64String;\r\n /** ViewState to use as a starting point */\r\n viewState?: ViewStateProp;\r\n /** Function to get a reference to the ScreenViewport */\r\n viewportRef?: (v: ScreenViewport) => void;\r\n /** controlId for this content component @internal */\r\n controlId?: string;\r\n /** @internal */\r\n onContextMenu?: (e: React.MouseEvent) => boolean;\r\n /** @internal */\r\n getViewOverlay?: (viewport: ScreenViewport) => React.ReactNode;\r\n /** @internal used only for testing */\r\n viewManagerOverride?: ViewManager;\r\n /** @internal used only for testing */\r\n screenViewportOverride?: typeof ScreenViewport;\r\n /** @internal used only for testing */\r\n tentativePointOverride?: TentativePoint;\r\n}\r\n\r\n/**\r\n * A viewport React component that creates a ScreenViewport.\r\n * @public\r\n */\r\nexport function ViewportComponent(props: ViewportProps) {\r\n const { viewState, imodel, viewDefinitionId, getViewOverlay, viewManagerOverride,\r\n tentativePointOverride, onContextMenu, style, className, screenViewportOverride, controlId, viewportRef } = props;\r\n // istanbul ignore next\r\n const viewManagerRef = React.useRef(viewManagerOverride ?? IModelApp.viewManager);\r\n const tentativePointOverrideRef = React.useRef(tentativePointOverride);\r\n const screenViewportCreated = React.useRef(false);\r\n const viewportDiv = React.useRef<HTMLDivElement>(null);\r\n const screenViewportRef = React.useRef<ScreenViewport | null>(null);\r\n const isMounted = React.useRef(false);\r\n const viewClassFullName = React.useRef(\"\");\r\n const viewId = React.useRef(\"0\");\r\n\r\n // istanbul ignore next\r\n const handleViewChanged = (vp: Viewport) => {\r\n // istanbul ignore next\r\n if (!(vp.iModel.isOpen || vp.iModel.isBlank))\r\n return;\r\n ViewportComponentEvents.setViewMatrix(vp);\r\n if (viewClassFullName.current !== vp.view.classFullName) {\r\n setTimeout(() => {\r\n ViewportComponentEvents.onViewClassFullNameChangedEvent.emit({ viewport: vp, oldName: viewClassFullName.current, newName: vp.view.classFullName });\r\n viewClassFullName.current = vp.view.classFullName;\r\n });\r\n }\r\n if (viewId.current !== vp.view.id) {\r\n setTimeout(() => {\r\n ViewportComponentEvents.onViewIdChangedEvent.emit({ viewport: vp, oldId: viewId.current, newId: vp.view.id });\r\n viewId.current = vp.view.id;\r\n });\r\n }\r\n };\r\n\r\n const handleStandardRotationChangeEvent = (args: StandardRotationChangeEventArgs) => {\r\n const viewManager = viewManagerRef.current;\r\n const currentScreenViewport = screenViewportRef.current;\r\n if (currentScreenViewport && viewManager.selectedView === currentScreenViewport) {\r\n currentScreenViewport.view.setRotationAboutPoint(ViewState.getStandardViewMatrix(args.standardRotation));\r\n currentScreenViewport.synchWithView();\r\n }\r\n };\r\n\r\n const handleDrawingViewportChangeEvent = (args: DrawingViewportChangeEventArgs) => {\r\n const viewManager = viewManagerRef.current;\r\n const currentScreenViewport = screenViewportRef.current;\r\n if (currentScreenViewport && viewManager.selectedView === currentScreenViewport) {\r\n currentScreenViewport.view.setOrigin(args.origin);\r\n currentScreenViewport.view.setRotation(args.rotation);\r\n currentScreenViewport.synchWithView({ noSaveInUndo: args.complete !== true });\r\n }\r\n };\r\n\r\n const targetPoint = React.useRef<Point3d | null>(null);\r\n\r\n const getRotatePoint = (vp: ScreenViewport): Point3d => {\r\n const lastTargetPoint = targetPoint.current;\r\n // istanbul ignore next\r\n const tentativePoint = tentativePointOverrideRef.current ?? IModelApp.tentativePoint;\r\n // istanbul ignore else\r\n if (tentativePoint.isActive)\r\n return tentativePoint.getPoint();\r\n\r\n // istanbul ignore else\r\n if (undefined !== vp.viewCmdTargetCenter) {\r\n const testPt = vp.worldToView(vp.viewCmdTargetCenter);\r\n const viewRect = vp.viewRect;\r\n if (viewRect.containsPoint(testPt))\r\n return vp.viewCmdTargetCenter;\r\n vp.viewCmdTargetCenter = undefined;\r\n }\r\n\r\n // istanbul ignore else\r\n if (null !== lastTargetPoint) {\r\n const testPt = vp.worldToView(lastTargetPoint);\r\n const viewRect = vp.viewRect.clone();\r\n viewRect.scaleAboutCenter(0.25, 0.25);\r\n // istanbul ignore next hard to reach because of mocks\r\n if (viewRect.containsPoint(testPt))\r\n return lastTargetPoint;\r\n targetPoint.current = null;\r\n }\r\n\r\n const visiblePoint = vp.pickNearestVisibleGeometry(vp.npcToWorld(NpcCenter), vp.pixelsFromInches(ToolSettings.viewToolPickRadiusInches));\r\n targetPoint.current = (undefined !== visiblePoint ? visiblePoint : vp.view.getTargetPoint());\r\n // istanbul ignore next\r\n return targetPoint.current ?? vp.view.getCenter();\r\n };\r\n\r\n const handleCubeRotationChangeEvent = (args: CubeRotationChangeEventArgs) => {\r\n const viewManager = viewManagerRef.current;\r\n const currentScreenViewport = screenViewportRef.current;\r\n // istanbul ignore else\r\n if (currentScreenViewport && viewManager.selectedView === currentScreenViewport) {\r\n const rotMatrix = args.rotMatrix;\r\n // istanbul ignore else\r\n if (currentScreenViewport.rotation !== rotMatrix) {\r\n const inverse = rotMatrix.transpose(); // rotation is from current nav cube state...\r\n const center = getRotatePoint(currentScreenViewport);\r\n const targetMatrix = inverse.multiplyMatrixMatrix(currentScreenViewport.view.getRotation());\r\n const worldTransform = Transform.createFixedPointAndMatrix(center, targetMatrix);\r\n const frustum = currentScreenViewport.getWorldFrustum();\r\n frustum.multiply(worldTransform);\r\n currentScreenViewport.view.setupFromFrustum(frustum);\r\n currentScreenViewport.synchWithView({ noSaveInUndo: !args.complete });\r\n }\r\n }\r\n };\r\n\r\n const handleDisconnectFromViewManager = () => {\r\n const screenViewport = screenViewportRef.current;\r\n if (screenViewport) {\r\n const viewManager = IModelApp.viewManager;\r\n screenViewport.onViewChanged.removeListener(handleViewChanged);\r\n screenViewportRef.current = null;\r\n screenViewportCreated.current = false;\r\n\r\n ViewportComponentEvents.onDrawingViewportChangeEvent.removeListener(handleDrawingViewportChangeEvent);\r\n ViewportComponentEvents.onCubeRotationChangeEvent.removeListener(handleCubeRotationChangeEvent);\r\n ViewportComponentEvents.onStandardRotationChangeEvent.removeListener(handleStandardRotationChangeEvent);\r\n viewManager.dropViewport(screenViewport, true);\r\n }\r\n };\r\n\r\n const getScreenViewport = (parentDiv: HTMLDivElement, inViewState: ViewState) => {\r\n // istanbul ignore next\r\n const screenViewportFactory = screenViewportOverride ? screenViewportOverride : ScreenViewport;\r\n const parentWindow = parentDiv.ownerDocument.defaultView as Window;\r\n parentWindow.addEventListener(\"beforeunload\", handleDisconnectFromViewManager, true); // listener clear after being called\r\n ViewportComponentEvents.initialize();\r\n ViewportComponentEvents.onDrawingViewportChangeEvent.addListener(handleDrawingViewportChangeEvent);\r\n ViewportComponentEvents.onCubeRotationChangeEvent.addListener(handleCubeRotationChangeEvent);\r\n ViewportComponentEvents.onStandardRotationChangeEvent.addListener(handleStandardRotationChangeEvent);\r\n const screenViewport = screenViewportFactory.create(parentDiv, inViewState);\r\n screenViewportCreated.current = true;\r\n viewClassFullName.current = screenViewport.view.classFullName;\r\n viewId.current = screenViewport.view.id;\r\n screenViewport.onViewChanged.addListener(handleViewChanged);\r\n return screenViewport;\r\n };\r\n\r\n React.useEffect(() => {\r\n isMounted.current = true;\r\n Logger.logInfo(\"ViewportComponent\", `mounting ViewportComponent for controlId=${controlId}`);\r\n\r\n return () => {\r\n isMounted.current = false;\r\n Logger.logInfo(\"ViewportComponent\", `un-mounting ViewportComponent for controlId=${controlId}`);\r\n handleDisconnectFromViewManager();\r\n };\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, []);\r\n\r\n const [initialViewState, setInitialViewState] = React.useState<ViewState | undefined>(() => {\r\n if (viewState) {\r\n if (typeof viewState === \"function\")\r\n return viewState().clone();\r\n else\r\n return viewState.clone();\r\n }\r\n return undefined;\r\n });\r\n\r\n React.useEffect(() => {\r\n setInitialViewState(undefined);\r\n }, [viewDefinitionId, viewState]);\r\n React.useEffect(() => {\r\n async function fetchInitialViewstate() {\r\n let currentViewState: ViewState | undefined;\r\n if (viewState) {\r\n if (typeof viewState === \"function\")\r\n currentViewState = viewState();\r\n else\r\n currentViewState = viewState;\r\n } else if (viewDefinitionId && imodel) {\r\n try {\r\n currentViewState = await imodel.views.load(viewDefinitionId);\r\n // istanbul ignore next\r\n if (!currentViewState) {\r\n Logger.logError(\"ViewportComponent\", `Viewstate failed to load`);\r\n }\r\n } catch (_e) {\r\n // istanbul ignore next\r\n Logger.logError(\"ViewportComponent\", `Viewstate failed to load`);\r\n }\r\n } else {\r\n Logger.logError(\"ViewportComponent\", `A Viewstate or a viewId and imodel must be provided`);\r\n }\r\n // istanbul ignore next\r\n if (isMounted.current && (currentViewState?.iModel.isOpen || currentViewState?.iModel.isBlank)) {\r\n setInitialViewState(currentViewState?.clone());\r\n }\r\n }\r\n if (undefined === initialViewState)\r\n fetchInitialViewstate(); // eslint-disable-line @typescript-eslint/no-floating-promises\r\n }, [imodel, initialViewState, viewDefinitionId, viewState]);\r\n\r\n const [viewOverlay, setViewOverlay] = React.useState<React.ReactNode>(null);\r\n\r\n // This useEffect connects to ViewManger as soon as initialViewState is available once component is mounted.\r\n React.useEffect(() => {\r\n const parentDiv = viewportDiv.current;\r\n const viewManager = viewManagerRef.current;\r\n // istanbul ignore next\r\n if (parentDiv && initialViewState && (initialViewState?.iModel.isOpen || initialViewState?.iModel.isBlank) ) {\r\n if (!screenViewportCreated.current) {\r\n const screenViewport = getScreenViewport(parentDiv, initialViewState);\r\n screenViewportRef.current = screenViewport;\r\n\r\n if (viewportRef)\r\n viewportRef(screenViewport);\r\n\r\n Logger.logInfo(\"ViewportComponent\", `processing viewManager.addViewport for controlId=${controlId}`);\r\n viewManager.addViewport(screenViewport);\r\n\r\n // overlay component is set up once a ScreenViewport is available. The overlay component must handle any view changes itself.\r\n setViewOverlay(getViewOverlay ? getViewOverlay(screenViewport) : null);\r\n } else {\r\n // istanbul ignore next\r\n screenViewportRef.current?.changeView(initialViewState);\r\n }\r\n }\r\n // eslint-disable-next-line react-hooks/exhaustive-deps\r\n }, [controlId, initialViewState, viewportRef]);\r\n\r\n const handleContextMenu = React.useCallback((e: React.MouseEvent) => {\r\n e.preventDefault();\r\n if (onContextMenu)\r\n onContextMenu(e);\r\n }, [onContextMenu]);\r\n\r\n const parentDivStyle: React.CSSProperties = {\r\n height: \"100%\", width: \"100%\", position: \"relative\",\r\n };\r\n\r\n const viewportDivStyle: React.CSSProperties = {\r\n ...style,\r\n height: \"100%\", width: \"100%\",\r\n };\r\n\r\n return (\r\n <div style={parentDivStyle} data-item-id={controlId}\r\n >\r\n <>\r\n <div\r\n ref={viewportDiv}\r\n data-testid=\"viewport-component\"\r\n className={className}\r\n style={viewportDivStyle}\r\n onContextMenu={handleContextMenu}\r\n />\r\n {viewOverlay}\r\n </>\r\n </div>\r\n );\r\n}\r\n"]}
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import { Matrix3d, Point3d, Vector3d } from "@itwin/core-geometry";
5
5
  import { StandardViewId, Viewport } from "@itwin/core-frontend";
6
- import { UiEvent } from "@itwin/core-react";
6
+ import { UiEvent } from "@itwin/appui-abstract";
7
7
  import { Face } from "../navigationaids/Cube";
8
8
  /** Arguments for [[DrawingViewportChangeEvent]]
9
9
  * @public
@@ -1 +1 @@
1
- {"version":3,"file":"ViewportComponentEvents.d.ts","sourceRoot":"","sources":["../../../../src/imodel-components-react/viewport/ViewportComponentEvents.ts"],"names":[],"mappings":"AAIA;;GAEG;AAEH,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAA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AsB,CAAC;CAAI;AAE3E;;GAEG;AACH,qBAAa,uBAAuB;IAClC,OAAO,CAAC,MAAM,CAAC,eAAe,CAAC,CAAa;WAE9B,UAAU;IAOxB,mCAAmC;WACrB,SAAS;IAOvB,OAAc,IAAI,OAAa;IAC/B,gBAAuB,MAAM,UAAwB;IACrD,gBAAuB,OAAO,WAAyB;IACvD,gBAAuB,cAAc,WAA6B;IAClE,gBAAuB,4BAA4B,6BAAoC;IACvF,gBAAuB,yBAAyB,0BAAiC;IACjF,gBAAuB,6BAA6B,8BAAqC;IACzF,gBAAuB,yBAAyB,0BAAiC;IACjF,gBAAuB,+BAA+B,gCAAuC;IAC7F,gBAAuB,oBAAoB,qBAA4B;IAEvE,OAAO,CAAC,MAAM,CAAC,6BAA6B;WAK9B,aAAa,CAAC,SAAS,EAAE,QAAQ,EAAE,IAAI,OAAY,EAAE,QAAQ,GAAE,OAAe,GAAG,IAAI;WAMrF,uBAAuB,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,GAAE,OAAe,GAAG,IAAI;WAI7F,mBAAmB,CAAC,gBAAgB,EAAE,cAAc,GAAG,IAAI;WAI3D,aAAa,CAAC,QAAQ,EAAE,QAAQ,EAAE,aAAa,CAAC,EAAE,MAAM,GAAG,IAAI;CAa9E"}
@@ -10,42 +10,42 @@ Object.defineProperty(exports, "__esModule", { value: true });
10
10
  exports.ViewportComponentEvents = exports.ViewIdChangedEvent = exports.ViewClassFullNameChangedEvent = exports.ViewRotationChangeEvent = exports.StandardRotationChangeEvent = exports.CubeRotationChangeEvent = exports.DrawingViewportChangeEvent = void 0;
11
11
  const core_geometry_1 = require("@itwin/core-geometry");
12
12
  const core_frontend_1 = require("@itwin/core-frontend");
13
- const core_react_1 = require("@itwin/core-react");
13
+ const appui_abstract_1 = require("@itwin/appui-abstract");
14
14
  const Cube_1 = require("../navigationaids/Cube");
15
15
  /** Drawing View Change event
16
16
  * @public
17
17
  */
18
- class DrawingViewportChangeEvent extends core_react_1.UiEvent {
18
+ class DrawingViewportChangeEvent extends appui_abstract_1.UiEvent {
19
19
  }
20
20
  exports.DrawingViewportChangeEvent = DrawingViewportChangeEvent;
21
21
  /** 3d Cube Rotation Change event
22
22
  * @public
23
23
  */
24
- class CubeRotationChangeEvent extends core_react_1.UiEvent {
24
+ class CubeRotationChangeEvent extends appui_abstract_1.UiEvent {
25
25
  }
26
26
  exports.CubeRotationChangeEvent = CubeRotationChangeEvent;
27
27
  /** Standard Rotation Change event
28
28
  * @public
29
29
  */
30
- class StandardRotationChangeEvent extends core_react_1.UiEvent {
30
+ class StandardRotationChangeEvent extends appui_abstract_1.UiEvent {
31
31
  }
32
32
  exports.StandardRotationChangeEvent = StandardRotationChangeEvent;
33
33
  /** View Rotation Change event
34
34
  * @public
35
35
  */
36
- class ViewRotationChangeEvent extends core_react_1.UiEvent {
36
+ class ViewRotationChangeEvent extends appui_abstract_1.UiEvent {
37
37
  }
38
38
  exports.ViewRotationChangeEvent = ViewRotationChangeEvent;
39
39
  /** View Class Full Name Change event
40
40
  * @public
41
41
  */
42
- class ViewClassFullNameChangedEvent extends core_react_1.UiEvent {
42
+ class ViewClassFullNameChangedEvent extends appui_abstract_1.UiEvent {
43
43
  }
44
44
  exports.ViewClassFullNameChangedEvent = ViewClassFullNameChangedEvent;
45
45
  /** View Id Change event
46
46
  * @public
47
47
  */
48
- class ViewIdChangedEvent extends core_react_1.UiEvent {
48
+ class ViewIdChangedEvent extends appui_abstract_1.UiEvent {
49
49
  }
50
50
  exports.ViewIdChangedEvent = ViewIdChangedEvent;
51
51
  /** Viewport Rotation events and methods
@@ -82,6 +82,7 @@ class ViewportComponentEvents {
82
82
  static setViewMatrix(viewport, animationTime) {
83
83
  // When handling onViewChanged, use setTimeout
84
84
  setTimeout(() => {
85
+ // istanbul ignore next
85
86
  if (viewport.view) {
86
87
  this.origin.setFrom(viewport.view.getOrigin());
87
88
  this.extents.setFrom(viewport.view.getExtents());