maplibre-gl 2.2.1 → 2.3.1-pre.2

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 (78) hide show
  1. package/build/generate-query-test-fixtures.ts +3 -2
  2. package/build/generate-struct-arrays.ts +0 -2
  3. package/build/generate-style-spec.ts +12 -17
  4. package/build/generate-typings.ts +11 -1
  5. package/build/rollup_plugins.ts +0 -4
  6. package/dist/maplibre-gl-csp-worker.js +1 -1
  7. package/dist/maplibre-gl-csp.js +1 -1
  8. package/dist/maplibre-gl-dev.js +376 -1402
  9. package/dist/maplibre-gl.d.ts +13 -16
  10. package/dist/maplibre-gl.js +4 -4
  11. package/dist/style-spec/index.d.ts +1768 -0
  12. package/package.json +14 -16
  13. package/src/data/array_types.g.ts +0 -5
  14. package/src/data/bucket/fill_bucket.ts +0 -2
  15. package/src/data/bucket/fill_extrusion_bucket.ts +0 -2
  16. package/src/data/bucket/symbol_bucket.test.ts +30 -19
  17. package/src/data/feature_position_map.ts +1 -2
  18. package/src/gl/framebuffer.ts +3 -2
  19. package/src/gl/index_buffer.ts +1 -2
  20. package/src/gl/vertex_buffer.ts +1 -2
  21. package/src/index.test.ts +9 -0
  22. package/src/index.ts +12 -4
  23. package/src/render/image_manager.ts +5 -7
  24. package/src/render/program/pattern.ts +0 -2
  25. package/src/render/program.ts +12 -9
  26. package/src/render/vertex_array_object.ts +1 -3
  27. package/src/source/geojson_worker_source.ts +0 -4
  28. package/src/source/query_features.ts +0 -3
  29. package/src/source/rtl_text_plugin.ts +3 -4
  30. package/src/source/source_cache.ts +0 -2
  31. package/src/source/tile_id.ts +8 -8
  32. package/src/source/worker.ts +0 -7
  33. package/src/source/worker_tile.ts +12 -3
  34. package/src/style/format_section_override.ts +1 -2
  35. package/src/style/properties.ts +1 -3
  36. package/src/style/style.ts +5 -5
  37. package/src/style/style_layer/custom_style_layer.ts +1 -2
  38. package/src/style/style_layer/symbol_style_layer.ts +1 -3
  39. package/src/style-spec/CHANGELOG.md +10 -0
  40. package/src/style-spec/composite.test.ts +7 -8
  41. package/src/style-spec/expression/compound_expression.ts +0 -4
  42. package/src/style-spec/expression/definitions/assertion.ts +2 -4
  43. package/src/style-spec/expression/definitions/case.ts +1 -2
  44. package/src/style-spec/expression/definitions/coalesce.ts +1 -3
  45. package/src/style-spec/expression/definitions/coercion.ts +2 -4
  46. package/src/style-spec/expression/definitions/match.ts +0 -3
  47. package/src/style-spec/expression/index.ts +13 -15
  48. package/src/style-spec/expression/parsing_context.ts +4 -4
  49. package/src/style-spec/expression/parsing_error.ts +2 -2
  50. package/src/style-spec/expression/values.ts +0 -2
  51. package/src/style-spec/feature_filter/feature_filter.test.ts +39 -2
  52. package/src/style-spec/function/convert.ts +1 -3
  53. package/src/style-spec/migrate/v8.test.ts +12 -14
  54. package/src/style-spec/migrate/v9.test.ts +2 -4
  55. package/src/style-spec/migrate.test.ts +6 -8
  56. package/src/style-spec/package.json +2 -1
  57. package/src/style-spec/types.g.ts +12 -17
  58. package/src/symbol/collision_index.ts +0 -3
  59. package/src/symbol/path_interpolator.ts +0 -2
  60. package/src/symbol/placement.ts +14 -9
  61. package/src/symbol/shaping.ts +0 -4
  62. package/src/symbol/symbol_layout.ts +56 -56
  63. package/src/ui/camera.ts +0 -10
  64. package/src/ui/control/geolocate_control.ts +4 -6
  65. package/src/ui/handler/handler_util.ts +1 -2
  66. package/src/ui/handler/scroll_zoom.ts +0 -2
  67. package/src/ui/handler_manager.ts +0 -2
  68. package/src/ui/map.test.ts +11 -0
  69. package/src/ui/map.ts +11 -0
  70. package/src/util/ajax.ts +1 -2
  71. package/src/util/color_ramp.ts +1 -2
  72. package/src/util/dictionary_coder.ts +1 -3
  73. package/src/util/dispatcher.ts +1 -4
  74. package/src/util/dom.ts +0 -3
  75. package/src/util/image.ts +1 -3
  76. package/src/util/struct_array.ts +0 -5
  77. package/src/util/task_queue.ts +1 -3
  78. package/src/util/web_worker_transfer.ts +5 -6
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "maplibre-gl",
3
3
  "description": "BSD licensed community fork of mapbox-gl, a WebGL interactive maps library",
