Skip to content

Commit

Permalink
prefer variable placements that fit icons
Browse files Browse the repository at this point in the history
  • Loading branch information
ansis authored and kkaefer committed Sep 25, 2019
1 parent 30db469 commit 9e0e2ee
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/symbol/placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,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<number>, offscreen: boolean } } {
textAllowOverlap: boolean, symbolInstance: SymbolInstance, bucket: SymbolBucket, orientation: number, iconBox: ?SingleCollisionBox): ?{ shift: Point, placedGlyphBoxes: { box: Array<number>, offscreen: boolean } } {

const textOffset = [symbolInstance.textOffset0, symbolInstance.textOffset1];
const shift = calculateVariableLayoutShift(anchor, width, height, textOffset, textBoxScale);
Expand All @@ -248,6 +248,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
Expand Down Expand Up @@ -431,7 +440,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, hasIconTextFit ? collisionArrays.iconBox : null);

if (result) {
placedBox = result.placedGlyphBoxes;
Expand Down

0 comments on commit 9e0e2ee

Please sign in to comment.