@math.gl/web-mercator 3.6.0-alpha.1 → 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.
Files changed (59) hide show
  1. package/dist/es5/fit-bounds.js +37 -31
  2. package/dist/es5/fit-bounds.js.map +1 -1
  3. package/dist/es5/fly-to-viewport.js +98 -75
  4. package/dist/es5/fly-to-viewport.js.map +1 -1
  5. package/dist/es5/get-bounds.js +25 -26
  6. package/dist/es5/get-bounds.js.map +1 -1
  7. package/dist/es5/index.js +31 -23
  8. package/dist/es5/index.js.map +1 -1
  9. package/dist/es5/math-utils.js +8 -3
  10. package/dist/es5/math-utils.js.map +1 -1
  11. package/dist/es5/normalize-viewport-props.js +21 -23
  12. package/dist/es5/normalize-viewport-props.js.map +1 -1
  13. package/dist/es5/web-mercator-utils.js +118 -92
  14. package/dist/es5/web-mercator-utils.js.map +1 -1
  15. package/dist/es5/web-mercator-viewport.js +239 -178
  16. package/dist/es5/web-mercator-viewport.js.map +1 -1
  17. package/dist/esm/fit-bounds.js +6 -13
  18. package/dist/esm/fit-bounds.js.map +1 -1
  19. package/dist/esm/fly-to-viewport.js.map +1 -1
  20. package/dist/esm/get-bounds.js +1 -1
  21. package/dist/esm/get-bounds.js.map +1 -1
  22. package/dist/esm/index.js +1 -1
  23. package/dist/esm/index.js.map +1 -1
  24. package/dist/esm/math-utils.js +3 -0
  25. package/dist/esm/math-utils.js.map +1 -1
  26. package/dist/esm/normalize-viewport-props.js.map +1 -1
  27. package/dist/esm/web-mercator-utils.js +2 -1
  28. package/dist/esm/web-mercator-utils.js.map +1 -1
  29. package/dist/esm/web-mercator-viewport.js +1 -1
  30. package/dist/esm/web-mercator-viewport.js.map +1 -1
  31. package/dist/fit-bounds.d.ts +3 -2
  32. package/dist/fit-bounds.d.ts.map +1 -1
  33. package/dist/fit-bounds.js +6 -13
  34. package/dist/fly-to-viewport.d.ts +6 -6
  35. package/dist/fly-to-viewport.d.ts.map +1 -1
  36. package/dist/get-bounds.js +1 -1
  37. package/dist/index.d.ts +4 -1
  38. package/dist/index.d.ts.map +1 -1
  39. package/dist/index.js +1 -1
  40. package/dist/math-utils.d.ts +2 -1
  41. package/dist/math-utils.d.ts.map +1 -1
  42. package/dist/math-utils.js +3 -0
  43. package/dist/normalize-viewport-props.d.ts +1 -2
  44. package/dist/normalize-viewport-props.d.ts.map +1 -1
  45. package/dist/web-mercator-utils.d.ts +4 -3
  46. package/dist/web-mercator-utils.d.ts.map +1 -1
  47. package/dist/web-mercator-utils.js +3 -2
  48. package/dist/web-mercator-viewport.d.ts +4 -5
  49. package/dist/web-mercator-viewport.d.ts.map +1 -1
  50. package/dist/web-mercator-viewport.js +1 -2
  51. package/package.json +3 -3
  52. package/src/fit-bounds.ts +8 -16
  53. package/src/fly-to-viewport.ts +26 -11
  54. package/src/get-bounds.ts +4 -4
  55. package/src/index.ts +5 -0
  56. package/src/math-utils.ts +6 -2
  57. package/src/normalize-viewport-props.ts +1 -1
  58. package/src/web-mercator-utils.ts +9 -8
  59. package/src/web-mercator-viewport.ts +8 -10
@@ -7,51 +7,57 @@ Object.defineProperty(exports, "__esModule", {
7
7
  });