4
- "version": "2.2.1",
4
+ "version": "2.3.1-pre.2",
5
5
  "main": "dist/maplibre-gl.js",
6
6
  "style": "dist/maplibre-gl.css",
7
7
  "license": "BSD-3-Clause",
@@ -28,6 +28,7 @@
28
28
  "earcut": "^2.2.4",
29
29
  "geojson-vt": "^3.2.1",
30
30
  "gl-matrix": "^3.4.3",
31
+ "global-prefix": "^3.0.0",
31
32
  "murmurhash-js": "^1.0.0",
32
33
  "pbf": "^3.2.1",
33
34
  "potpack": "^1.0.2",
@@ -39,7 +40,7 @@
39
40
  "devDependencies": {
40
41
  "@mapbox/gazetteer": "^5.1.0",
41
42
  "@mapbox/mapbox-gl-rtl-text": "^0.2.3",
42
- "@mapbox/mvt-fixtures": "^3.9.0",
43
+ "@mapbox/mvt-fixtures": "^3.10.0",
43
44
  "@rollup/plugin-commonjs": "^22.0.2",
44
45
  "@rollup/plugin-json": "^4.1.0",
45
46
  "@rollup/plugin-node-resolve": "^13.3.0",
@@ -47,7 +48,6 @@
47
48
  "@rollup/plugin-strip": "^2.1.0",
48
49
  "@rollup/plugin-typescript": "^8.3.4",
49
50
  "@types/benchmark": "^2.1.1",
50
- "@types/browserify": "^12.0.37",
51
51
  "@types/cssnano": "^5.0.0",
52
52
  "@types/d3": "^7.4.0",
53
53
  "@types/diff": "^5.0.2",
@@ -63,7 +63,7 @@
63
63
  "@types/offscreencanvas": "^2019.7.0",
64
64
  "@types/pixelmatch": "^5.2.4",
65
65
  "@types/pngjs": "^6.0.1",
66
- "@types/react": "^18.0.15",
66
+ "@types/react": "^18.0.17",
67
67
  "@types/react-dom": "^18.0.6",
68
68
  "@types/request": "^2.48.8",
69
69
  "@types/rollup-plugin-json": "^3.0.3",
@@ -75,15 +75,14 @@
75
75
  "acorn-import-assertions": "^1.8.0",
76
76
  "address": "^1.2.0",
77
77
  "benchmark": "^2.1.4",
78
- "browserify": "^17.0.0",
79
78
  "canvas": "^2.9.3",
80
- "cssnano": "^5.1.12",
79
+ "cssnano": "^5.1.13",
81
80
  "d3": "^7.6.1",
82
81
  "d3-queue": "^3.0.7",
83
82
  "diff": "^5.1.0",
84
83
  "documentation": "14.0.0-alpha.1",
85
84
  "dts-bundle-generator": "^6.12.0",
86
- "eslint": "^8.21.0",
85
+ "eslint": "^8.22.0",
87
86
  "eslint-config-mourner": "^3.0.0",
88
87
  "eslint-plugin-html": "^7.1.0",
89
88
  "eslint-plugin-import": "^2.26.0",
@@ -106,9 +105,9 @@
106
105
  "node-plantuml": "^0.9.0",
107
106
  "npm-font-open-sans": "^1.1.0",
108
107
  "npm-run-all": "^4.1.5",
109
- "pdf-merger-js": "^3.4.0",
108
+ "pdf-merger-js": "^4.0.0",
110
109
  "pixelmatch": "^5.3.0",
111
- "playwright": "^1.24.2",
110
+ "playwright": "^1.25.0",
112
111
  "pngjs": "^6.0.0",
113
112
  "postcss": "^8.4.14",
114
113
  "postcss-cli": "^10.0.0",
@@ -117,7 +116,7 @@
117
116
  "react": "^18.2.0",
118
117
  "react-dom": "^18.2.0",
119
118
  "request": "^2.88.0",
120
- "rollup": "^2.77.2",
119
+ "rollup": "^2.78.0",
121
120
  "rollup-plugin-import-assert": "^2.1.0",
122
121
  "rollup-plugin-sourcemaps": "^0.6.3",
123
122
  "rollup-plugin-terser": "^7.0.2",
@@ -126,12 +125,11 @@
126
125
  "shuffle-seed": "^1.1.6",
127
126
  "source-map-explorer": "^2.5.2",
128
127
  "st": "^3.0.0",
129
- "stylelint": "^14.9.1",
130
- "stylelint-config-standard": "^26.0.0",
131
- "ts-jest": "^28.0.7",
128
+ "stylelint": "^14.10.0",
129
+ "stylelint-config-standard": "^27.0.0",
130
+ "ts-jest": "^28.0.8",
132
131
  "ts-node": "^10.9.1",
133
- "typescript": "^4.7.4",
134
- "unassert-rollup-plugin": "^2.0.0"
132
+ "typescript": "^4.7.4"
135
133
  },
