@math.gl/web-mercator 3.5.3 → 3.6.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assert.d.ts +2 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +8 -0
- package/dist/es5/assert.js.map +1 -1
- package/dist/es5/fit-bounds.js +40 -50
- package/dist/es5/fit-bounds.js.map +1 -1
- package/dist/es5/fly-to-viewport.js +82 -98
- package/dist/es5/fly-to-viewport.js.map +1 -1
- package/dist/es5/get-bounds.js +25 -24
- package/dist/es5/get-bounds.js.map +1 -1
- package/dist/es5/index.js +23 -25
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/math-utils.js +5 -11
- package/dist/es5/math-utils.js.map +1 -1
- package/dist/es5/normalize-viewport-props.js +36 -51
- package/dist/es5/normalize-viewport-props.js.map +1 -1
- package/dist/es5/web-mercator-utils.js +104 -144
- package/dist/es5/web-mercator-utils.js.map +1 -1
- package/dist/es5/web-mercator-viewport.js +198 -241
- package/dist/es5/web-mercator-viewport.js.map +1 -1
- package/dist/esm/assert.js.map +1 -1
- package/dist/esm/fit-bounds.js +24 -22
- package/dist/esm/fit-bounds.js.map +1 -1
- package/dist/esm/fly-to-viewport.js +13 -9
- package/dist/esm/fly-to-viewport.js.map +1 -1
- package/dist/esm/get-bounds.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math-utils.js +3 -3
- package/dist/esm/math-utils.js.map +1 -1
- package/dist/esm/normalize-viewport-props.js +30 -41
- package/dist/esm/normalize-viewport-props.js.map +1 -1
- package/dist/esm/web-mercator-utils.js +46 -52
- package/dist/esm/web-mercator-utils.js.map +1 -1
- package/dist/esm/web-mercator-viewport.js +75 -33
- package/dist/esm/web-mercator-viewport.js.map +1 -1
- package/dist/fit-bounds.d.ts +49 -0
- package/dist/fit-bounds.d.ts.map +1 -0
- package/dist/fit-bounds.js +70 -0
- package/dist/fly-to-viewport.d.ts +19 -0
- package/dist/fly-to-viewport.d.ts.map +1 -0
- package/dist/fly-to-viewport.js +87 -0
- package/dist/get-bounds.d.ts +3 -0
- package/dist/get-bounds.d.ts.map +1 -0
- package/dist/get-bounds.js +51 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/math-utils.d.ts +6 -0
- package/dist/math-utils.d.ts.map +1 -0
- package/dist/math-utils.js +23 -0
- package/dist/normalize-viewport-props.d.ts +17 -0
- package/dist/normalize-viewport-props.d.ts.map +1 -0
- package/dist/normalize-viewport-props.js +41 -0
- package/dist/{es5/web-mercator-utils.d.ts → web-mercator-utils.d.ts} +77 -94
- package/dist/web-mercator-utils.d.ts.map +1 -0
- package/dist/web-mercator-utils.js +289 -0
- package/dist/web-mercator-viewport.d.ts +183 -0
- package/dist/web-mercator-viewport.d.ts.map +1 -0
- package/dist/web-mercator-viewport.js +282 -0
- package/package.json +4 -4
- package/src/{assert.js → assert.ts} +1 -1
- package/src/fit-bounds.ts +135 -0
- package/src/{fly-to-viewport.js → fly-to-viewport.ts} +33 -10
- package/src/{get-bounds.js → get-bounds.ts} +4 -2
- package/src/{index.js → index.ts} +0 -0
- package/src/{math-utils.js → math-utils.ts} +7 -7
- package/src/normalize-viewport-props.ts +55 -0
- package/src/{web-mercator-utils.js → web-mercator-utils.ts} +181 -72
- package/src/web-mercator-viewport.ts +417 -0
- package/dist/es5/fit-bounds.d.ts +0 -64
- package/dist/es5/fly-to-viewport.d.ts +0 -31
- package/dist/es5/get-bounds.d.ts +0 -3
- package/dist/es5/index.d.ts +0 -23
- package/dist/es5/normalize-viewport-props.d.ts +0 -16
- package/dist/es5/web-mercator-viewport.d.ts +0 -187
- package/dist/esm/fit-bounds.d.ts +0 -64
- package/dist/esm/fly-to-viewport.d.ts +0 -31
- package/dist/esm/get-bounds.d.ts +0 -3
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/normalize-viewport-props.d.ts +0 -16
- package/dist/esm/web-mercator-utils.d.ts +0 -189
- package/dist/esm/web-mercator-viewport.d.ts +0 -187
- package/src/fit-bounds.d.ts +0 -64
- package/src/fit-bounds.js +0 -84
- package/src/fly-to-viewport.d.ts +0 -31
- package/src/get-bounds.d.ts +0 -3
- package/src/index.d.ts +0 -23
- package/src/normalize-viewport-props.d.ts +0 -16
- package/src/normalize-viewport-props.js +0 -55
- package/src/web-mercator-utils.d.ts +0 -189
- package/src/web-mercator-viewport.d.ts +0 -187
- package/src/web-mercator-viewport.js +0 -262
package/dist/esm/fit-bounds.js
CHANGED
|
@@ -1,29 +1,17 @@
|
|
|
1
1
|
import WebMercatorViewport from './web-mercator-viewport';
|
|
2
2
|
import assert from './assert';
|
|
3
3
|
import { log2 } from './math-utils';
|
|
4
|
-
export default function fitBounds({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
4
|
+
export default function fitBounds(options) {
|
|
5
|
+
const {
|
|
6
|
+
width,
|
|
7
|
+
height,
|
|
8
|
+
bounds,
|
|
9
|
+
minExtent = 0,
|
|
10
|
+
maxZoom = 24,
|
|
11
|
+
offset = [0, 0]
|
|
12
|
+
} = options;
|
|
13
13
|
const [[west, south], [east, north]] = bounds;
|
|
14
|
-
|
|
15
|
-
if (Number.isFinite(padding)) {
|
|
16
|
-
const p = padding;
|
|
17
|
-
padding = {
|
|
18
|
-
top: p,
|
|
19
|
-
bottom: p,
|
|
20
|
-
left: p,
|
|
21
|
-
right: p
|
|
22
|
-
};
|
|
23
|
-
} else {
|
|
24
|
-
assert(Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right));
|
|
25
|
-
}
|
|
26
|
-
|
|
14
|
+
const padding = getPaddingObject(options.padding);
|
|
27
15
|
const viewport = new WebMercatorViewport({
|
|
28
16
|
width,
|
|
29
17
|
height,
|
|
@@ -50,4 +38,18 @@ export default function fitBounds({
|
|
|
50
38
|
zoom
|
|
51
39
|
};
|
|
52
40
|
}
|
|
41
|
+
|
|
42
|
+
function getPaddingObject(padding = 0) {
|
|
43
|
+
if (typeof padding === 'number') {
|
|
44
|
+
return {
|
|
45
|
+
top: padding,
|
|
46
|
+
bottom: padding,
|
|
47
|
+
left: padding,
|
|
48
|
+
right: padding
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
assert(Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right));
|
|
53
|
+
return padding;
|
|
54
|
+
}
|
|
53
55
|
//# sourceMappingURL=fit-bounds.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fit-bounds.
|
|
1
|
+
{"version":3,"sources":["../../src/fit-bounds.ts"],"names":["WebMercatorViewport","assert","log2","fitBounds","options","width","height","bounds","minExtent","maxZoom","offset","west","south","east","north","padding","getPaddingObject","viewport","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,OAAOA,mBAAP,MAAgC,yBAAhC;AACA,OAAOC,MAAP,MAAmB,UAAnB;AACA,SAAQC,IAAR,QAAmB,cAAnB;AAqDA,eAAe,SAASC,SAAT,CAAmBC,OAAnB,EAAsD;AACnE,QAAM;AACJC,IAAAA,KADI;AAEJC,IAAAA,MAFI;AAGJC,IAAAA,MAHI;AAIJC,IAAAA,SAAS,GAAG,CAJR;AAKJC,IAAAA,OAAO,GAAG,EALN;AAMJC,IAAAA,MAAM,GAAG,CAAC,CAAD,EAAI,CAAJ;AANL,MAOFN,OAPJ;AASA,QAAM,CAAC,CAACO,IAAD,EAAOC,KAAP,CAAD,EAAgB,CAACC,IAAD,EAAOC,KAAP,CAAhB,IAAiCP,MAAvC;AACA,QAAMQ,OAAO,GAAGC,gBAAgB,CAACZ,OAAO,C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OAFH;AAGLc,MAAAA,IAAI,EAAEd,OAHD;AAILe,MAAAA,KAAK,EAAEf;AAJF,KAAP;AAMD;;AAGDd,EAAAA,MAAM,CACJwC,MAAM,CAACC,QAAP,CAAgB3B,OAAO,CAACgB,GAAxB,KACEU,MAAM,CAACC,QAAP,CAAgB3B,OAAO,CAACiB,MAAxB,CADF,IAEES,MAAM,CAACC,QAAP,CAAgB3B,OAAO,CAACc,IAAxB,CAFF,IAGEY,MAAM,CAACC,QAAP,CAAgB3B,OAAO,CAACe,KAAxB,CAJE,CAAN;AAOA,SAAOf,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"}
|
|
@@ -7,8 +7,7 @@ const DEFAULT_OPTS = {
|
|
|
7
7
|
curve: 1.414,
|
|
8
8
|
speed: 1.2
|
|
9
9
|
};
|
|
10
|
-
export default function flyToViewport(startProps, endProps, t,
|
|
11
|
-
const viewport = {};
|
|
10
|
+
export default function flyToViewport(startProps, endProps, t, options) {
|
|
12
11
|
const {
|
|
13
12
|
startZoom,
|
|
14
13
|
startCenterXY,
|
|
@@ -19,9 +18,11 @@ export default function flyToViewport(startProps, endProps, t, opts = {}) {
|
|
|
19
18
|
rho,
|
|
20
19
|
rho2,
|
|
21
20
|
r0
|
|
22
|
-
} = getFlyToTransitionParams(startProps, endProps,
|
|
21
|
+
} = getFlyToTransitionParams(startProps, endProps, options);
|
|
23
22
|
|
|
24
23
|
if (u1 < EPSILON) {
|
|
24
|
+
const viewport = {};
|
|
25
|
+
|
|
25
26
|
for (const key of VIEWPORT_TRANSITION_PROPS) {
|
|
26
27
|
const startValue = startProps[key];
|
|
27
28
|
const endValue = endProps[key];
|
|
@@ -39,13 +40,16 @@ export default function flyToViewport(startProps, endProps, t, opts = {}) {
|
|
|
39
40
|
const newCenterWorld = vec2.scale([], uDelta, u);
|
|
40
41
|
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
|
|
41
42
|
const newCenter = worldToLngLat(newCenterWorld);
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
43
|
+
return {
|
|
44
|
+
longitude: newCenter[0],
|
|
45
|
+
latitude: newCenter[1],
|
|
46
|
+
zoom: newZoom
|
|
47
|
+
};
|
|
46
48
|
}
|
|
47
|
-
export function getFlyToDuration(startProps, endProps,
|
|
48
|
-
opts =
|
|
49
|
+
export function getFlyToDuration(startProps, endProps, options) {
|
|
50
|
+
const opts = { ...DEFAULT_OPTS,
|
|
51
|
+
...options
|
|
52
|
+
};
|
|
49
53
|
const {
|
|
50
54
|
screenSpeed,
|
|
51
55
|
speed,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fly-to-viewport.
|
|
1
|
+
{"version":3,"sources":["../../src/fly-to-viewport.ts"],"names":["lerp","scaleToZoom","zoomToScale","lngLatToWorld","worldToLngLat","vec2","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","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,SAAQA,IAAR,QAAmB,cAAnB;AACA,SAAQC,WAAR,EAAqBC,WAArB,EAAkCC,aAAlC,EAAiDC,aAAjD,QAAqE,sBAArE;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAEA,MAAMC,OAAO,GAAG,IAAhB;AACA,MAAMC,yBAAyB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,MAA1B,CAAlC;AACA,MAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,KADY;AAEnBC,EAAAA,KAAK,EAAE;AAFY,CAArB;AAwBA,eAAe,SAASC,aAAT,CACbC,UADa,EAEbC,QAFa,EAGbC,CAHa,EAIbC,OAJa,EAKE;AAGf,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,aAAZ;AAA2BC,IAAAA,MAA3B;AAAmCC,IAAAA,EAAnC;AAAuCC,IAAAA,EAAvC;AAA2CC,IAAAA,CAA3C;AAA8CC,IAAAA,GAA9C;AAAmDC,IAAAA,IAAnD;AAAyDC,IAAAA;AAAzD,MAA+DC,wBAAwB,CAC3Fb,UAD2F,EAE3FC,QAF2F,EAG3FE,OAH2F,CAA7F;;AAOA,MAAIK,EAAE,GAAGd,OAAT,EAAkB;AAChB,UAAMoB,QAAQ,GAAG,EAAjB;;AACA,SAAK,MAAM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AAUF,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,QAAM/C,CAAC,GAAG,CAACkD,EAAE,GAAG/C,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;AAA6D+C,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 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/get-bounds.
|
|
1
|
+
{"version":3,"sources":["../../src/get-bounds.ts"],"names":["worldToLngLat","vec2","transformVector","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","lerp","result"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,sBAA5B;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,SAAQC,eAAR,QAA8B,cAA9B;AAGA,MAAMC,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;AAOA,eAAe,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,CA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F,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,GAAG/B,IAAI,CAACgC,IAAL,CAAU,EAAV,EAAcN,MAAd,EAAsBC,MAAtB,EAA8BG,CAA9B,CAAd;AAEA,QAAMG,MAAM,GAAGlC,aAAa,CAACgC,KAAD,CAA5B;AACAE,EAAAA,MAAM,CAAC,CAAD,CAAN,GAAYrB,OAAZ;AACA,SAAOqB,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"}
|
package/dist/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
1
|
+
{"version":3,"sources":["../../src/index.ts"],"names":["default","WebMercatorViewport","getBounds","fitBounds","normalizeViewportProps","flyToViewport","getFlyToDuration","lngLatToWorld","worldToLngLat","worldToPixels","pixelsToWorld","zoomToScale","scaleToZoom","altitudeToFovy","fovyToAltitude","getMeterZoom","getDistanceScales","addMetersToLngLat","getViewMatrix","getProjectionMatrix","getProjectionParameters"],"mappings":"AACA,SAAQA,OAAR,QAAsB,yBAAtB;AACA,SAAQA,OAAO,IAAIC,mBAAnB,QAA6C,yBAA7C;AAEA,SAAQD,OAAO,IAAIE,SAAnB,QAAmC,cAAnC;AACA,SAAQF,OAAO,IAAIG,SAAnB,QAAmC,cAAnC;AACA,SAAQH,OAAO,IAAII,sBAAnB,QAAgD,4BAAhD;AACA,SAAQJ,OAAO,IAAIK,aAAnB,EAAkCC,gBAAlC,QAAyD,mBAAzD;AAEA,SACEC,aADF,EAEEC,aAFF,EAGEC,aAHF,EAIEC,aAJF,EAKEC,WALF,EAMEC,WANF,EAOEC,cAPF,EAQEC,cARF,EASEC,YATF,EAUEC,iBAVF,EAWEC,iBAXF,EAYEC,aAZF,EAaEC,mBAbF,EAcEC,uBAdF,QAeO,sBAfP","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 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"],"file":"index.js"}
|
package/dist/esm/math-utils.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { transformMat4, scale } from 'gl-matrix/vec4';
|
|
2
2
|
export function createMat4() {
|
|
3
3
|
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
4
4
|
}
|
|
5
5
|
export function transformVector(matrix, vector) {
|
|
6
|
-
const result =
|
|
7
|
-
|
|
6
|
+
const result = transformMat4([], vector, matrix);
|
|
7
|
+
scale(result, result, 1 / result[3]);
|
|
8
8
|
return result;
|
|
9
9
|
}
|
|
10
10
|
export function mod(value, divisor) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math-utils.
|
|
1
|
+
{"version":3,"sources":["../../src/math-utils.ts"],"names":["transformMat4","scale","createMat4","transformVector","matrix","vector","result","mod","value","divisor","modulus","lerp","start","end","step","ieLog2","x","Math","log","LOG2E","log2"],"mappings":"AAAA,SAAQA,aAAR,EAAuBC,KAAvB,QAAmC,gBAAnC;AAGA,OAAO,SAASC,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;AAGD,OAAO,SAASC,eAAT,CAAyBC,MAAzB,EAAiCC,MAAjC,EAAyC;AAC9C,QAAMC,MAAM,GAAGN,aAAa,CAAC,EAAD,EAAKK,MAAL,EAAaD,MAAb,CAA5B;AACAH,EAAAA,KAAK,CAACK,MAAD,EAASA,MAAT,EAAiB,IAAIA,MAAM,CAAC,CAAD,CAA3B,CAAL;AACA,SAAOA,MAAP;AACD;AAED,OAAO,SAASC,GAAT,CAAaC,KAAb,EAA4BC,OAA5B,EAAqD;AAC1D,QAAMC,OAAO,GAAGF,KAAK,GAAGC,OAAxB;AACA,SAAOC,OAAO,GAAG,CAAV,GAAcD,OAAO,GAAGC,OAAxB,GAAkCA,OAAzC;AACD;AAED,OAAO,SAASC,IAAT,CAAcC,KAAd,EAA6BC,GAA7B,EAA0CC,IAA1C,EAAgE;AACrE,SAAOA,IAAI,GAAGD,GAAP,GAAa,CAAC,IAAIC,IAAL,IAAaF,KAAjC;AACD;;AAED,SAASG,MAAT,CAAgBC,CAAhB,EAAmC;AACjC,SAAOC,IAAI,CAACC,GAAL,CAASF,CAAT,IAAcC,IAAI,CAACE,KAA1B;AACD;;AAED,OAAO,MAAMC,IAAI,GAAGH,IAAI,CAACG,IAAL,IAAaL,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, vector) {\n const result = transformMat4([], 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\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"}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { worldToLngLat } from './web-mercator-utils';
|
|
2
2
|
import { mod, log2 } from './math-utils';
|
|
3
|
-
const
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
const TILE_SIZE = 512;
|
|
4
|
+
export default function normalizeViewportProps(props) {
|
|
5
|
+
const {
|
|
6
|
+
width,
|
|
7
|
+
height,
|
|
8
|
+
pitch = 0
|
|
9
|
+
} = props;
|
|
10
|
+
let {
|
|
11
|
+
longitude,
|
|
12
|
+
latitude,
|
|
13
|
+
zoom,
|
|
14
|
+
bearing = 0
|
|
15
|
+
} = props;
|
|
16
|
+
|
|
14
17
|
if (longitude < -180 || longitude > 180) {
|
|
15
18
|
longitude = mod(longitude + 180, 360) - 180;
|
|
16
19
|
}
|
|
@@ -19,38 +22,24 @@ export default function normalizeViewportProps({
|
|
|
19
22
|
bearing = mod(bearing + 180, 360) - 180;
|
|
20
23
|
}
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
width,
|
|
24
|
-
height,
|
|
25
|
-
longitude,
|
|
26
|
-
latitude,
|
|
27
|
-
zoom
|
|
28
|
-
});
|
|
29
|
-
let topY = flatViewport.project([longitude, MAX_LATITUDE])[1];
|
|
30
|
-
let bottomY = flatViewport.project([longitude, MIN_LATITUDE])[1];
|
|
31
|
-
let shiftY = 0;
|
|
25
|
+
const minZoom = log2(height / TILE_SIZE);
|
|
32
26
|
|
|
33
|
-
if (
|
|
34
|
-
zoom
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
latitude,
|
|
40
|
-
zoom
|
|
41
|
-
});
|
|
42
|
-
topY = flatViewport.project([longitude, MAX_LATITUDE])[1];
|
|
43
|
-
bottomY = flatViewport.project([longitude, MIN_LATITUDE])[1];
|
|
44
|
-
}
|
|
27
|
+
if (zoom <= minZoom) {
|
|
28
|
+
zoom = minZoom;
|
|
29
|
+
latitude = 0;
|
|
30
|
+
} else {
|
|
31
|
+
const halfHeightPixels = height / 2 / Math.pow(2, zoom);
|
|
32
|
+
const minLatitude = worldToLngLat([0, halfHeightPixels])[1];
|
|
45
33
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
34
|
+
if (latitude < minLatitude) {
|
|
35
|
+
latitude = minLatitude;
|
|
36
|
+
} else {
|
|
37
|
+
const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];
|
|
51
38
|
|
|
52
|
-
|
|
53
|
-
|
|
39
|
+
if (latitude > maxLatitude) {
|
|
40
|
+
latitude = maxLatitude;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
54
43
|
}
|
|
55
44
|
|
|
56
45
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/normalize-viewport-props.
|
|
1
|
+
{"version":3,"sources":["../../src/normalize-viewport-props.ts"],"names":["worldToLngLat","mod","log2","TILE_SIZE","normalizeViewportProps","props","width","height","pitch","longitude","latitude","zoom","bearing","minZoom","halfHeightPixels","Math","pow","minLatitude","maxLatitude"],"mappings":"AAAA,SAAQA,aAAR,QAA4B,sBAA5B;AACA,SAAQC,GAAR,EAAaC,IAAb,QAAwB,cAAxB;AAGA,MAAMC,SAAS,GAAG,GAAlB;AAkBA,eAAe,SAASC,sBAAT,CAAgCC,KAAhC,EAAqE;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,GAAGQ,WAAX;AACD;AACF;AACF;;AAED,SAAO;AAACZ,IAAAA,KAAD;AAAQC,IAAAA,MAAR;AAAgBE,IAAAA,SAAhB;AAA2BC,IAAAA,QAA3B;AAAqCC,IAAAA,IAArC;AAA2CH,IAAAA,KAA3C;AAAkDI,IAAAA;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 */\ntype 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"}
|
|
@@ -16,7 +16,8 @@ export function zoomToScale(zoom) {
|
|
|
16
16
|
export function scaleToZoom(scale) {
|
|
17
17
|
return log2(scale);
|
|
18
18
|
}
|
|
19
|
-
export function lngLatToWorld(
|
|
19
|
+
export function lngLatToWorld(lngLat) {
|
|
20
|
+
const [lng, lat] = lngLat;
|
|
20
21
|
assert(Number.isFinite(lng));
|
|
21
22
|
assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, 'invalid latitude');
|
|
22
23
|
const lambda2 = lng * DEGREES_TO_RADIANS;
|
|
@@ -25,34 +26,38 @@ export function lngLatToWorld([lng, lat]) {
|
|
|
25
26
|
const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
|
|
26
27
|
return [x, y];
|
|
27
28
|
}
|
|
28
|
-
export function worldToLngLat(
|
|
29
|
+
export function worldToLngLat(xy) {
|
|
30
|
+
const [x, y] = xy;
|
|
29
31
|
const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
|
|
30
32
|
const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
|
|
31
33
|
return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
|
|
32
34
|
}
|
|
33
|
-
export function getMeterZoom({
|
|
34
|
-
|
|
35
|
-
|
|
35
|
+
export function getMeterZoom(options) {
|
|
36
|
+
const {
|
|
37
|
+
latitude
|
|
38
|
+
} = options;
|
|
36
39
|
assert(Number.isFinite(latitude));
|
|
37
40
|
const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
|
|
38
41
|
return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;
|
|
39
42
|
}
|
|
40
|
-
export function getDistanceScales({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
43
|
+
export function getDistanceScales(options) {
|
|
44
|
+
const {
|
|
45
|
+
latitude,
|
|
46
|
+
longitude,
|
|
47
|
+
highPrecision = false
|
|
48
|
+
} = options;
|
|
45
49
|
assert(Number.isFinite(latitude) && Number.isFinite(longitude));
|
|
46
|
-
const result = {};
|
|
47
50
|
const worldSize = TILE_SIZE;
|
|
48
51
|
const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
|
|
49
52
|
const unitsPerDegreeX = worldSize / 360;
|
|
50
53
|
const unitsPerDegreeY = unitsPerDegreeX / latCosine;
|
|
51
54
|
const altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;
|
|
52
|
-
result
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
55
|
+
const result = {
|
|
56
|
+
unitsPerMeter: [altUnitsPerMeter, altUnitsPerMeter, altUnitsPerMeter],
|
|
57
|
+
metersPerUnit: [1 / altUnitsPerMeter, 1 / altUnitsPerMeter, 1 / altUnitsPerMeter],
|
|
58
|
+
unitsPerDegree: [unitsPerDegreeX, unitsPerDegreeY, altUnitsPerMeter],
|
|
59
|
+
degreesPerUnit: [1 / unitsPerDegreeX, 1 / unitsPerDegreeY, 1 / altUnitsPerMeter]
|
|
60
|
+
};
|
|
56
61
|
|
|
57
62
|
if (highPrecision) {
|
|
58
63
|
const latCosine2 = DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS) / latCosine;
|
|
@@ -83,20 +88,21 @@ export function addMetersToLngLat(lngLatZ, xyz) {
|
|
|
83
88
|
const newZ = (z0 || 0) + (z || 0);
|
|
84
89
|
return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;
|
|
85
90
|
}
|
|
86
|
-
export function getViewMatrix({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
91
|
+
export function getViewMatrix(options) {
|
|
92
|
+
const {
|
|
93
|
+
height,
|
|
94
|
+
pitch,
|
|
95
|
+
bearing,
|
|
96
|
+
altitude,
|
|
97
|
+
scale,
|
|
98
|
+
center = null
|
|
99
|
+
} = options;
|
|
94
100
|
const vm = createMat4();
|
|
95
101
|
mat4.translate(vm, vm, [0, 0, -altitude]);
|
|
96
102
|
mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
|
|
97
103
|
mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
|
|
98
|
-
scale
|
|
99
|
-
mat4.scale(vm, vm, [
|
|
104
|
+
const relativeScale = scale / height;
|
|
105
|
+
mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);
|
|
100
106
|
|
|
101
107
|
if (center) {
|
|
102
108
|
mat4.translate(vm, vm, vec3.negate([], center));
|
|
@@ -104,15 +110,19 @@ export function getViewMatrix({
|
|
|
104
110
|
|
|
105
111
|
return vm;
|
|
106
112
|
}
|
|
107
|
-
export function getProjectionParameters({
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
113
|
+
export function getProjectionParameters(options) {
|
|
114
|
+
const {
|
|
115
|
+
width,
|
|
116
|
+
height,
|
|
117
|
+
altitude,
|
|
118
|
+
pitch = 0,
|
|
119
|
+
nearZMultiplier = 1,
|
|
120
|
+
farZMultiplier = 1
|
|
121
|
+
} = options;
|
|
122
|
+
let {
|
|
123
|
+
fovy = altitudeToFovy(DEFAULT_ALTITUDE)
|
|
124
|
+
} = options;
|
|
125
|
+
|
|
116
126
|
if (altitude !== undefined) {
|
|
117
127
|
fovy = altitudeToFovy(altitude);
|
|
118
128
|
}
|
|
@@ -130,29 +140,13 @@ export function getProjectionParameters({
|
|
|
130
140
|
far: farZ * farZMultiplier
|
|
131
141
|
};
|
|
132
142
|
}
|
|
133
|
-
export function getProjectionMatrix({
|
|
134
|
-
width,
|
|
135
|
-
height,
|
|
136
|
-
pitch,
|
|
137
|
-
altitude,
|
|
138
|
-
fovy,
|
|
139
|
-
nearZMultiplier,
|
|
140
|
-
farZMultiplier
|
|
141
|
-
}) {
|
|
143
|
+
export function getProjectionMatrix(options) {
|
|
142
144
|
const {
|
|
143
145
|
fov,
|
|
144
146
|
aspect,
|
|
145
147
|
near,
|
|
146
148
|
far
|
|
147
|
-
} = getProjectionParameters(
|
|
148
|
-
width,
|
|
149
|
-
height,
|
|
150
|
-
altitude,
|
|
151
|
-
fovy,
|
|
152
|
-
pitch,
|
|
153
|
-
nearZMultiplier,
|
|
154
|
-
farZMultiplier
|
|
155
|
-
});
|
|
149
|
+
} = getProjectionParameters(options);
|
|
156
150
|
const projectionMatrix = mat4.perspective([], fov, aspect, near, far);
|
|
157
151
|
return projectionMatrix;
|
|
158
152
|
}
|