maplibre-gl 6.1.0 → 6.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 (112) hide show
  1. package/build/readme.md +0 -2
  2. package/dist/maplibre-gl-dev.mjs +179 -190
  3. package/dist/maplibre-gl-dev.mjs.map +1 -1
  4. package/dist/maplibre-gl-shared-dev.mjs +869 -825
  5. package/dist/maplibre-gl-shared-dev.mjs.map +1 -1
  6. package/dist/maplibre-gl-shared.mjs +2 -2
  7. package/dist/maplibre-gl-shared.mjs.map +1 -1
  8. package/dist/maplibre-gl-worker-dev.mjs +14 -12
  9. package/dist/maplibre-gl-worker-dev.mjs.map +1 -1
  10. package/dist/maplibre-gl-worker.mjs +2 -2
  11. package/dist/maplibre-gl-worker.mjs.map +1 -1
  12. package/dist/maplibre-gl.css +1 -1
  13. package/dist/maplibre-gl.d.ts +24 -6
  14. package/dist/maplibre-gl.mjs +13 -13
  15. package/dist/maplibre-gl.mjs.map +1 -1
  16. package/package.json +10 -13
  17. package/src/data/bucket/fill_extrusion_bucket.test.ts +22 -0
  18. package/src/data/bucket/fill_extrusion_bucket.ts +16 -4
  19. package/src/data/bucket/round_polygon_corners.test.ts +159 -0
  20. package/src/data/bucket/round_polygon_corners.ts +121 -0
  21. package/src/data/bucket/symbol_bucket.test.ts +1 -1
  22. package/src/data/dem_data.test.ts +23 -23
  23. package/src/data/feature_position_map.test.ts +1 -1
  24. package/src/data/segment.test.ts +14 -14
  25. package/src/geo/bounds.test.ts +4 -4
  26. package/src/geo/lng_lat_bounds.test.ts +1 -1
  27. package/src/geo/projection/mercator_transform.test.ts +1 -1
  28. package/src/geo/projection/mercator_utils.test.ts +8 -8
  29. package/src/index.test.ts +7 -12
  30. package/src/render/glyph_manager.test.ts +6 -22
  31. package/src/render/painter.test.ts +2 -0
  32. package/src/render/painter.ts +7 -5
  33. package/src/render/subdivision.test.ts +22 -22
  34. package/src/render/terrain.test.ts +68 -34
  35. package/src/render/terrain.ts +69 -26
  36. package/src/source/canvas_source.test.ts +1 -1
  37. package/src/source/geojson_source.test.ts +5 -4
  38. package/src/source/geojson_source_diff.test.ts +2 -2
  39. package/src/source/geojson_worker_source.test.ts +9 -5
  40. package/src/source/image_source.test.ts +0 -3
  41. package/src/source/raster_dem_tile_source.test.ts +2 -2
  42. package/src/source/raster_tile_source.test.ts +15 -9
  43. package/src/source/rtl_text_plugin_main_thread.test.ts +14 -14
  44. package/src/source/source.test.ts +8 -8
  45. package/src/source/vector_tile_source.test.ts +1 -1
  46. package/src/source/vector_tile_worker_source.test.ts +7 -5
  47. package/src/source/worker.test.ts +1 -1
  48. package/src/source/worker_tile.test.ts +4 -2
  49. package/src/style/load_glyph_range.test.ts +8 -8
  50. package/src/style/load_sprite.test.ts +1 -1
  51. package/src/style/style.test.ts +36 -34
  52. package/src/style/style_layer/color_relief_style_layer.test.ts +1 -1
  53. package/src/style/style_layer/fill_extrusion_style_layer.ts +6 -3
  54. package/src/style/style_layer/raster_style_layer.test.ts +2 -2
  55. package/src/style/style_layer.test.ts +3 -50
  56. package/src/symbol/collision_index.test.ts +1 -1
  57. package/src/symbol/grid_index.test.ts +1 -1
  58. package/src/tile/terrain_tile_manager.test.ts +2 -2
  59. package/src/tile/tile_id.test.ts +5 -5
  60. package/src/tile/tile_manager.test.ts +85 -72
  61. package/src/tile/tile_manager_in_view_tiles.test.ts +2 -2
  62. package/src/ui/camera.test.ts +137 -134
  63. package/src/ui/control/geolocate_control.test.ts +6 -29
  64. package/src/ui/handler/dblclick_zoom.test.ts +2 -2
  65. package/src/ui/handler/scroll_zoom.test.ts +2 -0
  66. package/src/ui/handler_manager.test.ts +7 -7
  67. package/src/ui/hash.test.ts +1 -0
  68. package/src/ui/map.ts +28 -18
  69. package/src/ui/map_tests/map_basic.test.ts +11 -23
  70. package/src/ui/map_tests/map_calculate_camera_options.test.ts +6 -6
  71. package/src/ui/map_tests/map_events.test.ts +5 -5
  72. package/src/ui/map_tests/map_global_state.test.ts +3 -3
  73. package/src/ui/map_tests/map_images.test.ts +3 -3
  74. package/src/ui/map_tests/map_is_moving.test.ts +1 -1
  75. package/src/ui/map_tests/map_is_rotating.test.ts +1 -1
  76. package/src/ui/map_tests/map_layer.test.ts +2 -1
  77. package/src/ui/map_tests/map_options.test.ts +1 -5
  78. package/src/ui/map_tests/map_pitch.test.ts +6 -6
  79. package/src/ui/map_tests/map_refresh_tiles.test.ts +2 -2
  80. package/src/ui/map_tests/map_render.test.ts +1 -1
  81. package/src/ui/map_tests/map_set_lod_params.test.ts +1 -1
  82. package/src/ui/map_tests/map_style.test.ts +9 -1
  83. package/src/ui/map_tests/map_terrain.test.ts +20 -0
  84. package/src/ui/map_tests/map_zoom.test.ts +15 -15
  85. package/src/ui/marker.test.ts +7 -13
  86. package/src/ui/popup.test.ts +3 -3
  87. package/src/util/actor.test.ts +6 -6
  88. package/src/util/ajax.test.ts +27 -39
  89. package/src/util/browser.test.ts +7 -9
  90. package/src/util/create_tile_mesh.test.ts +2 -2
  91. package/src/util/dispatcher.test.ts +1 -1
  92. package/src/util/evented.test.ts +4 -1
  93. package/src/util/fast_maths.test.ts +4 -4
  94. package/src/util/image_request.test.ts +6 -4
  95. package/src/util/struct_array.test.ts +2 -2
  96. package/src/util/task_queue.test.ts +1 -1
  97. package/src/util/test/util.ts +1 -0
  98. package/src/util/time_control.test.ts +2 -2
  99. package/src/util/transferable_grid_index.test.ts +1 -1
  100. package/src/util/util.test.ts +27 -13
  101. package/src/util/verticalize_punctuation.test.ts +4 -4
  102. package/src/util/web_worker_transfer.test.ts +5 -5
  103. package/src/webgl/draw/draw_custom.test.ts +13 -13
  104. package/src/webgl/draw/draw_debug.test.ts +1 -1
  105. package/src/webgl/draw/draw_fill.test.ts +12 -12
  106. package/src/webgl/draw/draw_symbol.test.ts +16 -16
  107. package/src/webgl/program.ts +2 -0
  108. package/src/webgl/render_to_texture.test.ts +5 -5
  109. package/src/webgl/state.test.ts +1 -1
  110. package/src/webgl/texture.test.ts +3 -3
  111. package/src/webgl/vertex_buffer.test.ts +1 -1
  112. package/build/rolldown_plugins.ts +0 -18
