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

Yet another Bucket refactor!? #5137

Merged
merged 4 commits into from
Aug 14, 2017
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
166 changes: 0 additions & 166 deletions src/data/array_group.js

This file was deleted.

96 changes: 22 additions & 74 deletions src/data/bucket.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
// @flow

const ArrayGroup = require('./array_group');
const BufferGroup = require('./buffer_group');
const util = require('../util/util');

import type CollisionBoxArray from '../symbol/collision_box';
import type Style from '../style/style';
import type StyleLayer from '../style/style_layer';
import type {ProgramInterface} from './program_configuration';
import type {PaintPropertyStatistics} from './program_configuration';
import type FeatureIndex from './feature_index';
import type {SerializedArrayGroup} from './array_group';

export type BucketParameters = {
index: number,
layers: Array<StyleLayer>,
zoom: number,
overscaling: number,
collisionBoxArray: CollisionBoxArray,
arrays?: SerializedArrayGroup
collisionBoxArray: CollisionBoxArray
}

export type PopulateParameters = {
Expand All @@ -28,8 +24,7 @@ export type PopulateParameters = {

export type SerializedBucket = {
zoom: number,
layerIds: Array<string>,
arrays: SerializedArrayGroup
layerIds: Array<string>
}

export type IndexedFeature = {
Expand All @@ -39,10 +34,10 @@ export type IndexedFeature = {
}

/**
* The `Bucket` class is the single point of knowledge about turning vector
* The `Bucket` interface is the single point of knowledge about turning vector
* tiles into WebGL buffers.
*
* `Bucket` is an abstract class. A subclass exists for each style layer type.
* `Bucket` is an abstract interface. An implementation exists for each style layer type.
* Create a bucket via the `StyleLayer#createBucket` method.
*
* The concrete bucket types, using layout options from the style layer,
Expand All @@ -61,17 +56,24 @@ export type IndexedFeature = {
*
* @private
*/
class Bucket {
index: number;
zoom: number;
overscaling: number;
layers: Array<StyleLayer>;
buffers: BufferGroup;
arrays: ArrayGroup;
export interface Bucket {
populate(features: Array<IndexedFeature>, options: PopulateParameters): void;
getPaintPropertyStatistics(): PaintPropertyStatistics;
isEmpty(): boolean;
serialize(transferables?: Array<Transferable>): SerializedBucket;

+addFeature: (feature: VectorTileFeature) => void;
/**
* Release the WebGL resources associated with the buffers. Note that because
* buckets are shared between layers having the same layout properties, they
* must be destroyed in groups (all buckets for a tile, or all symbol buckets).
*
* @private
*/
destroy(): void;
}

static deserialize(input: Array<SerializedBucket>, style: Style): {[string]: Bucket} {
module.exports = {
deserialize(input: Array<SerializedBucket>, style: Style): {[string]: Bucket} {
const output = {};

// Guard against the case where the map's style has been set to null while
Expand All @@ -95,58 +97,4 @@ class Bucket {

return output;
}

constructor(options: BucketParameters, programInterface: ProgramInterface) {
this.zoom = options.zoom;
this.overscaling = options.overscaling;
this.layers = options.layers;
this.index = options.index;

if (options.arrays) {
this.buffers = new BufferGroup(programInterface, options.layers, options.zoom, options.arrays);
} else {
this.arrays = new ArrayGroup(programInterface, options.layers, options.zoom);
}
}

populate(features: Array<IndexedFeature>, options: PopulateParameters) {
for (const {feature, index, sourceLayerIndex} of features) {
if (this.layers[0].filter(feature)) {
this.addFeature(feature);
options.featureIndex.insert(feature, index, sourceLayerIndex, this.index);
}
}
}

getPaintPropertyStatistics() {
return util.mapObject(this.arrays.programConfigurations, config => config.paintPropertyStatistics);
}

isEmpty() {
return this.arrays.isEmpty();
}

serialize(transferables?: Array<Transferable>): SerializedBucket {
return {
zoom: this.zoom,
layerIds: this.layers.map((l) => l.id),
arrays: this.arrays.serialize(transferables)
};
}

/**
* Release the WebGL resources associated with the buffers. Note that because
* buckets are shared between layers having the same layout properties, they
* must be destroyed in groups (all buckets for a tile, or all symbol buckets).
*
* @private
*/
destroy() {
if (this.buffers) {
this.buffers.destroy();
(this: any).buffers = null;
}
}
}

module.exports = Bucket;
};
Loading