maplibre-gl 3.2.1 → 3.3.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 (88) hide show
  1. package/build/generate-struct-arrays.ts +6 -3
  2. package/build/generate-style-code.ts +7 -8
  3. package/dist/maplibre-gl-csp-worker.js +1 -1
  4. package/dist/maplibre-gl-csp-worker.js.map +1 -1
  5. package/dist/maplibre-gl-csp.js +1 -1
  6. package/dist/maplibre-gl-csp.js.map +1 -1
  7. package/dist/maplibre-gl-dev.js +565 -243
  8. package/dist/maplibre-gl-dev.js.map +1 -1
  9. package/dist/maplibre-gl.d.ts +111 -57
  10. package/dist/maplibre-gl.js +4 -4
  11. package/dist/maplibre-gl.js.map +1 -1
  12. package/package.json +20 -20
  13. package/src/data/array_types.g.ts +110 -24
  14. package/src/data/bucket/circle_bucket.ts +1 -0
  15. package/src/data/bucket/line_bucket.ts +1 -0
  16. package/src/data/bucket/symbol_attributes.ts +7 -1
  17. package/src/data/bucket/symbol_bucket.ts +5 -1
  18. package/src/data/feature_index.ts +1 -0
  19. package/src/data/program_configuration.ts +1 -0
  20. package/src/data/segment.ts +2 -0
  21. package/src/geo/transform.ts +1 -0
  22. package/src/gl/context.ts +1 -0
  23. package/src/gl/framebuffer.ts +1 -0
  24. package/src/gl/index_buffer.ts +1 -0
  25. package/src/gl/render_pool.ts +2 -1
  26. package/src/gl/vertex_buffer.ts +1 -0
  27. package/src/render/draw_symbol.ts +8 -9
  28. package/src/render/image_atlas.ts +1 -0
  29. package/src/render/line_atlas.ts +1 -0
  30. package/src/render/painter.ts +1 -0
  31. package/src/render/program.ts +1 -0
  32. package/src/render/render_to_texture.ts +31 -14
  33. package/src/render/terrain.ts +3 -0
  34. package/src/render/texture.ts +1 -0
  35. package/src/render/uniform_binding.ts +2 -0
  36. package/src/render/vertex_array_object.ts +1 -0
  37. package/src/shaders/symbol_sdf.fragment.glsl +9 -3
  38. package/src/shaders/symbol_sdf.fragment.glsl.g.ts +1 -1
  39. package/src/source/canvas_source.ts +1 -3
  40. package/src/source/geojson_source.ts +1 -3
  41. package/src/source/image_source.ts +2 -4
  42. package/src/source/source_cache.ts +1 -0
  43. package/src/source/source_state.ts +1 -0
  44. package/src/source/terrain_source_cache.ts +1 -0
  45. package/src/source/tile.ts +1 -0
  46. package/src/source/tile_cache.ts +1 -1
  47. package/src/source/tile_id.ts +1 -0
  48. package/src/source/vector_tile_worker_source.test.ts +79 -0
  49. package/src/source/vector_tile_worker_source.ts +26 -1
  50. package/src/source/worker_source.ts +1 -0
  51. package/src/style/evaluation_parameters.ts +1 -0
  52. package/src/style/properties.ts +18 -0
  53. package/src/style/style.ts +1 -0
  54. package/src/style/style_glyph.ts +1 -0
  55. package/src/style/style_layer/background_style_layer_properties.g.ts +1 -6
  56. package/src/style/style_layer/circle_style_layer_properties.g.ts +1 -6
  57. package/src/style/style_layer/fill_extrusion_style_layer_properties.g.ts +1 -6
  58. package/src/style/style_layer/fill_style_layer_properties.g.ts +1 -6
  59. package/src/style/style_layer/heatmap_style_layer_properties.g.ts +1 -6
  60. package/src/style/style_layer/hillshade_style_layer_properties.g.ts +1 -6
  61. package/src/style/style_layer/line_style_layer_properties.g.ts +1 -6
  62. package/src/style/style_layer/raster_style_layer_properties.g.ts +1 -6
  63. package/src/style/style_layer/symbol_style_layer_properties.g.ts +4 -6
  64. package/src/style/style_layer/variable_text_anchor.test.ts +117 -0
  65. package/src/style/style_layer/variable_text_anchor.ts +163 -0
  66. package/src/symbol/collision_index.ts +1 -0
  67. package/src/symbol/grid_index.ts +1 -0
  68. package/src/symbol/placement.ts +52 -40
  69. package/src/symbol/symbol_layout.ts +42 -116
  70. package/src/ui/camera.ts +8 -8
  71. package/src/ui/handler/box_zoom.ts +1 -3
  72. package/src/ui/handler/click_zoom.ts +1 -3
  73. package/src/ui/handler/keyboard.ts +1 -3
  74. package/src/ui/handler/scroll_zoom.ts +1 -3
  75. package/src/ui/handler/shim/dblclick_zoom.ts +1 -3
  76. package/src/ui/handler/shim/drag_pan.ts +1 -3
  77. package/src/ui/handler/shim/drag_rotate.ts +1 -3
  78. package/src/ui/handler/shim/two_fingers_touch.ts +1 -3
  79. package/src/ui/handler/transform-provider.ts +1 -0
  80. package/src/ui/handler/two_fingers_touch.ts +1 -3
  81. package/src/ui/map.ts +7 -6
  82. package/src/util/ajax.test.ts +33 -0
  83. package/src/util/ajax.ts +5 -0
  84. package/src/util/image.ts +1 -0
  85. package/src/util/image_request.ts +2 -2
  86. package/src/util/performance.ts +1 -2
  87. package/src/util/struct_array.ts +5 -1
  88. package/src/util/test/mock_fetch.ts +51 -0
@@ -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
+ }