Skip to content

Commit 7a41aaf

Browse files
authored
Merge pull request #1841 from xeokit/XCD-267-large-number-of-annotations
XCD-267 Implement "legacy" annotation alignment for the large number of annotations case
2 parents 0261ffb + e2cec58 commit 7a41aaf

File tree

1 file changed

+28
-16
lines changed

1 file changed

+28
-16
lines changed

src/plugins/AnnotationsPlugin/Annotation.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ const tempVec3a = math.vec3();
77
const tempVec3b = math.vec3();
88
const tempVec3c = math.vec3();
99

10+
const px = x => x + "px";
11+
1012
/**
1113
* A {@link Marker} with an HTML label attached to it, managed by an {@link AnnotationsPlugin}.
1214
*
@@ -213,22 +215,29 @@ class Annotation extends Marker {
213215
* @private
214216
*/
215217
_updateWithCurWidths() {
216-
const px = x => x + "px";
217218
const boundary = this.scene.canvas.boundary;
218219
const left = boundary[0] + this.canvasPos[0];
219220
const top = boundary[1] + this.canvasPos[1];
220-
const markerWidth = this._curMarkerWidth;
221-
const markerDir = (this._markerAlign === "right") ? -1 : ((this._markerAlign === "center") ? 0 : 1);
222-
const markerCenter = left + markerDir * (markerWidth / 2 - 12);
223-
this._marker.style.left = px(markerCenter - markerWidth / 2);
224-
this._marker.style.top = px(top - 12);
225-
this._marker.style["z-index"] = 90005 + Math.floor(this._viewPos[2]) + 1;
226-
227-
const labelWidth = this._curLabelWidth;
228-
const labelDir = Math.sign(this._labelPosition);
229-
this._label.style.left = px(markerCenter + labelDir * (markerWidth / 2 + Math.abs(this._labelPosition) + labelWidth / 2) - labelWidth / 2);
221+
this._marker.style.top = px(top - 12);
230222
this._label.style.top = px(top - 17);
231-
this._label.style["z-index"] = 90005 + Math.floor(this._viewPos[2]) + 1;
223+
224+
if (this._markerAlign === "legacy") {
225+
this._marker.style.left = px(left - 12);
226+
this._label.style.left = px(left + 40);
227+
} else {
228+
const markerWidth = this._curMarkerWidth;
229+
const markerDir = (this._markerAlign === "right") ? -1 : ((this._markerAlign === "center") ? 0 : 1);
230+
const markerCenter = left + markerDir * (markerWidth / 2 - 12);
231+
this._marker.style.left = px(markerCenter - markerWidth / 2);
232+
233+
const labelWidth = this._curLabelWidth;
234+
const labelDir = Math.sign(this._labelPosition);
235+
this._label.style.left = px(markerCenter + labelDir * (markerWidth / 2 + Math.abs(this._labelPosition) + labelWidth / 2) - labelWidth / 2);
236+
}
237+
238+
const zIndex = 90005 + Math.floor(this._viewPos[2]) + 1;
239+
this._marker.style["z-index"] = zIndex;
240+
this._label.style["z-index"] = zIndex;
232241
}
233242

234243
/**
@@ -259,15 +268,18 @@ class Annotation extends Marker {
259268
* @private
260269
*/
261270
_updatePosition() {
262-
if (this._curMarkerWidth === undefined) {
271+
const isLegacy = this._markerAlign === "legacy";
272+
if ((! isLegacy) && (this._curMarkerWidth === undefined)) {
263273
this._updateIfWidthsChanged();
264274
} else {
265275
// Update position with cached width values
266276
// and postpone expensive Annotation's getBoundingClientRect calls
267277
// so they don't interfere with e.g. interactive scene manipulation
268278
this._updateWithCurWidths();
269279
window.clearTimeout(this._widthTimeout);
270-
this._widthTimeout = window.setTimeout(() => this._updateIfWidthsChanged(), 500);
280+
if (! isLegacy) {
281+
this._widthTimeout = window.setTimeout(() => this._updateIfWidthsChanged(), 500);
282+
}
271283
}
272284
}
273285

@@ -305,10 +317,10 @@ class Annotation extends Marker {
305317
/**
306318
* Sets the horizontal alignment of the Annotation's marker HTML.
307319
*
308-
* @param {String} align Either "left", "center", "right" (default "left")
320+
* @param {String} align Either "left", "center", "right", "legacy" (default "left")
309321
*/
310322
setMarkerAlign(align) {
311-
const valid = [ "left", "center", "right" ];
323+
const valid = [ "left", "center", "right", "legacy" ];
312324
if (! valid.includes(align)) {
313325
this.error("Param 'align' should be one of: " + JSON.stringify(valid));
314326
} else {

0 commit comments

Comments
 (0)