@math.gl/web-mercator 4.0.0 → 4.0.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 +0 -1
- package/dist/assert.js +6 -4
- package/dist/fit-bounds.d.ts +3 -4
- package/dist/fit-bounds.js +56 -41
- package/dist/fly-to-viewport.d.ts +2 -3
- package/dist/fly-to-viewport.js +74 -97
- package/dist/get-bounds.d.ts +1 -2
- package/dist/get-bounds.js +44 -37
- package/dist/index.cjs +19 -57
- package/dist/index.cjs.map +7 -0
- package/dist/index.d.ts +9 -10
- package/dist/index.js +2 -1
- package/dist/math-utils.d.ts +0 -1
- package/dist/math-utils.js +12 -12
- package/dist/normalize-viewport-props.d.ts +1 -2
- package/dist/normalize-viewport-props.js +35 -49
- package/dist/web-mercator-utils.d.ts +2 -3
- package/dist/web-mercator-utils.js +273 -154
- package/dist/web-mercator-viewport.d.ts +3 -4
- package/dist/web-mercator-viewport.js +265 -256
- package/package.json +4 -7
- package/dist/assert.d.ts.map +0 -1
- package/dist/assert.js.map +0 -1
- package/dist/fit-bounds.d.ts.map +0 -1
- package/dist/fit-bounds.js.map +0 -1
- package/dist/fly-to-viewport.d.ts.map +0 -1
- package/dist/fly-to-viewport.js.map +0 -1
- package/dist/get-bounds.d.ts.map +0 -1
- package/dist/get-bounds.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/math-utils.d.ts.map +0 -1
- package/dist/math-utils.js.map +0 -1
- package/dist/normalize-viewport-props.d.ts.map +0 -1
- package/dist/normalize-viewport-props.js.map +0 -1
- package/dist/web-mercator-utils.d.ts.map +0 -1
- package/dist/web-mercator-utils.js.map +0 -1
- package/dist/web-mercator-viewport.d.ts.map +0 -1
- package/dist/web-mercator-viewport.js.map +0 -1
package/dist/assert.d.ts
CHANGED
package/dist/assert.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
// Replacement for the external assert method to reduce bundle size
|
|
2
|
+
// Note: We don't use the second "message" argument in calling code,
|
|
3
|
+
// so no need to support it here
|
|
1
4
|
export function assert(condition, message) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
+
if (!condition) {
|
|
6
|
+
throw new Error(message || '@math.gl/web-mercator: assertion failed.');
|
|
7
|
+
}
|
|
5
8
|
}
|
|
6
|
-
//# sourceMappingURL=assert.js.map
|
package/dist/fit-bounds.d.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
* properties defining the padding.
|
|
10
10
|
* @param options.offset= - The center of the given bounds relative to the map's center,
|
|
11
11
|
*/
|
|
12
|
-
export
|
|
12
|
+
export type FitBoundsOptions = {
|
|
13
13
|
width: number;
|
|
14
14
|
height: number;
|
|
15
15
|
bounds: [[number, number], [number, number]];
|
|
@@ -25,13 +25,13 @@ export declare type FitBoundsOptions = {
|
|
|
25
25
|
* @property left - Padding from left in pixels to add to the given bounds
|
|
26
26
|
* @property right - Padding from right in pixels to add to the given bounds
|
|
27
27
|
*/
|
|
28
|
-
export
|
|
28
|
+
export type Padding = {
|
|
29
29
|
top: number;
|
|
30
30
|
bottom: number;
|
|
31
31
|
left: number;
|
|
32
32
|
right: number;
|
|
33
33
|
};
|
|
34
|
-
|
|
34
|
+
type ViewportProps = {
|
|
35
35
|
longitude: number;
|
|
36
36
|
latitude: number;
|
|
37
37
|
zoom: number;
|
|
@@ -47,4 +47,3 @@ declare type ViewportProps = {
|
|
|
47
47
|
*/
|
|
48
48
|
export declare function fitBounds(options: FitBoundsOptions): ViewportProps;
|
|
49
49
|
export {};
|
|
50
|
-
//# sourceMappingURL=fit-bounds.d.ts.map
|
package/dist/fit-bounds.js
CHANGED
|
@@ -1,48 +1,63 @@
|
|
|
1
1
|
import { assert } from "./assert.js";
|
|
2
2
|
import { log2, clamp } from "./math-utils.js";
|
|
3
3
|
import { MAX_LATITUDE, lngLatToWorld, worldToLngLat } from "./web-mercator-utils.js";
|
|
4
|
+
/**
|
|
5
|
+
* Returns map settings {latitude, longitude, zoom}
|
|
6
|
+
* that will contain the provided corners within the provided width.
|
|
7
|
+
*
|
|
8
|
+
* > _Note: Only supports non-perspective mode._
|
|
9
|
+
*
|
|
10
|
+
* @param options fit bounds parameters
|
|
11
|
+
* @returns - latitude, longitude and zoom
|
|
12
|
+
*/
|
|
4
13
|
export function fitBounds(options) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
bounds
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
zoom
|
|
32
|
-
};
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
function getPaddingObject(padding = 0) {
|
|
36
|
-
if (typeof padding === 'number') {
|
|
14
|
+
const { width, height, bounds, minExtent = 0, // 0.01 would be about 1000 meters (degree is ~110KM)
|
|
15
|
+
maxZoom = 24, // ~x4,000,000 => About 10 meter extents
|
|
16
|
+
offset = [0, 0] } = options;
|
|
17
|
+
const [[west, south], [east, north]] = bounds;
|
|
18
|
+
const padding = getPaddingObject(options.padding);
|
|
19
|
+
const nw = lngLatToWorld([west, clamp(north, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
20
|
+
const se = lngLatToWorld([east, clamp(south, -MAX_LATITUDE, MAX_LATITUDE)]);
|
|
21
|
+
// width/height on the Web Mercator plane
|
|
22
|
+
const size = [
|
|
23
|
+
Math.max(Math.abs(se[0] - nw[0]), minExtent),
|
|
24
|
+
Math.max(Math.abs(se[1] - nw[1]), minExtent)
|
|
25
|
+
];
|
|
26
|
+
const targetSize = [
|
|
27
|
+
width - padding.left - padding.right - Math.abs(offset[0]) * 2,
|
|
28
|
+
height - padding.top - padding.bottom - Math.abs(offset[1]) * 2
|
|
29
|
+
];
|
|
30
|
+
assert(targetSize[0] > 0 && targetSize[1] > 0);
|
|
31
|
+
// scale = screen pixels per unit on the Web Mercator plane
|
|
32
|
+
const scaleX = targetSize[0] / size[0];
|
|
33
|
+
const scaleY = targetSize[1] / size[1];
|
|
34
|
+
// Find how much we need to shift the center
|
|
35
|
+
const offsetX = (padding.right - padding.left) / 2 / scaleX;
|
|
36
|
+
const offsetY = (padding.top - padding.bottom) / 2 / scaleY;
|
|
37
|
+
const center = [(se[0] + nw[0]) / 2 + offsetX, (se[1] + nw[1]) / 2 + offsetY];
|
|
38
|
+
const centerLngLat = worldToLngLat(center);
|
|
39
|
+
const zoom = Math.min(maxZoom, log2(Math.abs(Math.min(scaleX, scaleY))));
|
|
40
|
+
assert(Number.isFinite(zoom));
|
|
37
41
|
return {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
right: padding
|
|
42
|
+
longitude: centerLngLat[0],
|
|
43
|
+
latitude: centerLngLat[1],
|
|
44
|
+
zoom
|
|
42
45
|
};
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
assert(Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right));
|
|
46
|
-
return padding;
|
|
47
46
|
}
|
|
48
|
-
|
|
47
|
+
// Helpers
|
|
48
|
+
function getPaddingObject(padding = 0) {
|
|
49
|
+
if (typeof padding === 'number') {
|
|
50
|
+
return {
|
|
51
|
+
top: padding,
|
|
52
|
+
bottom: padding,
|
|
53
|
+
left: padding,
|
|
54
|
+
right: padding
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
// Make sure all the required properties are set
|
|
58
|
+
assert(Number.isFinite(padding.top) &&
|
|
59
|
+
Number.isFinite(padding.bottom) &&
|
|
60
|
+
Number.isFinite(padding.left) &&
|
|
61
|
+
Number.isFinite(padding.right));
|
|
62
|
+
return padding;
|
|
63
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { ViewportProps } from
|
|
2
|
-
export
|
|
1
|
+
import type { ViewportProps } from "./normalize-viewport-props.js";
|
|
2
|
+
export type FlytoTransitionOptions = {
|
|
3
3
|
curve?: number;
|
|
4
4
|
speed?: number;
|
|
5
5
|
screenSpeed?: number;
|
|
@@ -16,4 +16,3 @@ export declare function flyToViewport(startProps: ViewportProps, endProps: Viewp
|
|
|
16
16
|
zoom: number;
|
|
17
17
|
};
|
|
18
18
|
export declare function getFlyToDuration(startProps: ViewportProps, endProps: ViewportProps, options?: FlytoTransitionOptions): number;
|
|
19
|
-
//# sourceMappingURL=fly-to-viewport.d.ts.map
|
package/dist/fly-to-viewport.js
CHANGED
|
@@ -4,108 +4,85 @@ import { vec2 } from '@math.gl/core';
|
|
|
4
4
|
const EPSILON = 0.01;
|
|
5
5
|
const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'];
|
|
6
6
|
const DEFAULT_OPTS = {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
curve: 1.414,
|
|
8
|
+
speed: 1.2
|
|
9
|
+
// screenSpeed and maxDuration are used only if specified
|
|
9
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.
|
|
13
|
+
* It implements “Smooth and efficient zooming and panning.” algorithm by
|
|
14
|
+
* "Jarke J. van Wijk and Wim A.A. Nuij"
|
|
15
|
+
*/
|
|
10
16
|
export function flyToViewport(startProps, endProps, t, options) {
|
|
11
|
-
|
|
12
|
-
startZoom,
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
const viewport = {};
|
|
25
|
-
|
|
26
|
-
for (const key of VIEWPORT_TRANSITION_PROPS) {
|
|
27
|
-
const startValue = startProps[key];
|
|
28
|
-
const endValue = endProps[key];
|
|
29
|
-
viewport[key] = lerp(startValue, endValue, t);
|
|
17
|
+
// Equations from above paper are referred where needed.
|
|
18
|
+
const { startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0 } = getFlyToTransitionParams(startProps, endProps, options);
|
|
19
|
+
// If change in center is too small, do linear interpolaiton.
|
|
20
|
+
if (u1 < EPSILON) {
|
|
21
|
+
const viewport = {};
|
|
22
|
+
for (const key of VIEWPORT_TRANSITION_PROPS) {
|
|
23
|
+
const startValue = startProps[key];
|
|
24
|
+
const endValue = endProps[key];
|
|
25
|
+
// @ts-ignore-error properties are populated dynamically
|
|
26
|
+
viewport[key] = lerp(startValue, endValue, t);
|
|
27
|
+
}
|
|
28
|
+
// @ts-expect-error properties are populated dynamically
|
|
29
|
+
return viewport;
|
|
30
30
|
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
longitude: newCenter[0],
|
|
45
|
-
latitude: newCenter[1],
|
|
46
|
-
zoom: newZoom
|
|
47
|
-
};
|
|
31
|
+
const s = t * S;
|
|
32
|
+
const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);
|
|
33
|
+
const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;
|
|
34
|
+
const scaleIncrement = 1 / w; // Using w method for scaling.
|
|
35
|
+
const newZoom = startZoom + scaleToZoom(scaleIncrement);
|
|
36
|
+
const newCenterWorld = vec2.scale([], uDelta, u);
|
|
37
|
+
vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
|
|
38
|
+
const newCenter = worldToLngLat(newCenterWorld);
|
|
39
|
+
return {
|
|
40
|
+
longitude: newCenter[0],
|
|
41
|
+
latitude: newCenter[1],
|
|
42
|
+
zoom: newZoom
|
|
43
|
+
};
|
|
48
44
|
}
|
|
45
|
+
// returns transition duration in milliseconds
|
|
49
46
|
export function getFlyToDuration(startProps, endProps, options) {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const length = 1000 * S;
|
|
63
|
-
let duration;
|
|
64
|
-
|
|
65
|
-
if (Number.isFinite(screenSpeed)) {
|
|
66
|
-
duration = length / (screenSpeed / rho);
|
|
67
|
-
} else {
|
|
68
|
-
duration = length / speed;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;
|
|
47
|
+
const opts = { ...DEFAULT_OPTS, ...options };
|
|
48
|
+
const { screenSpeed, speed, maxDuration } = opts;
|
|
49
|
+
const { S, rho } = getFlyToTransitionParams(startProps, endProps, opts);
|
|
50
|
+
const length = 1000 * S;
|
|
51
|
+
let duration;
|
|
52
|
+
if (Number.isFinite(screenSpeed)) {
|
|
53
|
+
duration = length / (screenSpeed / rho);
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
duration = length / speed;
|
|
57
|
+
}
|
|
58
|
+
return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;
|
|
72
59
|
}
|
|
73
|
-
|
|
60
|
+
// Private Methods
|
|
61
|
+
// Calculate all parameters that are static for given startProps and endProps
|
|
74
62
|
function getFlyToTransitionParams(startProps, endProps, opts) {
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
startZoom,
|
|
100
|
-
startCenterXY,
|
|
101
|
-
uDelta,
|
|
102
|
-
w0,
|
|
103
|
-
u1,
|
|
104
|
-
S,
|
|
105
|
-
rho,
|
|
106
|
-
rho2,
|
|
107
|
-
r0,
|
|
108
|
-
r1
|
|
109
|
-
};
|
|
63
|
+
opts = Object.assign({}, DEFAULT_OPTS, opts);
|
|
64
|
+
const rho = opts.curve;
|
|
65
|
+
const startZoom = startProps.zoom;
|
|
66
|
+
const startCenter = [startProps.longitude, startProps.latitude];
|
|
67
|
+
const startScale = zoomToScale(startZoom);
|
|
68
|
+
const endZoom = endProps.zoom;
|
|
69
|
+
const endCenter = [endProps.longitude, endProps.latitude];
|
|
70
|
+
const scale = zoomToScale(endZoom - startZoom);
|
|
71
|
+
const startCenterXY = lngLatToWorld(startCenter);
|
|
72
|
+
const endCenterXY = lngLatToWorld(endCenter);
|
|
73
|
+
const uDelta = vec2.sub([], endCenterXY, startCenterXY);
|
|
74
|
+
const w0 = Math.max(startProps.width, startProps.height);
|
|
75
|
+
const w1 = w0 / scale;
|
|
76
|
+
const u1 = vec2.length(uDelta) * startScale;
|
|
77
|
+
// u0 is treated as '0' in Eq (9).
|
|
78
|
+
// If u1 is too small, will generate invalid number
|
|
79
|
+
const _u1 = Math.max(u1, EPSILON);
|
|
80
|
+
// Implement Equation (9) from above algorithm.
|
|
81
|
+
const rho2 = rho * rho;
|
|
82
|
+
const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);
|
|
83
|
+
const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);
|
|
84
|
+
const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
|
|
85
|
+
const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
|
|
86
|
+
const S = (r1 - r0) / rho;
|
|
87
|
+
return { startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1 };
|
|
110
88
|
}
|
|
111
|
-
//# sourceMappingURL=fly-to-viewport.js.map
|
package/dist/get-bounds.d.ts
CHANGED
|
@@ -1,3 +1,2 @@
|
|
|
1
|
-
import type { WebMercatorViewport } from
|
|
1
|
+
import type { WebMercatorViewport } from "./web-mercator-viewport.js";
|
|
2
2
|
export declare function getBounds(viewport: WebMercatorViewport, z?: number): number[][];
|
|
3
|
-
//# sourceMappingURL=get-bounds.d.ts.map
|
package/dist/get-bounds.js
CHANGED
|
@@ -1,45 +1,52 @@
|
|
|
1
|
+
/* eslint-disable camelcase */
|
|
1
2
|
import { vec2 } from '@math.gl/core';
|
|
2
3
|
import { worldToLngLat } from "./web-mercator-utils.js";
|
|
3
4
|
import { transformVector } from "./math-utils.js";
|
|
4
5
|
const DEGREES_TO_RADIANS = Math.PI / 180;
|
|
6
|
+
/*
|
|
7
|
+
* Returns the quad at the intersection of the frustum and the given z plane
|
|
8
|
+
* @param {WebMercatorViewport} viewport
|
|
9
|
+
* @param {Number} z - elevation in meters
|
|
10
|
+
*/
|
|
5
11
|
export function getBounds(viewport, z = 0) {
|
|
6
|
-
|
|
7
|
-
width,
|
|
8
|
-
|
|
9
|
-
unproject
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
return [bottomLeft, bottomRight, topRight, topLeft];
|
|
12
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
13
|
+
const { width, height, unproject } = viewport;
|
|
14
|
+
const unprojectOps = { targetZ: z };
|
|
15
|
+
const bottomLeft = unproject([0, height], unprojectOps);
|
|
16
|
+
const bottomRight = unproject([width, height], unprojectOps);
|
|
17
|
+
let topLeft;
|
|
18
|
+
let topRight;
|
|
19
|
+
const halfFov = viewport.fovy
|
|
20
|
+
? 0.5 * viewport.fovy * DEGREES_TO_RADIANS
|
|
21
|
+
: Math.atan(0.5 / viewport.altitude);
|
|
22
|
+
const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;
|
|
23
|
+
// The top plane is parallel to the ground if halfFov == angleToGround
|
|
24
|
+
if (halfFov > angleToGround - 0.01) {
|
|
25
|
+
// intersect with the far plane
|
|
26
|
+
topLeft = unprojectOnFarPlane(viewport, 0, z);
|
|
27
|
+
topRight = unprojectOnFarPlane(viewport, width, z);
|
|
28
|
+
}
|
|
29
|
+
else {
|
|
30
|
+
// intersect with the top plane
|
|
31
|
+
topLeft = unproject([0, 0], unprojectOps);
|
|
32
|
+
topRight = unproject([width, 0], unprojectOps);
|
|
33
|
+
}
|
|
34
|
+
return [bottomLeft, bottomRight, topRight, topLeft];
|
|
30
35
|
}
|
|
31
|
-
|
|
36
|
+
/*
|
|
37
|
+
* Find a point on the far clipping plane of the viewport
|
|
38
|
+
* @param {WebMercatorViewport} viewport
|
|
39
|
+
* @param {Number} x - projected x in screen space
|
|
40
|
+
* @param {Number} targetZ - the elevation of the point in meters
|
|
41
|
+
*/
|
|
32
42
|
function unprojectOnFarPlane(viewport, x, targetZ) {
|
|
33
|
-
|
|
34
|
-
pixelUnprojectionMatrix
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
result.push(targetZ);
|
|
43
|
-
return result;
|
|
43
|
+
const { pixelUnprojectionMatrix } = viewport;
|
|
44
|
+
const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);
|
|
45
|
+
const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
|
|
46
|
+
const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
|
|
47
|
+
const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
|
|
48
|
+
const coord = vec2.lerp([], coord0, coord1, t);
|
|
49
|
+
const result = worldToLngLat(coord);
|
|
50
|
+
result.push(targetZ);
|
|
51
|
+
return result;
|
|
44
52
|
}
|
|
45
|
-
//# sourceMappingURL=get-bounds.js.map
|
package/dist/index.cjs
CHANGED
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
-
var __spreadValues = (a, b) => {
|
|
9
|
-
for (var prop in b || (b = {}))
|
|
10
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
-
__defNormalProp(a, prop, b[prop]);
|
|
12
|
-
if (__getOwnPropSymbols)
|
|
13
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
-
__defNormalProp(a, prop, b[prop]);
|
|
16
|
-
}
|
|
17
|
-
return a;
|
|
18
|
-
};
|
|
19
5
|
var __export = (target, all) => {
|
|
20
6
|
for (var name in all)
|
|
21
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -30,9 +16,9 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
30
16
|
};
|
|
31
17
|
var __toCommonJS = (mod2) => __copyProps(__defProp({}, "__esModule", { value: true }), mod2);
|
|
32
18
|
|
|
33
|
-
//
|
|
34
|
-
var
|
|
35
|
-
__export(
|
|
19
|
+
// dist/index.js
|
|
20
|
+
var dist_exports = {};
|
|
21
|
+
__export(dist_exports, {
|
|
36
22
|
MAX_LATITUDE: () => MAX_LATITUDE,
|
|
37
23
|
WebMercatorViewport: () => WebMercatorViewport,
|
|
38
24
|
addMetersToLngLat: () => addMetersToLngLat,
|
|
@@ -57,9 +43,9 @@ __export(src_exports, {
|
|
|
57
43
|
worldToPixels: () => worldToPixels,
|
|
58
44
|
zoomToScale: () => zoomToScale
|
|
59
45
|
});
|
|
60
|
-
module.exports = __toCommonJS(
|
|
46
|
+
module.exports = __toCommonJS(dist_exports);
|
|
61
47
|
|
|
62
|
-
//
|
|
48
|
+
// dist/math-utils.js
|
|
63
49
|
var import_core = require("@math.gl/core");
|
|
64
50
|
function createMat4() {
|
|
65
51
|
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
@@ -84,17 +70,17 @@ function ieLog2(x) {
|
|
|
84
70
|
}
|
|
85
71
|
var log2 = Math.log2 || ieLog2;
|
|
86
72
|
|
|
87
|
-
//
|
|
73
|
+
// dist/web-mercator-utils.js
|
|
88
74
|
var import_core2 = require("@math.gl/core");
|
|
89
75
|
|
|
90
|
-
//
|
|
76
|
+
// dist/assert.js
|
|
91
77
|
function assert(condition, message) {
|
|
92
78
|
if (!condition) {
|
|
93
79
|
throw new Error(message || "@math.gl/web-mercator: assertion failed.");
|
|
94
80
|
}
|
|
95
81
|
}
|
|
96
82
|
|
|
97
|
-
//
|
|
83
|
+
// dist/web-mercator-utils.js
|
|
98
84
|
var PI = Math.PI;
|
|
99
85
|
var PI_4 = PI / 4;
|
|
100
86
|
var DEGREES_TO_RADIANS = PI / 180;
|
|
@@ -195,17 +181,7 @@ function getViewMatrix(options) {
|
|
|
195
181
|
return vm;
|
|
196
182
|
}
|
|
197
183
|
function getProjectionParameters(options) {
|
|
198
|
-
const {
|
|
199
|
-
width,
|
|
200
|
-
height,
|
|
201
|
-
altitude,
|
|
202
|
-
pitch = 0,
|
|
203
|
-
offset,
|
|
204
|
-
center,
|
|
205
|
-
scale,
|
|
206
|
-
nearZMultiplier = 1,
|
|
207
|
-
farZMultiplier = 1
|
|
208
|
-
} = options;
|
|
184
|
+
const { width, height, altitude, pitch = 0, offset, center, scale, nearZMultiplier = 1, farZMultiplier = 1 } = options;
|
|
209
185
|
let { fovy = altitudeToFovy(DEFAULT_ALTITUDE) } = options;
|
|
210
186
|
if (altitude !== void 0) {
|
|
211
187
|
fovy = altitudeToFovy(altitude);
|
|
@@ -267,7 +243,7 @@ function pixelsToWorld(xyz, pixelUnprojectionMatrix, targetZ = 0) {
|
|
|
267
243
|
return import_core2.vec2.lerp([], coord0, coord1, t);
|
|
268
244
|
}
|
|
269
245
|
|
|
270
|
-
//
|
|
246
|
+
// dist/fit-bounds.js
|
|
271
247
|
function fitBounds(options) {
|
|
272
248
|
const {
|
|
273
249
|
width,
|
|
@@ -313,13 +289,11 @@ function getPaddingObject(padding = 0) {
|
|
|
313
289
|
right: padding
|
|
314
290
|
};
|
|
315
291
|
}
|
|
316
|
-
assert(
|
|
317
|
-
Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right)
|
|
318
|
-
);
|
|
292
|
+
assert(Number.isFinite(padding.top) && Number.isFinite(padding.bottom) && Number.isFinite(padding.left) && Number.isFinite(padding.right));
|
|
319
293
|
return padding;
|
|
320
294
|
}
|
|
321
295
|
|
|
322
|
-
//
|
|
296
|
+
// dist/get-bounds.js
|
|
323
297
|
var import_core3 = require("@math.gl/core");
|
|
324
298
|
var DEGREES_TO_RADIANS2 = Math.PI / 180;
|
|
325
299
|
function getBounds(viewport, z = 0) {
|
|
@@ -352,7 +326,7 @@ function unprojectOnFarPlane(viewport, x, targetZ) {
|
|
|
352
326
|
return result;
|
|
353
327
|
}
|
|
354
328
|
|
|
355
|
-
//
|
|
329
|
+
// dist/web-mercator-viewport.js
|
|
356
330
|
var import_core4 = require("@math.gl/core");
|
|
357
331
|
var WebMercatorViewport = class {
|
|
358
332
|
constructor(props = { width: 1, height: 1 }) {
|
|
@@ -398,16 +372,7 @@ var WebMercatorViewport = class {
|
|
|
398
372
|
altitude = null,
|
|
399
373
|
fovy = null
|
|
400
374
|
} = props;
|
|
401
|
-
const {
|
|
402
|
-
latitude = 0,
|
|
403
|
-
longitude = 0,
|
|
404
|
-
zoom = 0,
|
|
405
|
-
pitch = 0,
|
|
406
|
-
bearing = 0,
|
|
407
|
-
position = null,
|
|
408
|
-
nearZMultiplier = 0.02,
|
|
409
|
-
farZMultiplier = 1.01
|
|
410
|
-
} = props;
|
|
375
|
+
const { latitude = 0, longitude = 0, zoom = 0, pitch = 0, bearing = 0, position = null, nearZMultiplier = 0.02, farZMultiplier = 1.01 } = props;
|
|
411
376
|
width = width || 1;
|
|
412
377
|
height = height || 1;
|
|
413
378
|
if (fovy === null && altitude === null) {
|
|
@@ -514,7 +479,7 @@ var WebMercatorViewport = class {
|
|
|
514
479
|
}
|
|
515
480
|
};
|
|
516
481
|
|
|
517
|
-
//
|
|
482
|
+
// dist/normalize-viewport-props.js
|
|
518
483
|
var TILE_SIZE2 = 512;
|
|
519
484
|
function normalizeViewportProps(props) {
|
|
520
485
|
const { width, height, pitch = 0 } = props;
|
|
@@ -544,7 +509,7 @@ function normalizeViewportProps(props) {
|
|
|
544
509
|
return { width, height, longitude, latitude, zoom, pitch, bearing };
|
|
545
510
|
}
|
|
546
511
|
|
|
547
|
-
//
|
|
512
|
+
// dist/fly-to-viewport.js
|
|
548
513
|
var import_core5 = require("@math.gl/core");
|
|
549
514
|
var EPSILON = 0.01;
|
|
550
515
|
var VIEWPORT_TRANSITION_PROPS = ["longitude", "latitude", "zoom"];
|
|
@@ -553,11 +518,7 @@ var DEFAULT_OPTS = {
|
|
|
553
518
|
speed: 1.2
|
|
554
519
|
};
|
|
555
520
|
function flyToViewport(startProps, endProps, t, options) {
|
|
556
|
-
const { startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0 } = getFlyToTransitionParams(
|
|
557
|
-
startProps,
|
|
558
|
-
endProps,
|
|
559
|
-
options
|
|
560
|
-
);
|
|
521
|
+
const { startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0 } = getFlyToTransitionParams(startProps, endProps, options);
|
|
561
522
|
if (u1 < EPSILON) {
|
|
562
523
|
const viewport = {};
|
|
563
524
|
for (const key of VIEWPORT_TRANSITION_PROPS) {
|
|
@@ -582,7 +543,7 @@ function flyToViewport(startProps, endProps, t, options) {
|
|
|
582
543
|
};
|
|
583
544
|
}
|
|
584
545
|
function getFlyToDuration(startProps, endProps, options) {
|
|
585
|
-
const opts =
|
|
546
|
+
const opts = { ...DEFAULT_OPTS, ...options };
|
|
586
547
|
const { screenSpeed, speed, maxDuration } = opts;
|
|
587
548
|
const { S, rho } = getFlyToTransitionParams(startProps, endProps, opts);
|
|
588
549
|
const length = 1e3 * S;
|
|
@@ -618,3 +579,4 @@ function getFlyToTransitionParams(startProps, endProps, opts) {
|
|
|
618
579
|
const S = (r1 - r0) / rho;
|
|
619
580
|
return { startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1 };
|
|
620
581
|
}
|
|
582
|
+
//# sourceMappingURL=index.cjs.map
|