Skip to content

Commit 6f7a082

Browse files
authored
Refactor passing global-state object from Style to expressions (maplibre#6366)
* maplibre-style-spec 24.1.0 * add missing typing that is required per maplibre/maplibre-style-spec#1128 maplibre/maplibre-style-spec#1128 * add missing typing to filters that is required per maplibre/maplibre-style-spec#1279 maplibre/maplibre-style-spec#1279 * render test for layer filter with `global-state` expression * pass `global-state` from `Style` to layers to expressions as parameter to constructor * pass `global-state` when creating a feature filter * remove `global-state` passed around in order to pass it to the `evaluate` function * fix render tests for `is_supported_script` * remove note that `global-state` is not supported in layout properties * changelog
1 parent 39fa720 commit 6f7a082

71 files changed

Lines changed: 514 additions & 357 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## main
22

33
### ✨ Features and improvements
4+
- Change the pathway for passing `global-state` object from `Style` to expression ([#6366](https://github.com/maplibre/maplibre-gl-js/pull/6366))
45
- _...Add new stuff here..._
56

67
### 🐞 Bug fixes

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
"@mapbox/unitbezier": "^0.0.1",
2525
"@mapbox/vector-tile": "^2.0.4",
2626
"@mapbox/whoots-js": "^3.1.0",
27-
"@maplibre/maplibre-gl-style-spec": "^23.3.0",
27+
"@maplibre/maplibre-gl-style-spec": "^24.1.0",
2828
"@maplibre/vt-pbf": "^4.0.3",
2929
"@types/geojson": "^7946.0.16",
3030
"@types/geojson-vt": "3.2.5",

src/data/bucket.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ export type BucketParameters<Layer extends TypedStyleLayer> = {
1919
collisionBoxArray: CollisionBoxArray;
2020
sourceLayerIndex: number;
2121
sourceID: string;
22-
globalState: Record<string, any>;
2322
};
2423

2524
export type PopulateParameters = {

src/data/bucket/circle_bucket.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ function addCircleVertex(layoutVertexArray, x, y, extrudeX, extrudeY) {
4949
export class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> implements Bucket {
5050
index: number;
5151
zoom: number;
52-
globalState: Record<string, any>;
5352
overscaling: number;
5453
layerIds: Array<string>;
5554
layers: Array<Layer>;
@@ -69,7 +68,6 @@ export class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> im
6968

7069
constructor(options: BucketParameters<Layer>) {
7170
this.zoom = options.zoom;
72-
this.globalState = options.globalState;
7371
this.overscaling = options.overscaling;
7472
this.layers = options.layers;
7573
this.layerIds = this.layers.map(layer => layer.id);
@@ -108,7 +106,7 @@ export class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> im
108106
const needGeometry = this.layers[0]._featureFilter.needGeometry;
109107
const evaluationFeature = toEvaluationFeature(feature, needGeometry);
110108

111-
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom, {globalState: this.globalState}), evaluationFeature, canonical)) continue;
109+
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) continue;
112110

113111
const sortKey = sortFeaturesByKey ?
114112
circleSortKey.evaluate(evaluationFeature, {}, canonical) :
@@ -145,8 +143,7 @@ export class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> im
145143
update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {[_: string]: ImagePosition}) {
146144
if (!this.stateDependentLayers.length) return;
147145
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, {
148-
imagePositions,
149-
globalState: this.globalState
146+
imagePositions
150147
});
151148
}
152149

@@ -235,7 +232,7 @@ export class CircleBucket<Layer extends CircleStyleLayer | HeatmapStyleLayer> im
235232
}
236233
}
237234

238-
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {imagePositions: {}, canonical, globalState: this.globalState});
235+
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {imagePositions: {}, canonical});
239236
}
240237
}
241238

src/data/bucket/fill_bucket.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ function createFillBucket({id, layout, paint, globalState, availableImages}: Cre
2626
type: 'fill',
2727
layout,
2828
paint
29-
} as LayerSpecification);
30-
layer.recalculate({zoom: 0, zoomHistory: {} as ZoomHistory, globalState} as EvaluationParameters,
29+
} as LayerSpecification, globalState);
30+
layer.recalculate({zoom: 0, zoomHistory: {} as ZoomHistory} as EvaluationParameters,
3131
availableImages as Array<string>);
3232

33-
return new FillBucket({layers: [layer], globalState} as BucketParameters<FillStyleLayer>);
33+
return new FillBucket({layers: [layer]} as BucketParameters<FillStyleLayer>);
3434
}
3535

