@xeokit/xeokit-sdk 2.6.25 → 2.6.26

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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xeokit/xeokit-sdk",
3
- "version": "2.6.25",
3
+ "version": "2.6.26",
4
4
  "description": "Web Programming Toolkit for 3D/2D BIM and AEC Graphics",
5
5
  "module": "./dist/xeokit-sdk.es.js",
6
6
  "main": "./dist/xeokit-sdk.cjs.js",
@@ -75,6 +75,7 @@ class Annotation extends Marker {
75
75
  this._values = cfg.values || {};
76
76
  this._layoutDirty = true;
77
77
  this._visibilityDirty = true;
78
+ this._labelPosition = 24;
78
79
 
79
80
  this._buildHTML();
80
81
 
@@ -205,17 +206,23 @@ class Annotation extends Marker {
205
206
  * @private
206
207
  */
207
208
  _updatePosition() {
209
+ const px = x => x + "px";
208
210
  const boundary = this.scene.canvas.boundary;
209
- const left = boundary[0];
210
- const top = boundary[1];
211
- const canvasPos = this.canvasPos;
212
- this._marker.style.left = (Math.floor(left + canvasPos[0]) - 12) + "px";
213
- this._marker.style.top = (Math.floor(top + canvasPos[1]) - 12) + "px";
211
+ const left = boundary[0] + this.canvasPos[0];
212
+ const top = boundary[1] + this.canvasPos[1];
213
+ const markerRect = this._marker.getBoundingClientRect();
214
+ const markerWidth = markerRect.width;
215
+ const markerDir = (this._markerAlign === "right") ? -1 : ((this._markerAlign === "center") ? 0 : 1);
216
+ const markerCenter = left + markerDir * (markerWidth / 2 - 12);
217
+ this._marker.style.left = px(markerCenter - markerWidth / 2);
218
+ this._marker.style.top = px(top - 12);
214
219
  this._marker.style["z-index"] = 90005 + Math.floor(this._viewPos[2]) + 1;
215
- const offsetX = 20;
216
- const offsetY = -17;
217
- this._label.style.left = 20 + Math.floor(left + canvasPos[0] + offsetX) + "px";
218
- this._label.style.top = Math.floor(top + canvasPos[1] + offsetY) + "px";
220
+
221
+ const labelRect = this._label.getBoundingClientRect();
222
+ const labelWidth = labelRect.width;
223
+ const labelDir = Math.sign(this._labelPosition);
224
+ this._label.style.left = px(markerCenter + labelDir * (markerWidth / 2 + Math.abs(this._labelPosition) + labelWidth / 2) - labelWidth / 2);
225
+ this._label.style.top = px(top - 17);
219
226
  this._label.style["z-index"] = 90005 + Math.floor(this._viewPos[2]) + 1;
220
227
  }
221
228
 
@@ -250,6 +257,37 @@ class Annotation extends Marker {
250
257
  }
251
258
  }
252
259
 
260
+ /**
261
+ * Sets the horizontal alignment of the Annotation's marker HTML.
262
+ *
263
+ * @param {String} align Either "left", "center", "right" (default "left")
264
+ */
265
+ setMarkerAlign(align) {
266
+ const valid = [ "left", "center", "right" ];
267
+ if (! valid.includes(align)) {
268
+ this.error("Param 'align' should be one of: " + JSON.stringify(valid));
269
+ } else {
270
+ this._markerAlign = align;
271
+ this._updatePosition();
272
+ }
273
+ }
274
+
275
+ /**
276
+ * Sets the relative horizontal position of the Annotation's label HTML.
277
+ *
278
+ * @param {Number} position Negative - to the left, positive - to the right, otherwise ignore (default 24)
279
+ */
280
+ setLabelPosition(position) {
281
+ if (typeof position !== "number") {
282
+ this.error("Param 'position' is not a number");
283
+ } else if (position === 0) {
284
+ this.error("Param 'position' is zero");
285
+ } else {
286
+ this._labelPosition = position;
287
+ this._updatePosition();
288
+ }
289
+ }
290
+
253
291
  /**
254
292
  * Sets whether or not to show this Annotation's marker.
255
293
  *
@@ -649,6 +649,8 @@ class CameraControl extends Component {
649
649
  snapToEdge: DEFAULT_SNAP_EDGE,
650
650
  snapRadius: DEFAULT_SNAP_PICK_RADIUS,
651
651
 
652
+ keyboardEnabledOnlyIfMouseover: true,
653
+
652
654
  // Rotation
653
655
 
654
656
  dragRotationRate: 360.0,
@@ -959,6 +961,24 @@ class CameraControl extends Component {
959
961
  get snapRadius() {
960
962
  return this._configs.snapRadius;
961
963
  }
964
+
965
+ /**
966
+ * If `true`, the keyboard shortcuts are enabled ONLY if the mouse is over the canvas.
967
+ *
968
+ * @param {boolean} value
969
+ */
970
+ set keyboardEnabledOnlyIfMouseover(value) {
971
+ this._configs.keyboardEnabledOnlyIfMouseover = !!value;
972
+ }
973
+
974
+ /**
975
+ * Gets whether the keyboard shortcuts are enabled ONLY if the mouse is over the canvas or ALWAYS.
976
+ *
977
+ * @returns {boolean}
978
+ */
979
+ get keyboardEnabledOnlyIfMouseover() {
980
+ return this._configs.keyboardEnabledOnlyIfMouseover;
981
+ }
962
982
 
963
983
  /**
964
984
  * Sets the current navigation mode.
@@ -29,7 +29,7 @@ class KeyboardAxisViewHandler {
29
29
  return;
30
30
  }
31
31
 
32
- if (!states.mouseover) {
32
+ if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) {
33
33
  return;
34
34
  }
35
35
 
@@ -22,7 +22,7 @@ class KeyboardPanRotateDollyHandler {
22
22
  if (!(configs.active && configs.pointerEnabled) || (!scene.input.keyboardEnabled)) {
23
23
  return;
24
24
  }
25
- if (!states.mouseover) {
25
+ if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) {
26
26
  return;
27
27
  }
28
28
  keyDownMap[keyCode] = true;
@@ -53,7 +53,7 @@ class KeyboardPanRotateDollyHandler {
53
53
  return;
54
54
  }
55
55
 
56
- if (!states.mouseover) {
56
+ if (configs.keyboardEnabledOnlyIfMouseover && !states.mouseover) {
57
57
  return;
58
58
  }
59
59
 
@@ -2099,10 +2099,10 @@ class Scene extends Component {
2099
2099
  */
2100
2100
  get center() {
2101
2101
  if (this._aabbDirty || !this._center) {
2102
- if (!this._center || !this._center) {
2102
+ const aabb = this.aabb;
2103
+ if (!this._center) {
2103
2104
  this._center = math.vec3();
2104
2105
  }
2105
- const aabb = this.aabb;
2106
2106
  this._center[0] = (aabb[0] + aabb[3]) / 2;
2107
2107
  this._center[1] = (aabb[1] + aabb[4]) / 2;
2108
2108
  this._center[2] = (aabb[2] + aabb[5]) / 2;
@@ -2177,6 +2177,7 @@ class Scene extends Component {
2177
2177
  this._aabb[4] = ymax;
2178
2178
  this._aabb[5] = zmax;
2179
2179
  this._aabbDirty = false;
2180
+ this._center = null;
2180
2181
  }
2181
2182
  return this._aabb;
2182
2183
  }
@@ -2832,4 +2833,4 @@ class Scene extends Component {
2832
2833
  }
2833
2834
  }
2834
2835
 
2835
- export {Scene};
2836
+ export {Scene};
@@ -17,6 +17,58 @@ export declare type AngleMeasurementsPluginConfiguration = {
17
17
  zIndex?: number;
18
18
  };
19
19
 
20
+ /**
21
+ * Event fire by {@link AngleMeasurementsPlugin} when mouse enters over an {@link AngleMeasurement}.
22
+ */
23
+ export declare type AngleMeasurementMouseOverEvent = {
24
+
25
+ /**
26
+ * The plugin.
27
+ */
28
+ plugin: AngleMeasurementsPlugin;
29
+
30
+ /**
31
+ * The measurement.
32
+ */
33
+ angleMeasurement: AngleMeasurement;
34
+
35
+ /**
36
+ * The measurement.
37
+ */
38
+ measurement: AngleMeasurement;
39
+
40
+ /**
41
+ * The original mouse event.
42
+ */
43
+ event: MouseEvent;
44
+ }
45
+
46
+ /**
47
+ * Event fire by {@link AngleMeasurementsPlugin} when mouse leaves an {@link AngleMeasurement}.
48
+ */
49
+ export declare type AngleMeasurementMouseLeaveEvent = {
50
+
51
+ /**
52
+ * The plugin.
53
+ */
54
+ plugin: AngleMeasurementsPlugin;
55
+
56
+ /**
57
+ * The measurement.
58
+ */
59
+ angleMeasurement: AngleMeasurement;
60
+
61
+ /**
62
+ * The measurement.
63
+ */
64
+ measurement: AngleMeasurement;
65
+
66
+ /**
67
+ * The original mouse event.
68
+ */
69
+ event: MouseEvent;
70
+ }
71
+
20
72
  /**
21
73
  * {@link Viewer} plugin for measuring angles.
22
74
  */
@@ -87,7 +139,35 @@ export declare class AngleMeasurementsPlugin extends Plugin {
87
139
  */
88
140
  clear(): void;
89
141
 
90
- /**
142
+ /**
143
+ * Fires when mouse is over a measurement.
144
+ * @param {String} event The mouseOver event
145
+ * @param {Function} callback Callback fired on the event
146
+ */
147
+ on(event: "mouseOver", callback: (event: AngleMeasurementMouseOverEvent)=> void): string;
148
+
149
+ /**
150
+ * Fires when mouse leaves a measurement.
151
+ * @param {String} event The mouseLeave event
152
+ * @param {Function} callback Callback fired on the event
153
+ */
154
+ on(event: "mouseLeave", callback: (event: AngleMeasurementMouseLeaveEvent)=> void): string;
155
+
156
+ /**
157
+ * Fires when a context menu is to be opened on a measurement.
158
+ * @param {String} event The contextMenu event
159
+ * @param {Function} callback Callback fired on the event
160
+ */
161
+ on(event: "contextMenu", callback: (measurement: AngleMeasurement)=> void): string;
162
+
163
+ /**
164
+ * Fires when a measurement is completed.
165
+ * @param {String} event The measurementEnd event
166
+ * @param {Function} callback Callback fired on the event
167
+ */
168
+ on(event: "measurementStart", callback: (measurement: AngleMeasurement)=> void): string;
169
+
170
+ /**
91
171
  * Fires when a measurement is created.
92
172
  * @param {String} event The measurementCreated event
93
173
  * @param {Function} callback Callback fired on the event
@@ -38,6 +38,59 @@ export declare type DistanceMeasurementsPluginConfiguration = {
38
38
  zIndex?: number;
39
39
  };
40
40
 
41
+
42
+ /**
43
+ * Event fire by {@link DistanceMeasurementsPlugin} when mouse enters over a {@link DistanceMeasurement}.
44
+ */
45
+ export declare type DistanceMeasurementMouseOverEvent = {
46
+
47
+ /**
48
+ * The plugin.
49
+ */
50
+ plugin: DistanceMeasurementsPlugin;
51
+
52
+ /**
53
+ * The measurement.
54
+ */
55
+ angleMeasurement: DistanceMeasurement;
56
+
57
+ /**
58
+ * The measurement.
59
+ */
60
+ measurement: DistanceMeasurement;
61
+
62
+ /**
63
+ * The original mouse event.
64
+ */
65
+ event: MouseEvent;
66
+ }
67
+
68
+ /**
69
+ * Event fire by {@link DistanceMeasurementsPlugin} when mouse leaves a {@link DistanceMeasurement}.
70
+ */
71
+ export declare type DistanceMeasurementMouseLeaveEvent = {
72
+
73
+ /**
74
+ * The plugin.
75
+ */
76
+ plugin: DistanceMeasurementsPlugin;
77
+
78
+ /**
79
+ * The measurement.
80
+ */
81
+ angleMeasurement: DistanceMeasurement;
82
+
83
+ /**
84
+ * The measurement.
85
+ */
86
+ measurement: DistanceMeasurement;
87
+
88
+ /**
89
+ * The original mouse event.
90
+ */
91
+ event: MouseEvent;
92
+ }
93
+
41
94
  /**
42
95
  * {@link Viewer} plugin for measuring point-to-point distances.
43
96
  */
@@ -134,6 +187,27 @@ export declare class DistanceMeasurementsPlugin extends Plugin {
134
187
  */
135
188
  clear(): void;
136
189
 
190
+ /**
191
+ * Fires when mouse is over a measurement.
192
+ * @param {String} event The mouseOver event
193
+ * @param {Function} callback Callback fired on the event
194
+ */
195
+ on(event: "mouseOver", callback: (event: DistanceMeasurementMouseOverEvent)=> void): string;
196
+
197
+ /**
198
+ * Fires when mouse leaves a measurement.
199
+ * @param {String} event The mouseLeave event
200
+ * @param {Function} callback Callback fired on the event
201
+ */
202
+ on(event: "mouseLeave", callback: (event: DistanceMeasurementMouseLeaveEvent)=> void): string;
203
+
204
+ /**
205
+ * Fires when a context menu is to be opened on a measurement.
206
+ * @param {String} event The contextMenu event
207
+ * @param {Function} callback Callback fired on the event
208
+ */
209
+ on(event: "contextMenu", callback: (measurement: DistanceMeasurement)=> void): string;
210
+
137
211
  /**
138
212
  * Fires when a measurement is created.
139
213
  * @param {String} event The measurementCreated event
@@ -141,6 +215,13 @@ export declare class DistanceMeasurementsPlugin extends Plugin {
141
215
  */
142
216
  on(event: "measurementCreated", callback: (measurement: DistanceMeasurement)=> void): string;
143
217
 
218
+ /**
219
+ * Fires when a measurement is completed.
220
+ * @param {String} event The measurementEnd event
221
+ * @param {Function} callback Callback fired on the event
222
+ */
223
+ on(event: "measurementStart", callback: (measurement: DistanceMeasurement)=> void): string;
224
+
144
225
  /**
145
226
  * Fires when a measurement is completed.
146
227
  * @param {String} event The measurementEnd event