@mapwhit/tilerenderer 0.51.0 → 0.52.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (99) hide show
  1. package/build/min/package.json +1 -1
  2. package/package.json +13 -9
  3. package/src/data/array_types.js +1 -1
  4. package/src/data/bucket/circle_bucket.js +4 -1
  5. package/src/data/bucket/fill_bucket.js +5 -1
  6. package/src/data/bucket/fill_extrusion_bucket.js +5 -1
  7. package/src/data/bucket/line_bucket.js +5 -1
  8. package/src/data/bucket/symbol_bucket.js +3 -2
  9. package/src/geo/transform.js +1 -1
  10. package/src/index.js +2 -2
  11. package/src/render/glyph_atlas.js +1 -1
  12. package/src/render/image_atlas.js +1 -1
  13. package/src/render/image_manager.js +1 -1
  14. package/src/source/geojson_source.js +3 -2
  15. package/src/source/geojson_worker_source.js +4 -4
  16. package/src/source/geojson_wrapper.js +1 -1
  17. package/src/source/image_source.js +2 -2
  18. package/src/source/raster_tile_source.js +1 -1
  19. package/src/source/rtl_text_plugin.js +1 -1
  20. package/src/source/source_cache.js +2 -2
  21. package/src/source/tile.js +1 -1
  22. package/src/source/vector_tile_source.js +3 -2
  23. package/src/source/vector_tile_worker_source.js +1 -0
  24. package/src/source/worker_tile.js +8 -6
  25. package/src/style/evaluation_parameters.js +6 -4
  26. package/src/style/light.js +1 -1
  27. package/src/style/properties.js +4 -0
  28. package/src/style/query_utils.js +1 -1
  29. package/src/style/style.js +80 -3
  30. package/src/style/style_layer/circle_style_layer.js +1 -1
  31. package/src/style/style_layer/fill_extrusion_style_layer.js +1 -1
  32. package/src/style/style_layer/line_style_layer.js +1 -1
  33. package/src/style/style_layer.js +34 -2
  34. package/src/style-spec/feature_filter/index.js +13 -4
  35. package/src/style-spec/reference/v8.json +53 -13
  36. package/src/symbol/anchor.js +1 -1
  37. package/src/symbol/clip_line.js +1 -1
  38. package/src/symbol/collision_feature.js +1 -1
  39. package/src/symbol/collision_index.js +1 -1
  40. package/src/symbol/projection.js +1 -1
  41. package/src/symbol/quads.js +1 -1
  42. package/src/ui/camera.js +2 -2
  43. package/src/ui/map.js +27 -5
  44. package/src/util/config.js +1 -1
  45. package/src/util/find_pole_of_inaccessibility.js +1 -1
  46. package/src/util/intersection_tests.js +1 -1
  47. package/src/util/transfer_registry.js +1 -0
  48. package/src/worker.js +4 -0
  49. package/build/min/src/shaders/_prelude.fragment.glsl.txt +0 -13
  50. package/build/min/src/shaders/_prelude.vertex.glsl.txt +0 -14
  51. package/build/min/src/shaders/background.fragment.glsl.txt +0 -5
  52. package/build/min/src/shaders/background.vertex.glsl.txt +0 -1
  53. package/build/min/src/shaders/background_pattern.fragment.glsl.txt +0 -5
  54. package/build/min/src/shaders/background_pattern.vertex.glsl.txt +0 -1
  55. package/build/min/src/shaders/circle.fragment.glsl.txt +0 -20
  56. package/build/min/src/shaders/circle.vertex.glsl.txt +0 -17
  57. package/build/min/src/shaders/clipping_mask.fragment.glsl.txt +0 -1
  58. package/build/min/src/shaders/clipping_mask.vertex.glsl.txt +0 -1
  59. package/build/min/src/shaders/collision_box.fragment.glsl.txt +0 -1
  60. package/build/min/src/shaders/collision_box.vertex.glsl.txt +0 -1
  61. package/build/min/src/shaders/collision_circle.fragment.glsl.txt +0 -1
  62. package/build/min/src/shaders/collision_circle.vertex.glsl.txt +0 -1
  63. package/build/min/src/shaders/debug.fragment.glsl.txt +0 -1
  64. package/build/min/src/shaders/debug.vertex.glsl.txt +0 -1
  65. package/build/min/src/shaders/fill.fragment.glsl.txt +0 -10
  66. package/build/min/src/shaders/fill.vertex.glsl.txt +0 -7
  67. package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +0 -5
  68. package/build/min/src/shaders/fill_extrusion.vertex.glsl.txt +0 -9
  69. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.txt +0 -15
  70. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.txt +0 -11
  71. package/build/min/src/shaders/fill_outline.fragment.glsl.txt +0 -10
  72. package/build/min/src/shaders/fill_outline.vertex.glsl.txt +0 -7
  73. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.txt +0 -13
  74. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.txt +0 -9
  75. package/build/min/src/shaders/fill_pattern.fragment.glsl.txt +0 -13
  76. package/build/min/src/shaders/fill_pattern.vertex.glsl.txt +0 -9
  77. package/build/min/src/shaders/heatmap.fragment.glsl.txt +0 -10
  78. package/build/min/src/shaders/heatmap.vertex.glsl.txt +0 -8
  79. package/build/min/src/shaders/heatmap_texture.fragment.glsl.txt +0 -5
  80. package/build/min/src/shaders/heatmap_texture.vertex.glsl.txt +0 -1
  81. package/build/min/src/shaders/hillshade.fragment.glsl.txt +0 -7
  82. package/build/min/src/shaders/hillshade.vertex.glsl.txt +0 -1
  83. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.txt +0 -8
  84. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.txt +0 -1
  85. package/build/min/src/shaders/line.fragment.glsl.txt +0 -12
  86. package/build/min/src/shaders/line.vertex.glsl.txt +0 -17
  87. package/build/min/src/shaders/line_gradient.fragment.glsl.txt +0 -10
  88. package/build/min/src/shaders/line_gradient.vertex.glsl.txt +0 -16
  89. package/build/min/src/shaders/line_pattern.fragment.glsl.txt +0 -15
  90. package/build/min/src/shaders/line_pattern.vertex.glsl.txt +0 -20
  91. package/build/min/src/shaders/line_sdf.fragment.glsl.txt +0 -17
  92. package/build/min/src/shaders/line_sdf.vertex.glsl.txt +0 -20
  93. package/build/min/src/shaders/raster.fragment.glsl.txt +0 -5
  94. package/build/min/src/shaders/raster.vertex.glsl.txt +0 -1
  95. package/build/min/src/shaders/symbol_icon.fragment.glsl.txt +0 -9
  96. package/build/min/src/shaders/symbol_icon.vertex.glsl.txt +0 -5
  97. package/build/min/src/shaders/symbol_sdf.fragment.glsl.txt +0 -19
  98. package/build/min/src/shaders/symbol_sdf.vertex.glsl.txt +0 -13
  99. package/src/util/evented.js +0 -182
