@@ -7,6 +7,8 @@ const tempVec3a = math.vec3();
7
7
const tempVec3b = math . vec3 ( ) ;
8
8
const tempVec3c = math . vec3 ( ) ;
9
9
10
+ const px = x => x + "px" ;
11
+
10
12
/**
11
13
* A {@link Marker} with an HTML label attached to it, managed by an {@link AnnotationsPlugin}.
12
14
*
@@ -213,22 +215,29 @@ class Annotation extends Marker {
213
215
* @private
214
216
*/
215
217
_updateWithCurWidths ( ) {
216
- const px = x => x + "px" ;
217
218
const boundary = this . scene . canvas . boundary ;
218
219
const left = boundary [ 0 ] + this . canvasPos [ 0 ] ;
219
220
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 ) ;
230
222
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 ;
232
241
}
233
242
234
243
/**
@@ -259,15 +268,18 @@ class Annotation extends Marker {
259
268
* @private
260
269
*/
261
270
_updatePosition ( ) {
262
- if ( this . _curMarkerWidth === undefined ) {
271
+ const isLegacy = this . _markerAlign === "legacy" ;
272
+ if ( ( ! isLegacy ) && ( this . _curMarkerWidth === undefined ) ) {
263
273
this . _updateIfWidthsChanged ( ) ;
264
274
} else {
265
275
// Update position with cached width values
266
276
// and postpone expensive Annotation's getBoundingClientRect calls
267
277
// so they don't interfere with e.g. interactive scene manipulation
268
278
this . _updateWithCurWidths ( ) ;
269
279
window . clearTimeout ( this . _widthTimeout ) ;
270
- this . _widthTimeout = window . setTimeout ( ( ) => this . _updateIfWidthsChanged ( ) , 500 ) ;
280
+ if ( ! isLegacy ) {
281
+ this . _widthTimeout = window . setTimeout ( ( ) => this . _updateIfWidthsChanged ( ) , 500 ) ;
282
+ }
271
283
}
272
284
}
273
285
@@ -305,10 +317,10 @@ class Annotation extends Marker {
305
317
/**
306
318
* Sets the horizontal alignment of the Annotation's marker HTML.
307
319
*
308
- * @param {String } align Either "left", "center", "right" (default "left")
320
+ * @param {String } align Either "left", "center", "right", "legacy" (default "left")
309
321
*/
310
322
setMarkerAlign ( align ) {
311
- const valid = [ "left" , "center" , "right" ] ;
323
+ const valid = [ "left" , "center" , "right" , "legacy" ] ;
312
324
if ( ! valid . includes ( align ) ) {
313
325
this . error ( "Param 'align' should be one of: " + JSON . stringify ( valid ) ) ;
314
326
} else {
0 commit comments