maplibre-gl 2.2.0 → 2.3.1-pre.1

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 (80) hide show
  1. package/build/generate-struct-arrays.ts +0 -2
  2. package/build/generate-style-spec.ts +2 -3
  3. package/build/generate-typings.ts +12 -2
  4. package/build/rollup_plugins.ts +0 -4
  5. package/dist/maplibre-gl-csp-worker.js +1 -1
  6. package/dist/maplibre-gl-csp.js +1 -1
  7. package/dist/maplibre-gl-dev.js +368 -1404
  8. package/dist/maplibre-gl.d.ts +19 -11
  9. package/dist/maplibre-gl.js +4 -4
  10. package/dist/style-spec/index.d.ts +1779 -0
  11. package/package.json +10 -12
  12. package/src/data/array_types.g.ts +0 -5
  13. package/src/data/bucket/fill_bucket.ts +0 -2
  14. package/src/data/bucket/fill_extrusion_bucket.ts +0 -2
  15. package/src/data/bucket/symbol_bucket.test.ts +30 -19
  16. package/src/data/feature_position_map.ts +1 -2
  17. package/src/gl/framebuffer.ts +3 -2
  18. package/src/gl/index_buffer.ts +1 -2
  19. package/src/gl/vertex_buffer.ts +1 -2
  20. package/src/index.test.ts +9 -0
  21. package/src/index.ts +12 -4
  22. package/src/render/image_manager.ts +5 -7
  23. package/src/render/program/pattern.ts +0 -2
  24. package/src/render/program.ts +0 -4
  25. package/src/render/vertex_array_object.ts +1 -3
  26. package/src/source/geojson_worker_source.ts +0 -4
  27. package/src/source/query_features.ts +0 -3
  28. package/src/source/rtl_text_plugin.ts +3 -4
  29. package/src/source/source_cache.ts +0 -2
  30. package/src/source/tile_id.ts +8 -8
  31. package/src/source/worker.ts +2 -11
  32. package/src/source/worker_tile.ts +12 -3
  33. package/src/style/format_section_override.ts +1 -2
  34. package/src/style/properties.ts +1 -3
  35. package/src/style/style.ts +5 -5
  36. package/src/style/style_layer/custom_style_layer.ts +1 -2
  37. package/src/style/style_layer/symbol_style_layer.ts +1 -3
  38. package/src/style-spec/CHANGELOG.md +10 -0
  39. package/src/style-spec/composite.test.ts +7 -8
  40. package/src/style-spec/expression/compound_expression.ts +0 -4
  41. package/src/style-spec/expression/definitions/assertion.ts +2 -4
  42. package/src/style-spec/expression/definitions/case.ts +1 -2
  43. package/src/style-spec/expression/definitions/coalesce.ts +1 -3
  44. package/src/style-spec/expression/definitions/coercion.ts +2 -4
  45. package/src/style-spec/expression/definitions/match.ts +0 -3
  46. package/src/style-spec/expression/index.ts +13 -15
  47. package/src/style-spec/expression/parsing_context.ts +4 -4
  48. package/src/style-spec/expression/parsing_error.ts +2 -2
  49. package/src/style-spec/expression/values.ts +0 -2
  50. package/src/style-spec/feature_filter/feature_filter.test.ts +7 -0
  51. package/src/style-spec/function/convert.ts +1 -3
  52. package/src/style-spec/migrate/v8.test.ts +12 -14
  53. package/src/style-spec/migrate/v9.test.ts +2 -4
  54. package/src/style-spec/migrate.test.ts +6 -8
  55. package/src/style-spec/package.json +2 -1
  56. package/src/style-spec/reference/latest.ts +1 -1
  57. package/src/style-spec/style-spec.ts +11 -10
  58. package/src/style-spec/types.g.ts +2 -3
  59. package/src/symbol/collision_index.ts +0 -3
  60. package/src/symbol/path_interpolator.ts +0 -2
  61. package/src/symbol/placement.ts +14 -9
  62. package/src/symbol/shaping.ts +0 -4
  63. package/src/symbol/symbol_layout.ts +56 -56
  64. package/src/ui/camera.ts +0 -10
  65. package/src/ui/control/geolocate_control.ts +4 -6
  66. package/src/ui/handler/handler_util.ts +1 -2
  67. package/src/ui/handler/scroll_zoom.ts +0 -2
  68. package/src/ui/handler_manager.ts +0 -2
  69. package/src/ui/map.test.ts +11 -0
  70. package/src/ui/map.ts +11 -0
  71. package/src/util/ajax.ts +1 -2
  72. package/src/util/color_ramp.ts +1 -2
  73. package/src/util/dictionary_coder.ts +1 -3
  74. package/src/util/dispatcher.ts +1 -4
  75. package/src/util/dom.ts +0 -3
  76. package/src/util/image.ts +1 -3
  77. package/src/util/struct_array.ts +0 -5
  78. package/src/util/task_queue.ts +1 -3
  79. package/src/util/util.ts +2 -3
  80. package/src/util/web_worker_transfer.ts +5 -6
