@math.gl/web-mercator 3.5.3 → 3.6.0-alpha.1
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/dist/assert.d.ts +2 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +8 -0
- package/dist/es5/assert.js.map +1 -1
- package/dist/es5/fit-bounds.js +40 -50
- package/dist/es5/fit-bounds.js.map +1 -1
- package/dist/es5/fly-to-viewport.js +82 -98
- package/dist/es5/fly-to-viewport.js.map +1 -1
- package/dist/es5/get-bounds.js +25 -24
- package/dist/es5/get-bounds.js.map +1 -1
- package/dist/es5/index.js +23 -25
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/math-utils.js +5 -11
- package/dist/es5/math-utils.js.map +1 -1
- package/dist/es5/normalize-viewport-props.js +36 -51
- package/dist/es5/normalize-viewport-props.js.map +1 -1
- package/dist/es5/web-mercator-utils.js +104 -144
- package/dist/es5/web-mercator-utils.js.map +1 -1
- package/dist/es5/web-mercator-viewport.js +198 -241
- package/dist/es5/web-mercator-viewport.js.map +1 -1
- package/dist/esm/assert.js.map +1 -1
- package/dist/esm/fit-bounds.js +24 -22
- package/dist/esm/fit-bounds.js.map +1 -1
- package/dist/esm/fly-to-viewport.js +13 -9
- package/dist/esm/fly-to-viewport.js.map +1 -1
- package/dist/esm/get-bounds.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math-utils.js +3 -3
- package/dist/esm/math-utils.js.map +1 -1
- package/dist/esm/normalize-viewport-props.js +30 -41
- package/dist/esm/normalize-viewport-props.js.map +1 -1
- package/dist/esm/web-mercator-utils.js +46 -52
- package/dist/esm/web-mercator-utils.js.map +1 -1
- package/dist/esm/web-mercator-viewport.js +75 -33
- package/dist/esm/web-mercator-viewport.js.map +1 -1
- package/dist/fit-bounds.d.ts +49 -0
- package/dist/fit-bounds.d.ts.map +1 -0
- package/dist/fit-bounds.js +70 -0
- package/dist/fly-to-viewport.d.ts +19 -0
- package/dist/fly-to-viewport.d.ts.map +1 -0
- package/dist/fly-to-viewport.js +87 -0
- package/dist/get-bounds.d.ts +3 -0
- package/dist/get-bounds.d.ts.map +1 -0
- package/dist/get-bounds.js +51 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/math-utils.d.ts +6 -0
- package/dist/math-utils.d.ts.map +1 -0
- package/dist/math-utils.js +23 -0
- package/dist/normalize-viewport-props.d.ts +17 -0
- package/dist/normalize-viewport-props.d.ts.map +1 -0
- package/dist/normalize-viewport-props.js +41 -0
- package/dist/{es5/web-mercator-utils.d.ts → web-mercator-utils.d.ts} +77 -94
- package/dist/web-mercator-utils.d.ts.map +1 -0
- package/dist/web-mercator-utils.js +289 -0
- package/dist/web-mercator-viewport.d.ts +183 -0
- package/dist/web-mercator-viewport.d.ts.map +1 -0
- package/dist/web-mercator-viewport.js +282 -0
- package/package.json +4 -4
- package/src/{assert.js → assert.ts} +1 -1
- package/src/fit-bounds.ts +135 -0
- package/src/{fly-to-viewport.js → fly-to-viewport.ts} +33 -10
- package/src/{get-bounds.js → get-bounds.ts} +4 -2
- package/src/{index.js → index.ts} +0 -0
- package/src/{math-utils.js → math-utils.ts} +7 -7
- package/src/normalize-viewport-props.ts +55 -0
- package/src/{web-mercator-utils.js → web-mercator-utils.ts} +181 -72
- package/src/web-mercator-viewport.ts +417 -0
- package/dist/es5/fit-bounds.d.ts +0 -64
- package/dist/es5/fly-to-viewport.d.ts +0 -31
- package/dist/es5/get-bounds.d.ts +0 -3
- package/dist/es5/index.d.ts +0 -23
- package/dist/es5/normalize-viewport-props.d.ts +0 -16
- package/dist/es5/web-mercator-viewport.d.ts +0 -187
- package/dist/esm/fit-bounds.d.ts +0 -64
- package/dist/esm/fly-to-viewport.d.ts +0 -31
- package/dist/esm/get-bounds.d.ts +0 -3
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/normalize-viewport-props.d.ts +0 -16
- package/dist/esm/web-mercator-utils.d.ts +0 -189
- package/dist/esm/web-mercator-viewport.d.ts +0 -187
- package/src/fit-bounds.d.ts +0 -64
- package/src/fit-bounds.js +0 -84
- package/src/fly-to-viewport.d.ts +0 -31
- package/src/get-bounds.d.ts +0 -3
- package/src/index.d.ts +0 -23
- package/src/normalize-viewport-props.d.ts +0 -16
- package/src/normalize-viewport-props.js +0 -55
- package/src/web-mercator-utils.d.ts +0 -189
- package/src/web-mercator-viewport.d.ts +0 -187
- package/src/web-mercator-viewport.js +0 -262
package/dist/assert.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"assert.d.ts","sourceRoot":"","sources":["../src/assert.ts"],"names":[],"mappings":"AAGA,MAAM,CAAC,OAAO,UAAU,MAAM,CAAC,SAAS,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAIzE"}
|
package/dist/assert.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Replacement for the external assert method to reduce bundle size
|
|
2
|
+
// Note: We don't use the second "message" argument in calling code,
|
|
3
|
+
// so no need to support it here
|
|
4
|
+
export default function assert(condition, message) {
|
|
5
|
+
if (!condition) {
|
|
6
|
+
throw new Error(message || '@math.gl/web-mercator: assertion failed.');
|
|
7
|
+
}
|
|
8
|
+
}
|
package/dist/es5/assert.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/assert.
|
|
1
|
+
{"version":3,"sources":["../../src/assert.ts"],"names":["assert","condition","message","Error"],"mappings":";;;;;;;AAGe,SAASA,MAAT,CAAgBC,SAAhB,EAAoCC,OAApC,EAA4D;AACzE,MAAI,CAACD,SAAL,EAAgB;AACd,UAAM,IAAIE,KAAJ,CAAUD,OAAO,IAAI,0CAArB,CAAN;AACD;AACF","sourcesContent":["// Replacement for the external assert method to reduce bundle size\n// Note: We don't use the second \"message\" argument in calling code,\n// so no need to support it here\nexport default function assert(condition: unknown, message?: string): void {\n if (!condition) {\n throw new Error(message || '@math.gl/web-mercator: assertion failed.');\n }\n}\n"],"file":"assert.js"}
|
package/dist/es5/fit-bounds.js
CHANGED
|
@@ -7,71 +7,61 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = fitBounds;
|
|
9
9
|
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
|
|
12
10
|
var _webMercatorViewport = _interopRequireDefault(require("./web-mercator-viewport"));
|
|
13
11
|
|
|
14
12
|
var _assert = _interopRequireDefault(require("./assert"));
|
|
15
13
|
|
|
16
14
|
var _mathUtils = require("./math-utils");
|
|
17
15
|
|
|
18
|
-
function fitBounds(
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
_bounds$ = (0, _slicedToArray2.default)(_bounds[0], 2),
|
|
33
|
-
west = _bounds$[0],
|
|
34
|
-
south = _bounds$[1],
|
|
35
|
-
_bounds$2 = (0, _slicedToArray2.default)(_bounds[1], 2),
|
|
36
|
-
east = _bounds$2[0],
|
|
37
|
-
north = _bounds$2[1];
|
|
38
|
-
|
|
39
|
-
if (Number.isFinite(padding)) {
|
|
40
|
-
var p = padding;
|
|
41
|
-
padding = {
|
|
42
|
-
top: p,
|
|
43
|
-
bottom: p,
|
|
44
|
-
left: p,
|
|
45
|
-
right: p
|
|
46
|
-
};
|
|
47
|
-
} else {
|
|
48
|
-
(0, _assert.default)(Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right));
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
var viewport = new _webMercatorViewport.default({
|
|
52
|
-
width: width,
|
|
53
|
-
height: height,
|
|
16
|
+
function fitBounds(options) {
|
|
17
|
+
const {
|
|
18
|
+
width,
|
|
19
|
+
height,
|
|
20
|
+
bounds,
|
|
21
|
+
minExtent = 0,
|
|
22
|
+
maxZoom = 24,
|
|
23
|
+
offset = [0, 0]
|
|
24
|
+
} = options;
|
|
25
|
+
const [[west, south], [east, north]] = bounds;
|
|
26
|
+
const padding = getPaddingObject(options.padding);
|
|
27
|
+
const viewport = new _webMercatorViewport.default({
|
|
28
|
+
width,
|
|
29
|
+
height,
|
|
54
30
|
longitude: 0,
|
|
55
31
|
latitude: 0,
|
|
56
32
|
zoom: 0
|
|
57
33
|
});
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
34
|
+
const nw = viewport.project([west, north]);
|
|
35
|
+
const se = viewport.project([east, south]);
|
|
36
|
+
const size = [Math.max(Math.abs(se[0] - nw[0]), minExtent), Math.max(Math.abs(se[1] - nw[1]), minExtent)];
|
|
37
|
+
const targetSize = [width - padding.left - padding.right - Math.abs(offset[0]) * 2, height - padding.top - padding.bottom - Math.abs(offset[1]) * 2];
|
|
62
38
|
(0, _assert.default)(targetSize[0] > 0 && targetSize[1] > 0);
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
39
|
+
const scaleX = targetSize[0] / size[0];
|
|
40
|
+
const scaleY = targetSize[1] / size[1];
|
|
41
|
+
const offsetX = (padding.right - padding.left) / 2 / scaleX;
|
|
42
|
+
const offsetY = (padding.bottom - padding.top) / 2 / scaleY;
|
|
43
|
+
const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
|
|
44
|
+
const centerLngLat = viewport.unproject(center);
|
|
45
|
+
const zoom = Math.min(maxZoom, viewport.zoom + (0, _mathUtils.log2)(Math.abs(Math.min(scaleX, scaleY))));
|
|
70
46
|
(0, _assert.default)(Number.isFinite(zoom));
|
|
71
47
|
return {
|
|
72
48
|
longitude: centerLngLat[0],
|
|
73
49
|
latitude: centerLngLat[1],
|
|
74
|
-
zoom
|
|
50
|
+
zoom
|
|
75
51
|
};
|
|
76
52
|
}
|
|
53
|
+
|
|
54
|
+
function getPaddingObject(padding = 0) {
|
|
55
|
+
if (typeof padding === 'number') {
|
|
56
|
+
return {
|
|
57
|
+
top: padding,
|
|
58
|
+
bottom: padding,
|
|
59
|
+
left: padding,
|
|
60
|
+
right: padding
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
(0, _assert.default)(Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right));
|
|
65
|
+
return padding;
|
|
66
|
+
}
|
|
77
67
|
//# sourceMappingURL=fit-bounds.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fit-bounds.
|
|
1
|
+
{"version":3,"sources":["../../src/fit-bounds.ts"],"names":["fitBounds","options","width","height","bounds","minExtent","maxZoom","offset","west","south","east","north","padding","getPaddingObject","viewport","WebMercatorViewport","longitude","latitude","zoom","nw","project","se","size","Math","max","abs","targetSize","left","right","top","bottom","scaleX","scaleY","offsetX","offsetY","center","centerLngLat","unproject","min","Number","isFinite"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;AAqDe,SAASA,SAAT,CAAmBC,OAAnB,EAAsD;AACnE,QAAM;AACJC,IAAAA,KADI;AAEJC,IAAAA,MAFI;AAGJC,IAAAA,MAHI;AAIJC,IAAAA,SAAS,GAAG,CAJR;AAKJC,IAAAA,OAAO,GAAG,EALN;AAMJC,IAAAA,MAAM,GAAG,CAAC,CAAD,EAAI,CAAJ;AANL,MAOFN,OAPJ;AASA,QAAM,CAAC,CAACO,IAAD,EAAOC,KAAP,CAAD,EAAgB,CAACC,IAAD,EAAOC,KAAP,CAAhB,IAAiCP,MAAvC;AACA,QAAMQ,OAAO,GAAGC,gBAAgB,CAACZ,OAAO,CAACW,OAAT,CAAhC;AAEA,QAAME,QAAQ,GAAG,IA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uBACE2B,MAAM,CAACC,QAAP,CAAgB5B,OAAO,CAACiB,GAAxB,KACEU,MAAM,CAACC,QAAP,CAAgB5B,OAAO,CAACkB,MAAxB,CADF,IAEES,MAAM,CAACC,QAAP,CAAgB5B,OAAO,CAACe,IAAxB,CAFF,IAGEY,MAAM,CAACC,QAAP,CAAgB5B,OAAO,CAACgB,KAAxB,CAJJ;AAOA,SAAOhB,OAAP;AACD","sourcesContent":["import WebMercatorViewport from './web-mercator-viewport';\nimport assert from './assert';\nimport {log2} from './math-utils';\n\n/**\n * Options for fitBounds\n * @param width - viewport width\n * @param height - viewport height\n * @param bounds - [[lon, lat], [lon, lat]]\n * @param minExtent - The width/height of the bounded area will never be smaller than this\n * @param padding - The amount of padding in pixels\n * to add to the given bounds. Can also be an object with top, bottom, left and right\n * properties defining the padding.\n * @param options.offset= - The center of the given bounds relative to the map's center,\n */\nexport type FitBoundsOptions = {\n width: number;\n height: number;\n bounds: [[number, number], [number, number]];\n minExtent?: number; // 0.01 would be about 1000 meters (degree is ~110KM)\n maxZoom?: number; // ~x4,000,000 => About 10 meter extents\n // options\n padding?: number | Padding;\n offset?: number[];\n};\n\n/**\n * An object describing the padding to add to the bounds.\n * @property top - Padding from top in pixels to add to the given bounds\n * @property bottom - Padding from bottom in pixels to add to the given bounds\n * @property left - Padding from left in pixels to add to the given bounds\n * @property right - Padding from right in pixels to add to the given bounds\n */\nexport type Padding = {\n top: number;\n bottom: number;\n left: number;\n right: number;\n};\n\nexport type Bounds = {\n longitude: number;\n latitude: number;\n zoom: number;\n};\n\n/**\n * Returns map settings {latitude, longitude, zoom}\n * that will contain the provided corners within the provided width.\n *\n * > _Note: Only supports non-perspective mode._\n *\n * @param options fit bounds parameters\n * @returns - latitude, longitude and zoom\n */\nexport default function fitBounds(options: FitBoundsOptions): Bounds {\n const {\n width,\n height,\n bounds,\n minExtent = 0, // 0.01 would be about 1000 meters (degree is ~110KM)\n maxZoom = 24, // ~x4,000,000 => About 10 meter extents\n offset = [0, 0]\n } = options;\n\n const [[west, south], [east, north]] = bounds;\n const padding = getPaddingObject(options.padding);\n\n const viewport = new WebMercatorViewport({\n width,\n height,\n longitude: 0,\n latitude: 0,\n zoom: 0\n });\n\n const nw = viewport.project([west, north]);\n const se = viewport.project([east, south]);\n\n // width/height on the Web Mercator plane\n const size = [\n Math.max(Math.abs(se[0] - nw[0]), minExtent),\n Math.max(Math.abs(se[1] - nw[1]), minExtent)\n ];\n\n const targetSize = [\n width - padding.left - padding.right - Math.abs(offset[0]) * 2,\n height - padding.top - padding.bottom - Math.abs(offset[1]) * 2\n ];\n\n assert(targetSize[0] > 0 && targetSize[1] > 0);\n\n // scale = screen pixels per unit on the Web Mercator plane\n const scaleX = targetSize[0] / size[0];\n const scaleY = targetSize[1] / size[1];\n\n // Find how much we need to shift the center\n const offsetX = (padding.right - padding.left) / 2 / scaleX;\n const offsetY = (padding.bottom - padding.top) / 2 / scaleY;\n\n const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];\n\n const centerLngLat = viewport.unproject(center);\n const zoom = Math.min(maxZoom, viewport.zoom + log2(Math.abs(Math.min(scaleX, scaleY))));\n\n assert(Number.isFinite(zoom));\n\n return {\n longitude: centerLngLat[0],\n latitude: centerLngLat[1],\n zoom\n };\n}\n\n// Helpers\nfunction getPaddingObject(padding: number | Padding = 0): Padding {\n if (typeof padding === 'number') {\n return {\n top: padding,\n bottom: padding,\n left: padding,\n right: padding\n };\n }\n\n // Make sure all the required properties are set\n assert(\n Number.isFinite(padding.top) &&\n Number.isFinite(padding.bottom) &&\n Number.isFinite(padding.left) &&\n Number.isFinite(padding.right)\n );\n\n return padding;\n}\n"],"file":"fit-bounds.js"}
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -14,86 +12,72 @@ var _webMercatorUtils = require("./web-mercator-utils");
|
|
|
14
12
|
|
|
15
13
|
var vec2 = _interopRequireWildcard(require("gl-matrix/vec2"));
|
|
16
14
|
|
|
17
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
18
|
-
|
|
19
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
20
|
-
|
|
21
|
-
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
|
|
15
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
22
16
|
|
|
23
|
-
function
|
|
17
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
24
18
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
var VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
|
|
29
|
-
var DEFAULT_OPTS = {
|
|
19
|
+
const EPSILON = 0.01;
|
|
20
|
+
const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
|
|
21
|
+
const DEFAULT_OPTS = {
|
|
30
22
|
curve: 1.414,
|
|
31
23
|
speed: 1.2
|
|
32
24
|
};
|
|
33
25
|
|
|
34
|
-
function flyToViewport(startProps, endProps, t) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
rho2 = _getFlyToTransitionPa.rho2,
|
|
47
|
-
r0 = _getFlyToTransitionPa.r0;
|
|
26
|
+
function flyToViewport(startProps, endProps, t, options) {
|
|
27
|
+
const {
|
|
28
|
+
startZoom,
|
|
29
|
+
startCenterXY,
|
|
30
|
+
uDelta,
|
|
31
|
+
w0,
|
|
32
|
+
u1,
|
|
33
|
+
S,
|
|
34
|
+
rho,
|
|
35
|
+
rho2,
|
|
36
|
+
r0
|
|
37
|
+
} = getFlyToTransitionParams(startProps, endProps, options);
|
|
48
38
|
|
|
49
39
|
if (u1 < EPSILON) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
var startValue = startProps[key];
|
|
57
|
-
var endValue = endProps[key];
|
|
58
|
-
viewport[key] = (0, _mathUtils.lerp)(startValue, endValue, t);
|
|
59
|
-
}
|
|
60
|
-
} catch (err) {
|
|
61
|
-
_iterator.e(err);
|
|
62
|
-
} finally {
|
|
63
|
-
_iterator.f();
|
|
40
|
+
const viewport = {};
|
|
41
|
+
|
|
42
|
+
for (const key of VIEWPORT_TRANSITION_PROPS) {
|
|
43
|
+
const startValue = startProps[key];
|
|
44
|
+
const endValue = endProps[key];
|
|
45
|
+
viewport[key] = (0, _mathUtils.lerp)(startValue, endValue, t);
|
|
64
46
|
}
|
|
65
47
|
|
|
66
48
|
return viewport;
|
|
67
49
|
}
|
|
68
50
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
51
|
+
const s = t * S;
|
|
52
|
+
const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);
|
|
53
|
+
const u = w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2) / u1;
|
|
54
|
+
const scaleIncrement = 1 / w;
|
|
55
|
+
const newZoom = startZoom + (0, _webMercatorUtils.scaleToZoom)(scaleIncrement);
|
|
56
|
+
const newCenterWorld = vec2.scale([], uDelta, u);
|
|
75
57
|
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
58
|
+
const newCenter = (0, _webMercatorUtils.worldToLngLat)(newCenterWorld);
|
|
59
|
+
return {
|
|
60
|
+
longitude: newCenter[0],
|
|
61
|
+
latitude: newCenter[1],
|
|
62
|
+
zoom: newZoom
|
|
63
|
+
};
|
|
81
64
|
}
|
|
82
65
|
|
|
83
|
-
function getFlyToDuration(startProps, endProps) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
66
|
+
function getFlyToDuration(startProps, endProps, options) {
|
|
67
|
+
const opts = { ...DEFAULT_OPTS,
|
|
68
|
+
...options
|
|
69
|
+
};
|
|
70
|
+
const {
|
|
71
|
+
screenSpeed,
|
|
72
|
+
speed,
|
|
73
|
+
maxDuration
|
|
74
|
+
} = opts;
|
|
75
|
+
const {
|
|
76
|
+
S,
|
|
77
|
+
rho
|
|
78
|
+
} = getFlyToTransitionParams(startProps, endProps, opts);
|
|
79
|
+
const length = 1000 * S;
|
|
80
|
+
let duration;
|
|
97
81
|
|
|
98
82
|
if (Number.isFinite(screenSpeed)) {
|
|
99
83
|
duration = length / (screenSpeed / rho);
|
|
@@ -106,39 +90,39 @@ function getFlyToDuration(startProps, endProps) {
|
|
|
106
90
|
|
|
107
91
|
function getFlyToTransitionParams(startProps, endProps, opts) {
|
|
108
92
|
opts = Object.assign({}, DEFAULT_OPTS, opts);
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
93
|
+
const rho = opts.curve;
|
|
94
|
+
const startZoom = startProps.zoom;
|
|
95
|
+
const startCenter = [startProps.longitude, startProps.latitude];
|
|
96
|
+
const startScale = (0, _webMercatorUtils.zoomToScale)(startZoom);
|
|
97
|
+
const endZoom = endProps.zoom;
|
|
98
|
+
const endCenter = [endProps.longitude, endProps.latitude];
|
|
99
|
+
const scale = (0, _webMercatorUtils.zoomToScale)(endZoom - startZoom);
|
|
100
|
+
const startCenterXY = (0, _webMercatorUtils.lngLatToWorld)(startCenter);
|
|
101
|
+
const endCenterXY = (0, _webMercatorUtils.lngLatToWorld)(endCenter);
|
|
102
|
+
const uDelta = vec2.sub([], endCenterXY, startCenterXY);
|
|
103
|
+
const w0 = Math.max(startProps.width, startProps.height);
|
|
104
|
+
const w1 = w0 / scale;
|
|
105
|
+
const u1 = vec2.length(uDelta) * startScale;
|
|
106
|
+
|
|
107
|
+
const _u1 = Math.max(u1, EPSILON);
|
|
108
|
+
|
|
109
|
+
const rho2 = rho * rho;
|
|
110
|
+
const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);
|
|
111
|
+
const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);
|
|
112
|
+
const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
|
|
113
|
+
const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
|
|
114
|
+
const S = (r1 - r0) / rho;
|
|
131
115
|
return {
|
|
132
|
-
startZoom
|
|
133
|
-
startCenterXY
|
|
134
|
-
uDelta
|
|
135
|
-
w0
|
|
136
|
-
u1
|
|
137
|
-
S
|
|
138
|
-
rho
|
|
139
|
-
rho2
|
|
140
|
-
r0
|
|
141
|
-
r1
|
|
116
|
+
startZoom,
|
|
117
|
+
startCenterXY,
|
|
118
|
+
uDelta,
|
|
119
|
+
w0,
|
|
120
|
+
u1,
|
|
121
|
+
S,
|
|
122
|
+
rho,
|
|
123
|
+
rho2,
|
|
124
|
+
r0,
|
|
125
|
+
r1
|
|
142
126
|
};
|
|
143
127
|
}
|
|
144
128
|
//# sourceMappingURL=fly-to-viewport.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fly-to-viewport.
|
|
1
|
+
{"version":3,"sources":["../../src/fly-to-viewport.ts"],"names":["EPSILON","VIEWPORT_TRANSITION_PROPS","DEFAULT_OPTS","curve","speed","flyToViewport","startProps","endProps","t","options","startZoom","startCenterXY","uDelta","w0","u1","S","rho","rho2","r0","getFlyToTransitionParams","viewport","key","startValue","endValue","s","w","Math","cosh","u","tanh","sinh","scaleIncrement","newZoom","newCenterWorld","vec2","scale","add","newCenter","longitude","latitude","zoom","getFlyToDuration","opts","screenSpeed","maxDuration","length","duration","Number","isFinite","Object","assign","startCenter","startScale","endZoom","endCenter","endCenterXY","sub","max","width","height","w1","_u1","b0","b1","log","sqrt","r1"],"mappings":";;;;;;;;AAAA;;AACA;;AACA;;;;;;AAEA,MAAMA,OAAO,GAAG,IAAhB;AACA,MAAMC,yBAAyB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,MAA1B,CAAlC;AACA,MAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,KADY;AAEnBC,EAAAA,KAAK,EAAE;AAFY,CAArB;;AAwBe,SAASC,aAAT,CACbC,UADa,EAEbC,QAFa,EAGbC,CAHa,EAIbC,OAJa,EAKE;AAGf,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,aAAZ;AAA2BC,IAAAA,MAA3B;AAAmCC,IAAAA,EAAnC;AAAuCC,IAAAA,EAAvC;AAA2CC,IAAAA,CAA3C;AAA8CC,IAAAA,GAA9C;AAAmDC,IAAAA,IAAnD;AAAyDC,IAAAA;AAAzD,MAA+DC,wBAAwB,CAC3Fb,UAD2F,EAE3FC,QAF2F,EAG3FE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AAE,GAAGxC,IAAI,CAACsC,GAAL,CAAStC,IAAI,CAACuC,IAAL,CAAUF,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,QAAMhD,CAAC,GAAG,CAACmD,EAAE,GAAGhD,EAAN,IAAYF,GAAtB;AAEA,SAAO;AAACN,IAAAA,SAAD;AAAYC,IAAAA,aAAZ;AAA2BC,IAAAA,MAA3B;AAAmCC,IAAAA,EAAnC;AAAuCC,IAAAA,EAAvC;AAA2CC,IAAAA,CAA3C;AAA8CC,IAAAA,GAA9C;AAAmDC,IAAAA,IAAnD;AAAyDC,IAAAA,EAAzD;AAA6DgD,IAAAA;AAA7D,GAAP;AACD","sourcesContent":["import {lerp} from './math-utils';\nimport {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';\nimport * as vec2 from 'gl-matrix/vec2';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];\nconst DEFAULT_OPTS = {\n curve: 1.414,\n speed: 1.2\n // screenSpeed and maxDuration are used only if specified\n};\n\nexport type FlytoTransitionOptions = {\n curve?: number;\n speed?: number;\n screenSpeed?: number;\n maxDuration?: number;\n};\n\nexport type ViewportProps = {\n longitude: number;\n latitude: number;\n zoom: number;\n};\n\n/**\n * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.\n * It implements “Smooth and efficient zooming and panning.” algorithm by\n * \"Jarke J. van Wijk and Wim A.A. Nuij\"\n */\nexport default function flyToViewport(\n startProps: ViewportProps,\n endProps: ViewportProps,\n t: number,\n options?: FlytoTransitionOptions\n): ViewportProps {\n // Equations from above paper are referred where needed.\n\n const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(\n startProps,\n endProps,\n options\n );\n\n // If change in center is too small, do linear interpolaiton.\n if (u1 < EPSILON) {\n const viewport = {};\n for (const key of VIEWPORT_TRANSITION_PROPS) {\n const startValue = startProps[key];\n const endValue = endProps[key];\n viewport[key] = lerp(startValue, endValue, t);\n }\n // @ts-expect-error\n return viewport;\n }\n\n const s = t * S;\n\n const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);\n const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;\n\n const scaleIncrement = 1 / w; // Using w method for scaling.\n const newZoom = startZoom + scaleToZoom(scaleIncrement);\n\n const newCenterWorld = vec2.scale([], uDelta, u);\n vec2.add(newCenterWorld, newCenterWorld, startCenterXY);\n\n const newCenter = worldToLngLat(newCenterWorld);\n return {\n longitude: newCenter[0],\n latitude: newCenter[1],\n zoom: newZoom\n };\n}\n\n// returns transition duration in milliseconds\nexport function getFlyToDuration(\n startProps: ViewportProps,\n endProps: ViewportProps,\n options?: FlytoTransitionOptions\n): number {\n const opts = {...DEFAULT_OPTS, ...options};\n const {screenSpeed, speed, maxDuration} = opts;\n const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);\n const length = 1000 * S;\n let duration;\n if (Number.isFinite(screenSpeed)) {\n duration = length / (screenSpeed / rho);\n } else {\n duration = length / speed;\n }\n\n return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;\n}\n\n// Private Methods\n\n// Calculate all parameters that are static for given startProps and endProps\nfunction getFlyToTransitionParams(startProps, endProps, opts) {\n opts = Object.assign({}, DEFAULT_OPTS, opts);\n const rho = opts.curve;\n const startZoom = startProps.zoom;\n const startCenter = [startProps.longitude, startProps.latitude];\n const startScale = zoomToScale(startZoom);\n const endZoom = endProps.zoom;\n const endCenter = [endProps.longitude, endProps.latitude];\n const scale = zoomToScale(endZoom - startZoom);\n\n const startCenterXY = lngLatToWorld(startCenter);\n const endCenterXY = lngLatToWorld(endCenter);\n const uDelta = vec2.sub([], endCenterXY, startCenterXY);\n\n const w0 = Math.max(startProps.width, startProps.height);\n const w1 = w0 / scale;\n const u1 = vec2.length(uDelta) * startScale;\n // u0 is treated as '0' in Eq (9).\n\n // If u1 is too small, will generate invalid number\n const _u1 = Math.max(u1, EPSILON);\n\n // Implement Equation (9) from above algorithm.\n const rho2 = rho * rho;\n const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);\n const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);\n const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);\n const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n const S = (r1 - r0) / rho;\n\n return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};\n}\n"],"file":"fly-to-viewport.js"}
|
package/dist/es5/get-bounds.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -13,26 +11,27 @@ var vec2 = _interopRequireWildcard(require("gl-matrix/vec2"));
|
|
|
13
11
|
|
|
14
12
|
var _mathUtils = require("./math-utils");
|
|
15
13
|
|
|
16
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
14
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
15
|
|
|
18
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
16
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
17
|
|
|
20
|
-
|
|
18
|
+
const DEGREES_TO_RADIANS = Math.PI / 180;
|
|
21
19
|
|
|
22
|
-
function getBounds(viewport) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
function getBounds(viewport, z = 0) {
|
|
21
|
+
const {
|
|
22
|
+
width,
|
|
23
|
+
height,
|
|
24
|
+
unproject
|
|
25
|
+
} = viewport;
|
|
26
|
+
const unprojectOps = {
|
|
28
27
|
targetZ: z
|
|
29
28
|
};
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
29
|
+
const bottomLeft = unproject([0, height], unprojectOps);
|
|
30
|
+
const bottomRight = unproject([width, height], unprojectOps);
|
|
31
|
+
let topLeft;
|
|
32
|
+
let topRight;
|
|
33
|
+
const halfFov = viewport.fovy ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS : Math.atan(0.5 / viewport.altitude);
|
|
34
|
+
const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;
|
|
36
35
|
|
|
37
36
|
if (halfFov > angleToGround - 0.01) {
|
|
38
37
|
topLeft = unprojectOnFarPlane(viewport, 0, z);
|
|
@@ -46,13 +45,15 @@ function getBounds(viewport) {
|
|
|
46
45
|
}
|
|
47
46
|
|
|
48
47
|
function unprojectOnFarPlane(viewport, x, targetZ) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
const {
|
|
49
|
+
pixelUnprojectionMatrix
|
|
50
|
+
} = viewport;
|
|
51
|
+
const coord0 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, 0, 1, 1]);
|
|
52
|
+
const coord1 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
|
|
53
|
+
const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
|
|
54
|
+
const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
|
|
55
|
+
const coord = vec2.lerp([], coord0, coord1, t);
|
|
56
|
+
const result = (0, _webMercatorUtils.worldToLngLat)(coord);
|
|
56
57
|
result[2] = targetZ;
|
|
57
58
|
return result;
|
|
58
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/get-bounds.
|
|
1
|
+
{"version":3,"sources":["../../src/get-bounds.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","getBounds","viewport","z","width","height","unproject","unprojectOps","targetZ","bottomLeft","bottomRight","topLeft","topRight","halfFov","fovy","atan","altitude","angleToGround","pitch","unprojectOnFarPlane","x","pixelUnprojectionMatrix","coord0","coord1","distanceScales","unitsPerMeter","t","coord","vec2","lerp","result"],"mappings":";;;;;;;AAAA;;AACA;;AACA;;;;;;AAGA,MAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;;AAOe,SAASC,SAAT,CAAmBC,QAAnB,EAAkDC,CAAS,GAAG,CAA9D,EAA6E;AAE1F,QAAM;AAACC,IAAAA,KAAD;AAAQC,IAAAA,MAAR;AAAgBC,IAAAA;AAAhB,MAA6BJ,QAAnC;AACA,QAAMK,YAAY,GAAG;AAACC,IAAAA,OAAO,EAAEL;AAAV,GAArB;AACA,QAAMM,UAAU,GAAGH,SAAS,CAA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AIlB,QAAQ,CAACG,MAAb,EAAqB,CAArB,EAAwB,CAAxB,CAAzC,CAAf;AAEA,QAAMF,CAAC,GAAGK,OAAO,GAAGN,QAAQ,CAACsB,cAAT,CAAwBC,aAAxB,CAAsC,CAAtC,CAApB;AACA,QAAMC,CAAC,GAAG,CAACvB,CAAC,GAAGmB,MAAM,CAAC,CAAD,CAAX,KAAmBC,MAAM,CAAC,CAAD,CAAN,GAAYD,MAAM,CAAC,CAAD,CAArC,CAAV;AACA,QAAMK,KAAK,GAAGC,IAAI,CAACC,IAAL,CAAU,EAAV,EAAcP,MAAd,EAAsBC,MAAtB,EAA8BG,CAA9B,CAAd;AAEA,QAAMI,MAAM,GAAG,qCAAcH,KAAd,CAAf;AACAG,EAAAA,MAAM,CAAC,CAAD,CAAN,GAAYtB,OAAZ;AACA,SAAOsB,MAAP;AACD","sourcesContent":["import {worldToLngLat} from './web-mercator-utils';\nimport * as vec2 from 'gl-matrix/vec2';\nimport {transformVector} from './math-utils';\nimport type WebMercatorViewport from './web-mercator-viewport';\n\nconst DEGREES_TO_RADIANS = Math.PI / 180;\n\n/*\n * Returns the quad at the intersection of the frustum and the given z plane\n * @param {WebMercatorViewport} viewport\n * @param {Number} z - elevation in meters\n */\nexport default function getBounds(viewport: WebMercatorViewport, z: number = 0): number[][] {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const {width, height, unproject} = viewport;\n const unprojectOps = {targetZ: z};\n const bottomLeft = unproject([0, height], unprojectOps);\n const bottomRight = unproject([width, height], unprojectOps);\n let topLeft;\n let topRight;\n\n const halfFov = viewport.fovy\n ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS\n : Math.atan(0.5 / viewport.altitude);\n const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;\n // The top plane is parallel to the ground if halfFov == angleToGround\n if (halfFov > angleToGround - 0.01) {\n // intersect with the far plane\n topLeft = unprojectOnFarPlane(viewport, 0, z);\n topRight = unprojectOnFarPlane(viewport, width, z);\n } else {\n // intersect with the top plane\n topLeft = unproject([0, 0], unprojectOps);\n topRight = unproject([width, 0], unprojectOps);\n }\n\n return [bottomLeft, bottomRight, topRight, topLeft];\n}\n\n/*\n * Find a point on the far clipping plane of the viewport\n * @param {WebMercatorViewport} viewport\n * @param {Number} x - projected x in screen space\n * @param {Number} targetZ - the elevation of the point in meters\n */\nfunction unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ) {\n const {pixelUnprojectionMatrix} = viewport;\n const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);\n const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);\n\n const z = targetZ * viewport.distanceScales.unitsPerMeter[2];\n const t = (z - coord0[2]) / (coord1[2] - coord0[2]);\n const coord = vec2.lerp([], coord0, coord1, t);\n\n const result = worldToLngLat(coord);\n result[2] = targetZ;\n return result;\n}\n"],"file":"get-bounds.js"}
|