maplibre-gl 2.0.1 → 2.0.5

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 (105) hide show
  1. package/build/generate-struct-arrays.ts +4 -4
  2. package/build/post-ts-build.js +1 -0
  3. package/build/release-notes.js +7 -32
  4. package/dist/maplibre-gl.d.ts +76 -192
  5. package/dist/maplibre-gl.js +4 -4
  6. package/dist/maplibre-gl.js.map +1 -1
  7. package/package.json +22 -27
  8. package/src/data/array_types.ts +21 -21
  9. package/src/data/bucket/circle_bucket.ts +1 -1
  10. package/src/data/bucket/fill_bucket.test.ts +2 -2
  11. package/src/data/bucket/fill_bucket.ts +1 -1
  12. package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
  13. package/src/data/bucket/line_bucket.test.ts +2 -2
  14. package/src/data/bucket/line_bucket.ts +1 -1
  15. package/src/data/bucket/symbol_bucket.ts +1 -1
  16. package/src/data/bucket.ts +1 -1
  17. package/src/data/evaluation_feature.ts +1 -1
  18. package/src/data/feature_index.ts +3 -3
  19. package/src/data/load_geometry.ts +1 -1
  20. package/src/geo/edge_insets.ts +1 -1
  21. package/src/geo/transform.test.ts +1 -1
  22. package/src/geo/transform.ts +1 -1
  23. package/src/index.ts +1 -2
  24. package/src/render/draw_symbol.ts +1 -1
  25. package/src/source/geojson_source.test.ts +27 -0
  26. package/src/source/geojson_source.ts +1 -3
  27. package/src/source/geojson_wrapper.ts +1 -1
  28. package/src/source/image_source.test.ts +153 -0
  29. package/src/source/query_features.test.ts +1 -1
  30. package/src/source/query_features.ts +1 -1
  31. package/src/source/source.ts +2 -2
  32. package/src/source/source_cache.test.ts +3 -3
  33. package/src/source/source_cache.ts +1 -1
  34. package/src/source/tile.ts +1 -1
  35. package/src/source/tile_id.ts +1 -1
  36. package/src/source/vector_tile_worker_source.test.ts +306 -0
  37. package/src/source/worker_tile.test.ts +2 -1
  38. package/src/style/query_utils.ts +1 -1
  39. package/src/style/style.ts +1 -1
  40. package/src/style/style_layer/circle_style_layer.ts +1 -1
  41. package/src/style/style_layer/fill_extrusion_style_layer.ts +1 -1
  42. package/src/style/style_layer/fill_style_layer.ts +1 -1
  43. package/src/style/style_layer/line_style_layer.ts +1 -1
  44. package/src/style/style_layer.ts +13 -16
  45. package/src/style-spec/expression/index.ts +1 -1
  46. package/src/style-spec/feature_filter/feature_filter.test.ts +1 -1
  47. package/src/style-spec/migrate.test.ts +112 -0
  48. package/src/style-spec/style-spec.ts +0 -3
  49. package/src/style-spec/validate_spec.test.ts +29 -0
  50. package/src/symbol/anchor.ts +1 -1
  51. package/src/symbol/check_max_angle.test.ts +1 -1
  52. package/src/symbol/check_max_angle.ts +1 -1
  53. package/src/symbol/clip_line.test.ts +1 -1
  54. package/src/symbol/clip_line.ts +1 -1
  55. package/src/symbol/collision_feature.test.ts +1 -1
  56. package/src/symbol/collision_feature.ts +1 -1
  57. package/src/symbol/collision_index.ts +1 -1
  58. package/src/symbol/get_anchors.test.ts +1 -1
  59. package/src/symbol/get_anchors.ts +1 -1
  60. package/src/symbol/mergelines.test.ts +1 -1
  61. package/src/symbol/path_interpolator.test.ts +1 -1
  62. package/src/symbol/path_interpolator.ts +1 -1
  63. package/src/symbol/placement.ts +1 -1
  64. package/src/symbol/projection.ts +1 -1
  65. package/src/symbol/quads.ts +1 -1
  66. package/src/symbol/symbol_layout.ts +1 -1
  67. package/src/ui/camera.test.ts +0 -8
  68. package/src/ui/camera.ts +13 -3
  69. package/src/ui/control/navigation_control.ts +1 -1
  70. package/src/ui/events.ts +1 -1
  71. package/src/ui/handler/box_zoom.ts +1 -1
  72. package/src/ui/handler/click_zoom.ts +1 -1
  73. package/src/ui/handler/handler_util.ts +1 -1
  74. package/src/ui/handler/map_event.ts +1 -1
  75. package/src/ui/handler/mouse.ts +1 -1
  76. package/src/ui/handler/scroll_zoom.ts +1 -1
  77. package/src/ui/handler/tap_drag_zoom.ts +1 -1
  78. package/src/ui/handler/tap_recognizer.ts +1 -1
  79. package/src/ui/handler/tap_zoom.ts +1 -1
  80. package/src/ui/handler/touch_pan.ts +1 -1
  81. package/src/ui/handler/touch_zoom_rotate.ts +1 -1
  82. package/src/ui/handler_inertia.ts +1 -1
  83. package/src/ui/handler_manager.ts +1 -1
  84. package/src/ui/map.ts +4 -4
  85. package/src/ui/marker.test.ts +1 -1
  86. package/src/ui/marker.ts +2 -1
  87. package/src/ui/popup.test.ts +1 -1
  88. package/src/ui/popup.ts +2 -2
  89. package/src/util/ajax.test.ts +206 -0
  90. package/src/util/classify_rings.test.ts +1 -1
  91. package/src/util/classify_rings.ts +1 -1
  92. package/src/util/dom.ts +1 -1
  93. package/src/util/find_pole_of_inaccessibility.test.ts +1 -1
  94. package/src/util/find_pole_of_inaccessibility.ts +1 -1
  95. package/src/util/intersection_tests.ts +1 -1
  96. package/src/util/smart_wrap.ts +1 -1
  97. package/src/util/test/util.ts +14 -0
  98. package/src/util/transferable_grid_index.test.ts +56 -0
  99. package/src/util/transferable_grid_index.ts +216 -0
  100. package/src/util/util.test.ts +1 -1
  101. package/src/util/util.ts +1 -1
  102. package/src/util/web_worker_transfer.ts +1 -17
  103. package/CHANGELOG.md +0 -2578
  104. package/src/types/non-typed-modules.d.ts +0 -47
  105. package/src/util/point.ts +0 -349
