@mapwhit/tilerenderer 1.1.0 → 1.2.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 (45) hide show
  1. package/build/min/package.json +1 -1
  2. package/package.json +5 -5
  3. package/src/data/bucket/circle_bucket.js +3 -8
  4. package/src/data/bucket/fill_bucket.js +4 -17
  5. package/src/data/bucket/fill_extrusion_bucket.js +4 -15
  6. package/src/data/bucket/line_bucket.js +4 -17
  7. package/src/data/bucket/pattern_bucket_features.js +4 -4
  8. package/src/data/bucket/symbol_bucket.js +4 -8
  9. package/src/data/feature_index.js +1 -1
  10. package/src/source/geojson_source.js +4 -3
  11. package/src/source/geojson_worker_source.js +26 -10
  12. package/src/source/load_tilejson.js +18 -6
  13. package/src/source/raster_tile_source.js +4 -5
  14. package/src/source/source_cache.js +9 -2
  15. package/src/source/tile.js +3 -0
  16. package/src/source/vector_tile_source.js +4 -6
  17. package/src/source/vector_tile_worker_source.js +6 -26
  18. package/src/source/worker_tile.js +67 -53
  19. package/src/style/create_style_layer.js +2 -2
  20. package/src/style/evaluation_parameters.js +0 -2
  21. package/src/style/properties.js +24 -15
  22. package/src/style/style.js +25 -10
  23. package/src/style/style_layer/background_style_layer.js +2 -2
  24. package/src/style/style_layer/circle_style_layer.js +3 -3
  25. package/src/style/style_layer/fill_extrusion_style_layer.js +3 -3
  26. package/src/style/style_layer/fill_style_layer.js +3 -3
  27. package/src/style/style_layer/heatmap_style_layer.js +3 -3
  28. package/src/style/style_layer/hillshade_style_layer.js +3 -3
  29. package/src/style/style_layer/line_style_layer.js +3 -3
  30. package/src/style/style_layer/raster_style_layer.js +2 -2
  31. package/src/style/style_layer/symbol_style_layer.js +2 -2
  32. package/src/style/style_layer.js +28 -7
  33. package/src/style-spec/feature_filter/index.js +7 -5
  34. package/src/style-spec/reference/v8.json +68 -9
  35. package/src/style-spec/visibility.js +37 -0
  36. package/src/symbol/collision_index.js +2 -2
  37. package/src/symbol/symbol_layout.js +1 -1
  38. package/src/ui/map.js +11 -4
  39. package/src/util/classify_rings.js +1 -1
  40. package/src/util/group_layers.js +1 -1
  41. package/src/util/object.js +0 -45
  42. package/src/util/util.js +0 -55
  43. package/src/util/async.js +0 -29
  44. package/src/util/find_pole_of_inaccessibility.js +0 -144
  45. package/src/util/intersection_tests.js +0 -245