136
134
  "scripts": {
137
135
  "generate-shaders": "node --loader ts-node/esm --experimental-specifier-resolution=node build/generate-shaders.ts",
@@ -167,7 +165,7 @@
167
165
  "test-render": "node --loader ts-node/esm --experimental-specifier-resolution=node --max-old-space-size=2048 test/integration/render/render.test.ts",
168
166
  "test-query": "jest -c ./jest.config.e2e.ts --roots ./test/integration/query",
169
167
  "test-expression": "jest --roots ./test/integration/expression",
170
- "test-unit": "jest -c ./jest.config.ts --roots ./src",
168
+ "test-unit": "jest --roots ./src -c ./jest.config.ts ",
171
169
  "codegen": "npm run generate-style-code && npm run generate-struct-arrays && npm run generate-style-spec && npm run generate-shaders && npm run generate-debug-index-file",
172
170
  "benchmark": "node --loader ts-node/esm --experimental-specifier-resolution=node test/bench/run-benchmarks.ts",
173
171
  "gl-stats": "node --loader ts-node/esm --experimental-specifier-resolution=node test/bench/gl-stats.ts",
@@ -1,6 +1,5 @@
1
1
  // This file is generated. Edit build/generate-struct-arrays.ts, then run `npm run codegen`.
2
2
 
3
- import assert from 'assert';
4
3
  import {Struct, StructArray} from '../util/struct_array';
5
4
  import {register} from '../util/web_worker_transfer';
6
5
  import Point from '@mapbox/point-geometry';
@@ -877,7 +876,6 @@ export class CollisionBoxArray extends StructArrayLayout6i1ul2ui20 {
877
876
  * @private
878
877
  */
879
878
  get(index: number): CollisionBoxStruct {
880
- assert(!this.isTransferred);
881
879
  return new CollisionBoxStruct(this, index);
882
880
  }
883
881
  }
@@ -922,7 +920,6 @@ export class PlacedSymbolArray extends StructArrayLayout2i2ui3ul3ui2f3ub1ul1i48
922
920
  * @private
923
921
  */
924
922
  get(index: number): PlacedSymbolStruct {
925
- assert(!this.isTransferred);
926
923
  return new PlacedSymbolStruct(this, index);
927
924
  }
928
925
  }
@@ -976,7 +973,6 @@ export class SymbolInstanceArray extends StructArrayLayout8i15ui1ul4f68 {
976
973
  * @private
977
974
  */
978
975
  get(index: number): SymbolInstanceStruct {
979
- assert(!this.isTransferred);
980
976
  return new SymbolInstanceStruct(this, index);
981
977
  }
982
978
  }
@@ -1024,7 +1020,6 @@ export class FeatureIndexArray extends StructArrayLayout1ul2ui8 {
1024
1020
  * @private
1025
1021
  */
1026
1022
  get(index: number): FeatureIndexStruct {
1027
- assert(!this.isTransferred);
1028
1023
  return new FeatureIndexStruct(this, index);
1029
1024
  }
1030
1025
  }
@@ -6,7 +6,6 @@ import {ProgramConfigurationSet} from '../program_configuration';
6
6
  import {LineIndexArray, TriangleIndexArray} from '../index_array_type';
7
7
  import earcut from 'earcut';
8
8
  import classifyRings from '../../util/classify_rings';
9
- import assert from 'assert';
10
9
  const EARCUT_MAX_RINGS = 500;
11
10
  import {register} from '../../util/web_worker_transfer';
12
11
  import {hasPattern, addPatternDependencies} from './pattern_bucket_features';
@@ -211,7 +210,6 @@ class FillBucket implements Bucket {
211
210
  }
212
211
 
213
212
  const indices = earcut(flattened, holeIndices);
214
- assert(indices.length % 3 === 0);
215
213
 