@@ -1,6 +1,6 @@
1
1
  import {isCounterClockwise} from './util';
2
2
 
3
- import Point from './point';
3
+ import Point from '@mapbox/point-geometry';
4
4
 
5
5
  export {polygonIntersectsBufferedPoint, polygonIntersectsMultiPolygon, polygonIntersectsBufferedMultiLine, polygonIntersectsPolygon, distToSegmentSquared, polygonIntersectsBox};
6
6
 
@@ -1,6 +1,6 @@
1
1
  import LngLat from '../geo/lng_lat';
2
2
 
3
- import type Point from './point';
3
+ import type Point from '@mapbox/point-geometry';
4
4
  import type Transform from '../geo/transform';
5
5
 
6
6
  /**
@@ -99,3 +99,17 @@ export function getMockDispatcher() {
99
99
 
100
100
  return mockDispatcher;
101
101
  }
102
+
103
+ export function stubAjaxGetImage(createImageBitmap) {
104
+ global.createImageBitmap = createImageBitmap;
105
+
106
+ global.URL.revokeObjectURL = () => {};
107
+ global.URL.createObjectURL = (_) => { return null; };
108
+
109
+ // eslint-disable-next-line accessor-pairs
110
+ Object.defineProperty(global.Image.prototype, 'src', {
111
+ set(_) {
112
+ this.onload();
113
+ }
114
+ });
115
+ }
@@ -0,0 +1,56 @@
1
+ import TransferableGridIndex from './transferable_grid_index';
2
+
3
+ describe('TransferableGridIndex', () => {
4
+
5
+ test('indexes features', () => {
6
+ const grid = new TransferableGridIndex(100, 4, 1);
7
+ grid.insert(0, 4, 10, 6, 30);
8
+ grid.insert(1, 4, 10, 30, 12);
9
+ grid.insert(2, -10, 30, -5, 35);
10
+
11
+ expect(grid.query(4, 10, 5, 11).sort()).toEqual([0, 1]);
12
+ expect(grid.query(24, 10, 25, 11).sort()).toEqual([1]);
13
+ expect(grid.query(40, 40, 100, 100)).toEqual([]);
14
+ expect(grid.query(-6, 0, -7, 100)).toEqual([2]);
15
+ expect(grid.query(-Infinity, -Infinity, Infinity, Infinity).sort()).toEqual([0, 1, 2]);
16
+ });
17
+
18
+ test('returns multiple copies of a key if multiple boxes were inserted with the same key', () => {
19
+ const grid = new TransferableGridIndex(100, 4, 0);
20
+ const key = 123;
21
+ grid.insert(key, 3, 3, 4, 4);
22
+ grid.insert(key, 13, 13, 14, 14);
23
+ grid.insert(key, 23, 23, 24, 24);
24
+ expect(grid.query(0, 0, 30, 30)).toEqual([key, key, key]);
25
+ });
26
+
27
+ test('serializing to an arraybuffer', () => {
28
+ const originalGrid = new TransferableGridIndex(100, 4, 1);
29
+ originalGrid.insert(0, 4, 10, 6, 30);
30
+ originalGrid.insert(1, 4, 10, 30, 12);
31
+ originalGrid.insert(2, -10, 30, -5, 35);
32
+
33
+ const arrayBuffer = originalGrid.toArrayBuffer();
34
+ const grid = new TransferableGridIndex(arrayBuffer);
35
+
36
+ expect(grid.query(4, 10, 5, 11).sort()).toEqual([0, 1]);
37
+ expect(grid.query(24, 10, 25, 11).sort()).toEqual([1]);
38
+ expect(grid.query(40, 40, 100, 100)).toEqual([]);
39
+ expect(grid.query(-6, 0, -7, 100)).toEqual([2]);
40
+ expect(grid.query(-Infinity, -Infinity, Infinity, Infinity).sort()).toEqual([0, 1, 2]);
41
+
42
+ expect(() => grid.insert(3, 0, 0, 0, 0)).toThrow();
43
+ });
44
+
45
+ test('serialize round trip', () => {
46
+ const grid = new TransferableGridIndex(100, 4, 0);
47
+ const key = 123;
48
+ grid.insert(key, 3, 3, 4, 4);
49
+ grid.insert(key, 13, 13, 14, 14);
50
+ grid.insert(key, 23, 23, 24, 24);
51
+ const serializedGrid = TransferableGridIndex.serialize(grid);
52
+ const deserializedGrid = TransferableGridIndex.deserialize(serializedGrid);
53
+ expect(deserializedGrid.query(0, 0, 30, 30)).toEqual([key, key, key]);
54
+ });
55
+
56
+ });
@@ -0,0 +1,216 @@
1
+ /*
2
+ This file was copied from https://github.com/mapbox/grid-index and was
3
+ migrated from JavaScript to TypeScript.
4
+
5
+ Copyright (c) 2016, Mapbox
6
+
7
+ Permission to use, copy, modify, and/or distribute this software for any purpose
8
+ with or without fee is hereby granted, provided that the above copyright notice
9
+ and this permission notice appear in all copies.
10
+
11
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
12
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
13
+ FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
14
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
15
+ OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16
+ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
17
+ THIS SOFTWARE.
18
+ */
19
+
20
+ const NUM_PARAMS = 3;
21
+
22
+ export type SerializedGrid = {
23
+ buffer: ArrayBuffer;
24
+ };
25
+
26
+ class TransferableGridIndex {
27
+ cells: number[][];
28
+ arrayBuffer: ArrayBuffer;
29
+ d: number;
30
+ keys: number[];
31
+ bboxes: number[];
32
+ n: number;
33
+ extent: number;
34
+ padding: number;
35
+ scale: any;
36
+ uid: number;
37
+ min: number;
38
+ max: number;
39
+
40
+ constructor(extent: number | ArrayBuffer, n?: number, padding?: number) {
41
+ const cells = this.cells = [];
42
+
43
+ if (extent instanceof ArrayBuffer) {
44
+ this.arrayBuffer = extent;
45
+ const array = new Int32Array(this.arrayBuffer);
46
+ extent = array[0];
47
+ n = array[1];
48
+ padding = array[2];
49
+
50
+ this.d = n + 2 * padding;
51
+ for (let k = 0; k < this.d * this.d; k++) {
52
+ const start = array[NUM_PARAMS + k];
53
+ const end = array[NUM_PARAMS + k + 1];
54
+ cells.push(start === end ? null : array.subarray(start, end));
55
+ }
56
+ const keysOffset = array[NUM_PARAMS + cells.length];
57
+ const bboxesOffset = array[NUM_PARAMS + cells.length + 1];
58
+ this.keys = array.subarray(keysOffset, bboxesOffset) as any as number[];
59
+ this.bboxes = array.subarray(bboxesOffset) as any as number[];
60
+
61
+ this.insert = this._insertReadonly;
62
+
63
+ } else {
64
+ this.d = n + 2 * padding;
65
+ for (let i = 0; i < this.d * this.d; i++) {
66
+ cells.push([]);
67
+ }
68
+ this.keys = [];
69
+ this.bboxes = [];
70
+ }
71
+
72
+ this.n = n;
73
+ this.extent = extent;
74
+ this.padding = padding;
75
+ this.scale = n / extent;
76
+ this.uid = 0;
77
+
78
+ const p = (padding / n) * extent;
79
+ this.min = -p;
80
+ this.max = extent + p;
81
+ }
82
+
83
+ insert(key: number, x1: number, y1: number, x2: number, y2: number) {
84
+ this._forEachCell(x1, y1, x2, y2, this._insertCell, this.uid++, undefined, undefined);
85
+ this.keys.push(key);
86
+ this.bboxes.push(x1);
87
+ this.bboxes.push(y1);
88
+ this.bboxes.push(x2);
89
+ this.bboxes.push(y2);
90
+ }
91
+
92
+ _insertReadonly() {
93
+ throw new Error('Cannot insert into a GridIndex created from an ArrayBuffer.');
94
+ }
95
+
96
+ _insertCell(x1: number, y1: number, x2: number, y2: number, cellIndex: number, uid: number) {
97
+ this.cells[cellIndex].push(uid);
98
+ }
99
+
100
+ query(x1: number, y1: number, x2: number, y2: number, intersectionTest?: Function): number[] {
101
+ const min = this.min;
102
+ const max = this.max;
103
+ if (x1 <= min && y1 <= min && max <= x2 && max <= y2 && !intersectionTest) {
104
+ // We use `Array#slice` because `this.keys` may be a `Int32Array` and
105
+ // some browsers (Safari and IE) do not support `TypedArray#slice`
106
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/slice#Browser_compatibility
107
+ return Array.prototype.slice.call(this.keys);
108
+
109
+ } else {
110
+ const result = [];
111
+ const seenUids = {};
112
+ this._forEachCell(x1, y1, x2, y2, this._queryCell, result, seenUids, intersectionTest);
113
+ return result;
114
+ }
115
+ }
116
+
117
+ _queryCell(x1: number, y1: number, x2: number, y2:number, cellIndex:number, result, seenUids, intersectionTest: Function) {
118
+ const cell = this.cells[cellIndex];
119
+ if (cell !== null) {
120
+ const keys = this.keys;
121
+ const bboxes = this.bboxes;
122
+ for (let u = 0; u < cell.length; u++) {
123
+ const uid = cell[u];
124
+ if (seenUids[uid] === undefined) {
125
+ const offset = uid * 4;
126
+ if (intersectionTest ?
127
+ intersectionTest(bboxes[offset + 0], bboxes[offset + 1], bboxes[offset + 2], bboxes[offset + 3]) :
128
+ ((x1 <= bboxes[offset + 2]) &&
129
+ (y1 <= bboxes[offset + 3]) &&
130
+ (x2 >= bboxes[offset + 0]) &&
131
+ (y2 >= bboxes[offset + 1]))) {
132
+ seenUids[uid] = true;
133
+ result.push(keys[uid]);
134
+ } else {
135
+ seenUids[uid] = false;
136
+ }
137
+ }
138
+ }
139
+ }
140
+ }
141
+
142
+ _forEachCell(x1: number, y1: number, x2:number, y2:number, fn: Function, arg1, arg2, intersectionTest) {
143
+ const cx1 = this._convertToCellCoord(x1);
144
+ const cy1 = this._convertToCellCoord(y1);
145
+ const cx2 = this._convertToCellCoord(x2);
146
+ const cy2 = this._convertToCellCoord(y2);
147
+ for (let x = cx1; x <= cx2; x++) {
148
+ for (let y = cy1; y <= cy2; y++) {
149
+ const cellIndex = this.d * y + x;
150
+ if (intersectionTest && !intersectionTest(
151
+ this._convertFromCellCoord(x),
152
+ this._convertFromCellCoord(y),
153
+ this._convertFromCellCoord(x + 1),
154
+ this._convertFromCellCoord(y + 1))) continue;
155
+ if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, intersectionTest)) return;
156
+ }
157
+ }
158
+ }
159
+
160
+ _convertFromCellCoord (x) {
161
+ return (x - this.padding) / this.scale;
162
+ }
163
+
164
+ _convertToCellCoord(x) {
165
+ return Math.max(0, Math.min(this.d - 1, Math.floor(x * this.scale) + this.padding));
166
+ }
167
+
168
+ toArrayBuffer(): ArrayBuffer {
169
+ if (this.arrayBuffer) return this.arrayBuffer;
170
+
171
+ const cells = this.cells;
172
+
173
+ const metadataLength = NUM_PARAMS + this.cells.length + 1 + 1;
174
+ let totalCellLength = 0;
175
+ for (let i = 0; i < this.cells.length; i++) {
176
+ totalCellLength += this.cells[i].length;
177
+ }
178
+
179
+ const array = new Int32Array(metadataLength + totalCellLength + this.keys.length + this.bboxes.length);
180
+ array[0] = this.extent;
181
+ array[1] = this.n;
182
+ array[2] = this.padding;
183
+
184
+ let offset = metadataLength;
185
+ for (let k = 0; k < cells.length; k++) {
186
+ const cell = cells[k];
187
+ array[NUM_PARAMS + k] = offset;
188
+ array.set(cell, offset);
189
+ offset += cell.length;
190
+ }
191
+
192
+ array[NUM_PARAMS + cells.length] = offset;
193
+ array.set(this.keys, offset);
194
+ offset += this.keys.length;
195
+
196
+ array[NUM_PARAMS + cells.length + 1] = offset;
197
+ array.set(this.bboxes, offset);
198
+ offset += this.bboxes.length;
199
+
200
+ return array.buffer;
201
+ }
202
+
203
+ public static serialize(grid: TransferableGridIndex, transferables?: Array<Transferable>): SerializedGrid {
204
+ const buffer = grid.toArrayBuffer();
205
+ if (transferables) {
206
+ transferables.push(buffer);
207
+ }
208
+ return {buffer};
209
+ }
210
+
211
+ public static deserialize(serialized: SerializedGrid): TransferableGridIndex {
212
+ return new TransferableGridIndex(serialized.buffer);
213
+ }
214
+ }
215
+
216
+ export default TransferableGridIndex;
@@ -1,5 +1,5 @@
1
1
  import {easeCubicInOut, keysDifference, extend, pick, uniqueId, bindAll, asyncAll, clamp, wrap, bezier, mapObject, filterObject, deepEqual, clone, arraysIntersect, isCounterClockwise, isClosedPolygon, parseCacheControl, nextPowerOfTwo, isPowerOfTwo} from './util';
