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