@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.
Files changed (158) hide show
  1. package/es/camera.js +595 -674
  2. package/es/earthmap.js +313 -276
  3. package/es/geo/edge_insets.js +57 -72
  4. package/es/geo/lng_lat.js +50 -64
  5. package/es/geo/lng_lat_bounds.js +101 -137
  6. package/es/geo/mercator.js +23 -35
  7. package/es/geo/point.js +150 -221
  8. package/es/geo/simple.js +22 -34
  9. package/es/geo/transform.js +839 -905
  10. package/es/handler/blockable_map_event.js +46 -66
  11. package/es/handler/box_zoom.js +125 -143
  12. package/es/handler/click_zoom.js +37 -51
  13. package/es/handler/events/event.js +11 -9
  14. package/es/handler/events/map_mouse_event.js +39 -54
  15. package/es/handler/events/map_touch_event.js +54 -73
  16. package/es/handler/events/map_wheel_event.js +22 -38
  17. package/es/handler/events/render_event.js +6 -23
  18. package/es/handler/handler_inertia.js +98 -113
  19. package/es/handler/handler_manager.js +349 -437
  20. package/es/handler/handler_util.js +2 -2
  21. package/es/handler/keyboard.js +98 -110
  22. package/es/handler/map_event.js +81 -117
  23. package/es/handler/mouse/mouse_handler.js +81 -100
  24. package/es/handler/mouse/mousepan_handler.js +16 -39
  25. package/es/handler/mouse/mousepitch_hander.js +18 -40
  26. package/es/handler/mouse/mouserotate_hander.js +18 -40
  27. package/es/handler/mouse/util.js +7 -6
  28. package/es/handler/scroll_zoom.js +221 -231
  29. package/es/handler/shim/dblclick_zoom.js +36 -47
  30. package/es/handler/shim/drag_pan.js +41 -50
  31. package/es/handler/shim/drag_rotate.js +38 -48
  32. package/es/handler/shim/touch_zoom_rotate.js +68 -79
  33. package/es/handler/tap/single_tap_recognizer.js +60 -80
  34. package/es/handler/tap/tap_drag_zoom.js +72 -89
  35. package/es/handler/tap/tap_recognizer.js +37 -45
  36. package/es/handler/tap/tap_zoom.js +67 -95
  37. package/es/handler/touch/touch_pan.js +77 -96
  38. package/es/handler/touch/touch_pitch.js +61 -79
  39. package/es/handler/touch/touch_rotate.js +47 -67
  40. package/es/handler/touch/touch_zoom.js +29 -46
  41. package/es/handler/touch/two_touch.js +79 -104
  42. package/es/hash.js +75 -88
  43. package/es/map.js +318 -284
  44. package/es/util.js +18 -37
  45. package/es/utils/Aabb.js +60 -100
  46. package/es/utils/dom.js +32 -55
  47. package/es/utils/performance.js +25 -29
  48. package/es/utils/primitives.js +33 -43
  49. package/es/utils/task_queue.js +47 -76
  50. package/lib/camera.d.ts +86 -0
  51. package/lib/camera.js +597 -672
  52. package/lib/earthmap.d.ts +69 -0
  53. package/lib/earthmap.js +314 -276
  54. package/lib/geo/edge_insets.d.ts +54 -0
  55. package/lib/geo/edge_insets.js +58 -70
  56. package/lib/geo/lng_lat.d.ts +18 -0
  57. package/lib/geo/lng_lat.js +50 -62
  58. package/lib/geo/lng_lat_bounds.d.ts +25 -0
  59. package/lib/geo/lng_lat_bounds.js +102 -136
  60. package/lib/geo/mercator.d.ts +30 -0
  61. package/lib/geo/mercator.js +26 -37
  62. package/lib/geo/point.d.ts +40 -0
  63. package/lib/geo/point.js +151 -220
  64. package/lib/geo/simple.d.ts +30 -0
  65. package/lib/geo/simple.js +25 -36
  66. package/lib/geo/transform.d.ts +198 -0
  67. package/lib/geo/transform.js +844 -907
  68. package/lib/handler/IHandler.d.ts +34 -0
  69. package/lib/handler/blockable_map_event.d.ts +17 -0
  70. package/lib/handler/blockable_map_event.js +48 -65
  71. package/lib/handler/box_zoom.d.ts +59 -0
  72. package/lib/handler/box_zoom.js +126 -143
  73. package/lib/handler/click_zoom.d.ts +16 -0
  74. package/lib/handler/click_zoom.js +38 -50
  75. package/lib/handler/events/event.d.ts +4 -0
  76. package/lib/handler/events/event.js +12 -9
  77. package/lib/handler/events/index.d.ts +4 -0
  78. package/lib/handler/events/index.js +3 -3
  79. package/lib/handler/events/map_mouse_event.d.ts +34 -0
  80. package/lib/handler/events/map_mouse_event.js +41 -52
  81. package/lib/handler/events/map_touch_event.d.ts +57 -0
  82. package/lib/handler/events/map_touch_event.js +56 -71
  83. package/lib/handler/events/map_wheel_event.d.ts +33 -0
  84. package/lib/handler/events/map_wheel_event.js +23 -37
  85. package/lib/handler/events/render_event.d.ts +5 -0
  86. package/lib/handler/events/render_event.js +7 -22
  87. package/lib/handler/handler_inertia.d.ts +23 -0
  88. package/lib/handler/handler_inertia.js +102 -112
  89. package/lib/handler/handler_manager.d.ts +61 -0
  90. package/lib/handler/handler_manager.js +351 -437
  91. package/lib/handler/handler_util.d.ts +4 -0
  92. package/lib/handler/handler_util.js +2 -2
  93. package/lib/handler/keyboard.d.ts +36 -0
  94. package/lib/handler/keyboard.js +98 -110
  95. package/lib/handler/map_event.d.ts +29 -0
  96. package/lib/handler/map_event.js +83 -116
  97. package/lib/handler/mouse/index.d.ts +4 -0
  98. package/lib/handler/mouse/index.js +3 -3
  99. package/lib/handler/mouse/mouse_handler.d.ts +22 -0
  100. package/lib/handler/mouse/mouse_handler.js +83 -99
  101. package/lib/handler/mouse/mousepan_handler.d.ts +10 -0
  102. package/lib/handler/mouse/mousepan_handler.js +19 -38
  103. package/lib/handler/mouse/mousepitch_hander.d.ts +9 -0
  104. package/lib/handler/mouse/mousepitch_hander.js +21 -39
  105. package/lib/handler/mouse/mouserotate_hander.d.ts +9 -0
  106. package/lib/handler/mouse/mouserotate_hander.js +21 -39
  107. package/lib/handler/mouse/util.d.ts +6 -0
  108. package/lib/handler/mouse/util.js +7 -7
  109. package/lib/handler/scroll_zoom.d.ts +93 -0
  110. package/lib/handler/scroll_zoom.js +221 -231
  111. package/lib/handler/shim/dblclick_zoom.d.ts +40 -0
  112. package/lib/handler/shim/dblclick_zoom.js +37 -46
  113. package/lib/handler/shim/drag_pan.d.ts +61 -0
  114. package/lib/handler/shim/drag_pan.js +42 -49
  115. package/lib/handler/shim/drag_rotate.d.ts +46 -0
  116. package/lib/handler/shim/drag_rotate.js +39 -47
  117. package/lib/handler/shim/touch_zoom_rotate.d.ts +70 -0
  118. package/lib/handler/shim/touch_zoom_rotate.js +69 -78
  119. package/lib/handler/tap/single_tap_recognizer.d.ts +20 -0
  120. package/lib/handler/tap/single_tap_recognizer.js +63 -79
  121. package/lib/handler/tap/tap_drag_zoom.d.ts +22 -0
  122. package/lib/handler/tap/tap_drag_zoom.js +74 -88
  123. package/lib/handler/tap/tap_recognizer.d.ts +17 -0
  124. package/lib/handler/tap/tap_recognizer.js +41 -47
  125. package/lib/handler/tap/tap_zoom.d.ts +22 -0
  126. package/lib/handler/tap/tap_zoom.js +69 -94
  127. package/lib/handler/touch/index.d.ts +5 -0
  128. package/lib/handler/touch/index.js +4 -4
  129. package/lib/handler/touch/touch_pan.d.ts +30 -0
  130. package/lib/handler/touch/touch_pan.js +79 -95
  131. package/lib/handler/touch/touch_pitch.d.ts +13 -0
  132. package/lib/handler/touch/touch_pitch.js +64 -78
  133. package/lib/handler/touch/touch_rotate.d.ts +12 -0
  134. package/lib/handler/touch/touch_rotate.js +50 -66
  135. package/lib/handler/touch/touch_zoom.d.ts +12 -0
  136. package/lib/handler/touch/touch_zoom.js +32 -45
  137. package/lib/handler/touch/two_touch.d.ts +23 -0
  138. package/lib/handler/touch/two_touch.js +81 -103
  139. package/lib/hash.d.ts +14 -0
  140. package/lib/hash.js +75 -88
  141. package/lib/index.d.ts +4 -0
  142. package/lib/index.js +4 -4
  143. package/lib/interface.d.ts +34 -0
  144. package/lib/map.d.ts +70 -0
  145. package/lib/map.js +319 -284
  146. package/lib/util.d.ts +25 -0
  147. package/lib/util.js +20 -36
  148. package/lib/utils/Aabb.d.ts +12 -0
  149. package/lib/utils/Aabb.js +61 -99
  150. package/lib/utils/dom.d.ts +4 -0
  151. package/lib/utils/dom.js +34 -55
  152. package/lib/utils/performance.d.ts +17 -0
  153. package/lib/utils/performance.js +25 -29
  154. package/lib/utils/primitives.d.ts +6 -0
  155. package/lib/utils/primitives.js +34 -42
  156. package/lib/utils/task_queue.d.ts +13 -0
  157. package/lib/utils/task_queue.js +47 -76
  158. package/package.json +25 -32
