@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
@@ -0,0 +1,54 @@
1
+ import Point from './point';
2
+ /**
3
+ * An `EdgeInset` object represents screen space padding applied to the edges of the viewport.
4
+ * This shifts the apprent center or the vanishing point of the map. This is useful for adding floating UI elements
5
+ * on top of the map and having the vanishing point shift as UI elements resize.
6
+ *
7
+ * @param {number} [top=0]
8
+ * @param {number} [bottom=0]
9
+ * @param {number} [left=0]
10
+ * @param {number} [right=0]
11
+ */
12
+ export default class EdgeInsets {
13
+ top: number;
14
+ bottom: number;
15
+ left: number;
16
+ right: number;
17
+ constructor(top?: number, bottom?: number, left?: number, right?: number);
18
+ /**
19
+ * Interpolates the inset in-place.
20
+ * This maintains the current inset value for any inset not present in `target`.
21
+ *
22
+ * @param {PaddingOptions} target
23
+ * @param {number} t
24
+ * @returns {EdgeInsets}
25
+ * @memberof EdgeInsets
26
+ */
27
+ interpolate(start: IPaddingOptions | EdgeInsets, target: IPaddingOptions, t: number): EdgeInsets;
28
+ /**
29
+ * Utility method that computes the new apprent center or vanishing point after applying insets.
30
+ * This is in pixels and with the top left being (0.0) and +y being downwards.
31
+ *
32
+ * @param {number} width
33
+ * @param {number} height
34
+ * @returns {Point}
35
+ * @memberof EdgeInsets
36
+ */
37
+ getCenter(width: number, height: number): Point;
38
+ equals(other: IPaddingOptions): boolean;
39
+ clone(): EdgeInsets;
40
+ /**
41
+ * Returns the current sdtate as json, useful when you want to have a
42
+ * read-only representation of the inset.
43
+ *
44
+ * @returns {PaddingOptions}
45
+ * @memberof EdgeInsets
46
+ */
47
+ toJSON(): IPaddingOptions;
48
+ }
49
+ export interface IPaddingOptions {
50
+ top?: number;
51
+ bottom?: number;
52
+ right?: number;
53
+ left?: number;
54
+ }
@@ -5,11 +5,11 @@ 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"));
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
9
  var _util = require("../util");
11
10
  var _point = _interopRequireDefault(require("./point"));
12
11
  // @ts-ignore
12
+
13
13
  /**
14
14
  * An `EdgeInset` object represents screen space padding applied to the edges of the viewport.
15
15
  * This shifts the apprent center or the vanishing point of the map. This is useful for adding floating UI elements
@@ -20,13 +20,12 @@ var _point = _interopRequireDefault(require("./point"));
20
20
  * @param {number} [left=0]
21
21
  * @param {number} [right=0]
22
22
  */