2
- import Point from './point';
2
+ import Point from '@mapbox/point-geometry';
3
3
 
4
4
  describe('util', () => {
5
5
  expect(easeCubicInOut(0)).toBe(0);
package/src/util/util.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import UnitBezier from '@mapbox/unitbezier';
2
2
 
3
- import Point from './point';
3
+ import Point from '@mapbox/point-geometry';
4
4
 
5
5
  import type {Callback} from '../types/callback';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import assert from 'assert';
2
2
 
3
- import TransferableGridIndex from 'grid-index';
3
+ import TransferableGridIndex from './transferable_grid_index';
4
4
  import Color from '../style-spec/util/color';
5
5
  import {StylePropertyFunction, StyleExpression, ZoomDependentExpression, ZoomConstantExpression} from '../style-spec/expression';
6
6
  import CompoundExpression from '../style-spec/expression/compound_expression';
@@ -63,22 +63,6 @@ export function register<T extends any>(
63
63
  }
64
64
 
65
65
  register('Object', Object);
66
-
67
- type SerializedGrid = {
68
- buffer: ArrayBuffer;
69
- };
70
-
71
- TransferableGridIndex.serialize = function serialize(grid: TransferableGridIndex, transferables?: Array<Transferable>): SerializedGrid {
72
- const buffer = grid.toArrayBuffer();
73
- if (transferables) {
74
- transferables.push(buffer);
75
- }
76
- return {buffer};
77
- };
78
-
79
- TransferableGridIndex.deserialize = function deserialize(serialized: SerializedGrid): TransferableGridIndex {
80
- return new TransferableGridIndex(serialized.buffer);
81
- };
82
66
  register('TransferableGridIndex', TransferableGridIndex);
83
67
 
84
68
  register('Color', Color);