216
214
  for (let i = 0; i < indices.length; i += 3) {
217
215
  this.indexArray.emplaceBack(
@@ -9,7 +9,6 @@ import earcut from 'earcut';
9
9
  import mvt from '@mapbox/vector-tile';
10
10
  const vectorTileFeatureTypes = mvt.VectorTileFeature.types;
11
11
  import classifyRings from '../../util/classify_rings';
12
- import assert from 'assert';
13
12
  const EARCUT_MAX_RINGS = 500;
14
13
  import {register} from '../../util/web_worker_transfer';
15
14
  import {hasPattern, addPatternDependencies} from './pattern_bucket_features';
@@ -264,7 +263,6 @@ class FillExtrusionBucket implements Bucket {
264
263
  }
265
264
 
266
265
  const indices = earcut(flattened, holeIndices);
267
- assert(indices.length % 3 === 0);
268
266
 
269
267
  for (let j = 0; j < indices.length; j += 3) {
270
268
  // Counter-clockwise winding order.
@@ -1,5 +1,3 @@
1
- // @ts-nocheck
2
-
3
1
  import fs from 'fs';
4
2
  import path from 'path';
5
3
  import Protobuf from 'pbf';
@@ -9,7 +7,7 @@ import {CollisionBoxArray} from '../../data/array_types.g';
9
7
  import {performSymbolLayout} from '../../symbol/symbol_layout';
10
8
  import {Placement} from '../../symbol/placement';
11
9
  import Transform from '../../geo/transform';
12
- import {OverscaledTileID} from '../../source/tile_id';
10
+ import {CanonicalTileID, OverscaledTileID} from '../../source/tile_id';
13
11
  import Tile from '../../source/tile';
14
12
  import CrossTileSymbolIndex from '../../symbol/cross_tile_symbol_index';
15
13
  import FeatureIndex from '../../data/feature_index';
@@ -66,26 +64,33 @@ describe('SymbolBucket', () => {
66
64
  const bucketA = bucketSetup() as any as SymbolBucket;
67
65
  const bucketB = bucketSetup() as any as SymbolBucket;
68
66
  const options = {iconDependencies: {}, glyphDependencies: {}} as PopulateParameters;
69
- const placement = new Placement(transform, 0, true);
67
+ const placement = new Placement(transform, undefined as any, 0, true);
70
68
  const tileID = new OverscaledTileID(0, 0, 0, 0, 0);
71
69
  const crossTileSymbolIndex = new CrossTileSymbolIndex();
72
70
 
73
71
  // add feature from bucket A
74
- bucketA.populate([{feature} as IndexedFeature], options, undefined);
75
- performSymbolLayout(bucketA, stacks, {}, undefined, undefined, undefined, undefined);
72
+ bucketA.populate([{feature} as IndexedFeature], options, undefined as any);
73
+ performSymbolLayout(
74
+ {
75
+ bucket: bucketA,
76
+ glyphMap: stacks,
77
+ glyphPositions: {}
78
+ } as any);
76
79
  const tileA = new Tile(tileID, 512);
77
80
  tileA.latestFeatureIndex = new FeatureIndex(tileID);
78
81
  tileA.buckets = {test: bucketA};
79
82
  tileA.collisionBoxArray = collisionBoxArray;
80
83
 
81
84
  // add same feature from bucket B
82
- bucketB.populate([{feature} as IndexedFeature], options, undefined);
83
- performSymbolLayout(bucketB, stacks, {}, undefined, undefined, undefined, undefined);
85
+ bucketB.populate([{feature} as IndexedFeature], options, undefined as any);
86
+ performSymbolLayout({
87
+ bucket: bucketB, glyphMap: stacks, glyphPositions: {}
88
+ } as any);
84
89
  const tileB = new Tile(tileID, 512);
85
90
  tileB.buckets = {test: bucketB};
86
91
  tileB.collisionBoxArray = collisionBoxArray;
87
92
 
88
- crossTileSymbolIndex.addLayer(bucketA.layers[0], [tileA, tileB], undefined);
93
+ crossTileSymbolIndex.addLayer(bucketA.layers[0], [tileA, tileB], undefined as any);
89
94
 
90
95
  const place = (layer, tile) => {
91
96
  const parts = [];
@@ -112,9 +117,13 @@ describe('SymbolBucket', () => {
112
117
  const bucket = bucketSetup() as any as SymbolBucket;
113
118
  const options = {iconDependencies: {}, glyphDependencies: {}} as PopulateParameters;
114
119
 
115
- bucket.populate([{feature} as IndexedFeature], options, undefined);
120
+ bucket.populate([{feature} as IndexedFeature], options, undefined as any);
116
121
  const fakeGlyph = {rect: {w: 10, h: 10}, metrics: {left: 10, top: 10, advance: 10}};
117
- performSymbolLayout(bucket, stacks, {'Test': {97: fakeGlyph, 98: fakeGlyph, 99: fakeGlyph, 100: fakeGlyph, 101: fakeGlyph, 102: fakeGlyph} as any}, undefined, undefined, undefined, undefined);
122
+ performSymbolLayout({
123
+ bucket,
124
+ glyphMap: stacks,
125
+ glyphPositions: {'Test': {97: fakeGlyph, 98: fakeGlyph, 99: fakeGlyph, 100: fakeGlyph, 101: fakeGlyph, 102: fakeGlyph} as any}
126
+ } as any);
118
127
 
119
128
  expect(spy).toHaveBeenCalledTimes(1);
120
129
  expect(spy.mock.calls[0][0].includes('Too many glyphs being rendered in a tile.')).toBeTruthy();
@@ -146,14 +155,16 @@ describe('SymbolBucket', () => {
146
155
  createIndexedFeature(1, 1, 'b'),
147
156
  createIndexedFeature(2, 2, 'a')
148
157
  ] as any as IndexedFeature[],
149
- options, undefined
158
+ options, undefined as any
150
159
  );
151
160
 
152
161
  const icons = options.iconDependencies as any;
153
162
  expect(icons.a).toBe(true);
154
163
  expect(icons.b).toBe(true);
155
164
 
156
- performSymbolLayout(bucket, null, null, imageMap, imagePos, undefined, undefined);
165
+ performSymbolLayout({
166
+ bucket, imageMap, imagePositions: imagePos
167
+ } as any);
157
168
 
158
169
  // undefined SDF should be treated the same as false SDF - no warning raised
159
170
  expect(spy).not.toHaveBeenCalledTimes(1);
@@ -186,14 +197,14 @@ describe('SymbolBucket', () => {
186
197
  createIndexedFeature(1, 1, 'b'),
187
198
  createIndexedFeature(2, 2, 'a')
188
199
  ] as any as IndexedFeature[],
189
- options, undefined
200
+ options, undefined as unknown as CanonicalTileID
190
201
  );
191
202
 
192
203
  const icons = options.iconDependencies as any;
193
204
  expect(icons.a).toBe(true);
194
205
  expect(icons.b).toBe(true);
195
206
 
196
- performSymbolLayout(bucket, null, null, imageMap, imagePos, undefined, undefined);
207
+ performSymbolLayout({bucket, imageMap, imagePositions: imagePos} as any);
197
208
 
198
209
  // true SDF and false SDF in same bucket should trigger warning
199
210
  expect(spy).toHaveBeenCalledTimes(1);
@@ -203,8 +214,8 @@ describe('SymbolBucket', () => {
203
214
  const rtlBucket = bucketSetup('مرحبا');
204
215
  const ltrBucket = bucketSetup('hello');
205
216
  const options = {iconDependencies: {}, glyphDependencies: {}} as PopulateParameters;
206
- rtlBucket.populate([{feature} as IndexedFeature], options, undefined);
207
- ltrBucket.populate([{feature} as IndexedFeature], options, undefined);
217
+ rtlBucket.populate([{feature} as IndexedFeature], options, undefined as any);
218
+ ltrBucket.populate([{feature} as IndexedFeature], options, undefined as any);
208
219
 
209
220
  expect(rtlBucket.hasRTLText).toBeTruthy();
210
221
  expect(ltrBucket.hasRTLText).toBeFalsy();
@@ -215,7 +226,7 @@ describe('SymbolBucket', () => {
215
226
  const rtlBucket = bucketSetup('مرحبا');
216
227
  const options = {iconDependencies: {}, glyphDependencies: {}} as PopulateParameters;
217
228
  rtlBucket.createArrays();
218
- rtlBucket.populate([{feature} as IndexedFeature], options, undefined);
229
+ rtlBucket.populate([{feature} as IndexedFeature], options, undefined as any);
219
230
 
220
231
  expect(rtlBucket.isEmpty()).toBeFalsy();
221
232
  expect(rtlBucket.symbolInstances).toHaveLength(0);
@@ -224,7 +235,7 @@ describe('SymbolBucket', () => {
224
235
  test('SymbolBucket detects rtl text mixed with ltr text', () => {
225
236
  const mixedBucket = bucketSetup('مرحبا translates to hello');
226
237
  const options = {iconDependencies: {}, glyphDependencies: {}} as PopulateParameters;
227
- mixedBucket.populate([{feature} as IndexedFeature], options, undefined);
238
+ mixedBucket.populate([{feature} as IndexedFeature], options, undefined as any);
228
239
 
229
240
  expect(mixedBucket.hasRTLText).toBeTruthy();
230
241
  });
@@ -1,6 +1,5 @@
1
1
  import murmur3 from 'murmurhash-js';
2
2
  import {register} from '../util/web_worker_transfer';
3
- import assert from 'assert';
4
3
 
5
4
  type SerializedFeaturePositionMap = {
6
5
  ids: Float64Array;
@@ -31,7 +30,7 @@ export default class FeaturePositionMap {
31
30
  }
32
31
 
33
32
  getPositions(id: unknown): Array<FeaturePosition> {
34
- assert(this.indexed);
33
+ if (!this.indexed) throw new Error('Trying to get index, but feature positions are not indexed');
35
34
 
36
35
  const intId = getNumericId(id);
37
36
 
@@ -1,5 +1,4 @@
1
1
  import {ColorAttachment, DepthAttachment} from './value';
2
- import assert from 'assert';
3
2
 
4
3
  import type Context from './context';
5
4
 
@@ -22,7 +21,9 @@ class Framebuffer {
22
21
  if (hasDepth) {
23
22
  this.depthAttachment = new DepthAttachment(context, fbo);
24
23
  }
25
- assert(gl.checkFramebufferStatus(gl.FRAMEBUFFER) === gl.FRAMEBUFFER_COMPLETE);
24
+ if (gl.checkFramebufferStatus(gl.FRAMEBUFFER) !== gl.FRAMEBUFFER_COMPLETE) {
25
+ throw new Error('Framebuffer is not complete');
26
+ }
26
27
  }
27
28
 
28
29
  destroy() {
@@ -1,4 +1,3 @@
1
- import assert from 'assert';
2
1
 
3
2
  import type {StructArray} from '../util/struct_array';
4
3
  import type {TriangleIndexArray, LineIndexArray, LineStripIndexArray} from '../data/index_array_type';
@@ -34,7 +33,7 @@ class IndexBuffer {
34
33
 
35
34
  updateData(array: StructArray) {
36
35
  const gl = this.context.gl;
37
- assert(this.dynamicDraw);
36
+ if (!this.dynamicDraw) throw new Error('Attempted to update data while not in dynamic mode.');
38
37
  // The right VAO will get this buffer re-bound later in VertexArrayObject#bind
39
38
  // See https://github.com/mapbox/mapbox-gl-js/issues/5620
40
39
  this.context.unbindVAO();
@@ -1,4 +1,3 @@
1
- import assert from 'assert';
2
1
 
3
2
  import type {
4
3
  StructArray,
@@ -62,7 +61,7 @@ class VertexBuffer {
62
61
  }
63
62
 
64
63
  updateData(array: StructArray) {
65
- assert(array.length === this.length);
64
+ if (array.length !== this.length) throw new Error(`Length of new data is ${array.length}, which doesn't match current length of ${this.length}`);
66
65
  const gl = this.context.gl;
67
66
  this.bind();
68
67
  gl.bufferSubData(gl.ARRAY_BUFFER, 0, array.arrayBuffer);
package/src/index.test.ts CHANGED
@@ -4,4 +4,13 @@ describe('maplibre', () => {
4
4
  test('workerCount', () => {
5
5
  expect(typeof maplibre.workerCount === 'number').toBeTruthy();
6
6
  });
7
+
8
+ test('version', () => {
9
+ expect(typeof maplibre.version === 'string').toBeTruthy();
10
+
11
+ // Semver regex: https://gist.github.com/jhorsman/62eeea161a13b80e39f5249281e17c39
12
+ // Backslashes are doubled to escape them
13
+ const regexp = new RegExp('^([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$');
14
+ expect(regexp.test(maplibre.version)).toBeTruthy();
15
+ });
7
16
  });
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
- import assert from 'assert';
2
1
  import {supported} from '@mapbox/mapbox-gl-supported';
3
-
2
+ import packageJSON from '../package.json' assert {type: 'json'};
4
3
  import Map from './ui/map';
5
4
  import NavigationControl from './ui/control/navigation_control';
6
5
  import GeolocateControl from './ui/control/geolocate_control';
@@ -36,6 +35,8 @@ import RasterTileSource from './source/raster_tile_source';
36
35
  import VectorTileSource from './source/vector_tile_source';
37
36
  import VideoSource from './source/video_source';
38
37
 
38
+ const version = packageJSON.version;
39
+
39
40
  const exported = {
40
41
  supported,
41
42
  setRTLTextPlugin,
@@ -99,6 +100,14 @@ const exported = {
99
100
  */
100
101
  clearPrewarmedResources,
101
102
 
103
+ /**
104
+ * Returns the package version of the library
105
+ * @returns {string} Package version of the library
106
+ */
107
+ get version(): string {
108
+ return version;
109
+ },
110
+
102
111
  /**
103
112
  * Gets and sets the number of web workers instantiated on a page with GL JS maps.
104
113
  * By default, it is set to half the number of CPU cores (capped at 6).
@@ -252,5 +261,4 @@ Debug.extend(exported, {isSafari, getPerformanceMetrics: PerformanceUtils.getPer
252
261
  */
253
262
 
254
263
  export default exported;
255
- // canary assert: used to confirm that asserts have been removed from production build
256
- assert(true, 'canary assert');
264
+
@@ -5,7 +5,6 @@ import {Event, ErrorEvent, Evented} from '../util/evented';
5
5
  import {RGBAImage} from '../util/image';
6
6
  import {ImagePosition} from './image_atlas';
7
7
  import Texture from './texture';
8
- import assert from 'assert';
9
8
  import {renderStyleImage} from '../style/style_image';
10
9
  import {warnOnce} from '../util/util';
11
10
 
@@ -88,7 +87,7 @@ class ImageManager extends Evented {
88
87
  }
89
88
 
90
89
  addImage(id: string, image: StyleImage) {
91
- assert(!this.images[id]);
90
+ if (this.images[id]) throw new Error(`Image id ${id} already exist, use updateImage instead`);
92
91
  if (this._validate(id, image)) {
93
92
  this.images[id] = image;
94
93
  }
@@ -135,16 +134,15 @@ class ImageManager extends Evented {
135
134
 
136
135
  updateImage(id: string, image: StyleImage) {
137
136
  const oldImage = this.images[id];
138
- assert(oldImage);
139
- assert(oldImage.data.width === image.data.width);
140
- assert(oldImage.data.height === image.data.height);
137
+ if (oldImage.data.width !== image.data.width || oldImage.data.height !== image.data.height) {
138
+ throw new Error(`size mismatch between old image (${oldImage.data.width}x${oldImage.data.height}) and new image (${image.data.width}x${image.data.height}).`);
139
+ }
141
140
  image.version = oldImage.version + 1;
142
141
  this.images[id] = image;
143
142
  this.updatedImages[id] = true;
144
143
  }
145
144
 
146
145
  removeImage(id: string) {
147
- assert(this.images[id]);
148
146
  const image = this.images[id];
149
147
  delete this.images[id];
150
148
  delete this.patterns[id];
@@ -295,7 +293,7 @@ class ImageManager extends Evented {
295
293
  this.callbackDispatchedThisFrame[id] = true;
296
294
 
297
295
  const image = this.images[id];
298
- assert(image);
296
+ if (!image) warnOnce(`Image with ID: "${id}" was not found`);
299
297
 
300
298
  const updated = renderStyleImage(image);
301
299
  if (updated) {
@@ -1,4 +1,3 @@
1
- import assert from 'assert';
2
1
  import {
3
2
  Uniform1i,
4
3
  Uniform1f,
@@ -74,7 +73,6 @@ function bgPatternUniformValues(
74
73
  ): UniformValues<BackgroundPatternUniformsType> {
75
74
  const imagePosA = painter.imageManager.getPattern(image.from.toString());
76
75
  const imagePosB = painter.imageManager.getPattern(image.to.toString());
77
- assert(imagePosA && imagePosB);
78
76
  const {width, height} = painter.imageManager.getPixelSize();
79
77
 
80
78
  const numTiles = Math.pow(2, tile.tileID.overscaledZ);
@@ -1,5 +1,4 @@
1
1
  import shaders from '../shaders/shaders';
2
- import assert from 'assert';
3
2
  import ProgramConfiguration from '../data/program_configuration';
4
3
  import VertexArrayObject from './vertex_array_object';
5
4
  import Context from '../gl/context';
@@ -84,7 +83,6 @@ class Program<Us extends UniformBindings> {
84
83
  }
85
84
  gl.shaderSource(fragmentShader, fragmentSource);
86
85
  gl.compileShader(fragmentShader);
87
- assert(gl.getShaderParameter(fragmentShader, gl.COMPILE_STATUS), (gl.getShaderInfoLog(fragmentShader) as any));
88
86
  gl.attachShader(this.program, fragmentShader);
89
87
 
90
88
  const vertexShader = gl.createShader(gl.VERTEX_SHADER);
@@ -94,7 +92,6 @@ class Program<Us extends UniformBindings> {
94
92
  }
95
93
  gl.shaderSource(vertexShader, vertexSource);
96
94
  gl.compileShader(vertexShader);
97
- assert(gl.getShaderParameter(vertexShader, gl.COMPILE_STATUS), (gl.getShaderInfoLog(vertexShader) as any));
98
95
  gl.attachShader(this.program, vertexShader);
99
96
 
100
97
  this.attributes = {};
@@ -110,7 +107,6 @@ class Program<Us extends UniformBindings> {
110
107
  }
111
108
 
112
109
  gl.linkProgram(this.program);
113
- assert(gl.getProgramParameter(this.program, gl.LINK_STATUS), (gl.getProgramInfoLog(this.program) as any));
114
110
 
115
111
  gl.deleteShader(vertexShader);
116
112
  gl.deleteShader(fragmentShader);
@@ -178,11 +174,18 @@ class Program<Us extends UniformBindings> {
178
174
  configuration.setUniforms(context, this.binderUniforms, currentProperties, {zoom: (zoom as any)});
179
175
  }
180
176
 
181
- const primitiveSize = {
182
- [gl.LINES]: 2,
183
- [gl.TRIANGLES]: 3,
184
- [gl.LINE_STRIP]: 1
185
- }[drawMode];
177
+ let primitiveSize = 0;
178
+ switch (drawMode) {
179
+ case gl.LINES:
180
+ primitiveSize = 2;
181
+ break;
182
+ case gl.TRIANGLES:
183
+ primitiveSize = 3;
184
+ break;
185
+ case gl.LINE_STRIP:
186
+ primitiveSize = 1;
187
+ break;
188
+ }
186
189
 
187
190
  for (const segment of segments.get()) {
188
191
  const vaos = segment.vaos || (segment.vaos = {});
@@ -1,4 +1,3 @@
1
- import assert from 'assert';
2
1
 
3
2
  import type Program from './program';
4
3
  import type VertexBuffer from '../gl/vertex_buffer';
@@ -119,9 +118,8 @@ class VertexArrayObject {
119
118
  // Disable all attributes from the previous program that aren't used in
120
119
  // the new program. Note: attribute indices are *not* program specific!
121
120
  for (let i = numNextAttributes; i < numPrevAttributes; i++) {
122
- // WebGL breaks if you disable attribute 0.
121
+ // WebGL breaks if you disable attribute 0, so if i == 0.
123
122
  // http://stackoverflow.com/questions/20305231
124
- assert(i !== 0);
125
123
  gl.disableVertexAttribArray(i);
126
124
  }
127
125
  }
@@ -6,7 +6,6 @@ import GeoJSONWrapper from './geojson_wrapper';
6
6
  import vtpbf from 'vt-pbf';
7
7
  import Supercluster from 'supercluster';
8
8
  import geojsonvt from 'geojson-vt';
9
- import assert from 'assert';
10
9
  import VectorTileWorkerSource from './vector_tile_worker_source';
11
10
  import {createExpression} from '../style-spec/expression';
12
11
 
@@ -292,9 +291,6 @@ function getSuperclusterOptions({superclusterOptions, clusterProperties}: { supe
292
291
  const reduceExpressionParsed = createExpression(
293
292
  typeof operator === 'string' ? [operator, ['accumulated'], ['get', key]] : operator);
294
293
 
295
- assert(mapExpressionParsed.result === 'success');
296
- assert(reduceExpressionParsed.result === 'success');
297
-
298
294
  mapExpressions[key] = mapExpressionParsed.value;
299
295
  reduceExpressions[key] = reduceExpressionParsed.value;
300
296
  }
@@ -6,7 +6,6 @@ import type {RetainedQueryData} from '../symbol/placement';
6
6
  import type {FilterSpecification} from '../style-spec/types.g';
7
7
  import type {MapGeoJSONFeature} from '../util/vectortile_to_geojson';
8
8
  import type Point from '@mapbox/point-geometry';
9
- import assert from 'assert';
10
9
  import {mat4} from 'gl-matrix';
11
10
 
12
11
  /*
@@ -137,8 +136,6 @@ export function queryRenderedSymbols(styleLayers: {[_: string]: StyleLayer},
137
136
  // we sort each feature based on the first matching symbol instance.
138
137
  const sortedA = featureSortOrder.indexOf(a.featureIndex);
139
138
  const sortedB = featureSortOrder.indexOf(b.featureIndex);
140
- assert(sortedA >= 0);
141
- assert(sortedB >= 0);
142
139
  return sortedB - sortedA;
143
140
  } else {
144
141
  // Bucket hasn't been re-sorted based on angle, so use the
@@ -1,7 +1,6 @@
1
1
  import {Event, Evented} from '../util/evented';
2
2
  import {getArrayBuffer} from '../util/ajax';
3
3
  import browser from '../util/browser';
4
- import assert from 'assert';
5
4
  import {isWorker} from '../util/util';
6
5
 
7
6
  const status = {
@@ -113,20 +112,20 @@ export const plugin: {
113
112
  return pluginStatus === status.loading;
114
113
  },
115
114
  setState(state: PluginState) { // Worker thread only: this tells the worker threads that the plugin is available on the Main thread
116
- assert(isWorker(), 'Cannot set the state of the rtl-text-plugin when not in the web-worker context');
115
+ if (!isWorker()) throw new Error('Cannot set the state of the rtl-text-plugin when not in the web-worker context');
117
116
 
118
117
  pluginStatus = state.pluginStatus;
119
118
  pluginURL = state.pluginURL;
120
119
  },
121
120
  isParsed(): boolean {
122
- assert(isWorker(), 'rtl-text-plugin is only parsed on the worker-threads');
121
+ if (!isWorker()) throw new Error('rtl-text-plugin is only parsed on the worker-threads');
123
122
 
124
123
  return plugin.applyArabicShaping != null &&
125
124
  plugin.processBidirectionalText != null &&
126
125
  plugin.processStyledBidirectionalText != null;
127
126
  },
128
127
  getPluginURL(): string {
129
- assert(isWorker(), 'rtl-text-plugin url can only be queried from the worker threads');
128
+ if (!isWorker()) throw new Error('rtl-text-plugin url can only be queried from the worker threads');
130
129
  return pluginURL;
131
130
  }
132
131
  };
@@ -10,7 +10,6 @@ import Context from '../gl/context';
10
10
  import Point from '@mapbox/point-geometry';
11
11
  import browser from '../util/browser';
12
12
  import {OverscaledTileID} from './tile_id';
13
- import assert from 'assert';
14
13
  import SourceFeatureState from './source_state';
15
14
 
16
15
  import type {Source} from './source';
@@ -556,7 +555,6 @@ class SourceCache extends Evented {
556
555
  const ids = Object.keys(retain);
557
556
  for (const id of ids) {
558
557
  const tileID = retain[id];
559
- assert(tileID.key === id);
560
558
 
561
559
  const tile = this._tiles[id];
562
560
  if (!tile || tile.fadeEndTime && tile.fadeEndTime <= browser.now()) continue;