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.
- package/build/generate-struct-arrays.ts +4 -4
- package/build/post-ts-build.js +1 -0
- package/build/release-notes.js +7 -32
- package/dist/maplibre-gl.d.ts +76 -192
- package/dist/maplibre-gl.js +4 -4
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +22 -27
- package/src/data/array_types.ts +21 -21
- package/src/data/bucket/circle_bucket.ts +1 -1
- package/src/data/bucket/fill_bucket.test.ts +2 -2
- package/src/data/bucket/fill_bucket.ts +1 -1
- package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
- package/src/data/bucket/line_bucket.test.ts +2 -2
- package/src/data/bucket/line_bucket.ts +1 -1
- package/src/data/bucket/symbol_bucket.ts +1 -1
- package/src/data/bucket.ts +1 -1
- package/src/data/evaluation_feature.ts +1 -1
- package/src/data/feature_index.ts +3 -3
- package/src/data/load_geometry.ts +1 -1
- package/src/geo/edge_insets.ts +1 -1
- package/src/geo/transform.test.ts +1 -1
- package/src/geo/transform.ts +1 -1
- package/src/index.ts +1 -2
- package/src/render/draw_symbol.ts +1 -1
- package/src/source/geojson_source.test.ts +27 -0
- package/src/source/geojson_source.ts +1 -3
- package/src/source/geojson_wrapper.ts +1 -1
- package/src/source/image_source.test.ts +153 -0
- package/src/source/query_features.test.ts +1 -1
- package/src/source/query_features.ts +1 -1
- package/src/source/source.ts +2 -2
- package/src/source/source_cache.test.ts +3 -3
- package/src/source/source_cache.ts +1 -1
- package/src/source/tile.ts +1 -1
- package/src/source/tile_id.ts +1 -1
- package/src/source/vector_tile_worker_source.test.ts +306 -0
- package/src/source/worker_tile.test.ts +2 -1
- package/src/style/query_utils.ts +1 -1
- package/src/style/style.ts +1 -1
- package/src/style/style_layer/circle_style_layer.ts +1 -1
- package/src/style/style_layer/fill_extrusion_style_layer.ts +1 -1
- package/src/style/style_layer/fill_style_layer.ts +1 -1
- package/src/style/style_layer/line_style_layer.ts +1 -1
- package/src/style/style_layer.ts +13 -16
- package/src/style-spec/expression/index.ts +1 -1
- package/src/style-spec/feature_filter/feature_filter.test.ts +1 -1
- package/src/style-spec/migrate.test.ts +112 -0
- package/src/style-spec/style-spec.ts +0 -3
- package/src/style-spec/validate_spec.test.ts +29 -0
- package/src/symbol/anchor.ts +1 -1
- package/src/symbol/check_max_angle.test.ts +1 -1
- package/src/symbol/check_max_angle.ts +1 -1
- package/src/symbol/clip_line.test.ts +1 -1
- package/src/symbol/clip_line.ts +1 -1
- package/src/symbol/collision_feature.test.ts +1 -1
- package/src/symbol/collision_feature.ts +1 -1
- package/src/symbol/collision_index.ts +1 -1
- package/src/symbol/get_anchors.test.ts +1 -1
- package/src/symbol/get_anchors.ts +1 -1
- package/src/symbol/mergelines.test.ts +1 -1
- package/src/symbol/path_interpolator.test.ts +1 -1
- package/src/symbol/path_interpolator.ts +1 -1
- package/src/symbol/placement.ts +1 -1
- package/src/symbol/projection.ts +1 -1
- package/src/symbol/quads.ts +1 -1
- package/src/symbol/symbol_layout.ts +1 -1
- package/src/ui/camera.test.ts +0 -8
- package/src/ui/camera.ts +13 -3
- package/src/ui/control/navigation_control.ts +1 -1
- package/src/ui/events.ts +1 -1
- package/src/ui/handler/box_zoom.ts +1 -1
- package/src/ui/handler/click_zoom.ts +1 -1
- package/src/ui/handler/handler_util.ts +1 -1
- package/src/ui/handler/map_event.ts +1 -1
- package/src/ui/handler/mouse.ts +1 -1
- package/src/ui/handler/scroll_zoom.ts +1 -1
- package/src/ui/handler/tap_drag_zoom.ts +1 -1
- package/src/ui/handler/tap_recognizer.ts +1 -1
- package/src/ui/handler/tap_zoom.ts +1 -1
- package/src/ui/handler/touch_pan.ts +1 -1
- package/src/ui/handler/touch_zoom_rotate.ts +1 -1
- package/src/ui/handler_inertia.ts +1 -1
- package/src/ui/handler_manager.ts +1 -1
- package/src/ui/map.ts +4 -4
- package/src/ui/marker.test.ts +1 -1
- package/src/ui/marker.ts +2 -1
- package/src/ui/popup.test.ts +1 -1
- package/src/ui/popup.ts +2 -2
- package/src/util/ajax.test.ts +206 -0
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/classify_rings.ts +1 -1
- package/src/util/dom.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.test.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +1 -1
- package/src/util/intersection_tests.ts +1 -1
- package/src/util/smart_wrap.ts +1 -1
- package/src/util/test/util.ts +14 -0
- package/src/util/transferable_grid_index.test.ts +56 -0
- package/src/util/transferable_grid_index.ts +216 -0
- package/src/util/util.test.ts +1 -1
- package/src/util/util.ts +1 -1
- package/src/util/web_worker_transfer.ts +1 -17
- package/CHANGELOG.md +0 -2578
- package/src/types/non-typed-modules.d.ts +0 -47
- package/src/util/point.ts +0 -349
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import SourceCache from './source_cache';
|
|
2
|
-
import {
|
|
2
|
+
import {setSourceType} from './source';
|
|
3
3
|
import Tile from './tile';
|
|
4
4
|
import {OverscaledTileID} from './tile_id';
|
|
5
5
|
import Transform from '../geo/transform';
|
|
6
6
|
import LngLat from '../geo/lng_lat';
|
|
7
|
-
import Point from '
|
|
7
|
+
import Point from '@mapbox/point-geometry';
|
|
8
8
|
import {Event, ErrorEvent, Evented} from '../util/evented';
|
|
9
9
|
import {extend} from '../util/util';
|
|
10
10
|
import browser from '../util/browser';
|
|
@@ -63,7 +63,7 @@ function createSource(id: string, sourceOptions: any, _dispatcher: any, eventedP
|
|
|
63
63
|
return source;
|
|
64
64
|
}
|
|
65
65
|
|
|
66
|
-
|
|
66
|
+
setSourceType('mock-source-type', createSource as any);
|
|
67
67
|
|
|
68
68
|
function createSourceCache(options?, used?) {
|
|
69
69
|
const sc = new SourceCache('id', extend({
|
|
@@ -7,7 +7,7 @@ import MercatorCoordinate from '../geo/mercator_coordinate';
|
|
|
7
7
|
import {keysDifference} from '../util/util';
|
|
8
8
|
import EXTENT from '../data/extent';
|
|
9
9
|
import Context from '../gl/context';
|
|
10
|
-
import Point from '
|
|
10
|
+
import Point from '@mapbox/point-geometry';
|
|
11
11
|
import browser from '../util/browser';
|
|
12
12
|
import {OverscaledTileID} from './tile_id';
|
|
13
13
|
import assert from 'assert';
|
package/src/source/tile.ts
CHANGED
|
@@ -30,7 +30,7 @@ import type Transform from '../geo/transform';
|
|
|
30
30
|
import type {LayerFeatureStates} from './source_state';
|
|
31
31
|
import type {Cancelable} from '../types/cancelable';
|
|
32
32
|
import type {FilterSpecification} from '../style-spec/types';
|
|
33
|
-
import type Point from '
|
|
33
|
+
import type Point from '@mapbox/point-geometry';
|
|
34
34
|
import {mat4} from 'gl-matrix';
|
|
35
35
|
import type {VectorTileLayer} from '@mapbox/vector-tile';
|
|
36
36
|
|
package/src/source/tile_id.ts
CHANGED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import vt from '@mapbox/vector-tile';
|
|
4
|
+
import Protobuf from 'pbf';
|
|
5
|
+
import VectorTileWorkerSource from '../source/vector_tile_worker_source';
|
|
6
|
+
import StyleLayerIndex from '../style/style_layer_index';
|
|
7
|
+
import {fakeServer, SinonFakeServer} from 'sinon';
|
|
8
|
+
import Actor from '../util/actor';
|
|
9
|
+
import {TileParameters, WorkerTileParameters} from './worker_source';
|
|
10
|
+
import WorkerTile from './worker_tile';
|
|
11
|
+
import {setPerformance} from '../util/test/util';
|
|
12
|
+
|
|
13
|
+
describe('vector tile worker source', () => {
|
|
14
|
+
const actor = {send: () => {}} as any as Actor;
|
|
15
|
+
let server: SinonFakeServer;
|
|
16
|
+
let originalGetEntriesByName;
|
|
17
|
+
let originalMeasure;
|
|
18
|
+
let originalMark;
|
|
19
|
+
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
global.fetch = null;
|
|
22
|
+
server = fakeServer.create();
|
|
23
|
+
setPerformance();
|
|
24
|
+
originalGetEntriesByName = window.performance.getEntriesByName;
|
|
25
|
+
originalMeasure = window.performance.measure;
|
|
26
|
+
originalMark = window.performance.mark;
|
|
27
|
+
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
afterEach(() => {
|
|
31
|
+
server.restore();
|
|
32
|
+
jest.clearAllMocks();
|
|
33
|
+
window.performance.getEntriesByName = originalGetEntriesByName;
|
|
34
|
+
window.performance.measure = originalMeasure;
|
|
35
|
+
window.performance.mark = originalMark;
|
|
36
|
+
});
|
|
37
|
+
test('VectorTileWorkerSource#abortTile aborts pending request', () => {
|
|
38
|
+
const source = new VectorTileWorkerSource(actor, new StyleLayerIndex(), []);
|
|
39
|
+
|
|
40
|
+
source.loadTile({
|
|
41
|
+
source: 'source',
|
|
42
|
+
uid: 0,
|
|
43
|
+
tileID: {overscaledZ: 0, wrap: 0, canonical: {x: 0, y: 0, z: 0, w: 0}},
|
|
44
|
+
request: {url: 'http://localhost:2900/abort'}
|
|
45
|
+
} as any as WorkerTileParameters, (err, res) => {
|
|
46
|
+
expect(err).toBeFalsy();
|
|
47
|
+
expect(res).toBeFalsy();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
source.abortTile({
|
|
51
|
+
source: 'source',
|
|
52
|
+
uid: 0
|
|
53
|
+
} as any as TileParameters, (err, res) => {
|
|
54
|
+
expect(err).toBeFalsy();
|
|
55
|
+
expect(res).toBeFalsy();
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(source.loading).toEqual({});
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('VectorTileWorkerSource#removeTile removes loaded tile', () => {
|
|
62
|
+
const source = new VectorTileWorkerSource(actor, new StyleLayerIndex(), []);
|
|
63
|
+
|
|
64
|
+
source.loaded = {
|
|
65
|
+
'0': {} as WorkerTile
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
source.removeTile({
|
|
69
|
+
source: 'source',
|
|
70
|
+
uid: 0
|
|
71
|
+
} as any as TileParameters, (err, res) => {
|
|
72
|
+
expect(err).toBeFalsy();
|
|
73
|
+
expect(res).toBeFalsy();
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
expect(source.loaded).toEqual({});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('VectorTileWorkerSource#reloadTile reloads a previously-loaded tile', () => {
|
|
80
|
+
const source = new VectorTileWorkerSource(actor, new StyleLayerIndex(), []);
|
|
81
|
+
const parse = jest.fn();
|
|
82
|
+
|
|
83
|
+
source.loaded = {
|
|
84
|
+
'0': {
|
|
85
|
+
status: 'done',
|
|
86
|
+
vectorTile: {},
|
|
87
|
+
parse
|
|
88
|
+
} as any as WorkerTile
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const callback = jest.fn();
|
|
92
|
+
source.reloadTile({uid: 0} as any as WorkerTileParameters, callback);
|
|
93
|
+
expect(parse).toHaveBeenCalledTimes(1);
|
|
94
|
+
|
|
95
|
+
parse.mock.calls[0][4]();
|
|
96
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
test('VectorTileWorkerSource#reloadTile queues a reload when parsing is in progress', () => {
|
|
100
|
+
const source = new VectorTileWorkerSource(actor, new StyleLayerIndex(), []);
|
|
101
|
+
const parse = jest.fn();
|
|
102
|
+
|
|
103
|
+
source.loaded = {
|
|
104
|
+
'0': {
|
|
105
|
+
status: 'done',
|
|
106
|
+
vectorTile: {},
|
|
107
|
+
parse
|
|
108
|
+
} as any as WorkerTile
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const callback1 = jest.fn();
|
|
112
|
+
const callback2 = jest.fn();
|
|
113
|
+
source.reloadTile({uid: 0} as any as WorkerTileParameters, callback1);
|
|
114
|
+
expect(parse).toHaveBeenCalledTimes(1);
|
|
115
|
+
|
|
116
|
+
source.loaded[0].status = 'parsing';
|
|
117
|
+
source.reloadTile({uid: 0} as any as WorkerTileParameters, callback2);
|
|
118
|
+
expect(parse).toHaveBeenCalledTimes(1);
|
|
119
|
+
|
|
120
|
+
parse.mock.calls[0][4]();
|
|
121
|
+
expect(parse).toHaveBeenCalledTimes(2);
|
|
122
|
+
expect(callback1).toHaveBeenCalledTimes(1);
|
|
123
|
+
expect(callback2).toHaveBeenCalledTimes(0);
|
|
124
|
+
|
|
125
|
+
parse.mock.calls[1][4]();
|
|
126
|
+
expect(callback1).toHaveBeenCalledTimes(1);
|
|
127
|
+
expect(callback2).toHaveBeenCalledTimes(1);
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
test('VectorTileWorkerSource#reloadTile handles multiple pending reloads', () => {
|
|
131
|
+
// https://github.com/mapbox/mapbox-gl-js/issues/6308
|
|
132
|
+
const source = new VectorTileWorkerSource(actor, new StyleLayerIndex(), []);
|
|
133
|
+
const parse = jest.fn();
|
|
134
|
+
|
|
135
|
+
source.loaded = {
|
|
136
|
+
'0': {
|
|
137
|
+
status: 'done',
|
|
138
|
+
vectorTile: {},
|
|
139
|
+
parse
|
|
140
|
+
} as any as WorkerTile
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
const callback1 = jest.fn();
|
|
144
|
+
const callback2 = jest.fn();
|
|
145
|
+
const callback3 = jest.fn();
|
|
146
|
+
source.reloadTile({uid: 0} as any as WorkerTileParameters, callback1);
|
|
147
|
+
expect(parse).toHaveBeenCalledTimes(1);
|
|
148
|
+
|
|
149
|
+
source.loaded[0].status = 'parsing';
|
|
150
|
+
source.reloadTile({uid: 0} as any as WorkerTileParameters, callback2);
|
|
151
|
+
expect(parse).toHaveBeenCalledTimes(1);
|
|
152
|
+
|
|
153
|
+
parse.mock.calls[0][4]();
|
|
154
|
+
expect(parse).toHaveBeenCalledTimes(2);
|
|
155
|
+
expect(callback1).toHaveBeenCalledTimes(1);
|
|
156
|
+
expect(callback2).toHaveBeenCalledTimes(0);
|
|
157
|
+
expect(callback3).toHaveBeenCalledTimes(0);
|
|
158
|
+
|
|
159
|
+
source.reloadTile({uid: 0} as any as WorkerTileParameters, callback3);
|
|
160
|
+
expect(parse).toHaveBeenCalledTimes(2);
|
|
161
|
+
expect(callback1).toHaveBeenCalledTimes(1);
|
|
162
|
+
expect(callback2).toHaveBeenCalledTimes(0);
|
|
163
|
+
expect(callback3).toHaveBeenCalledTimes(0);
|
|
164
|
+
|
|
165
|
+
parse.mock.calls[1][4]();
|
|
166
|
+
expect(parse).toHaveBeenCalledTimes(3);
|
|
167
|
+
expect(callback1).toHaveBeenCalledTimes(1);
|
|
168
|
+
expect(callback2).toHaveBeenCalledTimes(1);
|
|
169
|
+
expect(callback3).toHaveBeenCalledTimes(0);
|
|
170
|
+
|
|
171
|
+
parse.mock.calls[2][4]();
|
|
172
|
+
expect(callback1).toHaveBeenCalledTimes(1);
|
|
173
|
+
expect(callback2).toHaveBeenCalledTimes(1);
|
|
174
|
+
expect(callback3).toHaveBeenCalledTimes(1);
|
|
175
|
+
|
|
176
|
+
});
|
|
177
|
+
|
|
178
|
+
test('VectorTileWorkerSource#reloadTile does not reparse tiles with no vectorTile data but does call callback', () => {
|
|
179
|
+
const source = new VectorTileWorkerSource(actor, new StyleLayerIndex(), []);
|
|
180
|
+
const parse = jest.fn();
|
|
181
|
+
|
|
182
|
+
source.loaded = {
|
|
183
|
+
'0': {
|
|
184
|
+
status: 'done',
|
|
185
|
+
parse
|
|
186
|
+
} as any as WorkerTile
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const callback = jest.fn();
|
|
190
|
+
|
|
191
|
+
source.reloadTile({uid: 0} as any as WorkerTileParameters, callback);
|
|
192
|
+
expect(parse).not.toHaveBeenCalled();
|
|
193
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
194
|
+
|
|
195
|
+
});
|
|
196
|
+
|
|
197
|
+
test('VectorTileWorkerSource provides resource timing information', done => {
|
|
198
|
+
const rawTileData = fs.readFileSync(path.join(__dirname, '/../../test/fixtures/mbsv5-6-18-23.vector.pbf'));
|
|
199
|
+
|
|
200
|
+
function loadVectorData(params, callback) {
|
|
201
|
+
return callback(null, {
|
|
202
|
+
vectorTile: new vt.VectorTile(new Protobuf(rawTileData)),
|
|
203
|
+
rawData: rawTileData,
|
|
204
|
+
cacheControl: null,
|
|
205
|
+
expires: null
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
const exampleResourceTiming = {
|
|
210
|
+
connectEnd: 473,
|
|
211
|
+
connectStart: 473,
|
|
212
|
+
decodedBodySize: 86494,
|
|
213
|
+
domainLookupEnd: 473,
|
|
214
|
+
domainLookupStart: 473,
|
|
215
|
+
duration: 341,
|
|
216
|
+
encodedBodySize: 52528,
|
|
217
|
+
entryType: 'resource',
|
|
218
|
+
fetchStart: 473.5,
|
|
219
|
+
initiatorType: 'xmlhttprequest',
|
|
220
|
+
name: 'http://localhost:2900/faketile.pbf',
|
|
221
|
+
nextHopProtocol: 'http/1.1',
|
|
222
|
+
redirectEnd: 0,
|
|
223
|
+
redirectStart: 0,
|
|
224
|
+
requestStart: 477,
|
|
225
|
+
responseEnd: 815,
|
|
226
|
+
responseStart: 672,
|
|
227
|
+
secureConnectionStart: 0
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
const layerIndex = new StyleLayerIndex([{
|
|
231
|
+
id: 'test',
|
|
232
|
+
source: 'source',
|
|
233
|
+
'source-layer': 'test',
|
|
234
|
+
type: 'fill'
|
|
235
|
+
}]);
|
|
236
|
+
|
|
237
|
+
const source = new VectorTileWorkerSource(actor, layerIndex, [], loadVectorData);
|
|
238
|
+
|
|
239
|
+
window.performance.getEntriesByName = jest.fn().mockReturnValue([ exampleResourceTiming ]);
|
|
240
|
+
|
|
241
|
+
source.loadTile({
|
|
242
|
+
source: 'source',
|
|
243
|
+
uid: 0,
|
|
244
|
+
tileID: {overscaledZ: 0, wrap: 0, canonical: {x: 0, y: 0, z: 0, w: 0}},
|
|
245
|
+
request: {url: 'http://localhost:2900/faketile.pbf', collectResourceTiming: true}
|
|
246
|
+
} as any as WorkerTileParameters, (err, res) => {
|
|
247
|
+
expect(err).toBeFalsy();
|
|
248
|
+
expect(res.resourceTiming[0]).toEqual(exampleResourceTiming);
|
|
249
|
+
done();
|
|
250
|
+
});
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
test('VectorTileWorkerSource provides resource timing information (fallback method)', done => {
|
|
254
|
+
const rawTileData = fs.readFileSync(path.join(__dirname, '/../../test/fixtures/mbsv5-6-18-23.vector.pbf'));
|
|
255
|
+
|
|
256
|
+
function loadVectorData(params, callback) {
|
|
257
|
+
return callback(null, {
|
|
258
|
+
vectorTile: new vt.VectorTile(new Protobuf(rawTileData)),
|
|
259
|
+
rawData: rawTileData,
|
|
260
|
+
cacheControl: null,
|
|
261
|
+
expires: null
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
const layerIndex = new StyleLayerIndex([{
|
|
266
|
+
id: 'test',
|
|
267
|
+
source: 'source',
|
|
268
|
+
'source-layer': 'test',
|
|
269
|
+
type: 'fill'
|
|
270
|
+
}]);
|
|
271
|
+
|
|
272
|
+
const source = new VectorTileWorkerSource(actor, layerIndex, [], loadVectorData);
|
|
273
|
+
|
|
274
|
+
const sampleMarks = [100, 350];
|
|
275
|
+
const marks = {};
|
|
276
|
+
const measures = {};
|
|
277
|
+
window.performance.getEntriesByName = jest.fn().mockImplementation(name => (measures[name] || []));
|
|
278
|
+
window.performance.mark = jest.fn().mockImplementation(name => {
|
|
279
|
+
marks[name] = sampleMarks.shift();
|
|
280
|
+
return null;
|
|
281
|
+
});
|
|
282
|
+
window.performance.measure = jest.fn().mockImplementation((name, start, end) => {
|
|
283
|
+
measures[name] = measures[name] || [];
|
|
284
|
+
measures[name].push({
|
|
285
|
+
duration: marks[end] - marks[start],
|
|
286
|
+
entryType: 'measure',
|
|
287
|
+
name,
|
|
288
|
+
startTime: marks[start]
|
|
289
|
+
});
|
|
290
|
+
return null;
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
source.loadTile({
|
|
294
|
+
source: 'source',
|
|
295
|
+
uid: 0,
|
|
296
|
+
tileID: {overscaledZ: 0, wrap: 0, canonical: {x: 0, y: 0, z: 0, w: 0}},
|
|
297
|
+
request: {url: 'http://localhost:2900/faketile.pbf', collectResourceTiming: true}
|
|
298
|
+
} as any as WorkerTileParameters, (err, res) => {
|
|
299
|
+
expect(err).toBeFalsy();
|
|
300
|
+
expect(res.resourceTiming[0]).toEqual(
|
|
301
|
+
{'duration': 250, 'entryType': 'measure', 'name': 'http://localhost:2900/faketile.pbf', 'startTime': 100}
|
|
302
|
+
);
|
|
303
|
+
done();
|
|
304
|
+
});
|
|
305
|
+
});
|
|
306
|
+
});
|
|
@@ -4,6 +4,7 @@ import {OverscaledTileID} from '../source/tile_id';
|
|
|
4
4
|
import StyleLayerIndex from '../style/style_layer_index';
|
|
5
5
|
import {WorkerTileParameters} from './worker_source';
|
|
6
6
|
import Actor from '../util/actor';
|
|
7
|
+
import {VectorTile} from '@mapbox/vector-tile';
|
|
7
8
|
|
|
8
9
|
function createWorkerTile() {
|
|
9
10
|
return new WorkerTile({
|
|
@@ -87,7 +88,7 @@ describe('worker tile', () => {
|
|
|
87
88
|
version: 1
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
};
|
|
91
|
+
} as any as VectorTile;
|
|
91
92
|
|
|
92
93
|
const spy = jest.spyOn(console, 'warn').mockImplementation(() => {});
|
|
93
94
|
|
package/src/style/query_utils.ts
CHANGED
package/src/style/style.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {getJSON, getReferrer, makeRequest, ResourceType} from '../util/ajax';
|
|
|
13
13
|
import browser from '../util/browser';
|
|
14
14
|
import Dispatcher from '../util/dispatcher';
|
|
15
15
|
import {validateStyle, emitValidationErrors as _emitValidationErrors} from './validate_style';
|
|
16
|
-
import {
|
|
16
|
+
import {getSourceType, setSourceType, Source} from '../source/source';
|
|
17
17
|
import type {SourceClass} from '../source/source';
|
|
18
18
|
import {queryRenderedFeatures, queryRenderedSymbols, querySourceFeatures} from '../source/query_features';
|
|
19
19
|
import SourceCache from '../source/source_cache';
|
|
@@ -6,7 +6,7 @@ import {getMaximumPaintValue, translateDistance, translate} from '../query_utils
|
|
|
6
6
|
import properties, {CircleLayoutPropsPossiblyEvaluated, CirclePaintPropsPossiblyEvaluated} from './circle_style_layer_properties';
|
|
7
7
|
import {Transitionable, Transitioning, Layout, PossiblyEvaluated} from '../properties';
|
|
8
8
|
import {mat4, vec4} from 'gl-matrix';
|
|
9
|
-
import Point from '
|
|
9
|
+
import Point from '@mapbox/point-geometry';
|
|
10
10
|
import type {FeatureState} from '../../style-spec/expression';
|
|
11
11
|
import type Transform from '../../geo/transform';
|
|
12
12
|
import type {Bucket, BucketParameters} from '../../data/bucket';
|
|
@@ -6,7 +6,7 @@ import {translateDistance, translate} from '../query_utils';
|
|
|
6
6
|
import properties, {FillExtrusionPaintPropsPossiblyEvaluated} from './fill_extrusion_style_layer_properties';
|
|
7
7
|
import {Transitionable, Transitioning, PossiblyEvaluated} from '../properties';
|
|
8
8
|
import {mat4, vec4} from 'gl-matrix';
|
|
9
|
-
import Point from '
|
|
9
|
+
import Point from '@mapbox/point-geometry';
|
|
10
10
|
import type {FeatureState} from '../../style-spec/expression';
|
|
11
11
|
import type {BucketParameters} from '../../data/bucket';
|
|
12
12
|
import type {FillExtrusionPaintProps} from './fill_extrusion_style_layer_properties';
|
|
@@ -8,7 +8,7 @@ import {Transitionable, Transitioning, Layout, PossiblyEvaluated} from '../prope
|
|
|
8
8
|
|
|
9
9
|
import type {FeatureState} from '../../style-spec/expression';
|
|
10
10
|
import type {BucketParameters} from '../../data/bucket';
|
|
11
|
-
import type Point from '
|
|
11
|
+
import type Point from '@mapbox/point-geometry';
|
|
12
12
|
import type {FillLayoutProps, FillPaintProps} from './fill_style_layer_properties';
|
|
13
13
|
import type EvaluationParameters from '../evaluation_parameters';
|
|
14
14
|
import type Transform from '../../geo/transform';
|
package/src/style/style_layer.ts
CHANGED
|
@@ -13,7 +13,7 @@ import {supportsPropertyExpression} from '../style-spec/util/properties';
|
|
|
13
13
|
|
|
14
14
|
import type {FeatureState} from '../style-spec/expression';
|
|
15
15
|
import type {Bucket} from '../data/bucket';
|
|
16
|
-
import type Point from '
|
|
16
|
+
import type Point from '@mapbox/point-geometry';
|
|
17
17
|
import type {FeatureFilter} from '../style-spec/feature_filter';
|
|
18
18
|
import type {TransitionParameters, PropertyValue} from './properties';
|
|
19
19
|
import EvaluationParameters from './evaluation_parameters';
|
|
@@ -32,21 +32,6 @@ import type {VectorTileFeature} from '@mapbox/vector-tile';
|
|
|
32
32
|
|
|
33
33
|
const TRANSITION_SUFFIX = '-transition';
|
|
34
34
|
|
|
35
|
-
// this interface is used to allow optional overload for this methods in the derived classes.
|
|
36
|
-
interface StyleLayer {
|
|
37
|
-
queryRadius?(bucket: Bucket): number;
|
|
38
|
-
queryIntersectsFeature?(
|
|
39
|
-
queryGeometry: Array<Point>,
|
|
40
|
-
feature: VectorTileFeature,
|
|
41
|
-
featureState: FeatureState,
|
|
42
|
-
geometry: Array<Array<Point>>,
|
|
43
|
-
zoom: number,
|
|
44
|
-
transform: Transform,
|
|
45
|
-
pixelsToTileUnits: number,
|
|
46
|
-
pixelPosMatrix: mat4
|
|
47
|
-
): boolean | number;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
35
|
abstract class StyleLayer extends Evented {
|
|
51
36
|
id: string;
|
|
52
37
|
metadata: unknown;
|
|
@@ -71,6 +56,18 @@ abstract class StyleLayer extends Evented {
|
|
|
71
56
|
readonly onAdd: ((map: Map) => void);
|
|
72
57
|
readonly onRemove: ((map: Map) => void);
|
|
73
58
|
|
|
59
|
+
queryRadius?(bucket: Bucket): number;
|
|
60
|
+
queryIntersectsFeature?(
|
|
61
|
+
queryGeometry: Array<Point>,
|
|
62
|
+
feature: VectorTileFeature,
|
|
63
|
+
featureState: FeatureState,
|
|
64
|
+
geometry: Array<Array<Point>>,
|
|
65
|
+
zoom: number,
|
|
66
|
+
transform: Transform,
|
|
67
|
+
pixelsToTileUnits: number,
|
|
68
|
+
pixelPosMatrix: mat4
|
|
69
|
+
): boolean | number;
|
|
70
|
+
|
|
74
71
|
constructor(layer: LayerSpecification | CustomLayerInterface, properties: Readonly<{
|
|
75
72
|
layout?: Properties<any>;
|
|
76
73
|
paint?: Properties<any>;
|
|
@@ -23,7 +23,7 @@ import type {Result} from '../util/result';
|
|
|
23
23
|
import type {InterpolationType} from './definitions/interpolate';
|
|
24
24
|
import type {PropertyValueSpecification} from '../types';
|
|
25
25
|
import type {FormattedSection} from './types/formatted';
|
|
26
|
-
import type Point from '
|
|
26
|
+
import type Point from '@mapbox/point-geometry';
|
|
27
27
|
import type {CanonicalTileID} from '../../source/tile_id';
|
|
28
28
|
|
|
29
29
|
export type Feature = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {default as createFilter, isExpressionFilter} from '.';
|
|
2
2
|
|
|
3
3
|
import convertFilter from './convert';
|
|
4
|
-
import Point from '
|
|
4
|
+
import Point from '@mapbox/point-geometry';
|
|
5
5
|
import MercatorCoordinate from '../../geo/mercator_coordinate';
|
|
6
6
|
import EXTENT from '../../data/extent';
|
|
7
7
|
import {CanonicalTileID} from '../../source/tile_id';
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import migrate from './migrate';
|
|
2
|
+
import * as spec from './style-spec';
|
|
3
|
+
import v8 from './reference/v8.json';
|
|
4
|
+
import validate from './validate_style';
|
|
5
|
+
|
|
6
|
+
describe('migrate', () => {
|
|
7
|
+
test('does not migrate from version 5', () => {
|
|
8
|
+
expect(() => {
|
|
9
|
+
migrate({version: 5, layers: []});
|
|
10
|
+
}).toThrow(new Error('Cannot migrate from 5'));
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
test('does not migrate from version 6', () => {
|
|
14
|
+
expect(() => {
|
|
15
|
+
migrate({version: 6, layers: []});
|
|
16
|
+
}).toThrow(new Error('Cannot migrate from 6'));
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
test('migrates to latest version from version 7', () => {
|
|
20
|
+
expect(migrate({version: 7, layers: []}).version).toEqual(spec.latest.$version);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
test('converts token strings to expressions', () => {
|
|
24
|
+
const migrated = migrate({
|
|
25
|
+
version: 8,
|
|
26
|
+
layers: [{
|
|
27
|
+
id: '1',
|
|
28
|
+
type: 'symbol',
|
|
29
|
+
layout: {'text-field': 'a{x}', 'icon-image': '{y}'}
|
|
30
|
+
}]
|
|
31
|
+
});
|
|
32
|
+
expect(migrated.layers[0].layout['text-field']).toEqual(['concat', 'a', ['get', 'x']]);
|
|
33
|
+
expect(migrated.layers[0].layout['icon-image']).toEqual(['to-string', ['get', 'y']]);
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
test('converts stop functions to expressions', () => {
|
|
37
|
+
const migrated = migrate({
|
|
38
|
+
version: 8,
|
|
39
|
+
layers: [{
|
|
40
|
+
id: '1',
|
|
41
|
+
type: 'background',
|
|
42
|
+
paint: {
|
|
43
|
+
'background-opacity': {
|
|
44
|
+
base: 1.0,
|
|
45
|
+
stops: [[0, 1], [10, 0.72]]
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}, {
|
|
49
|
+
id: '2',
|
|
50
|
+
type: 'background',
|
|
51
|
+
paint: {
|
|
52
|
+
'background-opacity': {
|
|
53
|
+
base: 1.0,
|
|
54
|
+
stops: [[0, [1, 2]], [10, [0.72, 0.98]]]
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}]
|
|
58
|
+
});
|
|
59
|
+
expect(migrated.layers[0].paint['background-opacity']).toEqual([
|
|
60
|
+
'interpolate',
|
|
61
|
+
['linear'],
|
|
62
|
+
['zoom'],
|
|
63
|
+
0,
|
|
64
|
+
1,
|
|
65
|
+
10,
|
|
66
|
+
0.72
|
|
67
|
+
]);
|
|
68
|
+
expect(migrated.layers[1].paint['background-opacity']).toEqual([
|
|
69
|
+
'interpolate',
|
|
70
|
+
['linear'],
|
|
71
|
+
['zoom'],
|
|
72
|
+
0,
|
|
73
|
+
['literal', [1, 2]],
|
|
74
|
+
10,
|
|
75
|
+
['literal', [0.72, 0.98]]
|
|
76
|
+
]);
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('converts categorical function on resolvedImage type to valid expression', () => {
|
|
80
|
+
const migrated = migrate({
|
|
81
|
+
version: 8,
|
|
82
|
+
sources: {
|
|
83
|
+
streets: {
|
|
84
|
+
url: 'mapbox://mapbox.streets',
|
|
85
|
+
type: 'vector'
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
layers: [{
|
|
89
|
+
id: '1',
|
|
90
|
+
source: 'streets',
|
|
91
|
+
'source-layer': 'labels',
|
|
92
|
+
type: 'symbol',
|
|
93
|
+
layout: {
|
|
94
|
+
'icon-image': {
|
|
95
|
+
base: 1,
|
|
96
|
+
type: 'categorical',
|
|
97
|
+
property: 'type',
|
|
98
|
+
stops: [['park', 'some-icon']]
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}]
|
|
102
|
+
});
|
|
103
|
+
expect(migrated.layers[0].layout['icon-image']).toEqual([
|
|
104
|
+
'match',
|
|
105
|
+
['get', 'type' ],
|
|
106
|
+
'park',
|
|
107
|
+
'some-icon',
|
|
108
|
+
''
|
|
109
|
+
]);
|
|
110
|
+
expect(validate(migrated, v8)).toEqual([]);
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import glob from 'glob';
|
|
2
|
+
import fs from 'fs';
|
|
3
|
+
import path from 'path';
|
|
4
|
+
import validate from '../style-spec/validate_style';
|
|
5
|
+
import reference from './reference/latest';
|
|
6
|
+
|
|
7
|
+
const UPDATE = !!process.env.UPDATE;
|
|
8
|
+
|
|
9
|
+
describe('validate_spec', () => {
|
|
10
|
+
glob.sync('test/unit/style-spec/fixture/*.input.json').forEach((file) => {
|
|
11
|
+
test(path.basename(file), () => {
|
|
12
|
+
const outputfile = file.replace('.input', '.output');
|
|
13
|
+
const style = fs.readFileSync(file);
|
|
14
|
+
const result = validate(style);
|
|
15
|
+
if (UPDATE) fs.writeFileSync(outputfile, JSON.stringify(result, null, 2));
|
|
16
|
+
const expectedOutput = JSON.parse(fs.readFileSync(outputfile).toString());
|
|
17
|
+
expect(result).toEqual(expectedOutput);
|
|
18
|
+
});
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
test('errors from validate do not contain line numbers', () => {
|
|
22
|
+
const fixtures = glob.sync('test/unit/style-spec/fixture/*.input.json');
|
|
23
|
+
const style = JSON.parse(fs.readFileSync(fixtures[0]).toString());
|
|
24
|
+
|
|
25
|
+
const result = validate(style, reference);
|
|
26
|
+
expect(result[0].line).toBeUndefined();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
});
|
package/src/symbol/anchor.ts
CHANGED