Skip to content

Commit

Permalink
Always update style.placement and style.collisionIndex when a new…
Browse files Browse the repository at this point in the history
… placement operation completes.

Refs #6074
  • Loading branch information
Anand Thakker committed Feb 8, 2018
1 parent a6c20c0 commit 68941ac
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 12 deletions.
13 changes: 6 additions & 7 deletions src/style/style.js
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ class Style extends Evented {

_updatePlacement(transform: Transform, showCollisionBoxes: boolean, fadeDuration: number) {
let symbolBucketsChanged = false;
let placementChanged = false;
let placementCommitted = false;

const layerTiles = {};

Expand Down Expand Up @@ -990,11 +990,10 @@ class Style extends Evented {

if (this.pauseablePlacement.isDone()) {
const placement = this.pauseablePlacement.placement;
placementChanged = placement.commit(this.placement, browser.now());
if (!this.placement || placementChanged || symbolBucketsChanged) {
this.placement = placement;
this.collisionIndex = this.placement.collisionIndex;
}
placement.commit(this.placement, browser.now());
placementCommitted = true;
this.placement = placement;
this.collisionIndex = this.placement.collisionIndex;
this.placement.setRecent(browser.now(), placement.stale);
}

Expand All @@ -1009,7 +1008,7 @@ class Style extends Evented {
this.placement.setStale();
}

if (placementChanged || symbolBucketsChanged) {
if (placementCommitted || symbolBucketsChanged) {
for (const layerID of this._order) {
const styleLayer = this._layers[layerID];
if (styleLayer.type !== 'symbol') continue;
Expand Down
19 changes: 14 additions & 5 deletions src/symbol/placement.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class Placement {
placements: { [string | number]: JointPlacement };
opacities: { [string | number]: JointOpacityState };
commitTime: number;
lastPlacementChangeTime: number;
stale: boolean;
fadeDuration: number;

Expand Down Expand Up @@ -204,11 +205,10 @@ class Placement {
bucket.justReloaded = false;
}

commit(prevPlacement: ?Placement, now: number) {
this.commitTime = now;

commit(prevPlacement: ?Placement, now: number): void {
let placementChanged = false;

this.commitTime = now;
const increment = (prevPlacement && this.fadeDuration !== 0) ?
(this.commitTime - prevPlacement.commitTime) / this.fadeDuration :
1;
Expand Down Expand Up @@ -242,7 +242,15 @@ class Placement {
}
}

return placementChanged;
// this.lastPlacementChangeTime is the time of the last commit() that
// resulted in a placement change -- in other words, the start time of
// the last symbol fade animation
assert(!prevPlacement || typeof prevPlacement.lastPlacementChangeTime === 'number');
if (placementChanged) {
this.lastPlacementChangeTime = now;
} else if (typeof this.lastPlacementChangeTime !== 'number') {
this.lastPlacementChangeTime = prevPlacement ? prevPlacement.lastPlacementChangeTime : now;
}
}

updateLayerOpacities(styleLayer: StyleLayer, tiles: Array<Tile>) {
Expand Down Expand Up @@ -362,7 +370,8 @@ class Placement {
}

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

stillRecent(now: number) {
Expand Down

0 comments on commit 68941ac

Please sign in to comment.