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
|
@@ -1,26 +1,48 @@
|
|
|
1
1
|
import type {MousePanHandler} from '../mouse';
|
|
2
|
-
import type TouchPanHandler from './../touch_pan';
|
|
2
|
+
import type {TouchPanHandler} from './../touch_pan';
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* A {@link DragPanHandler} options object
|
|
6
|
+
*/
|
|
4
7
|
export type DragPanOptions = {
|
|
8
|
+
/**
|
|
9
|
+
* factor used to scale the drag velocity
|
|
10
|
+
* @defaultValue 0
|
|
11
|
+
*/
|
|
5
12
|
linearity?: number;
|
|
13
|
+
/**
|
|
14
|
+
* easing function applled to `map.panTo` when applying the drag.
|
|
15
|
+
* @param t - the easing function
|
|
16
|
+
* @defaultValue bezier(0, 0, 0.3, 1)
|
|
17
|
+
*/
|
|
6
18
|
easing?: (t: number) => number;
|
|
19
|
+
/**
|
|
20
|
+
* the maximum value of the drag velocity.
|
|
21
|
+
* @defaultValue 1400
|
|
22
|
+
*/
|
|
7
23
|
deceleration?: number;
|
|
24
|
+
/**
|
|
25
|
+
* the rate at which the speed reduces after the pan ends.
|
|
26
|
+
* @defaultValue 2500
|
|
27
|
+
*/
|
|
8
28
|
maxSpeed?: number;
|
|
9
29
|
};
|
|
10
30
|
|
|
11
31
|
/**
|
|
12
32
|
* The `DragPanHandler` allows the user to pan the map by clicking and dragging
|
|
13
33
|
* the cursor.
|
|
34
|
+
*
|
|
35
|
+
* @group Handlers
|
|
14
36
|
*/
|
|
15
|
-
export
|
|
37
|
+
export class DragPanHandler {
|
|
16
38
|
|
|
17
39
|
_el: HTMLElement;
|
|
18
40
|
_mousePan: MousePanHandler;
|
|
19
41
|
_touchPan: TouchPanHandler;
|
|
20
|
-
_inertiaOptions: DragPanOptions;
|
|
42
|
+
_inertiaOptions: DragPanOptions | boolean;
|
|
21
43
|
|
|
22
44
|
/**
|
|
23
|
-
* @
|
|
45
|
+
* @hidden
|
|
24
46
|
*/
|
|
25
47
|
constructor(el: HTMLElement, mousePan: MousePanHandler, touchPan: TouchPanHandler) {
|
|
26
48
|
this._el = el;
|
|
@@ -31,23 +53,19 @@ export default class DragPanHandler {
|
|
|
31
53
|
/**
|
|
32
54
|
* Enables the "drag to pan" interaction.
|
|
33
55
|
*
|
|
34
|
-
* @param
|
|
35
|
-
* @param {number} [options.linearity=0] factor used to scale the drag velocity
|
|
36
|
-
* @param {Function} [options.easing=bezier(0, 0, 0.3, 1)] easing function applled to `map.panTo` when applying the drag.
|
|
37
|
-
* @param {number} [options.maxSpeed=1400] the maximum value of the drag velocity.
|
|
38
|
-
* @param {number} [options.deceleration=2500] the rate at which the speed reduces after the pan ends.
|
|
39
|
-
*
|
|
56
|
+
* @param options - Options object
|
|
40
57
|
* @example
|
|
58
|
+
* ```ts
|
|
41
59
|
* map.dragPan.enable();
|
|
42
|
-
* @example
|
|
43
60
|
* map.dragPan.enable({
|
|
44
61
|
* linearity: 0.3,
|
|
45
62
|
* easing: bezier(0, 0, 0.3, 1),
|
|
46
63
|
* maxSpeed: 1400,
|
|
47
64
|
* deceleration: 2500,
|
|
48
65
|
* });
|
|
66
|
+
* ```
|
|
49
67
|
*/
|
|
50
|
-
enable(options?: DragPanOptions) {
|
|
68
|
+
enable(options?: DragPanOptions | boolean) {
|
|
51
69
|
this._inertiaOptions = options || {};
|
|
52
70
|
this._mousePan.enable();
|
|
53
71
|
this._touchPan.enable();
|
|
@@ -58,7 +76,9 @@ export default class DragPanHandler {
|
|
|
58
76
|
* Disables the "drag to pan" interaction.
|
|
59
77
|
*
|
|
60
78
|
* @example
|
|
79
|
+
* ```ts
|
|
61
80
|
* map.dragPan.disable();
|
|
81
|
+
* ```
|
|
62
82
|
*/
|
|
63
83
|
disable() {
|
|
64
84
|
this._mousePan.disable();
|
|
@@ -69,7 +89,7 @@ export default class DragPanHandler {
|
|
|
69
89
|
/**
|
|
70
90
|
* Returns a Boolean indicating whether the "drag to pan" interaction is enabled.
|
|
71
91
|
*
|
|
72
|
-
* @returns
|
|
92
|
+
* @returns `true` if the "drag to pan" interaction is enabled.
|
|
73
93
|
*/
|
|
74
94
|
isEnabled() {
|
|
75
95
|
return this._mousePan.isEnabled() && this._touchPan.isEnabled();
|
|
@@ -78,7 +98,7 @@ export default class DragPanHandler {
|
|
|
78
98
|
/**
|
|
79
99
|
* Returns a Boolean indicating whether the "drag to pan" interaction is active, i.e. currently being used.
|
|
80
100
|
*
|
|
81
|
-
* @returns
|
|
101
|
+
* @returns `true` if the "drag to pan" interaction is active.
|
|
82
102
|
*/
|
|
83
103
|
isActive() {
|
|
84
104
|
return this._mousePan.isActive() || this._touchPan.isActive();
|
|
@@ -1,25 +1,29 @@
|
|
|
1
1
|
import type {MousePitchHandler, MouseRotateHandler} from '../mouse';
|
|
2
2
|
|
|
3
|
+
export type DragRotateHandlerOptions = {
|
|
4
|
+
/**
|
|
5
|
+
* Control the map pitch in addition to the bearing
|
|
6
|
+
* @defaultValue true
|
|
7
|
+
*/
|
|
8
|
+
pitchWithRotate: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
3
11
|
/**
|
|
4
12
|
* The `DragRotateHandler` allows the user to rotate the map by clicking and
|
|
5
13
|
* dragging the cursor while holding the right mouse button or `ctrl` key.
|
|
14
|
+
*
|
|
15
|
+
* @group Handlers
|
|
6
16
|
*/
|
|
7
|
-
export
|
|
17
|
+
export class DragRotateHandler {
|
|
8
18
|
|
|
9
19
|
_mouseRotate: MouseRotateHandler;
|
|
10
20
|
_mousePitch: MousePitchHandler;
|
|
11
21
|
_pitchWithRotate: boolean;
|
|
12
22
|
|
|
13
23
|
/**
|
|
14
|
-
* @
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* @param {bool} [options.pitchWithRotate=true] Control the map pitch in addition to the bearing
|
|
18
|
-
* @private
|
|
19
|
-
*/
|
|
20
|
-
constructor(options: {
|
|
21
|
-
pitchWithRotate: boolean;
|
|
22
|
-
}, mouseRotate: MouseRotateHandler, mousePitch: MousePitchHandler) {
|
|
24
|
+
* @hidden
|
|
25
|
+
*/
|
|
26
|
+
constructor(options: DragRotateHandlerOptions, mouseRotate: MouseRotateHandler, mousePitch: MousePitchHandler) {
|
|
23
27
|
this._pitchWithRotate = options.pitchWithRotate;
|
|
24
28
|
this._mouseRotate = mouseRotate;
|
|
25
29
|
this._mousePitch = mousePitch;
|
|
@@ -29,7 +33,9 @@ export default class DragRotateHandler {
|
|
|
29
33
|
* Enables the "drag to rotate" interaction.
|
|
30
34
|
*
|
|
31
35
|
* @example
|
|
36
|
+
* ```ts
|
|
32
37
|
* map.dragRotate.enable();
|
|
38
|
+
* ```
|
|
33
39
|
*/
|
|
34
40
|
enable() {
|
|
35
41
|
this._mouseRotate.enable();
|
|
@@ -40,7 +46,9 @@ export default class DragRotateHandler {
|
|
|
40
46
|
* Disables the "drag to rotate" interaction.
|
|
41
47
|
*
|
|
42
48
|
* @example
|
|
49
|
+
* ```ts
|
|
43
50
|
* map.dragRotate.disable();
|
|
51
|
+
* ```
|
|
44
52
|
*/
|
|
45
53
|
disable() {
|
|
46
54
|
this._mouseRotate.disable();
|
|
@@ -50,7 +58,7 @@ export default class DragRotateHandler {
|
|
|
50
58
|
/**
|
|
51
59
|
* Returns a Boolean indicating whether the "drag to rotate" interaction is enabled.
|
|
52
60
|
*
|
|
53
|
-
* @returns
|
|
61
|
+
* @returns `true` if the "drag to rotate" interaction is enabled.
|
|
54
62
|
*/
|
|
55
63
|
isEnabled() {
|
|
56
64
|
return this._mouseRotate.isEnabled() && (!this._pitchWithRotate || this._mousePitch.isEnabled());
|
|
@@ -59,7 +67,7 @@ export default class DragRotateHandler {
|
|
|
59
67
|
/**
|
|
60
68
|
* Returns a Boolean indicating whether the "drag to rotate" interaction is active, i.e. currently being used.
|
|
61
69
|
*
|
|
62
|
-
* @returns
|
|
70
|
+
* @returns `true` if the "drag to rotate" interaction is active.
|
|
63
71
|
*/
|
|
64
72
|
isActive() {
|
|
65
73
|
return this._mouseRotate.isActive() || this._mousePitch.isActive();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type {TwoFingersTouchZoomHandler, TwoFingersTouchRotateHandler} from '../two_fingers_touch';
|
|
2
|
-
import type TapDragZoomHandler from '../tap_drag_zoom';
|
|
1
|
+
import type {TwoFingersTouchZoomHandler, TwoFingersTouchRotateHandler, AroundCenterOptions} from '../two_fingers_touch';
|
|
2
|
+
import type {TapDragZoomHandler} from '../tap_drag_zoom';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* The `TwoFingersTouchZoomRotateHandler` allows the user to zoom and rotate the map by
|
|
@@ -7,8 +7,10 @@ import type TapDragZoomHandler from '../tap_drag_zoom';
|
|
|
7
7
|
*
|
|
8
8
|
* They can zoom with one finger by double tapping and dragging. On the second tap,
|
|
9
9
|
* hold the finger down and drag up or down to zoom in or out.
|
|
10
|
+
*
|
|
11
|
+
* @group Handlers
|
|
10
12
|
*/
|
|
11
|
-
export
|
|
13
|
+
export class TwoFingersTouchZoomRotateHandler {
|
|
12
14
|
|
|
13
15
|
_el: HTMLElement;
|
|
14
16
|
_touchZoom: TwoFingersTouchZoomHandler;
|
|
@@ -18,7 +20,7 @@ export default class TwoFingersTouchZoomRotateHandler {
|
|
|
18
20
|
_enabled: boolean;
|
|
19
21
|
|
|
20
22
|
/**
|
|
21
|
-
* @
|
|
23
|
+
* @hidden
|
|
22
24
|
*/
|
|
23
25
|
constructor(el: HTMLElement, touchZoom: TwoFingersTouchZoomHandler, touchRotate: TwoFingersTouchRotateHandler, tapDragZoom: TapDragZoomHandler) {
|
|
24
26
|
this._el = el;
|
|
@@ -32,17 +34,15 @@ export default class TwoFingersTouchZoomRotateHandler {
|
|
|
32
34
|
/**
|
|
33
35
|
* Enables the "pinch to rotate and zoom" interaction.
|
|
34
36
|
*
|
|
35
|
-
* @param
|
|
36
|
-
* @param {string} [options.around] If "center" is passed, map will zoom around the center
|
|
37
|
+
* @param options - Options object.
|
|
37
38
|
*
|
|
38
39
|
* @example
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* map.touchZoomRotate.enable();
|
|
42
|
+
* map.touchZoomRotate.enable({ around: 'center' });
|
|
43
|
+
* ```
|
|
42
44
|
*/
|
|
43
|
-
enable(options?: {
|
|
44
|
-
around?: 'center';
|
|
45
|
-
} | null) {
|
|
45
|
+
enable(options?: AroundCenterOptions | boolean | null) {
|
|
46
46
|
this._touchZoom.enable(options);
|
|
47
47
|
if (!this._rotationDisabled) this._touchRotate.enable(options);
|
|
48
48
|
this._tapDragZoom.enable();
|
|
@@ -53,7 +53,9 @@ export default class TwoFingersTouchZoomRotateHandler {
|
|
|
53
53
|
* Disables the "pinch to rotate and zoom" interaction.
|
|
54
54
|
*
|
|
55
55
|
* @example
|
|
56
|
-
*
|
|
56
|
+
* ```ts
|
|
57
|
+
* map.touchZoomRotate.disable();
|
|
58
|
+
* ```
|
|
57
59
|
*/
|
|
58
60
|
disable() {
|
|
59
61
|
this._touchZoom.disable();
|
|
@@ -65,7 +67,7 @@ export default class TwoFingersTouchZoomRotateHandler {
|
|
|
65
67
|
/**
|
|
66
68
|
* Returns a Boolean indicating whether the "pinch to rotate and zoom" interaction is enabled.
|
|
67
69
|
*
|
|
68
|
-
* @returns
|
|
70
|
+
* @returns `true` if the "pinch to rotate and zoom" interaction is enabled.
|
|
69
71
|
*/
|
|
70
72
|
isEnabled() {
|
|
71
73
|
return this._touchZoom.isEnabled() &&
|
|
@@ -76,7 +78,7 @@ export default class TwoFingersTouchZoomRotateHandler {
|
|
|
76
78
|
/**
|
|
77
79
|
* Returns true if the handler is enabled and has detected the start of a zoom/rotate gesture.
|
|
78
80
|
*
|
|
79
|
-
* @returns
|
|
81
|
+
* @returns `true` if the handler is active, `false` otherwise
|
|
80
82
|
*/
|
|
81
83
|
isActive() {
|
|
82
84
|
return this._touchZoom.isActive() || this._touchRotate.isActive() || this._tapDragZoom.isActive();
|
|
@@ -87,7 +89,9 @@ export default class TwoFingersTouchZoomRotateHandler {
|
|
|
87
89
|
* interaction enabled.
|
|
88
90
|
*
|
|
89
91
|
* @example
|
|
90
|
-
*
|
|
92
|
+
* ```ts
|
|
93
|
+
* map.touchZoomRotate.disableRotation();
|
|
94
|
+
* ```
|
|
91
95
|
*/
|
|
92
96
|
disableRotation() {
|
|
93
97
|
this._rotationDisabled = true;
|
|
@@ -98,8 +102,10 @@ export default class TwoFingersTouchZoomRotateHandler {
|
|
|
98
102
|
* Enables the "pinch to rotate" interaction.
|
|
99
103
|
*
|
|
100
104
|
* @example
|
|
101
|
-
*
|
|
102
|
-
*
|
|
105
|
+
* ```ts
|
|
106
|
+
* map.touchZoomRotate.enable();
|
|
107
|
+
* map.touchZoomRotate.enableRotation();
|
|
108
|
+
* ```
|
|
103
109
|
*/
|
|
104
110
|
enableRotation() {
|
|
105
111
|
this._rotationDisabled = false;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {beforeMapTest} from '../../util/test/util';
|
|
2
|
+
import simulate from '../../../test/unit/lib/simulate_interaction';
|
|
3
|
+
import {Map, MapOptions} from '../map';
|
|
4
|
+
|
|
5
|
+
function createMap() {
|
|
6
|
+
return new Map({container: window.document.createElement('div')} as any as MapOptions);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
function setupEvents(map: Map) {
|
|
10
|
+
const zoomstart = jest.fn();
|
|
11
|
+
map.on('zoomstart', zoomstart);
|
|
12
|
+
|
|
13
|
+
const zoom = jest.fn();
|
|
14
|
+
map.on('zoom', zoom);
|
|
15
|
+
|
|
16
|
+
const zoomend = jest.fn();
|
|
17
|
+
map.on('zoomend', zoomend);
|
|
18
|
+
|
|
19
|
+
return {
|
|
20
|
+
zoomstart,
|
|
21
|
+
zoom,
|
|
22
|
+
zoomend
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
beforeEach(() => {
|
|
27
|
+
beforeMapTest();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
describe('tap_drag_zoom', () => {
|
|
31
|
+
test('TapDragZoomHandler fires zoomstart, zoom, and zoomend at appropriate times in response to a double-tap and drag gesture', () => {
|
|
32
|
+
const map = createMap();
|
|
33
|
+
const target = map.getCanvas();
|
|
34
|
+
|
|
35
|
+
const {zoomstart, zoom, zoomend} = setupEvents(map);
|
|
36
|
+
|
|
37
|
+
const pointTouchOptions = {
|
|
38
|
+
touches: [{target, clientX: 100, clientY: 100}]
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
simulate.touchstart(target, pointTouchOptions);
|
|
42
|
+
simulate.touchend(target);
|
|
43
|
+
simulate.touchstart(target, pointTouchOptions);
|
|
44
|
+
map._renderTaskQueue.run();
|
|
45
|
+
|
|
46
|
+
expect(zoomstart).not.toHaveBeenCalled();
|
|
47
|
+
expect(zoom).not.toHaveBeenCalled();
|
|
48
|
+
expect(zoomend).not.toHaveBeenCalled();
|
|
49
|
+
|
|
50
|
+
simulate.touchmove(target, {
|
|
51
|
+
touches: [{target, clientX: 100, clientY: 110}]
|
|
52
|
+
});
|
|
53
|
+
map._renderTaskQueue.run();
|
|
54
|
+
|
|
55
|
+
expect(zoomstart).toHaveBeenCalled();
|
|
56
|
+
expect(zoom).toHaveBeenCalled();
|
|
57
|
+
expect(zoomend).not.toHaveBeenCalled();
|
|
58
|
+
|
|
59
|
+
simulate.touchend(target);
|
|
60
|
+
map._renderTaskQueue.run();
|
|
61
|
+
expect(zoomend).toHaveBeenCalled();
|
|
62
|
+
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
test('TapDragZoomHandler does not fire zoom on tap and drag if touchstart events are > 500ms apart', done => {
|
|
66
|
+
const map = createMap();
|
|
67
|
+
const target = map.getCanvas();
|
|
68
|
+
|
|
69
|
+
const {zoomstart, zoom, zoomend} = setupEvents(map);
|
|
70
|
+
|
|
71
|
+
const pointTouchOptions = {
|
|
72
|
+
touches: [{target, clientX: 100, clientY: 100}]
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
simulate.touchstart(target, pointTouchOptions);
|
|
76
|
+
simulate.touchend(target);
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
simulate.touchstart(target, pointTouchOptions);
|
|
79
|
+
simulate.touchmove(target, {
|
|
80
|
+
touches: [{target, clientX: 100, clientY: 110}]
|
|
81
|
+
});
|
|
82
|
+
map._renderTaskQueue.run();
|
|
83
|
+
|
|
84
|
+
expect(zoomstart).not.toHaveBeenCalled();
|
|
85
|
+
expect(zoom).not.toHaveBeenCalled();
|
|
86
|
+
expect(zoomend).not.toHaveBeenCalled();
|
|
87
|
+
done();
|
|
88
|
+
}, 510);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
test('TapDragZoomHandler does not zoom on double-tap and drag if touchstart events are in different locations (>30px apart)', () => {
|
|
92
|
+
const map = createMap();
|
|
93
|
+
const target = map.getCanvas();
|
|
94
|
+
|
|
95
|
+
const {zoomstart, zoom, zoomend} = setupEvents(map);
|
|
96
|
+
|
|
97
|
+
simulate.touchstart(target, {
|
|
98
|
+
touches: [{target, clientX: 100, clientY: 100}]
|
|
99
|
+
});
|
|
100
|
+
simulate.touchend(target);
|
|
101
|
+
simulate.touchstart(target, {
|
|
102
|
+
touches: [{target, clientX: 140, clientY: 100}]
|
|
103
|
+
});
|
|
104
|
+
simulate.touchmove(target, {
|
|
105
|
+
touches: [{target, clientX: 140, clientY: 110}]
|
|
106
|
+
});
|
|
107
|
+
map._renderTaskQueue.run();
|
|
108
|
+
|
|
109
|
+
expect(zoomstart).not.toHaveBeenCalled();
|
|
110
|
+
expect(zoom).not.toHaveBeenCalled();
|
|
111
|
+
expect(zoomend).not.toHaveBeenCalled();
|
|
112
|
+
});
|
|
113
|
+
});
|
|
@@ -1,13 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {Handler} from '../handler_manager';
|
|
2
|
+
import {TapRecognizer, MAX_TAP_INTERVAL, MAX_DIST} from './tap_recognizer';
|
|
2
3
|
import type Point from '@mapbox/point-geometry';
|
|
3
4
|
|
|
4
|
-
export
|
|
5
|
+
export class TapDragZoomHandler implements Handler {
|
|
5
6
|
|
|
6
7
|
_enabled: boolean;
|
|
7
8
|
_active: boolean;
|
|
8
9
|
_swipePoint: Point;
|
|
9
10
|
_swipeTouch: number;
|
|
10
11
|
_tapTime: number;
|
|
12
|
+
_tapPoint: Point;
|
|
11
13
|
_tap: TapRecognizer;
|
|
12
14
|
|
|
13
15
|
constructor() {
|
|
@@ -25,23 +27,28 @@ export default class TapDragZoomHandler {
|
|
|
25
27
|
delete this._swipePoint;
|
|
26
28
|
delete this._swipeTouch;
|
|
27
29
|
delete this._tapTime;
|
|
30
|
+
delete this._tapPoint;
|
|
28
31
|
this._tap.reset();
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
touchstart(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
|
|
32
35
|
if (this._swipePoint) return;
|
|
33
36
|
|
|
34
|
-
if (this._tapTime && e.timeStamp - this._tapTime > MAX_TAP_INTERVAL) {
|
|
35
|
-
this.reset();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
37
|
if (!this._tapTime) {
|
|
39
38
|
this._tap.touchstart(e, points, mapTouches);
|
|
40
|
-
} else
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
} else {
|
|
40
|
+
const swipePoint = points[0];
|
|
41
|
+
|
|
42
|
+
const soonEnough = e.timeStamp - this._tapTime < MAX_TAP_INTERVAL;
|
|
43
|
+
const closeEnough = this._tapPoint.dist(swipePoint) < MAX_DIST;
|
|
44
44
|
|
|
45
|
+
if (!soonEnough || !closeEnough) {
|
|
46
|
+
this.reset();
|
|
47
|
+
} else if (mapTouches.length > 0) {
|
|
48
|
+
this._swipePoint = swipePoint;
|
|
49
|
+
this._swipeTouch = mapTouches[0].identifier;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
touchmove(e: TouchEvent, points: Array<Point>, mapTouches: Array<Touch>) {
|
|
@@ -70,6 +77,7 @@ export default class TapDragZoomHandler {
|
|
|
70
77
|
const point = this._tap.touchend(e, points, mapTouches);
|
|
71
78
|
if (point) {
|
|
72
79
|
this._tapTime = e.timeStamp;
|
|
80
|
+
this._tapPoint = point;
|
|
73
81
|
}
|
|
74
82
|
} else if (this._swipePoint) {
|
|
75
83
|
if (mapTouches.length === 0) {
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {TapRecognizer} from './tap_recognizer';
|
|
2
2
|
import type Point from '@mapbox/point-geometry';
|
|
3
|
-
import type Map from '../map';
|
|
4
|
-
import TransformProvider from './transform-provider';
|
|
3
|
+
import type {Map} from '../map';
|
|
4
|
+
import {TransformProvider} from './transform-provider';
|
|
5
|
+
import {Handler} from '../handler_manager';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
+
export class TapZoomHandler implements Handler {
|
|
7
8
|
_tr: TransformProvider;
|
|
8
9
|
_enabled: boolean;
|
|
9
10
|
_active: boolean;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import Point from '@mapbox/point-geometry';
|
|
2
2
|
import {indexTouches} from './handler_util';
|
|
3
|
-
import type Map from '../map';
|
|
3
|
+
import type {Map} from '../map';
|
|
4
4
|
import {GestureOptions} from '../map';
|
|
5
|
+
import {Handler} from '../handler_manager';
|
|
5
6
|
|
|
6
|
-
export
|
|
7
|
+
export class TouchPanHandler implements Handler {
|
|
7
8
|
|
|
8
9
|
_enabled: boolean;
|
|
9
10
|
_active: boolean;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import type Map from '../map';
|
|
1
|
+
import type {Map} from '../map';
|
|
2
2
|
import type {PointLike} from '../camera';
|
|
3
|
-
import type Transform from '../../geo/transform';
|
|
3
|
+
import type {Transform} from '../../geo/transform';
|
|
4
4
|
import Point from '@mapbox/point-geometry';
|
|
5
|
-
import LngLat from '../../geo/lng_lat';
|
|
5
|
+
import {LngLat} from '../../geo/lng_lat';
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Shared utilities for the Handler classes to access the correct camera state.
|
|
9
9
|
* If Camera.transformCameraUpdate is specified, the "desired state" of camera may differ from the state used for rendering.
|
|
10
10
|
* The handlers need the "desired state" to track accumulated changes.
|
|
11
11
|
*/
|
|
12
|
-
class TransformProvider {
|
|
12
|
+
export class TransformProvider {
|
|
13
13
|
_map: Map;
|
|
14
14
|
|
|
15
15
|
constructor(map: Map) {
|
|
@@ -40,5 +40,3 @@ class TransformProvider {
|
|
|
40
40
|
return this.transform.pointLocation(Point.convert(point), this._map.terrain);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
|
-
|
|
44
|
-
export default TransformProvider;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Map,
|
|
2
|
-
import Marker from '../marker';
|
|
3
|
-
import DOM from '../../util/dom';
|
|
1
|
+
import {Map, MapOptions} from '../map';
|
|
2
|
+
import {Marker} from '../marker';
|
|
3
|
+
import {DOM} from '../../util/dom';
|
|
4
4
|
import simulate from '../../../test/unit/lib/simulate_interaction';
|
|
5
5
|
import {beforeMapTest} from '../../util/test/util';
|
|
6
6
|
|