3636
describe('FillBucket', () => {

src/data/bucket/fill_bucket.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ export class FillBucket implements Bucket {
4141
stateDependentLayers: Array<FillStyleLayer>;
4242
stateDependentLayerIds: Array<string>;
4343
patternFeatures: Array<BucketFeature>;
44-
globalState: Record<string, any>;
4544

4645
layoutVertexArray: FillLayoutArray;
4746
layoutVertexBuffer: VertexBuffer;
@@ -60,7 +59,6 @@ export class FillBucket implements Bucket {
6059

6160
constructor(options: BucketParameters<FillStyleLayer>) {
6261
this.zoom = options.zoom;
63-
this.globalState = options.globalState;
6462
this.overscaling = options.overscaling;
6563
this.layers = options.layers;
6664
this.layerIds = this.layers.map(layer => layer.id);
@@ -87,7 +85,7 @@ export class FillBucket implements Bucket {
8785
const needGeometry = this.layers[0]._featureFilter.needGeometry;
8886
const evaluationFeature = toEvaluationFeature(feature, needGeometry);
8987

90-
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom, {globalState: this.globalState}), evaluationFeature, canonical)) continue;
88+
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) continue;
9189

9290
const sortKey = sortFeaturesByKey ?
9391
fillSortKey.evaluate(evaluationFeature, {}, canonical, options.availableImages) :
@@ -115,7 +113,7 @@ export class FillBucket implements Bucket {
115113
const {geometry, index, sourceLayerIndex} = bucketFeature;
116114

117115
if (this.hasPattern) {
118-
const patternFeature = addPatternDependencies('fill', this.layers, bucketFeature, {zoom: this.zoom, globalState: this.globalState}, options);
116+
const patternFeature = addPatternDependencies('fill', this.layers, bucketFeature, {zoom: this.zoom}, options);
119117
// pattern features are added only once the pattern is loaded into the image atlas
120118
// so are stored during populate until later updated with positions by tile worker in addFeatures
121119
this.patternFeatures.push(patternFeature);
@@ -133,8 +131,7 @@ export class FillBucket implements Bucket {
133131
}) {
134132
if (!this.stateDependentLayers.length) return;
135133
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, {
136-
imagePositions,
137-
globalState: this.globalState
134+
imagePositions
138135
});
139136
}
140137

@@ -195,7 +192,7 @@ export class FillBucket implements Bucket {
195192
subdivided.indicesLineList,
196193
);
197194
}
198-
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {imagePositions, canonical, globalState: this.globalState});
195+
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {imagePositions, canonical});
199196
}
200197
}
201198

src/data/bucket/fill_extrusion_bucket.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ function createFillExtrusionBucket({id, layout, paint, globalState, availableIma
1414
type: 'fill-extrusion',
1515
layout,
1616
paint
17-
} as LayerSpecification);
18-
layer.recalculate({zoom: 0, zoomHistory: {} as ZoomHistory, globalState} as EvaluationParameters,
17+
} as LayerSpecification, globalState);
18+
layer.recalculate({zoom: 0, zoomHistory: {} as ZoomHistory} as EvaluationParameters,
1919
availableImages as Array<string>);
2020

21-
return new FillExtrusionBucket({layers: [layer], globalState} as BucketParameters<FillExtrusionStyleLayer>);
21+
return new FillExtrusionBucket({layers: [layer]} as BucketParameters<FillExtrusionStyleLayer>);
2222
}
2323

2424
describe('FillExtrusionBucket', () => {

src/data/bucket/fill_extrusion_bucket.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@ type CentroidAccumulator = {
5959
export class FillExtrusionBucket implements Bucket {
6060
index: number;
6161
zoom: number;
62-
globalState: Record<string, any>;
6362
overscaling: number;
6463
layers: Array<FillExtrusionStyleLayer>;
6564
layerIds: Array<string>;
@@ -83,7 +82,6 @@ export class FillExtrusionBucket implements Bucket {
8382

8483
constructor(options: BucketParameters<FillExtrusionStyleLayer>) {
8584
this.zoom = options.zoom;
86-
this.globalState = options.globalState;
8785
this.overscaling = options.overscaling;
8886
this.layers = options.layers;
8987
this.layerIds = this.layers.map(layer => layer.id);
@@ -106,7 +104,7 @@ export class FillExtrusionBucket implements Bucket {
106104
const needGeometry = this.layers[0]._featureFilter.needGeometry;
107105
const evaluationFeature = toEvaluationFeature(feature, needGeometry);
108106

109-
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom, {globalState: this.globalState}), evaluationFeature, canonical)) continue;
107+
if (!this.layers[0]._featureFilter.filter(new EvaluationParameters(this.zoom), evaluationFeature, canonical)) continue;
110108

111109
const bucketFeature: BucketFeature = {
112110
id,
@@ -119,7 +117,7 @@ export class FillExtrusionBucket implements Bucket {
119117
};
120118

121119
if (this.hasPattern) {
122-
this.features.push(addPatternDependencies('fill-extrusion', this.layers, bucketFeature, {zoom: this.zoom, globalState: this.globalState}, options));
120+
this.features.push(addPatternDependencies('fill-extrusion', this.layers, bucketFeature, {zoom: this.zoom}, options));
123121
} else {
124122
this.addFeature(bucketFeature, bucketFeature.geometry, index, canonical, {}, options.subdivisionGranularity);
125123
}
@@ -138,8 +136,7 @@ export class FillExtrusionBucket implements Bucket {
138136
update(states: FeatureStates, vtLayer: VectorTileLayer, imagePositions: {[_: string]: ImagePosition}) {
139137
if (!this.stateDependentLayers.length) return;
140138
this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, {
141-
imagePositions,
142-
globalState: this.globalState
139+
imagePositions
143140
});
144141
}
145142

@@ -190,7 +187,7 @@ export class FillExtrusionBucket implements Bucket {
190187
}
191188
}
192189

193-
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {imagePositions, canonical, globalState: this.globalState});
190+
this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {imagePositions, canonical});
194191
}
195192

196193
private processPolygon(

src/data/bucket/line_bucket.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,11 @@ function createLineBucket({id, layout, paint, globalState, availableImages}: Cre
2727
type: 'line',
2828
layout,
2929
paint
30-
} as LayerSpecification);
31-
layer.recalculate({zoom: 0, zoomHistory: {} as ZoomHistory, globalState} as EvaluationParameters,
30+
} as LayerSpecification, globalState);
31+
layer.recalculate({zoom: 0, zoomHistory: {} as ZoomHistory} as EvaluationParameters,
3232
availableImages as Array<string>);
3333

34-
return new LineBucket({layers: [layer], globalState} as BucketParameters<LineStyleLayer>);
34+
return new LineBucket({layers: [layer]} as BucketParameters<LineStyleLayer>);
3535
}
3636

3737
describe('LineBucket', () => {

0 commit comments

Comments
 (0)