@@ -1,4 +1,4 @@
1
1
  {
2
- "version": "1.1.0",
2
+ "version": "1.2.0",
3
3
  "type": "module"
4
4
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mapwhit/tilerenderer",
3
3
  "description": "A WebGL interactive maps library",
4
- "version": "1.1.0",
4
+ "version": "1.2.0",
5
5
  "type": "module",
6
6
  "exports": {
7
7
  ".": "./src/index.js",
@@ -17,10 +17,11 @@
17
17
  "@mapbox/point-geometry": "~1",
18
18
  "@mapbox/unitbezier": "^0.0.1",
19
19
  "@mapbox/whoots-js": "^3.0.0",
20
- "@mapwhit/events": "^0.0.1",
20
+ "@mapwhit/events": "^0.1.0",
21
21
  "@mapwhit/geojson-rewind": "^2.0.0",
22
+ "@mapwhit/geometry": "^1.0.0",
22
23
  "@mapwhit/pbf": "^1.0.0",
23
- "@mapwhit/style-expressions": "^1.1.0",
24
+ "@mapwhit/style-expressions": "^1.2.0",
24
25
  "@mapwhit/vector-tile": "^2.0.1",
25
26
  "@pirxpilot/nanoassert": "~1",
26
27
  "csscolorparser": "^1.0.3",
@@ -31,8 +32,7 @@
31
32
  "murmurhash-js": "^1.0.0",
32
33
  "potpack": "^2.1.0",
33
34
  "quickselect": "^3.0.0",
34
- "supercluster": "^8.0.1",
35
- "tinyqueue": "^3.0.0"
35
+ "supercluster": "^8.0.1"
36
36
  },
37
37
  "browser": {
38
38
  "assert": "@pirxpilot/nanoassert",
@@ -23,7 +23,6 @@ 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;
27
26
  this.overscaling = options.overscaling;
28
27
  this.layers = options.layers;
29
28
  this.index = options.index;
@@ -37,9 +36,7 @@ class CircleBucket {
37
36
 
38
37
  populate(features, options) {
39
38
  for (const { feature, index, sourceLayerIndex } of features) {
40
- if (
41
- this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
42
- ) {
39
+ if (this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) {
43
40
  const geometry = loadGeometry(feature);
44
41
  this.addFeature(feature, geometry, index);
45
42
  options.featureIndex.insert(feature, geometry, index, sourceLayerIndex, this.index);
@@ -52,8 +49,7 @@ class CircleBucket {
52
49
  return;
53
50
  }
54
51
  this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, {
55
- imagePositions,
56
- globalState: this.globalState
52
+ imagePositions
57
53
  });
58
54
  }
59
55
 
@@ -121,8 +117,7 @@ class CircleBucket {
121
117
  }
122
118
 
123
119
  this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {
124
- imagePositions: {},
125
- globalState: this.globalState
120
+ imagePositions: {}
126
121
  });
127
122
  }
128
123
  }
@@ -16,7 +16,6 @@ const layoutAttributes = layout.members;
16
16
  class FillBucket {
17
17
  constructor(options) {
18
18
  this.zoom = options.zoom;
19
- this.globalState = options.globalState;
20
19
  this.overscaling = options.overscaling;
21
20
  this.layers = options.layers;
22
21
  this.index = options.index;
@@ -35,9 +34,7 @@ class FillBucket {
35
34
  this.hasPattern = hasPattern('fill', this.layers, options);
36
35
 
37
36
  for (const { feature, index, sourceLayerIndex } of features) {
38
- if (
39
- !this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
40
- ) {
37
+ if (!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) {
41
38
  continue;
42
39
  }
43
40
 
@@ -57,15 +54,7 @@ class FillBucket {
57
54
  }
58
55
 
59
56
  if (this.hasPattern) {
60
- this.features.push(
61
- addPatternDependencies(
62
- 'fill',
63
- this.layers,
64
- patternFeature,
65
- { zoom: this.zoom, globalState: this.globalState },
66
- options
67
- )
68
- );
57
+ this.features.push(addPatternDependencies('fill', this.layers, patternFeature, { zoom: this.zoom }, options));
69
58
  } else {
70
59
  this.addFeature(patternFeature, geometry, index, {});
71
60
  }
@@ -79,8 +68,7 @@ class FillBucket {
79
68
  return;
80
69
  }
81
70
  this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, {
82
- imagePositions,
83
- globalState: this.globalState
71
+ imagePositions
84
72
  });
85
73
  }
86
74
 
@@ -178,8 +166,7 @@ class FillBucket {
178
166
  }
179
167
 
180
168
  this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {
181
- imagePositions,
182
- globalState: this.globalState
169
+ imagePositions
183
170
  });
184
171
  }
185
172
  }
@@ -37,7 +37,6 @@ function addVertex(vertexArray, x, y, nx, ny, nz, t, e) {
37
37
  class FillExtrusionBucket {
38
38
  constructor(options) {
39
39
  this.zoom = options.zoom;
40
- this.globalState = options.globalState;
41
40
  this.overscaling = options.overscaling;
42
41
  this.layers = options.layers;
43
42
  this.index = options.index;
@@ -54,9 +53,7 @@ class FillExtrusionBucket {
54
53
  this.hasPattern = hasPattern('fill-extrusion', this.layers, options);
55
54
 
56
55
  for (const { feature, index, sourceLayerIndex } of features) {
57
- if (
58
- !this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
59
- ) {
56
+ if (!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) {
60
57
  continue;
61
58
  }
62
59
 
@@ -77,13 +74,7 @@ class FillExtrusionBucket {
77
74
 
78
75
  if (this.hasPattern) {
79
76
  this.features.push(
80
- addPatternDependencies(
81
- 'fill-extrusion',
82
- this.layers,
83
- patternFeature,
84
- { zoom: this.zoom, globalState: this.globalState },
85
- options
86
- )
77
+ addPatternDependencies('fill-extrusion', this.layers, patternFeature, { zoom: this.zoom }, options)
87
78
  );
88
79
  } else {
89
80
  this.addFeature(patternFeature, geometry, index, {});
@@ -105,8 +96,7 @@ class FillExtrusionBucket {
105
96
  return;
106
97
  }
107
98
  this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, {
108
- imagePositions,
109
- globalState: this.globalState
99
+ imagePositions
110
100
  });
111
101
  }
112
102
 
@@ -246,8 +236,7 @@ class FillExtrusionBucket {
246
236
  }
247
237
 
248
238
  this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {
249
- imagePositions,
250
- globalState: this.globalState
239
+ imagePositions
251
240
  });
252
241
  }
253
242
  }
@@ -72,7 +72,6 @@ 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;
76
75
  this.overscaling = options.overscaling;
77
76
  this.layers = options.layers;
78
77
  this.index = options.index;
@@ -90,9 +89,7 @@ class LineBucket {
90
89
  this.hasPattern = hasPattern('line', this.layers, options);
91
90
 
92
91
  for (const { feature, index, sourceLayerIndex } of features) {
93
- if (
94
- !this.layers[0]._featureFilter(new EvaluationParameters(this.zoom, { globalState: this.globalState }), feature)
95
- ) {
92
+ if (!this.layers[0]._featureFilter(new EvaluationParameters(this.zoom), feature)) {
96
93
  continue;
97
94
  }
98
95
 
@@ -112,15 +109,7 @@ class LineBucket {
112
109
  }
113
110
 
114
111
  if (this.hasPattern) {
115
- this.features.push(
116
- addPatternDependencies(
117
- 'line',
118
- this.layers,
119
- patternFeature,
120
- { zoom: this.zoom, globalState: this.globalState },
121
- options
122
- )
123
- );
112
+ this.features.push(addPatternDependencies('line', this.layers, patternFeature, { zoom: this.zoom }, options));
124
113
  } else {
125
114
  this.addFeature(patternFeature, geometry, index, {});
126
115
  }
@@ -134,8 +123,7 @@ class LineBucket {
134
123
  return;
135
124
  }
136
125
  this.programConfigurations.updatePaintArrays(states, vtLayer, this.stateDependentLayers, {
137
- imagePositions,
138
- globalState: this.globalState
126
+ imagePositions
139
127
  });
140
128
  }
141
129
 
@@ -544,8 +532,7 @@ class LineBucket {
544
532
  }
545
533
 
546
534
  this.programConfigurations.populatePaintArrays(this.layoutVertexArray.length, feature, index, {
547
- imagePositions,
548
- globalState: this.globalState
535
+ imagePositions
549
536
  });
550
537
  }
551
538
 
@@ -19,16 +19,16 @@ export function hasPattern(type, layers, options) {
19
19
  return hasPattern;
20
20
  }
21
21
 
22
- export function addPatternDependencies(type, layers, patternFeature, { zoom, globalState }, options) {
22
+ export function addPatternDependencies(type, layers, patternFeature, { zoom }, options) {
23
23
  const patterns = options.patternDependencies;
24
24
  for (const layer of layers) {
25
25
  const patternProperty = layer._paint.get(`${type}-pattern`);
26
26
 
27
27
  const patternPropertyValue = patternProperty.value;
28
28
  if (patternPropertyValue.kind !== 'constant') {
29
- const min = patternPropertyValue.evaluate({ zoom: zoom - 1, globalState }, patternFeature, {});
30
- const mid = patternPropertyValue.evaluate({ zoom: zoom, globalState }, patternFeature, {});
31
- const max = patternPropertyValue.evaluate({ zoom: zoom + 1, globalState }, patternFeature, {});
29
+ const min = patternPropertyValue.evaluate({ zoom: zoom - 1 }, patternFeature, {});
30
+ const mid = patternPropertyValue.evaluate({ zoom: zoom }, patternFeature, {});
31
+ const max = patternPropertyValue.evaluate({ zoom: zoom + 1 }, patternFeature, {});
32
32
  // add to patternDependencies
33
33
  patterns[min] = true;
34
34
  patterns[mid] = true;
@@ -81,7 +81,6 @@ export default class SymbolBucket {
81
81
  constructor(options) {
82
82
  this.collisionBoxArray = options.collisionBoxArray;
83
83
  this.zoom = options.zoom;
84
- this.globalState = options.globalState;
85
84
  this.overscaling = options.overscaling;
86
85
  this.layers = options.layers;
87
86
  this.index = options.index;
@@ -151,7 +150,7 @@ export default class SymbolBucket {
151
150
 
152
151
  const icons = options.iconDependencies;
153
152
  const stacks = options.glyphDependencies;
154
- const globalProperties = new EvaluationParameters(this.zoom, { globalState: this.globalState });
153
+ const globalProperties = new EvaluationParameters(this.zoom);
155
154
 
156
155
  for (const { feature, index, sourceLayerIndex } of features) {
157
156
  if (!layer._featureFilter(globalProperties, feature)) {
@@ -223,12 +222,10 @@ export default class SymbolBucket {
223
222
  return;
224
223
  }
225
224
  this.text.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, {
226
- imagePositions,
227
- globalState: this.globalState
225
+ imagePositions
228
226
  });
229
227
  this.icon.programConfigurations.updatePaintArrays(states, vtLayer, this.layers, {
230
- imagePositions,
231
- globalState: this.globalState
228
+ imagePositions
232
229
  });
233
230
  }
234
231
 
@@ -343,8 +340,7 @@ export default class SymbolBucket {
343
340
  );
344
341
 
345
342
  arrays.programConfigurations.populatePaintArrays(arrays.layoutVertexArray.length, feature, feature.index, {
346
- imagePositions: {},
347
- globalState: this.globalState
343
+ imagePositions: {}
348
344
  });
349
345
  }
350
346
 
@@ -1,8 +1,8 @@
1
+ import { polygonIntersectsBox } from '@mapwhit/geometry';
1
2
  import Grid from 'grid-index';
2
3
  import EvaluationParameters from '../style/evaluation_parameters.js';
3
4
  import featureFilter from '../style-spec/feature_filter/index.js';
4
5
  import dictionaryCoder from '../util/dictionary_coder.js';
5
- import { polygonIntersectsBox } from '../util/intersection_tests.js';
6
6
  import { arraysIntersect } from '../util/object.js';
7
7
  import GeoJSONFeature from '../util/vectortile_to_geojson.js';
8
8
  import { FeatureIndexArray } from './array_types.js';
@@ -98,7 +98,8 @@ class GeoJSONSource extends Evented {
98
98
  tolerance: (options.tolerance !== undefined ? options.tolerance : 0.375) * scale,
99
99
  extent: EXTENT,
100
100
  maxZoom: this.maxzoom,
101
- lineMetrics: options.lineMetrics || false
101
+ lineMetrics: options.lineMetrics || false,
102
+ generateId: options.generateId || false
102
103
  },
103
104
  superclusterOptions: {
104
105
  maxZoom:
@@ -107,7 +108,8 @@ class GeoJSONSource extends Evented {
107
108
  : this.maxzoom - 1,
108
109
  extent: EXTENT,
109
110
  radius: (options.clusterRadius || 50) * scale,
110
- log: false
111
+ log: false,
112
+ generateId: options.generateId || false
111
113
  }
112
114
  },
113
115
  options.workerOptions
@@ -187,7 +189,6 @@ class GeoJSONSource extends Evented {
187
189
  source: this.id,
188
190
  pixelRatio: browser.devicePixelRatio,
189
191
  showCollisionBoxes: this.map.showCollisionBoxes,
190
- globalState: this.map.getGlobalState(),
191
192
  justReloaded: tile.workerID != null,
192
193
  painter: this.map.painter
193
194
  };
@@ -2,13 +2,17 @@ import rewind from '@mapwhit/geojson-rewind';
2
2
  import geojsonvt from 'geojson-vt';
3
3
  import Supercluster from 'supercluster';
4
4
  import GeoJSONWrapper from './geojson_wrapper.js';
5
- import VectorTileWorkerSource from './vector_tile_worker_source.js';
5
+ import { makeSingleSourceLayerWorkerTile as makeWorkerTile } from './worker_tile.js';
6
6
 
7
7
  /**
8
8
  * The {@link WorkerSource} implementation that supports {@link GeoJSONSource}.
9
9
  *
10
10
  */
11
- class GeoJSONWorkerSource extends VectorTileWorkerSource {
11
+ class GeoJSONWorkerSource {
12
+ constructor(resources, layerIndex) {
13
+ this.resources = resources;
14
+ this.layerIndex = layerIndex;
15
+ }
12
16
  /**
13
17
  * Fetches (if appropriate), parses, and index geojson data into tiles. This
14
18
  * preparatory method must be called before {@link GeoJSONWorkerSource#loadTile}
@@ -22,7 +26,7 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
22
26
  * @param callback
23
27
  */
24
28
  loadData(params) {
25
- const data = loadJSON(params.data);
29
+ const data = loadJSON(params);
26
30
  this._geoJSONIndex = null;
27
31
  this._createGeoJSONIndex = params.cluster
28
32
  ? () => {
@@ -51,17 +55,29 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
51
55
  return this._geoJSONIndex.getTile(z, x, y);
52
56
  }
53
57
 
54
- loadVectorData({ tileID }) {
58
+ /**
59
+ * Implements {@link WorkerSource#loadTile}.
60
+ */
61
+ async loadTile(params) {
62
+ const { tileID, source } = params;
55
63
  const geoJSONTile = this.getTile(tileID);
56
64
  if (!geoJSONTile) {
57
65
  return; // nothing in the given tile
58
66
  }
67
+ const sourceLayer = new GeoJSONWrapper(geoJSONTile.features);
68
+ const layerFamilies = this.layerIndex.familiesBySource.get(source);
69
+ if (!layerFamilies) {
70
+ return;
71
+ }
72
+ const features = new Array(sourceLayer.length);
73
+ for (let index = 0; index < sourceLayer.length; index++) {
74
+ features[index] = { feature: sourceLayer.feature(index), index, sourceLayerIndex: 0 };
75
+ }
59
76
 
60
- const vectorTile = new GeoJSONWrapper(geoJSONTile.features);
77
+ const result = await makeWorkerTile(params, features, layerFamilies.get(sourceLayer.name), this.resources);
61
78
 
62
- return {
63
- vectorTile
64
- };
79
+ result.vectorTile = sourceLayer;
80
+ return result;
65
81
  }
66
82
  }
67
83
 
@@ -70,11 +86,11 @@ class GeoJSONWorkerSource extends VectorTileWorkerSource {
70
86
  *
71
87
  * @param data Literal GeoJSON data. Must be provided.
72
88
  */
73
- function loadJSON(data) {
89
+ function loadJSON({ data, source }) {
74
90
  try {
75
91
  return typeof data === 'string' ? JSON.parse(data) : data;
76
92
  } catch {
77
- throw new Error('Input data is not a valid GeoJSON object.');
93
+ throw new Error(`Input data given to '${source}' is not a valid GeoJSON object.`);
78
94
  }
79
95
  }
80
96
 
@@ -1,13 +1,25 @@
1
- import { pick } from '../util/object.js';
2
-
3
1
  export default function (tileJSON) {
4
2
  return tileJSON.resourceSets ? fromResourseSets(tileJSON) : fromTileJSON(tileJSON);
5
3
  }
6
4
 
7
- function fromTileJSON(tileJSON) {
8
- const result = pick(tileJSON, ['tiles', 'minzoom', 'maxzoom', 'attribution', 'bounds']);
9
- if (tileJSON.vector_layers) {
10
- result.vectorLayers = tileJSON.vector_layers;
5
+ function fromTileJSON({ tiles, minzoom, maxzoom, attribution, bounds, vector_layers }) {
6
+ const result = {
7
+ tiles
8
+ };
9
+ if (typeof minzoom === 'number') {
10
+ result.minzoom = minzoom;
11
+ }
12
+ if (typeof maxzoom === 'number') {
13
+ result.maxzoom = maxzoom;
14
+ }
15
+ if (bounds) {
16
+ result.bounds = bounds;
17
+ }
18
+ if (attribution) {
19
+ result.attribution = attribution;
20
+ }
21
+ if (vector_layers) {
22
+ result.vectorLayers = vector_layers;
11
23
  result.vectorLayerIds = result.vectorLayers.map(layer => layer.id);
12
24
  }
13
25
  return result;
@@ -1,7 +1,6 @@
1
1
  import { ErrorEvent, Event, Evented } from '@mapwhit/events';
2
2
  import Texture from '../render/texture.js';
3
3
  import loadImage from '../util/loader/image.js';
4
- import { pick } from '../util/object.js';
5
4
  import loadTileJSON from './load_tilejson.js';
6
5
  import TileBounds from './tile_bounds.js';
7
6
 
@@ -15,12 +14,12 @@ class RasterTileSource extends Evented {
15
14
  this.minzoom = 0;
16
15
  this.maxzoom = 22;
17
16
  this.roundZoom = true;
18
- this.scheme = 'xyz';
19
- this.tileSize = 512;
20
17
  this._loaded = false;
21
18
 
22
- this._options = Object.assign({}, options);
23
- Object.assign(this, pick(options, ['url', 'scheme', 'tileSize']));
19
+ this._options = { ...options };
20
+ this.url = options.url;
21
+ this.scheme = options.scheme ?? 'xyz';
22
+ this.tileSize = options.tileSize ?? 512;
24
23
  }
25
24
 
26
25
  async load() {
@@ -75,10 +75,14 @@ class SourceCache extends Evented {
75
75
  }
76
76
 
77
77
  /**
78
- * Return true if no tile data is pending, tiles will not change unless
78
+ * Return `true` if no tile data is pending, tiles will not change unless
79
79
  * an additional API call is received.
80
+ * If `ignoreTilesLoading` is set, return `true` even when tiles are pending,
81
+ * otherwise there is no way to check that source is ready after loading style.
82
+ * Without `ignoreTilesLoading` the state of style being loaded or not depends on
83
+ * the tiles being in the process of loading or not.
80
84
  */
81
- loaded() {
85
+ loaded(ignoreTilesLoading) {
82
86
  if (this.#sourceErrored) {
83
87
  return true;
84
88
  }
@@ -87,6 +91,9 @@ class SourceCache extends Evented {
87
91
  return false;
88
92
  }
89
93
 
94
+ if (ignoreTilesLoading) {
95
+ return true;
96
+ }
90
97
  for (const tile of this._tiles.values()) {
91
98
  if (tile.state !== 'loaded' && tile.state !== 'errored') {
92
99
  return false;
@@ -110,6 +110,9 @@ class Tile {
110
110
  * @private
111
111
  */
112
112
  unloadVectorData() {
113
+ if (this.state === 'unloaded') {
114
+ return;
115
+ }
113
116
  for (const bucket of this.buckets.values()) {
114
117
  bucket.destroy();
115
118
  }
@@ -1,6 +1,5 @@
1
1
  import { ErrorEvent, Event, Evented } from '@mapwhit/events';
2
2
  import browser from '../util/browser.js';
3
- import { pick } from '../util/object.js';
4
3
  import loadTileJSON from './load_tilejson.js';
5
4
  import TileBounds from './tile_bounds.js';
6
5
  import VectorTileWorkerSource from './vector_tile_worker_source.js';
@@ -15,14 +14,14 @@ class VectorTileSource extends Evented {
15
14
  this.type = 'vector';
16
15
  this.minzoom = 0;
17
16
  this.maxzoom = 22;
18
- this.scheme = 'xyz';
19
- this.tileSize = 512;
20
17
  this.reparseOverscaled = true;
21
18
  this.isTileClipped = true;
22
19
  this._showTileBoundaries = showTileBoundaries;
23
20
 
24
- Object.assign(this, pick(options, ['url', 'scheme', 'tileSize']));
25
- this._options = Object.assign({ type: 'vector' }, options);
21
+ this._options = { type: 'vector', ...options };
22
+ this.url = options.url;
23
+ this.scheme = options.scheme ?? 'xyz';
24
+ this.tileSize = options.tileSize ?? 512;
26
25
 
27
26
  if (this.tileSize !== 512) {
28
27
  throw new Error('vector tile sources must have a tileSize of 512');
@@ -94,7 +93,6 @@ class VectorTileSource extends Evented {
94
93
  source: this.id,
95
94
  pixelRatio: browser.devicePixelRatio,
96
95
  showCollisionBoxes: this.map.showCollisionBoxes,
97
- globalState: this.map.getGlobalState(),
98
96
  painter: this.map.painter
99
97
  };
100
98
  tile.workerID ??= true;
@@ -4,17 +4,11 @@ import makeWorkerTile from './worker_tile.js';
4
4
 
5
5
  /**
6
6
  * The {@link WorkerSource} implementation that supports {@link VectorTileSource}.
7
- * This class is designed to be easily reused to support custom source types
8
- * for data formats that can be parsed/converted into an in-memory VectorTile
9
- * representation. To do so, create it with
10
- * `new VectorTileWorkerSource(resources, styleLayers, customLoadVectorDataFunction)`.
11
7
  *
12
8
  * @private
13
9
  */
14
10
  class VectorTileWorkerSource {
15
11
  /**
16
- * @param [loadVectorData] Optional method for custom loading of a VectorTile
17
- * object based on parameters passed from the main-thread Source. See
18
12
  * {@link VectorTileWorkerSource#loadTile}. The default implementation simply
19
13
  * loads the pbf at `params.url`.
20
14
  */
@@ -23,7 +17,10 @@ class VectorTileWorkerSource {
23
17
  this.layerIndex = layerIndex;
24
18
  }
25
19
 
26
- loadVectorData(params) {
20
+ /**
21
+ * Implements {@link WorkerSource#loadTile}.
22
+ */
23
+ async loadTile(params) {
27
24
  if (!params.response) {
28
25
  throw new Error('no tile data');
29
26
  }
@@ -31,26 +28,9 @@ class VectorTileWorkerSource {
31
28
  if (!data) {
32
29
  return;
33
30
  }
34
- return {
35
- vectorTile: new VectorTile(new Protobuf(data))
36
- };
37
- }
38
-
39
- /**
40
- * Implements {@link WorkerSource#loadTile}. Delegates to
41
- * {@link VectorTileWorkerSource#loadVectorData} (which by default expects
42
- * a `params.url` property) for fetching and producing a VectorTile object.
43
- */
44
- async loadTile(params) {
45
- const response = this.loadVectorData(params);
46
- if (!response) {
47
- return;
48
- }
49
- const { vectorTile } = response;
31
+ const vectorTile = new VectorTile(new Protobuf(data));
50
32
  const result = await makeWorkerTile(params, vectorTile, this.layerIndex, this.resources);
51
- if (vectorTile) {
52
- result.vectorTile = vectorTile;
53
- }
33
+ result.vectorTile = vectorTile;
54
34
  return result;
55
35
  }
56
36
  }