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