@@ -151,55 +151,55 @@ export function evaluateVariableOffset(anchor: TextAnchor, offset: [number, numb
151
151
  return (offset[1] !== INVALID_TEXT_OFFSET) ? fromTextOffset(anchor, offset[0], offset[1]) : fromRadialOffset(anchor, offset[0]);
152
152
  }
153
153
 
154
- export function performSymbolLayout(
155
- bucket: SymbolBucket,
154
+ export function performSymbolLayout(args: {
155
+ bucket: SymbolBucket;
156
156
  glyphMap: {
157
157
  [_: string]: {
158
158
  [x: number]: StyleGlyph;
159
159
  };
160
- },
160
+ };
161
161
  glyphPositions: {
162
162
  [_: string]: {
163
163
  [x: number]: GlyphPosition;
164
164
  };
165
- },
166
- imageMap: {[_: string]: StyleImage},
167
- imagePositions: {[_: string]: ImagePosition},
168
- showCollisionBoxes: boolean,
169
- canonical: CanonicalTileID
170
- ) {
171
- bucket.createArrays();
165
+ };
166
+ imageMap: {[_: string]: StyleImage};
167
+ imagePositions: {[_: string]: ImagePosition};
168
+ showCollisionBoxes: boolean;
169
+ canonical: CanonicalTileID;
170
+ }) {
171
+ args.bucket.createArrays();
172
172
 
173
- const tileSize = 512 * bucket.overscaling;
174
- bucket.tilePixelRatio = EXTENT / tileSize;
175
- bucket.compareText = {};
176
- bucket.iconsNeedLinear = false;
173
+ const tileSize = 512 * args.bucket.overscaling;
174
+ args.bucket.tilePixelRatio = EXTENT / tileSize;
175
+ args.bucket.compareText = {};
176
+ args.bucket.iconsNeedLinear = false;
177
177
 
178
- const layout = bucket.layers[0].layout;
179
- const unevaluatedLayoutValues = bucket.layers[0]._unevaluatedLayout._values;
178
+ const layout = args.bucket.layers[0].layout;
179
+ const unevaluatedLayoutValues = args.bucket.layers[0]._unevaluatedLayout._values;
180
180
 
181
181
  const sizes: Sizes = {
182
182
  // Filled in below, if *SizeData.kind is 'composite'
183
183
  // compositeIconSizes: undefined,
184
184
  // compositeTextSizes: undefined,
185
- layoutIconSize: unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(bucket.zoom + 1), canonical),
186
- layoutTextSize: unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(bucket.zoom + 1), canonical),
185
+ layoutIconSize: unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(args.bucket.zoom + 1), args.canonical),
186
+ layoutTextSize: unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(args.bucket.zoom + 1), args.canonical),
187
187
  textMaxSize: unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(18))
188
188
  } as Sizes;
189
189
 
190
- if (bucket.textSizeData.kind === 'composite') {
191
- const {minZoom, maxZoom} = bucket.textSizeData;
190
+ if (args.bucket.textSizeData.kind === 'composite') {
191
+ const {minZoom, maxZoom} = args.bucket.textSizeData;
192
192
  sizes.compositeTextSizes = [
193
- unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(minZoom), canonical),
194
- unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(maxZoom), canonical)
193
+ unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(minZoom), args.canonical),
194
+ unevaluatedLayoutValues['text-size'].possiblyEvaluate(new EvaluationParameters(maxZoom), args.canonical)
195
195
  ];
196
196
  }
197
197
 
198
- if (bucket.iconSizeData.kind === 'composite') {
199
- const {minZoom, maxZoom} = bucket.iconSizeData;
198
+ if (args.bucket.iconSizeData.kind === 'composite') {
199
+ const {minZoom, maxZoom} = args.bucket.iconSizeData;
200
200
  sizes.compositeIconSizes = [
201
- unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(minZoom), canonical),
202
- unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(maxZoom), canonical)
201
+ unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(minZoom), args.canonical),
202
+ unevaluatedLayoutValues['icon-size'].possiblyEvaluate(new EvaluationParameters(maxZoom), args.canonical)
203
203
  ];
