@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/geo/mercator.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -14,15 +13,14 @@ exports.mercatorScale = mercatorScale;
|
|
|
14
13
|
exports.mercatorXfromLng = mercatorXfromLng;
|
|
15
14
|
exports.mercatorYfromLat = mercatorYfromLat;
|
|
16
15
|
exports.mercatorZfromAltitude = mercatorZfromAltitude;
|
|
17
|
-
var
|
|
18
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
17
|
var _lng_lat = _interopRequireWildcard(require("../geo/lng_lat"));
|
|
20
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
21
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
18
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
20
|
/*
|
|
23
21
|
* The average circumference of the world in meters.
|
|
24
22
|
*/
|
|
25
|
-
|
|
23
|
+
const earthCircumfrence = 2 * Math.PI * _lng_lat.earthRadius; // meters
|
|
26
24
|
|
|
27
25
|
/*
|
|
28
26
|
* The circumference at a line of latitude in meters.
|
|
@@ -43,7 +41,7 @@ function lngFromMercatorX(x) {
|
|
|
43
41
|
return x * 360 - 180;
|
|
44
42
|
}
|
|
45
43
|
function latFromMercatorY(y) {
|
|
46
|
-
|
|
44
|
+
const y2 = 180 - y * 360;
|
|
47
45
|
return 360 / Math.PI * Math.atan(Math.exp(y2 * Math.PI / 180)) - 90;
|
|
48
46
|
}
|
|
49
47
|
function altitudeFromMercatorZ(z, y) {
|
|
@@ -63,37 +61,28 @@ function altitudeFromMercatorZ(z, y) {
|
|
|
63
61
|
function mercatorScale(lat) {
|
|
64
62
|
return 1 / Math.cos(lat * Math.PI / 180);
|
|
65
63
|
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
(
|
|
64
|
+
class MercatorCoordinate {
|
|
65
|
+
static fromLngLat(lngLatLike, altitude = 0) {
|
|
66
|
+
const lngLat = _lng_lat.default.convert(lngLatLike);
|
|
67
|
+
return new MercatorCoordinate(mercatorXfromLng(lngLat.lng), mercatorYfromLat(lngLat.lat), mercatorZfromAltitude(altitude, lngLat.lat));
|
|
68
|
+
}
|
|
69
|
+
constructor(x, y, z = 0) {
|
|
70
|
+
(0, _defineProperty2.default)(this, "x", void 0);
|
|
71
|
+
(0, _defineProperty2.default)(this, "y", void 0);
|
|
72
|
+
(0, _defineProperty2.default)(this, "z", void 0);
|
|
70
73
|
this.x = +x;
|
|
71
74
|
this.y = +y;
|
|
72
75
|
this.z = +z;
|
|
73
76
|
}
|
|
74
|
-
(
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
value: function meterInMercatorCoordinateUnits() {
|
|
87
|
-
// 1 meter / circumference at equator in meters * Mercator projection scale factor at this latitude
|
|
88
|
-
return 1 / earthCircumfrence * mercatorScale(latFromMercatorY(this.y));
|
|
89
|
-
}
|
|
90
|
-
}], [{
|
|
91
|
-
key: "fromLngLat",
|
|
92
|
-
value: function fromLngLat(lngLatLike) {
|
|
93
|
-
var altitude = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
94
|
-
var lngLat = _lng_lat.default.convert(lngLatLike);
|
|
95
|
-
return new MercatorCoordinate(mercatorXfromLng(lngLat.lng), mercatorYfromLat(lngLat.lat), mercatorZfromAltitude(altitude, lngLat.lat));
|
|
96
|
-
}
|
|
97
|
-
}]);
|
|
98
|
-
return MercatorCoordinate;
|
|
99
|
-
}();
|
|
77
|
+
toLngLat() {
|
|
78
|
+
return new _lng_lat.default(lngFromMercatorX(this.x), latFromMercatorY(this.y));
|
|
79
|
+
}
|
|
80
|
+
toAltitude() {
|
|
81
|
+
return altitudeFromMercatorZ(this.z, this.y);
|
|
82
|
+
}
|
|
83
|
+
meterInMercatorCoordinateUnits() {
|
|
84
|
+
// 1 meter / circumference at equator in meters * Mercator projection scale factor at this latitude
|
|
85
|
+
return 1 / earthCircumfrence * mercatorScale(latFromMercatorY(this.y));
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
exports.MercatorCoordinate = exports.default = MercatorCoordinate;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type PointLike = [number, number] | Point;
|
|
2
|
+
export default class Point {
|
|
3
|
+
static convert(a: any): any;
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
constructor(x: number, y: number);
|
|
7
|
+
clone(): Point;
|
|
8
|
+
_add(p: Point): this;
|
|
9
|
+
add(p: Point): Point;
|
|
10
|
+
_sub(p: Point): this;
|
|
11
|
+
sub(p: Point): Point;
|
|
12
|
+
_multByPoint(p: Point): this;
|
|
13
|
+
multByPoint(p: Point): Point;
|
|
14
|
+
_divByPoint(p: Point): this;
|
|
15
|
+
divByPoint(p: Point): Point;
|
|
16
|
+
_mult(k: number): this;
|
|
17
|
+
mult(k: number): Point;
|
|
18
|
+
_div(k: number): this;
|
|
19
|
+
div(k: number): Point;
|
|
20
|
+
_rotate(angle: number): this;
|
|
21
|
+
rotate(angle: number): Point;
|
|
22
|
+
_rotateAround(angle: number, p: Point): this;
|
|
23
|
+
roateAround(angle: number, p: Point): Point;
|
|
24
|
+
_matMult(m: number[]): this;
|
|
25
|
+
matMult(m: number[]): Point;
|
|
26
|
+
_unit(): this;
|
|
27
|
+
unit(): Point;
|
|
28
|
+
_perp(): this;
|
|
29
|
+
perp(): Point;
|
|
30
|
+
_round(): this;
|
|
31
|
+
round(): Point;
|
|
32
|
+
mag(): number;
|
|
33
|
+
equals(other: Point): boolean;
|
|
34
|
+
dist(p: Point): number;
|
|
35
|
+
distSqr(p: Point): number;
|
|
36
|
+
angle(): number;
|
|
37
|
+
angleTo(b: Point): number;
|
|
38
|
+
angleWith(b: Point): number;
|
|
39
|
+
angleWithSep(x: number, y: number): number;
|
|
40
|
+
}
|
package/lib/geo/point.js
CHANGED
|
@@ -5,226 +5,157 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.default = void 0;
|
|
8
|
-
var
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
class Point {
|
|
10
|
+
static convert(a) {
|
|
11
|
+
if (a instanceof Point) {
|
|
12
|
+
return a;
|
|
13
|
+
}
|
|
14
|
+
if (Array.isArray(a)) {
|
|
15
|
+
return new Point(a[0], a[1]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
}
|
|
19
|
+
constructor(x, y) {
|
|
20
|
+
(0, _defineProperty2.default)(this, "x", void 0);
|
|
21
|
+
(0, _defineProperty2.default)(this, "y", void 0);
|
|
13
22
|
this.x = x;
|
|
14
23
|
this.y = y;
|
|
15
24
|
}
|
|
16
|
-
(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
var y = this.y;
|
|
154
|
-
this.y = this.x;
|
|
155
|
-
this.x = -y;
|
|
156
|
-
return this;
|
|
157
|
-
}
|
|
158
|
-
}, {
|
|
159
|
-
key: "perp",
|
|
160
|
-
value: function perp() {
|
|
161
|
-
return this.clone()._perp();
|
|
162
|
-
}
|
|
163
|
-
}, {
|
|
164
|
-
key: "_round",
|
|
165
|
-
value: function _round() {
|
|
166
|
-
this.x = Math.round(this.x);
|
|
167
|
-
this.y = Math.round(this.y);
|
|
168
|
-
return this;
|
|
169
|
-
}
|
|
170
|
-
}, {
|
|
171
|
-
key: "round",
|
|
172
|
-
value: function round() {
|
|
173
|
-
return this.clone()._round();
|
|
174
|
-
}
|
|
175
|
-
}, {
|
|
176
|
-
key: "mag",
|
|
177
|
-
value: function mag() {
|
|
178
|
-
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
179
|
-
}
|
|
180
|
-
}, {
|
|
181
|
-
key: "equals",
|
|
182
|
-
value: function equals(other) {
|
|
183
|
-
return this.x === other.x && this.y === other.y;
|
|
184
|
-
}
|
|
185
|
-
}, {
|
|
186
|
-
key: "dist",
|
|
187
|
-
value: function dist(p) {
|
|
188
|
-
return Math.sqrt(this.distSqr(p));
|
|
189
|
-
}
|
|
190
|
-
}, {
|
|
191
|
-
key: "distSqr",
|
|
192
|
-
value: function distSqr(p) {
|
|
193
|
-
var dx = p.x - this.x;
|
|
194
|
-
var dy = p.y - this.y;
|
|
195
|
-
return dx * dx + dy * dy;
|
|
196
|
-
}
|
|
197
|
-
}, {
|
|
198
|
-
key: "angle",
|
|
199
|
-
value: function angle() {
|
|
200
|
-
return Math.atan2(this.y, this.x);
|
|
201
|
-
}
|
|
202
|
-
}, {
|
|
203
|
-
key: "angleTo",
|
|
204
|
-
value: function angleTo(b) {
|
|
205
|
-
return Math.atan2(this.y - b.y, this.x - b.x);
|
|
206
|
-
}
|
|
207
|
-
}, {
|
|
208
|
-
key: "angleWith",
|
|
209
|
-
value: function angleWith(b) {
|
|
210
|
-
return this.angleWithSep(b.x, b.y);
|
|
211
|
-
}
|
|
212
|
-
}, {
|
|
213
|
-
key: "angleWithSep",
|
|
214
|
-
value: function angleWithSep(x, y) {
|
|
215
|
-
return Math.atan2(this.x * y - this.y * x, this.x * x + this.y * y);
|
|
216
|
-
}
|
|
217
|
-
}], [{
|
|
218
|
-
key: "convert",
|
|
219
|
-
value: function convert(a) {
|
|
220
|
-
if (a instanceof Point) {
|
|
221
|
-
return a;
|
|
222
|
-
}
|
|
223
|
-
if (Array.isArray(a)) {
|
|
224
|
-
return new Point(a[0], a[1]);
|
|
225
|
-
}
|
|
226
|
-
return a;
|
|
227
|
-
}
|
|
228
|
-
}]);
|
|
229
|
-
return Point;
|
|
230
|
-
}();
|
|
25
|
+
clone() {
|
|
26
|
+
return new Point(this.x, this.y);
|
|
27
|
+
}
|
|
28
|
+
_add(p) {
|
|
29
|
+
this.x += p.x;
|
|
30
|
+
this.y += p.y;
|
|
31
|
+
return this;
|
|
32
|
+
}
|
|
33
|
+
add(p) {
|
|
34
|
+
return this.clone()._add(p);
|
|
35
|
+
}
|
|
36
|
+
_sub(p) {
|
|
37
|
+
this.x -= p.x;
|
|
38
|
+
this.y -= p.y;
|
|
39
|
+
return this;
|
|
40
|
+
}
|
|
41
|
+
sub(p) {
|
|
42
|
+
return this.clone()._sub(p);
|
|
43
|
+
}
|
|
44
|
+
_multByPoint(p) {
|
|
45
|
+
this.x *= p.x;
|
|
46
|
+
this.y *= p.y;
|
|
47
|
+
return this;
|
|
48
|
+
}
|
|
49
|
+
multByPoint(p) {
|
|
50
|
+
return this.clone()._multByPoint(p);
|
|
51
|
+
}
|
|
52
|
+
_divByPoint(p) {
|
|
53
|
+
this.x /= p.x;
|
|
54
|
+
this.y /= p.y;
|
|
55
|
+
return this;
|
|
56
|
+
}
|
|
57
|
+
divByPoint(p) {
|
|
58
|
+
return this.clone()._divByPoint(p);
|
|
59
|
+
}
|
|
60
|
+
_mult(k) {
|
|
61
|
+
this.x *= k;
|
|
62
|
+
this.y *= k;
|
|
63
|
+
return this;
|
|
64
|
+
}
|
|
65
|
+
mult(k) {
|
|
66
|
+
return this.clone()._mult(k);
|
|
67
|
+
}
|
|
68
|
+
_div(k) {
|
|
69
|
+
this.x /= k;
|
|
70
|
+
this.y /= k;
|
|
71
|
+
return this;
|
|
72
|
+
}
|
|
73
|
+
div(k) {
|
|
74
|
+
return this.clone()._div(k);
|
|
75
|
+
}
|
|
76
|
+
_rotate(angle) {
|
|
77
|
+
const cos = Math.cos(angle);
|
|
78
|
+
const sin = Math.sin(angle);
|
|
79
|
+
const x = cos * this.x - sin * this.y;
|
|
80
|
+
const y = sin * this.x + cos * this.y;
|
|
81
|
+
this.x = x;
|
|
82
|
+
this.y = y;
|
|
83
|
+
return this;
|
|
84
|
+
}
|
|
85
|
+
rotate(angle) {
|
|
86
|
+
return this.clone()._rotate(angle);
|
|
87
|
+
}
|
|
88
|
+
_rotateAround(angle, p) {
|
|
89
|
+
const cos = Math.cos(angle);
|
|
90
|
+
const sin = Math.sin(angle);
|
|
91
|
+
const x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y);
|
|
92
|
+
const y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
|
|
93
|
+
this.x = x;
|
|
94
|
+
this.y = y;
|
|
95
|
+
return this;
|
|
96
|
+
}
|
|
97
|
+
roateAround(angle, p) {
|
|
98
|
+
return this.clone()._rotateAround(angle, p);
|
|
99
|
+
}
|
|
100
|
+
_matMult(m) {
|
|
101
|
+
const x = m[0] * this.x + m[1] * this.y;
|
|
102
|
+
const y = m[2] * this.x + m[3] * this.y;
|
|
103
|
+
this.x = x;
|
|
104
|
+
this.y = y;
|
|
105
|
+
return this;
|
|
106
|
+
}
|
|
107
|
+
matMult(m) {
|
|
108
|
+
return this.clone()._matMult(m);
|
|
109
|
+
}
|
|
110
|
+
_unit() {
|
|
111
|
+
this.div(this.mag());
|
|
112
|
+
return this;
|
|
113
|
+
}
|
|
114
|
+
unit() {
|
|
115
|
+
return this.clone()._unit();
|
|
116
|
+
}
|
|
117
|
+
_perp() {
|
|
118
|
+
const y = this.y;
|
|
119
|
+
this.y = this.x;
|
|
120
|
+
this.x = -y;
|
|
121
|
+
return this;
|
|
122
|
+
}
|
|
123
|
+
perp() {
|
|
124
|
+
return this.clone()._perp();
|
|
125
|
+
}
|
|
126
|
+
_round() {
|
|
127
|
+
this.x = Math.round(this.x);
|
|
128
|
+
this.y = Math.round(this.y);
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
round() {
|
|
132
|
+
return this.clone()._round();
|
|
133
|
+
}
|
|
134
|
+
mag() {
|
|
135
|
+
return Math.sqrt(this.x * this.x + this.y * this.y);
|
|
136
|
+
}
|
|
137
|
+
equals(other) {
|
|
138
|
+
return this.x === other.x && this.y === other.y;
|
|
139
|
+
}
|
|
140
|
+
dist(p) {
|
|
141
|
+
return Math.sqrt(this.distSqr(p));
|
|
142
|
+
}
|
|
143
|
+
distSqr(p) {
|
|
144
|
+
const dx = p.x - this.x;
|
|
145
|
+
const dy = p.y - this.y;
|
|
146
|
+
return dx * dx + dy * dy;
|
|
147
|
+
}
|
|
148
|
+
angle() {
|
|
149
|
+
return Math.atan2(this.y, this.x);
|
|
150
|
+
}
|
|
151
|
+
angleTo(b) {
|
|
152
|
+
return Math.atan2(this.y - b.y, this.x - b.x);
|
|
153
|
+
}
|
|
154
|
+
angleWith(b) {
|
|
155
|
+
return this.angleWithSep(b.x, b.y);
|
|
156
|
+
}
|
|
157
|
+
angleWithSep(x, y) {
|
|
158
|
+
return Math.atan2(this.x * y - this.y * x, this.x * x + this.y * y);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
exports.default = Point;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { LngLatLike } from '../geo/lng_lat';
|
|
2
|
+
import LngLat from '../geo/lng_lat';
|
|
3
|
+
export declare function circumferenceAtLatitude(latitude: number): number;
|
|
4
|
+
export declare function mercatorXfromLng(lng: number): number;
|
|
5
|
+
export declare function mercatorYfromLat(lat: number): number;
|
|
6
|
+
export declare function mercatorZfromAltitude(altitude: number, lat: number): number;
|
|
7
|
+
export declare function lngFromMercatorX(x: number): number;
|
|
8
|
+
export declare function latFromMercatorY(y: number): number;
|
|
9
|
+
export declare function altitudeFromMercatorZ(z: number, y: number): number;
|
|
10
|
+
/**
|
|
11
|
+
* Determine the Mercator scale factor for a given latitude, see
|
|
12
|
+
* https://en.wikipedia.org/wiki/Mercator_projection#Scale_factor
|
|
13
|
+
*
|
|
14
|
+
* At the equator the scale factor will be 1, which increases at higher latitudes.
|
|
15
|
+
*
|
|
16
|
+
* @param {number} lat Latitude
|
|
17
|
+
* @returns {number} scale factor
|
|
18
|
+
* @private
|
|
19
|
+
*/
|
|
20
|
+
export declare function mercatorScale(lat: number): number;
|
|
21
|
+
export default class SimpleCoordinate {
|
|
22
|
+
static fromLngLat(lngLatLike: LngLatLike, altitude?: number): SimpleCoordinate;
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
z: number;
|
|
26
|
+
constructor(x: number, y: number, z?: number);
|
|
27
|
+
toLngLat(): LngLat;
|
|
28
|
+
toAltitude(): number;
|
|
29
|
+
meterInMercatorCoordinateUnits(): number;
|
|
30
|
+
}
|
package/lib/geo/simple.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -14,15 +13,14 @@ exports.mercatorScale = mercatorScale;
|
|
|
14
13
|
exports.mercatorXfromLng = mercatorXfromLng;
|
|
15
14
|
exports.mercatorYfromLat = mercatorYfromLat;
|
|
16
15
|
exports.mercatorZfromAltitude = mercatorZfromAltitude;
|
|
17
|
-
var
|
|
18
|
-
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
16
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
19
17
|
var _lng_lat = _interopRequireWildcard(require("../geo/lng_lat"));
|
|
20
|
-
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function
|
|
21
|
-
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" !=
|
|
18
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
|
|
19
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
|
22
20
|
/*
|
|
23
21
|
* The average circumference of the world in meters.
|
|
24
22
|
*/
|
|
25
|
-
|
|
23
|
+
const earthCircumfrence = 2 * Math.PI * _lng_lat.earthRadius; // meters
|
|
26
24
|
|
|
27
25
|
/*
|
|
28
26
|
* The circumference at a line of latitude in meters.
|
|
@@ -67,37 +65,28 @@ function altitudeFromMercatorZ(z, y) {
|
|
|
67
65
|
function mercatorScale(lat) {
|
|
68
66
|
return 1;
|
|
69
67
|
}
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
(
|
|
68
|
+
class SimpleCoordinate {
|
|
69
|
+
static fromLngLat(lngLatLike, altitude = 0) {
|
|
70
|
+
const lngLat = _lng_lat.default.convert(lngLatLike);
|
|
71
|
+
return new SimpleCoordinate(mercatorXfromLng(lngLat.lng), mercatorYfromLat(lngLat.lat), mercatorZfromAltitude(altitude, lngLat.lat));
|
|
72
|
+
}
|
|
73
|
+
constructor(x, y, z = 0) {
|
|
74
|
+
(0, _defineProperty2.default)(this, "x", void 0);
|
|
75
|
+
(0, _defineProperty2.default)(this, "y", void 0);
|
|
76
|
+
(0, _defineProperty2.default)(this, "z", void 0);
|
|
74
77
|
this.x = +x;
|
|
75
78
|
this.y = +y;
|
|
76
79
|
this.z = +z;
|
|
77
80
|
}
|
|
78
|
-
(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
value: function meterInMercatorCoordinateUnits() {
|
|
91
|
-
// 1 meter / circumference at equator in meters * Mercator projection scale factor at this latitude
|
|
92
|
-
return 1;
|
|
93
|
-
}
|
|
94
|
-
}], [{
|
|
95
|
-
key: "fromLngLat",
|
|
96
|
-
value: function fromLngLat(lngLatLike) {
|
|
97
|
-
var altitude = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
|
|
98
|
-
var lngLat = _lng_lat.default.convert(lngLatLike);
|
|
99
|
-
return new SimpleCoordinate(mercatorXfromLng(lngLat.lng), mercatorYfromLat(lngLat.lat), mercatorZfromAltitude(altitude, lngLat.lat));
|
|
100
|
-
}
|
|
101
|
-
}]);
|
|
102
|
-
return SimpleCoordinate;
|
|
103
|
-
}();
|
|
81
|
+
toLngLat() {
|
|
82
|
+
return new _lng_lat.default(this.x, this.y);
|
|
83
|
+
}
|
|
84
|
+
toAltitude() {
|
|
85
|
+
return this.z;
|
|
86
|
+
}
|
|
87
|
+
meterInMercatorCoordinateUnits() {
|
|
88
|
+
// 1 meter / circumference at equator in meters * Mercator projection scale factor at this latitude
|
|
89
|
+
return 1;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
exports.default = SimpleCoordinate;
|