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

Delegate Bucket creation to StyleLayer #3471

Merged
merged 2 commits into from
Oct 27, 2016
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
31 changes: 3 additions & 28 deletions js/data/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ const FAKE_ZOOM_HISTORY = { lastIntegerZoom: Infinity, lastIntegerZoomTime: 0, l
* The `Bucket` class is the single point of knowledge about turning vector
* tiles into WebGL buffers.
*
* `Bucket` is an abstract class. A subclass exists for each Mapbox GL
* style spec layer type. Because `Bucket` is an abstract class,
* instances should be created via the `Bucket.create` method.
* `Bucket` is an abstract class. A subclass exists for each style layer type.
* Create a bucket via the `StyleLayer#createBucket` method.
*
* @private
*/
Expand Down Expand Up @@ -101,30 +100,6 @@ class Bucket {

module.exports = Bucket;

const subclasses = {
fill: require('./bucket/fill_bucket'),
fillextrusion: require('./bucket/fill_extrusion_bucket'),
line: require('./bucket/line_bucket'),
circle: require('./bucket/circle_bucket'),
symbol: require('./bucket/symbol_bucket')
};

/**
* Instantiate the appropriate subclass of `Bucket` for `options`.
* @param options See `Bucket` constructor options
* @returns {Bucket}
*/
Bucket.create = function(options) {
const layer = options.layers[0];
let type = layer.type;
if (type === 'fill' && (!layer.isPaintValueFeatureConstant('fill-extrude-height') ||
!layer.isPaintValueZoomConstant('fill-extrude-height') ||
layer.getPaintValue('fill-extrude-height', {zoom: options.zoom}) !== 0)) {
type = 'fillextrusion';
}
return new subclasses[type](options);
};

Bucket.deserialize = function(input, style) {
// Guard against the case where the map's style has been set to null while
// this bucket has been parsing.
Expand All @@ -140,7 +115,7 @@ Bucket.deserialize = function(input, style) {
continue;
}

output[layers[0].id] = Bucket.create(util.extend({layers}, serialized));
output[layers[0].id] = layers[0].createBucket(util.extend({layers}, serialized));
}
return output;
};
3 changes: 1 addition & 2 deletions js/source/worker_tile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const FeatureIndex = require('../data/feature_index');
const CollisionTile = require('../symbol/collision_tile');
const Bucket = require('../data/bucket');
const CollisionBoxArray = require('../symbol/collision_box');
const DictionaryCoder = require('../util/dictionary_coder');
const util = require('../util/util');
Expand Down Expand Up @@ -83,7 +82,7 @@ class WorkerTile {
if (layer.maxzoom && this.zoom >= layer.maxzoom) continue;
if (layer.layout && layer.layout.visibility === 'none') continue;

const bucket = buckets[layer.id] = Bucket.create({
const bucket = buckets[layer.id] = layer.createBucket({
index: bucketIndex++,
layers: family,
zoom: this.zoom,
Expand Down
1 change: 1 addition & 0 deletions js/style/style_layer.js
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ class StyleLayer extends Evented {
module.exports = StyleLayer;

const subclasses = {
'circle': require('./style_layer/circle_style_layer'),
'fill': require('./style_layer/fill_style_layer'),
'line': require('./style_layer/line_style_layer'),
'symbol': require('./style_layer/symbol_style_layer')
Expand Down
12 changes: 12 additions & 0 deletions js/style/style_layer/circle_style_layer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

const StyleLayer = require('../style_layer');
const CircleBucket = require('../../data/bucket/circle_bucket');

class CircleStyleLayer extends StyleLayer {
createBucket(options) {
return new CircleBucket(options);
}
}

module.exports = CircleStyleLayer;
11 changes: 11 additions & 0 deletions js/style/style_layer/fill_style_layer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
'use strict';

const StyleLayer = require('../style_layer');
const FillBucket = require('../../data/bucket/fill_bucket');
const FillExtrusionBucket = require('../../data/bucket/fill_extrusion_bucket');

class FillStyleLayer extends StyleLayer {

Expand Down Expand Up @@ -43,6 +45,15 @@ class FillStyleLayer extends StyleLayer {
return super.isPaintValueZoomConstant(name);
}
}

createBucket(options) {
if (!this.isPaintValueFeatureConstant('fill-extrude-height') ||
!this.isPaintValueZoomConstant('fill-extrude-height') ||
this.getPaintValue('fill-extrude-height', {zoom: options.zoom}) !== 0) {
return new FillExtrusionBucket(options);
}
return new FillBucket(options);
}
}

module.exports = FillStyleLayer;
5 changes: 5 additions & 0 deletions js/style/style_layer/line_style_layer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const StyleLayer = require('../style_layer');
const LineBucket = require('../../data/bucket/line_bucket');
const util = require('../../util/util');

class LineStyleLayer extends StyleLayer {
Expand All @@ -19,6 +20,10 @@ class LineStyleLayer extends StyleLayer {

return value;
}

createBucket(options) {
return new LineBucket(options);
}
}

module.exports = LineStyleLayer;
5 changes: 5 additions & 0 deletions js/style/style_layer/symbol_style_layer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use strict';

const StyleLayer = require('../style_layer');
const SymbolBucket = require('../../data/bucket/symbol_bucket');

class SymbolStyleLayer extends StyleLayer {

Expand All @@ -20,6 +21,10 @@ class SymbolStyleLayer extends StyleLayer {
return value;
}
}

createBucket(options) {
return new SymbolBucket(options);
}
}

module.exports = SymbolStyleLayer;