maplibre-gl 3.2.1 → 3.2.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 (72) hide show
  1. package/build/generate-struct-arrays.ts +3 -2
  2. package/dist/maplibre-gl-csp-worker.js +1 -1
  3. package/dist/maplibre-gl-csp-worker.js.map +1 -1
  4. package/dist/maplibre-gl-csp.js +1 -1
  5. package/dist/maplibre-gl-csp.js.map +1 -1
  6. package/dist/maplibre-gl-dev.js +150 -84
  7. package/dist/maplibre-gl-dev.js.map +1 -1
  8. package/dist/maplibre-gl.d.ts +67 -50
  9. package/dist/maplibre-gl.js +4 -4
  10. package/dist/maplibre-gl.js.map +1 -1
  11. package/package.json +18 -18
  12. package/src/data/array_types.g.ts +32 -10
  13. package/src/data/bucket/circle_bucket.ts +1 -0
  14. package/src/data/bucket/line_bucket.ts +1 -0
  15. package/src/data/bucket/symbol_bucket.ts +1 -0
  16. package/src/data/feature_index.ts +1 -0
  17. package/src/data/program_configuration.ts +1 -0
  18. package/src/data/segment.ts +2 -0
  19. package/src/geo/transform.ts +1 -0
  20. package/src/gl/context.ts +1 -0
  21. package/src/gl/framebuffer.ts +1 -0
  22. package/src/gl/index_buffer.ts +1 -0
  23. package/src/gl/render_pool.ts +2 -1
  24. package/src/gl/vertex_buffer.ts +1 -0
  25. package/src/render/image_atlas.ts +1 -0
  26. package/src/render/line_atlas.ts +1 -0
  27. package/src/render/painter.ts +1 -0
  28. package/src/render/program.ts +1 -0
  29. package/src/render/render_to_texture.ts +31 -14
  30. package/src/render/terrain.ts +3 -0
  31. package/src/render/texture.ts +1 -0
  32. package/src/render/uniform_binding.ts +2 -0
  33. package/src/render/vertex_array_object.ts +1 -0
  34. package/src/shaders/symbol_sdf.fragment.glsl +9 -3
  35. package/src/shaders/symbol_sdf.fragment.glsl.g.ts +1 -1
  36. package/src/source/canvas_source.ts +1 -3
  37. package/src/source/geojson_source.ts +1 -3
  38. package/src/source/image_source.ts +2 -4
  39. package/src/source/source_cache.ts +1 -0
  40. package/src/source/source_state.ts +1 -0
  41. package/src/source/terrain_source_cache.ts +1 -0
  42. package/src/source/tile.ts +1 -0
  43. package/src/source/tile_cache.ts +1 -1
  44. package/src/source/tile_id.ts +1 -0
  45. package/src/source/vector_tile_worker_source.test.ts +79 -0
  46. package/src/source/vector_tile_worker_source.ts +26 -1
  47. package/src/source/worker_source.ts +1 -0
  48. package/src/style/evaluation_parameters.ts +1 -0
  49. package/src/style/properties.ts +14 -0
  50. package/src/style/style.ts +1 -0
  51. package/src/style/style_glyph.ts +1 -0
  52. package/src/symbol/collision_index.ts +1 -0
  53. package/src/symbol/grid_index.ts +1 -0
  54. package/src/ui/camera.ts +8 -8
  55. package/src/ui/handler/box_zoom.ts +1 -3
  56. package/src/ui/handler/click_zoom.ts +1 -3
  57. package/src/ui/handler/keyboard.ts +1 -3
  58. package/src/ui/handler/scroll_zoom.ts +1 -3
  59. package/src/ui/handler/shim/dblclick_zoom.ts +1 -3
  60. package/src/ui/handler/shim/drag_pan.ts +1 -3
  61. package/src/ui/handler/shim/drag_rotate.ts +1 -3
  62. package/src/ui/handler/shim/two_fingers_touch.ts +1 -3
  63. package/src/ui/handler/transform-provider.ts +1 -0
  64. package/src/ui/handler/two_fingers_touch.ts +1 -3
  65. package/src/ui/map.ts +7 -6
  66. package/src/util/ajax.test.ts +33 -0
  67. package/src/util/ajax.ts +5 -0
  68. package/src/util/image.ts +1 -0
  69. package/src/util/image_request.ts +2 -2
  70. package/src/util/performance.ts +1 -2
  71. package/src/util/struct_array.ts +5 -1
  72. package/src/util/test/mock_fetch.ts +51 -0
