@xeokit/xeokit-sdk 2.6.91 → 2.6.92

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.91",
3
+ "version": "2.6.92",
4
4
  "description": "3D BIM IFC Viewer SDK for AEC engineering applications. Open Source JavaScript Toolkit based on pure WebGL for top performance, real-world coordinates and full double precision",
5
5
  "module": "./dist/xeokit-sdk.es.js",
6
6
  "main": "./dist/xeokit-sdk.cjs.js",
@@ -60,6 +60,9 @@ class AngleMeasurement extends Component {
60
60
 
61
61
  this.approximate = cfg.approximate;
62
62
 
63
+ this._labelStringFormat = (angle) => {
64
+ return (this._approximate ? " ~ " : " = ") + angle.toFixed(2) + "°";
65
+ };
63
66
 
64
67
  const canvas = scene.canvas.canvas;
65
68
 
@@ -181,7 +184,7 @@ class AngleMeasurement extends Component {
181
184
  math.normalizeVec3(tmpVec3a);
182
185
  math.normalizeVec3(tmpVec3b);
183
186
  this._angle = Math.abs(math.angleVec3(tmpVec3a, tmpVec3b)) * math.RADTODEG;
184
- this._angleLabel.setText((this._approximate ? " ~ " : " = ") + this._angle.toFixed(2) + "°");
187
+ this._angleLabel.setText(this._labelStringFormat(this._angle));
185
188
  } else {
186
189
  this._angle = undefined;
187
190
  this._angleLabel.setText("");
@@ -441,6 +444,23 @@ class AngleMeasurement extends Component {
441
444
  this._drawables.forEach(d => d.setClickable(this._clickable.get()));
442
445
  }
443
446
 
447
+ /**
448
+ * Gets the function that formats the angle label's text.
449
+ *
450
+ * By default, this function formats the angle with two decimal places.
451
+ */
452
+ get labelStringFormat() {
453
+ return this._labelStringFormat;
454
+ }
455
+
456
+ /**
457
+ * Sets the function that formats the angle label's text.
458
+ */
459
+ set labelStringFormat(value) {
460
+ this._labelStringFormat = value;
461
+ this._update();
462
+ }
463
+
444
464
  /**
445
465
  * Gets if the wires, dots ad labels will fire "mouseOver" "mouseLeave" and "contextMenu" events.
446
466
  *
@@ -72,6 +72,13 @@ class DistanceMeasurement extends Component {
72
72
  this._axesBasis = math.identityMat4();
73
73
  this.approximate = cfg.approximate;
74
74
 
75
+ this._labelStringFormat = (len) => {
76
+ const metrics = this.plugin.viewer.scene.metrics;
77
+ const scale = metrics.scale;
78
+ const unit = metrics.unitsInfo[metrics.units].abbrev;
79
+
80
+ return (this.approximate ? " ~ " : " = ") + (len * scale).toFixed(2) + unit;
81
+ };
75
82
 
76
83
  const canvas = scene.canvas.canvas;
77
84
 
@@ -209,24 +216,24 @@ class DistanceMeasurement extends Component {
209
216
  label.setPosOnWire(p0, p1, offsetIdx * 35, 0);
210
217
  }
211
218
  };
212
- const unitStr = len => (this._approximate ? " ~ " : " = ") + len.toFixed(2) + unit;
213
219
 
214
220
  this._xAxisWire.setEnds(p0, xEnd);
215
221
  setAxisLabelCoords(this._xAxisLabel, p0, xEnd, 1);
216
- this._xAxisLabel.setText("X" + unitStr(math.distVec3(p0, xEnd) * scale));
222
+ this._xAxisLabel.setText("X" + this._labelStringFormat(math.distVec3(p0, xEnd)));
217
223
 
218
224
  this._yAxisWire.setEnds(xEnd, zStart);
219
225
  setAxisLabelCoords(this._yAxisLabel, xEnd, zStart, 2);
220
- this._yAxisLabel.setText("Y" + unitStr(math.distVec3(xEnd, zStart) * scale));
226
+ this._yAxisLabel.setText("Y" + this._labelStringFormat(math.distVec3(xEnd, zStart)));
221
227
 
222
228
  this._zAxisWire.setEnds(zStart, p1);
223
229
  setAxisLabelCoords(this._zAxisLabel, zStart, p1, 3);
224
- this._zAxisLabel.setText((measurementOrientationVertical ? "" : "Z") + unitStr(math.distVec3(zStart, p1) * scale));
230
+ this._zAxisLabel.setText((measurementOrientationVertical ? "" : "Z") + this._labelStringFormat(math.distVec3(zStart, p1)));
225
231
 
226
232
  this._lengthWire.setEnds(p0, p1);
227
233
  setAxisLabelCoords(this._lengthLabel, p0, p1, 0);
228
- this._length = math.distVec3(p0, p1) * scale;
229
- this._lengthLabel.setText(unitStr(this._length));
234
+ const length = math.distVec3(p0, p1);
235
+ this._length = length * scale;
236
+ this._lengthLabel.setText(this._labelStringFormat(length));
230
237
  };
231
238
 
232
239
  if (measurementOrientationVertical) {
@@ -679,6 +686,25 @@ class DistanceMeasurement extends Component {
679
686
  return this._clickable.get();
680
687
  }
681
688
 
689
+ /**
690
+ * Sets the function to format unit strings.
691
+ *
692
+ * @type {Function}
693
+ */
694
+ set labelStringFormat(value) {
695
+ this._labelStringFormat = value;
696
+ this._update();
697
+ }
698
+
699
+ /**
700
+ * Gets the function to format unit strings.
701
+ *
702
+ * @type {Function}
703
+ */
704
+ get labelStringFormat() {
705
+ return this._labelStringFormat;
706
+ }
707
+
682
708
  /**
683
709
  * @private
684
710
  */