@mapwhit/tilerenderer 0.50.0 → 0.51.0

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.
Files changed (142) hide show
  1. package/build/min/package.json +1 -1
  2. package/build/min/src/shaders/.dir +0 -0
  3. package/build/min/src/shaders/_prelude.fragment.glsl.js +14 -0
  4. package/build/min/src/shaders/_prelude.vertex.glsl.js +14 -0
  5. package/build/min/src/shaders/background.fragment.glsl.js +5 -0
  6. package/build/min/src/shaders/background.vertex.glsl.js +1 -0
  7. package/build/min/src/shaders/background_pattern.fragment.glsl.js +5 -0
  8. package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -0
  9. package/build/min/src/shaders/circle.fragment.glsl.js +20 -0
  10. package/build/min/src/shaders/circle.vertex.glsl.js +17 -0
  11. package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -0
  12. package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -0
  13. package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -0
  14. package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -0
  15. package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -0
  16. package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -0
  17. package/build/min/src/shaders/debug.fragment.glsl.js +1 -0
  18. package/build/min/src/shaders/debug.vertex.glsl.js +1 -0
  19. package/build/min/src/shaders/fill.fragment.glsl.js +10 -0
  20. package/build/min/src/shaders/fill.vertex.glsl.js +7 -0
  21. package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +5 -0
  22. package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +9 -0
  23. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +15 -0
  24. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +11 -0
  25. package/build/min/src/shaders/fill_outline.fragment.glsl.js +10 -0
  26. package/build/min/src/shaders/fill_outline.vertex.glsl.js +7 -0
  27. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +13 -0
  28. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +9 -0
  29. package/build/min/src/shaders/fill_pattern.fragment.glsl.js +13 -0
  30. package/build/min/src/shaders/fill_pattern.vertex.glsl.js +9 -0
  31. package/build/min/src/shaders/heatmap.fragment.glsl.js +10 -0
  32. package/build/min/src/shaders/heatmap.vertex.glsl.js +8 -0
  33. package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +5 -0
  34. package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -0
  35. package/build/min/src/shaders/hillshade.fragment.glsl.js +7 -0
  36. package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -0
  37. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +8 -0
  38. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -0
  39. package/build/min/src/shaders/line.fragment.glsl.js +12 -0
  40. package/build/min/src/shaders/line.vertex.glsl.js +17 -0
  41. package/build/min/src/shaders/line_gradient.fragment.glsl.js +10 -0
  42. package/build/min/src/shaders/line_gradient.vertex.glsl.js +16 -0
  43. package/build/min/src/shaders/line_pattern.fragment.glsl.js +15 -0
  44. package/build/min/src/shaders/line_pattern.vertex.glsl.js +20 -0
  45. package/build/min/src/shaders/line_sdf.fragment.glsl.js +17 -0
  46. package/build/min/src/shaders/line_sdf.vertex.glsl.js +20 -0
  47. package/build/min/src/shaders/raster.fragment.glsl.js +5 -0
  48. package/build/min/src/shaders/raster.vertex.glsl.js +1 -0
  49. package/build/min/src/shaders/symbol_icon.fragment.glsl.js +9 -0
  50. package/build/min/src/shaders/symbol_icon.vertex.glsl.js +5 -0
  51. package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +19 -0
  52. package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +13 -0
  53. package/package.json +7 -7
  54. package/src/data/bucket/fill_bucket.js +1 -1
  55. package/src/data/bucket/fill_extrusion_bucket.js +2 -2
  56. package/src/data/bucket/line_bucket.js +1 -1
  57. package/src/data/bucket/symbol_bucket.js +2 -2
  58. package/src/data/feature_index.js +1 -1
  59. package/src/data/program_configuration.js +1 -1
  60. package/src/gl/color_mode.js +1 -1
  61. package/src/gl/value.js +1 -1
  62. package/src/render/draw_debug.js +1 -1
  63. package/src/render/draw_fill.js +1 -1
  64. package/src/render/draw_heatmap.js +1 -1
  65. package/src/render/glyph_manager.js +6 -130
  66. package/src/render/painter.js +1 -1
  67. package/src/render/uniform_binding.js +1 -1
  68. package/src/shaders/index.js +50 -50
  69. package/src/source/geojson_worker_source.js +4 -4
  70. package/src/source/geojson_wrapper.js +34 -26
  71. package/src/source/resources/glyphs.js +73 -0
  72. package/src/source/resources/images.js +68 -0
  73. package/src/source/resources/index.js +22 -0
  74. package/src/source/vector_tile_worker_source.js +5 -5
  75. package/src/source/worker.js +6 -5
  76. package/src/source/worker_tile.js +4 -4
  77. package/src/style/properties.js +1 -2
  78. package/src/style/style.js +3 -3
  79. package/src/style/style_layer/symbol_style_layer.js +1 -1
  80. package/src/style/style_layer.js +1 -1
  81. package/src/style-spec/feature_filter/index.js +43 -34
  82. package/src/style-spec/group_by_layout.js +10 -32
  83. package/src/symbol/mergelines.js +0 -2
  84. package/src/symbol/symbol_layout.js +0 -1
  85. package/src/symbol/symbol_size.js +1 -1
  86. package/src/symbol/transform_text.js +0 -1
  87. package/src/ui/map.js +11 -39
  88. package/src/util/browser.js +3 -18
  89. package/src/util/classify_rings.js +1 -1
  90. package/src/util/dom.js +0 -88
  91. package/src/util/find_pole_of_inaccessibility.js +2 -2
  92. package/src/util/web_worker_transfer.js +4 -4
  93. package/src/style/load_glyph_range.js +0 -17
  94. package/src/style-spec/expression/compound_expression.js +0 -132
  95. package/src/style-spec/expression/definitions/assertion.js +0 -116
  96. package/src/style-spec/expression/definitions/at.js +0 -57
  97. package/src/style-spec/expression/definitions/case.js +0 -73
  98. package/src/style-spec/expression/definitions/coalesce.js +0 -66
  99. package/src/style-spec/expression/definitions/coercion.js +0 -120
  100. package/src/style-spec/expression/definitions/collator.js +0 -80
  101. package/src/style-spec/expression/definitions/comparison.js +0 -193
  102. package/src/style-spec/expression/definitions/format.js +0 -97
  103. package/src/style-spec/expression/definitions/index.js +0 -339
  104. package/src/style-spec/expression/definitions/interpolate.js +0 -245
  105. package/src/style-spec/expression/definitions/length.js +0 -54
  106. package/src/style-spec/expression/definitions/let.js +0 -60
  107. package/src/style-spec/expression/definitions/literal.js +0 -69
  108. package/src/style-spec/expression/definitions/match.js +0 -142
  109. package/src/style-spec/expression/definitions/step.js +0 -116
  110. package/src/style-spec/expression/definitions/var.js +0 -38
  111. package/src/style-spec/expression/evaluation_context.js +0 -38
  112. package/src/style-spec/expression/index.js +0 -330
  113. package/src/style-spec/expression/is_constant.js +0 -63
  114. package/src/style-spec/expression/parsing_context.js +0 -221
  115. package/src/style-spec/expression/parsing_error.js +0 -9
  116. package/src/style-spec/expression/runtime_error.js +0 -12
  117. package/src/style-spec/expression/scope.js +0 -34
  118. package/src/style-spec/expression/stops.js +0 -37
  119. package/src/style-spec/expression/types/collator.js +0 -24
  120. package/src/style-spec/expression/types/formatted.js +0 -39
  121. package/src/style-spec/expression/types.js +0 -88
  122. package/src/style-spec/expression/values.js +0 -149
  123. package/src/style-spec/function/convert.js +0 -240
  124. package/src/style-spec/function/index.js +0 -303
  125. package/src/style-spec/util/color.js +0 -73
  126. package/src/style-spec/util/color_spaces.js +0 -128
  127. package/src/style-spec/util/get_type.js +0 -18
  128. package/src/style-spec/util/interpolate.js +0 -21
  129. package/src/style-spec/util/properties.js +0 -17
  130. package/src/style-spec/util/result.js +0 -19
  131. package/src/ui/anchor.js +0 -24
  132. package/src/ui/bind_handlers.js +0 -199
  133. package/src/ui/events.js +0 -210
  134. package/src/ui/handler/box_zoom.js +0 -151
  135. package/src/ui/handler/dblclick_zoom.js +0 -91
  136. package/src/ui/handler/drag_pan.js +0 -285
  137. package/src/ui/handler/drag_rotate.js +0 -290
  138. package/src/ui/handler/frame.js +0 -28
  139. package/src/ui/handler/inertia.js +0 -45
  140. package/src/ui/handler/keyboard.js +0 -148
  141. package/src/ui/handler/scroll_zoom.js +0 -284
  142. package/src/ui/handler/touch_zoom_rotate.js +0 -263
