From 671073e7ebccc2d3bc68321d6bf32e3b6236a733 Mon Sep 17 00:00:00 2001 From: Asheem Mamoowala Date: Tue, 4 Dec 2018 15:39:44 -0800 Subject: [PATCH] Evaluate feature-state dependent layer IDs on bucket creation instead of deserialize --- src/data/bucket.js | 6 ++++-- src/data/bucket/circle_bucket.js | 2 ++ src/data/bucket/fill_bucket.js | 2 ++ src/data/bucket/fill_extrusion_bucket.js | 2 ++ src/data/bucket/line_bucket.js | 2 ++ src/data/bucket/symbol_bucket.js | 2 ++ 6 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/data/bucket.js b/src/data/bucket.js index 33fb1bb1b65..a31cf9b81db 100644 --- a/src/data/bucket.js +++ b/src/data/bucket.js @@ -70,7 +70,7 @@ export interface Bucket { hasPattern: boolean; +layers: Array; +stateDependentLayers: Array; - + +stateDependentLayerIds: Array; populate(features: Array, options: PopulateParameters): void; update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {[string]: ImagePosition}): void; isEmpty(): boolean; @@ -107,7 +107,9 @@ export function deserialize(input: Array, 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; } diff --git a/src/data/bucket/circle_bucket.js b/src/data/bucket/circle_bucket.js index 107d8161539..dc8d4fc6704 100644 --- a/src/data/bucket/circle_bucket.js +++ b/src/data/bucket/circle_bucket.js @@ -72,6 +72,8 @@ class CircleBucket 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, options: PopulateParameters) { diff --git a/src/data/bucket/fill_bucket.js b/src/data/bucket/fill_bucket.js index fa194648863..e6716e0b74e 100644 --- a/src/data/bucket/fill_bucket.js +++ b/src/data/bucket/fill_bucket.js @@ -68,6 +68,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, options: PopulateParameters) { diff --git a/src/data/bucket/fill_extrusion_bucket.js b/src/data/bucket/fill_extrusion_bucket.js index 37c71761571..d39c5fd05e3 100644 --- a/src/data/bucket/fill_extrusion_bucket.js +++ b/src/data/bucket/fill_extrusion_bucket.js @@ -82,6 +82,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, options: PopulateParameters) { diff --git a/src/data/bucket/line_bucket.js b/src/data/bucket/line_bucket.js index 6b4e93b7947..681e14756cd 100644 --- a/src/data/bucket/line_bucket.js +++ b/src/data/bucket/line_bucket.js @@ -125,6 +125,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, options: PopulateParameters) { diff --git a/src/data/bucket/symbol_bucket.js b/src/data/bucket/symbol_bucket.js index 420703acf9c..68a6147d894 100644 --- a/src/data/bucket/symbol_bucket.js +++ b/src/data/bucket/symbol_bucket.js @@ -300,6 +300,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; }