package/src/ui/map.ts CHANGED
@@ -504,7 +504,7 @@ export class Map extends Camera {
504
504
  _terrainDataCallback: (e: MapStyleDataEvent | MapSourceDataEvent) => void;
505
505
 
506
506
  /**
507
- * @hidden
507
+ * @internal
508
508
  * image queue throttling handle. To be used later when clean up
509
509
  */
510
510
  _imageQueueHandle: number;
@@ -707,9 +707,9 @@ export class Map extends Camera {
707
707
  }
708
708
 
709
709
  /**
710
+ * @internal
710
711
  * Returns a unique number for this map instance which is used for the MapLoadEvent
711
712
  * to make sure we only fire one event per instantiated map object.
712
- * @hidden
713
713
  * @returns the uniq map ID
714
714
  */
715
715
  _getMapId() {
@@ -868,9 +868,9 @@ export class Map extends Camera {
868
868
  }
869
869
 
870
870
  /**
871
+ * @internal
871
872
  * Return the map's pixel ratio eventually scaled down to respect maxCanvasSize.
872
873
  * Internally you should use this and not getPixelRatio().
873
- * @hidden
874
874
  */
875
875
  _getClampedPixelRatio(width: number, height: number): number {
876
876
  const {0: maxCanvasWidth, 1: maxCanvasHeight} = this._maxCanvasSize;
@@ -3070,9 +3070,9 @@ export class Map extends Camera {
3070
3070
  }
3071
3071
 
3072
3072
  /**
3073
+ * @internal
3073
3074
  * Update this map's style and sources, and re-render the map.
3074
3075
  *
3075
- * @hidden
3076
3076
  * @param updateStyle - mark the map's style for reprocessing as
3077
3077
  * well as its sources
3078
3078
  * @returns `this`
@@ -3088,9 +3088,10 @@ export class Map extends Camera {
3088
3088
  }
3089
3089
 
3090
3090
  /**
3091
+ * @internal
3091
3092
  * Request that the given callback be executed during the next render
3092
3093
  * frame. Schedule a render frame if one is not already scheduled.
3093
- * @hidden
3094
+ *
3094
3095
  * @returns An id that can be used to cancel the callback
3095
3096
  */
3096
3097
  _requestRenderFrame(callback: () => void): TaskID {
@@ -3103,6 +3104,7 @@ export class Map extends Camera {
3103
3104
  }
3104
3105
 
3105
3106
  /**
3107
+ * @internal
3106
3108
  * Call when a (re-)render of the map is required:
3107
3109
  * - The style has changed (`setPaintProperty()`, etc.)
3108
3110
  * - Source data has changed (e.g. tiles have finished loading)
@@ -3110,7 +3112,6 @@ export class Map extends Camera {
3110
3112
  * - A transition is in progress
3111
3113
  *
3112
3114
  * @param paintStartTimeStamp - The time when the animation frame began executing.
3113
- * @hidden
3114
3115
  *
3115
3116
  * @returns `this`
3116
3117
  */
@@ -7,6 +7,7 @@ import {
7
7
  } from './ajax';
8
8
 
9
9
  import {fakeServer, FakeServer} from 'nise';
10
+ import {destroyFetchMock, FetchMock, RequestMock, setupFetchMock} from './test/mock_fetch';
10
11
 
11
12
  function readAsText(blob) {
12
13
  return new Promise((resolve, reject) => {
@@ -141,4 +142,36 @@ describe('ajax', () => {
141
142
  // edge case
142
143
  expect(sameOrigin('://foo')).toBe(true);
143
144
  });
145
+
146
+ describe('requests parameters', () => {
147
+ let fetch: FetchMock;
148
+
149
+ beforeEach(() => {
150
+ fetch = setupFetchMock();
151
+ });
152
+
153
+ afterEach(() => {
154
+ destroyFetchMock();
155
+ });
156
+
157
+ test('should be provided to fetch API in getArrayBuffer function', (done) => {
158
+ getArrayBuffer({url: 'http://example.com/test-params.json', cache: 'force-cache', headers: {'Authorization': 'Bearer 123'}}, () => {
159
+ expect(fetch).toHaveBeenCalledTimes(1);
160
+ expect(fetch).toHaveBeenCalledWith(expect.objectContaining({url: 'http://example.com/test-params.json', method: 'GET', cache: 'force-cache'}));
161
+ expect((fetch.mock.calls[0][0] as RequestMock).headers.get('Authorization')).toBe('Bearer 123');
162
+
163
+ done();
164
+ });
165
+ });
166
+
167
+ test('should be provided to fetch API in getJSON function', (done) => {
168
+ getJSON({url: 'http://example.com/test-params.json', cache: 'force-cache', headers: {'Authorization': 'Bearer 123'}}, () => {
169
+ expect(fetch).toHaveBeenCalledTimes(1);
170
+ expect(fetch).toHaveBeenCalledWith(expect.objectContaining({url: 'http://example.com/test-params.json', method: 'GET', cache: 'force-cache'}));
171
+ expect((fetch.mock.calls[0][0] as RequestMock).headers.get('Authorization')).toBe('Bearer 123');
172
+
173
+ done();
174
+ });
175
+ });
176
+ });
144
177
  });
package/src/util/ajax.ts CHANGED
@@ -49,6 +49,10 @@ export type RequestParameters = {
49
49
  * If `true`, Resource Timing API information will be collected for these transformed requests and returned in a resourceTiming property of relevant data events.
50
50
  */
51
51
  collectResourceTiming?: boolean;
52
+ /**
53
+ * Parameters supported only by browser fetch API. Property of the Request interface contains the cache mode of the request. It controls how the request will interact with the browser's HTTP cache. (https://developer.mozilla.org/en-US/docs/Web/API/Request/cache)
54
+ */
55
+ cache?: RequestCache;
52
56
  };
53
57
 
54
58
  /**
@@ -123,6 +127,7 @@ function makeFetchRequest(requestParameters: RequestParameters, callback: Respon
123
127
  body: requestParameters.body,
124
128
  credentials: requestParameters.credentials,
125
129
  headers: requestParameters.headers,
130
+ cache: requestParameters.cache,
126
131
  referrer: getReferrer(),
127
132
  signal: controller.signal
128
133
  });
package/src/util/image.ts CHANGED
@@ -82,6 +82,7 @@ function copyImage(srcImg: any, dstImg: any, srcPt: Point2D, dstPt: Point2D, siz
82
82
  }
83
83
 
84
84
  /**
85
+ * @internal
85
86
  * An image with alpha color value
86
87
  */
87
88
  export class AlphaImage {
@@ -2,7 +2,7 @@ import type {Cancelable} from '../types/cancelable';
2
2
  import {RequestParameters, ExpiryData, makeRequest, sameOrigin, getProtocolAction} from './ajax';
3
3
  import type {Callback} from '../types/callback';
4
4
 
5
- import {arrayBufferToImageBitmap, arrayBufferToImage, extend, isWorker} from './util';
5
+ import {arrayBufferToImageBitmap, arrayBufferToImage, extend, isWorker, isImageBitmap} from './util';
6
6
  import {webpSupported} from './webp_supported';
7
7
  import {config} from './config';
8
8
 
@@ -202,7 +202,7 @@ export namespace ImageRequest {
202
202
  expires?: string | null): void => {
203
203
  if (err) {
204
204
  callback(err);
205
- } else if (data instanceof HTMLImageElement || data instanceof ImageBitmap) {
205
+ } else if (data instanceof HTMLImageElement || isImageBitmap(data)) {
206
206
  // User using addProtocol can directly return HTMLImageElement/ImageBitmap type
207
207
  // If HtmlImageElement is used to get image then response type will be HTMLImageElement
208
208
  callback(null, data);
@@ -75,9 +75,8 @@ export const PerformanceUtils = {
75
75
  };
76
76
 
77
77
  /**
78
+ * @internal
78
79
  * Safe wrapper for the performance resource timing API in web workers with graceful degradation
79
- *
80
- * @hidden
81
80
  */
82
81
  export class RequestPerformance {
83
82
  _marks: {
@@ -3,6 +3,7 @@
3
3
  import type {Transferable} from '../types/transferable';
4
4
 
5
5
  /**
6
+ * @internal
6
7
  * A view type size
7
8
  */
8
9
  const viewTypes = {
@@ -16,11 +17,12 @@ const viewTypes = {
16
17
  };
17
18
 
18
19
  /**
20
+ * @internal
19
21
  * A view type size
20
22
  */
21
23
  export type ViewType = keyof typeof viewTypes;
22
24
 
23
- /** */
25
+ /** @internal */
24
26
  class Struct {
25
27
  _pos1: number;
26
28
  _pos2: number;
@@ -48,6 +50,7 @@ const DEFAULT_CAPACITY = 128;
48
50
  const RESIZE_MULTIPLIER = 5;
49
51
 
50
52
  /**
53
+ * @internal
51
54
  * A struct array memeber
52
55
  */
53
56
  export type StructArrayMember = {
@@ -72,6 +75,7 @@ export type SerializedStructArray = {
72
75
  };
73
76
 
74
77
  /**
78
+ * @internal
75
79
  * `StructArray` provides an abstraction over `ArrayBuffer` and `TypedArray`
76
80
  * making it behave like an array of typed structs.
77
81
  *
@@ -0,0 +1,51 @@
1
+ export class RequestMock implements Partial<Request> {
2
+ public readonly cache: RequestCache;
3
+ public readonly headers: Headers = new Headers();
4
+ public readonly method?: string;
5
+ public readonly url?: string;
6
+
7
+ public get signal(): AbortSignal {
8
+ return null;
9
+ }
10
+
11
+ constructor(input: RequestInfo | URL, init?: RequestInit) {
12
+ this.cache = typeof input === 'object' && 'cache' in input ? input.cache : init.cache;
13
+ this.method = typeof input === 'object' && 'method' in input ? input.method : init.method;
14
+ this.url = typeof input === 'object' && 'url' in input ? input.url : input.toString();
15
+ this.headers = typeof input === 'object' && 'headers' in input ? new Headers(input.headers) : new Headers(init.headers || {});
16
+ }
17
+ }
18
+
19
+ class AbortControllerMock {
20
+ public signal: AbortSignal;
21
+
22
+ public abort(): void {}
23
+ }
24
+
25
+ export type FetchMock = jest.Mock<Promise<Response>, [input: RequestInfo | URL, init?: RequestInit], any>;
26
+
27
+ let _AbortController: typeof AbortController;
28
+ let _Request: typeof Request;
29
+ let _fetch: typeof fetch;
30
+
31
+ export function destroyFetchMock(): void {
32
+ global.AbortController = _AbortController ?? global.AbortController;
33
+ global.Request = _Request ?? global.Request;
34
+ global.fetch = _fetch ?? global.fetch;
35
+ }
36
+
37
+ export function setupFetchMock(): FetchMock {
38
+ _AbortController = _AbortController ?? global.AbortController;
39
+ _Request = _Request ?? global.Request;
40
+ _fetch = _fetch ?? global.fetch;
41
+
42
+ const fetchMock = jest.fn(async (_input: RequestInfo | URL, _init?: RequestInit): Promise<Response> => {
43
+ return <Response>{};
44
+ });
45
+
46
+ global.AbortController = AbortControllerMock;
47
+ global.Request = RequestMock as unknown as typeof Request;
48
+ global.fetch = fetchMock;
49
+
50
+ return fetchMock;
51
+ }