@antv/l7-map 2.21.1 → 2.21.3
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 -5
- 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 -42
- 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 -6
- 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 -41
- package/lib/utils/task_queue.d.ts +13 -0
- package/lib/utils/task_queue.js +47 -76
- package/package.json +25 -32
package/es/geo/edge_insets.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import
|
|
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
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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(
|
|
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
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
+
}
|
package/es/geo/lng_lat_bounds.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
if (
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
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
|
+
}
|
package/es/geo/mercator.js
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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 };
|