@antv/l7-map 2.21.0 → 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 -6
- 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 -43
- 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 -7
- 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 -42
- package/lib/utils/task_queue.d.ts +13 -0
- package/lib/utils/task_queue.js +47 -76
- package/package.json +25 -32
package/lib/util.d.ts
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface ICancelable {
|
|
2
|
+
cancel: () => void;
|
|
3
|
+
}
|
|
4
|
+
export declare function wrap(n: number, min: number, max: number): number;
|
|
5
|
+
export declare function clamp(n: number, min: number, max: number): number;
|
|
6
|
+
export declare function interpolate(a: number, b: number, t: number): number;
|
|
7
|
+
export declare function bezier(p1x: number, p1y: number, p2x: number, p2y: number): (t: number) => number;
|
|
8
|
+
export declare const ease: (t: number) => number;
|
|
9
|
+
export declare function prefersReducedMotion(): boolean;
|
|
10
|
+
export declare function pick(src: {
|
|
11
|
+
[key: string]: any;
|
|
12
|
+
}, properties: string[]): {
|
|
13
|
+
[key: string]: any;
|
|
14
|
+
};
|
|
15
|
+
export declare const now: () => number;
|
|
16
|
+
export declare const raf: ((callback: FrameRequestCallback) => number) & typeof requestAnimationFrame;
|
|
17
|
+
export declare const cancel: ((handle: number) => void) & typeof cancelAnimationFrame;
|
|
18
|
+
export declare function renderframe(fn: (paintStartTimestamp: number) => void): ICancelable;
|
|
19
|
+
export declare function extend(dest: {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
}, ...sources: Array<Partial<{
|
|
22
|
+
[key: string]: any;
|
|
23
|
+
}>>): {
|
|
24
|
+
[key: string]: any;
|
|
25
|
+
};
|
package/lib/util.js
CHANGED
|
@@ -17,13 +17,12 @@ exports.raf = void 0;
|
|
|
17
17
|
exports.renderframe = renderframe;
|
|
18
18
|
exports.wrap = wrap;
|
|
19
19
|
var _unitbezier = _interopRequireDefault(require("@mapbox/unitbezier"));
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
var reducedMotionQuery;
|
|
20
|
+
// @ts-ignore
|
|
21
|
+
|
|
22
|
+
let reducedMotionQuery;
|
|
24
23
|
function wrap(n, min, max) {
|
|
25
|
-
|
|
26
|
-
|
|
24
|
+
const d = max - min;
|
|
25
|
+
const w = ((n - min) % d + d) % d + min;
|
|
27
26
|
return w === min ? max : w;
|
|
28
27
|
}
|
|
29
28
|
function clamp(n, min, max) {
|
|
@@ -33,12 +32,12 @@ function interpolate(a, b, t) {
|
|
|
33
32
|
return a * (1 - t) + b * t;
|
|
34
33
|
}
|
|
35
34
|
function bezier(p1x, p1y, p2x, p2y) {
|
|
36
|
-
|
|
37
|
-
return
|
|
35
|
+
const bez = new _unitbezier.default(p1x, p1y, p2x, p2y);
|
|
36
|
+
return t => {
|
|
38
37
|
return bez.solve(t);
|
|
39
38
|
};
|
|
40
39
|
}
|
|
41
|
-
|
|
40
|
+
const ease = exports.ease = bezier(0.25, 0.1, 0.25, 1);
|
|
42
41
|
function prefersReducedMotion() {
|
|
43
42
|
var _reducedMotionQuery;
|
|
44
43
|
// Lazily initialize media query
|
|
@@ -49,32 +48,23 @@ function prefersReducedMotion() {
|
|
|
49
48
|
return (_reducedMotionQuery = reducedMotionQuery) === null || _reducedMotionQuery === void 0 ? void 0 : _reducedMotionQuery.matches;
|
|
50
49
|
}
|
|
51
50
|
function pick(src, properties) {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
57
|
-
var name = _step.value;
|
|
58
|
-
if (name in src) {
|
|
59
|
-
result[name] = src[name];
|
|
60
|
-
}
|
|
51
|
+
const result = {};
|
|
52
|
+
for (const name of properties) {
|
|
53
|
+
if (name in src) {
|
|
54
|
+
result[name] = src[name];
|
|
61
55
|
}
|
|
62
|
-
} catch (err) {
|
|
63
|
-
_iterator.e(err);
|
|
64
|
-
} finally {
|
|
65
|
-
_iterator.f();
|
|
66
56
|
}
|
|
67
57
|
return result;
|
|
68
58
|
}
|
|
69
|
-
|
|
70
|
-
|
|
59
|
+
const now = exports.now = window.performance && window.performance.now ? window.performance.now.bind(window.performance) : Date.now.bind(Date);
|
|
60
|
+
const raf = exports.raf = window.requestAnimationFrame ||
|
|
71
61
|
// @ts-ignore
|
|
72
62
|
window.mozRequestAnimationFrame ||
|
|
73
63
|
// @ts-ignore
|
|
74
64
|
window.webkitRequestAnimationFrame ||
|
|
75
65
|
// @ts-ignore
|
|
76
66
|
window.msRequestAnimationFrame;
|
|
77
|
-
|
|
67
|
+
const cancel = exports.cancel = window.cancelAnimationFrame ||
|
|
78
68
|
// @ts-ignore
|
|
79
69
|
window.mozCancelAnimationFrame ||
|
|
80
70
|
// @ts-ignore
|
|
@@ -82,20 +72,14 @@ window.webkitCancelAnimationFrame ||
|
|
|
82
72
|
// @ts-ignore
|
|
83
73
|
window.msCancelAnimationFrame;
|
|
84
74
|
function renderframe(fn) {
|
|
85
|
-
|
|
75
|
+
const frame = raf(fn);
|
|
86
76
|
return {
|
|
87
|
-
cancel:
|
|
88
|
-
return _cancel(frame);
|
|
89
|
-
}
|
|
77
|
+
cancel: () => cancel(frame)
|
|
90
78
|
};
|
|
91
79
|
}
|
|
92
|
-
function extend(dest) {
|
|
93
|
-
for (
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
for (var _i = 0, _sources = sources; _i < _sources.length; _i++) {
|
|
97
|
-
var src = _sources[_i];
|
|
98
|
-
for (var k in src) {
|
|
80
|
+
function extend(dest, ...sources) {
|
|
81
|
+
for (const src of sources) {
|
|
82
|
+
for (const k in src) {
|
|
99
83
|
if (src[k] !== undefined) {
|
|
100
84
|
dest[k] = src[k];
|
|
101
85
|
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { vec3 } from 'gl-matrix';
|
|
2
|
+
import type Frustum from './primitives';
|
|
3
|
+
export default class Aabb {
|
|
4
|
+
min: vec3;
|
|
5
|
+
max: vec3;
|
|
6
|
+
center: vec3;
|
|
7
|
+
constructor(min: vec3, max: vec3);
|
|
8
|
+
quadrant(index: number): Aabb;
|
|
9
|
+
distanceX(point: number[]): number;
|
|
10
|
+
distanceY(point: number[]): number;
|
|
11
|
+
intersects(frustum: Frustum): number;
|
|
12
|
+
}
|
package/lib/utils/Aabb.js
CHANGED
|
@@ -5,114 +5,76 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var
|
|
9
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
9
|
var _glMatrix = require("gl-matrix");
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
(0, _classCallCheck2.default)(this, Aabb);
|
|
10
|
+
class Aabb {
|
|
11
|
+
constructor(min, max) {
|
|
12
|
+
(0, _defineProperty2.default)(this, "min", void 0);
|
|
13
|
+
(0, _defineProperty2.default)(this, "max", void 0);
|
|
14
|
+
(0, _defineProperty2.default)(this, "center", void 0);
|
|
17
15
|
this.min = min;
|
|
18
16
|
this.max = max;
|
|
19
17
|
this.center = _glMatrix.vec3.scale(new Float32Array(3), _glMatrix.vec3.add(new Float32Array(3), this.min, this.max), 0.5);
|
|
20
18
|
}
|
|
21
|
-
(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
|
|
29
|
-
qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
|
|
30
|
-
}
|
|
31
|
-
// Elevation is always constant, hence quadrant.max.z = this.max.z
|
|
32
|
-
qMax[2] = this.max[2];
|
|
33
|
-
return new Aabb(qMin, qMax);
|
|
34
|
-
}
|
|
35
|
-
}, {
|
|
36
|
-
key: "distanceX",
|
|
37
|
-
value: function distanceX(point) {
|
|
38
|
-
var pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
|
|
39
|
-
return pointOnAabb - point[0];
|
|
40
|
-
}
|
|
41
|
-
}, {
|
|
42
|
-
key: "distanceY",
|
|
43
|
-
value: function distanceY(point) {
|
|
44
|
-
var pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
|
|
45
|
-
return pointOnAabb - point[1];
|
|
19
|
+
quadrant(index) {
|
|
20
|
+
const split = [index % 2 === 0, index < 2];
|
|
21
|
+
const qMin = _glMatrix.vec3.clone(this.min);
|
|
22
|
+
const qMax = _glMatrix.vec3.clone(this.max);
|
|
23
|
+
for (let axis = 0; axis < split.length; axis++) {
|
|
24
|
+
qMin[axis] = split[axis] ? this.min[axis] : this.center[axis];
|
|
25
|
+
qMax[axis] = split[axis] ? this.center[axis] : this.max[axis];
|
|
46
26
|
}
|
|
27
|
+
// Elevation is always constant, hence quadrant.max.z = this.max.z
|
|
28
|
+
qMax[2] = this.max[2];
|
|
29
|
+
return new Aabb(qMin, qMax);
|
|
30
|
+
}
|
|
31
|
+
distanceX(point) {
|
|
32
|
+
const pointOnAabb = Math.max(Math.min(this.max[0], point[0]), this.min[0]);
|
|
33
|
+
return pointOnAabb - point[0];
|
|
34
|
+
}
|
|
35
|
+
distanceY(point) {
|
|
36
|
+
const pointOnAabb = Math.max(Math.min(this.max[1], point[1]), this.min[1]);
|
|
37
|
+
return pointOnAabb - point[1];
|
|
38
|
+
}
|
|
47
39
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// Each frustum plane together with 3 major axes define the separating axes
|
|
55
|
-
// Note: test only 4 points as both min and max points have equal elevation
|
|
40
|
+
// Performs a frustum-aabb intersection test. Returns 0 if there's no intersection,
|
|
41
|
+
// 1 if shapes are intersecting and 2 if the aabb if fully inside the frustum.
|
|
42
|
+
intersects(frustum) {
|
|
43
|
+
// Execute separating axis test between two convex objects to find intersections
|
|
44
|
+
// Each frustum plane together with 3 major axes define the separating axes
|
|
45
|
+
// Note: test only 4 points as both min and max points have equal elevation
|
|
56
46
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
var pointsInside = 0;
|
|
65
|
-
var _iterator3 = _createForOfIteratorHelper(aabbPoints),
|
|
66
|
-
_step3;
|
|
67
|
-
try {
|
|
68
|
-
for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
|
|
69
|
-
var i = _step3.value;
|
|
70
|
-
// @ts-ignore
|
|
71
|
-
pointsInside += _glMatrix.vec4.dot(plane, i) >= 0;
|
|
72
|
-
}
|
|
73
|
-
} catch (err) {
|
|
74
|
-
_iterator3.e(err);
|
|
75
|
-
} finally {
|
|
76
|
-
_iterator3.f();
|
|
77
|
-
}
|
|
78
|
-
if (pointsInside === 0) {
|
|
79
|
-
return 0;
|
|
80
|
-
}
|
|
81
|
-
if (pointsInside !== aabbPoints.length) {
|
|
82
|
-
fullyInside = false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
} catch (err) {
|
|
86
|
-
_iterator.e(err);
|
|
87
|
-
} finally {
|
|
88
|
-
_iterator.f();
|
|
47
|
+
const aabbPoints = [[this.min[0], this.min[1], 0.0, 1], [this.max[0], this.min[1], 0.0, 1], [this.max[0], this.max[1], 0.0, 1], [this.min[0], this.max[1], 0.0, 1]];
|
|
48
|
+
let fullyInside = true;
|
|
49
|
+
for (const plane of frustum.planes) {
|
|
50
|
+
let pointsInside = 0;
|
|
51
|
+
for (const i of aabbPoints) {
|
|
52
|
+
// @ts-ignore
|
|
53
|
+
pointsInside += _glMatrix.vec4.dot(plane, i) >= 0;
|
|
89
54
|
}
|
|
90
|
-
if (
|
|
91
|
-
return
|
|
55
|
+
if (pointsInside === 0) {
|
|
56
|
+
return 0;
|
|
92
57
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
var projMax = -Number.MAX_VALUE;
|
|
96
|
-
var _iterator2 = _createForOfIteratorHelper(frustum.points),
|
|
97
|
-
_step2;
|
|
98
|
-
try {
|
|
99
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
100
|
-
var p = _step2.value;
|
|
101
|
-
var projectedPoint = p[axis] - this.min[axis];
|
|
102
|
-
projMin = Math.min(projMin, projectedPoint);
|
|
103
|
-
projMax = Math.max(projMax, projectedPoint);
|
|
104
|
-
}
|
|
105
|
-
} catch (err) {
|
|
106
|
-
_iterator2.e(err);
|
|
107
|
-
} finally {
|
|
108
|
-
_iterator2.f();
|
|
109
|
-
}
|
|
110
|
-
if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
|
|
111
|
-
return 0;
|
|
112
|
-
}
|
|
58
|
+
if (pointsInside !== aabbPoints.length) {
|
|
59
|
+
fullyInside = false;
|
|
113
60
|
}
|
|
114
|
-
return 1;
|
|
115
61
|
}
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
}
|
|
62
|
+
if (fullyInside) {
|
|
63
|
+
return 2;
|
|
64
|
+
}
|
|
65
|
+
for (let axis = 0; axis < 3; axis++) {
|
|
66
|
+
let projMin = Number.MAX_VALUE;
|
|
67
|
+
let projMax = -Number.MAX_VALUE;
|
|
68
|
+
for (const p of frustum.points) {
|
|
69
|
+
const projectedPoint = p[axis] - this.min[axis];
|
|
70
|
+
projMin = Math.min(projMin, projectedPoint);
|
|
71
|
+
projMax = Math.max(projMax, projectedPoint);
|
|
72
|
+
}
|
|
73
|
+
if (projMax < 0 || projMin > this.max[axis] - this.min[axis]) {
|
|
74
|
+
return 0;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return 1;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
exports.default = Aabb;
|
package/lib/utils/dom.js
CHANGED
|
@@ -6,13 +6,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
8
|
var _point = _interopRequireDefault(require("../geo/point"));
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
var DOM = {};
|
|
9
|
+
// @ts-ignore
|
|
10
|
+
|
|
11
|
+
const DOM = {};
|
|
13
12
|
var _default = exports.default = DOM;
|
|
14
|
-
DOM.create =
|
|
15
|
-
|
|
13
|
+
DOM.create = (tagName, className, container) => {
|
|
14
|
+
const el = window.document.createElement(tagName);
|
|
16
15
|
if (className !== undefined) {
|
|
17
16
|
el.className = className;
|
|
18
17
|
}
|
|
@@ -21,58 +20,49 @@ DOM.create = function (tagName, className, container) {
|
|
|
21
20
|
}
|
|
22
21
|
return el;
|
|
23
22
|
};
|
|
24
|
-
DOM.createNS =
|
|
25
|
-
|
|
23
|
+
DOM.createNS = (namespaceURI, tagName) => {
|
|
24
|
+
const el = window.document.createElementNS(namespaceURI, tagName);
|
|
26
25
|
return el;
|
|
27
26
|
};
|
|
28
|
-
|
|
27
|
+
const docStyle = window.document && window.document.documentElement.style;
|
|
29
28
|
function testProp(props) {
|
|
30
29
|
if (!docStyle) {
|
|
31
30
|
return props[0];
|
|
32
31
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
37
|
-
var i = _step.value;
|
|
38
|
-
if (i in docStyle) {
|
|
39
|
-
return i;
|
|
40
|
-
}
|
|
32
|
+
for (const i of props) {
|
|
33
|
+
if (i in docStyle) {
|
|
34
|
+
return i;
|
|
41
35
|
}
|
|
42
|
-
} catch (err) {
|
|
43
|
-
_iterator.e(err);
|
|
44
|
-
} finally {
|
|
45
|
-
_iterator.f();
|
|
46
36
|
}
|
|
47
37
|
return props[0];
|
|
48
38
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
DOM.disableDrag =
|
|
39
|
+
const selectProp = testProp(['userSelect', 'MozUserSelect', 'WebkitUserSelect', 'msUserSelect']);
|
|
40
|
+
let userSelect;
|
|
41
|
+
DOM.disableDrag = () => {
|
|
52
42
|
if (docStyle && selectProp) {
|
|
53
43
|
userSelect = docStyle[selectProp];
|
|
54
44
|
docStyle[selectProp] = 'none';
|
|
55
45
|
}
|
|
56
46
|
};
|
|
57
|
-
DOM.enableDrag =
|
|
47
|
+
DOM.enableDrag = () => {
|
|
58
48
|
if (docStyle && selectProp) {
|
|
59
49
|
docStyle[selectProp] = userSelect;
|
|
60
50
|
}
|
|
61
51
|
};
|
|
62
|
-
|
|
63
|
-
DOM.setTransform =
|
|
52
|
+
const transformProp = testProp(['transform', 'WebkitTransform']);
|
|
53
|
+
DOM.setTransform = (el, value) => {
|
|
64
54
|
// https://github.com/facebook/flow/issues/7754
|
|
65
55
|
// $FlowFixMe
|
|
66
56
|
el.style[transformProp] = value;
|
|
67
57
|
};
|
|
68
58
|
|
|
69
59
|
// Feature detection for {passive: false} support in add/removeEventListener.
|
|
70
|
-
|
|
60
|
+
let passiveSupported = false;
|
|
71
61
|
try {
|
|
72
62
|
// https://github.com/facebook/flow/issues/285
|
|
73
63
|
// $FlowFixMe
|
|
74
|
-
|
|
75
|
-
get
|
|
64
|
+
const options = Object.defineProperty({}, 'passive', {
|
|
65
|
+
get() {
|
|
76
66
|
// eslint-disable-line
|
|
77
67
|
passiveSupported = true;
|
|
78
68
|
}
|
|
@@ -84,16 +74,14 @@ try {
|
|
|
84
74
|
} catch (err) {
|
|
85
75
|
passiveSupported = false;
|
|
86
76
|
}
|
|
87
|
-
DOM.addEventListener =
|
|
88
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
77
|
+
DOM.addEventListener = (target, type, callback, options = {}) => {
|
|
89
78
|
if ('passive' in options && passiveSupported) {
|
|
90
79
|
target.addEventListener(type, callback, options);
|
|
91
80
|
} else {
|
|
92
81
|
target.addEventListener(type, callback, options.capture);
|
|
93
82
|
}
|
|
94
83
|
};
|
|
95
|
-
DOM.removeEventListener =
|
|
96
|
-
var options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : {};
|
|
84
|
+
DOM.removeEventListener = (target, type, callback, options = {}) => {
|
|
97
85
|
if ('passive' in options && passiveSupported) {
|
|
98
86
|
target.removeEventListener(type, callback, options);
|
|
99
87
|
} else {
|
|
@@ -102,44 +90,35 @@ DOM.removeEventListener = function (target, type, callback) {
|
|
|
102
90
|
};
|
|
103
91
|
|
|
104
92
|
// Suppress the next click, but only if it's immediate.
|
|
105
|
-
|
|
93
|
+
const suppressClick = e => {
|
|
106
94
|
e.preventDefault();
|
|
107
95
|
e.stopPropagation();
|
|
108
96
|
window.removeEventListener('click', suppressClick, true);
|
|
109
97
|
};
|
|
110
|
-
DOM.suppressClick =
|
|
98
|
+
DOM.suppressClick = () => {
|
|
111
99
|
window.addEventListener('click', suppressClick, true);
|
|
112
|
-
setTimeout(
|
|
100
|
+
setTimeout(() => {
|
|
113
101
|
window.removeEventListener('click', suppressClick, true);
|
|
114
102
|
}, 0);
|
|
115
103
|
};
|
|
116
|
-
DOM.mousePos =
|
|
104
|
+
DOM.mousePos = (el, e) => {
|
|
117
105
|
// 暂时从 el 上获取 top/left, 后面需要动态获取
|
|
118
|
-
|
|
106
|
+
const rect = el.getBoundingClientRect();
|
|
119
107
|
return new _point.default(e.clientX - rect.left - el.clientLeft, e.clientY - rect.top - el.clientTop);
|
|
120
108
|
};
|
|
121
|
-
DOM.touchPos =
|
|
109
|
+
DOM.touchPos = (el, touches) => {
|
|
122
110
|
// 暂时从 el 上获取 top/left, 后面需要动态获取
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
try {
|
|
128
|
-
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
129
|
-
var touche = _step2.value;
|
|
130
|
-
points.push(new _point.default(touche.clientX - rect.left - el.clientLeft, touche.clientY - rect.top - el.clientTop));
|
|
131
|
-
}
|
|
132
|
-
} catch (err) {
|
|
133
|
-
_iterator2.e(err);
|
|
134
|
-
} finally {
|
|
135
|
-
_iterator2.f();
|
|
111
|
+
const rect = el.getBoundingClientRect();
|
|
112
|
+
const points = [];
|
|
113
|
+
for (const touche of touches) {
|
|
114
|
+
points.push(new _point.default(touche.clientX - rect.left - el.clientLeft, touche.clientY - rect.top - el.clientTop));
|
|
136
115
|
}
|
|
137
116
|
return points;
|
|
138
117
|
};
|
|
139
|
-
DOM.mouseButton =
|
|
118
|
+
DOM.mouseButton = e => {
|
|
140
119
|
return e.button;
|
|
141
120
|
};
|
|
142
|
-
DOM.remove =
|
|
121
|
+
DOM.remove = node => {
|
|
143
122
|
if (node.parentNode) {
|
|
144
123
|
node.parentNode.removeChild(node);
|
|
145
124
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export interface IPerformanceMetrics {
|
|
2
|
+
loadTime: number;
|
|
3
|
+
fullLoadTime: number;
|
|
4
|
+
fps: number;
|
|
5
|
+
percentDroppedFrames: number;
|
|
6
|
+
}
|
|
7
|
+
export declare const PerformanceMarkers: {
|
|
8
|
+
create: string;
|
|
9
|
+
load: string;
|
|
10
|
+
fullLoad: string;
|
|
11
|
+
};
|
|
12
|
+
export declare const PerformanceUtils: {
|
|
13
|
+
mark(marker: string): void;
|
|
14
|
+
frame(timestamp: number): void;
|
|
15
|
+
clearMetrics(): void;
|
|
16
|
+
getPerformanceMetrics(): IPerformanceMetrics;
|
|
17
|
+
};
|
package/lib/utils/performance.js
CHANGED
|
@@ -4,65 +4,61 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.PerformanceUtils = exports.PerformanceMarkers = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
7
|
+
let lastFrameTime = null;
|
|
8
|
+
let frameTimes = [];
|
|
9
|
+
const minFramerateTarget = 30;
|
|
10
|
+
const frameTimeTarget = 1000 / minFramerateTarget;
|
|
11
|
+
const performance = window.performance;
|
|
12
|
+
const PerformanceMarkers = exports.PerformanceMarkers = {
|
|
13
13
|
create: 'create',
|
|
14
14
|
load: 'load',
|
|
15
15
|
fullLoad: 'fullLoad'
|
|
16
16
|
};
|
|
17
|
-
|
|
18
|
-
mark
|
|
17
|
+
const PerformanceUtils = exports.PerformanceUtils = {
|
|
18
|
+
mark(marker) {
|
|
19
19
|
performance.mark(marker);
|
|
20
20
|
},
|
|
21
|
-
frame
|
|
22
|
-
|
|
21
|
+
frame(timestamp) {
|
|
22
|
+
const currTimestamp = timestamp;
|
|
23
23
|
if (lastFrameTime != null) {
|
|
24
|
-
|
|
24
|
+
const frameTime = currTimestamp - lastFrameTime;
|
|
25
25
|
frameTimes.push(frameTime);
|
|
26
26
|
}
|
|
27
27
|
lastFrameTime = currTimestamp;
|
|
28
28
|
},
|
|
29
|
-
clearMetrics
|
|
29
|
+
clearMetrics() {
|
|
30
30
|
lastFrameTime = null;
|
|
31
31
|
frameTimes = [];
|
|
32
32
|
performance.clearMeasures('loadTime');
|
|
33
33
|
performance.clearMeasures('fullLoadTime');
|
|
34
34
|
// @ts-ignore
|
|
35
35
|
// tslint:disable-next-line:forin
|
|
36
|
-
for (
|
|
36
|
+
for (const marker in PerformanceMarkers) {
|
|
37
37
|
// @ts-ignore
|
|
38
38
|
performance.clearMarks(PerformanceMarkers[marker]);
|
|
39
39
|
}
|
|
40
40
|
},
|
|
41
|
-
getPerformanceMetrics
|
|
42
|
-
|
|
41
|
+
getPerformanceMetrics() {
|
|
42
|
+
const loadTime = performance.measure('loadTime', PerformanceMarkers.create, PerformanceMarkers.load
|
|
43
43
|
// @ts-ignore
|
|
44
44
|
).duration;
|
|
45
|
-
|
|
45
|
+
const fullLoadTime = performance.measure('fullLoadTime', PerformanceMarkers.create, PerformanceMarkers.fullLoad
|
|
46
46
|
// @ts-ignore
|
|
47
47
|
).duration;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
}, 0) / totalFrames / 1000;
|
|
52
|
-
var fps = 1 / avgFrameTime;
|
|
48
|
+
const totalFrames = frameTimes.length;
|
|
49
|
+
const avgFrameTime = frameTimes.reduce((prev, curr) => prev + curr, 0) / totalFrames / 1000;
|
|
50
|
+
const fps = 1 / avgFrameTime;
|
|
53
51
|
|
|
54
52
|
// count frames that missed our framerate target
|
|
55
|
-
|
|
56
|
-
return frameTime > frameTimeTarget;
|
|
57
|
-
}).reduce(function (acc, curr) {
|
|
53
|
+
const droppedFrames = frameTimes.filter(frameTime => frameTime > frameTimeTarget).reduce((acc, curr) => {
|
|
58
54
|
return acc + (curr - frameTimeTarget) / frameTimeTarget;
|
|
59
55
|
}, 0);
|
|
60
|
-
|
|
56
|
+
const percentDroppedFrames = droppedFrames / (totalFrames + droppedFrames) * 100;
|
|
61
57
|
return {
|
|
62
|
-
loadTime
|
|
63
|
-
fullLoadTime
|
|
64
|
-
fps
|
|
65
|
-
percentDroppedFrames
|
|
58
|
+
loadTime,
|
|
59
|
+
fullLoadTime,
|
|
60
|
+
fps,
|
|
61
|
+
percentDroppedFrames
|
|
66
62
|
};
|
|
67
63
|
}
|
|
68
64
|
};
|