Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

reduce symbol overlap when zooming out quickly #8628

Merged
merged 3 commits into from
Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -1200,7 +1200,7 @@ class Style extends Evented {
// tiles will fully display symbols in their first frame
const forceFullPlacement = this._layerOrderChanged || fadeDuration === 0;

if (forceFullPlacement || !this.pauseablePlacement || (this.pauseablePlacement.isDone() && !this.placement.stillRecent(browser.now()))) {
if (forceFullPlacement || !this.pauseablePlacement || (this.pauseablePlacement.isDone() && !this.placement.stillRecent(browser.now(), transform.zoom))) {
this.pauseablePlacement = new PauseablePlacement(transform, this._order, forceFullPlacement, showCollisionBoxes, fadeDuration, crossSourceCollisions, this.placement);
this._layerOrderChanged = false;
}
Expand Down
30 changes: 24 additions & 6 deletions src/symbol/placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,12 +167,14 @@ export class Placement {
variableOffsets: {[CrossTileID]: VariableOffset };
placedOrientations: {[CrossTileID]: number };
commitTime: number;
prevZoomAdjustment: number;
lastPlacementChangeTime: number;
stale: boolean;
fadeDuration: number;
retainedQueryData: {[number]: RetainedQueryData};
collisionGroups: CollisionGroups;
prevPlacement: ?Placement;
zoomAtLastRecencyCheck: number;

constructor(transform: Transform, fadeDuration: number, crossSourceCollisions: boolean, prevPlacement?: Placement) {
this.transform = transform.clone();
Expand Down Expand Up @@ -636,13 +638,13 @@ export class Placement {

commit(now: number): void {
this.commitTime = now;
this.zoomAtLastRecencyCheck = this.transform.zoom;

const prevPlacement = this.prevPlacement;
let placementChanged = false;

const increment = (prevPlacement && this.fadeDuration !== 0) ?
(this.commitTime - prevPlacement.commitTime) / this.fadeDuration :
1;
this.prevZoomAdjustment = prevPlacement ? prevPlacement.zoomAdjustment(this.transform.zoom) : 0;
const increment = prevPlacement ? prevPlacement.symbolFadeChange(now) : 1;

const prevOpacities = prevPlacement ? prevPlacement.opacities : {};
const prevOffsets = prevPlacement ? prevPlacement.variableOffsets : {};
Expand Down Expand Up @@ -893,16 +895,32 @@ export class Placement {
symbolFadeChange(now: number) {
return this.fadeDuration === 0 ?
1 :
(now - this.commitTime) / this.fadeDuration;
((now - this.commitTime) / this.fadeDuration + this.prevZoomAdjustment);
}

zoomAdjustment(zoom: number) {
// When zooming out quickly, labels can overlap each other. This
// adjustment is used to reduce the interval between placement calculations
// and to reduce the fade duration when zooming out quickly. Discovering the
// collisions more quickly and fading them more quickly reduces the unwanted effect.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discovering the collisions more quickly and fading them more quickly reduces the unwanted effect.

nit: This part of the comment can be removed, or make it clearer. It is not clear how zoomAdjustment results in discovering the collisions more quickly.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not clear how zoomAdjustment results in discovering the collisions more quickly.

+1 to this - it took me reading through all the code to understand how the adjustment works. Perhaps merging the "Discovering" sentence into the previous one would make it clearer, something like:

"This adjustment is applied when zooming out quickly to reduce the interval between placement calculations so we can discover & correct label collisions sooner, and also to reduce the fade duration so that overlapping labels fade out more quickly."

Just a suggestion, not sure if that wording would make it any clearer to someone else.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As is, it seems relatively clear to me that "reducing the interval between placement calculations" discovers collisions more quickly and "reducing the fade duration" fades them more quickly. I agree with @vakila that keeping the order of the clauses in the last sentence parallel to the previous sentence would improve clarity. I think shorter and simpler sentences are generally easier to follow than longer ones.

        // When zooming out quickly, labels can overlap each other. This
        // adjustment is used to reduce the interval between placement calculations
        // and to reduce the fade duration when zooming out quickly. Discovering the
        // collisions more quickly and fading them more quickly reduces the unwanted effect.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all the suggestions on how to make this better! I've committed chloe's version with shorter sentences.

return Math.max(0, (this.transform.zoom - zoom) / 1.5);
}

hasTransitions(now: number) {
return this.stale ||
now - this.lastPlacementChangeTime < this.fadeDuration;
}

stillRecent(now: number) {
return this.commitTime + this.fadeDuration > now;
stillRecent(now: number, zoom: number) {
// The adjustment makes placement more frequent when zooming.
// This condition applies the adjustment only after the map has
// stopped zooming. This avoids adding extra jank while zooming.
const durationAdjustment = this.zoomAtLastRecencyCheck === zoom ?
(1 - this.zoomAdjustment(zoom)) :
1;
this.zoomAtLastRecencyCheck = zoom;

return this.commitTime + this.fadeDuration * durationAdjustment > now;
}

setStale() {
Expand Down