Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
HARP-13785: Mark rejected new labels as rejected instead of invisible.
Browse files Browse the repository at this point in the history
If text is marked as invisible, it's icon is still rendered.
  • Loading branch information
atomicsulfate committed Jan 19, 2021
1 parent 135329e commit 0236bf2
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 5 deletions.
7 changes: 2 additions & 5 deletions @here/harp-mapview/lib/text/Placement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -565,11 +565,8 @@ function placePointLabelChoosingAnchor(
return allInvisible
? // All text's placements out of the screen.
PlacementResult.Invisible
: persistent
? // All placements are either colliding or out of screen for persistent label.
PlacementResult.Rejected
: // No placement found for the new label.
PlacementResult.Invisible;
: // All placements are either colliding or out of screen .
PlacementResult.Rejected;
}

/**
Expand Down
42 changes: 42 additions & 0 deletions @here/harp-mapview/test/PlacementTest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1325,6 +1325,48 @@ describe("Placement", function () {

expect(textElement.bounds).to.not.be.undefined;
});

it("returns rejected for visible new labels with no available space", async function () {
const collisionsStub = new ScreenCollisions();

const textElement = await createTextElement(
textCanvas,
"Text",
new THREE.Vector3(),
{},
{
horizontalAlignment: HorizontalAlignment.Right,
verticalAlignment: VerticalAlignment.Below,
placements: createTextPlacements(
HorizontalPlacement.Left,
VerticalPlacement.Bottom
)
}
);
const state = new TextElementState(textElement);
const screenPos = new THREE.Vector2(0, 0);
const scale = 1.0;
const env = new Env();
const outPos = new THREE.Vector3();
textCanvas.textRenderStyle = textElement.renderStyle!;
textCanvas.textLayoutStyle = textElement.layoutStyle!;

sandbox.stub(collisionsStub, "isVisible").returns(true);
sandbox.stub(collisionsStub, "isAllocated").returns(true);

const result = placePointLabel(
state,
screenPos,
scale,
textCanvas,
env,
collisionsStub,
outPos,
true
);

expect(result).equals(PlacementResult.Rejected);
});
});

describe("placeIcon", function () {
Expand Down

0 comments on commit 0236bf2

Please sign in to comment.