@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.
- package/build/min/package.json +1 -1
- package/build/min/src/shaders/.dir +0 -0
- package/build/min/src/shaders/_prelude.fragment.glsl.js +14 -0
- package/build/min/src/shaders/_prelude.vertex.glsl.js +14 -0
- package/build/min/src/shaders/background.fragment.glsl.js +5 -0
- package/build/min/src/shaders/background.vertex.glsl.js +1 -0
- package/build/min/src/shaders/background_pattern.fragment.glsl.js +5 -0
- package/build/min/src/shaders/background_pattern.vertex.glsl.js +1 -0
- package/build/min/src/shaders/circle.fragment.glsl.js +20 -0
- package/build/min/src/shaders/circle.vertex.glsl.js +17 -0
- package/build/min/src/shaders/clipping_mask.fragment.glsl.js +1 -0
- package/build/min/src/shaders/clipping_mask.vertex.glsl.js +1 -0
- package/build/min/src/shaders/collision_box.fragment.glsl.js +1 -0
- package/build/min/src/shaders/collision_box.vertex.glsl.js +1 -0
- package/build/min/src/shaders/collision_circle.fragment.glsl.js +1 -0
- package/build/min/src/shaders/collision_circle.vertex.glsl.js +1 -0
- package/build/min/src/shaders/debug.fragment.glsl.js +1 -0
- package/build/min/src/shaders/debug.vertex.glsl.js +1 -0
- package/build/min/src/shaders/fill.fragment.glsl.js +10 -0
- package/build/min/src/shaders/fill.vertex.glsl.js +7 -0
- package/build/min/src/shaders/fill_extrusion.fragment.glsl.js +5 -0
- package/build/min/src/shaders/fill_extrusion.vertex.glsl.js +9 -0
- package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.js +15 -0
- package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.js +11 -0
- package/build/min/src/shaders/fill_outline.fragment.glsl.js +10 -0
- package/build/min/src/shaders/fill_outline.vertex.glsl.js +7 -0
- package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.js +13 -0
- package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.js +9 -0
- package/build/min/src/shaders/fill_pattern.fragment.glsl.js +13 -0
- package/build/min/src/shaders/fill_pattern.vertex.glsl.js +9 -0
- package/build/min/src/shaders/heatmap.fragment.glsl.js +10 -0
- package/build/min/src/shaders/heatmap.vertex.glsl.js +8 -0
- package/build/min/src/shaders/heatmap_texture.fragment.glsl.js +5 -0
- package/build/min/src/shaders/heatmap_texture.vertex.glsl.js +1 -0
- package/build/min/src/shaders/hillshade.fragment.glsl.js +7 -0
- package/build/min/src/shaders/hillshade.vertex.glsl.js +1 -0
- package/build/min/src/shaders/hillshade_prepare.fragment.glsl.js +8 -0
- package/build/min/src/shaders/hillshade_prepare.vertex.glsl.js +1 -0
- package/build/min/src/shaders/line.fragment.glsl.js +12 -0
- package/build/min/src/shaders/line.vertex.glsl.js +17 -0
- package/build/min/src/shaders/line_gradient.fragment.glsl.js +10 -0
- package/build/min/src/shaders/line_gradient.vertex.glsl.js +16 -0
- package/build/min/src/shaders/line_pattern.fragment.glsl.js +15 -0
- package/build/min/src/shaders/line_pattern.vertex.glsl.js +20 -0
- package/build/min/src/shaders/line_sdf.fragment.glsl.js +17 -0
- package/build/min/src/shaders/line_sdf.vertex.glsl.js +20 -0
- package/build/min/src/shaders/raster.fragment.glsl.js +5 -0
- package/build/min/src/shaders/raster.vertex.glsl.js +1 -0
- package/build/min/src/shaders/symbol_icon.fragment.glsl.js +9 -0
- package/build/min/src/shaders/symbol_icon.vertex.glsl.js +5 -0
- package/build/min/src/shaders/symbol_sdf.fragment.glsl.js +19 -0
- package/build/min/src/shaders/symbol_sdf.vertex.glsl.js +13 -0
- package/package.json +7 -7
- package/src/data/bucket/fill_bucket.js +1 -1
- package/src/data/bucket/fill_extrusion_bucket.js +2 -2
- package/src/data/bucket/line_bucket.js +1 -1
- package/src/data/bucket/symbol_bucket.js +2 -2
- package/src/data/feature_index.js +1 -1
- package/src/data/program_configuration.js +1 -1
- package/src/gl/color_mode.js +1 -1
- package/src/gl/value.js +1 -1
- package/src/render/draw_debug.js +1 -1
- package/src/render/draw_fill.js +1 -1
- package/src/render/draw_heatmap.js +1 -1
- package/src/render/glyph_manager.js +6 -130
- package/src/render/painter.js +1 -1
- package/src/render/uniform_binding.js +1 -1
- package/src/shaders/index.js +50 -50
- package/src/source/geojson_worker_source.js +4 -4
- package/src/source/geojson_wrapper.js +34 -26
- package/src/source/resources/glyphs.js +73 -0
- package/src/source/resources/images.js +68 -0
- package/src/source/resources/index.js +22 -0
- package/src/source/vector_tile_worker_source.js +5 -5
- package/src/source/worker.js +6 -5
- package/src/source/worker_tile.js +4 -4
- package/src/style/properties.js +1 -2
- package/src/style/style.js +3 -3
- package/src/style/style_layer/symbol_style_layer.js +1 -1
- package/src/style/style_layer.js +1 -1
- package/src/style-spec/feature_filter/index.js +43 -34
- package/src/style-spec/group_by_layout.js +10 -32
- package/src/symbol/mergelines.js +0 -2
- package/src/symbol/symbol_layout.js +0 -1
- package/src/symbol/symbol_size.js +1 -1
- package/src/symbol/transform_text.js +0 -1
- package/src/ui/map.js +11 -39
- package/src/util/browser.js +3 -18
- package/src/util/classify_rings.js +1 -1
- package/src/util/dom.js +0 -88
- package/src/util/find_pole_of_inaccessibility.js +2 -2
- package/src/util/web_worker_transfer.js +4 -4
- package/src/style/load_glyph_range.js +0 -17
- package/src/style-spec/expression/compound_expression.js +0 -132
- package/src/style-spec/expression/definitions/assertion.js +0 -116
- package/src/style-spec/expression/definitions/at.js +0 -57
- package/src/style-spec/expression/definitions/case.js +0 -73
- package/src/style-spec/expression/definitions/coalesce.js +0 -66
- package/src/style-spec/expression/definitions/coercion.js +0 -120
- package/src/style-spec/expression/definitions/collator.js +0 -80
- package/src/style-spec/expression/definitions/comparison.js +0 -193
- package/src/style-spec/expression/definitions/format.js +0 -97
- package/src/style-spec/expression/definitions/index.js +0 -339
- package/src/style-spec/expression/definitions/interpolate.js +0 -245
- package/src/style-spec/expression/definitions/length.js +0 -54
- package/src/style-spec/expression/definitions/let.js +0 -60
- package/src/style-spec/expression/definitions/literal.js +0 -69
- package/src/style-spec/expression/definitions/match.js +0 -142
- package/src/style-spec/expression/definitions/step.js +0 -116
- package/src/style-spec/expression/definitions/var.js +0 -38
- package/src/style-spec/expression/evaluation_context.js +0 -38
- package/src/style-spec/expression/index.js +0 -330
- package/src/style-spec/expression/is_constant.js +0 -63
- package/src/style-spec/expression/parsing_context.js +0 -221
- package/src/style-spec/expression/parsing_error.js +0 -9
- package/src/style-spec/expression/runtime_error.js +0 -12
- package/src/style-spec/expression/scope.js +0 -34
- package/src/style-spec/expression/stops.js +0 -37
- package/src/style-spec/expression/types/collator.js +0 -24
- package/src/style-spec/expression/types/formatted.js +0 -39
- package/src/style-spec/expression/types.js +0 -88
- package/src/style-spec/expression/values.js +0 -149
- package/src/style-spec/function/convert.js +0 -240
- package/src/style-spec/function/index.js +0 -303
- package/src/style-spec/util/color.js +0 -73
- package/src/style-spec/util/color_spaces.js +0 -128
- package/src/style-spec/util/get_type.js +0 -18
- package/src/style-spec/util/interpolate.js +0 -21
- package/src/style-spec/util/properties.js +0 -17
- package/src/style-spec/util/result.js +0 -19
- package/src/ui/anchor.js +0 -24
- package/src/ui/bind_handlers.js +0 -199
- package/src/ui/events.js +0 -210
- package/src/ui/handler/box_zoom.js +0 -151
- package/src/ui/handler/dblclick_zoom.js +0 -91
- package/src/ui/handler/drag_pan.js +0 -285
- package/src/ui/handler/drag_rotate.js +0 -290
- package/src/ui/handler/frame.js +0 -28
- package/src/ui/handler/inertia.js +0 -45
- package/src/ui/handler/keyboard.js +0 -148
- package/src/ui/handler/scroll_zoom.js +0 -284
- package/src/ui/handler/touch_zoom_rotate.js +0 -263
|
@@ -1,148 +0,0 @@
|
|
|
1
|
-
const panStep = 100;
|
|
2
|
-
const bearingStep = 15;
|
|
3
|
-
const pitchStep = 10;
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* The `KeyboardHandler` allows the user to zoom, rotate, and pan the map using
|
|
7
|
-
* the following keyboard shortcuts:
|
|
8
|
-
*
|
|
9
|
-
* - `=` / `+`: Increase the zoom level by 1.
|
|
10
|
-
* - `Shift-=` / `Shift-+`: Increase the zoom level by 2.
|
|
11
|
-
* - `-`: Decrease the zoom level by 1.
|
|
12
|
-
* - `Shift--`: Decrease the zoom level by 2.
|
|
13
|
-
* - Arrow keys: Pan by 100 pixels.
|
|
14
|
-
* - `Shift+⇢`: Increase the rotation by 15 degrees.
|
|
15
|
-
* - `Shift+⇠`: Decrease the rotation by 15 degrees.
|
|
16
|
-
* - `Shift+⇡`: Increase the pitch by 10 degrees.
|
|
17
|
-
* - `Shift+⇣`: Decrease the pitch by 10 degrees.
|
|
18
|
-
*/
|
|
19
|
-
function keyboardHandler(map) {
|
|
20
|
-
const el = map.getCanvasContainer();
|
|
21
|
-
|
|
22
|
-
let enabled = false;
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Returns a Boolean indicating whether keyboard interaction is enabled.
|
|
26
|
-
*
|
|
27
|
-
* @returns {boolean} `true` if keyboard interaction is enabled.
|
|
28
|
-
*/
|
|
29
|
-
function isEnabled() {
|
|
30
|
-
return enabled;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Enables keyboard interaction.
|
|
35
|
-
*
|
|
36
|
-
* @example
|
|
37
|
-
* map.keyboard.enable();
|
|
38
|
-
*/
|
|
39
|
-
function enable() {
|
|
40
|
-
if (enabled) return;
|
|
41
|
-
el.addEventListener('keydown', onKeyDown, false);
|
|
42
|
-
enabled = true;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* Disables keyboard interaction.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* map.keyboard.disable();
|
|
50
|
-
*/
|
|
51
|
-
function disable() {
|
|
52
|
-
if (!enabled) return;
|
|
53
|
-
el.removeEventListener('keydown', onKeyDown);
|
|
54
|
-
enabled = false;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function onKeyDown(e) {
|
|
58
|
-
if (e.altKey || e.ctrlKey || e.metaKey) return;
|
|
59
|
-
|
|
60
|
-
let zoomDir = 0;
|
|
61
|
-
let bearingDir = 0;
|
|
62
|
-
let pitchDir = 0;
|
|
63
|
-
let xDir = 0;
|
|
64
|
-
let yDir = 0;
|
|
65
|
-
|
|
66
|
-
switch (e.keyCode) {
|
|
67
|
-
case 61:
|
|
68
|
-
case 107:
|
|
69
|
-
case 171:
|
|
70
|
-
case 187:
|
|
71
|
-
zoomDir = 1;
|
|
72
|
-
break;
|
|
73
|
-
|
|
74
|
-
case 189:
|
|
75
|
-
case 109:
|
|
76
|
-
case 173:
|
|
77
|
-
zoomDir = -1;
|
|
78
|
-
break;
|
|
79
|
-
|
|
80
|
-
case 37:
|
|
81
|
-
if (e.shiftKey) {
|
|
82
|
-
bearingDir = -1;
|
|
83
|
-
} else {
|
|
84
|
-
e.preventDefault();
|
|
85
|
-
xDir = -1;
|
|
86
|
-
}
|
|
87
|
-
break;
|
|
88
|
-
|
|
89
|
-
case 39:
|
|
90
|
-
if (e.shiftKey) {
|
|
91
|
-
bearingDir = 1;
|
|
92
|
-
} else {
|
|
93
|
-
e.preventDefault();
|
|
94
|
-
xDir = 1;
|
|
95
|
-
}
|
|
96
|
-
break;
|
|
97
|
-
|
|
98
|
-
case 38:
|
|
99
|
-
if (e.shiftKey) {
|
|
100
|
-
pitchDir = 1;
|
|
101
|
-
} else {
|
|
102
|
-
e.preventDefault();
|
|
103
|
-
yDir = -1;
|
|
104
|
-
}
|
|
105
|
-
break;
|
|
106
|
-
|
|
107
|
-
case 40:
|
|
108
|
-
if (e.shiftKey) {
|
|
109
|
-
pitchDir = -1;
|
|
110
|
-
} else {
|
|
111
|
-
yDir = 1;
|
|
112
|
-
e.preventDefault();
|
|
113
|
-
}
|
|
114
|
-
break;
|
|
115
|
-
|
|
116
|
-
default:
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const zoom = map.getZoom();
|
|
121
|
-
|
|
122
|
-
const easeOptions = {
|
|
123
|
-
duration: 300,
|
|
124
|
-
delayEndEvents: 500,
|
|
125
|
-
easing: easeOut,
|
|
126
|
-
|
|
127
|
-
zoom: zoomDir ? Math.round(zoom) + zoomDir * (e.shiftKey ? 2 : 1) : zoom,
|
|
128
|
-
bearing: map.getBearing() + bearingDir * bearingStep,
|
|
129
|
-
pitch: map.getPitch() + pitchDir * pitchStep,
|
|
130
|
-
offset: [-xDir * panStep, -yDir * panStep],
|
|
131
|
-
center: map.getCenter()
|
|
132
|
-
};
|
|
133
|
-
|
|
134
|
-
map.easeTo(easeOptions, { originalEvent: e });
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
return {
|
|
138
|
-
isEnabled,
|
|
139
|
-
enable,
|
|
140
|
-
disable
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
function easeOut(t) {
|
|
145
|
-
return t * (2 - t);
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
module.exports = keyboardHandler;
|
|
@@ -1,284 +0,0 @@
|
|
|
1
|
-
const DOM = require('../../util/dom');
|
|
2
|
-
|
|
3
|
-
const browser = require('../../util/browser');
|
|
4
|
-
const interpolate = require('../../util/interpolate');
|
|
5
|
-
const { Event } = require('../../util/evented');
|
|
6
|
-
const makeFrame = require('./frame');
|
|
7
|
-
|
|
8
|
-
// deltaY value for mouse scroll wheel identification
|
|
9
|
-
const wheelZoomDelta = 4.000244140625;
|
|
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
|
-
function computeSmoothOutEasing() {
|
|
20
|
-
const { ease, bezier } = require('../../util/util');
|
|
21
|
-
let _prevEase;
|
|
22
|
-
|
|
23
|
-
function compute(duration) {
|
|
24
|
-
let easing = ease;
|
|
25
|
-
|
|
26
|
-
if (_prevEase) {
|
|
27
|
-
const t = (browser.now() - _prevEase.start) / _prevEase.duration;
|
|
28
|
-
const speed = _prevEase.easing(t + 0.01) - _prevEase.easing(t);
|
|
29
|
-
|
|
30
|
-
// Quick hack to make new bezier that is continuous with last
|
|
31
|
-
const x = (0.27 / Math.sqrt(speed * speed + 0.0001)) * 0.01;
|
|
32
|
-
const y = Math.sqrt(0.27 * 0.27 - x * x);
|
|
33
|
-
|
|
34
|
-
easing = bezier(x, y, 0.25, 1);
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
_prevEase = {
|
|
38
|
-
start: browser.now(),
|
|
39
|
-
duration,
|
|
40
|
-
easing
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
return easing;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return compute;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* The `ScrollZoomHandler` allows the user to zoom the map by scrolling.
|
|
51
|
-
*/
|
|
52
|
-
function scrollZoomHandler(_map) {
|
|
53
|
-
// used for delayed-handling of a single wheel movement
|
|
54
|
-
// used to delay final '{move,zoom}end' events
|
|
55
|
-
|
|
56
|
-
let _delta = 0;
|
|
57
|
-
|
|
58
|
-
let enabled = false;
|
|
59
|
-
let active = false;
|
|
60
|
-
let zooming = false;
|
|
61
|
-
let aroundCenter;
|
|
62
|
-
|
|
63
|
-
let _lastWheelEvent;
|
|
64
|
-
let _lastWheelEventTime = 0;
|
|
65
|
-
let _lastValue = 0;
|
|
66
|
-
|
|
67
|
-
let _timeout;
|
|
68
|
-
let _finishTimeout;
|
|
69
|
-
|
|
70
|
-
let _type;
|
|
71
|
-
let _around;
|
|
72
|
-
let _aroundPoint;
|
|
73
|
-
|
|
74
|
-
let _startZoom;
|
|
75
|
-
let _targetZoom;
|
|
76
|
-
let _easing;
|
|
77
|
-
|
|
78
|
-
const frame = makeFrame(_map, onScrollFrame);
|
|
79
|
-
const smoothOutEasing = computeSmoothOutEasing();
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Returns a Boolean indicating whether the "scroll to zoom" interaction is enabled.
|
|
83
|
-
*
|
|
84
|
-
* @returns {boolean} `true` if the "scroll to zoom" interaction is enabled.
|
|
85
|
-
*/
|
|
86
|
-
function isEnabled() {
|
|
87
|
-
return enabled;
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
function isActive() {
|
|
91
|
-
return active;
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
function isZooming() {
|
|
95
|
-
return zooming;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Enables the "scroll to zoom" interaction.
|
|
100
|
-
*
|
|
101
|
-
* @param {Object} [options]
|
|
102
|
-
* @param {string} [options.around] If "center" is passed, map will zoom around center of map
|
|
103
|
-
*
|
|
104
|
-
* @example
|
|
105
|
-
* map.scrollZoom.enable();
|
|
106
|
-
* @example
|
|
107
|
-
* map.scrollZoom.enable({ around: 'center' })
|
|
108
|
-
*/
|
|
109
|
-
function enable(options) {
|
|
110
|
-
if (enabled) return;
|
|
111
|
-
enabled = true;
|
|
112
|
-
aroundCenter = options && options.around === 'center';
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
/**
|
|
116
|
-
* Disables the "scroll to zoom" interaction.
|
|
117
|
-
*
|
|
118
|
-
* @example
|
|
119
|
-
* map.scrollZoom.disable();
|
|
120
|
-
*/
|
|
121
|
-
function disable() {
|
|
122
|
-
enabled = false;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
function onWheel(e) {
|
|
126
|
-
if (!enabled) return;
|
|
127
|
-
|
|
128
|
-
let value = e.deltaMode === window.WheelEvent.DOM_DELTA_LINE ? e.deltaY * 40 : e.deltaY;
|
|
129
|
-
const now = browser.now();
|
|
130
|
-
const timeDelta = now - _lastWheelEventTime;
|
|
131
|
-
|
|
132
|
-
_lastWheelEventTime = now;
|
|
133
|
-
_lastWheelEvent = e;
|
|
134
|
-
|
|
135
|
-
if (value !== 0 && value % wheelZoomDelta === 0) {
|
|
136
|
-
// This one is definitely a mouse wheel event.
|
|
137
|
-
_type = 'wheel';
|
|
138
|
-
} else if (value !== 0 && Math.abs(value) < 4) {
|
|
139
|
-
// This one is definitely a trackpad event because it is so small.
|
|
140
|
-
_type = 'trackpad';
|
|
141
|
-
} else if (timeDelta > 400) {
|
|
142
|
-
// This is likely a new scroll action.
|
|
143
|
-
_type = undefined;
|
|
144
|
-
_lastValue = value;
|
|
145
|
-
|
|
146
|
-
// Start a timeout in case this was a singular event, and dely it by up to 40ms.
|
|
147
|
-
_timeout = setTimeout(onTimeout, 40);
|
|
148
|
-
} else if (!_type) {
|
|
149
|
-
// This is a repeating event, but we don't know the type of event just yet.
|
|
150
|
-
// If the delta per time is small, we assume it's a fast trackpad; otherwise we switch into wheel mode.
|
|
151
|
-
_type = Math.abs(timeDelta * value) < 200 ? 'trackpad' : 'wheel';
|
|
152
|
-
|
|
153
|
-
// Make sure our delayed event isn't fired again, because we accumulate
|
|
154
|
-
// the previous event (which was less than 40ms ago) into this event.
|
|
155
|
-
if (_timeout) {
|
|
156
|
-
clearTimeout(_timeout);
|
|
157
|
-
_timeout = undefined;
|
|
158
|
-
value += _lastValue;
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
// Slow down zoom if shift key is held for more precise zooming
|
|
163
|
-
if (e.shiftKey && value) value = value / 4;
|
|
164
|
-
|
|
165
|
-
// Only fire the callback if we actually know what type of scrolling device the user uses.
|
|
166
|
-
if (_type) {
|
|
167
|
-
_delta -= value;
|
|
168
|
-
if (!active) {
|
|
169
|
-
start(e);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
e.preventDefault();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function onTimeout() {
|
|
177
|
-
_timeout = undefined;
|
|
178
|
-
_type = 'wheel';
|
|
179
|
-
_delta -= _lastValue;
|
|
180
|
-
if (!active) {
|
|
181
|
-
start();
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function start() {
|
|
186
|
-
if (!_delta) return;
|
|
187
|
-
|
|
188
|
-
frame.cancel();
|
|
189
|
-
active = true;
|
|
190
|
-
|
|
191
|
-
if (!zooming) {
|
|
192
|
-
zooming = true;
|
|
193
|
-
_map.fire(new Event('movestart', { originalEvent: _lastWheelEvent }));
|
|
194
|
-
_map.fire(new Event('zoomstart', { originalEvent: _lastWheelEvent }));
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
if (_finishTimeout) {
|
|
198
|
-
clearTimeout(_finishTimeout);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
if (aroundCenter) {
|
|
202
|
-
_around = _map.getCenter();
|
|
203
|
-
_aroundPoint = _map.transform.locationPoint(_around);
|
|
204
|
-
} else {
|
|
205
|
-
_aroundPoint = DOM.mousePos(_map.getCanvasContainer(), _lastWheelEvent);
|
|
206
|
-
_around = _map.unproject(_aroundPoint);
|
|
207
|
-
}
|
|
208
|
-
frame.request();
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
function onScrollFrame() {
|
|
212
|
-
if (!active) return;
|
|
213
|
-
const tr = _map.transform;
|
|
214
|
-
|
|
215
|
-
// if we've had scroll events since the last render frame, consume the
|
|
216
|
-
// accumulated delta, and update the target zoom level accordingly
|
|
217
|
-
if (_delta !== 0) {
|
|
218
|
-
// For trackpad events and single mouse wheel ticks, use the default zoom rate
|
|
219
|
-
const zoomRate = _type === 'wheel' && Math.abs(_delta) > wheelZoomDelta ? wheelZoomRate : defaultZoomRate;
|
|
220
|
-
// Scale by sigmoid of scroll wheel delta.
|
|
221
|
-
let scale = maxScalePerFrame / (1 + Math.exp(-Math.abs(_delta * zoomRate)));
|
|
222
|
-
|
|
223
|
-
if (_delta < 0 && scale !== 0) {
|
|
224
|
-
scale = 1 / scale;
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
const fromScale = typeof _targetZoom === 'number' ? tr.zoomScale(_targetZoom) : tr.scale;
|
|
228
|
-
_targetZoom = Math.min(tr.maxZoom, Math.max(tr.minZoom, tr.scaleZoom(fromScale * scale)));
|
|
229
|
-
|
|
230
|
-
// if this is a mouse wheel, refresh the starting zoom and easing
|
|
231
|
-
// function we're using to smooth out the zooming between wheel
|
|
232
|
-
// events
|
|
233
|
-
if (_type === 'wheel') {
|
|
234
|
-
_startZoom = tr.zoom;
|
|
235
|
-
_easing = smoothOutEasing(200);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
_delta = 0;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
const targetZoom = typeof _targetZoom === 'number' ? _targetZoom : tr.zoom;
|
|
242
|
-
let finished = false;
|
|
243
|
-
if (_type === 'wheel' && _startZoom && _easing) {
|
|
244
|
-
const t = Math.min((browser.now() - _lastWheelEventTime) / 200, 1);
|
|
245
|
-
const k = _easing(t);
|
|
246
|
-
tr.zoom = interpolate(_startZoom, targetZoom, k);
|
|
247
|
-
if (t < 1) {
|
|
248
|
-
frame.request();
|
|
249
|
-
} else {
|
|
250
|
-
finished = true;
|
|
251
|
-
}
|
|
252
|
-
} else {
|
|
253
|
-
tr.zoom = targetZoom;
|
|
254
|
-
finished = true;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
tr.setLocationAtPoint(_around, _aroundPoint);
|
|
258
|
-
|
|
259
|
-
_map.fire(new Event('move', { originalEvent: _lastWheelEvent }));
|
|
260
|
-
_map.fire(new Event('zoom', { originalEvent: _lastWheelEvent }));
|
|
261
|
-
|
|
262
|
-
if (finished) {
|
|
263
|
-
active = false;
|
|
264
|
-
_finishTimeout = setTimeout(() => {
|
|
265
|
-
zooming = false;
|
|
266
|
-
_finishTimeout = undefined;
|
|
267
|
-
_map.fire(new Event('zoomend', { originalEvent: _lastWheelEvent }));
|
|
268
|
-
_map.fire(new Event('moveend', { originalEvent: _lastWheelEvent }));
|
|
269
|
-
_targetZoom = undefined;
|
|
270
|
-
}, 200);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
return {
|
|
275
|
-
isActive,
|
|
276
|
-
isZooming,
|
|
277
|
-
isEnabled,
|
|
278
|
-
enable,
|
|
279
|
-
disable,
|
|
280
|
-
onWheel
|
|
281
|
-
};
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
module.exports = scrollZoomHandler;
|
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
const DOM = require('../../util/dom');
|
|
2
|
-
const { bezier } = require('../../util/util');
|
|
3
|
-
const { Event } = require('../../util/evented');
|
|
4
|
-
const makeFrame = require('./frame');
|
|
5
|
-
const makeInertia = require('./inertia');
|
|
6
|
-
|
|
7
|
-
const INERTIA_LINEARITY = 0.15;
|
|
8
|
-
const INERTIA_EASING = bezier(0, 0, INERTIA_LINEARITY, 1);
|
|
9
|
-
const INERTIA_DECELERATION = 12; // scale / s^2
|
|
10
|
-
const INERTIA_MAX_SPEED = 2.5; // scale / s;
|
|
11
|
-
|
|
12
|
-
const SIGNIFICANT_SCALE_THRESHOLD = 0.15;
|
|
13
|
-
const SIGNIFICANT_ROTATE_THRESHOLD = 10;
|
|
14
|
-
|
|
15
|
-
function makeMovement(map, { rotationDisabled, aroundCenter }, e) {
|
|
16
|
-
const el = map.getCanvasContainer();
|
|
17
|
-
|
|
18
|
-
const frame = makeFrame(map, onFrame);
|
|
19
|
-
|
|
20
|
-
const { vector: startVector, center } = getVector(e);
|
|
21
|
-
const startScale = map.transform.scale;
|
|
22
|
-
const startBearing = map.transform.bearing;
|
|
23
|
-
const inertia = makeInertia(map, calculateInertia);
|
|
24
|
-
|
|
25
|
-
let gestureIntent;
|
|
26
|
-
let lastCenter = center;
|
|
27
|
-
const around = map.transform.pointLocation(center);
|
|
28
|
-
|
|
29
|
-
function onMove(e) {
|
|
30
|
-
const { vector, center } = getVector(e);
|
|
31
|
-
lastCenter = center;
|
|
32
|
-
|
|
33
|
-
const scale = vector.mag() / startVector.mag();
|
|
34
|
-
inertia.update(scale);
|
|
35
|
-
frame.request(e, { vector, scale, center });
|
|
36
|
-
|
|
37
|
-
if (gestureIntent) return;
|
|
38
|
-
|
|
39
|
-
// Determine 'intent' by whichever threshold is surpassed first,
|
|
40
|
-
// then keep that state for the duration of this gesture.
|
|
41
|
-
if (!rotationDisabled) {
|
|
42
|
-
const bearing = (vector.angleWith(startVector) * 180) / Math.PI;
|
|
43
|
-
if (Math.abs(bearing) > SIGNIFICANT_ROTATE_THRESHOLD) {
|
|
44
|
-
gestureIntent = 'rotate';
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!gestureIntent) {
|
|
49
|
-
if (rotationDisabled && scale !== 1) {
|
|
50
|
-
// when rotation is disabled, any scale change triggers the zoom gesture to start
|
|
51
|
-
gestureIntent = 'zoom';
|
|
52
|
-
} else if (Math.abs(1 - scale) > SIGNIFICANT_SCALE_THRESHOLD) {
|
|
53
|
-
gestureIntent = 'zoom';
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
if (gestureIntent) {
|
|
58
|
-
map.fire(new Event(`${gestureIntent}start`, { originalEvent: e }));
|
|
59
|
-
map.fire(new Event('movestart', { originalEvent: e }));
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
function onFrame(e, { vector, scale, center }) {
|
|
64
|
-
if (!gestureIntent) return;
|
|
65
|
-
|
|
66
|
-
if (gestureIntent === 'rotate') {
|
|
67
|
-
const bearing = (vector.angleWith(startVector) * 180) / Math.PI;
|
|
68
|
-
map.transform.bearing = startBearing + bearing;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
map.transform.zoom = map.transform.scaleZoom(startScale * scale);
|
|
72
|
-
map.transform.setLocationAtPoint(around, center);
|
|
73
|
-
|
|
74
|
-
map.fire(new Event(gestureIntent, { originalEvent: e }));
|
|
75
|
-
map.fire(new Event('move', { originalEvent: e }));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
function onEnd(e) {
|
|
79
|
-
frame.cancel();
|
|
80
|
-
|
|
81
|
-
if (!gestureIntent) return;
|
|
82
|
-
|
|
83
|
-
map.fire(new Event(`${gestureIntent}end`, { originalEvent: e }));
|
|
84
|
-
|
|
85
|
-
const { zoom, duration, empty } = inertia.calculate();
|
|
86
|
-
if (empty) {
|
|
87
|
-
map.snapToNorth({}, { originalEvent: e });
|
|
88
|
-
} else {
|
|
89
|
-
map.easeTo(
|
|
90
|
-
{
|
|
91
|
-
zoom,
|
|
92
|
-
duration,
|
|
93
|
-
easing: INERTIA_EASING,
|
|
94
|
-
around: aroundCenter ? map.getCenter() : map.unproject(lastCenter),
|
|
95
|
-
noMoveStart: true
|
|
96
|
-
},
|
|
97
|
-
{ originalEvent: e }
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
function getVector({ touches: [t0, t1] }) {
|
|
103
|
-
const p0 = DOM.mousePos(el, t0);
|
|
104
|
-
const p1 = DOM.mousePos(el, t1);
|
|
105
|
-
|
|
106
|
-
return {
|
|
107
|
-
vector: p0.sub(p1),
|
|
108
|
-
center: p0.add(p1).div(2)
|
|
109
|
-
};
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
function calculateInertia(first, last) {
|
|
113
|
-
const firstZoom = map.transform.scaleZoom(startScale * first.value);
|
|
114
|
-
const lastZoom = map.transform.scaleZoom(startScale * last.value);
|
|
115
|
-
|
|
116
|
-
const scaleDuration = (last.time - first.time) / 1000;
|
|
117
|
-
if (scaleDuration === 0 || lastZoom === firstZoom) {
|
|
118
|
-
return { empty: true };
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
// calculate scale/s speed and adjust for increased initial animation speed when easing
|
|
122
|
-
let speed = ((lastZoom - firstZoom) * INERTIA_LINEARITY) / scaleDuration; // scale/s
|
|
123
|
-
if (speed > INERTIA_MAX_SPEED) {
|
|
124
|
-
speed = INERTIA_MAX_SPEED;
|
|
125
|
-
} else if (speed < -INERTIA_MAX_SPEED) {
|
|
126
|
-
speed = -INERTIA_MAX_SPEED;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
const duration = Math.abs(speed / (INERTIA_DECELERATION * INERTIA_LINEARITY)) * 1000;
|
|
130
|
-
let zoom = lastZoom + (speed * duration) / 2000;
|
|
131
|
-
if (zoom < 0) {
|
|
132
|
-
zoom = 0;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
return { zoom, duration };
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
return {
|
|
139
|
-
onMove,
|
|
140
|
-
onFrame,
|
|
141
|
-
onEnd
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* The `TouchZoomRotateHandler` allows the user to zoom and rotate the map by
|
|
147
|
-
* pinching on a touchscreen.
|
|
148
|
-
*/
|
|
149
|
-
function touchZoomRotateHandler(map) {
|
|
150
|
-
let enabled = false;
|
|
151
|
-
let aroundCenter = false;
|
|
152
|
-
let rotationDisabled = false;
|
|
153
|
-
|
|
154
|
-
let movement;
|
|
155
|
-
|
|
156
|
-
/**
|
|
157
|
-
* Returns a Boolean indicating whether the "pinch to rotate and zoom" interaction is enabled.
|
|
158
|
-
*
|
|
159
|
-
* @returns {boolean} `true` if the "pinch to rotate and zoom" interaction is enabled.
|
|
160
|
-
*/
|
|
161
|
-
function isEnabled() {
|
|
162
|
-
return enabled;
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
/**
|
|
166
|
-
* Returns a Boolean indicating whether the "pinch to rotate and zoom" interaction is active.
|
|
167
|
-
*
|
|
168
|
-
* @returns {boolean} `true` if the "pinch to rotate and zoom" interaction is active.
|
|
169
|
-
*/
|
|
170
|
-
function isActive() {
|
|
171
|
-
return !!movement;
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Enables the "pinch to rotate and zoom" interaction.
|
|
176
|
-
*
|
|
177
|
-
* @param {Object} [options]
|
|
178
|
-
* @param {string} [options.around] If "center" is passed, map will zoom around the center
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* map.touchZoomRotate.enable();
|
|
182
|
-
* @example
|
|
183
|
-
* map.touchZoomRotate.enable({ around: 'center' });
|
|
184
|
-
*/
|
|
185
|
-
function enable(options) {
|
|
186
|
-
if (enabled) return;
|
|
187
|
-
map.getCanvasContainer().classList.add('mapboxgl-touch-zoom-rotate');
|
|
188
|
-
enabled = true;
|
|
189
|
-
aroundCenter = options && options.around === 'center';
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Disables the "pinch to rotate and zoom" interaction.
|
|
194
|
-
*
|
|
195
|
-
* @example
|
|
196
|
-
* map.touchZoomRotate.disable();
|
|
197
|
-
*/
|
|
198
|
-
function disable() {
|
|
199
|
-
if (!enabled) return;
|
|
200
|
-
map.getCanvasContainer().classList.remove('mapboxgl-touch-zoom-rotate');
|
|
201
|
-
enabled = false;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
* Disables the "pinch to rotate" interaction, leaving the "pinch to zoom"
|
|
206
|
-
* interaction enabled.
|
|
207
|
-
*
|
|
208
|
-
* @example
|
|
209
|
-
* map.touchZoomRotate.disableRotation();
|
|
210
|
-
*/
|
|
211
|
-
function disableRotation() {
|
|
212
|
-
rotationDisabled = true;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* Enables the "pinch to rotate" interaction.
|
|
217
|
-
*
|
|
218
|
-
* @example
|
|
219
|
-
* map.touchZoomRotate.enable();
|
|
220
|
-
* map.touchZoomRotate.enableRotation();
|
|
221
|
-
*/
|
|
222
|
-
function enableRotation() {
|
|
223
|
-
rotationDisabled = false;
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
function onStart(e) {
|
|
227
|
-
if (!enabled) return;
|
|
228
|
-
if (e.touches.length !== 2) return;
|
|
229
|
-
|
|
230
|
-
movement = makeMovement(map, { rotationDisabled, aroundCenter }, e);
|
|
231
|
-
|
|
232
|
-
window.document.addEventListener('touchmove', onMove, { passive: false });
|
|
233
|
-
window.document.addEventListener('touchend', onEnd);
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
function onMove(e) {
|
|
237
|
-
if (e.touches.length !== 2) return;
|
|
238
|
-
if (movement) {
|
|
239
|
-
movement.onMove(e);
|
|
240
|
-
e.preventDefault();
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
function onEnd(e) {
|
|
245
|
-
window.document.removeEventListener('touchmove', onMove, { passive: false });
|
|
246
|
-
window.document.removeEventListener('touchend', onEnd);
|
|
247
|
-
|
|
248
|
-
movement.onEnd(e);
|
|
249
|
-
movement = undefined;
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return {
|
|
253
|
-
isEnabled,
|
|
254
|
-
isActive,
|
|
255
|
-
enable,
|
|
256
|
-
disable,
|
|
257
|
-
enableRotation,
|
|
258
|
-
disableRotation,
|
|
259
|
-
onStart
|
|
260
|
-
};
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
module.exports = touchZoomRotateHandler;
|