@antv/l7-map 2.25.7 → 2.25.10
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/es/index.d.ts +5 -0
- package/es/index.js +4 -0
- package/es/map/camera.d.ts +690 -0
- package/es/map/camera.js +1138 -0
- package/es/map/css/l7.css +171 -0
- package/es/map/events.d.ts +384 -0
- package/es/map/events.js +231 -0
- package/es/map/geo/edge_insets.d.ts +97 -0
- package/es/map/geo/edge_insets.js +115 -0
- package/es/map/geo/lng_lat.d.ts +116 -0
- package/es/map/geo/lng_lat.js +159 -0
- package/es/map/geo/lng_lat_bounds.d.ts +217 -0
- package/es/map/geo/lng_lat_bounds.js +334 -0
- package/es/map/geo/mercator_coordinate.d.ts +113 -0
- package/es/map/geo/mercator_coordinate.js +142 -0
- package/es/map/geo/transform.d.ts +262 -0
- package/es/map/geo/transform.js +736 -0
- package/es/map/handler/box_zoom.d.ts +65 -0
- package/es/map/handler/box_zoom.js +145 -0
- package/es/map/handler/click_zoom.d.ts +24 -0
- package/es/map/handler/click_zoom.js +47 -0
- package/es/map/handler/cooperative_gestures.d.ts +40 -0
- package/es/map/handler/cooperative_gestures.js +94 -0
- package/es/map/handler/drag_handler.d.ts +88 -0
- package/es/map/handler/drag_handler.js +89 -0
- package/es/map/handler/drag_move_state_manager.d.ts +30 -0
- package/es/map/handler/drag_move_state_manager.js +94 -0
- package/es/map/handler/handler_util.d.ts +3 -0
- package/es/map/handler/handler_util.js +8 -0
- package/es/map/handler/keyboard.d.ts +88 -0
- package/es/map/handler/keyboard.js +197 -0
- package/es/map/handler/map_event.d.ts +46 -0
- package/es/map/handler/map_event.js +131 -0
- package/es/map/handler/mouse.d.ts +30 -0
- package/es/map/handler/mouse.js +85 -0
- package/es/map/handler/one_finger_touch_drag.d.ts +15 -0
- package/es/map/handler/one_finger_touch_drag.js +39 -0
- package/es/map/handler/scroll_zoom.d.ts +102 -0
- package/es/map/handler/scroll_zoom.js +312 -0
- package/es/map/handler/shim/dblclick_zoom.d.ts +44 -0
- package/es/map/handler/shim/dblclick_zoom.js +60 -0
- package/es/map/handler/shim/drag_pan.d.ts +79 -0
- package/es/map/handler/shim/drag_pan.js +77 -0
- package/es/map/handler/shim/drag_rotate.d.ts +54 -0
- package/es/map/handler/shim/drag_rotate.js +66 -0
- package/es/map/handler/shim/two_fingers_touch.d.ts +74 -0
- package/es/map/handler/shim/two_fingers_touch.js +106 -0
- package/es/map/handler/tap_drag_zoom.d.ts +28 -0
- package/es/map/handler/tap_drag_zoom.js +92 -0
- package/es/map/handler/tap_recognizer.d.ts +35 -0
- package/es/map/handler/tap_recognizer.js +107 -0
- package/es/map/handler/tap_zoom.d.ts +28 -0
- package/es/map/handler/tap_zoom.js +87 -0
- package/es/map/handler/touch_pan.d.ts +40 -0
- package/es/map/handler/touch_pan.js +85 -0
- package/es/map/handler/transform-provider.d.ts +23 -0
- package/es/map/handler/transform-provider.js +35 -0
- package/es/map/handler/two_fingers_touch.d.ts +107 -0
- package/es/map/handler/two_fingers_touch.js +289 -0
- package/es/map/handler_inertia.d.ts +20 -0
- package/es/map/handler_inertia.js +128 -0
- package/es/map/handler_manager.d.ts +154 -0
- package/es/map/handler_manager.js +466 -0
- package/es/map/map.d.ts +637 -0
- package/es/map/map.js +984 -0
- package/es/map/util/abort_error.d.ts +15 -0
- package/es/map/util/abort_error.js +21 -0
- package/es/map/util/browser.d.ts +10 -0
- package/es/map/util/browser.js +30 -0
- package/es/map/util/dom.d.ts +30 -0
- package/es/map/util/dom.js +105 -0
- package/es/map/util/evented.d.ts +75 -0
- package/es/map/util/evented.js +158 -0
- package/es/map/util/simpleMapCoord.d.ts +31 -0
- package/es/map/util/simpleMapCoord.js +54 -0
- package/es/map/util/task_queue.d.ts +18 -0
- package/es/map/util/task_queue.js +54 -0
- package/es/map/util/util.d.ts +104 -0
- package/es/map/util/util.js +155 -0
- package/lib/index.d.ts +5 -0
- package/lib/index.js +33 -0
- package/lib/map/camera.d.ts +690 -0
- package/lib/map/camera.js +1145 -0
- package/lib/map/css/l7.css +171 -0
- package/lib/map/events.d.ts +384 -0
- package/lib/map/events.js +240 -0
- package/lib/map/geo/edge_insets.d.ts +97 -0
- package/lib/map/geo/edge_insets.js +122 -0
- package/lib/map/geo/lng_lat.d.ts +116 -0
- package/lib/map/geo/lng_lat.js +166 -0
- package/lib/map/geo/lng_lat_bounds.d.ts +217 -0
- package/lib/map/geo/lng_lat_bounds.js +341 -0
- package/lib/map/geo/mercator_coordinate.d.ts +113 -0
- package/lib/map/geo/mercator_coordinate.js +157 -0
- package/lib/map/geo/transform.d.ts +262 -0
- package/lib/map/geo/transform.js +744 -0
- package/lib/map/handler/box_zoom.d.ts +65 -0
- package/lib/map/handler/box_zoom.js +153 -0
- package/lib/map/handler/click_zoom.d.ts +24 -0
- package/lib/map/handler/click_zoom.js +54 -0
- package/lib/map/handler/cooperative_gestures.d.ts +40 -0
- package/lib/map/handler/cooperative_gestures.js +101 -0
- package/lib/map/handler/drag_handler.d.ts +88 -0
- package/lib/map/handler/drag_handler.js +97 -0
- package/lib/map/handler/drag_move_state_manager.d.ts +30 -0
- package/lib/map/handler/drag_move_state_manager.js +103 -0
- package/lib/map/handler/handler_util.d.ts +3 -0
- package/lib/map/handler/handler_util.js +14 -0
- package/lib/map/handler/keyboard.d.ts +88 -0
- package/lib/map/handler/keyboard.js +205 -0
- package/lib/map/handler/map_event.d.ts +46 -0
- package/lib/map/handler/map_event.js +140 -0
- package/lib/map/handler/mouse.d.ts +30 -0
- package/lib/map/handler/mouse.js +93 -0
- package/lib/map/handler/one_finger_touch_drag.d.ts +15 -0
- package/lib/map/handler/one_finger_touch_drag.js +47 -0
- package/lib/map/handler/scroll_zoom.d.ts +102 -0
- package/lib/map/handler/scroll_zoom.js +320 -0
- package/lib/map/handler/shim/dblclick_zoom.d.ts +44 -0
- package/lib/map/handler/shim/dblclick_zoom.js +68 -0
- package/lib/map/handler/shim/drag_pan.d.ts +79 -0
- package/lib/map/handler/shim/drag_pan.js +85 -0
- package/lib/map/handler/shim/drag_rotate.d.ts +54 -0
- package/lib/map/handler/shim/drag_rotate.js +74 -0
- package/lib/map/handler/shim/two_fingers_touch.d.ts +74 -0
- package/lib/map/handler/shim/two_fingers_touch.js +114 -0
- package/lib/map/handler/tap_drag_zoom.d.ts +28 -0
- package/lib/map/handler/tap_drag_zoom.js +99 -0
- package/lib/map/handler/tap_recognizer.d.ts +35 -0
- package/lib/map/handler/tap_recognizer.js +116 -0
- package/lib/map/handler/tap_zoom.d.ts +28 -0
- package/lib/map/handler/tap_zoom.js +94 -0
- package/lib/map/handler/touch_pan.d.ts +40 -0
- package/lib/map/handler/touch_pan.js +92 -0
- package/lib/map/handler/transform-provider.d.ts +23 -0
- package/lib/map/handler/transform-provider.js +43 -0
- package/lib/map/handler/two_fingers_touch.d.ts +107 -0
- package/lib/map/handler/two_fingers_touch.js +296 -0
- package/lib/map/handler_inertia.d.ts +20 -0
- package/lib/map/handler_inertia.js +136 -0
- package/lib/map/handler_manager.d.ts +154 -0
- package/lib/map/handler_manager.js +474 -0
- package/lib/map/map.d.ts +637 -0
- package/lib/map/map.js +991 -0
- package/lib/map/util/abort_error.d.ts +15 -0
- package/lib/map/util/abort_error.js +29 -0
- package/lib/map/util/browser.d.ts +10 -0
- package/lib/map/util/browser.js +36 -0
- package/lib/map/util/dom.d.ts +30 -0
- package/lib/map/util/dom.js +113 -0
- package/lib/map/util/evented.d.ts +75 -0
- package/lib/map/util/evented.js +167 -0
- package/lib/map/util/simpleMapCoord.d.ts +31 -0
- package/lib/map/util/simpleMapCoord.js +62 -0
- package/lib/map/util/task_queue.d.ts +18 -0
- package/lib/map/util/task_queue.js +62 -0
- package/lib/map/util/util.d.ts +104 -0
- package/lib/map/util/util.js +171 -0
- package/package.json +2 -2
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { DragHandler } from "./drag_handler";
|
|
2
|
+
import { OneFingerTouchMoveStateManager } from "./drag_move_state_manager";
|
|
3
|
+
const assignEvents = handler => {
|
|
4
|
+
handler.touchstart = handler.dragStart;
|
|
5
|
+
handler.touchmoveWindow = handler.dragMove;
|
|
6
|
+
handler.touchend = handler.dragEnd;
|
|
7
|
+
};
|
|
8
|
+
export const generateOneFingerTouchRotationHandler = ({
|
|
9
|
+
enable,
|
|
10
|
+
clickTolerance,
|
|
11
|
+
bearingDegreesPerPixelMoved = 0.8
|
|
12
|
+
}) => {
|
|
13
|
+
const touchMoveStateManager = new OneFingerTouchMoveStateManager();
|
|
14
|
+
return new DragHandler({
|
|
15
|
+
clickTolerance,
|
|
16
|
+
move: (lastPoint, point) => ({
|
|
17
|
+
bearingDelta: (point.x - lastPoint.x) * bearingDegreesPerPixelMoved
|
|
18
|
+
}),
|
|
19
|
+
moveStateManager: touchMoveStateManager,
|
|
20
|
+
enable,
|
|
21
|
+
assignEvents
|
|
22
|
+
});
|
|
23
|
+
};
|
|
24
|
+
export const generateOneFingerTouchPitchHandler = ({
|
|
25
|
+
enable,
|
|
26
|
+
clickTolerance,
|
|
27
|
+
pitchDegreesPerPixelMoved = -0.5
|
|
28
|
+
}) => {
|
|
29
|
+
const touchMoveStateManager = new OneFingerTouchMoveStateManager();
|
|
30
|
+
return new DragHandler({
|
|
31
|
+
clickTolerance,
|
|
32
|
+
move: (lastPoint, point) => ({
|
|
33
|
+
pitchDelta: (point.y - lastPoint.y) * pitchDegreesPerPixelMoved
|
|
34
|
+
}),
|
|
35
|
+
moveStateManager: touchMoveStateManager,
|
|
36
|
+
enable,
|
|
37
|
+
assignEvents
|
|
38
|
+
});
|
|
39
|
+
};
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
/// <reference types="mapbox__point-geometry" />
|
|
2
|
+
import { LngLat } from '../geo/lng_lat';
|
|
3
|
+
import { TransformProvider } from './transform-provider';
|
|
4
|
+
import type Point from '@mapbox/point-geometry';
|
|
5
|
+
import type { Handler } from '../handler_manager';
|
|
6
|
+
import type { Map } from '../map';
|
|
7
|
+
import type { AroundCenterOptions } from './two_fingers_touch';
|
|
8
|
+
/**
|
|
9
|
+
* The `ScrollZoomHandler` allows the user to zoom the map by scrolling.
|
|
10
|
+
*
|
|
11
|
+
* @group Handlers
|
|
12
|
+
*/
|
|
13
|
+
export declare class ScrollZoomHandler implements Handler {
|
|
14
|
+
_map: Map;
|
|
15
|
+
_tr: TransformProvider;
|
|
16
|
+
_enabled: boolean;
|
|
17
|
+
_active: boolean;
|
|
18
|
+
_zooming: boolean;
|
|
19
|
+
_aroundCenter: boolean;
|
|
20
|
+
_around: LngLat;
|
|
21
|
+
_aroundPoint: Point;
|
|
22
|
+
_type: 'wheel' | 'trackpad' | null;
|
|
23
|
+
_lastValue: number;
|
|
24
|
+
_timeout: ReturnType<typeof setTimeout>;
|
|
25
|
+
_finishTimeout: ReturnType<typeof setTimeout>;
|
|
26
|
+
_lastWheelEvent: any;
|
|
27
|
+
_lastWheelEventTime: number;
|
|
28
|
+
_startZoom: number;
|
|
29
|
+
_targetZoom: number;
|
|
30
|
+
_delta: number;
|
|
31
|
+
_easing: (a: number) => number;
|
|
32
|
+
_prevEase: {
|
|
33
|
+
start: number;
|
|
34
|
+
duration: number;
|
|
35
|
+
easing: (_: number) => number;
|
|
36
|
+
};
|
|
37
|
+
_frameId: boolean;
|
|
38
|
+
_triggerRenderFrame: () => void;
|
|
39
|
+
_defaultZoomRate: number;
|
|
40
|
+
_wheelZoomRate: number;
|
|
41
|
+
/** @internal */
|
|
42
|
+
constructor(map: Map, triggerRenderFrame: () => void);
|
|
43
|
+
/**
|
|
44
|
+
* Set the zoom rate of a trackpad
|
|
45
|
+
* @param zoomRate - 1/100 The rate used to scale trackpad movement to a zoom value.
|
|
46
|
+
* @example
|
|
47
|
+
* Speed up trackpad zoom
|
|
48
|
+
* ```ts
|
|
49
|
+
* map.scrollZoom.setZoomRate(1/25);
|
|
50
|
+
* ```
|
|
51
|
+
*/
|
|
52
|
+
setZoomRate(zoomRate: number): void;
|
|
53
|
+
/**
|
|
54
|
+
* Set the zoom rate of a mouse wheel
|
|
55
|
+
* @param wheelZoomRate - 1/450 The rate used to scale mouse wheel movement to a zoom value.
|
|
56
|
+
* @example
|
|
57
|
+
* Slow down zoom of mouse wheel
|
|
58
|
+
* ```ts
|
|
59
|
+
* map.scrollZoom.setWheelZoomRate(1/600);
|
|
60
|
+
* ```
|
|
61
|
+
*/
|
|
62
|
+
setWheelZoomRate(wheelZoomRate: number): void;
|
|
63
|
+
/**
|
|
64
|
+
* Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled.
|
|
65
|
+
* @returns `true` if the "scroll to zoom" interaction is enabled.
|
|
66
|
+
*/
|
|
67
|
+
isEnabled(): boolean;
|
|
68
|
+
isActive(): boolean;
|
|
69
|
+
isZooming(): boolean;
|
|
70
|
+
/**
|
|
71
|
+
* Enables the "scroll to zoom" interaction.
|
|
72
|
+
*
|
|
73
|
+
* @param options - Options object.
|
|
74
|
+
* @example
|
|
75
|
+
* ```ts
|
|
76
|
+
* map.scrollZoom.enable();
|
|
77
|
+
* map.scrollZoom.enable({ around: 'center' })
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
enable(options?: AroundCenterOptions | boolean): void;
|
|
81
|
+
/**
|
|
82
|
+
* Disables the "scroll to zoom" interaction.
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```ts
|
|
86
|
+
* map.scrollZoom.disable();
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
disable(): void;
|
|
90
|
+
wheel(e: WheelEvent): void;
|
|
91
|
+
_onTimeout: (initialEvent: MouseEvent) => void;
|
|
92
|
+
_start(e: MouseEvent): void;
|
|
93
|
+
renderFrame(): {
|
|
94
|
+
noInertia: boolean;
|
|
95
|
+
needsRenderFrame: boolean;
|
|
96
|
+
zoomDelta: number;
|
|
97
|
+
around: Point;
|
|
98
|
+
originalEvent: any;
|
|
99
|
+
};
|
|
100
|
+
_smoothOutEasing(duration: number): (t: number) => number;
|
|
101
|
+
reset(): void;
|
|
102
|
+
}
|
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import { DOM } from "../util/dom";
|
|
3
|
+
import { LngLat } from "../geo/lng_lat";
|
|
4
|
+
import { browser } from "../util/browser";
|
|
5
|
+
import { bezier, defaultEasing, interpolates } from "../util/util";
|
|
6
|
+
import { TransformProvider } from "./transform-provider";
|
|
7
|
+
// deltaY value for mouse scroll wheel identification
|
|
8
|
+
const wheelZoomDelta = 4.000244140625;
|
|
9
|
+
|
|
10
|
+
// These magic numbers control the rate of zoom. Trackpad events fire at a greater
|
|
11
|
+
// frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick
|
|
12
|
+
const defaultZoomRate = 1 / 100;
|
|
13
|
+
const wheelZoomRate = 1 / 450;
|
|
14
|
+
|
|
15
|
+
// upper bound on how much we scale the map in any single render frame; this
|
|
16
|
+
// is used to limit zoom rate in the case of very fast scrolling
|
|
17
|
+
const maxScalePerFrame = 2;
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The `ScrollZoomHandler` allows the user to zoom the map by scrolling.
|
|
21
|
+
*
|
|
22
|
+
* @group Handlers
|
|
23
|
+
*/
|
|
24
|
+
export class ScrollZoomHandler {
|
|
25
|
+
/** @internal */
|
|
26
|
+
constructor(map, triggerRenderFrame) {
|
|
27
|
+
_defineProperty(this, "_map", void 0);
|
|
28
|
+
_defineProperty(this, "_tr", void 0);
|
|
29
|
+
_defineProperty(this, "_enabled", void 0);
|
|
30
|
+
_defineProperty(this, "_active", void 0);
|
|
31
|
+
_defineProperty(this, "_zooming", void 0);
|
|
32
|
+
_defineProperty(this, "_aroundCenter", void 0);
|
|
33
|
+
_defineProperty(this, "_around", void 0);
|
|
34
|
+
_defineProperty(this, "_aroundPoint", void 0);
|
|
35
|
+
_defineProperty(this, "_type", void 0);
|
|
36
|
+
_defineProperty(this, "_lastValue", void 0);
|
|
37
|
+
_defineProperty(this, "_timeout", void 0);
|
|
38
|
+
// used for delayed-handling of a single wheel movement
|
|
39
|
+
_defineProperty(this, "_finishTimeout", void 0);
|
|
40
|
+
// used to delay final '{move,zoom}end' events
|
|
41
|
+
_defineProperty(this, "_lastWheelEvent", void 0);
|
|
42
|
+
_defineProperty(this, "_lastWheelEventTime", void 0);
|
|
43
|
+
_defineProperty(this, "_startZoom", void 0);
|
|
44
|
+
_defineProperty(this, "_targetZoom", void 0);
|
|
45
|
+
_defineProperty(this, "_delta", void 0);
|
|
46
|
+
_defineProperty(this, "_easing", void 0);
|
|
47
|
+
_defineProperty(this, "_prevEase", void 0);
|
|
48
|
+
_defineProperty(this, "_frameId", void 0);
|
|
49
|
+
_defineProperty(this, "_triggerRenderFrame", void 0);
|
|
50
|
+
_defineProperty(this, "_defaultZoomRate", void 0);
|
|
51
|
+
_defineProperty(this, "_wheelZoomRate", void 0);
|
|
52
|
+
_defineProperty(this, "_onTimeout", initialEvent => {
|
|
53
|
+
this._type = 'wheel';
|
|
54
|
+
this._delta -= this._lastValue;
|
|
55
|
+
if (!this._active) {
|
|
56
|
+
this._start(initialEvent);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
this._map = map;
|
|
60
|
+
this._tr = new TransformProvider(map);
|
|
61
|
+
this._triggerRenderFrame = triggerRenderFrame;
|
|
62
|
+
this._delta = 0;
|
|
63
|
+
this._defaultZoomRate = defaultZoomRate;
|
|
64
|
+
this._wheelZoomRate = wheelZoomRate;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Set the zoom rate of a trackpad
|
|
69
|
+
* @param zoomRate - 1/100 The rate used to scale trackpad movement to a zoom value.
|
|
70
|
+
* @example
|
|
71
|
+
* Speed up trackpad zoom
|
|
72
|
+
* ```ts
|
|
73
|
+
* map.scrollZoom.setZoomRate(1/25);
|
|
74
|
+
* ```
|
|
75
|
+
*/
|
|
76
|
+
setZoomRate(zoomRate) {
|
|
77
|
+
this._defaultZoomRate = zoomRate;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* Set the zoom rate of a mouse wheel
|
|
82
|
+
* @param wheelZoomRate - 1/450 The rate used to scale mouse wheel movement to a zoom value.
|
|
83
|
+
* @example
|
|
84
|
+
* Slow down zoom of mouse wheel
|
|
85
|
+
* ```ts
|
|
86
|
+
* map.scrollZoom.setWheelZoomRate(1/600);
|
|
87
|
+
* ```
|
|
88
|
+
*/
|
|
89
|
+
setWheelZoomRate(wheelZoomRate) {
|
|
90
|
+
this._wheelZoomRate = wheelZoomRate;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled.
|
|
95
|
+
* @returns `true` if the "scroll to zoom" interaction is enabled.
|
|
96
|
+
*/
|
|
97
|
+
isEnabled() {
|
|
98
|
+
return !!this._enabled;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/*
|
|
102
|
+
* Active state is turned on and off with every scroll wheel event and is set back to false before the map
|
|
103
|
+
* render is called, so _active is not a good candidate for determining if a scroll zoom animation is in
|
|
104
|
+
* progress.
|
|
105
|
+
*/
|
|
106
|
+
isActive() {
|
|
107
|
+
return !!this._active || this._finishTimeout !== undefined;
|
|
108
|
+
}
|
|
109
|
+
isZooming() {
|
|
110
|
+
return !!this._zooming;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Enables the "scroll to zoom" interaction.
|
|
115
|
+
*
|
|
116
|
+
* @param options - Options object.
|
|
117
|
+
* @example
|
|
118
|
+
* ```ts
|
|
119
|
+
* map.scrollZoom.enable();
|
|
120
|
+
* map.scrollZoom.enable({ around: 'center' })
|
|
121
|
+
* ```
|
|
122
|
+
*/
|
|
123
|
+
enable(options) {
|
|
124
|
+
if (this.isEnabled()) return;
|
|
125
|
+
this._enabled = true;
|
|
126
|
+
this._aroundCenter = !!options && options.around === 'center';
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Disables the "scroll to zoom" interaction.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* map.scrollZoom.disable();
|
|
135
|
+
* ```
|
|
136
|
+
*/
|
|
137
|
+
disable() {
|
|
138
|
+
if (!this.isEnabled()) return;
|
|
139
|
+
this._enabled = false;
|
|
140
|
+
}
|
|
141
|
+
wheel(e) {
|
|
142
|
+
if (!this.isEnabled()) return;
|
|
143
|
+
if (this._map.cooperativeGestures.isEnabled() && !e[this._map.cooperativeGestures._bypassKey]) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
let value = e.deltaMode === WheelEvent.DOM_DELTA_LINE ? e.deltaY * 40 : e.deltaY;
|
|
147
|
+
const now = browser.now(),
|
|
148
|
+
timeDelta = now - (this._lastWheelEventTime || 0);
|
|
149
|
+
this._lastWheelEventTime = now;
|
|
150
|
+
if (value !== 0 && value % wheelZoomDelta === 0) {
|
|
151
|
+
// This one is definitely a mouse wheel event.
|
|
152
|
+
this._type = 'wheel';
|
|
153
|
+
} else if (value !== 0 && Math.abs(value) < 4) {
|
|
154
|
+
// This one is definitely a trackpad event because it is so small.
|
|
155
|
+
this._type = 'trackpad';
|
|
156
|
+
} else if (timeDelta > 400) {
|
|
157
|
+
// This is likely a new scroll action.
|
|
158
|
+
this._type = null;
|
|
159
|
+
this._lastValue = value;
|
|
160
|
+
|
|
161
|
+
// Start a timeout in case this was a singular event, and dely it by up to 40ms.
|
|
162
|
+
this._timeout = setTimeout(this._onTimeout, 40, e);
|
|
163
|
+
} else if (!this._type) {
|
|
164
|
+
// This is a repeating event, but we don't know the type of event just yet.
|
|
165
|
+
// If the delta per time is small, we assume it's a fast trackpad; otherwise we switch into wheel mode.
|
|
166
|
+
this._type = Math.abs(timeDelta * value) < 200 ? 'trackpad' : 'wheel';
|
|
167
|
+
|
|
168
|
+
// Make sure our delayed event isn't fired again, because we accumulate
|
|
169
|
+
// the previous event (which was less than 40ms ago) into this event.
|
|
170
|
+
if (this._timeout) {
|
|
171
|
+
clearTimeout(this._timeout);
|
|
172
|
+
this._timeout = null;
|
|
173
|
+
value += this._lastValue;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
// Slow down zoom if shift key is held for more precise zooming
|
|
178
|
+
if (e.shiftKey && value) value = value / 4;
|
|
179
|
+
|
|
180
|
+
// Only fire the callback if we actually know what type of scrolling device the user uses.
|
|
181
|
+
if (this._type) {
|
|
182
|
+
this._lastWheelEvent = e;
|
|
183
|
+
this._delta -= value;
|
|
184
|
+
if (!this._active) {
|
|
185
|
+
this._start(e);
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
e.preventDefault();
|
|
189
|
+
}
|
|
190
|
+
_start(e) {
|
|
191
|
+
if (!this._delta) return;
|
|
192
|
+
if (this._frameId) {
|
|
193
|
+
this._frameId = null;
|
|
194
|
+
}
|
|
195
|
+
this._active = true;
|
|
196
|
+
if (!this.isZooming()) {
|
|
197
|
+
this._zooming = true;
|
|
198
|
+
}
|
|
199
|
+
if (this._finishTimeout) {
|
|
200
|
+
clearTimeout(this._finishTimeout);
|
|
201
|
+
delete this._finishTimeout;
|
|
202
|
+
}
|
|
203
|
+
const pos = DOM.mousePos(this._map.getCanvasContainer(), e);
|
|
204
|
+
const tr = this._tr;
|
|
205
|
+
if (pos.y > tr.transform.height / 2 - tr.transform.getHorizon()) {
|
|
206
|
+
this._around = LngLat.convert(this._aroundCenter ? tr.center : tr.unproject(pos));
|
|
207
|
+
} else {
|
|
208
|
+
// Do not use current cursor position if above the horizon to avoid 'unproject' this point
|
|
209
|
+
// as it is not mapped into 'coords' framebuffer or inversible with 'pixelMatrixInverse'.
|
|
210
|
+
this._around = LngLat.convert(tr.center);
|
|
211
|
+
}
|
|
212
|
+
this._aroundPoint = tr.transform.locationPoint(this._around);
|
|
213
|
+
if (!this._frameId) {
|
|
214
|
+
this._frameId = true;
|
|
215
|
+
this._triggerRenderFrame();
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
renderFrame() {
|
|
219
|
+
if (!this._frameId) return;
|
|
220
|
+
this._frameId = null;
|
|
221
|
+
if (!this.isActive()) return;
|
|
222
|
+
const tr = this._tr.transform;
|
|
223
|
+
|
|
224
|
+
// if we've had scroll events since the last render frame, consume the
|
|
225
|
+
// accumulated delta, and update the target zoom level accordingly
|
|
226
|
+
if (this._delta !== 0) {
|
|
227
|
+
// For trackpad events and single mouse wheel ticks, use the default zoom rate
|
|
228
|
+
const zoomRate = this._type === 'wheel' && Math.abs(this._delta) > wheelZoomDelta ? this._wheelZoomRate : this._defaultZoomRate;
|
|
229
|
+
// Scale by sigmoid of scroll wheel delta.
|
|
230
|
+
let scale = maxScalePerFrame / (1 + Math.exp(-Math.abs(this._delta * zoomRate)));
|
|
231
|
+
if (this._delta < 0 && scale !== 0) {
|
|
232
|
+
scale = 1 / scale;
|
|
233
|
+
}
|
|
234
|
+
const fromScale = typeof this._targetZoom === 'number' ? tr.zoomScale(this._targetZoom) : tr.scale;
|
|
235
|
+
this._targetZoom = Math.min(tr.maxZoom, Math.max(tr.minZoom, tr.scaleZoom(fromScale * scale)));
|
|
236
|
+
|
|
237
|
+
// if this is a mouse wheel, refresh the starting zoom and easing
|
|
238
|
+
// function we're using to smooth out the zooming between wheel
|
|
239
|
+
// events
|
|
240
|
+
if (this._type === 'wheel') {
|
|
241
|
+
this._startZoom = tr.zoom;
|
|
242
|
+
this._easing = this._smoothOutEasing(200);
|
|
243
|
+
}
|
|
244
|
+
this._delta = 0;
|
|
245
|
+
}
|
|
246
|
+
const targetZoom = typeof this._targetZoom === 'number' ? this._targetZoom : tr.zoom;
|
|
247
|
+
const startZoom = this._startZoom;
|
|
248
|
+
const easing = this._easing;
|
|
249
|
+
let finished = false;
|
|
250
|
+
let zoom;
|
|
251
|
+
if (this._type === 'wheel' && startZoom && easing) {
|
|
252
|
+
const t = Math.min((browser.now() - this._lastWheelEventTime) / 200, 1);
|
|
253
|
+
const k = easing(t);
|
|
254
|
+
zoom = interpolates.number(startZoom, targetZoom, k);
|
|
255
|
+
if (t < 1) {
|
|
256
|
+
if (!this._frameId) {
|
|
257
|
+
this._frameId = true;
|
|
258
|
+
}
|
|
259
|
+
} else {
|
|
260
|
+
finished = true;
|
|
261
|
+
}
|
|
262
|
+
} else {
|
|
263
|
+
zoom = targetZoom;
|
|
264
|
+
finished = true;
|
|
265
|
+
}
|
|
266
|
+
this._active = true;
|
|
267
|
+
if (finished) {
|
|
268
|
+
this._active = false;
|
|
269
|
+
this._finishTimeout = setTimeout(() => {
|
|
270
|
+
this._zooming = false;
|
|
271
|
+
this._triggerRenderFrame();
|
|
272
|
+
delete this._targetZoom;
|
|
273
|
+
delete this._finishTimeout;
|
|
274
|
+
}, 200);
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
noInertia: true,
|
|
278
|
+
needsRenderFrame: !finished,
|
|
279
|
+
zoomDelta: zoom - tr.zoom,
|
|
280
|
+
around: this._aroundPoint,
|
|
281
|
+
originalEvent: this._lastWheelEvent
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
_smoothOutEasing(duration) {
|
|
285
|
+
let easing = defaultEasing;
|
|
286
|
+
if (this._prevEase) {
|
|
287
|
+
const currentEase = this._prevEase;
|
|
288
|
+
const t = (browser.now() - currentEase.start) / currentEase.duration;
|
|
289
|
+
const speed = currentEase.easing(t + 0.01) - currentEase.easing(t);
|
|
290
|
+
|
|
291
|
+
// Quick hack to make new bezier that is continuous with last
|
|
292
|
+
const x = 0.27 / Math.sqrt(speed * speed + 0.0001) * 0.01;
|
|
293
|
+
const y = Math.sqrt(0.27 * 0.27 - x * x);
|
|
294
|
+
easing = bezier(x, y, 0.25, 1);
|
|
295
|
+
}
|
|
296
|
+
this._prevEase = {
|
|
297
|
+
start: browser.now(),
|
|
298
|
+
duration,
|
|
299
|
+
easing
|
|
300
|
+
};
|
|
301
|
+
return easing;
|
|
302
|
+
}
|
|
303
|
+
reset() {
|
|
304
|
+
this._active = false;
|
|
305
|
+
this._zooming = false;
|
|
306
|
+
delete this._targetZoom;
|
|
307
|
+
if (this._finishTimeout) {
|
|
308
|
+
clearTimeout(this._finishTimeout);
|
|
309
|
+
delete this._finishTimeout;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { ClickZoomHandler } from '../click_zoom';
|
|
2
|
+
import type { TapZoomHandler } from '../tap_zoom';
|
|
3
|
+
/**
|
|
4
|
+
* The `DoubleClickZoomHandler` allows the user to zoom the map at a point by
|
|
5
|
+
* double clicking or double tapping.
|
|
6
|
+
*
|
|
7
|
+
* @group Handlers
|
|
8
|
+
*/
|
|
9
|
+
export declare class DoubleClickZoomHandler {
|
|
10
|
+
_clickZoom: ClickZoomHandler;
|
|
11
|
+
_tapZoom: TapZoomHandler;
|
|
12
|
+
/** @internal */
|
|
13
|
+
constructor(clickZoom: ClickZoomHandler, TapZoom: TapZoomHandler);
|
|
14
|
+
/**
|
|
15
|
+
* Enables the "double click to zoom" interaction.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* map.doubleClickZoom.enable();
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
enable(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Disables the "double click to zoom" interaction.
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* ```ts
|
|
28
|
+
* map.doubleClickZoom.disable();
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
disable(): void;
|
|
32
|
+
/**
|
|
33
|
+
* Returns a Boolean indicating whether the "double click to zoom" interaction is enabled.
|
|
34
|
+
*
|
|
35
|
+
* @returns `true` if the "double click to zoom" interaction is enabled.
|
|
36
|
+
*/
|
|
37
|
+
isEnabled(): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Returns a Boolean indicating whether the "double click to zoom" interaction is active, i.e. currently being used.
|
|
40
|
+
*
|
|
41
|
+
* @returns `true` if the "double click to zoom" interaction is active.
|
|
42
|
+
*/
|
|
43
|
+
isActive(): boolean;
|
|
44
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
/**
|
|
3
|
+
* The `DoubleClickZoomHandler` allows the user to zoom the map at a point by
|
|
4
|
+
* double clicking or double tapping.
|
|
5
|
+
*
|
|
6
|
+
* @group Handlers
|
|
7
|
+
*/
|
|
8
|
+
export class DoubleClickZoomHandler {
|
|
9
|
+
/** @internal */
|
|
10
|
+
constructor(clickZoom, TapZoom) {
|
|
11
|
+
_defineProperty(this, "_clickZoom", void 0);
|
|
12
|
+
_defineProperty(this, "_tapZoom", void 0);
|
|
13
|
+
this._clickZoom = clickZoom;
|
|
14
|
+
this._tapZoom = TapZoom;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Enables the "double click to zoom" interaction.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* map.doubleClickZoom.enable();
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
enable() {
|
|
26
|
+
this._clickZoom.enable();
|
|
27
|
+
this._tapZoom.enable();
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Disables the "double click to zoom" interaction.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* map.doubleClickZoom.disable();
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
disable() {
|
|
39
|
+
this._clickZoom.disable();
|
|
40
|
+
this._tapZoom.disable();
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Returns a Boolean indicating whether the "double click to zoom" interaction is enabled.
|
|
45
|
+
*
|
|
46
|
+
* @returns `true` if the "double click to zoom" interaction is enabled.
|
|
47
|
+
*/
|
|
48
|
+
isEnabled() {
|
|
49
|
+
return this._clickZoom.isEnabled() && this._tapZoom.isEnabled();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Returns a Boolean indicating whether the "double click to zoom" interaction is active, i.e. currently being used.
|
|
54
|
+
*
|
|
55
|
+
* @returns `true` if the "double click to zoom" interaction is active.
|
|
56
|
+
*/
|
|
57
|
+
isActive() {
|
|
58
|
+
return this._clickZoom.isActive() || this._tapZoom.isActive();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import type { MousePanHandler } from '../mouse';
|
|
2
|
+
import type { TouchPanHandler } from '../touch_pan';
|
|
3
|
+
/**
|
|
4
|
+
* A {@link DragPanHandler} options object
|
|
5
|
+
*/
|
|
6
|
+
export type DragPanOptions = {
|
|
7
|
+
/**
|
|
8
|
+
* factor used to scale the drag velocity
|
|
9
|
+
* @defaultValue 0
|
|
10
|
+
*/
|
|
11
|
+
linearity?: number;
|
|
12
|
+
/**
|
|
13
|
+
* easing function applied to `map.panTo` when applying the drag.
|
|
14
|
+
* @param t - the easing function
|
|
15
|
+
* @defaultValue bezier(0, 0, 0.3, 1)
|
|
16
|
+
*/
|
|
17
|
+
easing?: (t: number) => number;
|
|
18
|
+
/**
|
|
19
|
+
* the maximum value of the drag velocity.
|
|
20
|
+
* @defaultValue 1400
|
|
21
|
+
*/
|
|
22
|
+
deceleration?: number;
|
|
23
|
+
/**
|
|
24
|
+
* the rate at which the speed reduces after the pan ends.
|
|
25
|
+
* @defaultValue 2500
|
|
26
|
+
*/
|
|
27
|
+
maxSpeed?: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The `DragPanHandler` allows the user to pan the map by clicking and dragging
|
|
31
|
+
* the cursor.
|
|
32
|
+
*
|
|
33
|
+
* @group Handlers
|
|
34
|
+
*/
|
|
35
|
+
export declare class DragPanHandler {
|
|
36
|
+
_el: HTMLElement;
|
|
37
|
+
_mousePan: MousePanHandler;
|
|
38
|
+
_touchPan: TouchPanHandler;
|
|
39
|
+
_inertiaOptions: DragPanOptions | boolean;
|
|
40
|
+
/** @internal */
|
|
41
|
+
constructor(el: HTMLElement, mousePan: MousePanHandler, touchPan: TouchPanHandler);
|
|
42
|
+
/**
|
|
43
|
+
* Enables the "drag to pan" interaction.
|
|
44
|
+
*
|
|
45
|
+
* @param options - Options object
|
|
46
|
+
* @example
|
|
47
|
+
* ```ts
|
|
48
|
+
* map.dragPan.enable();
|
|
49
|
+
* map.dragPan.enable({
|
|
50
|
+
* linearity: 0.3,
|
|
51
|
+
* easing: bezier(0, 0, 0.3, 1),
|
|
52
|
+
* maxSpeed: 1400,
|
|
53
|
+
* deceleration: 2500,
|
|
54
|
+
* });
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
enable(options?: DragPanOptions | boolean): void;
|
|
58
|
+
/**
|
|
59
|
+
* Disables the "drag to pan" interaction.
|
|
60
|
+
*
|
|
61
|
+
* @example
|
|
62
|
+
* ```ts
|
|
63
|
+
* map.dragPan.disable();
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
disable(): void;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a Boolean indicating whether the "drag to pan" interaction is enabled.
|
|
69
|
+
*
|
|
70
|
+
* @returns `true` if the "drag to pan" interaction is enabled.
|
|
71
|
+
*/
|
|
72
|
+
isEnabled(): boolean;
|
|
73
|
+
/**
|
|
74
|
+
* Returns a Boolean indicating whether the "drag to pan" interaction is active, i.e. currently being used.
|
|
75
|
+
*
|
|
76
|
+
* @returns `true` if the "drag to pan" interaction is active.
|
|
77
|
+
*/
|
|
78
|
+
isActive(): boolean;
|
|
79
|
+
}
|