8
8
  exports.default = fitBounds;
9
9
 
10
- var _webMercatorViewport = _interopRequireDefault(require("./web-mercator-viewport"));
10
+ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
11
11
 
12
12
  var _assert = _interopRequireDefault(require("./assert"));
13
13
 
14
14
  var _mathUtils = require("./math-utils");
15
15
 
16
+ var _webMercatorUtils = require("./web-mercator-utils");
17
+
16
18
  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,
30
- longitude: 0,
31
- latitude: 0,
32
- zoom: 0
33
- });
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];
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;
28
+
29
+ var _bounds = (0, _slicedToArray2.default)(bounds, 2),
30
+ _bounds$ = (0, _slicedToArray2.default)(_bounds[0], 2),
31
+ west = _bounds$[0],
32
+ south = _bounds$[1],
33
+ _bounds$2 = (0, _slicedToArray2.default)(_bounds[1], 2),
34
+ east = _bounds$2[0],
35
+ north = _bounds$2[1];
36
+
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)]);
40
+ var size = [Math.max(Math.abs(se[0] - nw[0]), minExtent), Math.max(Math.abs(se[1] - nw[1]), minExtent)];
41
+ var targetSize = [width - padding.left - padding.right - Math.abs(offset[0]) * 2, height - padding.top - padding.bottom - Math.abs(offset[1]) * 2];
38
42
  (0, _assert.default)(targetSize[0] > 0 && targetSize[1] > 0);
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))));
43
+ var scaleX = targetSize[0] / size[0];
44
+ var scaleY = targetSize[1] / size[1];
45
+ var offsetX = (padding.right - padding.left) / 2 / scaleX;
46
+ var offsetY = (padding.bottom - padding.top) / 2 / scaleY;
47
+ var center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
48
+ var centerLngLat = (0, _webMercatorUtils.worldToLngLat)(center);
49
+ var zoom = Math.min(maxZoom, (0, _mathUtils.log2)(Math.abs(Math.min(scaleX, scaleY))));
46
50
  (0, _assert.default)(Number.isFinite(zoom));
47
51
  return {
48
52
  longitude: centerLngLat[0],
49
53
  latitude: centerLngLat[1],
50
- zoom
54
+ zoom: zoom
51
55
  };
52
56
  }
53
57
 
