@math.gl/web-mercator 3.5.6 → 3.6.0-alpha.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.
- 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 +33 -37
- package/dist/es5/fit-bounds.js.map +1 -1
- package/dist/es5/fly-to-viewport.js +23 -16
- package/dist/es5/fly-to-viewport.js.map +1 -1
- package/dist/es5/get-bounds.js +1 -1
- package/dist/es5/get-bounds.js.map +1 -1
- package/dist/es5/index.js +6 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/math-utils.js +8 -9
- package/dist/es5/math-utils.js.map +1 -1
- package/dist/es5/normalize-viewport-props.js +10 -10
- package/dist/es5/normalize-viewport-props.js.map +1 -1
- package/dist/es5/web-mercator-utils.js +47 -61
- package/dist/es5/web-mercator-utils.js.map +1 -1
- package/dist/es5/web-mercator-viewport.js +69 -51
- package/dist/es5/web-mercator-viewport.js.map +1 -1
- package/dist/esm/assert.js.map +1 -1
- package/dist/esm/fit-bounds.js +29 -34
- 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 +1 -1
- package/dist/esm/get-bounds.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math-utils.js +6 -3
- package/dist/esm/math-utils.js.map +1 -1
- package/dist/esm/normalize-viewport-props.js +13 -9
- package/dist/esm/normalize-viewport-props.js.map +1 -1
- package/dist/esm/web-mercator-utils.js +47 -52
- package/dist/esm/web-mercator-utils.js.map +1 -1
- package/dist/esm/web-mercator-viewport.js +76 -34
- package/dist/esm/web-mercator-viewport.js.map +1 -1
- package/dist/fit-bounds.d.ts +50 -0
- package/dist/fit-bounds.d.ts.map +1 -0
- package/dist/fit-bounds.js +63 -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 +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/math-utils.d.ts +7 -0
- package/dist/math-utils.d.ts.map +1 -0
- package/dist/math-utils.js +26 -0
- package/dist/normalize-viewport-props.d.ts +16 -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} +78 -94
- package/dist/web-mercator-utils.d.ts.map +1 -0
- package/dist/web-mercator-utils.js +290 -0
- package/dist/web-mercator-viewport.d.ts +182 -0
- package/dist/web-mercator-viewport.d.ts.map +1 -0
- package/dist/web-mercator-viewport.js +281 -0
- package/package.json +4 -4
- package/src/{assert.js → assert.ts} +1 -1
- package/src/fit-bounds.ts +127 -0
- package/src/{fly-to-viewport.js → fly-to-viewport.ts} +52 -14
- package/src/{get-bounds.js → get-bounds.ts} +7 -5
- package/src/{index.js → index.ts} +5 -0
- package/src/math-utils.ts +32 -0
- package/src/{normalize-viewport-props.js → normalize-viewport-props.ts} +19 -10
- package/src/{web-mercator-utils.js → web-mercator-utils.ts} +186 -76
- package/src/web-mercator-viewport.ts +415 -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/math-utils.js +0 -28
- package/src/normalize-viewport-props.d.ts +0 -16
- 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
|
@@ -9,24 +9,22 @@ exports.default = fitBounds;
|
|
|
9
9
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
11
|
|
|
12
|
-
var _webMercatorViewport = _interopRequireDefault(require("./web-mercator-viewport"));
|
|
13
|
-
|
|
14
12
|
var _assert = _interopRequireDefault(require("./assert"));
|
|
15
13
|
|
|
16
14
|
var _mathUtils = require("./math-utils");
|
|
17
15
|
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
offset =
|
|
16
|
+
var _webMercatorUtils = require("./web-mercator-utils");
|
|
17
|
+
|
|
18
|
+
function fitBounds(options) {
|
|
19
|
+
var width = options.width,
|
|
20
|
+
height = options.height,
|
|
21
|
+
bounds = options.bounds,
|
|
22
|
+
_options$minExtent = options.minExtent,
|
|
23
|
+
minExtent = _options$minExtent === void 0 ? 0 : _options$minExtent,
|
|
24
|
+
_options$maxZoom = options.maxZoom,
|
|
25
|
+
maxZoom = _options$maxZoom === void 0 ? 24 : _options$maxZoom,
|
|
26
|
+
_options$offset = options.offset,
|
|
27
|
+
offset = _options$offset === void 0 ? [0, 0] : _options$offset;
|
|
30
28
|
|
|
31
29
|
var _bounds = (0, _slicedToArray2.default)(bounds, 2),
|
|
32
30
|
_bounds$ = (0, _slicedToArray2.default)(_bounds[0], 2),
|
|
@@ -36,27 +34,9 @@ function fitBounds(_ref) {
|
|
|
36
34
|
east = _bounds$2[0],
|
|
37
35
|
north = _bounds$2[1];
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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,
|
|
54
|
-
longitude: 0,
|
|
55
|
-
latitude: 0,
|
|
56
|
-
zoom: 0
|
|
57
|
-
});
|
|
58
|
-
var nw = viewport.project([west, north]);
|
|
59
|
-
var se = viewport.project([east, south]);
|
|
37
|
+
var padding = getPaddingObject(options.padding);
|
|
38
|
+
var nw = (0, _webMercatorUtils.lngLatToWorld)([west, (0, _mathUtils.clamp)(north, -_webMercatorUtils.MAX_LATITUDE, _webMercatorUtils.MAX_LATITUDE)]);
|
|
39
|
+
var se = (0, _webMercatorUtils.lngLatToWorld)([east, (0, _mathUtils.clamp)(south, -_webMercatorUtils.MAX_LATITUDE, _webMercatorUtils.MAX_LATITUDE)]);
|
|
60
40
|
var size = [Math.max(Math.abs(se[0] - nw[0]), minExtent), Math.max(Math.abs(se[1] - nw[1]), minExtent)];
|
|
61
41
|
var targetSize = [width - padding.left - padding.right - Math.abs(offset[0]) * 2, height - padding.top - padding.bottom - Math.abs(offset[1]) * 2];
|
|
62
42
|
(0, _assert.default)(targetSize[0] > 0 && targetSize[1] > 0);
|
|
@@ -65,8 +45,8 @@ function fitBounds(_ref) {
|
|
|
65
45
|
var offsetX = (padding.right - padding.left) / 2 / scaleX;
|
|
66
46
|
var offsetY = (padding.bottom - padding.top) / 2 / scaleY;
|
|
67
47
|
var center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
|
|
68
|
-
var centerLngLat =
|
|
69
|
-
var zoom = Math.min(maxZoom,
|
|
48
|
+
var centerLngLat = (0, _webMercatorUtils.worldToLngLat)(center);
|
|
49
|
+
var zoom = Math.min(maxZoom, (0, _mathUtils.log2)(Math.abs(Math.min(scaleX, scaleY))));
|
|
70
50
|
(0, _assert.default)(Number.isFinite(zoom));
|
|
71
51
|
return {
|
|
72
52
|
longitude: centerLngLat[0],
|
|
@@ -74,4 +54,20 @@ function fitBounds(_ref) {
|
|
|
74
54
|
zoom: zoom
|
|
75
55
|
};
|
|
76
56
|
}
|
|
57
|
+
|
|
58
|
+
function getPaddingObject() {
|
|
59
|
+
var padding = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
|
|
60
|
+
|
|
61
|
+
if (typeof padding === 'number') {
|
|
62
|
+
return {
|
|
63
|
+
top: padding,
|
|
64
|
+
bottom: padding,
|
|
65
|
+
left: padding,
|
|
66
|
+
right: padding
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
(0, _assert.default)(Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right));
|
|
71
|
+
return padding;
|
|
72
|
+
}
|
|
77
73
|
//# 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","nw","MAX_LATITUDE","se","size","Math","max","abs","targetSize","left","right","top","bottom","scaleX","scaleY","offsetX","offsetY","center","centerLngLat","zoom","min","Number","isFinite","longitude","latitude"],"mappings":";;;;;;;;;;;AAAA;;AACA;;AACA;;AAqDe,SAASA,SAAT,CAAmBC,OAAnB,EAA6D;AAC1E,MACEC,KADF,GAOID,OAPJ,CACEC,KADF;AAAA,MAEEC,MAFF,GAOIF,OAPJ,CAEEE,MAFF;AAAA,MAGEC,MAHF,GAOIH,OAPJ,CAGEG,MAHF;AAAA,2BAOIH,OAPJ,CAI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,OAAP,KAAmB,QAAvB,EAAiC;AAC/B,WAAO;AACLY,MAAAA,GAAG,EAAEZ,OADA;AAELa,MAAAA,MAAM,EAAEb,OAFH;AAGLU,MAAAA,IAAI,EAAEV,OAHD;AAILW,MAAAA,KAAK,EAAEX;AAJF,KAAP;AAMD;;AAGD,uBACEsB,MAAM,CAACC,QAAP,CAAgBvB,OAAO,CAACY,GAAxB,KACEU,MAAM,CAACC,QAAP,CAAgBvB,OAAO,CAACa,MAAxB,CADF,IAEES,MAAM,CAACC,QAAP,CAAgBvB,OAAO,CAACU,IAAxB,CAFF,IAGEY,MAAM,CAACC,QAAP,CAAgBvB,OAAO,CAACW,KAAxB,CAJJ;AAOA,SAAOX,OAAP;AACD","sourcesContent":["import assert from './assert';\nimport {log2, clamp} from './math-utils';\nimport {MAX_LATITUDE, lngLatToWorld, worldToLngLat} from './web-mercator-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\ntype ViewportProps = {\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): ViewportProps {\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 nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);\n const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);\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 = worldToLngLat(center);\n const zoom = Math.min(maxZoom, 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,5 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
3
5
|
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
6
|
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
@@ -8,6 +10,8 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
8
10
|
exports.default = flyToViewport;
|
|
9
11
|
exports.getFlyToDuration = getFlyToDuration;
|
|
10
12
|
|
|
13
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
|
+
|
|
11
15
|
var _mathUtils = require("./math-utils");
|
|
12
16
|
|
|
13
17
|
var _webMercatorUtils = require("./web-mercator-utils");
|
|
@@ -18,6 +22,10 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
|
|
|
18
22
|
|
|
19
23
|
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
24
|
|
|
25
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
26
|
+
|
|
27
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2.default)(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
28
|
+
|
|
21
29
|
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; } } }; }
|
|
22
30
|
|
|
23
31
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -31,11 +39,8 @@ var DEFAULT_OPTS = {
|
|
|
31
39
|
speed: 1.2
|
|
32
40
|
};
|
|
33
41
|
|
|
34
|
-
function flyToViewport(startProps, endProps, t) {
|
|
35
|
-
var
|
|
36
|
-
var viewport = {};
|
|
37
|
-
|
|
38
|
-
var _getFlyToTransitionPa = getFlyToTransitionParams(startProps, endProps, opts),
|
|
42
|
+
function flyToViewport(startProps, endProps, t, options) {
|
|
43
|
+
var _getFlyToTransitionPa = getFlyToTransitionParams(startProps, endProps, options),
|
|
39
44
|
startZoom = _getFlyToTransitionPa.startZoom,
|
|
40
45
|
startCenterXY = _getFlyToTransitionPa.startCenterXY,
|
|
41
46
|
uDelta = _getFlyToTransitionPa.uDelta,
|
|
@@ -47,6 +52,8 @@ function flyToViewport(startProps, endProps, t) {
|
|
|
47
52
|
r0 = _getFlyToTransitionPa.r0;
|
|
48
53
|
|
|
49
54
|
if (u1 < EPSILON) {
|
|
55
|
+
var viewport = {};
|
|
56
|
+
|
|
50
57
|
var _iterator = _createForOfIteratorHelper(VIEWPORT_TRANSITION_PROPS),
|
|
51
58
|
_step;
|
|
52
59
|
|
|
@@ -74,19 +81,19 @@ function flyToViewport(startProps, endProps, t) {
|
|
|
74
81
|
var newCenterWorld = vec2.scale([], uDelta, u);
|
|
75
82
|
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
|
|
76
83
|
var newCenter = (0, _webMercatorUtils.worldToLngLat)(newCenterWorld);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
84
|
+
return {
|
|
85
|
+
longitude: newCenter[0],
|
|
86
|
+
latitude: newCenter[1],
|
|
87
|
+
zoom: newZoom
|
|
88
|
+
};
|
|
81
89
|
}
|
|
82
90
|
|
|
83
|
-
function getFlyToDuration(startProps, endProps) {
|
|
84
|
-
var opts =
|
|
85
|
-
|
|
86
|
-
var
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
maxDuration = _opts.maxDuration;
|
|
91
|
+
function getFlyToDuration(startProps, endProps, options) {
|
|
92
|
+
var opts = _objectSpread(_objectSpread({}, DEFAULT_OPTS), options);
|
|
93
|
+
|
|
94
|
+
var screenSpeed = opts.screenSpeed,
|
|
95
|
+
speed = opts.speed,
|
|
96
|
+
maxDuration = opts.maxDuration;
|
|
90
97
|
|
|
91
98
|
var _getFlyToTransitionPa2 = getFlyToTransitionParams(startProps, endProps, opts),
|
|
92
99
|
S = _getFlyToTransitionPa2.S,
|
|
@@ -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","getFlyToTransitionParams","startZoom","startCenterXY","uDelta","w0","u1","S","rho","rho2","r0","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;;;;;;;;;;;;;;;;AAIA,IAAMA,OAAO,GAAG,IAAhB;AACA,IAAMC,yBAAyB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,MAA1B,CAAlC;AACA,IAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,KADY;AAEnBC,EAAAA,KAAK,EAAE;AAFY,CAArB;;AAkBe,SAASC,aAAT,CACbC,UADa,EAEbC,QAFa,EAGbC,CAHa,EAIbC,OAJa,EASb;AAGA,8BAAqEC,wBAAwB,CAC3FJ,UAD2F,EAE3FC,QAF2F,EAG3FE,OAH2F,CAA7F;AAAA,MAAOE,SAAP,yBAAOA,SAAP;AAAA,MAAkBC,aAAlB,yBAAkBA,aAAlB;AAAA,MAAiCC,MAAjC,yBAAiCA,MAAjC;AAAA,MAAyCC,EAAzC,yBAAyCA,EAAzC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L,GAAU9C,EAAE,GAAGA,EAAf,GAAoBI,IAAI,GAAGA,IAAP,GAAc2C,GAAd,GAAoBA,GAAzC,KAAiD,IAAID,EAAJ,GAAS1C,IAAT,GAAgB2C,GAAjE,CAAX;AACA,MAAM1C,EAAE,GAAGO,IAAI,CAACsC,GAAL,CAAStC,IAAI,CAACuC,IAAL,CAAUH,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,MAAMI,EAAE,GAAGxC,IAAI,CAACsC,GAAL,CAAStC,IAAI,CAACuC,IAAL,CAAUF,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,MAAM/C,CAAC,GAAG,CAACkD,EAAE,GAAG/C,EAAN,IAAYF,GAAtB;AAEA,SAAO;AAACN,IAAAA,SAAS,EAATA,SAAD;AAAYC,IAAAA,aAAa,EAAbA,aAAZ;AAA2BC,IAAAA,MAAM,EAANA,MAA3B;AAAmCC,IAAAA,EAAE,EAAFA,EAAnC;AAAuCC,IAAAA,EAAE,EAAFA,EAAvC;AAA2CC,IAAAA,CAAC,EAADA,CAA3C;AAA8CC,IAAAA,GAAG,EAAHA,GAA9C;AAAmDC,IAAAA,IAAI,EAAJA,IAAnD;AAAyDC,IAAAA,EAAE,EAAFA,EAAzD;AAA6D+C,IAAAA,EAAE,EAAFA;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\nimport type {ViewportProps} from './normalize-viewport-props';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;\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\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): {\n longitude: number;\n latitude: number;\n zoom: number;\n} {\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: number;\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(\n startProps: ViewportProps,\n endProps: ViewportProps,\n opts: FlytoTransitionOptions\n): {\n startZoom: number;\n startCenterXY: number[];\n uDelta: number[];\n w0: number;\n u1: number;\n S: number;\n rho: number;\n rho2: number;\n r0: number;\n r1: number;\n} {\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([] as number[], 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
|
@@ -53,7 +53,7 @@ function unprojectOnFarPlane(viewport, x, targetZ) {
|
|
|
53
53
|
var t = (z - coord0[2]) / (coord1[2] - coord0[2]);
|
|
54
54
|
var coord = vec2.lerp([], coord0, coord1, t);
|
|
55
55
|
var result = (0, _webMercatorUtils.worldToLngLat)(coord);
|
|
56
|
-
result
|
|
56
|
+
result.push(targetZ);
|
|
57
57
|
return result;
|
|
58
58
|
}
|
|
59
59
|
//# sourceMappingURL=get-bounds.js.map
|
|
@@ -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","push"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;;;;;AAGA,IAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;;AAOe,SAASC,SAAT,CAAmBC,QAAnB,EAA6E;AAAA,MAA3BC,CAA2B,uEAAf,CAAe;AAE1F,MAAOC,KAAP,GAAmCF,QAAnC,CAAOE,KAAP;AAAA,MAAcC,MAAd,GAAmCH,QAAnC,CAAcG,MAAd;AAAA,MAAsBC,SAAtB,GAAmCJ,QAAnC,CAAsBI,SAAtB;AACA,MAAMC,YAAY,GAAG;AAACC,IAAAA,OAAO,EAAEL;AAAV,GAArB;AACA,MAAMM,UAAU,GAAGH,SAAS,CAAC,CAAC,CAAD,EAAID,MAAJ,CAAD,EAAcE,YAAd,CAA5B;AACA,MAAMG,WAAW,GAAGJ,SAAS,CAAC,CAACF,KAAD,EAAQC,MAAR,CAAD,EAAkBE,YAAlB,CAA7B;AACA,MAAII,OAAJ;AACA,MAAIC,QAAJ;AAEA,MAAMC,OAAO,GAAGX,QAAQ,CAACY,IAAT,GACZ,MAAMZ,QAAQ,CAACY,IAAf,GAAsBhB,kBADV,GAEZC,IAAI,CAACgB,IAAL,CAAU,MAAMb,QAAQ,CAACc,QAAzB,CAFJ;AAGA,MAAMC,aAAa,GAAG,CAAC,K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C,MAAtB,EAA8BG,CAA9B,CAAd;AAEA,MAAMI,MAAM,GAAG,qCAAcH,KAAd,CAAf;AACAG,EAAAA,MAAM,CAACC,IAAP,CAAYvB,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: number[];\n let topRight: number[];\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: number): number[] {\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.push(targetZ);\n return result;\n}\n"],"file":"get-bounds.js"}
|
package/dist/es5/index.js
CHANGED
|
@@ -49,6 +49,12 @@ Object.defineProperty(exports, "getFlyToDuration", {
|
|
|
49
49
|
return _flyToViewport.getFlyToDuration;
|
|
50
50
|
}
|
|
51
51
|
});
|
|
52
|
+
Object.defineProperty(exports, "MAX_LATITUDE", {
|
|
53
|
+
enumerable: true,
|
|
54
|
+
get: function get() {
|
|
55
|
+
return _webMercatorUtils.MAX_LATITUDE;
|
|
56
|
+
}
|
|
57
|
+
});
|
|
52
58
|
Object.defineProperty(exports, "lngLatToWorld", {
|
|
53
59
|
enumerable: true,
|
|
54
60
|
get: function get() {
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAGA;;AACA;;AACA;;AACA;;AAEA","sourcesContent":["// Classic web-mercator-project\nexport {default} from './web-mercator-viewport';\nexport {default as WebMercatorViewport} from './web-mercator-viewport';\n\nexport {default as getBounds} from './get-bounds';\nexport {default as fitBounds} from './fit-bounds';\nexport {default as normalizeViewportProps} from './normalize-viewport-props';\nexport {default as flyToViewport, getFlyToDuration} from './fly-to-viewport';\n\nexport {\n MAX_LATITUDE,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n pixelsToWorld,\n zoomToScale,\n scaleToZoom,\n altitudeToFovy,\n fovyToAltitude,\n getMeterZoom,\n getDistanceScales,\n addMetersToLngLat,\n getViewMatrix,\n getProjectionMatrix,\n getProjectionParameters\n} from './web-mercator-utils';\n\n/** Types */\nexport type {FitBoundsOptions} from './fit-bounds';\nexport type {DistanceScales} from './web-mercator-utils';\n"],"file":"index.js"}
|
package/dist/es5/math-utils.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
|
});
|
|
@@ -9,21 +7,18 @@ exports.createMat4 = createMat4;
|
|
|
9
7
|
exports.transformVector = transformVector;
|
|
10
8
|
exports.mod = mod;
|
|
11
9
|
exports.lerp = lerp;
|
|
10
|
+
exports.clamp = clamp;
|
|
12
11
|
exports.log2 = void 0;
|
|
13
12
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
-
|
|
18
|
-
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; }
|
|
13
|
+
var _vec = require("gl-matrix/vec4");
|
|
19
14
|
|
|
20
15
|
function createMat4() {
|
|
21
16
|
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
22
17
|
}
|
|
23
18
|
|
|
24
19
|
function transformVector(matrix, vector) {
|
|
25
|
-
var result =
|
|
26
|
-
|
|
20
|
+
var result = (0, _vec.transformMat4)([], vector, matrix);
|
|
21
|
+
(0, _vec.scale)(result, result, 1 / result[3]);
|
|
27
22
|
return result;
|
|
28
23
|
}
|
|
29
24
|
|
|
@@ -36,6 +31,10 @@ function lerp(start, end, step) {
|
|
|
36
31
|
return step * end + (1 - step) * start;
|
|
37
32
|
}
|
|
38
33
|
|
|
34
|
+
function clamp(x, min, max) {
|
|
35
|
+
return x < min ? min : x > max ? max : x;
|
|
36
|
+
}
|
|
37
|
+
|
|
39
38
|
function ieLog2(x) {
|
|
40
39
|
return Math.log(x) * Math.LOG2E;
|
|
41
40
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math-utils.
|
|
1
|
+
{"version":3,"sources":["../../src/math-utils.ts"],"names":["createMat4","transformVector","matrix","vector","result","mod","value","divisor","modulus","lerp","start","end","step","clamp","x","min","max","ieLog2","Math","log","LOG2E","log2"],"mappings":";;;;;;;;;;;;AAAA;;AAGO,SAASA,UAAT,GAAgC;AACrC,SAAO,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,EAAkC,CAAlC,EAAqC,CAArC,EAAwC,CAAxC,EAA2C,CAA3C,EAA8C,CAA9C,CAAP;AACD;;AAGM,SAASC,eAAT,CAAyBC,MAAzB,EAA2CC,MAA3C,EAAuE;AAC5E,MAAMC,MAAM,GAAG,wBAAc,EAAd,EAA8BD,MAA9B,EAAsCD,MAAtC,CAAf;AACA,kBAAME,MAAN,EAAcA,MAAd,EAAsB,IAAIA,MAAM,CAAC,CAAD,CAAhC;AACA,SAAOA,MAAP;AACD;;AAEM,SAASC,GAAT,CAAaC,KAAb,EAA4BC,OAA5B,EAAqD;AAC1D,MAAMC,OAAO,GAAGF,KAAK,GAAGC,OAAxB;AACA,SAAOC,OAAO,GAAG,CAAV,GAAcD,OAAO,GAAGC,OAAxB,GAAkCA,OAAzC;AACD;;AAEM,SAASC,IAAT,CAAcC,KAAd,EAA6BC,GAA7B,EAA0CC,IAA1C,EAAgE;AACrE,SAAOA,IAAI,GAAGD,GAAP,GAAa,CAAC,IAAIC,IAAL,IAAaF,KAAjC;AACD;;AAEM,SAASG,KAAT,CAAeC,CAAf,EAA0BC,GAA1B,EAAuCC,GAAvC,EAA4D;AACjE,SAAOF,CAAC,GAAGC,GAAJ,GAAUA,GAAV,GAAgBD,CAAC,GAAGE,GAAJ,GAAUA,GAAV,GAAgBF,CAAvC;AACD;;AAED,SAASG,MAAT,CAAgBH,CAAhB,EAAmC;AACjC,SAAOI,IAAI,CAACC,GAAL,CAASL,CAAT,IAAcI,IAAI,CAACE,KAA1B;AACD;;AAEM,IAAMC,IAAI,GAAGH,IAAI,CAACG,IAAL,IAAaJ,MAA1B","sourcesContent":["import {transformMat4, scale} from 'gl-matrix/vec4';\n\n// Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()\nexport function createMat4(): number[] {\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n}\n\n// Transforms a vec4 with a projection matrix\nexport function transformVector(matrix: number[], vector: number[]): number[] {\n const result = transformMat4([] as number[], vector, matrix);\n scale(result, result, 1 / result[3]);\n return result;\n}\n\nexport function mod(value: number, divisor: number): number {\n const modulus = value % divisor;\n return modulus < 0 ? divisor + modulus : modulus;\n}\n\nexport function lerp(start: number, end: number, step: number): number {\n return step * end + (1 - step) * start;\n}\n\nexport function clamp(x: number, min: number, max: number): number {\n return x < min ? min : x > max ? max : x;\n}\n\nfunction ieLog2(x: number): number {\n return Math.log(x) * Math.LOG2E;\n}\n// Handle missing log2 in IE 11\nexport const log2 = Math.log2 || ieLog2;\n"],"file":"math-utils.js"}
|
|
@@ -11,16 +11,16 @@ var _mathUtils = require("./math-utils");
|
|
|
11
11
|
|
|
12
12
|
var TILE_SIZE = 512;
|
|
13
13
|
|
|
14
|
-
function normalizeViewportProps(
|
|
15
|
-
var width =
|
|
16
|
-
height =
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
bearing =
|
|
14
|
+
function normalizeViewportProps(props) {
|
|
15
|
+
var width = props.width,
|
|
16
|
+
height = props.height,
|
|
17
|
+
_props$pitch = props.pitch,
|
|
18
|
+
pitch = _props$pitch === void 0 ? 0 : _props$pitch;
|
|
19
|
+
var longitude = props.longitude,
|
|
20
|
+
latitude = props.latitude,
|
|
21
|
+
zoom = props.zoom,
|
|
22
|
+
_props$bearing = props.bearing,
|
|
23
|
+
bearing = _props$bearing === void 0 ? 0 : _props$bearing;
|
|
24
24
|
|
|
25
25
|
if (longitude < -180 || longitude > 180) {
|
|
26
26
|
longitude = (0, _mathUtils.mod)(longitude + 180, 360) - 180;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/normalize-viewport-props.
|
|
1
|
+
{"version":3,"sources":["../../src/normalize-viewport-props.ts"],"names":["TILE_SIZE","normalizeViewportProps","props","width","height","pitch","longitude","latitude","zoom","bearing","minZoom","halfHeightPixels","Math","pow","minLatitude","maxLatitude"],"mappings":";;;;;;;AAAA;;AACA;;AAGA,IAAMA,SAAS,GAAG,GAAlB;;AAkBe,SAASC,sBAAT,CAAgCC,KAAhC,EAAqE;AAClF,MAAOC,KAAP,GAAmCD,KAAnC,CAAOC,KAAP;AAAA,MAAcC,MAAd,GAAmCF,KAAnC,CAAcE,M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Af,EAA4B;AAC1BR,QAAAA,QAAQ,GAAGQ,WAAX;AACD;AACF;AACF;;AAED,SAAO;AAACZ,IAAAA,KAAK,EAALA,KAAD;AAAQC,IAAAA,MAAM,EAANA,MAAR;AAAgBE,IAAAA,SAAS,EAATA,SAAhB;AAA2BC,IAAAA,QAAQ,EAARA,QAA3B;AAAqCC,IAAAA,IAAI,EAAJA,IAArC;AAA2CH,IAAAA,KAAK,EAALA,KAA3C;AAAkDI,IAAAA,OAAO,EAAPA;AAAlD,GAAP;AACD","sourcesContent":["import {worldToLngLat} from './web-mercator-utils';\nimport {mod, log2} from './math-utils';\n\n// defined by mapbox-gl\nconst TILE_SIZE = 512;\n\n/** Description of viewport */\nexport type ViewportProps = {\n width: number;\n height: number;\n longitude: number;\n latitude: number;\n zoom: number;\n pitch?: number;\n bearing?: number;\n};\n\n/**\n * Apply mathematical constraints to viewport props\n * @param props\n */\n// eslint-disable-next-line complexity\nexport default function normalizeViewportProps(props: ViewportProps): ViewportProps {\n const {width, height, pitch = 0} = props;\n let {longitude, latitude, zoom, bearing = 0} = props;\n\n // Normalize degrees\n if (longitude < -180 || longitude > 180) {\n longitude = mod(longitude + 180, 360) - 180;\n }\n if (bearing < -180 || bearing > 180) {\n bearing = mod(bearing + 180, 360) - 180;\n }\n\n // Constrain zoom and shift center at low zoom levels\n const minZoom = log2(height / TILE_SIZE);\n if (zoom <= minZoom) {\n zoom = minZoom;\n latitude = 0;\n } else {\n // Eliminate white space above and below the map\n const halfHeightPixels = height / 2 / Math.pow(2, zoom);\n const minLatitude = worldToLngLat([0, halfHeightPixels])[1];\n if (latitude < minLatitude) {\n latitude = minLatitude;\n } else {\n const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];\n if (latitude > maxLatitude) {\n latitude = maxLatitude;\n }\n }\n }\n\n return {width, height, longitude, latitude, zoom, pitch, bearing};\n}\n"],"file":"normalize-viewport-props.js"}
|