Skip to content

Commit

Permalink
Evaluate feature-state dependent layer IDs on bucket creation (#7790)
Browse files Browse the repository at this point in the history
* Evaluate feature-state dependent layer IDs on bucket creation instead of deserialize

* lint and flow
  • Loading branch information
Asheem Mamoowala authored and mourner committed Jan 21, 2019
1 parent 4de4e47 commit b47e761
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/data/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export interface Bucket {
hasPattern: boolean;
+layers: Array<any>;
+stateDependentLayers: Array<any>;

+stateDependentLayerIds: Array<string>;
populate(features: Array<IndexedFeature>, options: PopulateParameters): void;
update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {[string]: ImagePosition}): void;
isEmpty(): boolean;
Expand Down Expand Up @@ -107,7 +107,9 @@ export function deserialize(input: Array<Bucket>, style: Style): {[string]: Buck
// look up StyleLayer objects from layer ids (since we don't
// want to waste time serializing/copying them from the worker)
(bucket: any).layers = layers;
(bucket: any).stateDependentLayers = layers.filter((l) => l.isStateDependent());
if ((bucket: any).stateDependentLayerIds) {
(bucket: any).stateDependentLayers = (bucket: any).stateDependentLayerIds.map((lId) => layers.find((l) => l.id === lId));
}
for (const layer of layers) {
output[layer.id] = bucket;
}
Expand Down
3 changes: 3 additions & 0 deletions src/data/bucket/circle_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class CircleBucket<Layer: CircleStyleLayer | HeatmapStyleLayer> implements Bucke
layerIds: Array<string>;
layers: Array<Layer>;
stateDependentLayers: Array<Layer>;
stateDependentLayerIds: Array<string>;

layoutVertexArray: CircleLayoutArray;
layoutVertexBuffer: VertexBuffer;
Expand All @@ -72,6 +73,8 @@ class CircleBucket<Layer: CircleStyleLayer | HeatmapStyleLayer> implements Bucke
this.indexArray = new TriangleIndexArray();
this.segments = new SegmentVector();
this.programConfigurations = new ProgramConfigurationSet(layoutAttributes, options.layers, options.zoom);
this.stateDependentLayerIds = this.layers.filter((l) => l.isStateDependent()).map((l) => l.id);

}

populate(features: Array<IndexedFeature>, options: PopulateParameters) {
Expand Down
3 changes: 3 additions & 0 deletions src/data/bucket/fill_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ class FillBucket implements Bucket {
layers: Array<FillStyleLayer>;
layerIds: Array<string>;
stateDependentLayers: Array<FillStyleLayer>;
stateDependentLayerIds: Array<string>;

layoutVertexArray: FillLayoutArray;
layoutVertexBuffer: VertexBuffer;
Expand Down Expand Up @@ -68,6 +69,8 @@ class FillBucket implements Bucket {
this.programConfigurations = new ProgramConfigurationSet(layoutAttributes, options.layers, options.zoom);
this.segments = new SegmentVector();
this.segments2 = new SegmentVector();
this.stateDependentLayerIds = this.layers.filter((l) => l.isStateDependent()).map((l) => l.id);

}

populate(features: Array<IndexedFeature>, options: PopulateParameters) {
Expand Down
3 changes: 3 additions & 0 deletions src/data/bucket/fill_extrusion_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class FillExtrusionBucket implements Bucket {
layers: Array<FillExtrusionStyleLayer>;
layerIds: Array<string>;
stateDependentLayers: Array<FillExtrusionStyleLayer>;
stateDependentLayerIds: Array<string>;

layoutVertexArray: FillExtrusionLayoutArray;
layoutVertexBuffer: VertexBuffer;
Expand All @@ -82,6 +83,8 @@ class FillExtrusionBucket implements Bucket {
this.indexArray = new TriangleIndexArray();
this.programConfigurations = new ProgramConfigurationSet(layoutAttributes, options.layers, options.zoom);
this.segments = new SegmentVector();
this.stateDependentLayerIds = this.layers.filter((l) => l.isStateDependent()).map((l) => l.id);

}

populate(features: Array<IndexedFeature>, options: PopulateParameters) {
Expand Down
3 changes: 3 additions & 0 deletions src/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ class LineBucket implements Bucket {
layers: Array<LineStyleLayer>;
layerIds: Array<string>;
stateDependentLayers: Array<any>;
stateDependentLayerIds: Array<string>;
features: Array<BucketFeature>;

layoutVertexArray: LineLayoutArray;
Expand All @@ -125,6 +126,8 @@ class LineBucket implements Bucket {
this.indexArray = new TriangleIndexArray();
this.programConfigurations = new ProgramConfigurationSet(layoutAttributes, options.layers, options.zoom);
this.segments = new SegmentVector();

this.stateDependentLayerIds = this.layers.filter((l) => l.isStateDependent()).map((l) => l.id);
}

populate(features: Array<IndexedFeature>, options: PopulateParameters) {
Expand Down
4 changes: 4 additions & 0 deletions src/data/bucket/symbol_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,8 @@ class SymbolBucket implements Bucket {
layers: Array<SymbolStyleLayer>;
layerIds: Array<string>;
stateDependentLayers: Array<SymbolStyleLayer>;
stateDependentLayerIds: Array<string>;

index: number;
sdfIcons: boolean;
iconsNeedLinear: boolean;
Expand Down Expand Up @@ -300,6 +302,8 @@ class SymbolBucket implements Bucket {
this.sortFeaturesByY = zOrderByViewportY && (layout.get('text-allow-overlap') || layout.get('icon-allow-overlap') ||
layout.get('text-ignore-placement') || layout.get('icon-ignore-placement'));

this.stateDependentLayerIds = this.layers.filter((l) => l.isStateDependent()).map((l) => l.id);

this.sourceID = options.sourceID;
}

Expand Down

0 comments on commit b47e761

Please sign in to comment.