@@ -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 _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
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 _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
- 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; }
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
- var earthCircumfrence = 2 * Math.PI * _lng_lat.earthRadius; // meters
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
- var y2 = 180 - y * 360;
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
- var MercatorCoordinate = exports.MercatorCoordinate = exports.default = /*#__PURE__*/function () {
67
- function MercatorCoordinate(x, y) {
68
- var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
69
- (0, _classCallCheck2.default)(this, MercatorCoordinate);
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
- (0, _createClass2.default)(MercatorCoordinate, [{
75
- key: "toLngLat",
76
- value: function toLngLat() {
77
- return new _lng_lat.default(lngFromMercatorX(this.x), latFromMercatorY(this.y));
78
- }
79
- }, {
80
- key: "toAltitude",
81
- value: function toAltitude() {
82
- return altitudeFromMercatorZ(this.z, this.y);
83
- }
84
- }, {
85
- key: "meterInMercatorCoordinateUnits",
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 _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
- var Point = exports.default = /*#__PURE__*/function () {
11
- function Point(x, y) {
12
- (0, _classCallCheck2.default)(this, Point);
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
- (0, _createClass2.default)(Point, [{
17
- key: "clone",
18
- value: function clone() {
19
- return new Point(this.x, this.y);
20
- }
21
- }, {
22
- key: "_add",
23
- value: function _add(p) {
24
- this.x += p.x;
25
- this.y += p.y;
26
- return this;
27
- }
28
- }, {
29
- key: "add",
30
- value: function add(p) {
31
- return this.clone()._add(p);
32
- }
33
- }, {
34
- key: "_sub",
35
- value: function _sub(p) {
36
- this.x -= p.x;
37
- this.y -= p.y;
38
- return this;
39
- }
40
- }, {
41
- key: "sub",
42
- value: function sub(p) {
43
- return this.clone()._sub(p);
44
- }
45
- }, {
46
- key: "_multByPoint",
47
- value: function _multByPoint(p) {
48
- this.x *= p.x;
49
- this.y *= p.y;
50
- return this;
51
- }
52
- }, {
53
- key: "multByPoint",
54
- value: function multByPoint(p) {
55
- return this.clone()._multByPoint(p);
56
- }
57
- }, {
58
- key: "_divByPoint",
59
- value: function _divByPoint(p) {
60
- this.x /= p.x;
61
- this.y /= p.y;
62
- return this;
63
- }
64
- }, {
65
- key: "divByPoint",
66
- value: function divByPoint(p) {
67
- return this.clone()._divByPoint(p);
68
- }
69
- }, {
70
- key: "_mult",
71
- value: function _mult(k) {
72
- this.x *= k;
73
- this.y *= k;
74
- return this;
75
- }
76
- }, {
77
- key: "mult",
78
- value: function mult(k) {
79
- return this.clone()._mult(k);
80
- }
81
- }, {
82
- key: "_div",
83
- value: function _div(k) {
84
- this.x /= k;
85
- this.y /= k;
86
- return this;
87
- }
88
- }, {
89
- key: "div",
90
- value: function div(k) {
91
- return this.clone()._div(k);
92
- }
93
- }, {
94
- key: "_rotate",
95
- value: function _rotate(angle) {
96
- var cos = Math.cos(angle);
97
- var sin = Math.sin(angle);
98
- var x = cos * this.x - sin * this.y;
99
- var y = sin * this.x + cos * this.y;
100
- this.x = x;
101
- this.y = y;
102
- return this;
103
- }
104
- }, {
105
- key: "rotate",
106
- value: function rotate(angle) {
107
- return this.clone()._rotate(angle);
108
- }
109
- }, {
110
- key: "_rotateAround",
111
- value: function _rotateAround(angle, p) {
112
- var cos = Math.cos(angle);
113
- var sin = Math.sin(angle);
114
- var x = p.x + cos * (this.x - p.x) - sin * (this.y - p.y);
115
- var y = p.y + sin * (this.x - p.x) + cos * (this.y - p.y);
116
- this.x = x;
117
- this.y = y;
118
- return this;
119
- }
120
- }, {
121
- key: "roateAround",
122
- value: function roateAround(angle, p) {
123
- return this.clone()._rotateAround(angle, p);
124
- }
125
- }, {
126
- key: "_matMult",
127
- value: function _matMult(m) {
128
- var x = m[0] * this.x + m[1] * this.y;
129
- var y = m[2] * this.x + m[3] * this.y;
130
- this.x = x;
131
- this.y = y;
132
- return this;
133
- }
134
- }, {
135
- key: "matMult",
136
- value: function matMult(m) {
137
- return this.clone()._matMult(m);
138
- }
139
- }, {
140
- key: "_unit",
141
- value: function _unit() {
142
- this.div(this.mag());
143
- return this;
144
- }
145
- }, {
146
- key: "unit",
147
- value: function unit() {
148
- return this.clone()._unit();
149
- }
150
- }, {
151
- key: "_perp",
152
- value: function _perp() {
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 _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
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 _getRequireWildcardCache(e) { return e ? t : r; })(e); }
21
- 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; }
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
- var earthCircumfrence = 2 * Math.PI * _lng_lat.earthRadius; // meters
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
- var SimpleCoordinate = exports.default = /*#__PURE__*/function () {
71
- function SimpleCoordinate(x, y) {
72
- var z = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
73
- (0, _classCallCheck2.default)(this, SimpleCoordinate);
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
- (0, _createClass2.default)(SimpleCoordinate, [{
79
- key: "toLngLat",
80
- value: function toLngLat() {
81
- return new _lng_lat.default(this.x, this.y);
82
- }
83
- }, {
84
- key: "toAltitude",
85
- value: function toAltitude() {
86
- return this.z;
87
- }
88
- }, {
89
- key: "meterInMercatorCoordinateUnits",
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;