54
- function getPaddingObject(padding = 0) {
58
+ function getPaddingObject() {
59
+ var padding = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
60
+
55
61
  if (typeof padding === 'number') {
56
62
  return {
57
63
  top: padding,
@@ -1 +1 @@
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;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AGD,SAASL,gBAAT,CAA0BD,OAAyB,GAAG,CAAtD,EAAkE;AAChE,MAAI,OAAOA,OAAP,KAAmB,QAAvB,EAAiC;AAC/B,WAAO;AACLiB,MAAAA,GAAG,EAAEjB,OADA;AAELkB,MAAAA,MAAM,EAAElB,OAFH;AAGLe,MAAAA,IAAI,EAAEf,OAHD;AAILgB,MAAAA,KAAK,EAAEhB;AAJF,KAAP;AAMD;;AAGD,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
+ {"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,CAIEI,SAJF;AAAA,MAIEA,SAJF,mCAIc,CAJd;AAAA,yBAOIJ,OAPJ,CAKEK,OALF;AAAA,MAKEA,OALF,iCAKY,EALZ;AAAA,wBAOIL,OAPJ,CAMEM,MANF;AAAA,MAMEA,MANF,gCAMW,CAAC,CAAD,EAAI,CAAJ,CANX;;AASA,6CAAuCH,MAAvC;AAAA;AAAA,MAAQI,IAAR;AAAA,MAAcC,KAAd;AAAA;AAAA,MAAuBC,IAAvB;AAAA,MAA6BC,KAA7B;;AACA,MAAMC,OAAO,GAAGC,gBAAgB,CAACZ,OAAO,CAACW,OAAT,CAAhC;AAEA,MAAME,EAAE,GAAG,qCAAc,CAACN,IAAD,EAAO,sBAAMG,KAAN,EAAa,CAACI,8BAAd,EAA4BA,8BAA5B,CAAP,CAAd,CAAX;AACA,MAAMC,EAAE,GAAG,qCAAc,CAACN,IAAD,EAAO,sBAAMD,KAAN,EAAa,CAACM,8BAAd,EAA4BA,8BAA5B,CAAP,CAAd,CAAX;AAGA,MAAME,IAAI,GAAG,CACXC,IAAI,CAACC,GAAL,CAASD,IAAI,CA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AAX,IAAkB,CAAlB,GAAsBe,OAAtD,CAAf;AAEA,MAAME,YAAY,GAAG,qCAAcD,MAAd,CAArB;AACA,MAAME,IAAI,GAAGd,IAAI,CAACe,GAAL,CAAS3B,OAAT,EAAkB,qBAAKY,IAAI,CAACE,GAAL,CAASF,IAAI,CAACe,GAAL,CAASP,MAAT,EAAiBC,MAAjB,CAAT,CAAL,CAAlB,CAAb;AAEA,uBAAOO,MAAM,CAACC,QAAP,CAAgBH,IAAhB,CAAP;AAEA,SAAO;AACLI,IAAAA,SAAS,EAAEL,YAAY,CAAC,CAAD,CADlB;AAELM,IAAAA,QAAQ,EAAEN,YAAY,CAAC,CAAD,CAFjB;AAGLC,IAAAA,IAAI,EAAJA;AAHK,GAAP;AAKD;;AAGD,SAASnB,gBAAT,GAAkE;AAAA,MAAxCD,OAAwC,uEAAZ,CAAY;;AAChE,MAAI,OAAOA,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,61 +1,86 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ var _typeof = require("@babel/runtime/helpers/typeof");
6
+
3
7
  Object.defineProperty(exports, "__esModule", {
4
8
  value: true
5
9
  });
6
10
  exports.default = flyToViewport;
7
11
  exports.getFlyToDuration = getFlyToDuration;
8
12
 
13
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
14
+
9
15
  var _mathUtils = require("./math-utils");
10
16
 
11
17
  var _webMercatorUtils = require("./web-mercator-utils");
12
18
 
13
19
  var vec2 = _interopRequireWildcard(require("gl-matrix/vec2"));
14
20
 
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); }
21
+ 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); }
22
+
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; }
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
+
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; } } }; }
16
30
 
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; }
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); }
18
32
 
19
- const EPSILON = 0.01;
20
- const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
21
- const DEFAULT_OPTS = {
33
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
34
+
35
+ var EPSILON = 0.01;
36
+ var VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
37
+ var DEFAULT_OPTS = {
22
38
  curve: 1.414,
23
39
  speed: 1.2
24
40
  };
25
41
 
26
42
  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);
43
+ var _getFlyToTransitionPa = getFlyToTransitionParams(startProps, endProps, options),
44
+ startZoom = _getFlyToTransitionPa.startZoom,
45
+ startCenterXY = _getFlyToTransitionPa.startCenterXY,
46
+ uDelta = _getFlyToTransitionPa.uDelta,
47
+ w0 = _getFlyToTransitionPa.w0,
48
+ u1 = _getFlyToTransitionPa.u1,
49
+ S = _getFlyToTransitionPa.S,
50
+ rho = _getFlyToTransitionPa.rho,
51
+ rho2 = _getFlyToTransitionPa.rho2,
52
+ r0 = _getFlyToTransitionPa.r0;
38
53
 
39
54
  if (u1 < EPSILON) {
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);
55
+ var viewport = {};
56
+
57
+ var _iterator = _createForOfIteratorHelper(VIEWPORT_TRANSITION_PROPS),
58
+ _step;
59
+
60
+ try {
61
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
62
+ var key = _step.value;
63
+ var startValue = startProps[key];
64
+ var endValue = endProps[key];
65
+ viewport[key] = (0, _mathUtils.lerp)(startValue, endValue, t);
66
+ }
67
+ } catch (err) {
68
+ _iterator.e(err);
69
+ } finally {
70
+ _iterator.f();
46
71
  }
