@antv/l7-map 2.21.1 → 2.21.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/es/camera.js +595 -674
- package/es/earthmap.js +313 -276
- package/es/geo/edge_insets.js +57 -72
- package/es/geo/lng_lat.js +50 -64
- package/es/geo/lng_lat_bounds.js +101 -137
- package/es/geo/mercator.js +23 -35
- package/es/geo/point.js +150 -221
- package/es/geo/simple.js +22 -34
- package/es/geo/transform.js +839 -905
- package/es/handler/blockable_map_event.js +46 -66
- package/es/handler/box_zoom.js +125 -143
- package/es/handler/click_zoom.js +37 -51
- package/es/handler/events/event.js +11 -9
- package/es/handler/events/map_mouse_event.js +39 -54
- package/es/handler/events/map_touch_event.js +54 -73
- package/es/handler/events/map_wheel_event.js +22 -38
- package/es/handler/events/render_event.js +6 -23
- package/es/handler/handler_inertia.js +98 -113
- package/es/handler/handler_manager.js +349 -437
- package/es/handler/handler_util.js +2 -2
- package/es/handler/keyboard.js +98 -110
- package/es/handler/map_event.js +81 -117
- package/es/handler/mouse/mouse_handler.js +81 -100
- package/es/handler/mouse/mousepan_handler.js +16 -39
- package/es/handler/mouse/mousepitch_hander.js +18 -40
- package/es/handler/mouse/mouserotate_hander.js +18 -40
- package/es/handler/mouse/util.js +7 -5
- package/es/handler/scroll_zoom.js +221 -231
- package/es/handler/shim/dblclick_zoom.js +36 -47
- package/es/handler/shim/drag_pan.js +41 -50
- package/es/handler/shim/drag_rotate.js +38 -48
- package/es/handler/shim/touch_zoom_rotate.js +68 -79
- package/es/handler/tap/single_tap_recognizer.js +60 -80
- package/es/handler/tap/tap_drag_zoom.js +72 -89
- package/es/handler/tap/tap_recognizer.js +37 -45
- package/es/handler/tap/tap_zoom.js +67 -95
- package/es/handler/touch/touch_pan.js +77 -96
- package/es/handler/touch/touch_pitch.js +61 -79
- package/es/handler/touch/touch_rotate.js +47 -67
- package/es/handler/touch/touch_zoom.js +29 -46
- package/es/handler/touch/two_touch.js +79 -104
- package/es/hash.js +75 -88
- package/es/map.js +318 -284
- package/es/util.js +18 -37
- package/es/utils/Aabb.js +60 -100
- package/es/utils/dom.js +32 -55
- package/es/utils/performance.js +25 -29
- package/es/utils/primitives.js +33 -42
- package/es/utils/task_queue.js +47 -76
- package/lib/camera.d.ts +86 -0
- package/lib/camera.js +597 -672
- package/lib/earthmap.d.ts +69 -0
- package/lib/earthmap.js +314 -276
- package/lib/geo/edge_insets.d.ts +54 -0
- package/lib/geo/edge_insets.js +58 -70
- package/lib/geo/lng_lat.d.ts +18 -0
- package/lib/geo/lng_lat.js +50 -62
- package/lib/geo/lng_lat_bounds.d.ts +25 -0
- package/lib/geo/lng_lat_bounds.js +102 -136
- package/lib/geo/mercator.d.ts +30 -0
- package/lib/geo/mercator.js +26 -37
- package/lib/geo/point.d.ts +40 -0
- package/lib/geo/point.js +151 -220
- package/lib/geo/simple.d.ts +30 -0
- package/lib/geo/simple.js +25 -36
- package/lib/geo/transform.d.ts +198 -0
- package/lib/geo/transform.js +844 -907
- package/lib/handler/IHandler.d.ts +34 -0
- package/lib/handler/blockable_map_event.d.ts +17 -0
- package/lib/handler/blockable_map_event.js +48 -65
- package/lib/handler/box_zoom.d.ts +59 -0
- package/lib/handler/box_zoom.js +126 -143
- package/lib/handler/click_zoom.d.ts +16 -0
- package/lib/handler/click_zoom.js +38 -50
- package/lib/handler/events/event.d.ts +4 -0
- package/lib/handler/events/event.js +12 -9
- package/lib/handler/events/index.d.ts +4 -0
- package/lib/handler/events/index.js +3 -3
- package/lib/handler/events/map_mouse_event.d.ts +34 -0
- package/lib/handler/events/map_mouse_event.js +41 -52
- package/lib/handler/events/map_touch_event.d.ts +57 -0
- package/lib/handler/events/map_touch_event.js +56 -71
- package/lib/handler/events/map_wheel_event.d.ts +33 -0
- package/lib/handler/events/map_wheel_event.js +23 -37
- package/lib/handler/events/render_event.d.ts +5 -0
- package/lib/handler/events/render_event.js +7 -22
- package/lib/handler/handler_inertia.d.ts +23 -0
- package/lib/handler/handler_inertia.js +102 -112
- package/lib/handler/handler_manager.d.ts +61 -0
- package/lib/handler/handler_manager.js +351 -437
- package/lib/handler/handler_util.d.ts +4 -0
- package/lib/handler/handler_util.js +2 -2
- package/lib/handler/keyboard.d.ts +36 -0
- package/lib/handler/keyboard.js +98 -110
- package/lib/handler/map_event.d.ts +29 -0
- package/lib/handler/map_event.js +83 -116
- package/lib/handler/mouse/index.d.ts +4 -0
- package/lib/handler/mouse/index.js +3 -3
- package/lib/handler/mouse/mouse_handler.d.ts +22 -0
- package/lib/handler/mouse/mouse_handler.js +83 -99
- package/lib/handler/mouse/mousepan_handler.d.ts +10 -0
- package/lib/handler/mouse/mousepan_handler.js +19 -38
- package/lib/handler/mouse/mousepitch_hander.d.ts +9 -0
- package/lib/handler/mouse/mousepitch_hander.js +21 -39
- package/lib/handler/mouse/mouserotate_hander.d.ts +9 -0
- package/lib/handler/mouse/mouserotate_hander.js +21 -39
- package/lib/handler/mouse/util.d.ts +6 -0
- package/lib/handler/mouse/util.js +7 -6
- package/lib/handler/scroll_zoom.d.ts +93 -0
- package/lib/handler/scroll_zoom.js +221 -231
- package/lib/handler/shim/dblclick_zoom.d.ts +40 -0
- package/lib/handler/shim/dblclick_zoom.js +37 -46
- package/lib/handler/shim/drag_pan.d.ts +61 -0
- package/lib/handler/shim/drag_pan.js +42 -49
- package/lib/handler/shim/drag_rotate.d.ts +46 -0
- package/lib/handler/shim/drag_rotate.js +39 -47
- package/lib/handler/shim/touch_zoom_rotate.d.ts +70 -0
- package/lib/handler/shim/touch_zoom_rotate.js +69 -78
- package/lib/handler/tap/single_tap_recognizer.d.ts +20 -0
- package/lib/handler/tap/single_tap_recognizer.js +63 -79
- package/lib/handler/tap/tap_drag_zoom.d.ts +22 -0
- package/lib/handler/tap/tap_drag_zoom.js +74 -88
- package/lib/handler/tap/tap_recognizer.d.ts +17 -0
- package/lib/handler/tap/tap_recognizer.js +41 -47
- package/lib/handler/tap/tap_zoom.d.ts +22 -0
- package/lib/handler/tap/tap_zoom.js +69 -94
- package/lib/handler/touch/index.d.ts +5 -0
- package/lib/handler/touch/index.js +4 -4
- package/lib/handler/touch/touch_pan.d.ts +30 -0
- package/lib/handler/touch/touch_pan.js +79 -95
- package/lib/handler/touch/touch_pitch.d.ts +13 -0
- package/lib/handler/touch/touch_pitch.js +64 -78
- package/lib/handler/touch/touch_rotate.d.ts +12 -0
- package/lib/handler/touch/touch_rotate.js +50 -66
- package/lib/handler/touch/touch_zoom.d.ts +12 -0
- package/lib/handler/touch/touch_zoom.js +32 -45
- package/lib/handler/touch/two_touch.d.ts +23 -0
- package/lib/handler/touch/two_touch.js +81 -103
- package/lib/hash.d.ts +14 -0
- package/lib/hash.js +75 -88
- package/lib/index.d.ts +4 -0
- package/lib/index.js +4 -4
- package/lib/interface.d.ts +34 -0
- package/lib/map.d.ts +70 -0
- package/lib/map.js +319 -284
- package/lib/util.d.ts +25 -0
- package/lib/util.js +20 -36
- package/lib/utils/Aabb.d.ts +12 -0
- package/lib/utils/Aabb.js +61 -99
- package/lib/utils/dom.d.ts +4 -0
- package/lib/utils/dom.js +34 -55
- package/lib/utils/performance.d.ts +17 -0
- package/lib/utils/performance.js +25 -29
- package/lib/utils/primitives.d.ts +6 -0
- package/lib/utils/primitives.js +34 -41
- package/lib/utils/task_queue.d.ts +13 -0
- package/lib/utils/task_queue.js +47 -76
- package/package.json +25 -32
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _classCallCheck from "@babel/runtime/helpers/esm/classCallCheck";
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
3
1
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
4
2
|
// @ts-ignore
|
|
5
3
|
|
|
@@ -7,74 +5,94 @@ import LngLat from "../geo/lng_lat";
|
|
|
7
5
|
import { bezier, ease, interpolate, now } from "../util";
|
|
8
6
|
import DOM from "../utils/dom";
|
|
9
7
|
// deltaY value for mouse scroll wheel identification
|
|
10
|
-
|
|
8
|
+
const wheelZoomDelta = 4.000244140625;
|
|
11
9
|
|
|
12
10
|
// These magic numbers control the rate of zoom. Trackpad events fire at a greater
|
|
13
11
|
// frequency than mouse scroll wheel, so reduce the zoom rate per wheel tick
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
const defaultZoomRate = 1 / 100;
|
|
13
|
+
const wheelZoomRate = 1 / 450;
|
|
16
14
|
|
|
17
15
|
// upper bound on how much we scale the map in any single render frame; this
|
|
18
16
|
// is used to limit zoom rate in the case of very fast scrolling
|
|
19
|
-
|
|
17
|
+
const maxScalePerFrame = 2;
|
|
20
18
|
|
|
21
19
|
/**
|
|
22
20
|
* The `ScrollZoomHandler` allows the user to zoom the map by scrolling.
|
|
23
21
|
*/
|
|
24
|
-
|
|
25
|
-
// used for delayed-handling of a single wheel movement
|
|
26
|
-
// used to delay final '{move,zoom}end' events
|
|
27
|
-
|
|
22
|
+
class ScrollZoomHandler {
|
|
28
23
|
/**
|
|
29
24
|
* @private
|
|
30
25
|
*/
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
_defineProperty(this, "
|
|
35
|
-
|
|
26
|
+
constructor(map, handler) {
|
|
27
|
+
_defineProperty(this, "map", void 0);
|
|
28
|
+
_defineProperty(this, "el", 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, "handler", void 0);
|
|
50
|
+
_defineProperty(this, "defaultZoomRate", void 0);
|
|
51
|
+
_defineProperty(this, "wheelZoomRate", void 0);
|
|
52
|
+
_defineProperty(this, "onScrollFrame", () => {
|
|
53
|
+
if (!this.frameId) {
|
|
36
54
|
return;
|
|
37
55
|
}
|
|
38
|
-
|
|
39
|
-
if (!
|
|
56
|
+
this.frameId = null;
|
|
57
|
+
if (!this.isActive()) {
|
|
40
58
|
return;
|
|
41
59
|
}
|
|
42
|
-
|
|
60
|
+
const tr = this.map.transform;
|
|
43
61
|
|
|
44
62
|
// if we've had scroll events since the last render frame, consume the
|
|
45
63
|
// accumulated delta, and update the target zoom level accordingly
|
|
46
|
-
if (
|
|
64
|
+
if (this.delta !== 0) {
|
|
47
65
|
// For trackpad events and single mouse wheel ticks, use the default zoom rate
|
|
48
|
-
|
|
66
|
+
const zoomRate = this.type === 'wheel' && Math.abs(this.delta) > wheelZoomDelta ? this.wheelZoomRate : this.defaultZoomRate;
|
|
49
67
|
// Scale by sigmoid of scroll wheel delta.
|
|
50
|
-
|
|
51
|
-
if (
|
|
68
|
+
let scale = maxScalePerFrame / (1 + Math.exp(-Math.abs(this.delta * zoomRate)));
|
|
69
|
+
if (this.delta < 0 && scale !== 0) {
|
|
52
70
|
scale = 1 / scale;
|
|
53
71
|
}
|
|
54
|
-
|
|
55
|
-
|
|
72
|
+
const fromScale = typeof this.targetZoom === 'number' ? tr.zoomScale(this.targetZoom) : tr.scale;
|
|
73
|
+
this.targetZoom = Math.min(tr.maxZoom, Math.max(tr.minZoom, tr.scaleZoom(fromScale * scale)));
|
|
56
74
|
|
|
57
75
|
// if this is a mouse wheel, refresh the starting zoom and easing
|
|
58
76
|
// function we're using to smooth out the zooming between wheel
|
|
59
77
|
// events
|
|
60
|
-
if (
|
|
61
|
-
|
|
62
|
-
|
|
78
|
+
if (this.type === 'wheel') {
|
|
79
|
+
this.startZoom = tr.zoom;
|
|
80
|
+
this.easing = this.smoothOutEasing(200);
|
|
63
81
|
}
|
|
64
|
-
|
|
82
|
+
this.delta = 0;
|
|
65
83
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
if (
|
|
72
|
-
|
|
73
|
-
|
|
84
|
+
const targetZoom = typeof this.targetZoom === 'number' ? this.targetZoom : tr.zoom;
|
|
85
|
+
const startZoom = this.startZoom;
|
|
86
|
+
const easing = this.easing;
|
|
87
|
+
let finished = false;
|
|
88
|
+
let zoom;
|
|
89
|
+
if (this.type === 'wheel' && startZoom && easing) {
|
|
90
|
+
const t = Math.min((now() - this.lastWheelEventTime) / 200, 1);
|
|
91
|
+
const k = easing(t);
|
|
74
92
|
zoom = interpolate(startZoom, targetZoom, k);
|
|
75
93
|
if (t < 1) {
|
|
76
|
-
if (!
|
|
77
|
-
|
|
94
|
+
if (!this.frameId) {
|
|
95
|
+
this.frameId = true;
|
|
78
96
|
}
|
|
79
97
|
} else {
|
|
80
98
|
finished = true;
|
|
@@ -83,25 +101,25 @@ var ScrollZoomHandler = /*#__PURE__*/function () {
|
|
|
83
101
|
zoom = targetZoom;
|
|
84
102
|
finished = true;
|
|
85
103
|
}
|
|
86
|
-
|
|
104
|
+
this.active = true;
|
|
87
105
|
if (finished) {
|
|
88
|
-
|
|
106
|
+
this.active = false;
|
|
89
107
|
// @ts-ignore
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
108
|
+
this.finishTimeout = setTimeout(() => {
|
|
109
|
+
this.zooming = false;
|
|
110
|
+
this.handler.triggerRenderFrame();
|
|
93
111
|
// @ts-ignore
|
|
94
|
-
delete
|
|
112
|
+
delete this.targetZoom;
|
|
95
113
|
// @ts-ignore
|
|
96
|
-
delete
|
|
114
|
+
delete this.finishTimeout;
|
|
97
115
|
}, 200);
|
|
98
116
|
}
|
|
99
117
|
return {
|
|
100
118
|
noInertia: true,
|
|
101
119
|
needsRenderFrame: !finished,
|
|
102
120
|
zoomDelta: zoom - tr.zoom,
|
|
103
|
-
around:
|
|
104
|
-
originalEvent:
|
|
121
|
+
around: this.aroundPoint,
|
|
122
|
+
originalEvent: this.lastWheelEvent
|
|
105
123
|
};
|
|
106
124
|
});
|
|
107
125
|
this.map = map;
|
|
@@ -119,207 +137,179 @@ var ScrollZoomHandler = /*#__PURE__*/function () {
|
|
|
119
137
|
* // Speed up trackpad zoom
|
|
120
138
|
* map.scrollZoom.setZoomRate(1/25);
|
|
121
139
|
*/
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
this.defaultZoomRate = zoomRate;
|
|
126
|
-
}
|
|
140
|
+
setZoomRate(zoomRate) {
|
|
141
|
+
this.defaultZoomRate = zoomRate;
|
|
142
|
+
}
|
|
127
143
|
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
this.wheelZoomRate = zoomRate;
|
|
139
|
-
}
|
|
144
|
+
/**
|
|
145
|
+
* Set the zoom rate of a mouse wheel
|
|
146
|
+
* @param {number} [wheelZoomRate=1/450] The rate used to scale mouse wheel movement to a zoom value.
|
|
147
|
+
* @example
|
|
148
|
+
* // Slow down zoom of mouse wheel
|
|
149
|
+
* map.scrollZoom.setWheelZoomRate(1/600);
|
|
150
|
+
*/
|
|
151
|
+
setWheelZoomRate(zoomRate) {
|
|
152
|
+
this.wheelZoomRate = zoomRate;
|
|
153
|
+
}
|
|
140
154
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
return !!this.enabled;
|
|
150
|
-
}
|
|
155
|
+
/**
|
|
156
|
+
* Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled.
|
|
157
|
+
*
|
|
158
|
+
* @returns {boolean} `true` if the "scroll to zoom" interaction is enabled.
|
|
159
|
+
*/
|
|
160
|
+
isEnabled() {
|
|
161
|
+
return !!this.enabled;
|
|
162
|
+
}
|
|
151
163
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
key: "isZooming",
|
|
164
|
-
value: function isZooming() {
|
|
165
|
-
return !!this.zooming;
|
|
166
|
-
}
|
|
164
|
+
/*
|
|
165
|
+
* Active state is turned on and off with every scroll wheel event and is set back to false before the map
|
|
166
|
+
* render is called, so _active is not a good candidate for determining if a scroll zoom animation is in
|
|
167
|
+
* progress.
|
|
168
|
+
*/
|
|
169
|
+
isActive() {
|
|
170
|
+
return !!this.active || this.finishTimeout !== undefined;
|
|
171
|
+
}
|
|
172
|
+
isZooming() {
|
|
173
|
+
return !!this.zooming;
|
|
174
|
+
}
|
|
167
175
|
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
if (this.isEnabled()) {
|
|
183
|
-
return;
|
|
184
|
-
}
|
|
185
|
-
this.enabled = true;
|
|
186
|
-
this.aroundCenter = options && options.around === 'center';
|
|
176
|
+
/**
|
|
177
|
+
* Enables the "scroll to zoom" interaction.
|
|
178
|
+
*
|
|
179
|
+
* @param {Object} [options] Options object.
|
|
180
|
+
* @param {string} [options.around] If "center" is passed, map will zoom around center of map
|
|
181
|
+
*
|
|
182
|
+
* @example
|
|
183
|
+
* map.scrollZoom.enable();
|
|
184
|
+
* @example
|
|
185
|
+
* map.scrollZoom.enable({ around: 'center' })
|
|
186
|
+
*/
|
|
187
|
+
enable(options) {
|
|
188
|
+
if (this.isEnabled()) {
|
|
189
|
+
return;
|
|
187
190
|
}
|
|
191
|
+
this.enabled = true;
|
|
192
|
+
this.aroundCenter = options && options.around === 'center';
|
|
193
|
+
}
|
|
188
194
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
if (!this.isEnabled()) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
this.enabled = false;
|
|
195
|
+
/**
|
|
196
|
+
* Disables the "scroll to zoom" interaction.
|
|
197
|
+
*
|
|
198
|
+
* @example
|
|
199
|
+
* map.scrollZoom.disable();
|
|
200
|
+
*/
|
|
201
|
+
disable() {
|
|
202
|
+
if (!this.isEnabled()) {
|
|
203
|
+
return;
|
|
202
204
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
205
|
+
this.enabled = false;
|
|
206
|
+
}
|
|
207
|
+
wheel(e) {
|
|
208
|
+
if (!this.isEnabled()) {
|
|
209
|
+
return;
|
|
210
|
+
}
|
|
211
|
+
// Remove `any` cast when https://github.com/facebook/flow/issues/4879 is fixed.
|
|
212
|
+
let value = e.deltaMode === window.WheelEvent.DOM_DELTA_LINE ? e.deltaY * 40 : e.deltaY;
|
|
213
|
+
const nowTime = now();
|
|
214
|
+
const timeDelta = nowTime - (this.lastWheelEventTime || 0);
|
|
215
|
+
this.lastWheelEventTime = nowTime;
|
|
216
|
+
if (value !== 0 && value % wheelZoomDelta === 0) {
|
|
217
|
+
// This one is definitely a mouse wheel event.
|
|
218
|
+
this.type = 'wheel';
|
|
219
|
+
} else if (value !== 0 && Math.abs(value) < 4) {
|
|
220
|
+
// This one is definitely a trackpad event because it is so small.
|
|
221
|
+
this.type = 'trackpad';
|
|
222
|
+
} else if (timeDelta > 400) {
|
|
223
|
+
// This is likely a new scroll action.
|
|
224
|
+
this.type = null;
|
|
225
|
+
this.lastValue = value;
|
|
224
226
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
227
|
+
// Start a timeout in case this was a singular event, and dely it by up to 40ms.
|
|
228
|
+
// @ts-ignore
|
|
229
|
+
this.timeout = setTimeout(this.onTimeout, 40, e);
|
|
230
|
+
} else if (!this.type) {
|
|
231
|
+
// This is a repeating event, but we don't know the type of event just yet.
|
|
232
|
+
// If the delta per time is small, we assume it's a fast trackpad; otherwise we switch into wheel mode.
|
|
233
|
+
this.type = Math.abs(timeDelta * value) < 200 ? 'trackpad' : 'wheel';
|
|
232
234
|
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
235
|
+
// Make sure our delayed event isn't fired again, because we accumulate
|
|
236
|
+
// the previous event (which was less than 40ms ago) into this event.
|
|
237
|
+
if (this.timeout) {
|
|
238
|
+
clearTimeout(this.timeout);
|
|
239
|
+
this.timeout = null;
|
|
240
|
+
value += this.lastValue;
|
|
240
241
|
}
|
|
242
|
+
}
|
|
241
243
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
244
|
+
// Slow down zoom if shift key is held for more precise zooming
|
|
245
|
+
if (e.shiftKey && value) {
|
|
246
|
+
value = value / 4;
|
|
247
|
+
}
|
|
248
|
+
// Only fire the callback if we actually know what type of scrolling device the user uses.
|
|
249
|
+
if (this.type) {
|
|
250
|
+
this.lastWheelEvent = e;
|
|
251
|
+
this.delta -= value;
|
|
252
|
+
if (!this.active) {
|
|
253
|
+
this.start(e);
|
|
253
254
|
}
|
|
254
|
-
e.preventDefault();
|
|
255
255
|
}
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
256
|
+
e.preventDefault();
|
|
257
|
+
}
|
|
258
|
+
renderFrame() {
|
|
259
|
+
return this.onScrollFrame();
|
|
260
|
+
}
|
|
261
|
+
reset() {
|
|
262
|
+
this.active = false;
|
|
263
|
+
}
|
|
264
|
+
onTimeout(initialEvent) {
|
|
265
|
+
this.type = 'wheel';
|
|
266
|
+
this.delta -= this.lastValue;
|
|
267
|
+
if (!this.active && this.start) {
|
|
268
|
+
this.start(initialEvent);
|
|
260
269
|
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
270
|
+
}
|
|
271
|
+
start(e) {
|
|
272
|
+
if (!this.delta) {
|
|
273
|
+
return;
|
|
265
274
|
}
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
value: function onTimeout(initialEvent) {
|
|
269
|
-
this.type = 'wheel';
|
|
270
|
-
this.delta -= this.lastValue;
|
|
271
|
-
if (!this.active && this.start) {
|
|
272
|
-
this.start(initialEvent);
|
|
273
|
-
}
|
|
275
|
+
if (this.frameId) {
|
|
276
|
+
this.frameId = null;
|
|
274
277
|
}
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
this.active = true;
|
|
285
|
-
if (!this.isZooming()) {
|
|
286
|
-
this.zooming = true;
|
|
287
|
-
}
|
|
288
|
-
if (this.finishTimeout) {
|
|
289
|
-
clearTimeout(this.finishTimeout);
|
|
290
|
-
// @ts-ignore
|
|
291
|
-
delete this.finishTimeout;
|
|
292
|
-
}
|
|
293
|
-
var pos = DOM.mousePos(this.el, e);
|
|
294
|
-
this.around = LngLat.convert(this.aroundCenter ? this.map.getCenter() : this.map.unproject(pos));
|
|
295
|
-
this.aroundPoint = this.map.transform.locationPoint(this.around);
|
|
296
|
-
if (!this.frameId) {
|
|
297
|
-
this.frameId = true;
|
|
298
|
-
this.handler.triggerRenderFrame();
|
|
299
|
-
}
|
|
278
|
+
this.active = true;
|
|
279
|
+
if (!this.isZooming()) {
|
|
280
|
+
this.zooming = true;
|
|
281
|
+
}
|
|
282
|
+
if (this.finishTimeout) {
|
|
283
|
+
clearTimeout(this.finishTimeout);
|
|
284
|
+
// @ts-ignore
|
|
285
|
+
delete this.finishTimeout;
|
|
300
286
|
}
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
287
|
+
const pos = DOM.mousePos(this.el, e);
|
|
288
|
+
this.around = LngLat.convert(this.aroundCenter ? this.map.getCenter() : this.map.unproject(pos));
|
|
289
|
+
this.aroundPoint = this.map.transform.locationPoint(this.around);
|
|
290
|
+
if (!this.frameId) {
|
|
291
|
+
this.frameId = true;
|
|
292
|
+
this.handler.triggerRenderFrame();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
smoothOutEasing(duration) {
|
|
296
|
+
let easing = ease;
|
|
297
|
+
if (this.prevEase) {
|
|
298
|
+
const preEase = this.prevEase;
|
|
299
|
+
const t = (now() - preEase.start) / preEase.duration;
|
|
300
|
+
const speed = preEase.easing(t + 0.01) - preEase.easing(t);
|
|
309
301
|
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
this.prevEase = {
|
|
316
|
-
start: now(),
|
|
317
|
-
duration: duration,
|
|
318
|
-
easing: easing
|
|
319
|
-
};
|
|
320
|
-
return easing;
|
|
302
|
+
// Quick hack to make new bezier that is continuous with last
|
|
303
|
+
const x = 0.27 / Math.sqrt(speed * speed + 0.0001) * 0.01;
|
|
304
|
+
const y = Math.sqrt(0.27 * 0.27 - x * x);
|
|
305
|
+
easing = bezier(x, y, 0.25, 1);
|
|
321
306
|
}
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
307
|
+
this.prevEase = {
|
|
308
|
+
start: now(),
|
|
309
|
+
duration,
|
|
310
|
+
easing
|
|
311
|
+
};
|
|
312
|
+
return easing;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
325
315
|
export default ScrollZoomHandler;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import
|
|
2
|
-
import _createClass from "@babel/runtime/helpers/esm/createClass";
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
3
2
|
/**
|
|
4
3
|
* The `DoubleClickZoomHandler` allows the user to zoom the map at a point by
|
|
5
4
|
* double clicking or double tapping.
|
|
6
5
|
*/
|
|
7
|
-
|
|
6
|
+
export default class DoubleClickZoomHandler {
|
|
8
7
|
/**
|
|
9
8
|
* @private
|
|
10
9
|
*/
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
constructor(clickZoom, TapZoom) {
|
|
11
|
+
_defineProperty(this, "clickZoom", void 0);
|
|
12
|
+
_defineProperty(this, "tapZoom", void 0);
|
|
13
13
|
this.clickZoom = clickZoom;
|
|
14
14
|
this.tapZoom = TapZoom;
|
|
15
15
|
}
|
|
@@ -20,48 +20,37 @@ var DoubleClickZoomHandler = /*#__PURE__*/function () {
|
|
|
20
20
|
* @example
|
|
21
21
|
* map.doubleClickZoom.enable();
|
|
22
22
|
*/
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
this.tapZoom.enable();
|
|
28
|
-
}
|
|
23
|
+
enable() {
|
|
24
|
+
this.clickZoom.enable();
|
|
25
|
+
this.tapZoom.enable();
|
|
26
|
+
}
|
|
29
27
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.tapZoom.disable();
|
|
41
|
-
}
|
|
28
|
+
/**
|
|
29
|
+
* Disables the "double click to zoom" interaction.
|
|
30
|
+
*
|
|
31
|
+
* @example
|
|
32
|
+
* map.doubleClickZoom.disable();
|
|
33
|
+
*/
|
|
34
|
+
disable() {
|
|
35
|
+
this.clickZoom.disable();
|
|
36
|
+
this.tapZoom.disable();
|
|
37
|
+
}
|
|
42
38
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
return this.clickZoom.isEnabled() && this.tapZoom.isEnabled();
|
|
52
|
-
}
|
|
39
|
+
/**
|
|
40
|
+
* Returns a Boolean indicating whether the "double click to zoom" interaction is enabled.
|
|
41
|
+
*
|
|
42
|
+
* @returns {boolean} `true` if the "double click to zoom" interaction is enabled.
|
|
43
|
+
*/
|
|
44
|
+
isEnabled() {
|
|
45
|
+
return this.clickZoom.isEnabled() && this.tapZoom.isEnabled();
|
|
46
|
+
}
|
|
53
47
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
}]);
|
|
65
|
-
return DoubleClickZoomHandler;
|
|
66
|
-
}();
|
|
67
|
-
export { DoubleClickZoomHandler as default };
|
|
48
|
+
/**
|
|
49
|
+
* Returns a Boolean indicating whether the "double click to zoom" interaction is active, i.e. currently being used.
|
|
50
|
+
*
|
|
51
|
+
* @returns {boolean} `true` if the "double click to zoom" interaction is active.
|
|
52
|
+
*/
|
|
53
|
+
isActive() {
|
|
54
|
+
return this.clickZoom.isActive() || this.tapZoom.isActive();
|
|
55
|
+
}
|
|
56
|
+
}
|