-
-
Notifications
You must be signed in to change notification settings - Fork 640
/
drag_rotate.ts
76 lines (68 loc) · 1.98 KB
/
drag_rotate.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import type {MousePitchHandler, MouseRotateHandler} from '../mouse';
/**
* Options object for `DragRotateHandler`.
*/
export type DragRotateHandlerOptions = {
/**
* Control the map pitch in addition to the bearing
* @defaultValue true
*/
pitchWithRotate: boolean;
}
/**
* The `DragRotateHandler` allows the user to rotate the map by clicking and
* dragging the cursor while holding the right mouse button or `ctrl` key.
*
* @group Handlers
*/
export class DragRotateHandler {
_mouseRotate: MouseRotateHandler;
_mousePitch: MousePitchHandler;
_pitchWithRotate: boolean;
/** @internal */
constructor(options: DragRotateHandlerOptions, mouseRotate: MouseRotateHandler, mousePitch: MousePitchHandler) {
this._pitchWithRotate = options.pitchWithRotate;
this._mouseRotate = mouseRotate;
this._mousePitch = mousePitch;
}
/**
* Enables the "drag to rotate" interaction.
*
* @example
* ```ts
* map.dragRotate.enable();
* ```
*/
enable() {
this._mouseRotate.enable();
if (this._pitchWithRotate) this._mousePitch.enable();
}
/**
* Disables the "drag to rotate" interaction.
*
* @example
* ```ts
* map.dragRotate.disable();
* ```
*/
disable() {
this._mouseRotate.disable();
this._mousePitch.disable();
}
/**
* Returns a Boolean indicating whether the "drag to rotate" interaction is enabled.
*
* @returns `true` if the "drag to rotate" interaction is enabled.
*/
isEnabled() {
return this._mouseRotate.isEnabled() && (!this._pitchWithRotate || this._mousePitch.isEnabled());
}
/**
* Returns a Boolean indicating whether the "drag to rotate" interaction is active, i.e. currently being used.
*
* @returns `true` if the "drag to rotate" interaction is active.
*/
isActive() {
return this._mouseRotate.isActive() || this._mousePitch.isActive();
}
}