47
72
 
48
73
  return viewport;
49
74
  }
50
75
 
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);
76
+ var s = t * S;
77
+ var w = Math.cosh(r0) / Math.cosh(r0 + rho * s);
78
+ var u = w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2) / u1;
79
+ var scaleIncrement = 1 / w;
80
+ var newZoom = startZoom + (0, _webMercatorUtils.scaleToZoom)(scaleIncrement);
81
+ var newCenterWorld = vec2.scale([], uDelta, u);
57
82
  vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
58
- const newCenter = (0, _webMercatorUtils.worldToLngLat)(newCenterWorld);
83
+ var newCenter = (0, _webMercatorUtils.worldToLngLat)(newCenterWorld);
59
84
  return {
60
85
  longitude: newCenter[0],
61
86
  latitude: newCenter[1],
@@ -64,20 +89,18 @@ function flyToViewport(startProps, endProps, t, options) {
64
89
  }
65
90
 
66
91
  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;
92
+ var opts = _objectSpread(_objectSpread({}, DEFAULT_OPTS), options);
93
+
94
+ var screenSpeed = opts.screenSpeed,
95
+ speed = opts.speed,
96
+ maxDuration = opts.maxDuration;
97
+
98
+ var _getFlyToTransitionPa2 = getFlyToTransitionParams(startProps, endProps, opts),
99
+ S = _getFlyToTransitionPa2.S,
100
+ rho = _getFlyToTransitionPa2.rho;
101
+
102
+ var length = 1000 * S;
103
+ var duration;
81
104
 
82
105
  if (Number.isFinite(screenSpeed)) {
83
106
  duration = length / (screenSpeed / rho);
@@ -90,39 +113,39 @@ function getFlyToDuration(startProps, endProps, options) {
90
113
 
91
114
  function getFlyToTransitionParams(startProps, endProps, opts) {
92
115
  opts = Object.assign({}, DEFAULT_OPTS, opts);
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;
116
+ var rho = opts.curve;
117
+ var startZoom = startProps.zoom;
118
+ var startCenter = [startProps.longitude, startProps.latitude];
119
+ var startScale = (0, _webMercatorUtils.zoomToScale)(startZoom);
120
+ var endZoom = endProps.zoom;
121
+ var endCenter = [endProps.longitude, endProps.latitude];
122
+ var scale = (0, _webMercatorUtils.zoomToScale)(endZoom - startZoom);
123
+ var startCenterXY = (0, _webMercatorUtils.lngLatToWorld)(startCenter);
124
+ var endCenterXY = (0, _webMercatorUtils.lngLatToWorld)(endCenter);
125
+ var uDelta = vec2.sub([], endCenterXY, startCenterXY);
126
+ var w0 = Math.max(startProps.width, startProps.height);
127
+ var w1 = w0 / scale;
128
+ var u1 = vec2.length(uDelta) * startScale;
129
+
130
+ var _u1 = Math.max(u1, EPSILON);
131
+
132
+ var rho2 = rho * rho;
133
+ var b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);
134
+ var b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);
135
+ var r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
136
+ var r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
137
+ var S = (r1 - r0) / rho;
115
138
  return {
116
- startZoom,
117
- startCenterXY,
118
- uDelta,
119
- w0,
120
- u1,
121
- S,
122
- rho,
123
- rho2,
124
- r0,
125
- r1
139
+ startZoom: startZoom,
140
+ startCenterXY: startCenterXY,
141
+ uDelta: uDelta,
142
+ w0: w0,
143
+ u1: u1,
144
+ S: S,
145
+ rho: rho,
146
+ rho2: rho2,
147
+ r0: r0,
148
+ r1: r1
126
149
  };
127
150
  }
128
151
  //# sourceMappingURL=fly-to-viewport.js.map
@@ -1 +1 @@
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,U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,GAAGA,EAAf,GAAoBI,IAAI,GAAGA,IAAP,GAAc4C,GAAd,GAAoBA,GAAzC,KAAiD,IAAIhD,EAAJ,GAASI,IAAT,GAAgB4C,GAAjE,CAAX;AACA,QAAME,EAAE,GAAG,CAACH,EAAE,GAAGA,EAAL,GAAU/C,EAAE,GAAGA,EAAf,GAAoBI,IAAI,GAAGA,IAAP,GAAc4C,GAAd,GAAoBA,GAAzC,KAAiD,IAAID,EAAJ,GAAS3C,IAAT,GAAgB4C,GAAjE,CAAX;AACA,QAAM3C,EAAE,GAAGQ,IAAI,CAACsC,GAAL,CAAStC,IAAI,CAACuC,IAAL,CAAUH,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,QAAMI,EAAE,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"}
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","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CC,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"}
@@ -1,5 +1,7 @@
1
1
  "use strict";
2
2
 
3
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
+
3
5
  Object.defineProperty(exports, "__esModule", {
4
6
  value: true
5
7
  });
@@ -11,27 +13,26 @@ var vec2 = _interopRequireWildcard(require("gl-matrix/vec2"));
11
13
 
12
14
  var _mathUtils = require("./math-utils");
13
15
 
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); }
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); }
15
17
 
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; }
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; }
17
19
 
