@math.gl/web-mercator 3.5.6 → 3.6.0-alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assert.d.ts +2 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +8 -0
- package/dist/es5/assert.js.map +1 -1
- package/dist/es5/fit-bounds.js +33 -37
- package/dist/es5/fit-bounds.js.map +1 -1
- package/dist/es5/fly-to-viewport.js +23 -16
- package/dist/es5/fly-to-viewport.js.map +1 -1
- package/dist/es5/get-bounds.js +1 -1
- package/dist/es5/get-bounds.js.map +1 -1
- package/dist/es5/index.js +6 -0
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/math-utils.js +8 -9
- package/dist/es5/math-utils.js.map +1 -1
- package/dist/es5/normalize-viewport-props.js +10 -10
- package/dist/es5/normalize-viewport-props.js.map +1 -1
- package/dist/es5/web-mercator-utils.js +47 -61
- package/dist/es5/web-mercator-utils.js.map +1 -1
- package/dist/es5/web-mercator-viewport.js +69 -51
- package/dist/es5/web-mercator-viewport.js.map +1 -1
- package/dist/esm/assert.js.map +1 -1
- package/dist/esm/fit-bounds.js +29 -34
- package/dist/esm/fit-bounds.js.map +1 -1
- package/dist/esm/fly-to-viewport.js +13 -9
- package/dist/esm/fly-to-viewport.js.map +1 -1
- package/dist/esm/get-bounds.js +1 -1
- package/dist/esm/get-bounds.js.map +1 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math-utils.js +6 -3
- package/dist/esm/math-utils.js.map +1 -1
- package/dist/esm/normalize-viewport-props.js +13 -9
- package/dist/esm/normalize-viewport-props.js.map +1 -1
- package/dist/esm/web-mercator-utils.js +47 -52
- package/dist/esm/web-mercator-utils.js.map +1 -1
- package/dist/esm/web-mercator-viewport.js +76 -34
- package/dist/esm/web-mercator-viewport.js.map +1 -1
- package/dist/fit-bounds.d.ts +50 -0
- package/dist/fit-bounds.d.ts.map +1 -0
- package/dist/fit-bounds.js +63 -0
- package/dist/fly-to-viewport.d.ts +19 -0
- package/dist/fly-to-viewport.d.ts.map +1 -0
- package/dist/fly-to-viewport.js +87 -0
- package/dist/get-bounds.d.ts +3 -0
- package/dist/get-bounds.d.ts.map +1 -0
- package/dist/get-bounds.js +51 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/math-utils.d.ts +7 -0
- package/dist/math-utils.d.ts.map +1 -0
- package/dist/math-utils.js +26 -0
- package/dist/normalize-viewport-props.d.ts +16 -0
- package/dist/normalize-viewport-props.d.ts.map +1 -0
- package/dist/normalize-viewport-props.js +41 -0
- package/dist/{es5/web-mercator-utils.d.ts → web-mercator-utils.d.ts} +78 -94
- package/dist/web-mercator-utils.d.ts.map +1 -0
- package/dist/web-mercator-utils.js +290 -0
- package/dist/web-mercator-viewport.d.ts +182 -0
- package/dist/web-mercator-viewport.d.ts.map +1 -0
- package/dist/web-mercator-viewport.js +281 -0
- package/package.json +4 -4
- package/src/{assert.js → assert.ts} +1 -1
- package/src/fit-bounds.ts +127 -0
- package/src/{fly-to-viewport.js → fly-to-viewport.ts} +52 -14
- package/src/{get-bounds.js → get-bounds.ts} +7 -5
- package/src/{index.js → index.ts} +5 -0
- package/src/math-utils.ts +32 -0
- package/src/{normalize-viewport-props.js → normalize-viewport-props.ts} +19 -10
- package/src/{web-mercator-utils.js → web-mercator-utils.ts} +186 -76
- package/src/web-mercator-viewport.ts +415 -0
- package/dist/es5/fit-bounds.d.ts +0 -64
- package/dist/es5/fly-to-viewport.d.ts +0 -31
- package/dist/es5/get-bounds.d.ts +0 -3
- package/dist/es5/index.d.ts +0 -23
- package/dist/es5/normalize-viewport-props.d.ts +0 -16
- package/dist/es5/web-mercator-viewport.d.ts +0 -187
- package/dist/esm/fit-bounds.d.ts +0 -64
- package/dist/esm/fly-to-viewport.d.ts +0 -31
- package/dist/esm/get-bounds.d.ts +0 -3
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/normalize-viewport-props.d.ts +0 -16
- package/dist/esm/web-mercator-utils.d.ts +0 -189
- package/dist/esm/web-mercator-viewport.d.ts +0 -187
- package/src/fit-bounds.d.ts +0 -64
- package/src/fit-bounds.js +0 -84
- package/src/fly-to-viewport.d.ts +0 -31
- package/src/get-bounds.d.ts +0 -3
- package/src/index.d.ts +0 -23
- package/src/math-utils.js +0 -28
- package/src/normalize-viewport-props.d.ts +0 -16
- package/src/web-mercator-utils.d.ts +0 -189
- package/src/web-mercator-viewport.d.ts +0 -187
- package/src/web-mercator-viewport.js +0 -262
package/dist/esm/fit-bounds.js
CHANGED
|
@@ -1,38 +1,19 @@
|
|
|
1
|
-
import WebMercatorViewport from './web-mercator-viewport';
|
|
2
1
|
import assert from './assert';
|
|
3
|
-
import { log2 } from './math-utils';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
bounds,
|
|
8
|
-
minExtent = 0,
|
|
9
|
-
maxZoom = 24,
|
|
10
|
-
padding = 0,
|
|
11
|
-
offset = [0, 0]
|
|
12
|
-
}) {
|
|
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
|
-
|
|
27
|
-
const viewport = new WebMercatorViewport({
|
|
2
|
+
import { log2, clamp } from './math-utils';
|
|
3
|
+
import { MAX_LATITUDE, lngLatToWorld, worldToLngLat } from './web-mercator-utils';
|
|
4
|
+
export default function fitBounds(options) {
|
|
5
|
+
const {
|
|
28
6
|
width,
|
|
29
7
|
height,
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
const
|
|
8
|
+
bounds,
|
|
9
|
+
minExtent = 0,
|
|
10
|
+
maxZoom = 24,
|
|
11
|
+
offset = [0, 0]
|
|
12
|
+
} = options;
|
|
13
|
+
const [[west, south], [east, north]] = bounds;
|
|
14
|
+
const padding = getPaddingObject(options.padding);
|
|
15
|
+
const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
16
|
+
const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
36
17
|
const size = [Math.max(Math.abs(se[0] - nw[0]), minExtent), Math.max(Math.abs(se[1] - nw[1]), minExtent)];
|
|
37
18
|
const targetSize = [width - padding.left - padding.right - Math.abs(offset[0]) * 2, height - padding.top - padding.bottom - Math.abs(offset[1]) * 2];
|
|
38
19
|
assert(targetSize[0] > 0 && targetSize[1] > 0);
|
|
@@ -41,8 +22,8 @@ export default function fitBounds({
|
|
|
41
22
|
const offsetX = (padding.right - padding.left) / 2 / scaleX;
|
|
42
23
|
const offsetY = (padding.bottom - padding.top) / 2 / scaleY;
|
|
43
24
|
const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
|
|
44
|
-
const centerLngLat =
|
|
45
|
-
const zoom = Math.min(maxZoom,
|
|
25
|
+
const centerLngLat = worldToLngLat(center);
|
|
26
|
+
const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));
|
|
46
27
|
assert(Number.isFinite(zoom));
|
|
47
28
|
return {
|
|
48
29
|
longitude: centerLngLat[0],
|
|
@@ -50,4 +31,18 @@ export default function fitBounds({
|
|
|
50
31
|
zoom
|
|
51
32
|
};
|
|
52
33
|
}
|
|
34
|
+
|
|
35
|
+
function getPaddingObject(padding = 0) {
|
|
36
|
+
if (typeof padding === 'number') {
|
|
37
|
+
return {
|
|
38
|
+
top: padding,
|
|
39
|
+
bottom: padding,
|
|
40
|
+
left: padding,
|
|
41
|
+
right: padding
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
assert(Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right));
|
|
46
|
+
return padding;
|
|
47
|
+
}
|
|
53
48
|
//# sourceMappingURL=fit-bounds.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/fit-bounds.
|
|
1
|
+
{"version":3,"sources":["../../src/fit-bounds.ts"],"names":["assert","log2","clamp","MAX_LATITUDE","lngLatToWorld","worldToLngLat","fitBounds","options","width","height","bounds","minExtent","maxZoom","offset","west","south","east","north","padding","getPaddingObject","nw","se","size","Math","max","abs","targetSize","left","right","top","bottom","scaleX","scaleY","offsetX","offsetY","center","centerLngLat","zoom","min","Number","isFinite","longitude","latitude"],"mappings":"AAAA,OAAOA,MAAP,MAAmB,UAAnB;AACA,SAAQC,IAAR,EAAcC,KAAd,QAA0B,cAA1B;AACA,SAAQC,YAAR,EAAsBC,aAAtB,EAAqCC,aAArC,QAAyD,sBAAzD;AAqDA,eAAe,SAASC,SAAT,CAAmBC,OAAnB,EAA6D;AAC1E,QAAM;AACJC,IAAAA,KADI;AAEJC,IAAAA,MAFI;AAGJC,IAAAA,MAHI;AAIJC,IAAAA,SAAS,GAAG,CAJR;AAKJC,IAAAA,OAAO,GAAG,EALN;AAMJC,IAAAA,MAAM,GAAG,CAAC,CAAD,EAAI,CAAJ;AANL,MAOFN,OAPJ;AASA,QAAM,CAAC,CAACO,IAAD,EAAOC,KAAP,CAAD,EAAgB,CAACC,IAAD,EAAOC,KAAP,CAAhB,IAAiCP,MAAvC;AACA,QAAMQ,OAAO,GAAGC,gBAAgB,CAACZ,OAAO,CAACW,OAAT,CAAhC;AAEA,QAAME,EAAE,GAAGhB,aAAa,CAAC,CAACU,IAAD,EAAOZ,KAAK,CAACe,KAAD,EAAQ,CAACd,YAAT,EAAuBA,YA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ACU,KAAxB,CAJE,CAAN;AAOA,SAAOV,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"}
|
|
@@ -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;AAIA,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;AAkBA,eAAe,SAASC,aAAT,CACbC,UADa,EAEbC,QAFa,EAGbC,CAHa,EAIbC,OAJa,EASb;AAGA,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,MAAMC,GAAX,IAAkBpB,yBAAlB,EAA6C;AAC3C,YAAMqB,UAAU,GAAGhB,UAAU,CAACe,GAAD,CAA7B;AACA,YAAME,QAAQ,GAAGhB,QAAQ,CAACc,GAAD,CAAzB;AACAD,MAAAA,QAAQ,CAACC,GAAD,CAAR,GAAgB3B,IAAI,CAAC4B,UAAD,EAAaC,QAAb,EAAuBf,CAAvB,CAApB;AACD;;AAED,WAAOY,QAAP;AACD;;AAED,QAAMI,CAAC,GA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A,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\nimport type {ViewportProps} from './normalize-viewport-props';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;\nconst DEFAULT_OPTS = {\n curve: 1.414,\n speed: 1.2\n // screenSpeed and maxDuration are used only if specified\n};\n\nexport type FlytoTransitionOptions = {\n curve?: number;\n speed?: number;\n screenSpeed?: number;\n maxDuration?: number;\n};\n\n/**\n * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.\n * It implements “Smooth and efficient zooming and panning.” algorithm by\n * \"Jarke J. van Wijk and Wim A.A. Nuij\"\n */\nexport default function flyToViewport(\n startProps: ViewportProps,\n endProps: ViewportProps,\n t: number,\n options?: FlytoTransitionOptions\n): {\n longitude: number;\n latitude: number;\n zoom: number;\n} {\n // Equations from above paper are referred where needed.\n\n const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(\n startProps,\n endProps,\n options\n );\n\n // If change in center is too small, do linear interpolaiton.\n if (u1 < EPSILON) {\n const viewport = {};\n for (const key of VIEWPORT_TRANSITION_PROPS) {\n const startValue = startProps[key];\n const endValue = endProps[key];\n viewport[key] = lerp(startValue, endValue, t);\n }\n // @ts-expect-error\n return viewport;\n }\n\n const s = t * S;\n\n const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);\n const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;\n\n const scaleIncrement = 1 / w; // Using w method for scaling.\n const newZoom = startZoom + scaleToZoom(scaleIncrement);\n\n const newCenterWorld = vec2.scale([], uDelta, u);\n vec2.add(newCenterWorld, newCenterWorld, startCenterXY);\n\n const newCenter = worldToLngLat(newCenterWorld);\n return {\n longitude: newCenter[0],\n latitude: newCenter[1],\n zoom: newZoom\n };\n}\n\n// returns transition duration in milliseconds\nexport function getFlyToDuration(\n startProps: ViewportProps,\n endProps: ViewportProps,\n options?: FlytoTransitionOptions\n): number {\n const opts = {...DEFAULT_OPTS, ...options};\n const {screenSpeed, speed, maxDuration} = opts;\n const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);\n const length = 1000 * S;\n let duration: number;\n if (Number.isFinite(screenSpeed)) {\n duration = length / (screenSpeed / rho);\n } else {\n duration = length / speed;\n }\n\n return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;\n}\n\n// Private Methods\n\n// Calculate all parameters that are static for given startProps and endProps\nfunction getFlyToTransitionParams(\n startProps: ViewportProps,\n endProps: ViewportProps,\n opts: FlytoTransitionOptions\n): {\n startZoom: number;\n startCenterXY: number[];\n uDelta: number[];\n w0: number;\n u1: number;\n S: number;\n rho: number;\n rho2: number;\n r0: number;\n r1: number;\n} {\n opts = Object.assign({}, DEFAULT_OPTS, opts);\n const rho = opts.curve;\n const startZoom = startProps.zoom;\n const startCenter = [startProps.longitude, startProps.latitude];\n const startScale = zoomToScale(startZoom);\n const endZoom = endProps.zoom;\n const endCenter = [endProps.longitude, endProps.latitude];\n const scale = zoomToScale(endZoom - startZoom);\n\n const startCenterXY = lngLatToWorld(startCenter);\n const endCenterXY = lngLatToWorld(endCenter);\n const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);\n\n const w0 = Math.max(startProps.width, startProps.height);\n const w1 = w0 / scale;\n const u1 = vec2.length(uDelta) * startScale;\n // u0 is treated as '0' in Eq (9).\n\n // If u1 is too small, will generate invalid number\n const _u1 = Math.max(u1, EPSILON);\n\n // Implement Equation (9) from above algorithm.\n const rho2 = rho * rho;\n const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);\n const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);\n const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);\n const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n const S = (r1 - r0) / rho;\n\n return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};\n}\n"],"file":"fly-to-viewport.js"}
|
package/dist/esm/get-bounds.js
CHANGED
|
@@ -39,7 +39,7 @@ function unprojectOnFarPlane(viewport, x, targetZ) {
|
|
|
39
39
|
const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
|
|
40
40
|
const coord = vec2.lerp([], coord0, coord1, t);
|
|
41
41
|
const result = worldToLngLat(coord);
|
|
42
|
-
result
|
|
42
|
+
result.push(targetZ);
|
|
43
43
|
return result;
|
|
44
44
|
}
|
|
45
45
|
//# sourceMappingURL=get-bounds.js.map
|
|
@@ -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","push"],"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,G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AAV,CAA1B,CAA9B;AACA,QAAMG,MAAM,GAAG1B,eAAe,CAACwB,uBAAD,EAA0B,CAACD,CAAD,EAAIlB,QAAQ,CAACG,MAAb,EAAqB,CAArB,EAAwB,CAAxB,CAA1B,CAA9B;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,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,CAACC,IAAP,CAAYtB,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: number[];\n let topRight: number[];\n\n const halfFov = viewport.fovy\n ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS\n : Math.atan(0.5 / viewport.altitude);\n const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;\n // The top plane is parallel to the ground if halfFov == angleToGround\n if (halfFov > angleToGround - 0.01) {\n // intersect with the far plane\n topLeft = unprojectOnFarPlane(viewport, 0, z);\n topRight = unprojectOnFarPlane(viewport, width, z);\n } else {\n // intersect with the top plane\n topLeft = unproject([0, 0], unprojectOps);\n topRight = unproject([width, 0], unprojectOps);\n }\n\n return [bottomLeft, bottomRight, topRight, topLeft];\n}\n\n/*\n * Find a point on the far clipping plane of the viewport\n * @param {WebMercatorViewport} viewport\n * @param {Number} x - projected x in screen space\n * @param {Number} targetZ - the elevation of the point in meters\n */\nfunction unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ: number): number[] {\n const {pixelUnprojectionMatrix} = viewport;\n const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);\n const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);\n\n const z = targetZ * viewport.distanceScales.unitsPerMeter[2];\n const t = (z - coord0[2]) / (coord1[2] - coord0[2]);\n const coord = vec2.lerp([], coord0, coord1, t);\n\n const result = worldToLngLat(coord);\n result.push(targetZ);\n return result;\n}\n"],"file":"get-bounds.js"}
|
package/dist/esm/index.js
CHANGED
|
@@ -4,5 +4,5 @@ export { default as getBounds } from './get-bounds';
|
|
|
4
4
|
export { default as fitBounds } from './fit-bounds';
|
|
5
5
|
export { default as normalizeViewportProps } from './normalize-viewport-props';
|
|
6
6
|
export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
|
|
7
|
-
export { lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
|
|
7
|
+
export { MAX_LATITUDE, lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
|
|
8
8
|
//# sourceMappingURL=index.js.map
|
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","MAX_LATITUDE","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,YADF,EAEEC,aAFF,EAGEC,aAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,WANF,EAOEC,WAPF,EAQEC,cARF,EASEC,cATF,EAUEC,YAVF,EAWEC,iBAXF,EAYEC,iBAZF,EAaEC,aAbF,EAcEC,mBAdF,EAeEC,uBAfF,QAgBO,sBAhBP","sourcesContent":["// Classic web-mercator-project\nexport {default} from './web-mercator-viewport';\nexport {default as WebMercatorViewport} from './web-mercator-viewport';\n\nexport {default as getBounds} from './get-bounds';\nexport {default as fitBounds} from './fit-bounds';\nexport {default as normalizeViewportProps} from './normalize-viewport-props';\nexport {default as flyToViewport, getFlyToDuration} from './fly-to-viewport';\n\nexport {\n MAX_LATITUDE,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n pixelsToWorld,\n zoomToScale,\n scaleToZoom,\n altitudeToFovy,\n fovyToAltitude,\n getMeterZoom,\n getDistanceScales,\n addMetersToLngLat,\n getViewMatrix,\n getProjectionMatrix,\n getProjectionParameters\n} from './web-mercator-utils';\n\n/** Types */\nexport type {FitBoundsOptions} from './fit-bounds';\nexport type {DistanceScales} from './web-mercator-utils';\n"],"file":"index.js"}
|
package/dist/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) {
|
|
@@ -14,6 +14,9 @@ export function mod(value, divisor) {
|
|
|
14
14
|
export function lerp(start, end, step) {
|
|
15
15
|
return step * end + (1 - step) * start;
|
|
16
16
|
}
|
|
17
|
+
export function clamp(x, min, max) {
|
|
18
|
+
return x < min ? min : x > max ? max : x;
|
|
19
|
+
}
|
|
17
20
|
|
|
18
21
|
function ieLog2(x) {
|
|
19
22
|
return Math.log(x) * Math.LOG2E;
|
|
@@ -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","clamp","x","min","max","ieLog2","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,EAA2CC,MAA3C,EAAuE;AAC5E,QAAMC,MAAM,GAAGN,aAAa,CAAC,EAAD,EAAiBK,MAAjB,EAAyBD,MAAzB,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,OAAO,SAASG,KAAT,CAAeC,CAAf,EAA0BC,GAA1B,EAAuCC,GAAvC,EAA4D;AACjE,SAAOF,CAAC,GAAGC,GAAJ,GAAUA,GAAV,GAAgBD,CAAC,GAAGE,GAAJ,GAAUA,GAAV,GAAgBF,CAAvC;AACD;;AAED,SAASG,MAAT,CAAgBH,CAAhB,EAAmC;AACjC,SAAOI,IAAI,CAACC,GAAL,CAASL,CAAT,IAAcI,IAAI,CAACE,KAA1B;AACD;;AAED,OAAO,MAAMC,IAAI,GAAGH,IAAI,CAACG,IAAL,IAAaJ,MAA1B","sourcesContent":["import {transformMat4, scale} from 'gl-matrix/vec4';\n\n// Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()\nexport function createMat4(): number[] {\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n}\n\n// Transforms a vec4 with a projection matrix\nexport function transformVector(matrix: number[], vector: number[]): number[] {\n const result = transformMat4([] as number[], vector, matrix);\n scale(result, result, 1 / result[3]);\n return result;\n}\n\nexport function mod(value: number, divisor: number): number {\n const modulus = value % divisor;\n return modulus < 0 ? divisor + modulus : modulus;\n}\n\nexport function lerp(start: number, end: number, step: number): number {\n return step * end + (1 - step) * start;\n}\n\nexport function clamp(x: number, min: number, max: number): number {\n return x < min ? min : x > max ? max : x;\n}\n\nfunction ieLog2(x: number): number {\n return Math.log(x) * Math.LOG2E;\n}\n// Handle missing log2 in IE 11\nexport const log2 = Math.log2 || ieLog2;\n"],"file":"math-utils.js"}
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import { worldToLngLat } from './web-mercator-utils';
|
|
2
2
|
import { mod, log2 } from './math-utils';
|
|
3
3
|
const TILE_SIZE = 512;
|
|
4
|
-
export default function normalizeViewportProps({
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
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
|
+
|
|
13
17
|
if (longitude < -180 || longitude > 180) {
|
|
14
18
|
longitude = mod(longitude + 180, 360) - 180;
|
|
15
19
|
}
|
|
@@ -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","halfHeight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WAAX;AACD,KAFD,MAEO;AACL,YAAMC,WAAW,GAAGlB,aAAa,CAAC,CAAC,CAAD,EAAIG,SAAS,GAAGW,gBAAhB,CAAD,CAAb,CAAiD,CAAjD,CAApB;;AACA,UAAIJ,QAAQ,GAAGQ,WAAf,EAA4B;AAC1BR,QAAAA,QAAQ,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 */\nexport type ViewportProps = {\n width: number;\n height: number;\n longitude: number;\n latitude: number;\n zoom: number;\n pitch?: number;\n bearing?: number;\n};\n\n/**\n * Apply mathematical constraints to viewport props\n * @param props\n */\n// eslint-disable-next-line complexity\nexport default function normalizeViewportProps(props: ViewportProps): ViewportProps {\n const {width, height, pitch = 0} = props;\n let {longitude, latitude, zoom, bearing = 0} = props;\n\n // Normalize degrees\n if (longitude < -180 || longitude > 180) {\n longitude = mod(longitude + 180, 360) - 180;\n }\n if (bearing < -180 || bearing > 180) {\n bearing = mod(bearing + 180, 360) - 180;\n }\n\n // Constrain zoom and shift center at low zoom levels\n const minZoom = log2(height / TILE_SIZE);\n if (zoom <= minZoom) {\n zoom = minZoom;\n latitude = 0;\n } else {\n // Eliminate white space above and below the map\n const halfHeightPixels = height / 2 / Math.pow(2, zoom);\n const minLatitude = worldToLngLat([0, halfHeightPixels])[1];\n if (latitude < minLatitude) {\n latitude = minLatitude;\n } else {\n const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];\n if (latitude > maxLatitude) {\n latitude = maxLatitude;\n }\n }\n }\n\n return {width, height, longitude, latitude, zoom, pitch, bearing};\n}\n"],"file":"normalize-viewport-props.js"}
|
|
@@ -9,6 +9,7 @@ const DEGREES_TO_RADIANS = PI / 180;
|
|
|
9
9
|
const RADIANS_TO_DEGREES = 180 / PI;
|
|
10
10
|
const TILE_SIZE = 512;
|
|
11
11
|
const EARTH_CIRCUMFERENCE = 40.03e6;
|
|
12
|
+
export const MAX_LATITUDE = 85.051129;
|
|
12
13
|
export const DEFAULT_ALTITUDE = 1.5;
|
|
13
14
|
export function zoomToScale(zoom) {
|
|
14
15
|
return Math.pow(2, zoom);
|
|
@@ -16,7 +17,8 @@ export function zoomToScale(zoom) {
|
|
|
16
17
|
export function scaleToZoom(scale) {
|
|
17
18
|
return log2(scale);
|
|
18
19
|
}
|
|
19
|
-
export function lngLatToWorld(
|
|
20
|
+
export function lngLatToWorld(lngLat) {
|
|
21
|
+
const [lng, lat] = lngLat;
|
|
20
22
|
assert(Number.isFinite(lng));
|
|
21
23
|
assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, 'invalid latitude');
|
|
22
24
|
const lambda2 = lng * DEGREES_TO_RADIANS;
|
|
@@ -25,34 +27,38 @@ export function lngLatToWorld([lng, lat]) {
|
|
|
25
27
|
const y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
|
|
26
28
|
return [x, y];
|
|
27
29
|
}
|
|
28
|
-
export function worldToLngLat(
|
|
30
|
+
export function worldToLngLat(xy) {
|
|
31
|
+
const [x, y] = xy;
|
|
29
32
|
const lambda2 = x / TILE_SIZE * (2 * PI) - PI;
|
|
30
33
|
const phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
|
|
31
34
|
return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
|
|
32
35
|
}
|
|
33
|
-
export function getMeterZoom({
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
export function getMeterZoom(options) {
|
|
37
|
+
const {
|
|
38
|
+
latitude
|
|
39
|
+
} = options;
|
|
36
40
|
assert(Number.isFinite(latitude));
|
|
37
41
|
const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
|
|
38
42
|
return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;
|
|
39
43
|
}
|
|
40
|
-
export function getDistanceScales({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
export function getDistanceScales(options) {
|
|
45
|
+
const {
|
|
46
|
+
latitude,
|
|
47
|
+
longitude,
|
|
48
|
+
highPrecision = false
|
|
49
|
+
} = options;
|
|
45
50
|
assert(Number.isFinite(latitude) && Number.isFinite(longitude));
|
|
46
|
-
const result = {};
|
|
47
51
|
const worldSize = TILE_SIZE;
|
|
48
52
|
const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
|
|
49
53
|
const unitsPerDegreeX = worldSize / 360;
|
|
50
54
|
const unitsPerDegreeY = unitsPerDegreeX / latCosine;
|
|
51
55
|
const altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;
|
|
52
|
-
result
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
+
const result = {
|
|
57
|
+
unitsPerMeter: [altUnitsPerMeter, altUnitsPerMeter, altUnitsPerMeter],
|
|
58
|
+
metersPerUnit: [1 / altUnitsPerMeter, 1 / altUnitsPerMeter, 1 / altUnitsPerMeter],
|
|
59
|
+
unitsPerDegree: [unitsPerDegreeX, unitsPerDegreeY, altUnitsPerMeter],
|
|
60
|
+
degreesPerUnit: [1 / unitsPerDegreeX, 1 / unitsPerDegreeY, 1 / altUnitsPerMeter]
|
|
61
|
+
};
|
|
56
62
|
|
|
57
63
|
if (highPrecision) {
|
|
58
64
|
const latCosine2 = DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS) / latCosine;
|
|
@@ -83,20 +89,21 @@ export function addMetersToLngLat(lngLatZ, xyz) {
|
|
|
83
89
|
const newZ = (z0 || 0) + (z || 0);
|
|
84
90
|
return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;
|
|
85
91
|
}
|
|
86
|
-
export function getViewMatrix({
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
92
|
+
export function getViewMatrix(options) {
|
|
93
|
+
const {
|
|
94
|
+
height,
|
|
95
|
+
pitch,
|
|
96
|
+
bearing,
|
|
97
|
+
altitude,
|
|
98
|
+
scale,
|
|
99
|
+
center
|
|
100
|
+
} = options;
|
|
94
101
|
const vm = createMat4();
|
|
95
102
|
mat4.translate(vm, vm, [0, 0, -altitude]);
|
|
96
103
|
mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
|
|
97
104
|
mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
|
|
98
|
-
scale
|
|
99
|
-
mat4.scale(vm, vm, [
|
|
105
|
+
const relativeScale = scale / height;
|
|
106
|
+
mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);
|
|
100
107
|
|
|
101
108
|
if (center) {
|
|
102
109
|
mat4.translate(vm, vm, vec3.negate([], center));
|
|
@@ -104,15 +111,19 @@ export function getViewMatrix({
|
|
|
104
111
|
|
|
105
112
|
return vm;
|
|
106
113
|
}
|
|
107
|
-
export function getProjectionParameters({
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
}
|
|
114
|
+
export function getProjectionParameters(options) {
|
|
115
|
+
const {
|
|
116
|
+
width,
|
|
117
|
+
height,
|
|
118
|
+
altitude,
|
|
119
|
+
pitch = 0,
|
|
120
|
+
nearZMultiplier = 1,
|
|
121
|
+
farZMultiplier = 1
|
|
122
|
+
} = options;
|
|
123
|
+
let {
|
|
124
|
+
fovy = altitudeToFovy(DEFAULT_ALTITUDE)
|
|
125
|
+
} = options;
|
|
126
|
+
|
|
116
127
|
if (altitude !== undefined) {
|
|
117
128
|
fovy = altitudeToFovy(altitude);
|
|
118
129
|
}
|
|
@@ -130,29 +141,13 @@ export function getProjectionParameters({
|
|
|
130
141
|
far: farZ * farZMultiplier
|
|
131
142
|
};
|
|
132
143
|
}
|
|
133
|
-
export function getProjectionMatrix({
|
|
134
|
-
width,
|
|
135
|
-
height,
|
|
136
|
-
pitch,
|
|
137
|
-
altitude,
|
|
138
|
-
fovy,
|
|
139
|
-
nearZMultiplier,
|
|
140
|
-
farZMultiplier
|
|
141
|
-
}) {
|
|
144
|
+
export function getProjectionMatrix(options) {
|
|
142
145
|
const {
|
|
143
146
|
fov,
|
|
144
147
|
aspect,
|
|
145
148
|
near,
|
|
146
149
|
far
|
|
147
|
-
} = getProjectionParameters(
|
|
148
|
-
width,
|
|
149
|
-
height,
|
|
150
|
-
altitude,
|
|
151
|
-
fovy,
|
|
152
|
-
pitch,
|
|
153
|
-
nearZMultiplier,
|
|
154
|
-
farZMultiplier
|
|
155
|
-
});
|
|
150
|
+
} = getProjectionParameters(options);
|
|
156
151
|
const projectionMatrix = mat4.perspective([], fov, aspect, near, far);
|
|
157
152
|
return projectionMatrix;
|
|
158
153
|
}
|