maplibre-gl 2.1.0 → 2.1.4
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/{banner.js → banner.ts} +1 -1
- package/build/generate-query-test-fixtures.ts +123 -0
- package/build/generate-shaders.ts +35 -0
- package/build/generate-struct-arrays.ts +7 -7
- package/build/generate-style-code.ts +8 -8
- package/build/generate-style-spec.ts +5 -4
- package/build/generate-typings.ts +16 -0
- package/build/readme.md +8 -18
- package/build/release-notes.js +9 -13
- package/build/{rollup_plugin_minify_style_spec.js → rollup_plugin_minify_style_spec.ts} +4 -3
- package/build/{rollup_plugins.js → rollup_plugins.ts} +12 -26
- package/dist/maplibre-gl-dev.js +54885 -0
- package/dist/maplibre-gl.css +1 -1
- package/dist/maplibre-gl.d.ts +1537 -1011
- package/dist/maplibre-gl.js +3 -3
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +83 -107
- package/postinstall.js +5 -0
- package/src/css/maplibre-gl.css +28 -28
- package/src/data/{array_types.ts → array_types.g.ts} +0 -0
- package/src/data/bucket/circle_bucket.ts +1 -1
- package/src/data/bucket/fill_bucket.test.ts +1 -1
- package/src/data/bucket/fill_bucket.ts +4 -4
- package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
- package/src/data/bucket/line_bucket.test.ts +1 -1
- package/src/data/bucket/line_bucket.ts +6 -6
- package/src/data/bucket/symbol_bucket.test.ts +16 -16
- package/src/data/bucket/symbol_bucket.ts +53 -53
- package/src/data/bucket.ts +43 -43
- package/src/data/dem_data.ts +12 -12
- package/src/data/evaluation_feature.ts +10 -10
- package/src/data/feature_index.ts +37 -37
- package/src/data/feature_position_map.ts +5 -5
- package/src/data/index_array_type.ts +1 -1
- package/src/data/load_geometry.test.ts +1 -1
- package/src/data/program_configuration.ts +46 -46
- package/src/data/segment.ts +14 -14
- package/src/geo/edge_insets.ts +2 -2
- package/src/geo/lng_lat.ts +4 -4
- package/src/geo/lng_lat_bounds.ts +35 -35
- package/src/geo/mercator_coordinate.ts +5 -5
- package/src/geo/transform.test.ts +1 -1
- package/src/geo/transform.ts +14 -14
- package/src/gl/context.ts +3 -3
- package/src/gl/types.ts +19 -19
- package/src/gl/value.ts +6 -6
- package/src/gl/vertex_buffer.test.ts +1 -1
- package/src/index.ts +24 -9
- package/src/render/draw_circle.ts +8 -8
- package/src/render/draw_collision_debug.ts +5 -5
- package/src/render/draw_line.ts +4 -4
- package/src/render/draw_symbol.ts +21 -21
- package/src/render/glyph_atlas.ts +12 -12
- package/src/render/glyph_manager.test.ts +10 -21
- package/src/render/glyph_manager.ts +33 -32
- package/src/render/image_manager.ts +4 -4
- package/src/render/painter.ts +11 -11
- package/src/render/program/background_program.ts +29 -29
- package/src/render/program/circle_program.ts +10 -10
- package/src/render/program/clipping_mask_program.ts +1 -1
- package/src/render/program/collision_program.ts +9 -9
- package/src/render/program/debug_program.ts +4 -4
- package/src/render/program/fill_extrusion_program.ts +31 -31
- package/src/render/program/fill_program.ts +29 -29
- package/src/render/program/heatmap_program.ts +12 -12
- package/src/render/program/hillshade_program.ts +12 -12
- package/src/render/program/line_program.ts +38 -38
- package/src/render/program/pattern.ts +28 -28
- package/src/render/program/raster_program.ts +21 -21
- package/src/render/program/symbol_program.ts +96 -96
- package/src/render/program.ts +25 -25
- package/src/render/texture.ts +9 -9
- package/src/render/uniform_binding.ts +1 -1
- package/src/render/vertex_array_object.ts +13 -13
- package/src/shaders/_prelude.fragment.glsl.g.ts +2 -0
- package/src/shaders/_prelude.vertex.glsl.g.ts +2 -0
- package/src/shaders/background.fragment.glsl.g.ts +2 -0
- package/src/shaders/background.vertex.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/background_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.fragment.glsl.g.ts +2 -0
- package/src/shaders/clipping_mask.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_box.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_box.vertex.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.fragment.glsl.g.ts +2 -0
- package/src/shaders/collision_circle.vertex.glsl.g.ts +2 -0
- package/src/shaders/debug.fragment.glsl.g.ts +2 -0
- package/src/shaders/debug.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/fill_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap.vertex.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.fragment.glsl.g.ts +2 -0
- package/src/shaders/heatmap_texture.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade.vertex.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +2 -0
- package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +2 -0
- package/src/shaders/line.fragment.glsl.g.ts +2 -0
- package/src/shaders/line.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_gradient.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_pattern.vertex.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/line_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/raster.fragment.glsl.g.ts +2 -0
- package/src/shaders/raster.vertex.glsl.g.ts +2 -0
- package/src/shaders/shaders.ts +52 -55
- package/src/shaders/symbol_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_icon.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_sdf.vertex.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +2 -0
- package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +2 -0
- package/src/source/canvas_source.test.ts +11 -12
- package/src/source/canvas_source.ts +4 -4
- package/src/source/geojson_worker_source.ts +23 -23
- package/src/source/geojson_wrapper.ts +8 -8
- package/src/source/image_source.test.ts +2 -2
- package/src/source/image_source.ts +6 -6
- package/src/source/pixels_to_tile_units.ts +6 -6
- package/src/source/query_features.ts +20 -20
- package/src/source/raster_dem_tile_source.test.ts +2 -2
- package/src/source/raster_tile_source.test.ts +2 -2
- package/src/source/rtl_text_plugin.ts +10 -10
- package/src/source/source.ts +29 -29
- package/src/source/source_cache.test.ts +32 -0
- package/src/source/source_cache.ts +7 -5
- package/src/source/source_state.ts +1 -1
- package/src/source/tile.test.ts +3 -3
- package/src/source/tile.ts +15 -15
- package/src/source/tile_cache.test.ts +6 -4
- package/src/source/tile_cache.ts +6 -6
- package/src/source/tile_id.test.ts +0 -1
- package/src/source/vector_tile_source.test.ts +16 -5
- package/src/source/vector_tile_source.ts +2 -3
- package/src/source/vector_tile_worker_source.test.ts +4 -4
- package/src/source/vector_tile_worker_source.ts +5 -5
- package/src/source/worker.test.ts +1 -1
- package/src/source/worker.ts +22 -22
- package/src/source/worker_source.ts +56 -56
- package/src/source/worker_tile.ts +4 -4
- package/src/style/evaluation_parameters.ts +3 -3
- package/src/style/format_section_override.test.ts +1 -1
- package/src/style/light.ts +10 -10
- package/src/style/load_glyph_range.test.ts +3 -5
- package/src/style/load_glyph_range.ts +6 -6
- package/src/style/load_sprite.ts +4 -4
- package/src/style/pauseable_placement.ts +1 -1
- package/src/style/properties.ts +69 -69
- package/src/style/query_utils.ts +7 -7
- package/src/style/style.test.ts +22 -15
- package/src/style/style.ts +29 -29
- package/src/style/style_glyph.ts +8 -8
- package/src/style/style_image.ts +58 -58
- package/src/style/style_layer/background_style_layer.ts +2 -2
- package/src/style/style_layer/{background_style_layer_properties.ts → background_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/circle_style_layer.ts +10 -10
- package/src/style/style_layer/{circle_style_layer_properties.ts → circle_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/custom_style_layer.ts +17 -17
- package/src/style/style_layer/fill_extrusion_style_layer.ts +10 -10
- package/src/style/style_layer/{fill_extrusion_style_layer_properties.ts → fill_extrusion_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/fill_style_layer.ts +9 -9
- package/src/style/style_layer/{fill_style_layer_properties.ts → fill_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/heatmap_style_layer.ts +2 -2
- package/src/style/style_layer/{heatmap_style_layer_properties.ts → heatmap_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/hillshade_style_layer.ts +2 -2
- package/src/style/style_layer/{hillshade_style_layer_properties.ts → hillshade_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/line_style_layer.ts +9 -9
- package/src/style/style_layer/{line_style_layer_properties.ts → line_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/raster_style_layer.ts +2 -2
- package/src/style/style_layer/{raster_style_layer_properties.ts → raster_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer/symbol_style_layer.ts +7 -7
- package/src/style/style_layer/{symbol_style_layer_properties.ts → symbol_style_layer_properties.g.ts} +0 -0
- package/src/style/style_layer.ts +10 -10
- package/src/style/style_layer_index.ts +3 -3
- package/src/style/validate_style.ts +15 -15
- package/src/style-spec/error/validation_error.ts +1 -1
- package/src/style-spec/expression/compound_expression.ts +3 -3
- package/src/style-spec/expression/definitions/format.ts +11 -11
- package/src/style-spec/expression/definitions/interpolate.ts +5 -5
- package/src/style-spec/expression/definitions/match.ts +2 -2
- package/src/style-spec/expression/definitions/number_format.ts +11 -11
- package/src/style-spec/expression/expression.ts +8 -8
- package/src/style-spec/expression/index.ts +97 -97
- package/src/style-spec/expression/parsing_context.ts +11 -11
- package/src/style-spec/expression/types/collator.ts +9 -9
- package/src/style-spec/expression/types/resolved_image.ts +2 -2
- package/src/style-spec/expression/types.ts +14 -14
- package/src/style-spec/expression/values.ts +1 -1
- package/src/style-spec/feature_filter/index.ts +66 -66
- package/src/style-spec/function/convert.ts +3 -3
- package/src/style-spec/style-spec.ts +44 -44
- package/src/style-spec/util/color_spaces.ts +8 -8
- package/src/style-spec/util/result.ts +4 -4
- package/src/style-spec/validate/validate_filter.ts +58 -58
- package/src/style-spec/validate/validate_source.ts +63 -63
- package/src/style-spec/visit.ts +11 -11
- package/src/symbol/collision_feature.test.ts +1 -1
- package/src/symbol/collision_feature.ts +10 -10
- package/src/symbol/collision_index.ts +26 -26
- package/src/symbol/cross_tile_symbol_index.ts +17 -17
- package/src/symbol/get_anchors.ts +16 -16
- package/src/symbol/grid_index.ts +7 -7
- package/src/symbol/placement.ts +72 -72
- package/src/symbol/projection.ts +30 -30
- package/src/symbol/quads.ts +30 -30
- package/src/symbol/shaping.ts +160 -160
- package/src/symbol/symbol_layout.ts +119 -119
- package/src/symbol/symbol_size.ts +29 -29
- package/src/symbol/symbol_style_layer.test.ts +1 -1
- package/src/types/cancelable.ts +1 -1
- package/src/types/tilejson.ts +13 -13
- package/src/ui/anchor.ts +1 -1
- package/src/ui/camera.test.ts +9 -9
- package/src/ui/camera.ts +18 -18
- package/src/ui/control/attribution_control.test.ts +51 -16
- package/src/ui/control/attribution_control.ts +35 -16
- package/src/ui/control/control.ts +40 -40
- package/src/ui/control/fullscreen_control.ts +1 -1
- package/src/ui/control/geolocate_control.test.ts +1 -1
- package/src/ui/control/geolocate_control.ts +102 -102
- package/src/ui/control/logo_control.test.ts +5 -4
- package/src/ui/control/navigation_control.ts +3 -3
- package/src/ui/control/scale_control.test.ts +2 -2
- package/src/ui/control/scale_control.ts +5 -5
- package/src/ui/events.ts +289 -200
- package/src/ui/handler/box_zoom.test.ts +1 -1
- package/src/ui/handler/box_zoom.ts +1 -1
- package/src/ui/handler/dblclick_zoom.test.ts +1 -1
- package/src/ui/handler/drag_pan.test.ts +1 -1
- package/src/ui/handler/drag_rotate.test.ts +1 -1
- package/src/ui/handler/keyboard.test.ts +1 -1
- package/src/ui/handler/keyboard.ts +51 -51
- package/src/ui/handler/map_event.test.ts +1 -1
- package/src/ui/handler/map_event.ts +1 -1
- package/src/ui/handler/mouse.ts +1 -1
- package/src/ui/handler/mouse_rotate.test.ts +1 -1
- package/src/ui/handler/scroll_zoom.test.ts +3 -2
- package/src/ui/handler/scroll_zoom.ts +9 -9
- package/src/ui/handler/shim/drag_pan.ts +4 -4
- package/src/ui/handler/shim/drag_rotate.ts +1 -1
- package/src/ui/handler/shim/touch_zoom_rotate.ts +1 -1
- package/src/ui/handler/tap_recognizer.ts +4 -4
- package/src/ui/handler/touch_pan.ts +2 -2
- package/src/ui/handler/touch_zoom_rotate.test.ts +1 -1
- package/src/ui/handler/touch_zoom_rotate.ts +1 -1
- package/src/ui/handler_inertia.ts +6 -6
- package/src/ui/handler_manager.ts +44 -44
- package/src/ui/map/isMoving.test.ts +1 -1
- package/src/ui/map/isRotating.test.ts +1 -1
- package/src/ui/map/isZooming.test.ts +1 -1
- package/src/ui/map.test.ts +26 -14
- package/src/ui/map.ts +107 -102
- package/src/ui/map_events.test.ts +1 -1
- package/src/ui/marker.test.ts +12 -12
- package/src/ui/marker.ts +37 -37
- package/src/ui/popup.test.ts +7 -7
- package/src/ui/popup.ts +9 -9
- package/src/util/actor.test.ts +41 -10
- package/src/util/actor.ts +8 -8
- package/src/util/ajax.test.ts +29 -21
- package/src/util/ajax.ts +51 -30
- package/src/util/browser.ts +1 -1
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/color_ramp.ts +5 -5
- package/src/util/config.ts +2 -2
- package/src/util/dispatcher.ts +1 -1
- package/src/util/dom.ts +2 -2
- package/src/util/evented.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +3 -3
- package/src/util/image.ts +5 -5
- package/src/util/performance.ts +7 -7
- package/src/util/request_manager.ts +4 -4
- package/src/util/resolve_tokens.ts +4 -4
- package/src/util/struct_array.test.ts +1 -1
- package/src/util/struct_array.ts +15 -15
- package/src/util/task_queue.ts +3 -3
- package/src/util/tile_request_cache.ts +3 -3
- package/src/util/transferable_grid_index.ts +4 -4
- package/src/util/util.ts +8 -8
- package/src/util/web_worker.ts +4 -68
- package/src/util/web_worker_transfer.test.ts +3 -0
- package/src/util/web_worker_transfer.ts +21 -17
- package/src/util/worker_pool.ts +1 -1
- package/build/.eslintrc +0 -21
- package/build/glsl_to_js.js +0 -12
- package/build/post-ts-build.js +0 -43
- package/build/release-notes.md.ejs +0 -8
- package/build/test/build-tape.js +0 -17
- package/build/web_worker_replacement.js +0 -5
- package/dist/package.json +0 -1
- package/src/style-spec/validate_spec.test.ts +0 -29
- package/src/symbol/shaping.test.ts +0 -392
- package/src/types/glsl.d.ts +0 -4
package/src/util/actor.test.ts
CHANGED
|
@@ -1,15 +1,42 @@
|
|
|
1
1
|
import Actor from './actor';
|
|
2
2
|
import workerFactory from './web_worker';
|
|
3
|
+
import {MessageBus} from '../../test/unit/lib/web_worker_mock';
|
|
4
|
+
|
|
5
|
+
const originalWorker = global.Worker;
|
|
6
|
+
|
|
7
|
+
function setTestWorker(MockWorker: { new(...args: any): any}) {
|
|
8
|
+
(global as any).Worker = function Worker(_: string) {
|
|
9
|
+
const parentListeners = [];
|
|
10
|
+
const workerListeners = [];
|
|
11
|
+
const parentBus = new MessageBus(workerListeners, parentListeners);
|
|
12
|
+
const workerBus = new MessageBus(parentListeners, workerListeners);
|
|
13
|
+
|
|
14
|
+
parentBus.target = workerBus;
|
|
15
|
+
workerBus.target = parentBus;
|
|
16
|
+
|
|
17
|
+
new MockWorker(workerBus);
|
|
18
|
+
|
|
19
|
+
return parentBus;
|
|
20
|
+
};
|
|
21
|
+
}
|
|
3
22
|
|
|
4
23
|
describe('Actor', () => {
|
|
24
|
+
afterAll(() => {
|
|
25
|
+
global.Worker = originalWorker;
|
|
26
|
+
});
|
|
27
|
+
|
|
5
28
|
test('forwards responses to correct callback', done => {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
29
|
+
setTestWorker(class MockWorker {
|
|
30
|
+
self: any;
|
|
31
|
+
actor: Actor;
|
|
32
|
+
constructor(self) {
|
|
33
|
+
this.self = self;
|
|
34
|
+
this.actor = new Actor(self, this);
|
|
35
|
+
}
|
|
36
|
+
test(mapId, params, callback) {
|
|
10
37
|
setTimeout(callback, 0, null, params);
|
|
11
|
-
}
|
|
12
|
-
}
|
|
38
|
+
}
|
|
39
|
+
});
|
|
13
40
|
|
|
14
41
|
const worker = workerFactory();
|
|
15
42
|
|
|
@@ -38,10 +65,14 @@ describe('Actor', () => {
|
|
|
38
65
|
test('targets worker-initiated messages to correct map instance', done => {
|
|
39
66
|
let workerActor;
|
|
40
67
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
68
|
+
setTestWorker(class MockWorker {
|
|
69
|
+
self: any;
|
|
70
|
+
actor: Actor;
|
|
71
|
+
constructor(self) {
|
|
72
|
+
this.self = self;
|
|
73
|
+
this.actor = workerActor = new Actor(self, this);
|
|
74
|
+
}
|
|
75
|
+
});
|
|
45
76
|
|
|
46
77
|
const worker = workerFactory();
|
|
47
78
|
|
package/src/util/actor.ts
CHANGED
|
@@ -21,15 +21,15 @@ class Actor {
|
|
|
21
21
|
parent: any;
|
|
22
22
|
mapId: number;
|
|
23
23
|
callbacks: {
|
|
24
|
-
|
|
24
|
+
number: any;
|
|
25
25
|
};
|
|
26
26
|
name: string;
|
|
27
27
|
tasks: {
|
|
28
|
-
|
|
28
|
+
number: any;
|
|
29
29
|
};
|
|
30
30
|
taskQueue: Array<number>;
|
|
31
31
|
cancelCallbacks: {
|
|
32
|
-
|
|
32
|
+
number: Cancelable;
|
|
33
33
|
};
|
|
34
34
|
invoker: ThrottledInvoker;
|
|
35
35
|
globalScope: any;
|
|
@@ -57,11 +57,11 @@ class Actor {
|
|
|
57
57
|
* @private
|
|
58
58
|
*/
|
|
59
59
|
send(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
60
|
+
type: string,
|
|
61
|
+
data: unknown,
|
|
62
|
+
callback?: Function | null,
|
|
63
|
+
targetMapId?: string | null,
|
|
64
|
+
mustQueue: boolean = false
|
|
65
65
|
): Cancelable {
|
|
66
66
|
// We're using a string ID instead of numbers because they are being used as object keys
|
|
67
67
|
// anyway, and thus stringified implicitly. We use random IDs because an actor may receive
|
package/src/util/ajax.test.ts
CHANGED
|
@@ -3,15 +3,25 @@ import {
|
|
|
3
3
|
getJSON,
|
|
4
4
|
postData,
|
|
5
5
|
getImage,
|
|
6
|
-
resetImageRequestQueue
|
|
6
|
+
resetImageRequestQueue,
|
|
7
|
+
AJAXError
|
|
7
8
|
} from './ajax';
|
|
8
9
|
import config from './config';
|
|
9
10
|
import webpSupported from './webp_supported';
|
|
10
|
-
import {fakeServer,
|
|
11
|
+
import {fakeServer, FakeServer} from 'nise';
|
|
11
12
|
import {stubAjaxGetImage} from './test/util';
|
|
12
13
|
|
|
14
|
+
function readAsText(blob) {
|
|
15
|
+
return new Promise((resolve, reject) => {
|
|
16
|
+
const fileReader = new FileReader();
|
|
17
|
+
fileReader.onload = () => resolve(fileReader.result);
|
|
18
|
+
fileReader.onerror = () => reject(fileReader.error);
|
|
19
|
+
fileReader.readAsText(blob);
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
|
|
13
23
|
describe('ajax', () => {
|
|
14
|
-
let server:
|
|
24
|
+
let server: FakeServer;
|
|
15
25
|
beforeEach(() => {
|
|
16
26
|
global.fetch = null;
|
|
17
27
|
server = fakeServer.create();
|
|
@@ -22,10 +32,15 @@ describe('ajax', () => {
|
|
|
22
32
|
|
|
23
33
|
test('getArrayBuffer, 404', done => {
|
|
24
34
|
server.respondWith(request => {
|
|
25
|
-
request.respond(404, undefined,
|
|
35
|
+
request.respond(404, undefined, '404 Not Found');
|
|
26
36
|
});
|
|
27
|
-
getArrayBuffer({url:''}, (error) => {
|
|
28
|
-
|
|
37
|
+
getArrayBuffer({url:'http://example.com/test.bin'}, async (error) => {
|
|
38
|
+
const ajaxError = error as AJAXError;
|
|
39
|
+
const body = await readAsText(ajaxError.body);
|
|
40
|
+
expect(ajaxError.status).toBe(404);
|
|
41
|
+
expect(ajaxError.statusText).toBe('Not Found');
|
|
42
|
+
expect(ajaxError.url).toBe('http://example.com/test.bin');
|
|
43
|
+
expect(body).toBe('404 Not Found');
|
|
29
44
|
done();
|
|
30
45
|
});
|
|
31
46
|
server.respond();
|
|
@@ -56,22 +71,15 @@ describe('ajax', () => {
|
|
|
56
71
|
|
|
57
72
|
test('getJSON, 404', done => {
|
|
58
73
|
server.respondWith(request => {
|
|
59
|
-
request.respond(404, undefined,
|
|
60
|
-
});
|
|
61
|
-
getJSON({url:''}, (error) => {
|
|
62
|
-
expect((error as any).status).toBe(404);
|
|
63
|
-
done();
|
|
74
|
+
request.respond(404, undefined, '404 Not Found');
|
|
64
75
|
});
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
getJSON({url:''}, (error) => {
|
|
73
|
-
expect((error as any).status).toBe(401);
|
|
74
|
-
expect(error.message).toBe('Unauthorized');
|
|
76
|
+
getJSON({url:'http://example.com/test.json'}, async (error) => {
|
|
77
|
+
const ajaxError = error as AJAXError;
|
|
78
|
+
const body = await readAsText(ajaxError.body);
|
|
79
|
+
expect(ajaxError.status).toBe(404);
|
|
80
|
+
expect(ajaxError.statusText).toBe('Not Found');
|
|
81
|
+
expect(ajaxError.url).toBe('http://example.com/test.json');
|
|
82
|
+
expect(body).toBe('404 Not Found');
|
|
75
83
|
done();
|
|
76
84
|
});
|
|
77
85
|
server.respond();
|
package/src/util/ajax.ts
CHANGED
|
@@ -64,37 +64,57 @@ if (typeof Object.freeze == 'function') {
|
|
|
64
64
|
*
|
|
65
65
|
*/
|
|
66
66
|
export type RequestParameters = {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
67
|
+
url: string;
|
|
68
|
+
headers?: any;
|
|
69
|
+
method?: 'GET' | 'POST' | 'PUT';
|
|
70
|
+
body?: string;
|
|
71
|
+
type?: 'string' | 'json' | 'arrayBuffer';
|
|
72
|
+
credentials?: 'same-origin' | 'include';
|
|
73
|
+
collectResourceTiming?: boolean;
|
|
74
74
|
};
|
|
75
75
|
|
|
76
76
|
export type ResponseCallback<T> = (
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
77
|
+
error?: Error | null,
|
|
78
|
+
data?: T | null,
|
|
79
|
+
cacheControl?: string | null,
|
|
80
|
+
expires?: string | null
|
|
81
81
|
) => void;
|
|
82
82
|
|
|
83
|
-
|
|
83
|
+
/**
|
|
84
|
+
* An error thrown when a HTTP request results in an error response.
|
|
85
|
+
* @extends Error
|
|
86
|
+
* @param {number} status The response's HTTP status code.
|
|
87
|
+
* @param {string} statusText The response's HTTP status text.
|
|
88
|
+
* @param {string} url The request's URL.
|
|
89
|
+
* @param {Blob} body The response's body.
|
|
90
|
+
*/
|
|
91
|
+
export class AJAXError extends Error {
|
|
92
|
+
/**
|
|
93
|
+
* The response's HTTP status code.
|
|
94
|
+
*/
|
|
84
95
|
status: number;
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The response's HTTP status text.
|
|
99
|
+
*/
|
|
100
|
+
statusText: string;
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* The request's URL.
|
|
104
|
+
*/
|
|
85
105
|
url: string;
|
|
86
|
-
constructor(message: string, status: number, url: string) {
|
|
87
|
-
super(message);
|
|
88
|
-
this.status = status;
|
|
89
|
-
this.url = url;
|
|
90
106
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
107
|
+
/**
|
|
108
|
+
* The response's body.
|
|
109
|
+
*/
|
|
110
|
+
body: Blob;
|
|
95
111
|
|
|
96
|
-
|
|
97
|
-
|
|
112
|
+
constructor(status: number, statusText: string, url: string, body: Blob) {
|
|
113
|
+
super(`AJAXError: ${statusText} (${status}): ${url}`);
|
|
114
|
+
this.status = status;
|
|
115
|
+
this.statusText = statusText;
|
|
116
|
+
this.url = url;
|
|
117
|
+
this.body = body;
|
|
98
118
|
}
|
|
99
119
|
}
|
|
100
120
|
|
|
@@ -159,7 +179,7 @@ function makeFetchRequest(requestParameters: RequestParameters, callback: Respon
|
|
|
159
179
|
return finishRequest(response, cacheableResponse, requestTime);
|
|
160
180
|
|
|
161
181
|
} else {
|
|
162
|
-
return callback(new AJAXError(response.
|
|
182
|
+
return response.blob().then(body => callback(new AJAXError(response.status, response.statusText, requestParameters.url, body)));
|
|
163
183
|
}
|
|
164
184
|
}).catch(error => {
|
|
165
185
|
if (error.code === 20) {
|
|
@@ -173,8 +193,8 @@ function makeFetchRequest(requestParameters: RequestParameters, callback: Respon
|
|
|
173
193
|
const finishRequest = (response, cacheableResponse?, requestTime?) => {
|
|
174
194
|
(
|
|
175
195
|
requestParameters.type === 'arrayBuffer' ? response.arrayBuffer() :
|
|
176
|
-
|
|
177
|
-
|
|
196
|
+
requestParameters.type === 'json' ? response.json() :
|
|
197
|
+
response.text()
|
|
178
198
|
).then(result => {
|
|
179
199
|
if (aborted) return;
|
|
180
200
|
if (cacheableResponse && requestTime) {
|
|
@@ -235,7 +255,8 @@ function makeXMLHttpRequest(requestParameters: RequestParameters, callback: Resp
|
|
|
235
255
|
}
|
|
236
256
|
callback(null, data, xhr.getResponseHeader('Cache-Control'), xhr.getResponseHeader('Expires'));
|
|
237
257
|
} else {
|
|
238
|
-
|
|
258
|
+
const body = new Blob([xhr.response], {type: xhr.getResponseHeader('Content-Type')});
|
|
259
|
+
callback(new AJAXError(xhr.status, xhr.statusText, requestParameters.url, body));
|
|
239
260
|
}
|
|
240
261
|
};
|
|
241
262
|
xhr.send(requestParameters.body);
|
|
@@ -277,8 +298,8 @@ export const getJSON = function(requestParameters: RequestParameters, callback:
|
|
|
277
298
|
};
|
|
278
299
|
|
|
279
300
|
export const getArrayBuffer = function(
|
|
280
|
-
|
|
281
|
-
|
|
301
|
+
requestParameters: RequestParameters,
|
|
302
|
+
callback: ResponseCallback<ArrayBuffer>
|
|
282
303
|
): Cancelable {
|
|
283
304
|
return makeRequest(extend(requestParameters, {type: 'arrayBuffer'}), callback);
|
|
284
305
|
};
|
|
@@ -339,8 +360,8 @@ export const resetImageRequestQueue = () => {
|
|
|
339
360
|
resetImageRequestQueue();
|
|
340
361
|
|
|
341
362
|
export const getImage = function(
|
|
342
|
-
|
|
343
|
-
|
|
363
|
+
requestParameters: RequestParameters,
|
|
364
|
+
callback: Callback<HTMLImageElement | ImageBitmap>
|
|
344
365
|
): Cancelable {
|
|
345
366
|
if (webpSupported.supported) {
|
|
346
367
|
if (!requestParameters.headers) {
|
package/src/util/browser.ts
CHANGED
|
@@ -6,7 +6,7 @@ import classifyRings from './classify_rings';
|
|
|
6
6
|
import Point from '@mapbox/point-geometry';
|
|
7
7
|
|
|
8
8
|
// Load a fill feature from fixture tile.
|
|
9
|
-
const vt = new VectorTile(new Protobuf(fs.readFileSync(path.resolve(__dirname, '../../test/
|
|
9
|
+
const vt = new VectorTile(new Protobuf(fs.readFileSync(path.resolve(__dirname, '../../test/unit/assets/mbsv5-6-18-23.vector.pbf'))));
|
|
10
10
|
const feature = vt.layers.water.feature(0);
|
|
11
11
|
|
|
12
12
|
describe('classifyRings', () => {
|
package/src/util/color_ramp.ts
CHANGED
|
@@ -5,11 +5,11 @@ import assert from 'assert';
|
|
|
5
5
|
import type {StylePropertyExpression} from '../style-spec/expression/index';
|
|
6
6
|
|
|
7
7
|
export type ColorRampParams = {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
expression: StylePropertyExpression;
|
|
9
|
+
evaluationKey: string;
|
|
10
|
+
resolution?: number;
|
|
11
|
+
image?: RGBAImage;
|
|
12
|
+
clips?: Array<any>;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
/**
|
package/src/util/config.ts
CHANGED
package/src/util/dispatcher.ts
CHANGED
package/src/util/dom.ts
CHANGED
|
@@ -53,7 +53,7 @@ export default class DOM {
|
|
|
53
53
|
public static addEventListener(target: any, type: any, callback: any, options: {
|
|
54
54
|
passive?: boolean;
|
|
55
55
|
capture?: boolean;
|
|
56
|
-
|
|
56
|
+
} = {}) {
|
|
57
57
|
if ('passive' in options) {
|
|
58
58
|
target.addEventListener(type, callback, options);
|
|
59
59
|
} else {
|
|
@@ -64,7 +64,7 @@ export default class DOM {
|
|
|
64
64
|
public static removeEventListener(target: any, type: any, callback: any, options: {
|
|
65
65
|
passive?: boolean;
|
|
66
66
|
capture?: boolean;
|
|
67
|
-
|
|
67
|
+
} = {}) {
|
|
68
68
|
if ('passive' in options) {
|
|
69
69
|
target.removeEventListener(type, callback, options);
|
|
70
70
|
} else {
|
package/src/util/evented.ts
CHANGED
|
@@ -14,9 +14,9 @@ import {distToSegmentSquared} from './intersection_tests';
|
|
|
14
14
|
* @private
|
|
15
15
|
*/
|
|
16
16
|
export default function(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
polygonRings: Array<Array<Point>>,
|
|
18
|
+
precision: number = 1,
|
|
19
|
+
debug: boolean = false
|
|
20
20
|
): Point {
|
|
21
21
|
// find the bounding box of the outer ring
|
|
22
22
|
let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
|
package/src/util/image.ts
CHANGED
|
@@ -3,13 +3,13 @@ import assert from 'assert';
|
|
|
3
3
|
import {register} from './web_worker_transfer';
|
|
4
4
|
|
|
5
5
|
export type Size = {
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
type Point2D = {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
x: number;
|
|
12
|
+
y: number;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
function createImage(image: any, {
|
|
@@ -21,7 +21,7 @@ function createImage(image: any, {
|
|
|
21
21
|
} else if (data instanceof Uint8ClampedArray) {
|
|
22
22
|
data = new Uint8Array(data.buffer);
|
|
23
23
|
} else if (data.length !== width * height * channels) {
|
|
24
|
-
throw new RangeError(
|
|
24
|
+
throw new RangeError(`mismatched image size. expected: ${data.length} but got: ${width * height * channels}`);
|
|
25
25
|
}
|
|
26
26
|
image.width = width;
|
|
27
27
|
image.height = height;
|
package/src/util/performance.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type {RequestParameters} from '../util/ajax';
|
|
2
2
|
|
|
3
3
|
export type PerformanceMetrics = {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
loadTime: number;
|
|
5
|
+
fullLoadTime: number;
|
|
6
|
+
fps: number;
|
|
7
|
+
percentDroppedFrames: number;
|
|
8
8
|
};
|
|
9
9
|
|
|
10
10
|
export enum PerformanceMarkers {
|
|
@@ -76,9 +76,9 @@ export const PerformanceUtils = {
|
|
|
76
76
|
*/
|
|
77
77
|
export class RequestPerformance {
|
|
78
78
|
_marks: {
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
start: string;
|
|
80
|
+
end: string;
|
|
81
|
+
measure: string;
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
constructor (request: RequestParameters) {
|
|
@@ -6,10 +6,10 @@ type ResourceTypeEnum = keyof IResourceType;
|
|
|
6
6
|
export type RequestTransformFunction = (url: string, resourceType?: ResourceTypeEnum) => RequestParameters;
|
|
7
7
|
|
|
8
8
|
type UrlObject = {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
protocol: string;
|
|
10
|
+
authority: string;
|
|
11
|
+
path: string;
|
|
12
|
+
params: Array<string>;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export class RequestManager {
|
|
@@ -9,10 +9,10 @@ export default resolveTokens;
|
|
|
9
9
|
* @private
|
|
10
10
|
*/
|
|
11
11
|
function resolveTokens(
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
properties: {
|
|
13
|
+
readonly [x: string]: unknown;
|
|
14
|
+
},
|
|
15
|
+
text: string
|
|
16
16
|
): string {
|
|
17
17
|
return text.replace(/{([^{}]+)}/g, (match, key: string) => {
|
|
18
18
|
return key in properties ? String(properties[key]) : '';
|
package/src/util/struct_array.ts
CHANGED
|
@@ -47,21 +47,21 @@ const DEFAULT_CAPACITY = 128;
|
|
|
47
47
|
const RESIZE_MULTIPLIER = 5;
|
|
48
48
|
|
|
49
49
|
export type StructArrayMember = {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
50
|
+
name: string;
|
|
51
|
+
type: ViewType;
|
|
52
|
+
components: number;
|
|
53
|
+
offset: number;
|
|
54
54
|
};
|
|
55
55
|
|
|
56
56
|
export type StructArrayLayout = {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
57
|
+
members: Array<StructArrayMember>;
|
|
58
|
+
size: number;
|
|
59
|
+
alignment: number;
|
|
60
60
|
};
|
|
61
61
|
|
|
62
62
|
export type SerializedStructArray = {
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
length: number;
|
|
64
|
+
arrayBuffer: ArrayBuffer;
|
|
65
65
|
};
|
|
66
66
|
|
|
67
67
|
/**
|
|
@@ -198,12 +198,12 @@ abstract class StructArray {
|
|
|
198
198
|
* @private
|
|
199
199
|
*/
|
|
200
200
|
function createLayout(
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
201
|
+
members: Array<{
|
|
202
|
+
name: string;
|
|
203
|
+
type: ViewType;
|
|
204
|
+
readonly components?: number;
|
|
205
|
+
}>,
|
|
206
|
+
alignment: number = 1
|
|
207
207
|
): StructArrayLayout {
|
|
208
208
|
|
|
209
209
|
let offset = 0;
|
package/src/util/task_queue.ts
CHANGED
|
@@ -3,9 +3,9 @@ import assert from 'assert';
|
|
|
3
3
|
export type TaskID = number; // can't mark opaque due to https://github.com/flowtype/flow-remove-types/pull/61
|
|
4
4
|
|
|
5
5
|
type Task = {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
callback: (timeStamp: number) => void;
|
|
7
|
+
id: TaskID;
|
|
8
|
+
cancelled: boolean;
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
class TaskQueue {
|
|
@@ -9,9 +9,9 @@ let cacheCheckThreshold = 50;
|
|
|
9
9
|
const MIN_TIME_UNTIL_EXPIRY = 1000 * 60 * 7; // 7 minutes. Skip caching tiles with a short enough max age.
|
|
10
10
|
|
|
11
11
|
export type ResponseOptions = {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
12
|
+
status: number;
|
|
13
|
+
statusText: string;
|
|
14
|
+
headers: Headers;
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
// We're using a global shared cache object. Normally, requesting ad-hoc Cache objects is fine, but
|
|
@@ -148,10 +148,10 @@ class TransferableGridIndex {
|
|
|
148
148
|
for (let y = cy1; y <= cy2; y++) {
|
|
149
149
|
const cellIndex = this.d * y + x;
|
|
150
150
|
if (intersectionTest && !intersectionTest(
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
this._convertFromCellCoord(x),
|
|
152
|
+
this._convertFromCellCoord(y),
|
|
153
|
+
this._convertFromCellCoord(x + 1),
|
|
154
|
+
this._convertFromCellCoord(y + 1))) continue;
|
|
155
155
|
if (fn.call(this, x1, y1, x2, y2, cellIndex, arg1, arg2, intersectionTest)) return;
|
|
156
156
|
}
|
|
157
157
|
}
|
package/src/util/util.ts
CHANGED
|
@@ -88,9 +88,9 @@ export function wrap(n: number, min: number, max: number): number {
|
|
|
88
88
|
* @private
|
|
89
89
|
*/
|
|
90
90
|
export function asyncAll<Item, Result>(
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
array: Array<Item>,
|
|
92
|
+
fn: (item: Item, fnCallback: Callback<Result>) => void,
|
|
93
|
+
callback: Callback<Array<Result>>
|
|
94
94
|
) {
|
|
95
95
|
if (!array.length) { return callback(null, []); }
|
|
96
96
|
let remaining = array.length;
|
|
@@ -113,8 +113,8 @@ export function asyncAll<Item, Result>(
|
|
|
113
113
|
* @private
|
|
114
114
|
*/
|
|
115
115
|
export function keysDifference<S, T>(
|
|
116
|
-
|
|
117
|
-
|
|
116
|
+
obj: {[key: string]: S},
|
|
117
|
+
other: {[key: string]: T}
|
|
118
118
|
): Array<string> {
|
|
119
119
|
const difference = [];
|
|
120
120
|
for (const i in obj) {
|
|
@@ -365,9 +365,9 @@ export function isClosedPolygon(points: Array<Point>): boolean {
|
|
|
365
365
|
*/
|
|
366
366
|
|
|
367
367
|
export function sphericalToCartesian([r, azimuthal, polar]: [number, number, number]): {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
368
|
+
x: number;
|
|
369
|
+
y: number;
|
|
370
|
+
z: number;
|
|
371
371
|
} {
|
|
372
372
|
// We abstract "north"/"up" (compass-wise) to be 0° when really this is 90° (π/2):
|
|
373
373
|
// correct for that here
|