23
- var EdgeInsets = exports.default = /*#__PURE__*/function () {
24
- function EdgeInsets() {
25
- var top = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
26
- var bottom = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
27
- var left = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
28
- var right = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 0;
29
- (0, _classCallCheck2.default)(this, EdgeInsets);
23
+ class EdgeInsets {
24
+ constructor(top = 0, bottom = 0, left = 0, right = 0) {
25
+ (0, _defineProperty2.default)(this, "top", void 0);
26
+ (0, _defineProperty2.default)(this, "bottom", void 0);
27
+ (0, _defineProperty2.default)(this, "left", void 0);
28
+ (0, _defineProperty2.default)(this, "right", void 0);
30
29
  if (isNaN(top) || top < 0 || isNaN(bottom) || bottom < 0 || isNaN(left) || left < 0 || isNaN(right) || right < 0) {
31
30
  throw new Error('Invalid value for edge-insets, top, bottom, left and right must all be numbers');
32
31
  }
@@ -45,69 +44,58 @@ var EdgeInsets = exports.default = /*#__PURE__*/function () {
45
44
  * @returns {EdgeInsets}
46
45
  * @memberof EdgeInsets
47
46
  */
48
- (0, _createClass2.default)(EdgeInsets, [{
49
- key: "interpolate",
50
- value: function interpolate(start, target, t) {
51
- if (target.top != null && start.top != null) {
52
- this.top = (0, _util.interpolate)(start.top, target.top, t);
53
- }
54
- if (target.bottom != null && start.bottom != null) {
55
- this.bottom = (0, _util.interpolate)(start.bottom, target.bottom, t);
56
- }
57
- if (target.left != null && start.left != null) {
58
- this.left = (0, _util.interpolate)(start.left, target.left, t);
59
- }
60
- if (target.right != null && start.right != null) {
61
- this.right = (0, _util.interpolate)(start.right, target.right, t);
62
- }
63
- return this;
47
+ interpolate(start, target, t) {
48
+ if (target.top != null && start.top != null) {
49
+ this.top = (0, _util.interpolate)(start.top, target.top, t);
64
50
  }
65
-
66
- /**
67
- * Utility method that computes the new apprent center or vanishing point after applying insets.
68
- * This is in pixels and with the top left being (0.0) and +y being downwards.
69
- *
70
- * @param {number} width
71
- * @param {number} height
72
- * @returns {Point}
73
- * @memberof EdgeInsets
74
- */
75
- }, {
76
- key: "getCenter",
77
- value: function getCenter(width, height) {
78
- // Clamp insets so they never overflow width/height and always calculate a valid center
79
- var x = (0, _util.clamp)((this.left + width - this.right) / 2, 0, width);
80
- var y = (0, _util.clamp)((this.top + height - this.bottom) / 2, 0, height);
81
- return new _point.default(x, y);
51
+ if (target.bottom != null && start.bottom != null) {
52
+ this.bottom = (0, _util.interpolate)(start.bottom, target.bottom, t);
82
53
  }
83
- }, {
84
- key: "equals",
85
- value: function equals(other) {
86
- return this.top === other.top && this.bottom === other.bottom && this.left === other.left && this.right === other.right;
54
+ if (target.left != null && start.left != null) {
55
+ this.left = (0, _util.interpolate)(start.left, target.left, t);
87
56
  }
88
- }, {
89
- key: "clone",
90
- value: function clone() {
91
- return new EdgeInsets(this.top, this.bottom, this.left, this.right);
57
+ if (target.right != null && start.right != null) {
58
+ this.right = (0, _util.interpolate)(start.right, target.right, t);
92
59
  }
60
+ return this;
61
+ }
93
62
 
94
- /**
95
- * Returns the current sdtate as json, useful when you want to have a
96
- * read-only representation of the inset.
97
- *
98
- * @returns {PaddingOptions}
99
- * @memberof EdgeInsets
100
- */
101
- }, {
102
- key: "toJSON",
103
- value: function toJSON() {
104
- return {
105
- top: this.top,
106
- bottom: this.bottom,
107
- left: this.left,
108
- right: this.right
109
- };
110
- }
111
- }]);
112
- return EdgeInsets;
113
- }();
63
+ /**
64
+ * Utility method that computes the new apprent center or vanishing point after applying insets.
65
+ * This is in pixels and with the top left being (0.0) and +y being downwards.
66
+ *
67
+ * @param {number} width
68
+ * @param {number} height
69
+ * @returns {Point}
70
+ * @memberof EdgeInsets
71
+ */
72
+ getCenter(width, height) {
73
+ // Clamp insets so they never overflow width/height and always calculate a valid center
74
+ const x = (0, _util.clamp)((this.left + width - this.right) / 2, 0, width);
75
+ const y = (0, _util.clamp)((this.top + height - this.bottom) / 2, 0, height);
76
+ return new _point.default(x, y);
77
+ }
78
+ equals(other) {
79
+ return this.top === other.top && this.bottom === other.bottom && this.left === other.left && this.right === other.right;
80
+ }
81
+ clone() {
82
+ return new EdgeInsets(this.top, this.bottom, this.left, this.right);
83
+ }
84
+
85
+ /**
86
+ * Returns the current sdtate as json, useful when you want to have a
87
+ * read-only representation of the inset.
88
+ *
89
+ * @returns {PaddingOptions}
90
+ * @memberof EdgeInsets
91
+ */
92
+ toJSON() {
93
+ return {
94
+ top: this.top,
95
+ bottom: this.bottom,
96
+ left: this.left,
97
+ right: this.right
98
+ };
99
+ }
100
+ }
101
+ exports.default = EdgeInsets;
@@ -0,0 +1,18 @@
1
+ export declare const earthRadius = 6371008.8;
2
+ export type LngLatLike = LngLat | {
3
+ lng: number;
4
+ lat: number;
5
+ } | {
6
+ lon: number;
7
+ lat: number;
8
+ } | [number, number];
9
+ export default class LngLat {
10
+ static convert(input: LngLatLike): LngLat;
11
+ lng: number;
12
+ lat: number;
13
+ constructor(lng: number, lat: number);
14
+ wrap(): LngLat;
15
+ toArray(): [number, number];
16
+ toString(): string;
17
+ distanceTo(lngLat: LngLat): number;
18
+ }
@@ -5,16 +5,30 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.earthRadius = exports.default = void 0;
8
- var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
9
  var _util = require("../util");
12
- var earthRadius = exports.earthRadius = 6371008.8;
13
- var LngLat = exports.default = /*#__PURE__*/function () {
14
- function LngLat(lng, lat) {
15
- (0, _classCallCheck2.default)(this, LngLat);
10
+ const earthRadius = exports.earthRadius = 6371008.8;
11
+ class LngLat {
12
+ static convert(input) {
13
+ if (input instanceof LngLat) {
14
+ return input;
15
+ }
16
+ if (Array.isArray(input) && (input.length === 2 || input.length === 3)) {
17
+ return new LngLat(Number(input[0]), Number(input[1]));
18
+ }
19
+ if (!Array.isArray(input) && typeof input === 'object' && input !== null) {
20
+ const lng = 'lng' in input ? input.lng : input.lon;
21
+ return new LngLat(
22
+ // flow can't refine this to have one of lng or lat, so we have to cast to any
23
+ Number(lng), Number(input.lat));
24
+ }
25
+ throw new Error('`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]');
26
+ }
27
+ constructor(lng, lat) {
28
+ (0, _defineProperty2.default)(this, "lng", void 0);
29
+ (0, _defineProperty2.default)(this, "lat", void 0);
16
30
  if (isNaN(lng) || isNaN(lat)) {
17
- throw new Error("Invalid LngLat object: (".concat(lng, ", ").concat(lat, ")"));
31
+ throw new Error(`Invalid LngLat object: (${lng}, ${lat})`);
18
32
  }
19
33
  this.lng = +lng;
20
34
  this.lat = +lat;
@@ -22,58 +36,32 @@ var LngLat = exports.default = /*#__PURE__*/function () {
22
36
  throw new Error('Invalid LngLat latitude value: must be between -90 and 90');
23
37
  }
24
38
  }
25
- (0, _createClass2.default)(LngLat, [{
26
- key: "wrap",
27
- value: function wrap() {
28
- return new LngLat((0, _util.wrap)(this.lng, -180, 180), this.lat);
29
- }
30
- }, {
31
- key: "toArray",
32
- value: function toArray() {
33
- return [this.lng, this.lat];
34
- }
35
- // public toBounds(radius: number = 0) {
36
- // const earthCircumferenceInMetersAtEquator = 40075017;
37
- // const latAccuracy = (360 * radius) / earthCircumferenceInMetersAtEquator;
38
- // const lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);
39
+ wrap() {
40
+ return new LngLat((0, _util.wrap)(this.lng, -180, 180), this.lat);
41
+ }
42
+ toArray() {
43
+ return [this.lng, this.lat];
44
+ }
45
+ // public toBounds(radius: number = 0) {
46
+ // const earthCircumferenceInMetersAtEquator = 40075017;
47
+ // const latAccuracy = (360 * radius) / earthCircumferenceInMetersAtEquator;
48
+ // const lngAccuracy = latAccuracy / Math.cos((Math.PI / 180) * this.lat);
39
49
 
40
- // return new LngLatBounds(
41
- // new LngLat(this.lng - lngAccuracy, this.lat - latAccuracy),
42
- // new LngLat(this.lng + lngAccuracy, this.lat + latAccuracy),
43
- // );
44
- // }
45
- }, {
46
- key: "toString",
47
- value: function toString() {
48
- return "LngLat(".concat(this.lng, ", ").concat(this.lat, ")");
49
- }
50
- }, {
51
- key: "distanceTo",
52
- value: function distanceTo(lngLat) {
53
- var rad = Math.PI / 180;
54
- var lat1 = this.lat * rad;
55
- var lat2 = lngLat.lat * rad;
56
- var a = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos((lngLat.lng - this.lng) * rad);
57
- var maxMeters = earthRadius * Math.acos(Math.min(a, 1));
58
- return maxMeters;
59
- }
60
- }], [{
61
- key: "convert",
62
- value: function convert(input) {
63
- if (input instanceof LngLat) {
64
- return input;
65
- }
66
- if (Array.isArray(input) && (input.length === 2 || input.length === 3)) {
67
- return new LngLat(Number(input[0]), Number(input[1]));
68
- }
69
- if (!Array.isArray(input) && (0, _typeof2.default)(input) === 'object' && input !== null) {
70
- var lng = 'lng' in input ? input.lng : input.lon;
71
- return new LngLat(
72
- // flow can't refine this to have one of lng or lat, so we have to cast to any
73
- Number(lng), Number(input.lat));
74
- }
75
- throw new Error('`LngLatLike` argument must be specified as a LngLat instance, an object {lng: <lng>, lat: <lat>}, an object {lon: <lng>, lat: <lat>}, or an array of [<lng>, <lat>]');
76
- }
77
- }]);
78
- return LngLat;
79
- }();
50
+ // return new LngLatBounds(
51
+ // new LngLat(this.lng - lngAccuracy, this.lat - latAccuracy),
52
+ // new LngLat(this.lng + lngAccuracy, this.lat + latAccuracy),
53
+ // );
54
+ // }
55
+ toString() {
56
+ return `LngLat(${this.lng}, ${this.lat})`;
57
+ }
58
+ distanceTo(lngLat) {
59
+ const rad = Math.PI / 180;
60
+ const lat1 = this.lat * rad;
61
+ const lat2 = lngLat.lat * rad;
62
+ const a = Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos((lngLat.lng - this.lng) * rad);
63
+ const maxMeters = earthRadius * Math.acos(Math.min(a, 1));
64
+ return maxMeters;
65
+ }
66
+ }
67
+ exports.default = LngLat;
@@ -0,0 +1,25 @@
1
+ import type { LngLatLike } from './lng_lat';
2
+ import LngLat from './lng_lat';
3
+ export type LngLatBoundsLike = LngLatBounds | [LngLatLike, LngLatLike] | [number, number, number, number];
4
+ export default class LngLatBounds {
5
+ static convert(input: LngLatBoundsLike): LngLatBounds;
6
+ private ne;
7
+ private sw;
8
+ constructor(sw?: any, ne?: any);
9
+ setNorthEast(ne: LngLatLike): this;
10
+ setSouthWest(sw: LngLatLike): this;
11
+ extend(obj: LngLatLike | LngLatBoundsLike): this;
12
+ getCenter(): LngLat;
13
+ getSouthWest(): LngLat;
14
+ getNorthEast(): LngLat;
15
+ getNorthWest(): LngLat;
16
+ getSouthEast(): LngLat;
17
+ getWest(): number;
18
+ getSouth(): number;
19
+ getEast(): number;
20
+ getNorth(): number;
21
+ toArray(): [[number, number], [number, number]];
22
+ toString(): string;
23
+ isEmpty(): boolean;
24
+ contains(lnglat: LngLatLike): boolean;
25
+ }
@@ -5,12 +5,18 @@ 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"));
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
9
  var _lng_lat = _interopRequireDefault(require("./lng_lat"));
11
- var LngLatBounds = exports.default = /*#__PURE__*/function () {
12
- function LngLatBounds(sw, ne) {
13
- (0, _classCallCheck2.default)(this, LngLatBounds);
10
+ class LngLatBounds {
11
+ static convert(input) {
12
+ if (input instanceof LngLatBounds) {
13
+ return input;
14
+ }
15
+ return new LngLatBounds(input);
16
+ }
17
+ constructor(sw, ne) {
18
+ (0, _defineProperty2.default)(this, "ne", void 0);
19
+ (0, _defineProperty2.default)(this, "sw", void 0);
14
20
  if (!sw) {
15
21
  // noop
16
22
  } else if (ne) {
@@ -21,140 +27,100 @@ var LngLatBounds = exports.default = /*#__PURE__*/function () {
21
27
  this.setSouthWest(sw[0]).setNorthEast(sw[1]);
22
28
  }
23
29
  }
24
- (0, _createClass2.default)(LngLatBounds, [{
25
- key: "setNorthEast",
26
- value: function setNorthEast(ne) {
27
- this.ne = ne instanceof _lng_lat.default ? new _lng_lat.default(ne.lng, ne.lat) : _lng_lat.default.convert(ne);
28
- return this;
29
- }
30
- }, {
31
- key: "setSouthWest",
32
- value: function setSouthWest(sw) {
33
- this.sw = sw instanceof _lng_lat.default ? new _lng_lat.default(sw.lng, sw.lat) : _lng_lat.default.convert(sw);
34
- return this;
35
- }
36
- }, {
37
- key: "extend",
38
- value: function extend(obj) {
39
- var sw = this.sw;
40
- var ne = this.ne;
41
- var sw2;
42
- var ne2;
43
- if (obj instanceof _lng_lat.default) {
44
- sw2 = obj;
45
- ne2 = obj;
46
- } else if (obj instanceof LngLatBounds) {
47
- sw2 = obj.sw;
48
- ne2 = obj.ne;
49
- if (!sw2 || !ne2) {
50
- return this;
51
- }
52
- } else {
53
- if (Array.isArray(obj)) {
54
- // @ts-ignore
55
- if (obj.length === 4 || obj.every(Array.isArray)) {
56
- var lngLatBoundsObj = obj;
57
- return this.extend(LngLatBounds.convert(lngLatBoundsObj));
58
- } else {
59
- var lngLatObj = obj;
60
- return this.extend(_lng_lat.default.convert(lngLatObj));
61
- }
62
- }
30
+ setNorthEast(ne) {
31
+ this.ne = ne instanceof _lng_lat.default ? new _lng_lat.default(ne.lng, ne.lat) : _lng_lat.default.convert(ne);
32
+ return this;
33
+ }
34
+ setSouthWest(sw) {
35
+ this.sw = sw instanceof _lng_lat.default ? new _lng_lat.default(sw.lng, sw.lat) : _lng_lat.default.convert(sw);
36
+ return this;
37
+ }
38
+ extend(obj) {
39
+ const sw = this.sw;
40
+ const ne = this.ne;
41
+ let sw2;
42
+ let ne2;
43
+ if (obj instanceof _lng_lat.default) {
44
+ sw2 = obj;
45
+ ne2 = obj;
46
+ } else if (obj instanceof LngLatBounds) {
47
+ sw2 = obj.sw;
48
+ ne2 = obj.ne;
49
+ if (!sw2 || !ne2) {
63
50
  return this;
64
51
  }
65
- if (!sw && !ne) {
66
- this.sw = new _lng_lat.default(sw2.lng, sw2.lat);
67
- this.ne = new _lng_lat.default(ne2.lng, ne2.lat);
68
- } else {
69
- sw.lng = Math.min(sw2.lng, sw.lng);
70
- sw.lat = Math.min(sw2.lat, sw.lat);
71
- ne.lng = Math.max(ne2.lng, ne.lng);
72
- ne.lat = Math.max(ne2.lat, ne.lat);
52
+ } else {
53
+ if (Array.isArray(obj)) {
54
+ // @ts-ignore
55
+ if (obj.length === 4 || obj.every(Array.isArray)) {
56
+ const lngLatBoundsObj = obj;
57
+ return this.extend(LngLatBounds.convert(lngLatBoundsObj));
58
+ } else {
59
+ const lngLatObj = obj;
60
+ return this.extend(_lng_lat.default.convert(lngLatObj));
61
+ }
73
62
  }
74
63
  return this;
75
64
  }
76
- }, {
77
- key: "getCenter",
78
- value: function getCenter() {
79
- return new _lng_lat.default((this.sw.lng + this.ne.lng) / 2, (this.sw.lat + this.ne.lat) / 2);
80
- }
81
- }, {
82
- key: "getSouthWest",
83
- value: function getSouthWest() {
84
- return this.sw;
85
- }
86
- }, {
87
- key: "getNorthEast",
88
- value: function getNorthEast() {
89
- return this.ne;
90
- }
91
- }, {
92
- key: "getNorthWest",
93
- value: function getNorthWest() {
94
- return new _lng_lat.default(this.getWest(), this.getNorth());
95
- }
96
- }, {
97
- key: "getSouthEast",
98
- value: function getSouthEast() {
99
- return new _lng_lat.default(this.getEast(), this.getSouth());
100
- }
101
- }, {
102
- key: "getWest",
103
- value: function getWest() {
104
- return this.sw.lng;
105
- }
106
- }, {
107
- key: "getSouth",
108
- value: function getSouth() {
109
- return this.sw.lat;
110
- }
111
- }, {
112
- key: "getEast",
113
- value: function getEast() {
114
- return this.ne.lng;
115
- }
116
- }, {
117
- key: "getNorth",
118
- value: function getNorth() {
119
- return this.ne.lat;
120
- }
121
- }, {
122
- key: "toArray",
123
- value: function toArray() {
124
- return [this.sw.toArray(), this.ne.toArray()];
125
- }
126
- }, {
127
- key: "toString",
128
- value: function toString() {
129
- return "LngLatBounds(".concat(this.sw.toString(), ", ").concat(this.ne.toString(), ")");
130
- }
131
- }, {
132
- key: "isEmpty",
133
- value: function isEmpty() {
134
- return !(this.sw && this.ne);
135
- }
136
- }, {
137
- key: "contains",
138
- value: function contains(lnglat) {
139
- var _LngLat$convert = _lng_lat.default.convert(lnglat),
140
- lng = _LngLat$convert.lng,
141
- lat = _LngLat$convert.lat;
142
- var containsLatitude = this.sw.lat <= lat && lat <= this.ne.lat;
143
- var containsLongitude = this.sw.lng <= lng && lng <= this.ne.lng;
144
- if (this.sw.lng > this.ne.lng) {
145
- // wrapped coordinates
146
- containsLongitude = this.sw.lng >= lng && lng >= this.ne.lng;
147
- }
148
- return containsLatitude && containsLongitude;
149
- }
150
- }], [{
151
- key: "convert",
152
- value: function convert(input) {
153
- if (input instanceof LngLatBounds) {
154
- return input;
155
- }
156
- return new LngLatBounds(input);
65
+ if (!sw && !ne) {
66
+ this.sw = new _lng_lat.default(sw2.lng, sw2.lat);
67
+ this.ne = new _lng_lat.default(ne2.lng, ne2.lat);
68
+ } else {
69
+ sw.lng = Math.min(sw2.lng, sw.lng);
70
+ sw.lat = Math.min(sw2.lat, sw.lat);
71
+ ne.lng = Math.max(ne2.lng, ne.lng);
72
+ ne.lat = Math.max(ne2.lat, ne.lat);
157
73
  }
158
- }]);
159
- return LngLatBounds;
160
- }();
74
+ return this;
75
+ }
76
+ getCenter() {
77
+ return new _lng_lat.default((this.sw.lng + this.ne.lng) / 2, (this.sw.lat + this.ne.lat) / 2);
78
+ }
79
+ getSouthWest() {
80
+ return this.sw;
81
+ }
82
+ getNorthEast() {
83
+ return this.ne;
84
+ }
85
+ getNorthWest() {
86
+ return new _lng_lat.default(this.getWest(), this.getNorth());
87
+ }
88
+ getSouthEast() {
89
+ return new _lng_lat.default(this.getEast(), this.getSouth());
90
+ }
91
+ getWest() {
92
+ return this.sw.lng;
93
+ }
94
+ getSouth() {
95
+ return this.sw.lat;
96
+ }
97
+ getEast() {
98
+ return this.ne.lng;
99
+ }
100
+ getNorth() {
101
+ return this.ne.lat;
102
+ }
103
+ toArray() {
104
+ return [this.sw.toArray(), this.ne.toArray()];
105
+ }
106
+ toString() {
107
+ return `LngLatBounds(${this.sw.toString()}, ${this.ne.toString()})`;
108
+ }
109
+ isEmpty() {
110
+ return !(this.sw && this.ne);
111
+ }
112
+ contains(lnglat) {
113
+ const {
114
+ lng,
115
+ lat
116
+ } = _lng_lat.default.convert(lnglat);
117
+ const containsLatitude = this.sw.lat <= lat && lat <= this.ne.lat;
118
+ let containsLongitude = this.sw.lng <= lng && lng <= this.ne.lng;
119
+ if (this.sw.lng > this.ne.lng) {
120
+ // wrapped coordinates
121
+ containsLongitude = this.sw.lng >= lng && lng >= this.ne.lng;
122
+ }
123
+ return containsLatitude && containsLongitude;
124
+ }
125
+ }
126
+ exports.default = LngLatBounds;
@@ -0,0 +1,30 @@
1
+ import type { LngLatLike } from '../geo/lng_lat';
2
+ import LngLat from '../geo/lng_lat';
3
+ export declare function mercatorXfromLng(lng: number): number;
4
+ export declare function mercatorYfromLat(lat: number): number;
5
+ export declare function mercatorZfromAltitude(altitude: number, lat: number): number;
6
+ export declare function lngFromMercatorX(x: number): number;
7
+ export declare function latFromMercatorY(y: number): number;
8
+ export declare function altitudeFromMercatorZ(z: number, y: number): number;
9
+ /**
10
+ * Determine the Mercator scale factor for a given latitude, see
11
+ * https://en.wikipedia.org/wiki/Mercator_projection#Scale_factor
12
+ *
13
+ * At the equator the scale factor will be 1, which increases at higher latitudes.
14
+ *
15
+ * @param {number} lat Latitude
16
+ * @returns {number} scale factor
17
+ * @private
18
+ */
19
+ export declare function mercatorScale(lat: number): number;
20
+ export default class MercatorCoordinate {
21
+ static fromLngLat(lngLatLike: LngLatLike, altitude?: number): MercatorCoordinate;
22
+ x: number;
23
+ y: number;
24
+ z: number;
25
+ constructor(x: number, y: number, z?: number);
26
+ toLngLat(): LngLat;
27
+ toAltitude(): number;
28
+ meterInMercatorCoordinateUnits(): number;
29
+ }
30
+ export { MercatorCoordinate };