204
204
  }
205
205
 
@@ -208,11 +208,11 @@ export function performSymbolLayout(
208
208
  const keepUpright = layout.get('text-keep-upright');
209
209
  const textSize = layout.get('text-size');
210
210
 
211
- for (const feature of bucket.features) {
212
- const fontstack = layout.get('text-font').evaluate(feature, {}, canonical).join(',');
213
- const layoutTextSizeThisZoom = textSize.evaluate(feature, {}, canonical);
214
- const layoutTextSize = sizes.layoutTextSize.evaluate(feature, {}, canonical);
215
- const layoutIconSize = sizes.layoutIconSize.evaluate(feature, {}, canonical);
211
+ for (const feature of args.bucket.features) {
212
+ const fontstack = layout.get('text-font').evaluate(feature, {}, args.canonical).join(',');
213
+ const layoutTextSizeThisZoom = textSize.evaluate(feature, {}, args.canonical);
214
+ const layoutTextSize = sizes.layoutTextSize.evaluate(feature, {}, args.canonical);
215
+ const layoutIconSize = sizes.layoutIconSize.evaluate(feature, {}, args.canonical);
216
216
 
217
217
  const shapedTextOrientations: ShapedTextOrientations = {
218
218
  horizontal: {} as Record<TextJustify, Shaping>,
@@ -222,14 +222,14 @@ export function performSymbolLayout(
222
222
  let textOffset: [number, number] = [0, 0];
223
223
  if (text) {
224
224
  const unformattedText = text.toString();
225
- const spacing = layout.get('text-letter-spacing').evaluate(feature, {}, canonical) * ONE_EM;
225
+ const spacing = layout.get('text-letter-spacing').evaluate(feature, {}, args.canonical) * ONE_EM;
226
226
  const spacingIfAllowed = allowsLetterSpacing(unformattedText) ? spacing : 0;
227
227
 
228
- const textAnchor = layout.get('text-anchor').evaluate(feature, {}, canonical);
228
+ const textAnchor = layout.get('text-anchor').evaluate(feature, {}, args.canonical);
229
229
  const variableTextAnchor = layout.get('text-variable-anchor');
230
230
 
231
231
  if (!variableTextAnchor) {
232
- const radialOffset = layout.get('text-radial-offset').evaluate(feature, {}, canonical);
232
+ const radialOffset = layout.get('text-radial-offset').evaluate(feature, {}, args.canonical);
233
233
  // Layers with variable anchors use the `text-radial-offset` property and the [x, y] offset vector
234
234
  // is calculated at placement time instead of layout time
235
235
  if (radialOffset) {
@@ -237,25 +237,25 @@ export function performSymbolLayout(
237
237
  // but doesn't actually specify what happens if you use both. We go with the radial offset.
238
238
  textOffset = evaluateVariableOffset(textAnchor, [radialOffset * ONE_EM, INVALID_TEXT_OFFSET]) as [number, number];
239
239
  } else {
240
- textOffset = (layout.get('text-offset').evaluate(feature, {}, canonical).map(t => t * ONE_EM) as [number, number]);
240
+ textOffset = (layout.get('text-offset').evaluate(feature, {}, args.canonical).map(t => t * ONE_EM) as [number, number]);
241
241
  }
242
242
  }
243
243
 
244
244
  let textJustify = textAlongLine ?
245
245
  'center' :
246
- layout.get('text-justify').evaluate(feature, {}, canonical);
246
+ layout.get('text-justify').evaluate(feature, {}, args.canonical);
247
247
 
248
248
  const symbolPlacement = layout.get('symbol-placement');
249
249
  const maxWidth = symbolPlacement === 'point' ?
250
- layout.get('text-max-width').evaluate(feature, {}, canonical) * ONE_EM :
250
+ layout.get('text-max-width').evaluate(feature, {}, args.canonical) * ONE_EM :
251
251
  0;
252
252
 
253
253
  const addVerticalShapingForPointLabelIfNeeded = () => {
254
- if (bucket.allowVerticalPlacement && allowsVerticalWritingMode(unformattedText)) {
254
+ if (args.bucket.allowVerticalPlacement && allowsVerticalWritingMode(unformattedText)) {
255
255
  // Vertical POI label placement is meant to be used for scripts that support vertical
256
256
  // writing mode, thus, default left justification is used. If Latin
257
257
  // scripts would need to be supported, this should take into account other justifications.
258
- shapedTextOrientations.vertical = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, textAnchor,
258
+ shapedTextOrientations.vertical = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, textAnchor,
259
259
  'left', spacingIfAllowed, textOffset, WritingMode.vertical, true, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
260
260
  }
261
261
  };
@@ -277,7 +277,7 @@ export function performSymbolLayout(
277
277
  } else {
278
278
  // If using text-variable-anchor for the layer, we use a center anchor for all shapings and apply
279
279
  // the offsets for the anchor in the placement step.
280
- const shaping = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, 'center',
280
+ const shaping = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, 'center',
281
281
  justification, spacingIfAllowed, textOffset, WritingMode.horizontal, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
282
282
  if (shaping) {
283
283
  shapedTextOrientations.horizontal[justification] = shaping;
@@ -293,7 +293,7 @@ export function performSymbolLayout(
293
293
  }
294
294
 
295
295
  // Horizontal point or line label.
296
- const shaping = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify, spacingIfAllowed,
296
+ const shaping = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify, spacingIfAllowed,
297
297
  textOffset, WritingMode.horizontal, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
298
298
  if (shaping) shapedTextOrientations.horizontal[textJustify] = shaping;
299
299
 
@@ -302,7 +302,7 @@ export function performSymbolLayout(
302
302
 
303
303
  // Verticalized line label.
304
304
  if (allowsVerticalWritingMode(unformattedText) && textAlongLine && keepUpright) {
305
- shapedTextOrientations.vertical = shapeText(text, glyphMap, glyphPositions, imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify,
305
+ shapedTextOrientations.vertical = shapeText(text, args.glyphMap, args.glyphPositions, args.imagePositions, fontstack, maxWidth, lineHeight, textAnchor, textJustify,
306
306
  spacingIfAllowed, textOffset, WritingMode.vertical, false, symbolPlacement, layoutTextSize, layoutTextSizeThisZoom);
307
307
  }
308
308
  }
@@ -311,36 +311,36 @@ export function performSymbolLayout(
311
311
  let shapedIcon;
312
312
  let isSDFIcon = false;
313
313
  if (feature.icon && feature.icon.name) {
314
- const image = imageMap[feature.icon.name];
314
+ const image = args.imageMap[feature.icon.name];
315
315
  if (image) {
316
316
  shapedIcon = shapeIcon(
317
- imagePositions[feature.icon.name],
318
- layout.get('icon-offset').evaluate(feature, {}, canonical),
319
- layout.get('icon-anchor').evaluate(feature, {}, canonical));
317
+ args.imagePositions[feature.icon.name],
318
+ layout.get('icon-offset').evaluate(feature, {}, args.canonical),
319
+ layout.get('icon-anchor').evaluate(feature, {}, args.canonical));
320
320
  // null/undefined SDF property treated same as default (false)
321
321
  isSDFIcon = !!image.sdf;
322
- if (bucket.sdfIcons === undefined) {
323
- bucket.sdfIcons = isSDFIcon;
324
- } else if (bucket.sdfIcons !== isSDFIcon) {
322
+ if (args.bucket.sdfIcons === undefined) {
323
+ args.bucket.sdfIcons = isSDFIcon;
324
+ } else if (args.bucket.sdfIcons !== isSDFIcon) {
325
325
  warnOnce('Style sheet warning: Cannot mix SDF and non-SDF icons in one buffer');
326
326
  }
327
- if (image.pixelRatio !== bucket.pixelRatio) {
328
- bucket.iconsNeedLinear = true;
327
+ if (image.pixelRatio !== args.bucket.pixelRatio) {
328
+ args.bucket.iconsNeedLinear = true;
329
329
  } else if (layout.get('icon-rotate').constantOr(1) !== 0) {
330
- bucket.iconsNeedLinear = true;
330
+ args.bucket.iconsNeedLinear = true;
331
331
  }
332
332
  }
333
333
  }
334
334
 
335
335
  const shapedText = getDefaultHorizontalShaping(shapedTextOrientations.horizontal) || shapedTextOrientations.vertical;
336
- bucket.iconsInText = shapedText ? shapedText.iconsInText : false;
336
+ args.bucket.iconsInText = shapedText ? shapedText.iconsInText : false;
337
337
  if (shapedText || shapedIcon) {
338
- addFeature(bucket, feature, shapedTextOrientations, shapedIcon, imageMap, sizes, layoutTextSize, layoutIconSize, textOffset, isSDFIcon, canonical);
338
+ addFeature(args.bucket, feature, shapedTextOrientations, shapedIcon, args.imageMap, sizes, layoutTextSize, layoutIconSize, textOffset, isSDFIcon, args.canonical);
339
339
  }
340
340
  }
341
341
 
342
- if (showCollisionBoxes) {
343
- bucket.generateCollisionDebugBuffers();
342
+ if (args.showCollisionBoxes) {
343
+ args.bucket.generateCollisionDebugBuffers();
344
344
  }
345
345
  }
346
346
 
package/src/ui/camera.ts CHANGED
@@ -5,7 +5,6 @@ import LngLat from '../geo/lng_lat';
5
5
  import LngLatBounds from '../geo/lng_lat_bounds';
6
6
  import Point from '@mapbox/point-geometry';
7
7
  import {Event, Evented} from '../util/evented';
8
- import assert from 'assert';
9
8
  import {Debug} from '../util/debug';
10
9
 
11
10
  import type Transform from '../geo/transform';
@@ -1273,19 +1272,10 @@ function addAssertions(camera: Camera) { //eslint-disable-line
1273
1272
  inProgress[name] = false;
1274
1273
 
1275
1274
  camera.on(`${name}start`, () => {
1276
- assert(!inProgress[name], `"${name}start" fired twice without a "${name}end"`);
1277
1275
  inProgress[name] = true;
1278
- assert(inProgress.move);
1279
- });
1280
-
1281
- camera.on(name, () => {
1282
- assert(inProgress[name]);
1283
- assert(inProgress.move);
1284
1276
  });
1285
1277
 
1286
1278
  camera.on(`${name}end`, () => {
1287
- assert(inProgress.move);
1288
- assert(inProgress[name]);
1289
1279
  inProgress[name] = false;
1290
1280
  });
1291
1281
  });
@@ -1,7 +1,6 @@
1
1
  import {Event, Evented} from '../../util/evented';
2
2
  import DOM from '../../util/dom';
3
3
  import {extend, bindAll, warnOnce} from '../../util/util';
4
- import assert from 'assert';
5
4
  import LngLat from '../../geo/lng_lat';
6
5
  import Marker from '../marker';
7
6
 
@@ -195,7 +194,7 @@ class GeolocateControl extends Evented implements IControl {
195
194
  case 'ACTIVE_ERROR':
196
195
  break;
197
196
  default:
198
- assert(false, `Unexpected watchState ${this._watchState}`);
197
+ throw new Error(`Unexpected watchState ${this._watchState}`);
199
198
  }
200
199
  }
201
200
 
@@ -244,7 +243,7 @@ class GeolocateControl extends Evented implements IControl {
244
243
  this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-background', 'mapboxgl-ctrl-geolocate-background');
245
244
  break;
246
245
  default:
247
- assert(false, `Unexpected watchState ${this._watchState}`);
246
+ throw new Error(`Unexpected watchState ${this._watchState}`);
248
247
  }
249
248
  }
250
249
 
@@ -306,7 +305,6 @@ class GeolocateControl extends Evented implements IControl {
306
305
  }
307
306
 
308
307
  _updateCircleRadius() {
309
- assert(this._circleElement);
310
308
  const y = this._map._container.clientHeight / 2;
311
309
  const a = this._map.unproject([0, y]);
312
310
  const b = this._map.unproject([1, y]);
@@ -485,7 +483,7 @@ class GeolocateControl extends Evented implements IControl {
485
483
  this.fire(new Event('trackuserlocationstart'));
486
484
  break;
487
485
  default:
488
- assert(false, `Unexpected watchState ${this._watchState}`);
486
+ throw new Error(`Unexpected watchState ${this._watchState}`);
489
487
  }
490
488
 
491
489
  // incoming state setup
@@ -500,7 +498,7 @@ class GeolocateControl extends Evented implements IControl {
500
498
  case 'OFF':
501
499
  break;
502
500
  default:
503
- assert(false, `Unexpected watchState ${this._watchState}`);
501
+ throw new Error(`Unexpected watchState ${this._watchState}`);
504
502
  }
505
503
 
506
504
  // manage geolocation.watchPosition / geolocation.clearWatch
@@ -1,8 +1,7 @@
1
- import assert from 'assert';
2
1
  import Point from '@mapbox/point-geometry';
3
2
 
4
3
  export function indexTouches(touches: Array<Touch>, points: Array<Point>) {
5
- assert(touches.length === points.length);
4
+ if (touches.length !== points.length) throw new Error(`The number of touches and points are not equal - touches ${touches.length}, points ${points.length}`);
6
5
  const obj = {};
7
6
  for (let i = 0; i < touches.length; i++) {
8
7
  obj[touches[i].identifier] = points[i];
@@ -1,4 +1,3 @@
1
- import assert from 'assert';
2
1
  import DOM from '../../util/dom';
3
2
 
4
3
  import {ease as _ease, bindAll, bezier} from '../../util/util';
@@ -282,7 +281,6 @@ class ScrollZoomHandler {
282
281
  let finished = false;
283
282
  let zoom;
284
283
  if (this._type === 'wheel' && startZoom && easing) {
285
- assert(easing && typeof startZoom === 'number');
286
284
 
287
285
  const t = Math.min((browser.now() - this._lastWheelEventTime) / 200, 1);
288
286
  const k = easing(t);
@@ -19,7 +19,6 @@ import TouchZoomRotateHandler from './handler/shim/touch_zoom_rotate';
19
19
  import {bindAll, extend} from '../util/util';
20
20
  import Point from '@mapbox/point-geometry';
21
21
  import LngLat from '../geo/lng_lat';
22
- import assert from 'assert';
23
22
 
24
23
  export type InputEvent = MouseEvent | TouchEvent | KeyboardEvent | WheelEvent;
25
24
 
@@ -299,7 +298,6 @@ class HandlerManager {
299
298
  }
300
299
 
301
300
  this._updatingCamera = true;
302
- assert(e.timeStamp !== undefined);
303
301
 
304
302
  const inputEvent = e.type === 'renderFrame' ? undefined : (e as any as InputEvent);
305
303
 
@@ -40,6 +40,17 @@ afterEach(() => {
40
40
 
41
41
  describe('Map', () => {
42
42
 
43
+ test('version', () => {
44
+ const map = createMap({interactive: true, style: null});
45
+
46
+ expect(typeof map.version === 'string').toBeTruthy();
47
+
48
+ // Semver regex: https://gist.github.com/jhorsman/62eeea161a13b80e39f5249281e17c39
49
+ // Backslashes are doubled to escape them
50
+ const regexp = new RegExp('^([0-9]+)\\.([0-9]+)\\.([0-9]+)(?:-([0-9A-Za-z-]+(?:\\.[0-9A-Za-z-]+)*))?(?:\\+[0-9A-Za-z-]+)?$');
51
+ expect(regexp.test(map.version)).toBeTruthy();
52
+ });
53
+
43
54
  test('constructor', () => {
44
55
  const map = createMap({interactive: true, style: null});
45
56
  expect(map.getContainer()).toBeTruthy();
package/src/ui/map.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import {extend, bindAll, warnOnce, uniqueId, isImageBitmap} from '../util/util';
2
2
  import browser from '../util/browser';
3
3
  import DOM from '../util/dom';
4
+ import packageJSON from '../../package.json' assert {type: 'json'};
4
5
  import {getImage, GetImageCallback, getJSON, ResourceType} from '../util/ajax';
5
6
  import {RequestManager} from '../util/request_manager';
6
7
  import Style from '../style/style';
@@ -58,6 +59,8 @@ import {Callback} from '../types/callback';
58
59
  import type {ControlPosition, IControl} from './control/control';
59
60
  import type {MapGeoJSONFeature} from '../util/vectortile_to_geojson';
60
61
 
62
+ const version = packageJSON.version;
63
+
61
64
  /* eslint-enable no-use-before-define */
62
65
  export type MapOptions = {
63
66
  hash?: boolean | string;
@@ -2925,6 +2928,14 @@ class Map extends Camera {
2925
2928
  _setCacheLimits(limit: number, checkThreshold: number) {
2926
2929
  setCacheLimits(limit, checkThreshold);
2927
2930
  }
2931
+
2932
+ /**
2933
+ * Returns the package version of the library
2934
+ * @returns {string} Package version of the library
2935
+ */
2936
+ get version(): string {
2937
+ return version;
2938
+ }
2928
2939
  }
2929
2940
 
2930
2941
  export default Map;
package/src/util/ajax.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  import {extend, warnOnce, isWorker} from './util';
2
2
  import config from './config';
3
- import assert from 'assert';
4
3
  import {cacheGet, cachePut} from './tile_request_cache';
5
4
  import webpSupported from './webp_supported';
6
5
 
@@ -390,7 +389,7 @@ export const getImage = function(
390
389
  if (advanced) return;
391
390
  advanced = true;
392
391
  numImageRequests--;
393
- assert(numImageRequests >= 0);
392
+
394
393
  while (imageQueue.length && numImageRequests < config.MAX_PARALLEL_IMAGE_REQUESTS) { // eslint-disable-line
395
394
  const request = imageQueue.shift();
396
395
  const {requestParameters, callback, cancelled} = request;
@@ -1,6 +1,5 @@
1
1
  import {RGBAImage} from './image';
2
2
  import {isPowerOfTwo} from './util';
3
- import assert from 'assert';
4
3
 
5
4
  import type {StylePropertyExpression} from '../style-spec/expression/index';
6
5
 
@@ -24,7 +23,7 @@ export function renderColorRamp(params: ColorRampParams): RGBAImage {
24
23
  const height = params.clips ? params.clips.length : 1;
25
24
  const image = params.image || new RGBAImage({width, height});
26
25
 
27
- assert(isPowerOfTwo(width));
26
+ if (!isPowerOfTwo(width)) throw new Error(`width is not a power of 2 - ${width}`);
28
27
 
29
28
  const renderPixel = (stride, index, progress) => {
30
29
  evaluationGlobals[params.evaluationKey] = progress;
@@ -1,4 +1,3 @@
1
- import assert from 'assert';
2
1
 
3
2
  class DictionaryCoder {
4
3
  _stringToNumber: {[_: string]: number};
@@ -15,12 +14,11 @@ class DictionaryCoder {
15
14
  }
16
15
 
17
16
  encode(string: string) {
18
- assert(string in this._stringToNumber);
19
17
  return this._stringToNumber[string];
20
18
  }
21
19
 
22
20
  decode(n: number) {
23
- assert(n < this._numberToString.length);
21
+ if (n >= this._numberToString.length) throw new Error(`Out of bounds. Index requested n=${n} can't be >= this._numberToString.length ${this._numberToString.length}`);
24
22
  return this._numberToString[n];
25
23
  }
26
24
  }
@@ -1,6 +1,5 @@
1
1
  import {uniqueId, asyncAll} from './util';
2
2
  import Actor from './actor';
3
- import assert from 'assert';
4
3
 
5
4
  import type WorkerPool from './worker_pool';
6
5
 
@@ -33,7 +32,7 @@ class Dispatcher {
33
32
  actor.name = `Worker ${i}`;
34
33
  this.actors.push(actor);
35
34
  }
36
- assert(this.actors.length);
35
+ if (!this.actors.length) throw new Error('No actors found');
37
36
  }
38
37
 
39
38
  /**
@@ -41,7 +40,6 @@ class Dispatcher {
41
40
  * @private
42
41
  */
43
42
  broadcast(type: string, data: unknown, cb?: (...args: any[]) => any) {
44
- assert(this.actors.length);
45
43
  cb = cb || function () {};
46
44
  asyncAll(this.actors, (actor, done) => {
47
45
  actor.send(type, data, done);
@@ -53,7 +51,6 @@ class Dispatcher {
53
51
  * @returns An actor object backed by a web worker for processing messages.
54
52
  */
55
53
  getActor(): Actor {
56
- assert(this.actors.length);
57
54
  this.currentActor = (this.currentActor + 1) % this.actors.length;
58
55
  return this.actors[this.currentActor];
59
56
  }
package/src/util/dom.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import Point from '@mapbox/point-geometry';
2
2
 
3
- import assert from 'assert';
4
-
5
3
  export default class DOM {
6
4
  private static readonly docStyle = typeof window !== 'undefined' && window.document && window.document.documentElement.style;
7
5
 
@@ -107,7 +105,6 @@ export default class DOM {
107
105
  }
108
106
 
109
107
  public static mouseButton(e: MouseEvent) {
110
- assert(e.type === 'mousedown' || e.type === 'mouseup');
111
108
  return e.button;
112
109
  }
113
110
 
package/src/util/image.ts CHANGED
@@ -1,5 +1,3 @@
1
- import assert from 'assert';
2
-
3
1
  import {register} from './web_worker_transfer';
4
2
 
5
3
  export type Size = {
@@ -71,7 +69,7 @@ function copyImage(srcImg: any, dstImg: any, srcPt: Point2D, dstPt: Point2D, siz
71
69
  const srcData = srcImg.data;
72
70
  const dstData = dstImg.data;
73
71
 
74
- assert(srcData !== dstData);
72
+ if (srcData === dstData) throw new Error('srcData equals dstData, so image is already copied');
75
73
 
76
74
  for (let y = 0; y < size.height; y++) {
77
75
  const srcOffset = ((srcPt.y + y) * srcImg.width + srcPt.x) * channels;
@@ -1,7 +1,5 @@
1
1
  // Note: all "sizes" are measured in bytes
2
2
 
3
- import assert from 'assert';
4
-
5
3
  import type {Transferable} from '../types/transferable';
6
4
 
7
5
  const viewTypes = {
@@ -111,7 +109,6 @@ abstract class StructArray {
111
109
  * @private
112
110
  */
113
111
  static serialize(array: StructArray, transferables?: Array<Transferable>): SerializedStructArray {
114
- assert(!array.isTransferred);
115
112
 
116
113
  array._trim();
117
114
 
@@ -160,7 +157,6 @@ abstract class StructArray {
160
157
  * @param {number} n The new size of the array.
161
158
  */
162
159
  resize(n: number) {
163
- assert(!this.isTransferred);
164
160
  this.reserve(n);
165
161
  this.length = n;
166
162
  }
@@ -209,7 +205,6 @@ function createLayout(
209
205
  let offset = 0;
210
206
  let maxSize = 0;
211
207
  const layoutMembers = members.map((member) => {
212
- assert(member.name.length);
213
208
  const typeSize = sizeOf(member.type);
214
209
  const memberOffset = offset = align(offset, Math.max(alignment, typeSize));
215
210
  const components = member.components || 1;
@@ -1,5 +1,3 @@
1
- import assert from 'assert';
2
-
3
1
  export type TaskID = number; // can't mark opaque due to https://github.com/flowtype/flow-remove-types/pull/61
4
2
 
5
3
  type Task = {
@@ -40,7 +38,7 @@ class TaskQueue {
40
38
  }
41
39
 
42
40
  run(timeStamp: number = 0) {
43
- assert(!this._currentlyRunning);
41
+ if (this._currentlyRunning) throw new Error('Attempting to run(), but is already running.');
44
42
  const queue = this._currentlyRunning = this._queue;
45
43
 
46
44
  // Tasks queued by callbacks in the current queue should be executed
package/src/util/util.ts CHANGED
@@ -384,7 +384,6 @@ export function sphericalToCartesian([r, azimuthal, polar]: [number, number, num
384
384
  };
385
385
  }
386
386
 
387
- /* global self, WorkerGlobalScope */
388
387
  /**
389
388
  * Returns true if the when run in the web-worker context.
390
389
  *
@@ -392,8 +391,8 @@ export function sphericalToCartesian([r, azimuthal, polar]: [number, number, num
392
391
  * @returns {boolean}
393
392
  */
394
393
  export function isWorker(): boolean {
395
- return typeof WorkerGlobalScope !== 'undefined' && typeof self !== 'undefined' &&
396
- self instanceof WorkerGlobalScope;
394
+ // @ts-ignore
395
+ return typeof WorkerGlobalScope !== 'undefined' && typeof self !== 'undefined' && self instanceof WorkerGlobalScope;
397
396
  }
398
397
 
399
398
  /**
@@ -1,5 +1,3 @@
1
- import assert from 'assert';
2
-
3
1
  import TransferableGridIndex from './transferable_grid_index';
4
2
  import Color from '../style-spec/util/color';
5
3
  import {StylePropertyFunction, StyleExpression, ZoomDependentExpression, ZoomConstantExpression} from '../style-spec/expression';
@@ -51,7 +49,7 @@ export function register<T extends any>(
51
49
  },
52
50
  options: RegisterOptions<T> = {}
53
51
  ) {
54
- assert(!registry[name], `${name} is already registered.`);
52
+ if (registry[name]) throw new Error(`${name} is already registered.`);
55
53
  ((Object.defineProperty as any))(klass, '_classRegistryKey', {
56
54
  value: name,
57
55
  writeable: false
@@ -159,7 +157,7 @@ export function serialize(input: unknown, transferables?: Array<Transferable> |
159
157
  if (!name) {
160
158
  throw new Error('can\'t serialize object of unregistered class');
161
159
  }
162
- assert(registry[name]);
160
+ if (!registry[name]) throw new Error(`${name} is not registered.`);
163
161
 
164
162
  const properties: SerializedObject = klass.serialize ?
165
163
  // (Temporary workaround) allow a class to provide static
@@ -185,8 +183,9 @@ export function serialize(input: unknown, transferables?: Array<Transferable> |
185
183
  properties.message = input.message;
186
184
  }
187
185
  } else {
188
- // make sure statically serialized object survives transfer of $name property
189
- assert(!transferables || properties as any !== transferables[transferables.length - 1]);
186
+ if (transferables && properties as any === transferables[transferables.length - 1]) {
187
+ throw new Error('statically serialized object won\'t survive transfer of $name property');
188
+ }
190
189
  }
191
190
 
192
191
  if (properties.$name) {