@@ -150,47 +150,25 @@ function rebindAllGlyphs(labelCollection, label) {
150150 // presize glyphs to match the new text length
151151 glyphs . length = textLength ;
152152
153- const showBackground =
154- label . show && label . _showBackground && text . split ( "\n" ) . join ( "" ) . length > 0 ;
155153 let backgroundBillboard = label . _backgroundBillboard ;
156154 const backgroundBillboardCollection =
157155 labelCollection . _backgroundBillboardCollection ;
158- if ( ! showBackground ) {
159- if ( defined ( backgroundBillboard ) ) {
160- backgroundBillboardCollection . remove ( backgroundBillboard ) ;
161- label . _backgroundBillboard = backgroundBillboard = undefined ;
162- }
163- } else {
164- if ( ! defined ( backgroundBillboard ) ) {
165- backgroundBillboard = getWhitePixelBillboard (
166- backgroundBillboardCollection ,
167- labelCollection ,
168- ) ;
169- label . _backgroundBillboard = backgroundBillboard ;
170- }
171156
172- backgroundBillboard . color = label . _backgroundColor ;
173- backgroundBillboard . show = label . _show ;
174- backgroundBillboard . position = label . _position ;
175- backgroundBillboard . eyeOffset = label . _eyeOffset ;
176- backgroundBillboard . pixelOffset = label . _pixelOffset ;
177- backgroundBillboard . horizontalOrigin = HorizontalOrigin . LEFT ;
178- backgroundBillboard . verticalOrigin = label . _verticalOrigin ;
179- backgroundBillboard . heightReference = label . _heightReference ;
180- backgroundBillboard . scale = label . totalScale ;
181- backgroundBillboard . pickPrimitive = label ;
182- backgroundBillboard . id = label . _id ;
183- backgroundBillboard . translucencyByDistance = label . _translucencyByDistance ;
184- backgroundBillboard . pixelOffsetScaleByDistance =
185- label . _pixelOffsetScaleByDistance ;
186- backgroundBillboard . scaleByDistance = label . _scaleByDistance ;
187- backgroundBillboard . distanceDisplayCondition =
188- label . _distanceDisplayCondition ;
189- backgroundBillboard . disableDepthTestDistance =
190- label . _disableDepthTestDistance ;
191- backgroundBillboard . clusterShow = label . clusterShow ;
157+ // Create backgroundBillboard if needed
158+ if ( label . _showBackground && ! defined ( backgroundBillboard ) ) {
159+ backgroundBillboard = getWhitePixelBillboard (
160+ backgroundBillboardCollection ,
161+ labelCollection ,
162+ ) ;
163+ label . _backgroundBillboard = backgroundBillboard ;
192164 }
193165
166+ updateBackgroundBillboard (
167+ backgroundBillboardCollection ,
168+ label ,
169+ backgroundBillboard ,
170+ ) ;
171+
194172 const glyphBillboardCollection = labelCollection . _glyphBillboardCollection ;
195173 const glyphTextureCache = glyphBillboardCollection . billboardTextureCache ;
196174 const textDimensionsCache = labelCollection . _textDimensionsCache ;
@@ -335,6 +313,47 @@ function rebindAllGlyphs(labelCollection, label) {
335313 label . _repositionAllGlyphs = true ;
336314}
337315
316+ function updateBackgroundBillboard (
317+ backgroundBillboardCollection ,
318+ label ,
319+ backgroundBillboard ,
320+ ) {
321+ if ( ! defined ( backgroundBillboard ) ) {
322+ return ;
323+ }
324+ const showBackground =
325+ label . show &&
326+ label . _showBackground &&
327+ label . _renderedText . split ( "\n" ) . join ( "" ) . length > 0 ;
328+ // Label is shown and background is hidden - remove the background billboard
329+ if ( label . show && ! showBackground ) {
330+ backgroundBillboardCollection . remove ( backgroundBillboard ) ;
331+ label . _backgroundBillboard = backgroundBillboard = undefined ;
332+ return ;
333+ }
334+
335+ backgroundBillboard . color = label . _backgroundColor ;
336+ backgroundBillboard . show = label . _show ;
337+ backgroundBillboard . position = label . _position ;
338+ backgroundBillboard . eyeOffset = label . _eyeOffset ;
339+ backgroundBillboard . pixelOffset = label . _pixelOffset ;
340+ backgroundBillboard . horizontalOrigin = HorizontalOrigin . LEFT ;
341+ backgroundBillboard . verticalOrigin = label . _verticalOrigin ;
342+ backgroundBillboard . heightReference = label . _heightReference ;
343+ backgroundBillboard . scale = label . totalScale ;
344+ backgroundBillboard . pickPrimitive = label ;
345+ backgroundBillboard . id = label . _id ;
346+ backgroundBillboard . translucencyByDistance = label . _translucencyByDistance ;
347+ backgroundBillboard . pixelOffsetScaleByDistance =
348+ label . _pixelOffsetScaleByDistance ;
349+ backgroundBillboard . scaleByDistance = label . _scaleByDistance ;
350+ backgroundBillboard . distanceDisplayCondition =
351+ label . _distanceDisplayCondition ;
352+ backgroundBillboard . disableDepthTestDistance =
353+ label . _disableDepthTestDistance ;
354+ backgroundBillboard . clusterShow = label . clusterShow ;
355+ }
356+
338357function calculateWidthOffset ( lineWidth , horizontalOrigin , backgroundPadding ) {
339358 if ( horizontalOrigin === HorizontalOrigin . CENTER ) {
340359 return - lineWidth / 2 ;
@@ -507,7 +526,6 @@ function repositionAllGlyphs(label) {
507526 glyphPixelOffset . y = 0 ;
508527 }
509528 glyphPixelOffset . y = glyphPixelOffset . y * scale ;
510-
511529 backgroundBillboard . width = totalLineWidth ;
512530 backgroundBillboard . height = totalLineHeight ;
513531 backgroundBillboard . _setTranslate ( glyphPixelOffset ) ;
0 commit comments