18
- const DEGREES_TO_RADIANS = Math.PI / 180;
20
+ var DEGREES_TO_RADIANS = Math.PI / 180;
19
21
 
20
- function getBounds(viewport, z = 0) {
21
- const {
22
- width,
23
- height,
24
- unproject
25
- } = viewport;
26
- const unprojectOps = {
22
+ function getBounds(viewport) {
23
+ var z = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
24
+ var width = viewport.width,
25
+ height = viewport.height,
26
+ unproject = viewport.unproject;
27
+ var unprojectOps = {
27
28
  targetZ: z
28
29
  };
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;
30
+ var bottomLeft = unproject([0, height], unprojectOps);
31
+ var bottomRight = unproject([width, height], unprojectOps);
32
+ var topLeft;
33
+ var topRight;
34
+ var halfFov = viewport.fovy ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS : Math.atan(0.5 / viewport.altitude);
35
+ var angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;
35
36
 
36
37
  if (halfFov > angleToGround - 0.01) {
37
38
  topLeft = unprojectOnFarPlane(viewport, 0, z);
@@ -45,16 +46,14 @@ function getBounds(viewport, z = 0) {
45
46
  }
46
47
 
47
48
  function unprojectOnFarPlane(viewport, x, targetZ) {
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);
57
- result[2] = targetZ;
49
+ var pixelUnprojectionMatrix = viewport.pixelUnprojectionMatrix;
50
+ var coord0 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, 0, 1, 1]);
51
+ var coord1 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
52
+ var z = targetZ * viewport.distanceScales.unitsPerMeter[2];
53
+ var t = (z - coord0[2]) / (coord1[2] - coord0[2]);
54
+ var coord = vec2.lerp([], coord0, coord1, t);
55
+ var result = (0, _webMercatorUtils.worldToLngLat)(coord);
56
+ result.push(targetZ);
58
57
  return result;
59
58
  }
60
59
  //# sourceMappingURL=get-bounds.js.map
@@ -1 +1 @@
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,CAAC,CAAC,CAAD,EAAID,MAAJ,CAAD,EAAcE,YAAd,CAA5B;AACA,QAAMG,WAAW,GAAGJ,SAAS,CAAC,CAACF,KAAD,EAAQC,MAAR,CAAD,EAAkBE,YAAlB,CAA7B;AACA,MAAII,OAAJ;AACA,MAAIC,QAAJ;AAEA,QAAMC,OAAO,GAAGX,QAAQ,CAACY,IAAT,GACZ,MAAMZ,QAAQ,CAACY,IAAf,GAAsBhB,kBADV,GAEZC,IAAI,CAACgB,IAAL,CAAU,MAAMb,QAAQ,CAACc,QAAzB,CAFJ;AAGA,QAAMC,aAAa,GAAG,CAAC,KAAKf,QAAQ,CAACgB,KAAf,IAAwBpB,kBAA9C;;AAEA,MAAIe,OAAO,GAAGI,aAAa,GAAG,IAA9B,EAAoC;AAElCN,IAAAA,OAAO,GAAGQ,mBAAmB,CAACjB,QAAD,EAAW,CAAX,EAAcC,CAAd,CAA7B;AACAS,IAAAA,QAAQ,GAAGO,mBAAmB,CAACjB,QAAD,EAAWE,KAAX,EAAkBD,CAAlB,CAA9B;AACD,GAJD,MAIO;AAELQ,IAAAA,OAAO,GAAGL,SAAS,CAAC,CAAC,CAAD,EAAI,CAAJ,CAAD,EAASC,YAAT,CAAnB;AACAK,IAAAA,QAAQ,GAAGN,SAAS,CAAC,CAACF,KAAD,EAAQ,CAAR,CAAD,EAAaG,YAAb,CAApB;AACD;;AAED,SAAO,CAACE,UAAD,EAAaC,WAAb,EAA0BE,QAA1B,EAAoCD,OAApC,CAAP;AACD;;AAQD,SAASQ,mBAAT,CAA6BjB,QAA7B,EAA4DkB,CAA5D,EAAuEZ,OAAvE,EAAgF;AAC9E,QAAM;AAACa,IAAAA;AAAD,MAA4BnB,QAAlC;AACA,QAAMoB,MAAM,GAAG,gCAAgBD,uBAAhB,EAAyC,CAACD,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAAzC,CAAf;AACA,QAAMG,MAAM,GAAG,gCAAgBF,uBAAhB,EAAyC,CAACD,CAAD,EAAIlB,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"}
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","pixel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T,CAAnB;AACAK,IAAAA,QAAQ,GAAGN,SAAS,CAAC,CAACF,KAAD,EAAQ,CAAR,CAAD,EAAaG,YAAb,CAApB;AACD;;AAED,SAAO,CAACE,UAAD,EAAaC,WAAb,EAA0BE,QAA1B,EAAoCD,OAApC,CAAP;AACD;;AAQD,SAASQ,mBAAT,CAA6BjB,QAA7B,EAA4DkB,CAA5D,EAAuEZ,OAAvE,EAAkG;AAChG,MAAOa,uBAAP,GAAkCnB,QAAlC,CAAOmB,uBAAP;AACA,MAAMC,MAAM,GAAG,gCAAgBD,uBAAhB,EAAyC,CAACD,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAAzC,CAAf;AACA,MAAMG,MAAM,GAAG,gCAAgBF,uBAAhB,EAAyC,CAACD,CAAD,EAAIlB,QAAQ,CAACG,MAAb,EAAqB,CAArB,EAAwB,CAAxB,CAAzC,CAAf;AAEA,MAAMF,CAAC,GAAGK,OAAO,GAAGN,QAAQ,CAACsB,cAAT,CAAwBC,aAAxB,CAAsC,CAAtC,CAApB;AACA,MAAMC,CAAC,GAAG,CAACvB,CAAC,GAAGmB,MAAM,CAAC,CAAD,CAAX,KAAmBC,MAAM,CAAC,CAAD,CAAN,GAAYD,MAAM,CAAC,CAAD,CAArC,CAAV;AACA,MAAMK,KAAK,GAAGC,IAAI,CAACC,IAAL,CAAU,EAAV,EAAcP,MAAd,EAAsBC,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"}