diff --git a/src/symbol/placement.js b/src/symbol/placement.js index 474da058c94..88836c44dff 100644 --- a/src/symbol/placement.js +++ b/src/symbol/placement.js @@ -239,7 +239,7 @@ export class Placement { attemptAnchorPlacement(anchor: TextAnchor, textBox: SingleCollisionBox, width: number, height: number, textBoxScale: number, rotateWithMap: boolean, pitchWithMap: boolean, textPixelRatio: number, posMatrix: mat4, collisionGroup: CollisionGroup, - textAllowOverlap: boolean, symbolInstance: SymbolInstance, bucket: SymbolBucket, orientation: number): ?{ shift: Point, placedGlyphBoxes: { box: Array, offscreen: boolean } } { + textAllowOverlap: boolean, symbolInstance: SymbolInstance, bucket: SymbolBucket, orientation: number, iconBox: ?SingleCollisionBox): ?{ shift: Point, placedGlyphBoxes: { box: Array, offscreen: boolean } } { const textOffset = [symbolInstance.textOffset0, symbolInstance.textOffset1]; const shift = calculateVariableLayoutShift(anchor, width, height, textOffset, textBoxScale); @@ -250,6 +250,15 @@ export class Placement { rotateWithMap, pitchWithMap, this.transform.angle), textAllowOverlap, textPixelRatio, posMatrix, collisionGroup.predicate); + if (iconBox) { + const placedIconBoxes = this.collisionIndex.placeCollisionBox( + shiftVariableCollisionBox( + iconBox, shift.x, shift.y, + rotateWithMap, pitchWithMap, this.transform.angle), + textAllowOverlap, textPixelRatio, posMatrix, collisionGroup.predicate); + if (placedIconBoxes.box.length === 0) return; + } + if (placedGlyphBoxes.box.length > 0) { let prevAnchor; // If this label was placed in the previous placement, record the anchor position @@ -420,11 +429,13 @@ export class Placement { } } - const placeBoxForVariableAnchors = (collisionTextBox, orientation) => { + const placeBoxForVariableAnchors = (collisionTextBox, collisionIconBox, orientation) => { const width = collisionTextBox.x2 - collisionTextBox.x1; const height = collisionTextBox.y2 - collisionTextBox.y1; const textBoxScale = symbolInstance.textBoxScale; + const variableIconBox = hasIconTextFit && !iconAllowOverlap ? collisionIconBox : null; + let placedBox: ?{ box: Array, offscreen: boolean } = {box: [], offscreen: false}; const placementAttempts = textAllowOverlap ? anchors.length * 2 : anchors.length; for (let i = 0; i < placementAttempts; ++i) { @@ -433,7 +444,7 @@ export class Placement { const result = this.attemptAnchorPlacement( anchor, collisionTextBox, width, height, textBoxScale, rotateWithMap, pitchWithMap, textPixelRatio, posMatrix, - collisionGroup, allowOverlap, symbolInstance, bucket, orientation); + collisionGroup, allowOverlap, symbolInstance, bucket, orientation, variableIconBox); if (result) { placedBox = result.placedGlyphBoxes; @@ -449,14 +460,14 @@ export class Placement { }; const placeHorizontal = () => { - return placeBoxForVariableAnchors(textBox, WritingMode.horizontal); + return placeBoxForVariableAnchors(textBox, collisionArrays.iconBox, WritingMode.horizontal); }; const placeVertical = () => { const verticalTextBox = collisionArrays.verticalTextBox; const wasPlaced = placed && placed.box && placed.box.length; if (bucket.allowVerticalPlacement && !wasPlaced && symbolInstance.numVerticalGlyphVertices > 0 && verticalTextBox) { - return placeBoxForVariableAnchors(verticalTextBox, WritingMode.vertical); + return placeBoxForVariableAnchors(verticalTextBox, collisionArrays.verticalIconBox, WritingMode.vertical); } return {box: null, offscreen: null}; }; diff --git a/test/integration/render-tests/icon-text-fit/text-variable-anchor/expected.png b/test/integration/render-tests/icon-text-fit/text-variable-anchor/expected.png index 1b0ecb25ce6..93fe892b0ea 100644 Binary files a/test/integration/render-tests/icon-text-fit/text-variable-anchor/expected.png and b/test/integration/render-tests/icon-text-fit/text-variable-anchor/expected.png differ diff --git a/test/integration/render-tests/text-variable-anchor/all-anchors-icon-text-fit/expected.png b/test/integration/render-tests/text-variable-anchor/all-anchors-icon-text-fit/expected.png index a5fecd1d97b..3d000a12eb0 100644 Binary files a/test/integration/render-tests/text-variable-anchor/all-anchors-icon-text-fit/expected.png and b/test/integration/render-tests/text-variable-anchor/all-anchors-icon-text-fit/expected.png differ