@@ -3,7 +3,7 @@ import geolocation from 'mock-geolocation';
3
3
  import {LngLatBounds} from '../../geo/lng_lat_bounds.ts';
4
4
  import {createMap, beforeMapTest, sleep} from '../../util/test/util.ts';
5
5
  import {GeolocateControl} from './geolocate_control.ts';
6
- vi.mock('../../util/geolocation_support', () => (
6
+ vi.mock(import('../../util/geolocation_support'), () => (
7
7
  {
8
8
  checkGeolocationSupport: vi.fn()
9
9
  }
@@ -61,7 +61,7 @@ describe('GeolocateControl with no options', () => {
61
61
  beforeEach(() => {
62
62
  beforeMapTest();
63
63
  map = createMap();
64
- (checkGeolocationSupport as unknown as MockInstance).mockImplementationOnce(() => Promise.resolve(true));
64
+ (checkGeolocationSupport as unknown as MockInstance).mockResolvedValueOnce(true);
65
65
  createResizeObserverEntryMock();
66
66
  });
67
67
 
@@ -70,7 +70,7 @@ describe('GeolocateControl with no options', () => {
70
70
  });
71
71
 
72
72
  test('is disabled when there is no support', async () => {
73
- (checkGeolocationSupport as unknown as MockInstance).mockReset().mockImplementationOnce(() => Promise.resolve(false));
73
+ (checkGeolocationSupport as unknown as MockInstance).mockReset().mockResolvedValueOnce(false);
74
74
  const geolocate = new GeolocateControl(undefined);
75
75
  const spy = vi.spyOn(console, 'warn').mockImplementation(() => {});
76
76
  map.addControl(geolocate);
@@ -237,13 +237,13 @@ describe('GeolocateControl with no options', () => {
237
237
 
238
238
  test('does not throw if removed quickly', () => {
239
239
  (checkGeolocationSupport as unknown as MockInstance).mockReset()
240
- .mockImplementationOnce(() => {
241
- return sleep(10);
242
- });
240
+ .mockReturnValueOnce(sleep(10));
243
241
 
244
242
  const geolocate = new GeolocateControl(undefined);
245
243
  map.addControl(geolocate);
246
244
  map.removeControl(geolocate);
245
+
246
+ expect(map.hasControl(geolocate)).toBe(false);
247
247
  });
248
248
 
249
249
  test('outofmaxbounds event in waiting active state', async () => {
@@ -857,29 +857,6 @@ describe('GeolocateControl with no options', () => {
857
857
  expect(geolocate._circleElement.style.width).toBeTruthy();
858
858
  });
859
859
 
860
- test('shown even if trackUserLocation = false', async () => {
861
- const geolocate = new GeolocateControl({
862
- trackUserLocation: false,
863
- showUserLocation: true,
864
- showAccuracyCircle: true,
865
- });
866
- map.addControl(geolocate);
867
- await sleep(0);
868
- const click = new window.Event('click');
869
-
870
- const geolocatePromise = geolocate.once('geolocate');
871
- geolocate._geolocateButton.dispatchEvent(click);
872
- geolocation.send({latitude: 10, longitude: 20, accuracy: 700});
873
- await geolocatePromise;
874
- map.jumpTo({
875
- center: [10, 20]
876
- });
877
- const zoomendPromise = map.once('zoomend');
878
- map.zoomTo(10, {duration: 0});
879
- await zoomendPromise;
880
- expect(geolocate._circleElement.style.width).toBeTruthy();
881
- });
882
-
883
860
  test('GeolocateControl does not crash on movestart after removal in ACTIVE_LOCK state', async () => {
884
861
  const geolocate = new GeolocateControl({trackUserLocation: true});
885
862
  map.addControl(geolocate);
@@ -191,7 +191,7 @@ describe('dbclick_zoom', () => {
191
191
  expect(zoom).not.toHaveBeenCalled();
192
192
  });
193
193
 
194
- test('DoubleClickZoomHandler snaps to nearest zoomSnap', () => {
194
+ test('DoubleClickZoomHandler snaps to nearest zoomSnap on a non-interactive map', () => {
195
195
  const map = createMap({zoom: 9.7, zoomSnap: 1.0});
196
196
  const spy = vi.spyOn(map, 'easeTo');
197
197
 
@@ -203,7 +203,7 @@ describe('dbclick_zoom', () => {
203
203
  map.remove();
204
204
  });
205
205
 
206
- test('DoubleClickZoomHandler double-tap snaps to nearest zoomSnap', async () => {
206
+ test('DoubleClickZoomHandler double-tap snaps to nearest zoomSnap on a non-interactive map', async () => {
207
207
  const map = createMap({zoom: 9.7, zoomSnap: 1.0});
208
208
  const spy = vi.spyOn(map, 'easeTo');
209
209
 
@@ -359,6 +359,7 @@ describe('ScrollZoomHandler', () => {
359
359
 
360
360
  const map = createMap();
361
361
  map._renderTaskQueue.run();
362
+ const startZoom = map.getZoom();
362
363
 
363
364
  simulate.wheel(map.getCanvas(), {deltaY: -1});
364
365
  simulate.wheel(map.getCanvas(), {deltaY: -1});
@@ -372,6 +373,7 @@ describe('ScrollZoomHandler', () => {
372
373
  timeControlNow.mockReturnValue(now);
373
374
  map._renderTaskQueue.run();
374
375
 
376
+ expect(map.getZoom()).toBeCloseTo(startZoom);
375
377
  map.remove();
376
378
  });
377
379
 
@@ -1,4 +1,4 @@
1
- import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest';
1
+ import {afterEach, beforeEach, describe, expect, vi, test} from 'vitest';
2
2
  import Point from '@mapbox/point-geometry';
3
3
 
4
4
  import type {HandlerManager, MapControlsScenarioOptions, EventInProgress, EventsInProgress} from './handler_manager.ts';
@@ -25,7 +25,7 @@ afterEach(() => {
25
25
  });
26
26
 
27
27
  describe('HandlerManager terrain scenarios', () => {
28
- it('_handleMapControls keeps terrain movement disabled when terrain is not enabled', () => {
28
+ test('_handleMapControls keeps terrain movement disabled when terrain is not enabled', () => {
29
29
  const handleZoom = vi.fn();
30
30
  const handlePan = vi.fn();
31
31
  map._camera.cameraHelper = {
@@ -73,7 +73,7 @@ describe('HandlerManager terrain scenarios', () => {
73
73
  expect(setCenterMock).not.toHaveBeenCalled();
74
74
  });
75
75
 
76
- it('_handleMapControls enables terrain movement for globe terrain handling', () => {
76
+ test('_handleMapControls enables terrain movement for globe terrain handling', () => {
77
77
  const handleZoom = vi.fn();
78
78
  const handlePan = vi.fn();
79
79
  map._camera.cameraHelper = {
@@ -114,7 +114,7 @@ describe('HandlerManager terrain scenarios', () => {
114
114
  expect(handlePan).toHaveBeenCalledWith(options.deltasForHelper, options.tr, options.preZoomAroundLoc);
115
115
  });
116
116
 
117
- it('_handleMapControls keeps terrain movement state when globe terrain is already active', () => {
117
+ test('_handleMapControls keeps terrain movement state when globe terrain is already active', () => {
118
118
  const handleZoom = vi.fn();
119
119
  const handlePan = vi.fn();
120
120
  map._camera.cameraHelper = {
@@ -155,7 +155,7 @@ describe('HandlerManager terrain scenarios', () => {
155
155
  expect(handlePan).toHaveBeenCalledWith(options.deltasForHelper, options.tr, options.preZoomAroundLoc);
156
156
  });
157
157
 
158
- it('_handleMapControls activates terrain movement on first drag in mercator terrain', () => {
158
+ test('_handleMapControls activates terrain movement on first drag in mercator terrain', () => {
159
159
  const handleZoom = vi.fn();
160
160
  const handlePan = vi.fn();
161
161
  map._camera.cameraHelper = {
@@ -199,7 +199,7 @@ describe('HandlerManager terrain scenarios', () => {
199
199
  expect(setCenterMock).not.toHaveBeenCalled();
200
200
  });
201
201
 
202
- it('_handleMapControls drags using transform when already moving in mercator terrain', () => {
202
+ test('_handleMapControls drags using transform when already moving in mercator terrain', () => {
203
203
  const handleZoom = vi.fn();
204
204
  const handlePan = vi.fn();
205
205
  map._camera.cameraHelper = {
@@ -245,7 +245,7 @@ describe('HandlerManager terrain scenarios', () => {
245
245
  expect(handlePan).not.toHaveBeenCalled();
246
246
  });
247
247
 
248
- it('_handleMapControls falls back to helper panning when not dragging in mercator terrain', () => {
248
+ test('_handleMapControls falls back to helper panning when not dragging in mercator terrain', () => {
249
249
  const handleZoom = vi.fn();
250
250
  const handlePan = vi.fn();
251
251
  map._camera.cameraHelper = {
@@ -522,6 +522,7 @@ describe('hash', () => {
522
522
 
523
523
  map.remove();
524
524
 
525
+ expect(map._removed).toBe(true);
525
526
  });
526
527
 
527
528
  test('hash with URL in other parameter does not change except normalization', () => {
package/src/ui/map.ts CHANGED
@@ -2951,24 +2951,7 @@ export class Map extends Evented<MapEventType> {
2951
2951
  this._camera.terrain = this.terrain;
2952
2952
  this._camera.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
2953
2953
  this._camera.transform.setElevation(this.terrain.getElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
2954
- this._terrainDataCallback = e => {
2955
- if (e.dataType === 'style') {
2956
- this.terrain.tileManager.releaseAllRTT();
2957
- } else if (e.dataType === 'source' && e.tile) {
2958
- if (e.sourceId === options.source && !this._camera.elevationFreeze) {
2959
- this._camera.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
2960
- if (this.getCenterClampedToGround()) {
2961
- this._camera.transform.setElevation(this.terrain.getElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
2962
- }
2963
- }
2964
-
2965
- if (e.source?.type === 'image') {
2966
- this.terrain.tileManager.releaseAllRTT();
2967
- } else {
2968
- this.terrain.tileManager.releaseRTT(e.tile.tileID);
2969
- }
2970
- }
2971
- };
2954
+ this._terrainDataCallback = e => this._handleTerrainDataEvent(e, options.source);
2972
2955
  this.style.on('data', this._terrainDataCallback);
2973
2956
  }
2974
2957
 
@@ -2976,6 +2959,31 @@ export class Map extends Evented<MapEventType> {
2976
2959
  return this;
2977
2960
  }
2978
2961
 
2962
+ private _handleTerrainDataEvent(event: MapStyleDataEvent | MapSourceDataEvent, terrainSourceId: string): void {
2963
+ if (event.dataType === 'style') {
2964
+ this.terrain.tileManager.releaseAllRTT();
2965
+ return;
2966
+ }
2967
+
2968
+ const isTerrainSourceEvent = event.sourceId === terrainSourceId;
2969
+ if (isTerrainSourceEvent) {
2970
+ this.terrain.resetElevationCache();
2971
+ }
2972
+ if (isTerrainSourceEvent && event.tile && !this._camera.elevationFreeze) {
2973
+ this._camera.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
2974
+ if (this.getCenterClampedToGround()) {
2975
+ this._camera.transform.setElevation(this.terrain.getElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
2976
+ }
2977
+ }
2978
+
2979
+ if (!event.tile) return;
2980
+ if (event.source?.type === 'image') {
2981
+ this.terrain.tileManager.releaseAllRTT();
2982
+ return;
2983
+ }
2984
+ this.terrain.tileManager.releaseRTT(event.tile.tileID);
2985
+ }
2986
+
2979
2987
  /**
2980
2988
  * Get the terrain-options if terrain is loaded
2981
2989
  * @returns the TerrainSpecification passed to setTerrain
@@ -4271,6 +4279,8 @@ export class Map extends Evented<MapEventType> {
4271
4279
  // update terrain stuff
4272
4280
  if (this.terrain) {
4273
4281
  this.terrain.tileManager.update(this._camera.transform, this.terrain);
4282
+ // Tile selection can change with the transform or cache state without a data event.
4283
+ this.terrain.resetElevationCache();
4274
4284
  this._camera.transform.setMinElevationForCurrentTile(this.terrain.getMinTileElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
4275
4285
  if (!this._camera.elevationFreeze && this.getCenterClampedToGround()) {
4276
4286
  this._camera.transform.setElevation(this.terrain.getElevationForLngLatZoom(this._camera.transform.center, this._camera.transform.tileZoom));
@@ -1,6 +1,6 @@
1
1
  import {describe, beforeEach, test, expect, vi} from 'vitest';
2
2
  import {Map} from '../map.ts';
3
- import {createMap, beforeMapTest, createStyle, createStyleSource, sleep} from '../../util/test/util.ts';
3
+ import {createMap, beforeMapTest, createStyle, createStyleSource, sleep, waitForEvent} from '../../util/test/util.ts';
4
4
  import {Tile} from '../../tile/tile.ts';
5
5
  import {OverscaledTileID} from '../../tile/tile_id.ts';
6
6
  import {fixedLngLat} from '../../../test/unit/lib/fixed.ts';
@@ -47,14 +47,6 @@ describe('Map', () => {
47
47
  );
48
48
  });
49
49
 
50
- test('bad map-specific token breaks map', () => {
51
- const container = window.document.createElement('div');
52
- Object.defineProperty(container, 'offsetWidth', {value: 512});
53
- Object.defineProperty(container, 'offsetHeight', {value: 512});
54
- createMap();
55
- //t.error();
56
- });
57
-
58
50
  describe('setTransformRequest', () => {
59
51
  test('returns self', () => {
60
52
  const transformRequest = (() => {}) as any as RequestTransformFunction;
@@ -69,6 +61,8 @@ describe('Map', () => {
69
61
  const transformRequest = (() => {}) as any as RequestTransformFunction;
70
62
  map.setTransformRequest(transformRequest);
71
63
  map.setTransformRequest(transformRequest);
64
+
65
+ expect(map._requestManager._transformRequestFn).toBe(transformRequest);
72
66
  });
73
67
 
74
68
  test('removes function when called with null', () => {
@@ -89,17 +83,12 @@ describe('Map', () => {
89
83
  const map = createMap({style});
90
84
 
91
85
  await map.once('load');
92
- const promise = new Promise<void>((resolve) => {
93
- map.on('data', (e) => {
94
- if (e.dataType === 'source' && e.sourceDataType === 'idle') {
95
- expect(map.isSourceLoaded('geojson')).toBe(true);
96
- resolve();
97
- }
98
- });
99
- });
86
+ const idlePromise = waitForEvent(map, 'data', (e) => e.dataType === 'source' && e.sourceDataType === 'idle');
100
87
  map.addSource('geojson', createStyleSource());
101
88
  expect(map.isSourceLoaded('geojson')).toBe(false);
102
- await promise;
89
+
90
+ await idlePromise;
91
+ expect(map.isSourceLoaded('geojson')).toBe(true);
103
92
  });
104
93
 
105
94
  test('Map.isSourceLoaded (equivalent to event.isSourceLoaded)', async () => {
@@ -109,11 +98,10 @@ describe('Map', () => {
109
98
  await map.once('load');
110
99
  const promise = new Promise<void>((resolve) => {
111
100
  map.on('data', (e: MapSourceDataEvent) => {
112
- if (e.dataType === 'source' && 'source' in e) {
113
- expect(map.isSourceLoaded('geojson')).toBe(e.isSourceLoaded);
114
- if (e.sourceDataType === 'idle') {
115
- resolve();
116
- }
101
+ if (e.dataType !== 'source' || !('source' in e)) return;
102
+ expect(map.isSourceLoaded('geojson')).toBe(e.isSourceLoaded);
103
+ if (e.sourceDataType === 'idle') {
104
+ resolve();
117
105
  }
118
106
  });
119
107
  });
@@ -27,7 +27,7 @@ describe('calculateCameraOptionsFromTo', () => {
27
27
  const cameraOptions: CameraOptions = map.calculateCameraOptionsFromTo(new LngLat(1, 0), 111200, new LngLat(0, 0));
28
28
  expect(cameraOptions).toBeDefined();
29
29
  expect(cameraOptions.pitch).toBeCloseTo(90);
30
- expect(mockedGetElevation.mock.calls).toHaveLength(1);
30
+ expect(mockedGetElevation).toHaveBeenCalledTimes(1);
31
31
  });
32
32
 
33
33
  test('pitch 153.435 with terrain', () => {
@@ -44,7 +44,7 @@ describe('calculateCameraOptionsFromTo', () => {
44
44
  const cameraOptions: CameraOptions = map.calculateCameraOptionsFromTo(new LngLat(1, 0), 111200, new LngLat(0, 0));
45
45
  expect(cameraOptions).toBeDefined();
46
46
  expect(cameraOptions.pitch).toBeCloseTo(153.435);
47
- expect(mockedGetElevation.mock.calls).toHaveLength(1);
47
+ expect(mockedGetElevation).toHaveBeenCalledTimes(1);
48
48
  });
49
49
 
50
50
  test('pitch 63 with terrain', () => {
@@ -62,7 +62,7 @@ describe('calculateCameraOptionsFromTo', () => {
62
62
  const cameraOptions: CameraOptions = map.calculateCameraOptionsFromTo(new LngLat(0, 0), 111200, new LngLat(1, 0));
63
63
  expect(cameraOptions).toBeDefined();
64
64
  expect(cameraOptions.pitch).toBeCloseTo(63.435);
65
- expect(mockedGetElevation.mock.calls).toHaveLength(1);
65
+ expect(mockedGetElevation).toHaveBeenCalledTimes(1);
66
66
  });
67
67
 
68
68
  test('zoom distance 1000', () => {
@@ -79,7 +79,7 @@ describe('calculateCameraOptionsFromTo', () => {
79
79
 
80
80
  expect(cameraOptions).toBeDefined();
81
81
  expect(cameraOptions.zoom).toBeCloseTo(expectedZoom);
82
- expect(mockedGetElevation.mock.calls).toHaveLength(1);
82
+ expect(mockedGetElevation).toHaveBeenCalledTimes(1);
83
83
  });
84
84
 
85
85
  test('don\'t call getElevation when altitude supplied', () => {
@@ -94,7 +94,7 @@ describe('calculateCameraOptionsFromTo', () => {
94
94
  const cameraOptions = map.calculateCameraOptionsFromTo(new LngLat(0, 0), 0, new LngLat(0, 0), 1000);
95
95
 
96
96
  expect(cameraOptions).toBeDefined();
97
- expect(mockedGetElevation.mock.calls).toHaveLength(0);
97
+ expect(mockedGetElevation).toHaveBeenCalledTimes(0);
98
98
  });
99
99
 
100
100
  test('don\'t call getElevation when altitude 0 supplied', () => {
@@ -109,6 +109,6 @@ describe('calculateCameraOptionsFromTo', () => {
109
109
  const cameraOptions = map.calculateCameraOptionsFromTo(new LngLat(0, 0), 0, new LngLat(1, 0), 0);
110
110
 
111
111
  expect(cameraOptions).toBeDefined();
112
- expect(mockedGetElevation.mock.calls).toHaveLength(0);
112
+ expect(mockedGetElevation).toHaveBeenCalledTimes(0);
113
113
  });
114
114
  });
@@ -247,7 +247,7 @@ describe('map events', () => {
247
247
  expect(handler.onMove).toHaveBeenCalledTimes(1);
248
248
  });
249
249
 
250
- test('Map.on allows a listener to infer the event type ', () => {
250
+ test('Map.on allows a listener to infer the event type', () => {
251
251
  const map = createMap();
252
252
 
253
253
  const spy = vi.fn();
@@ -411,7 +411,7 @@ describe('map events', () => {
411
411
  expect(handler.onMove).toHaveBeenCalledTimes(0);
412
412
  });
413
413
 
414
- test('Map.off allows a listener to infer the event type ', () => {
414
+ test('Map.off allows a listener to infer the event type', () => {
415
415
  const map = createMap();
416
416
 
417
417
  const spy = vi.fn();
@@ -440,7 +440,7 @@ describe('map events', () => {
440
440
  expect(handler.onMoveOnce).toHaveBeenCalledTimes(1);
441
441
  });
442
442
 
443
- test('Map.once allows a listener to infer the event type ', () => {
443
+ test('Map.once allows a listener to infer the event type', () => {
444
444
  const map = createMap();
445
445
 
446
446
  const spy = vi.fn();
@@ -964,7 +964,7 @@ describe('map events', () => {
964
964
  map.on('load', loadHandler);
965
965
  await sleep(1);
966
966
 
967
- expect(loadHandler).toThrowError();
967
+ expect(loadHandler).toThrow('Error in load handler');
968
968
  });
969
969
 
970
970
  test('no idle event during move', async () => {
@@ -981,7 +981,7 @@ describe('map events', () => {
981
981
  const map = createMap();
982
982
  const sourcePromise = map.once('sourcedataabort');
983
983
  map.fire(new EventedEvent('dataabort'));
984
- await sourcePromise;
984
+ await expect(sourcePromise).resolves.toBeDefined();
985
985
  });
986
986
 
987
987
  test('getZoom on moveend is the same as after the map end moving, with terrain on', async () => {
@@ -1,4 +1,4 @@
1
- import {describe, beforeEach, test, expect, vitest} from 'vitest';
1
+ import {describe, beforeEach, test, expect, vi} from 'vitest';
2
2
  import {createMap, beforeMapTest} from '../../util/test/util.ts';
3
3
 
4
4
  beforeEach(() => {
@@ -27,7 +27,7 @@ describe('setGlobalStateProperty', () => {
27
27
  });
28
28
 
29
29
  await map.once('style.load');
30
- map._update = vitest.fn();
30
+ map._update = vi.fn();
31
31
 
32
32
  map.setGlobalStateProperty('backgroundColor', 'blue');
33
33
 
@@ -56,7 +56,7 @@ describe('setGlobalStateProperty', () => {
56
56
  });
57
57
 
58
58
  await map.once('style.load');
59
- map._update = vitest.fn();
59
+ map._update = vi.fn();
60
60
 
61
61
  map.setGlobalStateProperty('backgroundColor', 'blue');
62
62
 
@@ -90,7 +90,7 @@ test('map fires `styleimagemissing` when missing style image resolver returns no
90
90
  const generatedImage = await map.style.imageManager.getImages([id]);
91
91
  expect(resolver).toHaveBeenCalledWith(id);
92
92
  expect(generatedImage[id]).toBeUndefined();
93
- expect(missingImageEventSpy).toHaveBeenCalledOnce();
93
+ expect(missingImageEventSpy).toHaveBeenCalledTimes(1);
94
94
  expect(missingImageEventSpy.mock.calls[0][0].id).toBe(id);
95
95
  expect(map.hasImage(id)).toBeFalsy();
96
96
  });
@@ -245,7 +245,7 @@ test('setImages broadcasts even when getImages is called between addImage and up
245
245
 
246
246
  await map.once('load');
247
247
 
248
- const broadcastSpy = vi.fn().mockReturnValue(Promise.resolve({}));
248
+ const broadcastSpy = vi.fn().mockResolvedValue({});
249
249
  map.style.dispatcher.broadcast = broadcastSpy;
250
250
 
251
251
  map.addImage('new-image', {width: 1, height: 1, data: new Uint8Array(4)});
@@ -271,7 +271,7 @@ test('setImages broadcasts after missing style image resolver adds an image', as
271
271
 
272
272
  await map.once('load');
273
273
 
274
- const broadcastSpy = vi.fn().mockReturnValue(Promise.resolve({}));
274
+ const broadcastSpy = vi.fn().mockResolvedValue({});
275
275
  map.style.dispatcher.broadcast = broadcastSpy;
276
276
 
277
277
  map.setMissingStyleImageResolver((id) => {
@@ -69,7 +69,7 @@ describe('Map.isMoving', () => {
69
69
 
70
70
  test('returns true when drag rotating', async () => {
71
71
  // Prevent inertial rotation.
72
- vi.spyOn(timeControl, 'now').mockImplementation(() => 0);
72
+ vi.spyOn(timeControl, 'now').mockReturnValue(0);
73
73
 
74
74
  map.on('movestart', () => {
75
75
  expect(map.isMoving()).toBe(true);
@@ -40,7 +40,7 @@ describe('Map.isRotating', () => {
40
40
 
41
41
  test('returns true when drag rotating', async () => {
42
42
  // Prevent inertial rotation.
43
- vi.spyOn(timeControl, 'now').mockImplementation(() => 0);
43
+ vi.spyOn(timeControl, 'now').mockReturnValue(0);
44
44
 
45
45
  map.on('rotatestart', () => {
46
46
  expect(map.isRotating()).toBe(true);
@@ -98,7 +98,8 @@ test('removeLayer restores Map.loaded() to true', async () => {
98
98
 
99
99
  await map.once('render');
100
100
  map.removeLayer('layerId');
101
- await waitForEvent(map, 'render', () => map.loaded());
101
+ await expect(waitForEvent(map, 'render', () => map.loaded())).resolves.toBeDefined();
102
+
102
103
  map.remove();
103
104
  });
104
105
 
@@ -49,11 +49,7 @@ describe('mapOptions', () => {
49
49
  let idleTriggered = false;
50
50
  const fadeDuration = 100;
51
51
  const spy = vi.spyOn(Style.prototype, 'update').mockImplementation((parameters: EvaluationParameters) => {
52
- if (!idleTriggered) {
53
- expect(parameters.fadeDuration).toBe(0);
54
- } else {
55
- expect(parameters.fadeDuration).toBe(fadeDuration);
56
- }
52
+ expect(parameters.fadeDuration).toBe(idleTriggered ? fadeDuration : 0);
57
53
  });
58
54
  const style = createStyle();
59
55
  const map = createMap({style, fadeDuration});
@@ -31,7 +31,7 @@ test('ignore minPitchs over maxPitch', () => {
31
31
  const map = createMap({pitch: 0, maxPitch: 10});
32
32
  expect(() => {
33
33
  map.setMinPitch(20);
34
- }).toThrow();
34
+ }).toThrow('minPitch must be between 0 and the current maxPitch, inclusive');
35
35
  map.setPitch(0);
36
36
  expect(map.getPitch()).toBe(0);
37
37
  });
@@ -89,7 +89,7 @@ test('ignore maxPitchs over minPitch', () => {
89
89
  const map = createMap({minPitch: 10});
90
90
  expect(() => {
91
91
  map.setMaxPitch(0);
92
- }).toThrow();
92
+ }).toThrow('maxPitch must be greater than the current minPitch');
93
93
  map.setPitch(10);
94
94
  expect(map.getPitch()).toBe(10);
95
95
  });
@@ -140,8 +140,8 @@ test('fire move and pitch events when pitch is changed due to minPitch change',
140
140
  map.on('pitch', handleEvent);
141
141
  map.on('pitchend', handleEvent);
142
142
  map.setMinPitch(11);
143
- expect(map.getPitch()).toEqual(11);
144
- expect(map.getMinPitch()).toEqual(11);
143
+ expect(map.getPitch()).toBe(11);
144
+ expect(map.getMinPitch()).toBe(11);
145
145
  expect(handleEvent).toHaveBeenCalledTimes(6);
146
146
  });
147
147
 
@@ -155,7 +155,7 @@ test('fire move and pitch events when pitch is changed due to maxPitch change',
155
155
  map.on('pitch', handleEvent);
156
156
  map.on('pitchend', handleEvent);
157
157
  map.setMaxPitch(10);
158
- expect(map.getPitch()).toEqual(10);
159
- expect(map.getMaxPitch()).toEqual(10);
158
+ expect(map.getPitch()).toBe(10);
159
+ expect(map.getMaxPitch()).toBe(10);
160
160
  expect(handleEvent).toHaveBeenCalledTimes(6);
161
161
  });
@@ -30,7 +30,7 @@ describe('Map::refreshTiles', () => {
30
30
  map.style.tileManagers['source-id1'].refreshTiles = spy;
31
31
 
32
32
  map.refreshTiles('source-id1', [{x: 1024, y: 1023, z: 11}]);
33
- expect(spy).toHaveBeenCalledOnce();
33
+ expect(spy).toHaveBeenCalledTimes(1);
34
34
  expect(spy.mock.calls[0][0]).toEqual([new CanonicalTileID(11, 1024, 1023)]);
35
35
  });
36
36
 
@@ -43,7 +43,7 @@ describe('Map::refreshTiles', () => {
43
43
  map.style.tileManagers['source-id1'].reload = spy;
44
44
 
45
45
  map.refreshTiles('source-id1');
46
- expect(spy).toHaveBeenCalledOnce();
46
+ expect(spy).toHaveBeenCalledTimes(1);
47
47
  expect(spy.mock.calls[0][0]).toBe(true);
48
48
  });
49
49
  });
@@ -87,5 +87,5 @@ test('redraw', async () => {
87
87
  const renderPromise = map.once('render');
88
88
 
89
89
  map.redraw();
90
- await renderPromise;
90
+ await expect(renderPromise).resolves.toBeDefined();
91
91
  });
@@ -42,7 +42,7 @@ test('set tile LOD params for a non-existent source', async () => {
42
42
 
43
43
  expect(map.getSource('source-id1').calculateTileZoom).toBeUndefined();
44
44
  expect(map.getSource('source-id2').calculateTileZoom).toBeUndefined();
45
- expect(() => {map.setSourceTileLodParams(1, 1, 'non-existent-source-id');}).toThrowError();
45
+ expect(() => {map.setSourceTileLodParams(1, 1, 'non-existent-source-id');}).toThrow('There is no source with ID "non-existent-source-id", cannot set LOD parameters');
46
46
  expect(map.getSource('source-id1').calculateTileZoom).toBeUndefined();
47
47
  expect(map.getSource('source-id2').calculateTileZoom).toBeUndefined();
48
48
  });
@@ -78,12 +78,14 @@ describe('setStyle', () => {
78
78
  ]);
79
79
  });
80
80
 
81
- test('can be called more than once', () => {
81
+ test('can be called more than once', async () => {
82
82
  const map = createMap();
83
83
 
84
84
  map.setStyle({version: 8, sources: {}, layers: []}, {diff: false});
85
85
  map.setStyle({version: 8, sources: {}, layers: []}, {diff: false});
86
+ await map.once('style.load');
86
87
 
88
+ expect(map.getStyle()).toEqual({version: 8, sources: {}, layers: []});
87
89
  });
88
90
 
89
91
  test('setStyle back to the first style should work', async () => {
@@ -477,12 +479,16 @@ describe('getStyle', () => {
477
479
  type: 'background'
478
480
  } as LayerSpecification;
479
481
  map.addLayer(layer);
482
+
483
+ expect(map.getLayer('background')).toBeDefined();
480
484
  });
481
485
 
482
486
  test('a source can be added even if a map is created without a style', () => {
483
487
  const map = createMap({deleteStyle: true});
484
488
  const source = createStyleSource();
485
489
  map.addSource('fill', source);
490
+
491
+ expect(map.getSource('fill')).toBeDefined();
486
492
  });
487
493
 
488
494
  test('a layer can be added with an embedded source specification', () => {
@@ -496,6 +502,8 @@ describe('getStyle', () => {
496
502
  type: 'symbol',
497
503
  source
498
504
  });
505
+
506
+ expect(map.getLayer('foo')).toBeDefined();
499
507
  });
500
508
 
501
509
  test('returns the style with added source and layer', async () => {
@@ -87,6 +87,26 @@ describe('setTerrain', () => {
87
87
  const innerContainer = map.getContainer().querySelector('.maplibregl-ctrl-attrib-inner');
88
88
  expect(innerContainer.innerHTML).toBe(`DEM B | ${defaultAttributionControlOptions.customAttribution}`);
89
89
  });
90
+
91
+ test('invalidates cached elevation when terrain source data changes without a tile', async () => {
92
+ await map.once('load');
93
+ map.addSource('terrainrgb', {
94
+ type: 'raster-dem',
95
+ tiles: ['http://example.com/{z}/{x}/{y}.png']
96
+ });
97
+ map.setTerrain({source: 'terrainrgb'});
98
+ if (!map.terrain) throw new Error('Expected terrain to be set');
99
+ const resetElevationCache = vi.spyOn(map.terrain, 'resetElevationCache');
100
+
101
+ map._terrainDataCallback({
102
+ dataType: 'source',
103
+ sourceId: 'terrainrgb',
104
+ sourceDataType: 'content',
105
+ source: {type: 'raster-dem'}
106
+ } as any);
107
+
108
+ expect(resetElevationCache).toHaveBeenCalledTimes(1);
109
+ });
90
110
  });
91
111
 
92
112
  describe('getTerrain', () => {