Skip to content

Commit 7925d00

Browse files
author
Natalia Kowalczyk
committed
global-state expression support in filter and paint properties (#5613)
maplibre/maplibre-gl-js#5613 - adds a new map methods: `setGlobalStateProperty` and `getGlobalState` - `global-state` expression won't work in layout properties (`setGlobalStateProperty` will have no effect on those)
1 parent db4e6d0 commit 7925d00

20 files changed

+593
-20
lines changed

src/data/bucket/circle_bucket.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ function addCircleVertex(layoutVertexArray, x, y, extrudeX, extrudeY) {
2323
class CircleBucket {
2424
constructor(options) {
2525
this.zoom = options.zoom;
26+
this.globalState = options.globalState;
2627
this.overscaling = options.overscaling;
2728
this.layers = options.layers;
2829
this.layerIds = this.layers.map(layer => layer.id);
@@ -37,7 +38,9 @@ class CircleBucket {
3738

3839
populate(features, options) {
3940
for (const { feature, index, sourceLayerIndex } of features) {
40-
if (this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) {
41+
if (
42+
this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
43+
) {
4144
const geometry = loadGeometry(feature);
4245
this.addFeature(feature, geometry, index);
4346
options.featureIndex.insert(feature, geometry, index, sourceLayerIndex, this.index);

src/data/bucket/fill_bucket.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const EvaluationParameters = require('../../style/evaluation_parameters');
1616
class FillBucket {
1717
constructor(options) {
1818
this.zoom = options.zoom;
19+
this.globalState = options.globalState;
1920
this.overscaling = options.overscaling;
2021
this.layers = options.layers;
2122
this.layerIds = this.layers.map(layer => layer.id);
@@ -35,7 +36,10 @@ class FillBucket {
3536
this.hasPattern = hasPattern('fill', this.layers, options);
3637

3738
for (const { feature, index, sourceLayerIndex } of features) {
38-
if (!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) continue;
39+
if (
40+
!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
41+
)
42+
continue;
3943

4044
const geometry = loadGeometry(feature);
4145

src/data/bucket/fill_extrusion_bucket.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ function addVertex(vertexArray, x, y, nx, ny, nz, t, e) {
3636
class FillExtrusionBucket {
3737
constructor(options) {
3838
this.zoom = options.zoom;
39+
this.globalState = options.globalState;
3940
this.overscaling = options.overscaling;
4041
this.layers = options.layers;
4142
this.layerIds = this.layers.map(layer => layer.id);
@@ -53,7 +54,10 @@ class FillExtrusionBucket {
5354
this.hasPattern = hasPattern('fill-extrusion', this.layers, options);
5455

5556
for (const { feature, index, sourceLayerIndex } of features) {
56-
if (!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) continue;
57+
if (
58+
!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
59+
)
60+
continue;
5761

5862
const geometry = loadGeometry(feature);
5963

src/data/bucket/line_bucket.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ function addLineVertex(layoutVertexBuffer, point, extrude, round, up, dir, lines
7272
class LineBucket {
7373
constructor(options) {
7474
this.zoom = options.zoom;
75+
this.globalState = options.globalState;
7576
this.overscaling = options.overscaling;
7677
this.layers = options.layers;
7778
this.layerIds = this.layers.map(layer => layer.id);
@@ -90,7 +91,10 @@ class LineBucket {
9091
this.hasPattern = hasPattern('line', this.layers, options);
9192

9293
for (const { feature, index, sourceLayerIndex } of features) {
93-
if (!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) continue;
94+
if (
95+
!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
96+
)
97+
continue;
9498

9599
const geometry = loadGeometry(feature);
96100

src/data/bucket/symbol_bucket.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ class SymbolBucket {
176176
constructor(options) {
177177
this.collisionBoxArray = options.collisionBoxArray;
178178
this.zoom = options.zoom;
179+
this.globalState = options.globalState;
179180
this.overscaling = options.overscaling;
180181
this.layers = options.layers;
181182
this.layerIds = this.layers.map(layer => layer.id);
@@ -258,7 +259,7 @@ class SymbolBucket {
258259

259260
const icons = options.iconDependencies;
260261
const stacks = options.glyphDependencies;
261-
const globalProperties = new EvaluationParameters(this.zoom);
262+
const globalProperties = new EvaluationParameters(this.zoom, { globalState: this.globalState });
262263

263264
for (const { feature, index, sourceLayerIndex } of features) {
264265
if (!layer._featureFilter(globalProperties, feature)) {

src/source/geojson_source.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ class GeoJSONSource extends Evented {
184184
tileSize: this.tileSize,
185185
source: this.id,
186186
pixelRatio: browser.devicePixelRatio,
187-
showCollisionBoxes: this.map.showCollisionBoxes
187+
showCollisionBoxes: this.map.showCollisionBoxes,
188+
globalState: this.map.getGlobalState()
188189
};
189190

190191
const justReloaded = tile.workerID != null;

src/source/vector_tile_source.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,8 @@ class VectorTileSource extends Evented {
9494
type: this.type,
9595
source: this.id,
9696
pixelRatio: browser.devicePixelRatio,
97-
showCollisionBoxes: this.map.showCollisionBoxes
97+
showCollisionBoxes: this.map.showCollisionBoxes,
98+
globalState: this.map.getGlobalState()
9899
};
99100
tile.workerID ??= this.dispatcher.nextWorkerId();
100101
const data = await this.dispatcher.send('loadTile', params, tile.workerID);

src/source/vector_tile_worker_source.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ class VectorTileWorkerSource {
4949
}
5050
const { vectorTile, rawData } = response;
5151
const workerTile = new WorkerTile(params);
52+
workerTile.globalState = params.globalState;
5253
workerTile.vectorTile = vectorTile;
5354
const result = await workerTile.parse(vectorTile, this.layerIndex, this.resources);
5455
if (rawData) {

src/source/worker_tile.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class WorkerTile {
3131
this.source = params.source;
3232
this.overscaling = this.tileID.overscaleFactor();
3333
this.showCollisionBoxes = params.showCollisionBoxes;
34+
this.globalState = params.globalState;
3435
}
3536

3637
async parse(data, layerIndex, resources) {
@@ -91,7 +92,8 @@ class WorkerTile {
9192
overscaling: this.overscaling,
9293
collisionBoxArray: this.collisionBoxArray,
9394
sourceLayerIndex: sourceLayerIndex,
94-
sourceID: this.source
95+
sourceID: this.source,
96+
globalState: this.globalState
9597
}));
9698

9799
bucket.populate(features, options);

src/style/evaluation_parameters.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ class EvaluationParameters {
88
this.zoom = zoom;
99

1010
if (options) {
11-
this.now = options.now;
12-
this.fadeDuration = options.fadeDuration;
13-
this.zoomHistory = options.zoomHistory;
14-
this.transition = options.transition;
11+
this.now = options.now || 0;
12+
this.fadeDuration = options.fadeDuration || 0;
13+
this.zoomHistory = options.zoomHistory || new ZoomHistory();
14+
this.transition = options.transition || {};
15+
this.globalState = options.globalState || {};
1516
} else {
1617
this.now = 0;
1718
this.fadeDuration = 0;
1819
this.zoomHistory = new ZoomHistory();
1920
this.transition = {};
21+
this.globalState = {};
2022
}
2123
}
2224

0 commit comments

Comments
 (0)