maplibre-gl 3.1.0 → 3.2.0-pre.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -7
- package/build/generate-doc-images.ts +73 -0
- package/build/generate-docs.ts +100 -0
- package/build/generate-struct-arrays.ts +9 -12
- package/dist/maplibre-gl-csp-worker.js +1 -1
- package/dist/maplibre-gl-csp-worker.js.map +1 -1
- package/dist/maplibre-gl-csp.js +1 -1
- package/dist/maplibre-gl-csp.js.map +1 -1
- package/dist/maplibre-gl-dev.js +3303 -3398
- package/dist/maplibre-gl-dev.js.map +1 -1
- package/dist/maplibre-gl.d.ts +3899 -3531
- package/dist/maplibre-gl.js +3 -3
- package/dist/maplibre-gl.js.map +1 -1
- package/package.json +28 -25
- package/src/data/array_types.g.ts +14 -48
- package/src/data/bucket/circle_bucket.ts +11 -14
- package/src/data/bucket/fill_bucket.test.ts +6 -6
- package/src/data/bucket/fill_bucket.ts +10 -12
- package/src/data/bucket/fill_extrusion_bucket.ts +11 -13
- package/src/data/bucket/heatmap_bucket.ts +3 -6
- package/src/data/bucket/line_attributes.ts +1 -2
- package/src/data/bucket/line_attributes_ext.ts +1 -2
- package/src/data/bucket/line_bucket.test.ts +5 -5
- package/src/data/bucket/line_bucket.ts +18 -21
- package/src/data/bucket/pattern_attributes.ts +1 -3
- package/src/data/bucket/pattern_bucket_features.ts +3 -3
- package/src/data/bucket/symbol_bucket.test.ts +5 -5
- package/src/data/bucket/symbol_bucket.ts +12 -15
- package/src/data/bucket.ts +7 -11
- package/src/data/dem_data.test.ts +1 -1
- package/src/data/dem_data.ts +1 -1
- package/src/data/evaluation_feature.ts +4 -5
- package/src/data/extent.ts +1 -4
- package/src/data/feature_index.ts +14 -13
- package/src/data/feature_position_map.test.ts +4 -4
- package/src/data/feature_position_map.ts +1 -1
- package/src/data/index_array_type.ts +0 -1
- package/src/data/load_geometry.test.ts +1 -1
- package/src/data/load_geometry.ts +3 -4
- package/src/data/program_configuration.ts +6 -11
- package/src/data/segment.ts +9 -6
- package/src/geo/edge_insets.test.ts +1 -1
- package/src/geo/edge_insets.ts +36 -26
- package/src/geo/lng_lat.test.ts +1 -1
- package/src/geo/lng_lat.ts +61 -44
- package/src/geo/lng_lat_bounds.test.ts +2 -2
- package/src/geo/lng_lat_bounds.ts +88 -68
- package/src/geo/mercator_coordinate.test.ts +2 -2
- package/src/geo/mercator_coordinate.ts +34 -27
- package/src/geo/transform.test.ts +3 -3
- package/src/geo/transform.ts +58 -79
- package/src/gl/color_mode.ts +1 -3
- package/src/gl/context.ts +12 -11
- package/src/gl/cull_face_mode.ts +1 -3
- package/src/gl/depth_mode.ts +1 -3
- package/src/gl/framebuffer.ts +5 -4
- package/src/gl/index_buffer.ts +5 -4
- package/src/gl/render_pool.test.ts +2 -2
- package/src/gl/render_pool.ts +5 -5
- package/src/gl/state.test.ts +1 -1
- package/src/gl/stencil_mode.ts +1 -3
- package/src/gl/value.ts +1 -1
- package/src/gl/vertex_buffer.test.ts +2 -2
- package/src/gl/vertex_buffer.ts +8 -14
- package/src/index.test.ts +2 -2
- package/src/index.ts +121 -113
- package/src/render/draw_background.ts +7 -9
- package/src/render/draw_circle.ts +13 -15
- package/src/render/draw_collision_debug.ts +11 -13
- package/src/render/draw_custom.ts +6 -8
- package/src/render/draw_debug.test.ts +4 -4
- package/src/render/draw_debug.ts +8 -10
- package/src/render/draw_fill.test.ts +13 -13
- package/src/render/draw_fill.ts +9 -11
- package/src/render/draw_fill_extrusion.ts +10 -12
- package/src/render/draw_heatmap.ts +12 -14
- package/src/render/draw_hillshade.ts +10 -12
- package/src/render/draw_line.ts +9 -9
- package/src/render/draw_raster.ts +9 -11
- package/src/render/draw_symbol.test.ts +16 -16
- package/src/render/draw_symbol.ts +15 -16
- package/src/render/draw_terrain.ts +11 -11
- package/src/render/glyph_atlas.ts +10 -1
- package/src/render/glyph_manager.test.ts +3 -3
- package/src/render/glyph_manager.ts +7 -7
- package/src/render/image_atlas.ts +6 -3
- package/src/render/image_manager.ts +3 -5
- package/src/render/line_atlas.test.ts +1 -1
- package/src/render/line_atlas.ts +19 -14
- package/src/render/painter.ts +85 -65
- package/src/render/program/background_program.ts +2 -2
- package/src/render/program/circle_program.ts +5 -5
- package/src/render/program/clipping_mask_program.ts +1 -1
- package/src/render/program/collision_program.ts +4 -4
- package/src/render/program/debug_program.ts +1 -1
- package/src/render/program/fill_extrusion_program.ts +3 -3
- package/src/render/program/fill_program.ts +3 -3
- package/src/render/program/heatmap_program.ts +5 -5
- package/src/render/program/hillshade_program.ts +7 -7
- package/src/render/program/line_program.ts +6 -6
- package/src/render/program/pattern.ts +3 -3
- package/src/render/program/raster_program.ts +2 -2
- package/src/render/program/symbol_program.ts +2 -2
- package/src/render/program/terrain_program.ts +1 -1
- package/src/render/program.ts +18 -16
- package/src/render/render_to_texture.test.ts +15 -15
- package/src/render/render_to_texture.ts +10 -10
- package/src/render/terrain.test.ts +38 -7
- package/src/render/terrain.ts +103 -67
- package/src/render/texture.ts +5 -4
- package/src/render/uniform_binding.test.ts +1 -1
- package/src/render/uniform_binding.ts +7 -1
- package/src/render/update_pattern_positions_in_program.ts +5 -5
- package/src/render/vertex_array_object.ts +9 -8
- package/src/shaders/encode_attribute.ts +0 -2
- package/src/shaders/shaders.ts +1 -3
- package/src/source/canvas_source.test.ts +6 -6
- package/src/source/canvas_source.ts +46 -60
- package/src/source/geojson_source.test.ts +5 -5
- package/src/source/geojson_source.ts +75 -59
- package/src/source/geojson_source_diff.ts +39 -2
- package/src/source/geojson_worker_source.test.ts +3 -3
- package/src/source/geojson_worker_source.ts +20 -26
- package/src/source/geojson_wrapper.test.ts +3 -3
- package/src/source/geojson_wrapper.ts +2 -4
- package/src/source/image_source.test.ts +9 -8
- package/src/source/image_source.ts +49 -35
- package/src/source/load_tilejson.ts +2 -2
- package/src/source/pixels_to_tile_units.ts +2 -3
- package/src/source/query_features.test.ts +3 -3
- package/src/source/query_features.ts +50 -19
- package/src/source/raster_dem_tile_source.test.ts +3 -3
- package/src/source/raster_dem_tile_source.ts +23 -10
- package/src/source/raster_dem_tile_worker_source.test.ts +2 -2
- package/src/source/raster_dem_tile_worker_source.ts +3 -5
- package/src/source/raster_tile_source.test.ts +3 -3
- package/src/source/raster_tile_source.ts +38 -11
- package/src/source/rtl_text_plugin.ts +4 -1
- package/src/source/source.ts +67 -59
- package/src/source/source_cache.test.ts +7 -7
- package/src/source/source_cache.ts +17 -38
- package/src/source/source_state.ts +2 -5
- package/src/source/terrain_source_cache.test.ts +8 -8
- package/src/source/terrain_source_cache.ts +42 -27
- package/src/source/tile.test.ts +3 -3
- package/src/source/tile.ts +32 -38
- package/src/source/tile_bounds.ts +2 -4
- package/src/source/tile_cache.test.ts +2 -2
- package/src/source/tile_cache.ts +20 -30
- package/src/source/tile_id.ts +11 -2
- package/src/source/vector_tile_source.test.ts +3 -3
- package/src/source/vector_tile_source.ts +34 -24
- package/src/source/vector_tile_worker_source.test.ts +4 -4
- package/src/source/vector_tile_worker_source.ts +11 -23
- package/src/source/video_source.test.ts +5 -5
- package/src/source/video_source.ts +21 -28
- package/src/source/worker.ts +6 -8
- package/src/source/worker_source.ts +6 -8
- package/src/source/worker_tile.test.ts +5 -5
- package/src/source/worker_tile.ts +13 -16
- package/src/style/create_style_layer.ts +31 -26
- package/src/style/evaluation_parameters.ts +5 -4
- package/src/style/format_section_override.test.ts +2 -2
- package/src/style/format_section_override.ts +1 -1
- package/src/style/light.test.ts +2 -2
- package/src/style/light.ts +3 -5
- package/src/style/load_glyph_range.test.ts +1 -1
- package/src/style/load_glyph_range.ts +3 -3
- package/src/style/load_sprite.test.ts +1 -1
- package/src/style/load_sprite.ts +3 -3
- package/src/style/parse_glyph_pbf.ts +1 -1
- package/src/style/pauseable_placement.ts +7 -9
- package/src/style/properties.ts +4 -53
- package/src/style/query_utils.ts +3 -3
- package/src/style/style.test.ts +22 -19
- package/src/style/style.ts +118 -84
- package/src/style/style_glyph.ts +6 -0
- package/src/style/style_image.ts +39 -33
- package/src/style/style_layer/background_style_layer.ts +2 -4
- package/src/style/style_layer/circle_style_layer.ts +7 -6
- package/src/style/style_layer/custom_style_layer.ts +23 -48
- package/src/style/style_layer/fill_extrusion_style_layer.ts +4 -6
- package/src/style/style_layer/fill_style_layer.ts +5 -7
- package/src/style/style_layer/heatmap_style_layer.ts +8 -7
- package/src/style/style_layer/hillshade_style_layer.ts +2 -4
- package/src/style/style_layer/line_style_layer.ts +6 -8
- package/src/style/style_layer/overlap_mode.test.ts +3 -3
- package/src/style/style_layer/overlap_mode.ts +3 -0
- package/src/style/style_layer/raster_style_layer.ts +2 -4
- package/src/style/style_layer/symbol_style_layer.ts +6 -8
- package/src/style/style_layer/typed_style_layer.ts +7 -7
- package/src/style/style_layer.test.ts +5 -5
- package/src/style/style_layer.ts +7 -6
- package/src/style/style_layer_index.test.ts +1 -1
- package/src/style/style_layer_index.ts +3 -5
- package/src/style/zoom_history.ts +1 -3
- package/src/symbol/anchor.test.ts +1 -1
- package/src/symbol/anchor.ts +1 -3
- package/src/symbol/check_max_angle.test.ts +8 -2
- package/src/symbol/check_max_angle.ts +10 -13
- package/src/symbol/clip_line.test.ts +1 -1
- package/src/symbol/clip_line.ts +6 -9
- package/src/symbol/collision_feature.test.ts +2 -2
- package/src/symbol/collision_feature.ts +7 -12
- package/src/symbol/collision_index.test.ts +2 -2
- package/src/symbol/collision_index.ts +5 -11
- package/src/symbol/cross_tile_symbol_index.test.ts +2 -2
- package/src/symbol/cross_tile_symbol_index.ts +5 -7
- package/src/symbol/get_anchors.ts +2 -2
- package/src/symbol/grid_index.test.ts +1 -1
- package/src/symbol/grid_index.ts +4 -5
- package/src/symbol/merge_lines.test.ts +1 -1
- package/src/symbol/merge_lines.ts +1 -1
- package/src/symbol/opacity_state.ts +1 -3
- package/src/symbol/path_interpolator.test.ts +1 -1
- package/src/symbol/path_interpolator.ts +1 -3
- package/src/symbol/placement.ts +9 -9
- package/src/symbol/projection.ts +61 -34
- package/src/symbol/quads.ts +7 -11
- package/src/symbol/shaping.ts +1 -1
- package/src/symbol/symbol_layout.ts +9 -12
- package/src/symbol/symbol_size.ts +1 -1
- package/src/symbol/symbol_style_layer.test.ts +4 -4
- package/src/symbol/transform_text.ts +2 -2
- package/src/types/callback.ts +14 -14
- package/src/types/cancelable.ts +3 -0
- package/src/types/transferable.ts +3 -0
- package/src/ui/anchor.ts +4 -0
- package/src/ui/camera.test.ts +6 -6
- package/src/ui/camera.ts +392 -361
- package/src/ui/control/attribution_control.test.ts +1 -1
- package/src/ui/control/attribution_control.ts +34 -30
- package/src/ui/control/control.ts +14 -20
- package/src/ui/control/fullscreen_control.test.ts +1 -1
- package/src/ui/control/fullscreen_control.ts +21 -26
- package/src/ui/control/geolocate_control.test.ts +5 -5
- package/src/ui/control/geolocate_control.ts +181 -194
- package/src/ui/control/logo_control.ts +20 -16
- package/src/ui/control/navigation_control.test.ts +1 -1
- package/src/ui/control/navigation_control.ts +46 -42
- package/src/ui/control/scale_control.test.ts +1 -1
- package/src/ui/control/scale_control.ts +30 -21
- package/src/ui/control/terrain_control.test.ts +1 -1
- package/src/ui/control/terrain_control.ts +14 -18
- package/src/ui/default_locale.ts +1 -3
- package/src/ui/events.ts +570 -1281
- package/src/ui/handler/box_zoom.test.ts +2 -2
- package/src/ui/handler/box_zoom.ts +16 -11
- package/src/ui/handler/click_zoom.ts +11 -3
- package/src/ui/handler/cooperative_gestures.test.ts +3 -3
- package/src/ui/handler/dblclick_zoom.test.ts +1 -1
- package/src/ui/handler/drag_handler.ts +30 -22
- package/src/ui/handler/drag_move_state_manager.ts +1 -1
- package/src/ui/handler/drag_pan.test.ts +2 -2
- package/src/ui/handler/drag_rotate.test.ts +3 -3
- package/src/ui/handler/keyboard.test.ts +2 -2
- package/src/ui/handler/keyboard.ts +22 -13
- package/src/ui/handler/map_event.test.ts +2 -2
- 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 +3 -3
- package/src/ui/handler/scroll_zoom.test.ts +3 -3
- package/src/ui/handler/scroll_zoom.ts +45 -52
- package/src/ui/handler/shim/dblclick_zoom.ts +12 -6
- package/src/ui/handler/shim/drag_pan.ts +34 -14
- package/src/ui/handler/shim/drag_rotate.ts +20 -12
- package/src/ui/handler/shim/two_fingers_touch.ts +24 -18
- package/src/ui/handler/tap_drag_zoom.test.ts +113 -0
- package/src/ui/handler/tap_drag_zoom.ts +18 -10
- package/src/ui/handler/tap_recognizer.ts +1 -1
- package/src/ui/handler/tap_zoom.ts +4 -3
- package/src/ui/handler/touch_pan.ts +3 -2
- package/src/ui/handler/transform-provider.ts +4 -6
- package/src/ui/handler/two_fingers_touch.test.ts +3 -3
- package/src/ui/handler/two_fingers_touch.ts +64 -47
- package/src/ui/handler_inertia.ts +4 -4
- package/src/ui/handler_manager.ts +86 -52
- package/src/ui/hash.test.ts +1 -1
- package/src/ui/hash.ts +21 -28
- package/src/ui/map/isMoving.test.ts +3 -3
- package/src/ui/map/isRotating.test.ts +3 -3
- package/src/ui/map/isZooming.test.ts +3 -3
- package/src/ui/map.test.ts +97 -8
- package/src/ui/map.ts +856 -702
- package/src/ui/map_events.test.ts +1 -1
- package/src/ui/marker.test.ts +35 -15
- package/src/ui/marker.ts +220 -141
- package/src/ui/popup.test.ts +2 -2
- package/src/ui/popup.ts +179 -147
- package/src/util/actor.test.ts +7 -7
- package/src/util/actor.ts +25 -22
- package/src/util/ajax.ts +37 -17
- package/src/util/browser.test.ts +1 -1
- package/src/util/browser.ts +2 -6
- package/src/util/classify_rings.test.ts +1 -1
- package/src/util/classify_rings.ts +1 -1
- package/src/util/color_ramp.ts +0 -2
- package/src/util/config.ts +6 -3
- package/src/util/debug.ts +0 -2
- package/src/util/dictionary_coder.ts +1 -4
- package/src/util/dispatcher.test.ts +3 -3
- package/src/util/dispatcher.ts +4 -9
- package/src/util/dom.ts +1 -1
- package/src/util/evented.ts +23 -18
- package/src/util/find_pole_of_inaccessibility.test.ts +1 -1
- package/src/util/find_pole_of_inaccessibility.ts +4 -5
- package/src/util/global_worker_pool.ts +2 -3
- package/src/util/image.ts +10 -4
- package/src/util/image_request.test.ts +3 -3
- package/src/util/image_request.ts +15 -14
- package/src/util/is_char_in_unicode_block.ts +1 -3
- package/src/util/offscreen_canvas_supported.ts +1 -1
- package/src/util/performance.ts +1 -2
- package/src/util/request_manager.ts +4 -0
- package/src/util/resolve_tokens.test.ts +1 -1
- package/src/util/resolve_tokens.ts +3 -6
- package/src/util/script_detection.ts +1 -4
- package/src/util/smart_wrap.ts +3 -5
- package/src/util/struct_array.ts +18 -14
- package/src/util/style.ts +2 -2
- package/src/util/task_queue.test.ts +1 -1
- package/src/util/task_queue.ts +1 -3
- package/src/util/test/mock_webgl.ts +6 -0
- package/src/util/test/util.ts +2 -2
- package/src/util/throttle.test.ts +1 -1
- package/src/util/throttle.ts +1 -2
- package/src/util/throttled_invoker.ts +1 -5
- package/src/util/transferable_grid_index.test.ts +1 -1
- package/src/util/transferable_grid_index.ts +1 -3
- package/src/util/util.test.ts +1 -14
- package/src/util/util.ts +44 -107
- package/src/util/vectortile_to_geojson.ts +13 -3
- package/src/util/verticalize_punctuation.ts +1 -1
- package/src/util/web_worker.ts +2 -2
- package/src/util/web_worker_transfer.ts +11 -8
- package/src/util/webp_supported.ts +2 -4
- package/src/util/worker_pool.test.ts +1 -1
- package/src/util/worker_pool.ts +4 -5
package/src/util/util.ts
CHANGED
|
@@ -2,17 +2,10 @@ import Point from '@mapbox/point-geometry';
|
|
|
2
2
|
import UnitBezier from '@mapbox/unitbezier';
|
|
3
3
|
import type {Callback} from '../types/callback';
|
|
4
4
|
|
|
5
|
-
/**
|
|
6
|
-
* @module util
|
|
7
|
-
* @private
|
|
8
|
-
*/
|
|
9
|
-
|
|
10
5
|
/**
|
|
11
6
|
* Given a value `t` that varies between 0 and 1, return
|
|
12
7
|
* an interpolation function that eases between 0 and 1 in a pleasing
|
|
13
8
|
* cubic in-out fashion.
|
|
14
|
-
*
|
|
15
|
-
* @private
|
|
16
9
|
*/
|
|
17
10
|
export function easeCubicInOut(t: number): number {
|
|
18
11
|
if (t <= 0) return 0;
|
|
@@ -26,11 +19,10 @@ export function easeCubicInOut(t: number): number {
|
|
|
26
19
|
* Given given (x, y), (x1, y1) control points for a bezier curve,
|
|
27
20
|
* return a function that interpolates along that curve.
|
|
28
21
|
*
|
|
29
|
-
* @param p1x control point 1 x coordinate
|
|
30
|
-
* @param p1y control point 1 y coordinate
|
|
31
|
-
* @param p2x control point 2 x coordinate
|
|
32
|
-
* @param p2y control point 2 y coordinate
|
|
33
|
-
* @private
|
|
22
|
+
* @param p1x - control point 1 x coordinate
|
|
23
|
+
* @param p1y - control point 1 y coordinate
|
|
24
|
+
* @param p2x - control point 2 x coordinate
|
|
25
|
+
* @param p2y - control point 2 y coordinate
|
|
34
26
|
*/
|
|
35
27
|
export function bezier(p1x: number, p1y: number, p2x: number, p2y: number): (t: number) => number {
|
|
36
28
|
const bezier = new UnitBezier(p1x, p1y, p2x, p2y);
|
|
@@ -42,19 +34,16 @@ export function bezier(p1x: number, p1y: number, p2x: number, p2y: number): (t:
|
|
|
42
34
|
/**
|
|
43
35
|
* A default bezier-curve powered easing function with
|
|
44
36
|
* control points (0.25, 0.1) and (0.25, 1)
|
|
45
|
-
*
|
|
46
|
-
* @private
|
|
47
37
|
*/
|
|
48
|
-
export const
|
|
38
|
+
export const defaultEasing = bezier(0.25, 0.1, 0.25, 1);
|
|
49
39
|
|
|
50
40
|
/**
|
|
51
41
|
* constrain n to the given range via min + max
|
|
52
42
|
*
|
|
53
|
-
* @param n value
|
|
54
|
-
* @param min the minimum value to be returned
|
|
55
|
-
* @param max the maximum value to be returned
|
|
43
|
+
* @param n - value
|
|
44
|
+
* @param min - the minimum value to be returned
|
|
45
|
+
* @param max - the maximum value to be returned
|
|
56
46
|
* @returns the clamped value
|
|
57
|
-
* @private
|
|
58
47
|
*/
|
|
59
48
|
export function clamp(n: number, min: number, max: number): number {
|
|
60
49
|
return Math.min(max, Math.max(min, n));
|
|
@@ -63,11 +52,10 @@ export function clamp(n: number, min: number, max: number): number {
|
|
|
63
52
|
/**
|
|
64
53
|
* constrain n to the given range, excluding the minimum, via modular arithmetic
|
|
65
54
|
*
|
|
66
|
-
* @param n value
|
|
67
|
-
* @param min the minimum value to be returned, exclusive
|
|
68
|
-
* @param max the maximum value to be returned, inclusive
|
|
55
|
+
* @param n - value
|
|
56
|
+
* @param min - the minimum value to be returned, exclusive
|
|
57
|
+
* @param max - the maximum value to be returned, inclusive
|
|
69
58
|
* @returns constrained number
|
|
70
|
-
* @private
|
|
71
59
|
*/
|
|
72
60
|
export function wrap(n: number, min: number, max: number): number {
|
|
73
61
|
const d = max - min;
|
|
@@ -75,15 +63,14 @@ export function wrap(n: number, min: number, max: number): number {
|
|
|
75
63
|
return (w === min) ? max : w;
|
|
76
64
|
}
|
|
77
65
|
|
|
78
|
-
|
|
66
|
+
/**
|
|
79
67
|
* Call an asynchronous function on an array of arguments,
|
|
80
68
|
* calling `callback` with the completed results of all calls.
|
|
81
69
|
*
|
|
82
|
-
* @param array input to each call of the async function.
|
|
83
|
-
* @param fn an async function with signature (data, callback)
|
|
84
|
-
* @param callback a callback run after all async work is done.
|
|
70
|
+
* @param array - input to each call of the async function.
|
|
71
|
+
* @param fn - an async function with signature (data, callback)
|
|
72
|
+
* @param callback - a callback run after all async work is done.
|
|
85
73
|
* called with an array, containing the results of each async call.
|
|
86
|
-
* @private
|
|
87
74
|
*/
|
|
88
75
|
export function asyncAll<Item, Result>(
|
|
89
76
|
array: Array<Item>,
|
|
@@ -103,12 +90,11 @@ export function asyncAll<Item, Result>(
|
|
|
103
90
|
});
|
|
104
91
|
}
|
|
105
92
|
|
|
106
|
-
|
|
93
|
+
/**
|
|
107
94
|
* Compute the difference between the keys in one object and the keys
|
|
108
95
|
* in another object.
|
|
109
96
|
*
|
|
110
97
|
* @returns keys difference
|
|
111
|
-
* @private
|
|
112
98
|
*/
|
|
113
99
|
export function keysDifference<S, T>(
|
|
114
100
|
obj: {[key: string]: S},
|
|
@@ -129,9 +115,8 @@ export function keysDifference<S, T>(
|
|
|
129
115
|
* The last source object given overrides properties from previous
|
|
130
116
|
* source objects.
|
|
131
117
|
*
|
|
132
|
-
* @param dest destination object
|
|
133
|
-
* @param sources sources from which properties are pulled
|
|
134
|
-
* @private
|
|
118
|
+
* @param dest - destination object
|
|
119
|
+
* @param sources - sources from which properties are pulled
|
|
135
120
|
*/
|
|
136
121
|
export function extend(dest: any, ...sources: Array<any>): any {
|
|
137
122
|
for (const src of sources) {
|
|
@@ -146,15 +131,15 @@ export function extend(dest: any, ...sources: Array<any>): any {
|
|
|
146
131
|
* Given an object and a number of properties as strings, return version
|
|
147
132
|
* of that object with only those properties.
|
|
148
133
|
*
|
|
149
|
-
* @param src the object
|
|
150
|
-
* @param properties an array of property names chosen
|
|
134
|
+
* @param src - the object
|
|
135
|
+
* @param properties - an array of property names chosen
|
|
151
136
|
* to appear on the resulting object.
|
|
152
137
|
* @returns object with limited properties.
|
|
153
138
|
* @example
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
* // justName = { name: 'Charlie' }
|
|
157
|
-
*
|
|
139
|
+
* ```ts
|
|
140
|
+
* let foo = { name: 'Charlie', age: 10 };
|
|
141
|
+
* let justName = pick(foo, ['name']); // justName = { name: 'Charlie' }
|
|
142
|
+
* ```
|
|
158
143
|
*/
|
|
159
144
|
export function pick(src: any, properties: Array<string>): any {
|
|
160
145
|
const result = {};
|
|
@@ -174,7 +159,6 @@ let id = 1;
|
|
|
174
159
|
* each call.
|
|
175
160
|
*
|
|
176
161
|
* @returns unique numeric id.
|
|
177
|
-
* @private
|
|
178
162
|
*/
|
|
179
163
|
export function uniqueId(): number {
|
|
180
164
|
return id++;
|
|
@@ -182,7 +166,6 @@ export function uniqueId(): number {
|
|
|
182
166
|
|
|
183
167
|
/**
|
|
184
168
|
* Return whether a given value is a power of two
|
|
185
|
-
* @private
|
|
186
169
|
*/
|
|
187
170
|
export function isPowerOfTwo(value: number): boolean {
|
|
188
171
|
return (Math.log(value) / Math.LN2) % 1 === 0;
|
|
@@ -190,46 +173,15 @@ export function isPowerOfTwo(value: number): boolean {
|
|
|
190
173
|
|
|
191
174
|
/**
|
|
192
175
|
* Return the next power of two, or the input value if already a power of two
|
|
193
|
-
* @private
|
|
194
176
|
*/
|
|
195
177
|
export function nextPowerOfTwo(value: number): number {
|
|
196
178
|
if (value <= 1) return 1;
|
|
197
179
|
return Math.pow(2, Math.ceil(Math.log(value) / Math.LN2));
|
|
198
180
|
}
|
|
199
181
|
|
|
200
|
-
/**
|
|
201
|
-
* Given an array of member function names as strings, replace all of them
|
|
202
|
-
* with bound versions that will always refer to `context` as `this`. This
|
|
203
|
-
* is useful for classes where otherwise event bindings would reassign
|
|
204
|
-
* `this` to the evented object or some other value: this lets you ensure
|
|
205
|
-
* the `this` value always.
|
|
206
|
-
*
|
|
207
|
-
* @param fns list of member function names
|
|
208
|
-
* @param context the context value
|
|
209
|
-
* @example
|
|
210
|
-
* function MyClass() {
|
|
211
|
-
* bindAll(['ontimer'], this);
|
|
212
|
-
* this.name = 'Tom';
|
|
213
|
-
* }
|
|
214
|
-
* MyClass.prototype.ontimer = function() {
|
|
215
|
-
* alert(this.name);
|
|
216
|
-
* };
|
|
217
|
-
* var myClass = new MyClass();
|
|
218
|
-
* setTimeout(myClass.ontimer, 100);
|
|
219
|
-
* @private
|
|
220
|
-
*/
|
|
221
|
-
export function bindAll(fns: Array<string>, context: any): void {
|
|
222
|
-
fns.forEach((fn) => {
|
|
223
|
-
if (!context[fn]) { return; }
|
|
224
|
-
context[fn] = context[fn].bind(context);
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
|
|
228
182
|
/**
|
|
229
183
|
* Create an object by mapping all the values of an existing object while
|
|
230
184
|
* preserving their keys.
|
|
231
|
-
*
|
|
232
|
-
* @private
|
|
233
185
|
*/
|
|
234
186
|
export function mapObject(input: any, iterator: Function, context?: any): any {
|
|
235
187
|
const output = {};
|
|
@@ -241,8 +193,6 @@ export function mapObject(input: any, iterator: Function, context?: any): any {
|
|
|
241
193
|
|
|
242
194
|
/**
|
|
243
195
|
* Create an object by filtering out values of an existing object.
|
|
244
|
-
*
|
|
245
|
-
* @private
|
|
246
196
|
*/
|
|
247
197
|
export function filterObject(input: any, iterator: Function, context?: any): any {
|
|
248
198
|
const output = {};
|
|
@@ -256,8 +206,8 @@ export function filterObject(input: any, iterator: Function, context?: any): any
|
|
|
256
206
|
|
|
257
207
|
/**
|
|
258
208
|
* Deeply compares two object literals.
|
|
259
|
-
* @param a first object literal to be compared
|
|
260
|
-
* @param b second object literal to be compared
|
|
209
|
+
* @param a - first object literal to be compared
|
|
210
|
+
* @param b - second object literal to be compared
|
|
261
211
|
* @returns true if the two object literals are deeply equal, false otherwise
|
|
262
212
|
*/
|
|
263
213
|
export function deepEqual(a?: unknown | null, b?: unknown | null): boolean {
|
|
@@ -282,8 +232,6 @@ export function deepEqual(a?: unknown | null, b?: unknown | null): boolean {
|
|
|
282
232
|
|
|
283
233
|
/**
|
|
284
234
|
* Deeply clones two objects.
|
|
285
|
-
*
|
|
286
|
-
* @private
|
|
287
235
|
*/
|
|
288
236
|
export function clone<T>(input: T): T {
|
|
289
237
|
if (Array.isArray(input)) {
|
|
@@ -297,8 +245,6 @@ export function clone<T>(input: T): T {
|
|
|
297
245
|
|
|
298
246
|
/**
|
|
299
247
|
* Check if two arrays have at least one common element.
|
|
300
|
-
*
|
|
301
|
-
* @private
|
|
302
248
|
*/
|
|
303
249
|
export function arraysIntersect<T>(a: Array<T>, b: Array<T>): boolean {
|
|
304
250
|
for (let l = 0; l < a.length; l++) {
|
|
@@ -310,8 +256,6 @@ export function arraysIntersect<T>(a: Array<T>, b: Array<T>): boolean {
|
|
|
310
256
|
/**
|
|
311
257
|
* Print a warning message to the console and ensure duplicate warning messages
|
|
312
258
|
* are not printed.
|
|
313
|
-
*
|
|
314
|
-
* @private
|
|
315
259
|
*/
|
|
316
260
|
const warnOnceHistory: {[key: string]: boolean} = {};
|
|
317
261
|
|
|
@@ -326,7 +270,6 @@ export function warnOnce(message: string): void {
|
|
|
326
270
|
/**
|
|
327
271
|
* Indicates if the provided Points are in a counter clockwise (true) or clockwise (false) order
|
|
328
272
|
*
|
|
329
|
-
* @private
|
|
330
273
|
* @returns true for a counter clockwise set of points
|
|
331
274
|
*/
|
|
332
275
|
// http://bryceboe.com/2006/10/23/line-segment-intersection-algorithm/
|
|
@@ -338,10 +281,10 @@ export function isCounterClockwise(a: Point, b: Point, c: Point): boolean {
|
|
|
338
281
|
* For two lines a and b in 2d space, defined by any two points along the lines,
|
|
339
282
|
* find the intersection point, or return null if the lines are parallel
|
|
340
283
|
*
|
|
341
|
-
* @param a1 First point on line a
|
|
342
|
-
* @param a2 Second point on line a
|
|
343
|
-
* @param b1 First point on line b
|
|
344
|
-
* @param b2 Second point on line b
|
|
284
|
+
* @param a1 - First point on line a
|
|
285
|
+
* @param a2 - Second point on line a
|
|
286
|
+
* @param b1 - First point on line b
|
|
287
|
+
* @param b2 - Second point on line b
|
|
345
288
|
*
|
|
346
289
|
* @returns the intersection point of the two lines or null if they are parallel
|
|
347
290
|
*/
|
|
@@ -371,8 +314,7 @@ export function findLineIntersection(a1: Point, a2: Point, b1: Point, b2: Point)
|
|
|
371
314
|
* have a clockwise winding. Negative areas are interior rings and have a counter clockwise
|
|
372
315
|
* ordering.
|
|
373
316
|
*
|
|
374
|
-
* @
|
|
375
|
-
* @param ring Exterior or interior ring
|
|
317
|
+
* @param ring - Exterior or interior ring
|
|
376
318
|
*/
|
|
377
319
|
export function calculateSignedArea(ring: Array<Point>): number {
|
|
378
320
|
let sum = 0;
|
|
@@ -387,9 +329,8 @@ export function calculateSignedArea(ring: Array<Point>): number {
|
|
|
387
329
|
/**
|
|
388
330
|
* Detects closed polygons, first + last point are equal
|
|
389
331
|
*
|
|
390
|
-
* @
|
|
391
|
-
* @
|
|
392
|
-
* @return true if the points are a closed polygon
|
|
332
|
+
* @param points - array of points
|
|
333
|
+
* @returns `true` if the points are a closed polygon
|
|
393
334
|
*/
|
|
394
335
|
export function isClosedPolygon(points: Array<Point>): boolean {
|
|
395
336
|
// If it is 2 points that are the same then it is a point
|
|
@@ -412,9 +353,8 @@ export function isClosedPolygon(points: Array<Point>): boolean {
|
|
|
412
353
|
/**
|
|
413
354
|
* Converts spherical coordinates to cartesian coordinates.
|
|
414
355
|
*
|
|
415
|
-
* @
|
|
416
|
-
* @
|
|
417
|
-
* @return cartesian coordinates in [x, y, z]
|
|
356
|
+
* @param spherical - Spherical coordinates, in [radial, azimuthal, polar]
|
|
357
|
+
* @returns cartesian coordinates in [x, y, z]
|
|
418
358
|
*/
|
|
419
359
|
|
|
420
360
|
export function sphericalToCartesian([r, azimuthal, polar]: [number, number, number]): {
|
|
@@ -440,8 +380,7 @@ export function sphericalToCartesian([r, azimuthal, polar]: [number, number, num
|
|
|
440
380
|
/**
|
|
441
381
|
* Returns true if the when run in the web-worker context.
|
|
442
382
|
*
|
|
443
|
-
* @
|
|
444
|
-
* @returns {boolean}
|
|
383
|
+
* @returns `true` if the when run in the web-worker context.
|
|
445
384
|
*/
|
|
446
385
|
export function isWorker(): boolean {
|
|
447
386
|
// @ts-ignore
|
|
@@ -451,9 +390,8 @@ export function isWorker(): boolean {
|
|
|
451
390
|
/**
|
|
452
391
|
* Parses data from 'Cache-Control' headers.
|
|
453
392
|
*
|
|
454
|
-
* @
|
|
455
|
-
* @
|
|
456
|
-
* @return object containing parsed header info.
|
|
393
|
+
* @param cacheControl - Value of 'Cache-Control' header
|
|
394
|
+
* @returns object containing parsed header info.
|
|
457
395
|
*/
|
|
458
396
|
|
|
459
397
|
export function parseCacheControl(cacheControl: string): any {
|
|
@@ -486,10 +424,9 @@ let _isSafari = null;
|
|
|
486
424
|
*
|
|
487
425
|
* This should be removed once the underlying Safari issue is fixed.
|
|
488
426
|
*
|
|
489
|
-
* @
|
|
490
|
-
* @param scope {WindowOrWorkerGlobalScope} Since this function is used both on the main thread and WebWorker context,
|
|
427
|
+
* @param scope - Since this function is used both on the main thread and WebWorker context,
|
|
491
428
|
* let the calling scope pass in the global scope object.
|
|
492
|
-
* @returns
|
|
429
|
+
* @returns `true` when run in WebKit derived browsers.
|
|
493
430
|
*/
|
|
494
431
|
export function isSafari(scope: any): boolean {
|
|
495
432
|
if (_isSafari == null) {
|
|
@@ -541,8 +478,8 @@ export function isImageBitmap(image: any): image is ImageBitmap {
|
|
|
541
478
|
* perfectly fine with ImageBitmaps. Might also be used for environments (other than testing) not supporting
|
|
542
479
|
* ArrayBuffers.
|
|
543
480
|
*
|
|
544
|
-
* @param data
|
|
545
|
-
* @param callback A callback executed after the conversion is finished. Invoked with error (if any) as the first argument and resulting image bitmap (when no error) as the second
|
|
481
|
+
* @param data - Data to convert
|
|
482
|
+
* @param callback - A callback executed after the conversion is finished. Invoked with error (if any) as the first argument and resulting image bitmap (when no error) as the second
|
|
546
483
|
*/
|
|
547
484
|
export function arrayBufferToImageBitmap(data: ArrayBuffer, callback: (err?: Error | null, image?: ImageBitmap | null) => void) {
|
|
548
485
|
const blob: Blob = new Blob([new Uint8Array(data)], {type: 'image/png'});
|
|
@@ -562,8 +499,8 @@ const transparentPngUrl = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAA
|
|
|
562
499
|
* perfectly fine with ImageBitmaps. Might also be used for environments (other than testing) not supporting
|
|
563
500
|
* ArrayBuffers.
|
|
564
501
|
*
|
|
565
|
-
* @param data
|
|
566
|
-
* @param callback A callback executed after the conversion is finished. Invoked with error (if any) as the first argument and resulting image element (when no error) as the second
|
|
502
|
+
* @param data - Data to convert
|
|
503
|
+
* @param callback - A callback executed after the conversion is finished. Invoked with error (if any) as the first argument and resulting image element (when no error) as the second
|
|
567
504
|
*/
|
|
568
505
|
export function arrayBufferToImage(data: ArrayBuffer, callback: (err?: Error | null, image?: HTMLImageElement | null) => void) {
|
|
569
506
|
const img: HTMLImageElement = new Image();
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
import type {VectorTileFeature} from '@mapbox/vector-tile';
|
|
2
2
|
import type {LayerSpecification} from '@maplibre/maplibre-gl-style-spec';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A helper for type to omit a property from a type
|
|
6
|
+
*/
|
|
4
7
|
type DistributiveKeys<T> = T extends T ? keyof T : never;
|
|
8
|
+
/**
|
|
9
|
+
* A helper for type to omit a property from a type
|
|
10
|
+
*/
|
|
5
11
|
type DistributiveOmit<T, K extends DistributiveKeys<T>> = T extends unknown
|
|
6
12
|
? Omit<T, K>
|
|
7
13
|
: never;
|
|
8
14
|
|
|
15
|
+
/**
|
|
16
|
+
* An extended geojson feature used by the events to return data to the listener
|
|
17
|
+
*/
|
|
9
18
|
export type MapGeoJSONFeature = GeoJSONFeature & {
|
|
10
19
|
layer: DistributiveOmit<LayerSpecification, 'source'> & {source: string};
|
|
11
20
|
source: string;
|
|
@@ -13,7 +22,10 @@ export type MapGeoJSONFeature = GeoJSONFeature & {
|
|
|
13
22
|
state: { [key: string]: any };
|
|
14
23
|
}
|
|
15
24
|
|
|
16
|
-
|
|
25
|
+
/**
|
|
26
|
+
* A geojson feature
|
|
27
|
+
*/
|
|
28
|
+
export class GeoJSONFeature {
|
|
17
29
|
type: 'Feature';
|
|
18
30
|
_geometry: GeoJSON.Geometry;
|
|
19
31
|
properties: { [name: string]: any };
|
|
@@ -58,5 +70,3 @@ class GeoJSONFeature {
|
|
|
58
70
|
return json;
|
|
59
71
|
}
|
|
60
72
|
}
|
|
61
|
-
|
|
62
|
-
export default GeoJSONFeature;
|
package/src/util/web_worker.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import config from './config';
|
|
1
|
+
import {config} from './config';
|
|
2
2
|
|
|
3
3
|
import type {WorkerSource} from '../source/worker_source';
|
|
4
4
|
|
|
@@ -28,6 +28,6 @@ export interface WorkerGlobalScopeInterface {
|
|
|
28
28
|
registerRTLTextPlugin: (_: any) => void;
|
|
29
29
|
}
|
|
30
30
|
|
|
31
|
-
export
|
|
31
|
+
export function workerFactory() {
|
|
32
32
|
return new Worker(config.WORKER_URL);
|
|
33
33
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import TransferableGridIndex from './transferable_grid_index';
|
|
1
|
+
import {TransferableGridIndex} from './transferable_grid_index';
|
|
2
2
|
import {Color, CompoundExpression, expressions, ResolvedImage, StylePropertyFunction,
|
|
3
3
|
StyleExpression, ZoomDependentExpression, ZoomConstantExpression} from '@maplibre/maplibre-gl-style-spec';
|
|
4
4
|
|
|
@@ -24,8 +24,17 @@ type Registry = {
|
|
|
24
24
|
};
|
|
25
25
|
};
|
|
26
26
|
|
|
27
|
+
/**
|
|
28
|
+
* Register options
|
|
29
|
+
*/
|
|
27
30
|
type RegisterOptions<T> = {
|
|
31
|
+
/**
|
|
32
|
+
* List of properties to omit from serialization (e.g., cached/computed properties)
|
|
33
|
+
*/
|
|
28
34
|
omit?: ReadonlyArray<keyof T>;
|
|
35
|
+
/**
|
|
36
|
+
* List of properties that should be serialized by a simple shallow copy, rather than by a recursive call to serialize().
|
|
37
|
+
*/
|
|
29
38
|
shallow?: ReadonlyArray<keyof T>;
|
|
30
39
|
};
|
|
31
40
|
|
|
@@ -34,11 +43,7 @@ const registry: Registry = {};
|
|
|
34
43
|
/**
|
|
35
44
|
* Register the given class as serializable.
|
|
36
45
|
*
|
|
37
|
-
* @param options
|
|
38
|
-
* @param options.omit List of properties to omit from serialization (e.g., cached/computed properties)
|
|
39
|
-
* @param options.shallow List of properties that should be serialized by a simple shallow copy, rather than by a recursive call to serialize().
|
|
40
|
-
*
|
|
41
|
-
* @private
|
|
46
|
+
* @param options - the registration options
|
|
42
47
|
*/
|
|
43
48
|
export function register<T extends any>(
|
|
44
49
|
name: string,
|
|
@@ -94,8 +99,6 @@ function isArrayBuffer(value: any): value is ArrayBuffer {
|
|
|
94
99
|
* If a `transferables` array is provided, add any transferable objects (i.e.,
|
|
95
100
|
* any ArrayBuffers or ArrayBuffer views) to the list. (If a copy is needed,
|
|
96
101
|
* this should happen in the client code, before using serialize().)
|
|
97
|
-
*
|
|
98
|
-
* @private
|
|
99
102
|
*/
|
|
100
103
|
export function serialize(input: unknown, transferables?: Array<Transferable> | null): Serialized {
|
|
101
104
|
if (input === null ||
|
|
@@ -1,10 +1,8 @@
|
|
|
1
|
-
const
|
|
1
|
+
export const webpSupported = {
|
|
2
2
|
supported: false,
|
|
3
3
|
testSupport
|
|
4
4
|
};
|
|
5
5
|
|
|
6
|
-
export default exported;
|
|
7
|
-
|
|
8
6
|
let glForTesting: WebGLRenderingContext|WebGL2RenderingContext;
|
|
9
7
|
let webpCheckComplete = false;
|
|
10
8
|
let webpImgTest;
|
|
@@ -54,7 +52,7 @@ function testWebpTextureUpload(gl: WebGLRenderingContext|WebGL2RenderingContext)
|
|
|
54
52
|
// The error does not get triggered in Edge if the context is lost
|
|
55
53
|
if (gl.isContextLost()) return;
|
|
56
54
|
|
|
57
|
-
|
|
55
|
+
webpSupported.supported = true;
|
|
58
56
|
} catch (e) {
|
|
59
57
|
// Catch "Unspecified Error." in Edge 18.
|
|
60
58
|
}
|
package/src/util/worker_pool.ts
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {workerFactory} from './web_worker';
|
|
2
2
|
import type {WorkerInterface} from './web_worker';
|
|
3
|
-
import browser from './browser';
|
|
3
|
+
import {browser} from './browser';
|
|
4
4
|
import {isSafari} from './util';
|
|
5
5
|
|
|
6
6
|
export const PRELOAD_POOL_ID = 'mapboxgl_preloaded_worker_pool';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Constructs a worker pool.
|
|
10
|
-
* @private
|
|
11
10
|
*/
|
|
12
|
-
export
|
|
11
|
+
export class WorkerPool {
|
|
13
12
|
static workerCount: number;
|
|
14
13
|
|
|
15
14
|
active: {
|
|
@@ -27,7 +26,7 @@ export default class WorkerPool {
|
|
|
27
26
|
// client code has had a chance to set it.
|
|
28
27
|
this.workers = [];
|
|
29
28
|
while (this.workers.length < WorkerPool.workerCount) {
|
|
30
|
-
this.workers.push(
|
|
29
|
+
this.workers.push(workerFactory());
|
|
31
30
|
}
|
|
32
31
|
}
|
|
33
32
|
|