Skip to content

Commit

Permalink
Create CollisionTile only after async glyph/icon returns to ensure it…
Browse files Browse the repository at this point in the history
… uses the most up-to-date angle and pitch
  • Loading branch information
Lauren Budorick committed Dec 3, 2016
1 parent 29db5d7 commit dbd4259
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions js/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,10 @@ class WorkerTile {
}
}

const collisionTile = new CollisionTile(this.angle, this.pitch, this.collisionBoxArray);

const done = () => {
const collisionTile = this.placeSymbols(this.showCollisionBoxes);

this.status = 'done';

const transferables = [];
Expand Down Expand Up @@ -141,7 +142,6 @@ class WorkerTile {
if (deps === 2) {
for (const bucket of this.symbolBuckets) {
bucket.prepare(stacks, icons);
placeSymbols(bucket, collisionTile, this.showCollisionBoxes, this.zoom);
}

done();
Expand Down Expand Up @@ -170,14 +170,11 @@ class WorkerTile {
redoPlacement(angle, pitch, showCollisionBoxes) {
if (this.status !== 'done') {
this.angle = angle;
this.pitch = pitch;
return {};
}

const collisionTile = new CollisionTile(angle, pitch, this.collisionBoxArray);

for (const bucket of this.symbolBuckets) {
placeSymbols(bucket, collisionTile, showCollisionBoxes, this.zoom);
}
const collisionTile = this.placeSymbols(showCollisionBoxes);

const transferables = [];
return {
Expand All @@ -188,6 +185,21 @@ class WorkerTile {
transferables: transferables
};
}

placeSymbols(showCollisionBoxes) {
const collisionTile = new CollisionTile(this.angle, this.pitch, this.collisionBoxArray);

for (const bucket of this.symbolBuckets) {
// Layers are shared and may have been used by a WorkerTile with a different zoom.
for (const layer of bucket.layers) {
layer.recalculate(this.zoom);
}

bucket.place(collisionTile, showCollisionBoxes);
}

return collisionTile;
}
}

function serializeBuckets(buckets, transferables) {
Expand All @@ -196,14 +208,4 @@ function serializeBuckets(buckets, transferables) {
.map((b) => b.serialize(transferables));
}

function placeSymbols(bucket, collisionTile, showCollisionBoxes, zoom) {
// Layers are shared and may have been used by a WorkerTile with a different zoom.
for (const layer of bucket.layers) {
layer.recalculate(zoom);
}

bucket.place(collisionTile, showCollisionBoxes);
}


module.exports = WorkerTile;

0 comments on commit dbd4259

Please sign in to comment.