@@ -1,3 +1,3 @@
1
1
  {
2
- "version": "0.50.0"
2
+ "version": "0.51.1"
3
3
  }
package/package.json CHANGED
@@ -1,8 +1,11 @@
1
1
  {
2
2
  "name": "@mapwhit/tilerenderer",
3
3
  "description": "A WebGL interactive maps library",
4
- "version": "0.51.0",
5
- "main": "src/index.js",
4
+ "version": "0.52.0",
5
+ "exports": {
6
+ ".": "./src/index.js",
7
+ "./worker": "./src/worker.js"
8
+ },
6
9
  "license": "BSD-3-Clause",
7
10
  "repository": {
8
11
  "type": "git",
@@ -10,23 +13,24 @@
10
13
  },
11
14
  "dependencies": {
12
15
  "@mapbox/gl-matrix": "^0.0.1",
13
- "@mapbox/point-geometry": "^0.1.0",
14
- "@mapbox/unitbezier": "^0.0.0",
16
+ "@mapbox/point-geometry": "~1",
17
+ "@mapbox/unitbezier": "^0.0.1",
15
18
  "@mapbox/whoots-js": "^3.0.0",
19
+ "@mapwhit/events": "^0.0.1",
16
20
  "@mapwhit/geojson-rewind": "^1.0.0",
17
21
  "@mapwhit/pbf": "^1.0.0",
18
- "@mapwhit/style-expressions": "^0.0.2",
19
- "@mapwhit/vector-tile": "^1.0.0",
20
- "@mapwhit/vt-pbf": "^1.0.0",
22
+ "@mapwhit/style-expressions": "^1.1.0",
23
+ "@mapwhit/vector-tile": "^2.0.1",
24
+ "@mapwhit/vt-pbf": "^2.0.0",
21
25
  "@pirxpilot/nanoassert": "~1",
22
26
  "csscolorparser": "^1.0.3",
23
27
  "earcut": "^3.0.1",
24
28
  "geojson-vt": "^4.0.2",
25
29
  "grid-index": "^1.1.0",
26
30
  "murmurhash-js": "^1.0.0",
27
- "potpack": "^1.0.1",
31
+ "potpack": "^2.1.0",
28
32
  "quickselect": "^3.0.0",
29
- "supercluster": "^2.0.1",
33
+ "supercluster": "^8.0.1",
30
34
  "tinyqueue": "^3.0.0"
31
35
  },
32
36
  "browser": {
@@ -3,7 +3,7 @@
3
3
  const assert = require('assert');
4
4
  const { Struct, StructArray } = require('../util/struct_array');
5
5
  const { register } = require('../util/transfer_registry');
6
- const Point = require('@mapbox/point-geometry');
6
+ const { default: Point } = require('@mapbox/point-geometry');
7
7
 
8
8
  /**
9
9
  * Implementation of the StructArray layout:
@@ -23,6 +23,7 @@ function addCircleVertex(layoutVertexArray, x, y, extrudeX, extrudeY) {
23
23
  class CircleBucket {
24
24
  constructor(options) {
25
25
  this.zoom = options.zoom;
26
+ this.globalState = options.globalState;
26
27
  this.overscaling = options.overscaling;
27
28
  this.layers = options.layers;
28
29
  this.layerIds = this.layers.map(layer => layer.id);
@@ -37,7 +38,9 @@ class CircleBucket {
37
38
 
38
39
  populate(features, options) {
39
40
  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
+ ) {
41
44
  const geometry = loadGeometry(feature);
42
45
  this.addFeature(feature, geometry, index);
43
46
  options.featureIndex.insert(feature, geometry, index, sourceLayerIndex, this.index);
@@ -16,6 +16,7 @@ const EvaluationParameters = require('../../style/evaluation_parameters');
16
16
  class FillBucket {
17
17
  constructor(options) {
18
18
  this.zoom = options.zoom;
19
+ this.globalState = options.globalState;
19
20
  this.overscaling = options.overscaling;
20
21
  this.layers = options.layers;
21
22
  this.layerIds = this.layers.map(layer => layer.id);
@@ -35,7 +36,10 @@ class FillBucket {
35
36
  this.hasPattern = hasPattern('fill', this.layers, options);
36
37
 
37
38
  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;
39
43
 
40
44
  const geometry = loadGeometry(feature);
41
45
 
@@ -36,6 +36,7 @@ function addVertex(vertexArray, x, y, nx, ny, nz, t, e) {
36
36
  class FillExtrusionBucket {
37
37
  constructor(options) {
38
38
  this.zoom = options.zoom;
39
+ this.globalState = options.globalState;
39
40
  this.overscaling = options.overscaling;
40
41
  this.layers = options.layers;
41
42
  this.layerIds = this.layers.map(layer => layer.id);
@@ -53,7 +54,10 @@ class FillExtrusionBucket {
53
54
  this.hasPattern = hasPattern('fill-extrusion', this.layers, options);
54
55
 
55
56
  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;
57
61
 
58
62
  const geometry = loadGeometry(feature);
59
63
 
@@ -72,6 +72,7 @@ function addLineVertex(layoutVertexBuffer, point, extrude, round, up, dir, lines
72
72
  class LineBucket {
73
73
  constructor(options) {
74
74
  this.zoom = options.zoom;
75
+ this.globalState = options.globalState;
75
76
  this.overscaling = options.overscaling;
76
77
  this.layers = options.layers;
77
78
  this.layerIds = this.layers.map(layer => layer.id);
@@ -90,7 +91,10 @@ class LineBucket {
90
91
  this.hasPattern = hasPattern('line', this.layers, options);
91
92
 
92
93
  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;
94
98
 
95
99
  const geometry = loadGeometry(feature);
96
100
 
@@ -18,7 +18,7 @@ const {
18
18
  GlyphOffsetArray,
19
19
  SymbolLineVertexArray
20
20
  } = require('../array_types');
21
- const Point = require('@mapbox/point-geometry');
21
+ const { default: Point } = require('@mapbox/point-geometry');
22
22
  const SegmentVector = require('../segment');
23
23
  const { ProgramConfigurationSet } = require('../program_configuration');
24
24
  const { TriangleIndexArray, LineIndexArray } = require('../index_array_type');
@@ -176,6 +176,7 @@ class SymbolBucket {
176
176
  constructor(options) {
177
177
  this.collisionBoxArray = options.collisionBoxArray;
178
178
  this.zoom = options.zoom;
179
+ this.globalState = options.globalState;
179
180
  this.overscaling = options.overscaling;
180
181
  this.layers = options.layers;
181
182
  this.layerIds = this.layers.map(layer => layer.id);
@@ -258,7 +259,7 @@ class SymbolBucket {
258
259
 
259
260
  const icons = options.iconDependencies;
260
261
  const stacks = options.glyphDependencies;
261
- const globalProperties = new EvaluationParameters(this.zoom);
262
+ const globalProperties = new EvaluationParameters(this.zoom, { globalState: this.globalState });
262
263
 
263
264
  for (const { feature, index, sourceLayerIndex } of features) {
264
265
  if (!layer._featureFilter(globalProperties, feature)) {
@@ -1,6 +1,6 @@
1
1
  const LngLat = require('./lng_lat');
2
2
 
3
- const Point = require('@mapbox/point-geometry');
3
+ const { default: Point } = require('@mapbox/point-geometry');
4
4
  const Coordinate = require('./coordinate');
5
5
  const { wrap, clamp } = require('../util/util');
6
6
  const interpolate = require('../util/interpolate');
package/src/index.js CHANGED
@@ -7,8 +7,8 @@ module.exports = {
7
7
  Style: require('./style/style'),
8
8
  LngLat: require('./geo/lng_lat'),
9
9
  LngLatBounds: require('./geo/lng_lat_bounds'),
10
- Point: require('@mapbox/point-geometry'),
11
- Evented: require('./util/evented').Evented,
10
+ Point: require('@mapbox/point-geometry').default,
11
+ Evented: require('@mapwhit/events').Evented,
12
12
  config: require('./util/config'),
13
13
 
14
14
  get workerCount() {
@@ -1,6 +1,6 @@
1
1
  const { AlphaImage } = require('../util/image');
2
2
  const { register } = require('../util/transfer_registry');
3
- const potpack = require('potpack');
3
+ const { default: potpack } = require('potpack');
4
4
 
5
5
  const padding = 1;
6
6
 
@@ -1,6 +1,6 @@
1
1
  const { RGBAImage } = require('../util/image');
2
2
  const { register } = require('../util/transfer_registry');
3
- const potpack = require('potpack');
3
+ const { default: potpack } = require('potpack');
4
4
 
5
5
  const padding = 1;
6
6
 
@@ -1,4 +1,4 @@
1
- const potpack = require('potpack');
1
+ const { default: potpack } = require('potpack');
2
2
 
3
3
  const { RGBAImage } = require('../util/image');
4
4
  const { ImagePosition } = require('./image_atlas');
@@ -1,4 +1,4 @@
1
- const { Event, ErrorEvent, Evented } = require('../util/evented');
1
+ const { Event, ErrorEvent, Evented } = require('@mapwhit/events');
2
2
 
3
3
  const EXTENT = require('../data/extent');
4
4
  const browser = require('../util/browser');
@@ -184,7 +184,8 @@ class GeoJSONSource extends Evented {
184
184
  tileSize: this.tileSize,
185
185
  source: this.id,
186
186
  pixelRatio: browser.devicePixelRatio,
187
- showCollisionBoxes: this.map.showCollisionBoxes
187
+ showCollisionBoxes: this.map.showCollisionBoxes,
188
+ globalState: this.map.getGlobalState()
188
189
  };
189
190
 
190
191
  const justReloaded = tile.workerID != null;
@@ -1,7 +1,7 @@
1
1
  const rewind = require('@mapwhit/geojson-rewind');
2
2
  const GeoJSONWrapper = require('./geojson_wrapper');
3
- const vtpbf = require('@mapwhit/vt-pbf');
4
- const supercluster = require('supercluster');
3
+ const { fromVectorTileJs } = require('@mapwhit/vt-pbf');
4
+ const { default: Supercluster } = require('supercluster');
5
5
  const { default: geojsonvt } = require('geojson-vt');
6
6
  const VectorTileWorkerSource = require('./vector_tile_worker_source');
7
7
 
@@ -29,7 +29,7 @@ function loadGeoJSONTile(params) {
29
29
  // Encode the geojson-vt tile into binary vector tile form. This
30
30
  // is a convenience that allows `FeatureIndex` to operate the same way
31
31
  // across `VectorTileSource` and `GeoJSONSource` data.
32
- let pbf = vtpbf(geojsonWrapper);
32
+ let pbf = fromVectorTileJs(geojsonWrapper);
33
33
  if (pbf.byteOffset !== 0 || pbf.byteLength !== pbf.buffer.byteLength) {
34
34
  // Compatibility with node Buffer (https://github.com/mapbox/pbf/issues/35)
35
35
  pbf = new Uint8Array(pbf);
@@ -81,7 +81,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
81
81
  this._createGeoJSONIndex = params.cluster
82
82
  ? () => {
83
83
  rewind(data, true);
84
- return supercluster(params.superclusterOptions).load(data.features);
84
+ return new Supercluster(params.superclusterOptions).load(data.features);
85
85
  }
86
86
  : () => {
87
87
  rewind(data, true);
@@ -1,4 +1,4 @@
1
- const Point = require('@mapbox/point-geometry');
1
+ const { default: Point } = require('@mapbox/point-geometry');
2
2
  const { VectorTileFeature } = require('@mapwhit/vector-tile');
3
3
  const EXTENT = require('../data/extent');
4
4
 
@@ -2,8 +2,8 @@ const { getCoordinatesCenter } = require('../util/util');
2
2
 
3
3
  const { CanonicalTileID } = require('./tile_id');
4
4
  const LngLat = require('../geo/lng_lat');
5
- const Point = require('@mapbox/point-geometry');
6
- const { Event, ErrorEvent, Evented } = require('../util/evented');
5
+ const { default: Point } = require('@mapbox/point-geometry');
6
+ const { Event, ErrorEvent, Evented } = require('@mapwhit/events');
7
7
  const loadImage = require('../util/loader/image');
8
8
  const EXTENT = require('../data/extent');
9
9
  const { RasterBoundsArray } = require('../data/array_types');
@@ -1,6 +1,6 @@
1
1
  const { pick } = require('../util/object');
2
2
  const loadImage = require('../util/loader/image');
3
- const { Event, ErrorEvent, Evented } = require('../util/evented');
3
+ const { Event, ErrorEvent, Evented } = require('@mapwhit/events');
4
4
  const loadTileJSON = require('./load_tilejson');
5
5
  const TileBounds = require('./tile_bounds');
6
6
  const Texture = require('../render/texture');
@@ -1,4 +1,4 @@
1
- const { Event, Evented } = require('../util/evented');
1
+ const { Event, Evented } = require('@mapwhit/events');
2
2
  const browser = require('../util/browser');
3
3
 
4
4
  let pluginRequested = false;
@@ -1,11 +1,11 @@
1
1
  const { create: createSource } = require('./source');
2
2
  const Tile = require('./tile');
3
- const { Event, ErrorEvent, Evented } = require('../util/evented');
3
+ const { Event, ErrorEvent, Evented } = require('@mapwhit/events');
4
4
  const TileCache = require('./tile_cache');
5
5
  const Coordinate = require('../geo/coordinate');
6
6
  const { keysDifference } = require('../util/object');
7
7
  const EXTENT = require('../data/extent');
8
- const Point = require('@mapbox/point-geometry');
8
+ const { default: Point } = require('@mapbox/point-geometry');
9
9
  const browser = require('../util/browser');
10
10
  const { OverscaledTileID } = require('./tile_id');
11
11
  const assert = require('assert');
@@ -7,7 +7,7 @@ const SymbolBucket = require('../data/bucket/symbol_bucket');
7
7
  const { RasterBoundsArray, CollisionBoxArray } = require('../data/array_types');
8
8
  const rasterBoundsAttributes = require('../data/raster_bounds_attributes');
9
9
  const EXTENT = require('../data/extent');
10
- const Point = require('@mapbox/point-geometry');
10
+ const { default: Point } = require('@mapbox/point-geometry');
11
11
  const Texture = require('../render/texture');
12
12
  const SegmentVector = require('../data/segment');
13
13
  const { TriangleIndexArray } = require('../data/index_array_type');
@@ -1,4 +1,4 @@
1
- const { Event, ErrorEvent, Evented } = require('../util/evented');
1
+ const { Event, ErrorEvent, Evented } = require('@mapwhit/events');
2
2
  const { pick } = require('../util/object');
3
3
  const loadTileJSON = require('./load_tilejson');
4
4
  const TileBounds = require('./tile_bounds');
@@ -94,7 +94,8 @@ class VectorTileSource extends Evented {
94
94
  type: this.type,
95
95
  source: this.id,
96
96
  pixelRatio: browser.devicePixelRatio,
97
- showCollisionBoxes: this.map.showCollisionBoxes
97
+ showCollisionBoxes: this.map.showCollisionBoxes,
98
+ globalState: this.map.getGlobalState()
98
99
  };
99
100
  tile.workerID ??= this.dispatcher.nextWorkerId();
100
101
  const data = await this.dispatcher.send('loadTile', params, tile.workerID);
@@ -49,6 +49,7 @@ class VectorTileWorkerSource {
49
49
  }
50
50
  const { vectorTile, rawData } = response;
51
51
  const workerTile = new WorkerTile(params);
52
+ workerTile.globalState = params.globalState;
52
53
  workerTile.vectorTile = vectorTile;
53
54
  const result = await workerTile.parse(vectorTile, this.layerIndex, this.resources);
54
55
  if (rawData) {
@@ -31,6 +31,7 @@ class WorkerTile {
31
31
  this.source = params.source;
32
32
  this.overscaling = this.tileID.overscaleFactor();
33
33
  this.showCollisionBoxes = params.showCollisionBoxes;
34
+ this.globalState = params.globalState;
34
35
  }
35
36
 
36
37
  async parse(data, layerIndex, resources) {
@@ -81,7 +82,7 @@ class WorkerTile {
81
82
  if (layer.maxzoom && this.zoom >= layer.maxzoom) continue;
82
83
  if (layer.visibility === 'none') continue;
83
84
 
84
- recalculateLayers(family, this.zoom);
85
+ recalculateLayers(family, this.zoom, { globalState: this.globalState });
85
86
 
86
87
  const bucket = (buckets[layer.id] = layer.createBucket({
87
88
  index: featureIndex.bucketLayerIDs.length,
@@ -91,7 +92,8 @@ class WorkerTile {
91
92
  overscaling: this.overscaling,
92
93
  collisionBoxArray: this.collisionBoxArray,
93
94
  sourceLayerIndex: sourceLayerIndex,
94
- sourceID: this.source
95
+ sourceID: this.source,
96
+ globalState: this.globalState
95
97
  }));
96
98
 
97
99
  bucket.populate(features, options);
@@ -114,7 +116,7 @@ class WorkerTile {
114
116
  for (const key in buckets) {
115
117
  const bucket = buckets[key];
116
118
  if (bucket instanceof SymbolBucket) {
117
- recalculateLayers(bucket.layers, this.zoom);
119
+ recalculateLayers(bucket.layers, this.zoom, { globalState: this.globalState });
118
120
  performSymbolLayout(
119
121
  bucket,
120
122
  glyphMap,
@@ -127,7 +129,7 @@ class WorkerTile {
127
129
  bucket.hasPattern &&
128
130
  (bucket instanceof LineBucket || bucket instanceof FillBucket || bucket instanceof FillExtrusionBucket)
129
131
  ) {
130
- recalculateLayers(bucket.layers, this.zoom);
132
+ recalculateLayers(bucket.layers, this.zoom, { globalState: this.globalState });
131
133
  bucket.addFeatures(options, imageAtlas.patternPositions);
132
134
  }
133
135
  }
@@ -143,9 +145,9 @@ class WorkerTile {
143
145
  }
144
146
  }
145
147
 
146
- function recalculateLayers(layers, zoom) {
148
+ function recalculateLayers(layers, zoom, options) {
147
149
  // Layers are shared and may have been used by a WorkerTile with a different zoom.
148
- const parameters = new EvaluationParameters(zoom);
150
+ const parameters = new EvaluationParameters(zoom, options);
149
151
  for (const layer of layers) {
150
152
  layer.recalculate(parameters);
151
153
  }
@@ -8,15 +8,17 @@ class EvaluationParameters {
8
8
  this.zoom = zoom;
9
9
 
10
10
  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 || {};
15
16
  } else {
16
17
  this.now = 0;
17
18
  this.fadeDuration = 0;
18
19
  this.zoomHistory = new ZoomHistory();
19
20
  this.transition = {};
21
+ this.globalState = {};
20
22
  }
21
23
  }
22
24
 
@@ -1,5 +1,5 @@
1
1
  const { sphericalToCartesian } = require('../util/util');
2
- const { Evented } = require('../util/evented');
2
+ const { Evented } = require('@mapwhit/events');
3
3
  const interpolate = require('../util/interpolate');
4
4
 
5
5
  const lightSpec = {
@@ -75,6 +75,10 @@ class PropertyValue {
75
75
  return this.expression.kind === 'source' || this.expression.kind === 'composite';
76
76
  }
77
77
 
78
+ getGlobalStateRefs() {
79
+ return this.expression.globalStateRefs ?? new Set();
80
+ }
81
+
78
82
  possiblyEvaluate(parameters) {
79
83
  return this.property.possiblyEvaluate(this, parameters);
80
84
  }
@@ -1,4 +1,4 @@
1
- const Point = require('@mapbox/point-geometry');
1
+ const { default: Point } = require('@mapbox/point-geometry');
2
2
 
3
3
  module.exports = {
4
4
  getMaximumPaintValue,
@@ -1,6 +1,6 @@
1
1
  const assert = require('assert');
2
2
 
3
- const { Event, ErrorEvent, Evented } = require('../util/evented');
3
+ const { Event, ErrorEvent, Evented } = require('@mapwhit/events');
4
4
  const createStyleLayer = require('./create_style_layer');
5
5
  const loadSprite = require('./load_sprite');
6
6
  const ImageManager = require('../render/image_manager');
@@ -41,6 +41,7 @@ class Style extends Evented {
41
41
  this.sourceCaches = {};
42
42
  this.zoomHistory = new ZoomHistory();
43
43
  this._loaded = false;
44
+ this._globalState = {};
44
45
 
45
46
  this._resetUpdates();
46
47
 
@@ -78,6 +79,80 @@ class Style extends Evented {
78
79
  });
79
80
  }
80
81
 
82
+ setGlobalStateProperty(name, value) {
83
+ this._checkLoaded();
84
+
85
+ const newValue = value === null ? (this.stylesheet.state?.[name]?.default ?? null) : value;
86
+
87
+ if (deepEqual(newValue, this._globalState[name])) {
88
+ return this;
89
+ }
90
+
91
+ this._globalState[name] = newValue;
92
+
93
+ const sourceIdsToReload = this._findGlobalStateAffectedSources([name]);
94
+
95
+ for (const id in this.sourceCaches) {
96
+ if (sourceIdsToReload.has(id)) {
97
+ this._reloadSource(id);
98
+ this._changed = true;
99
+ }
100
+ }
101
+ }
102
+
103
+ getGlobalState() {
104
+ return this._globalState;
105
+ }
106
+
107
+ setGlobalState(newStylesheetState) {
108
+ this._checkLoaded();
109
+
110
+ const changedGlobalStateRefs = [];
111
+
112
+ for (const propertyName in newStylesheetState) {
113
+ const didChange = !deepEqual(this._globalState[propertyName], newStylesheetState[propertyName].default);
114
+
115
+ if (didChange) {
116
+ changedGlobalStateRefs.push(propertyName);
117
+ this._globalState[propertyName] = newStylesheetState[propertyName].default;
118
+ }
119
+ }
120
+
121
+ const sourceIdsToReload = this._findGlobalStateAffectedSources(changedGlobalStateRefs);
122
+
123
+ for (const id in this.sourceCaches) {
124
+ if (sourceIdsToReload.has(id)) {
125
+ this._reloadSource(id);
126
+ this._changed = true;
127
+ }
128
+ }
129
+ }
130
+
131
+ /**
132
+ * Find all sources that are affected by the global state changes.
133
+ * For example, if a layer filter uses global-state expression, this function will return the source id of that layer.
134
+ */
135
+ _findGlobalStateAffectedSources(globalStateRefs) {
136
+ if (globalStateRefs.length === 0) {
137
+ return new Set();
138
+ }
139
+
140
+ const sourceIdsToReload = new Set();
141
+
142
+ for (const layerId in this._layers) {
143
+ const layer = this._layers[layerId];
144
+ const layoutAffectingGlobalStateRefs = layer.getLayoutAffectingGlobalStateRefs();
145
+
146
+ for (const ref of globalStateRefs) {
147
+ if (layoutAffectingGlobalStateRefs.has(ref)) {
148
+ sourceIdsToReload.add(layer.source);
149
+ }
150
+ }
151
+ }
152
+
153
+ return sourceIdsToReload;
154
+ }
155
+
81
156
  loadJSON(json) {
82
157
  this.fire(new Event('dataloading', { dataType: 'style' }));
83
158
 
@@ -128,6 +203,8 @@ class Style extends Evented {
128
203
 
129
204
  this.light = new Light(this.stylesheet.light);
130
205
 
206
+ this.setGlobalState(this.stylesheet.state ?? null);
207
+
131
208
  this.fire(new Event('data', { dataType: 'style' }));
132
209
  this.fire(new Event('style.load'));
133
210
  }
@@ -547,12 +624,12 @@ class Style extends Evented {
547
624
  }
548
625
 
549
626
  if (filter === null || filter === undefined) {
550
- layer.filter = undefined;
627
+ layer.setFilter(undefined);
551
628
  this._updateLayer(layer);
552
629
  return;
553
630
  }
554
631
 
555
- layer.filter = clone(filter);
632
+ layer.setFilter(clone(filter));
556
633
  this._updateLayer(layer);
557
634
  }
558
635
 
@@ -5,7 +5,7 @@ const { polygonIntersectsBufferedPoint } = require('../../util/intersection_test
5
5
  const { getMaximumPaintValue, translateDistance, translate } = require('../query_utils');
6
6
  const properties = require('./circle_style_layer_properties');
7
7
  const { vec4 } = require('@mapbox/gl-matrix');
8
- const Point = require('@mapbox/point-geometry');
8
+ const { default: Point } = require('@mapbox/point-geometry');
9
9
 
10
10
  class CircleStyleLayer extends StyleLayer {
11
11
  constructor(layer) {
@@ -5,7 +5,7 @@ const { polygonIntersectsPolygon, polygonIntersectsMultiPolygon } = require('../
5
5
  const { translateDistance, translate } = require('../query_utils');
6
6
  const properties = require('./fill_extrusion_style_layer_properties');
7
7
  const { vec4 } = require('@mapbox/gl-matrix');
8
- const Point = require('@mapbox/point-geometry');
8
+ const { default: Point } = require('@mapbox/point-geometry');
9
9
 
10
10
  class FillExtrusionStyleLayer extends StyleLayer {
11
11
  constructor(layer) {
@@ -1,4 +1,4 @@
1
- const Point = require('@mapbox/point-geometry');
1
+ const { default: Point } = require('@mapbox/point-geometry');
2
2
 
3
3
  const StyleLayer = require('../style_layer');
4
4
  const LineBucket = require('../../data/bucket/line_bucket');