@@ -1,285 +0,0 @@
1
- const assert = require('assert');
2
-
3
- const DOM = require('../../util/dom');
4
- const { bezier } = require('../../util/util');
5
- const { Event } = require('../../util/evented');
6
- const makeFrame = require('./frame');
7
- const makeInertia = require('./inertia');
8
-
9
- const inertiaLinearity = 0.3;
10
- const inertiaEasing = bezier(0, 0, inertiaLinearity, 1);
11
- const inertiaMaxSpeed = 1400; // px/s
12
- const inertiaDeceleration = 2500; // px/s^2
13
-
14
- /**
15
- * The `DragPanHandler` allows the user to pan the map by clicking and dragging
16
- * the cursor.
17
- */
18
- function dragPanHandler(map) {
19
- const _el = map.getCanvasContainer();
20
- const frame = makeFrame(map, onDragFrame);
21
-
22
- let state = 'disabled';
23
- let inertia;
24
- let previousPos;
25
-
26
- /**
27
- * Returns a Boolean indicating whether the "drag to pan" interaction is enabled.
28
- *
29
- * @returns {boolean} `true` if the "drag to pan" interaction is enabled.
30
- */
31
- function isEnabled() {
32
- return state !== 'disabled';
33
- }
34
-
35
- /**
36
- * Returns a Boolean indicating whether the "drag to pan" interaction is active, i.e. currently being used.
37
- *
38
- * @returns {boolean} `true` if the "drag to pan" interaction is active.
39
- */
40
- function isActive() {
41
- return state === 'active';
42
- }
43
-
44
- /**
45
- * Enables the "drag to pan" interaction.
46
- *
47
- * @example
48
- * map.dragPan.enable();
49
- */
50
- function enable() {
51
- if (isEnabled()) return;
52
- map.getCanvasContainer().classList.add('mapboxgl-touch-drag-pan');
53
- state = 'enabled';
54
- }
55
-
56
- /**
57
- * Disables the "drag to pan" interaction.
58
- *
59
- * @example
60
- * map.dragPan.disable();
61
- */
62
- function disable() {
63
- if (!isEnabled()) return;
64
- map.getCanvasContainer().classList.remove('mapboxgl-touch-drag-pan');
65
- switch (state) {
66
- case 'active':
67
- state = 'disabled';
68
- unbind();
69
- deactivate();
70
- fireEvent('dragend');
71
- fireEvent('moveend');
72
- break;
73
- case 'pending':
74
- state = 'disabled';
75
- unbind();
76
- break;
77
- default:
78
- state = 'disabled';
79
- break;
80
- }
81
- }
82
-
83
- function onMouseDown(e) {
84
- if (state !== 'enabled') return;
85
- if (e.ctrlKey || DOM.mouseButton(e) !== 0) return;
86
-
87
- // Bind window-level event listeners for mousemove/up events. In the absence of
88
- // the pointer capture API, which is not supported by all necessary platforms,
89
- // window-level event listeners give us the best shot at capturing events that
90
- // fall outside the map canvas element. Use `{capture: true}` for the move event
91
- // to prevent map move events from being fired during a drag.
92
- window.document.addEventListener('mousemove', onMove, { capture: true });
93
- window.document.addEventListener('mouseup', onMouseUp);
94
-
95
- start(e);
96
- }
97
-
98
- function onTouchStart(e) {
99
- if (state !== 'enabled') return;
100
- if (e.touches.length > 1) return;
101
-
102
- // Bind window-level event listeners for touchmove/end events. In the absence of
103
- // the pointer capture API, which is not supported by all necessary platforms,
104
- // window-level event listeners give us the best shot at capturing events that
105
- // fall outside the map canvas element. Use `{capture: true}` for the move event
106
- // to prevent map move events from being fired during a drag.
107
- window.document.addEventListener('touchmove', onMove, { capture: true, passive: false });
108
- window.document.addEventListener('touchend', onTouchEnd);
109
-
110
- start(e);
111
- }
112
-
113
- function start(e) {
114
- // Deactivate when the window loses focus. Otherwise if a mouseup occurs when the window
115
- // isn't in focus, dragging will continue even though the mouse is no longer pressed.
116
- window.addEventListener('blur', onBlur);
117
-
118
- state = 'pending';
119
- previousPos = DOM.mousePos(_el, e);
120
- inertia = makeInertia(map, calculateInertia);
121
- inertia.update(previousPos);
122
- }
123
-
124
- function onMove(e) {
125
- e.preventDefault();
126
-
127
- const pos = DOM.mousePos(_el, e);
128
- inertia.update(pos);
129
- frame.request(e, pos);
130
-
131
- if (state === 'pending') {
132
- // we treat the first move event (rather than the mousedown event)
133
- // as the start of the drag
134
- state = 'active';
135
- fireEvent('dragstart', e);
136
- fireEvent('movestart', e);
137
- }
138
- }
139
-
140
- /**
141
- * Called in each render frame while dragging is happening.
142
- * @private
143
- */
144
- function onDragFrame(e, pos) {
145
- const tr = map.transform;
146
- tr.setLocationAtPoint(tr.pointLocation(previousPos), pos);
147
- fireEvent('drag', e);
148
- fireEvent('move', e);
149
-
150
- previousPos = pos;
151
- }
152
-
153
- function onMouseUp(e) {
154
- if (DOM.mouseButton(e) !== 0) return;
155
- switch (state) {
156
- case 'active':
157
- state = 'enabled';
158
- DOM.suppressClick();
159
- unbind();
160
- deactivate();
161
- inertialPan(e);
162
- break;
163
- case 'pending':
164
- state = 'enabled';
165
- unbind();
166
- break;
167
- default:
168
- assert(false);
169
- break;
170
- }
171
- }
172
-
173
- function onTouchEnd(e) {
174
- switch (state) {
175
- case 'active':
176
- state = 'enabled';
177
- unbind();
178
- deactivate();
179
- inertialPan(e);
180
- break;
181
- case 'pending':
182
- state = 'enabled';
183
- unbind();
184
- break;
185
- default:
186
- assert(false);
187
- break;
188
- }
189
- }
190
-
191
- function onBlur(e) {
192
- switch (state) {
193
- case 'active':
194
- state = 'enabled';
195
- unbind();
196
- deactivate();
197
- fireEvent('dragend', e);
198
- fireEvent('moveend', e);
199
- break;
200
- case 'pending':
201
- state = 'enabled';
202
- unbind();
203
- break;
204
- default:
205
- assert(false);
206
- break;
207
- }
208
- }
209
-
210
- function unbind() {
211
- window.document.removeEventListener('touchmove', onMove, { capture: true, passive: false });
212
- window.document.removeEventListener('touchend', onTouchEnd);
213
- window.document.removeEventListener('mousemove', onMove, { capture: true });
214
- window.document.removeEventListener('mouseup', onMouseUp);
215
- window.removeEventListener('blur', onBlur);
216
- }
217
-
218
- function deactivate() {
219
- frame.cancel();
220
- previousPos = undefined;
221
- }
222
-
223
- function calculateInertia(first, last) {
224
- const flingOffset = last.value.sub(first.value);
225
- const flingDuration = (last.time - first.time) / 1000;
226
-
227
- if (flingDuration === 0 || last.value.equals(first.value)) {
228
- return { empty: true };
229
- }
230
-
231
- // calculate px/s velocity & adjust for increased initial animation speed when easing out
232
- const velocity = flingOffset.mult(inertiaLinearity / flingDuration);
233
- let speed = velocity.mag(); // px/s
234
-
235
- if (speed > inertiaMaxSpeed) {
236
- speed = inertiaMaxSpeed;
237
- velocity._unit()._mult(speed);
238
- }
239
-
240
- const duration = speed / (inertiaDeceleration * inertiaLinearity);
241
- const offset = velocity.mult(-duration / 2);
242
-
243
- return {
244
- duration: duration * 1000,
245
- offset
246
- };
247
- }
248
-
249
- function inertialPan(e) {
250
- fireEvent('dragend', e);
251
-
252
- const { empty, duration, offset } = inertia.calculate();
253
- inertia = undefined;
254
-
255
- if (empty) {
256
- fireEvent('moveend', e);
257
- return;
258
- }
259
-
260
- map.panBy(
261
- offset,
262
- {
263
- duration,
264
- easing: inertiaEasing,
265
- noMoveStart: true
266
- },
267
- { originalEvent: e }
268
- );
269
- }
270
-
271
- function fireEvent(type, e) {
272
- return map.fire(new Event(type, e ? { originalEvent: e } : {}));
273
- }
274
-
275
- return {
276
- isActive,
277
- isEnabled,
278
- enable,
279
- disable,
280
- onMouseDown,
281
- onTouchStart
282
- };
283
- }
284
-
285
- module.exports = dragPanHandler;
@@ -1,290 +0,0 @@
1
- const DOM = require('../../util/dom');
2
-
3
- const { bezier } = require('../../util/util');
4
- const { Event } = require('../../util/evented');
5
- const assert = require('assert');
6
- const makeFrame = require('./frame');
7
- const makeInertia = require('./inertia');
8
-
9
- const inertiaLinearity = 0.25;
10
- const inertiaEasing = bezier(0, 0, inertiaLinearity, 1);
11
- const inertiaMaxSpeed = 180; // deg/s
12
- const inertiaDeceleration = 720; // deg/s^2
13
-
14
- /**
15
- * The `DragRotateHandler` allows the user to rotate the map by clicking and
16
- * dragging the cursor while holding the right mouse button or `ctrl` key.
17
- * @param {Map} map The Mapbox GL JS map to add the handler to.
18
- * @param {Object} [options]
19
- * @param {number} [options.bearingSnap] The threshold, measured in degrees, that determines when the map's
20
- * bearing will snap to north.
21
- * @param {bool} [options.pitchWithRotate=true] Control the map pitch in addition to the bearing
22
- */
23
- function dragRotateHandler(map, { element, button = 'right', bearingSnap = 0, pitchWithRotate = true } = {}) {
24
- const el = element || map.getCanvasContainer();
25
-
26
- const frame = makeFrame(map, onDragFrame);
27
-
28
- let eventButton;
29
- let inertia;
30
- let state = 'disabled';
31
- let previousPos;
32
- let previousBearing;
33
-
34
- /**
35
- * Returns a Boolean indicating whether the "drag to rotate" interaction is enabled.
36
- *
37
- * @returns {boolean} `true` if the "drag to rotate" interaction is enabled.
38
- */
39
- function isEnabled() {
40
- return state !== 'disabled';
41
- }
42
-
43
- /**
44
- * Returns a Boolean indicating whether the "drag to rotate" interaction is active, i.e. currently being used.
45
- *
46
- * @returns {boolean} `true` if the "drag to rotate" interaction is active.
47
- */
48
- function isActive() {
49
- return state === 'active';
50
- }
51
-
52
- /**
53
- * Enables the "drag to rotate" interaction.
54
- *
55
- * @example
56
- * map.dragRotate.enable();
57
- */
58
- function enable() {
59
- if (isEnabled()) return;
60
- state = 'enabled';
61
- }
62
-
63
- /**
64
- * Disables the "drag to rotate" interaction.
65
- *
66
- * @example
67
- * map.dragRotate.disable();
68
- */
69
- function disable() {
70
- if (!isEnabled()) return;
71
- switch (state) {
72
- case 'active':
73
- state = 'disabled';
74
- unbind();
75
- deactivate();
76
- fireEvent('rotateend');
77
- if (pitchWithRotate) fireEvent('pitchend');
78
- fireEvent('moveend');
79
- break;
80
- case 'pending':
81
- state = 'disabled';
82
- unbind();
83
- break;
84
- default:
85
- state = 'disabled';
86
- break;
87
- }
88
- }
89
-
90
- function onMouseDown(e) {
91
- if (state !== 'enabled') return;
92
-
93
- if (button === 'right') {
94
- eventButton = DOM.mouseButton(e);
95
- if (eventButton !== (e.ctrlKey ? 0 : 2)) return;
96
- } else {
97
- if (e.ctrlKey || DOM.mouseButton(e) !== 0) return;
98
- eventButton = 0;
99
- }
100
-
101
- DOM.disableDrag();
102
-
103
- // Bind window-level event listeners for move and up/end events. In the absence of
104
- // the pointer capture API, which is not supported by all necessary platforms,
105
- // window-level event listeners give us the best shot at capturing events that
106
- // fall outside the map canvas element. Use `{capture: true}` for the move event
107
- // to prevent map move events from being fired during a drag.
108
- window.document.addEventListener('mousemove', onMouseMove, { capture: true });
109
- window.document.addEventListener('mouseup', onMouseUp);
110
-
111
- // Deactivate when the window loses focus. Otherwise if a mouseup occurs when the window
112
- // isn't in focus, dragging will continue even though the mouse is no longer pressed.
113
- window.addEventListener('blur', onBlur);
114
-
115
- state = 'pending';
116
-
117
- previousPos = DOM.mousePos(el, e);
118
- previousBearing = map.getBearing();
119
-
120
- inertia = makeInertia(map, calculateInertia);
121
- inertia.update(previousBearing);
122
-
123
- e.preventDefault();
124
- }
125
-
126
- function onMouseMove(e) {
127
- const pos = DOM.mousePos(el, e);
128
- frame.request(e, pos);
129
-
130
- if (state === 'pending') {
131
- state = 'active';
132
- fireEvent('rotatestart', e);
133
- fireEvent('movestart', e);
134
- if (pitchWithRotate) fireEvent('pitchstart', e);
135
- }
136
- }
137
-
138
- function onDragFrame(e, pos) {
139
- const tr = map.transform;
140
-
141
- const bearingDiff = (pos.x - previousPos.x) * -0.8;
142
- const pitchDiff = (pos.y - previousPos.y) * 0.5;
143
-
144
- const bearing = tr.bearing - bearingDiff;
145
- const pitch = tr.pitch - pitchDiff;
146
-
147
- const normalizedBearing = map._normalizeBearing(bearing, previousBearing);
148
- inertia.update(normalizedBearing);
149
-
150
- tr.bearing = bearing;
151
- if (pitchWithRotate) {
152
- fireEvent('pitch', e);
153
- tr.pitch = pitch;
154
- }
155
-
156
- fireEvent('rotate', e);
157
- fireEvent('move', e);
158
-
159
- previousBearing = normalizedBearing;
160
- previousPos = pos;
161
- }
162
-
163
- function onMouseUp(e) {
164
- if (DOM.mouseButton(e) !== eventButton) return;
165
- switch (state) {
166
- case 'active':
167
- state = 'enabled';
168
- DOM.suppressClick();
169
- unbind();
170
- deactivate();
171
- inertialRotate(e);
172
- break;
173
- case 'pending':
174
- state = 'enabled';
175
- unbind();
176
- break;
177
- default:
178
- assert(false);
179
- break;
180
- }
181
- }
182
-
183
- function onBlur(e) {
184
- switch (state) {
185
- case 'active':
186
- state = 'enabled';
187
- unbind();
188
- deactivate();
189
- fireEvent('rotateend', e);
190
- if (pitchWithRotate) fireEvent('pitchend', e);
191
- fireEvent('moveend', e);
192
- break;
193
- case 'pending':
194
- state = 'enabled';
195
- unbind();
196
- break;
197
- default:
198
- assert(false);
199
- break;
200
- }
201
- }
202
-
203
- function unbind() {
204
- window.document.removeEventListener('mousemove', onMouseMove, { capture: true });
205
- window.document.removeEventListener('mouseup', onMouseUp);
206
- window.removeEventListener('blur', onBlur);
207
- DOM.enableDrag();
208
- }
209
-
210
- function deactivate() {
211
- frame.cancel();
212
-
213
- previousPos = undefined;
214
- previousBearing = undefined;
215
- eventButton = undefined;
216
- }
217
-
218
- function calculateInertia(first, last) {
219
- const mapBearing = map.getBearing();
220
- let bearing = map._normalizeBearing(mapBearing, previousBearing);
221
-
222
- const flingDiff = last.value - first.value;
223
- const sign = flingDiff < 0 ? -1 : 1;
224
- const flingDuration = (last.time - first.time) / 1000;
225
-
226
- if (flingDiff === 0 || flingDuration === 0) {
227
- return { empty: true };
228
- }
229
-
230
- let speed = Math.abs(flingDiff * (inertiaLinearity / flingDuration)); // deg/s
231
- if (speed > inertiaMaxSpeed) {
232
- speed = inertiaMaxSpeed;
233
- }
234
-
235
- const duration = speed / (inertiaDeceleration * inertiaLinearity);
236
- const offset = sign * speed * (duration / 2);
237
-
238
- bearing += offset;
239
-
240
- if (Math.abs(map._normalizeBearing(bearing, 0)) < bearingSnap) {
241
- bearing = map._normalizeBearing(0, bearing);
242
- }
243
-
244
- return {
245
- duration: duration * 1000,
246
- bearing
247
- };
248
- }
249
-
250
- function inertialRotate(e) {
251
- fireEvent('rotateend', e);
252
-
253
- const { empty, bearing, duration } = inertia.calculate();
254
- if (empty) {
255
- if (Math.abs(map.getBearing()) < bearingSnap) {
256
- map.resetNorth({ noMoveStart: true }, { originalEvent: e });
257
- } else {
258
- fireEvent('moveend', e);
259
- }
260
- if (pitchWithRotate) fireEvent('pitchend', e);
261
- return;
262
- }
263
-
264
- map.rotateTo(
265
- bearing,
266
- {
267
- duration,
268
- easing: inertiaEasing,
269
- noMoveStart: true
270
- },
271
- { originalEvent: e }
272
- );
273
- }
274
-
275
- function fireEvent(type, e) {
276
- return map.fire(new Event(type, e ? { originalEvent: e } : {}));
277
- }
278
-
279
- DOM.initEnableDisableDrag();
280
-
281
- return {
282
- isActive,
283
- isEnabled,
284
- enable,
285
- disable,
286
- onMouseDown
287
- };
288
- }
289
-
290
- module.exports = dragRotateHandler;
@@ -1,28 +0,0 @@
1
- module.exports = frame;
2
-
3
- function frame(map, fn) {
4
- let id;
5
- let args;
6
-
7
- function callback() {
8
- id = undefined;
9
- fn(...args);
10
- }
11
-
12
- function request(..._args) {
13
- args = _args;
14
- if (id) return;
15
- id = map._requestRenderFrame(callback);
16
- }
17
-
18
- function cancel() {
19
- if (!id) return;
20
- map._cancelRenderFrame(id);
21
- id = undefined;
22
- }
23
-
24
- return {
25
- request,
26
- cancel
27
- };
28
- }
@@ -1,45 +0,0 @@
1
- const browser = require('../../util/browser');
2
-
3
- module.exports = inertia;
4
-
5
- const INERTIA_CUTOFF = 160; // msec
6
- const EMPTY = { empty: true };
7
- const MAX_LEN = 1000;
8
- const MIN_REMOVE = Math.floor(MAX_LEN / 2);
9
-
10
- function inertia(map, calculateInertia) {
11
- const states = [];
12
-
13
- function update(value) {
14
- const now = browser.now();
15
- const data = { time: now, value };
16
- const len = states.push(data);
17
- if (len > MAX_LEN) {
18
- let first = getFirst(now);
19
- if (first < 0) {
20
- first = len - 1;
21
- } else if (first < MIN_REMOVE) {
22
- first = MIN_REMOVE;
23
- }
24
- states.splice(0, first);
25
- }
26
- }
27
-
28
- function getFirst(now = browser.now()) {
29
- return states.findIndex(item => now - item.time < INERTIA_CUTOFF);
30
- }
31
-
32
- function calculate() {
33
- const first = getFirst();
34
- const last = states.length - 1;
35
- if (first < 0 || first >= last) {
36
- return EMPTY;
37
- }
38
- return calculateInertia(states[first], states[last]);
39
- }
40
-
41
- return {
42
- update,
43
- calculate
44
- };
45
- }