Skip to content

Commit

Permalink
Remove this.features dependency from buckets
Browse files Browse the repository at this point in the history
  • Loading branch information
jfirebaugh authored and Lucas Wojciechowski committed Jan 27, 2016
1 parent 4520a6f commit 2b01616
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
6 changes: 3 additions & 3 deletions js/data/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ function Bucket(options) {
* Build the buffers! Features are set directly to the `features` property.
* @private
*/
Bucket.prototype.addFeatures = function() {
for (var i = 0; i < this.features.length; i++) {
this.addFeature(this.features[i]);
Bucket.prototype.addFeatures = function(features) {
for (var i = 0; i < features.length; i++) {
this.addFeature(features[i]);
}
};

Expand Down
13 changes: 6 additions & 7 deletions js/data/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,14 @@ SymbolBucket.prototype.shaders = {
}
};

SymbolBucket.prototype.addFeatures = function(collisionTile, stacks, icons) {
SymbolBucket.prototype.addFeatures = function(features, collisionTile, stacks, icons) {
var tileSize = 512 * this.overscaling;
this.tilePixelRatio = this.tileExtent / tileSize;
this.compareText = {};
this.symbolInstances = [];
this.iconsNeedLinear = false;

var layout = this.layer.layout;
var features = this.features;
var textFeatures = this.textFeatures;

var horizontalAlign = 0.5,
Expand Down Expand Up @@ -472,22 +471,22 @@ SymbolBucket.prototype.addSymbols = function(shaderName, quads, scale, keepUprig

};

SymbolBucket.prototype.updateIcons = function(icons) {
SymbolBucket.prototype.updateIcons = function(features, icons) {
var iconValue = this.layer.layout['icon-image'];
if (!iconValue) return;

for (var i = 0; i < this.features.length; i++) {
var iconName = resolveTokens(this.features[i].properties, iconValue);
for (var i = 0; i < features.length; i++) {
var iconName = resolveTokens(features[i].properties, iconValue);
if (iconName)
icons[iconName] = true;
}
};

SymbolBucket.prototype.updateFont = function(stacks) {
SymbolBucket.prototype.updateFont = function(features, stacks) {
var fontName = this.layer.layout['text-font'],
stack = stacks[fontName] = stacks[fontName] || {};

this.textFeatures = resolveText(this.features, this.layer.layout, stack);
this.textFeatures = resolveText(features, this.layer.layout, stack);
};

SymbolBucket.prototype.addToDebugBuffers = function(collisionTile) {
Expand Down
7 changes: 4 additions & 3 deletions js/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,9 @@ WorkerTile.prototype.parse = function(data, layers, actor, callback) {

// Get dependencies for symbol buckets
for (i = symbolBuckets.length - 1; i >= 0; i--) {
symbolBuckets[i].updateIcons(icons);
symbolBuckets[i].updateFont(stacks);
bucket = symbolBuckets[i];
bucket.updateIcons(bucket.features, icons);
bucket.updateFont(bucket.features, stacks);
}

for (var fontName in stacks) {
Expand Down Expand Up @@ -165,7 +166,7 @@ WorkerTile.prototype.parse = function(data, layers, actor, callback) {

function parseBucket(tile, bucket) {
var now = Date.now();
bucket.addFeatures(collisionTile, stacks, icons);
bucket.addFeatures(bucket.features, collisionTile, stacks, icons);
var time = Date.now() - now;

if (bucket.interactive) {
Expand Down
12 changes: 4 additions & 8 deletions test/js/data/bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ test('Bucket', function(t) {
t.test('add features', function(t) {
var builder = create();

builder.features = [createFeature(17, 42)];
builder.addFeatures();
builder.addFeatures([createFeature(17, 42)]);

var testVertex = builder.buffers.testVertex;
t.equal(testVertex.type, Buffer.BufferType.VERTEX);
Expand All @@ -89,8 +88,7 @@ test('Bucket', function(t) {
t.test('reset buffers', function(t) {
var builder = create();

builder.features = [createFeature(17, 42)];
builder.addFeatures();
builder.addFeatures([createFeature(17, 42)]);

var buffers = {};
builder.resetBuffers(buffers);
Expand All @@ -106,11 +104,9 @@ test('Bucket', function(t) {
t.test('add features after resetting buffers', function(t) {
var builder = create();

builder.features = [createFeature(1, 5)];
builder.addFeatures();
builder.addFeatures([createFeature(1, 5)]);
builder.resetBuffers({});
builder.features = [createFeature(17, 42)];
builder.addFeatures();
builder.addFeatures([createFeature(17, 42)]);

var testVertex = builder.buffers.testVertex;
t.equal(testVertex.length, 1);
Expand Down
5 changes: 2 additions & 3 deletions test/js/data/symbol_bucket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ test('SymbolBucket', function(t) {
tileExtent: 4096
});
bucket.textFeatures = ['abcde'];
bucket.features = [feature];
t.ok(bucket, 'bucketSetup');
return bucket;
}
Expand All @@ -45,13 +44,13 @@ test('SymbolBucket', function(t) {

// add feature from bucket A
var a = JSON.stringify(collision);
t.equal(bucketA.addFeatures(collision, stacks), undefined);
t.equal(bucketA.addFeatures([feature], collision, stacks), undefined);
var b = JSON.stringify(collision);
t.notEqual(a, b, 'places feature');

// add same feature from bucket B
a = JSON.stringify(collision);
t.equal(bucketB.addFeatures(collision, stacks), undefined);
t.equal(bucketB.addFeatures([feature], collision, stacks), undefined);
b = JSON.stringify(collision);
t.equal(a, b, 'detects collision and does not place feature');

Expand Down

0 comments on commit 2b01616

Please sign in to comment.