@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
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { worldToLngLat } from './web-mercator-utils';
|
|
2
|
+
import * as vec2 from 'gl-matrix/vec2';
|
|
3
|
+
import { transformVector } from './math-utils';
|
|
4
|
+
const DEGREES_TO_RADIANS = Math.PI / 180;
|
|
5
|
+
/*
|
|
6
|
+
* Returns the quad at the intersection of the frustum and the given z plane
|
|
7
|
+
* @param {WebMercatorViewport} viewport
|
|
8
|
+
* @param {Number} z - elevation in meters
|
|
9
|
+
*/
|
|
10
|
+
export default function getBounds(viewport, z = 0) {
|
|
11
|
+
// eslint-disable-next-line @typescript-eslint/unbound-method
|
|
12
|
+
const { width, height, unproject } = viewport;
|
|
13
|
+
const unprojectOps = { targetZ: z };
|
|
14
|
+
const bottomLeft = unproject([0, height], unprojectOps);
|
|
15
|
+
const bottomRight = unproject([width, height], unprojectOps);
|
|
16
|
+
let topLeft;
|
|
17
|
+
let topRight;
|
|
18
|
+
const halfFov = viewport.fovy
|
|
19
|
+
? 0.5 * viewport.fovy * DEGREES_TO_RADIANS
|
|
20
|
+
: Math.atan(0.5 / viewport.altitude);
|
|
21
|
+
const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;
|
|
22
|
+
// The top plane is parallel to the ground if halfFov == angleToGround
|
|
23
|
+
if (halfFov > angleToGround - 0.01) {
|
|
24
|
+
// intersect with the far plane
|
|
25
|
+
topLeft = unprojectOnFarPlane(viewport, 0, z);
|
|
26
|
+
topRight = unprojectOnFarPlane(viewport, width, z);
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
// intersect with the top plane
|
|
30
|
+
topLeft = unproject([0, 0], unprojectOps);
|
|
31
|
+
topRight = unproject([width, 0], unprojectOps);
|
|
32
|
+
}
|
|
33
|
+
return [bottomLeft, bottomRight, topRight, topLeft];
|
|
34
|
+
}
|
|
35
|
+
/*
|
|
36
|
+
* Find a point on the far clipping plane of the viewport
|
|
37
|
+
* @param {WebMercatorViewport} viewport
|
|
38
|
+
* @param {Number} x - projected x in screen space
|
|
39
|
+
* @param {Number} targetZ - the elevation of the point in meters
|
|
40
|
+
*/
|
|
41
|
+
function unprojectOnFarPlane(viewport, x, targetZ) {
|
|
42
|
+
const { pixelUnprojectionMatrix } = viewport;
|
|
43
|
+
const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);
|
|
44
|
+
const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
|
|
45
|
+
const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
|
|
46
|
+
const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
|
|
47
|
+
const coord = vec2.lerp([], coord0, coord1, t);
|
|
48
|
+
const result = worldToLngLat(coord);
|
|
49
|
+
result.push(targetZ);
|
|
50
|
+
return result;
|
|
51
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { default } from './web-mercator-viewport';
|
|
2
|
+
export { default as WebMercatorViewport } from './web-mercator-viewport';
|
|
3
|
+
export { default as getBounds } from './get-bounds';
|
|
4
|
+
export { default as fitBounds } from './fit-bounds';
|
|
5
|
+
export { default as normalizeViewportProps } from './normalize-viewport-props';
|
|
6
|
+
export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
|
|
7
|
+
export { MAX_LATITUDE, lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
|
|
8
|
+
/** Types */
|
|
9
|
+
export type { FitBoundsOptions } from './fit-bounds';
|
|
10
|
+
export type { DistanceScales } from './web-mercator-utils';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,OAAO,EAAC,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAC,OAAO,IAAI,mBAAmB,EAAC,MAAM,yBAAyB,CAAC;AAEvE,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,OAAO,IAAI,SAAS,EAAC,MAAM,cAAc,CAAC;AAClD,OAAO,EAAC,OAAO,IAAI,sBAAsB,EAAC,MAAM,4BAA4B,CAAC;AAC7E,OAAO,EAAC,OAAO,IAAI,aAAa,EAAE,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAE7E,OAAO,EACL,YAAY,EACZ,aAAa,EACb,aAAa,EACb,aAAa,EACb,aAAa,EACb,WAAW,EACX,WAAW,EACX,cAAc,EACd,cAAc,EACd,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,aAAa,EACb,mBAAmB,EACnB,uBAAuB,EACxB,MAAM,sBAAsB,CAAC;AAE9B,YAAY;AACZ,YAAY,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AACnD,YAAY,EAAC,cAAc,EAAC,MAAM,sBAAsB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Classic web-mercator-project
|
|
2
|
+
export { default } from './web-mercator-viewport';
|
|
3
|
+
export { default as WebMercatorViewport } from './web-mercator-viewport';
|
|
4
|
+
export { default as getBounds } from './get-bounds';
|
|
5
|
+
export { default as fitBounds } from './fit-bounds';
|
|
6
|
+
export { default as normalizeViewportProps } from './normalize-viewport-props';
|
|
7
|
+
export { default as flyToViewport, getFlyToDuration } from './fly-to-viewport';
|
|
8
|
+
export { MAX_LATITUDE, lngLatToWorld, worldToLngLat, worldToPixels, pixelsToWorld, zoomToScale, scaleToZoom, altitudeToFovy, fovyToAltitude, getMeterZoom, getDistanceScales, addMetersToLngLat, getViewMatrix, getProjectionMatrix, getProjectionParameters } from './web-mercator-utils';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare function createMat4(): number[];
|
|
2
|
+
export declare function transformVector(matrix: number[], vector: number[]): number[];
|
|
3
|
+
export declare function mod(value: number, divisor: number): number;
|
|
4
|
+
export declare function lerp(start: number, end: number, step: number): number;
|
|
5
|
+
export declare function clamp(x: number, min: number, max: number): number;
|
|
6
|
+
export declare const log2: (x: number) => number;
|
|
7
|
+
//# sourceMappingURL=math-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"math-utils.d.ts","sourceRoot":"","sources":["../src/math-utils.ts"],"names":[],"mappings":"AAGA,wBAAgB,UAAU,IAAI,MAAM,EAAE,CAErC;AAGD,wBAAgB,eAAe,CAAC,MAAM,EAAE,MAAM,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE,CAI5E;AAED,wBAAgB,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,MAAM,CAG1D;AAED,wBAAgB,IAAI,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAErE;AAED,wBAAgB,KAAK,CAAC,CAAC,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,CAEjE;AAMD,eAAO,MAAM,IAAI,uBAAsB,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { transformMat4, scale } from 'gl-matrix/vec4';
|
|
2
|
+
// Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()
|
|
3
|
+
export function createMat4() {
|
|
4
|
+
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
5
|
+
}
|
|
6
|
+
// Transforms a vec4 with a projection matrix
|
|
7
|
+
export function transformVector(matrix, vector) {
|
|
8
|
+
const result = transformMat4([], vector, matrix);
|
|
9
|
+
scale(result, result, 1 / result[3]);
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
export function mod(value, divisor) {
|
|
13
|
+
const modulus = value % divisor;
|
|
14
|
+
return modulus < 0 ? divisor + modulus : modulus;
|
|
15
|
+
}
|
|
16
|
+
export function lerp(start, end, step) {
|
|
17
|
+
return step * end + (1 - step) * start;
|
|
18
|
+
}
|
|
19
|
+
export function clamp(x, min, max) {
|
|
20
|
+
return x < min ? min : x > max ? max : x;
|
|
21
|
+
}
|
|
22
|
+
function ieLog2(x) {
|
|
23
|
+
return Math.log(x) * Math.LOG2E;
|
|
24
|
+
}
|
|
25
|
+
// Handle missing log2 in IE 11
|
|
26
|
+
export const log2 = Math.log2 || ieLog2;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/** Description of viewport */
|
|
2
|
+
export declare type ViewportProps = {
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
longitude: number;
|
|
6
|
+
latitude: number;
|
|
7
|
+
zoom: number;
|
|
8
|
+
pitch?: number;
|
|
9
|
+
bearing?: number;
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Apply mathematical constraints to viewport props
|
|
13
|
+
* @param props
|
|
14
|
+
*/
|
|
15
|
+
export default function normalizeViewportProps(props: ViewportProps): ViewportProps;
|
|
16
|
+
//# sourceMappingURL=normalize-viewport-props.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"normalize-viewport-props.d.ts","sourceRoot":"","sources":["../src/normalize-viewport-props.ts"],"names":[],"mappings":"AAMA,8BAA8B;AAC9B,oBAAY,aAAa,GAAG;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF;;;GAGG;AAEH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,KAAK,EAAE,aAAa,GAAG,aAAa,CAgClF"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { worldToLngLat } from './web-mercator-utils';
|
|
2
|
+
import { mod, log2 } from './math-utils';
|
|
3
|
+
// defined by mapbox-gl
|
|
4
|
+
const TILE_SIZE = 512;
|
|
5
|
+
/**
|
|
6
|
+
* Apply mathematical constraints to viewport props
|
|
7
|
+
* @param props
|
|
8
|
+
*/
|
|
9
|
+
// eslint-disable-next-line complexity
|
|
10
|
+
export default function normalizeViewportProps(props) {
|
|
11
|
+
const { width, height, pitch = 0 } = props;
|
|
12
|
+
let { longitude, latitude, zoom, bearing = 0 } = props;
|
|
13
|
+
// Normalize degrees
|
|
14
|
+
if (longitude < -180 || longitude > 180) {
|
|
15
|
+
longitude = mod(longitude + 180, 360) - 180;
|
|
16
|
+
}
|
|
17
|
+
if (bearing < -180 || bearing > 180) {
|
|
18
|
+
bearing = mod(bearing + 180, 360) - 180;
|
|
19
|
+
}
|
|
20
|
+
// Constrain zoom and shift center at low zoom levels
|
|
21
|
+
const minZoom = log2(height / TILE_SIZE);
|
|
22
|
+
if (zoom <= minZoom) {
|
|
23
|
+
zoom = minZoom;
|
|
24
|
+
latitude = 0;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
// Eliminate white space above and below the map
|
|
28
|
+
const halfHeightPixels = height / 2 / Math.pow(2, zoom);
|
|
29
|
+
const minLatitude = worldToLngLat([0, halfHeightPixels])[1];
|
|
30
|
+
if (latitude < minLatitude) {
|
|
31
|
+
latitude = minLatitude;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];
|
|
35
|
+
if (latitude > maxLatitude) {
|
|
36
|
+
latitude = maxLatitude;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return { width, height, longitude, latitude, zoom, pitch, bearing };
|
|
41
|
+
}
|
|
@@ -1,13 +1,34 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
1
|
+
export declare const MAX_LATITUDE = 85.051129;
|
|
2
|
+
export declare const DEFAULT_ALTITUDE = 1.5;
|
|
3
|
+
export declare type DistanceScales = {
|
|
4
|
+
unitsPerMeter: number[];
|
|
5
|
+
metersPerUnit: number[];
|
|
6
|
+
unitsPerMeter2?: number[];
|
|
7
|
+
unitsPerDegree: number[];
|
|
8
|
+
degreesPerUnit: number[];
|
|
9
|
+
unitsPerDegree2?: number[];
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* PROJECTION MATRIX PARAMETERS
|
|
13
|
+
*
|
|
14
|
+
* TODO how to document mebers
|
|
15
|
+
* @param fov in radians. fov is variable, depends on pitch and altitude
|
|
16
|
+
* @param aspect width/height
|
|
17
|
+
* @param focalDistance distance at which visual scale factor is 1
|
|
18
|
+
* @param near near clipping plane
|
|
19
|
+
* @param far far clipping plane
|
|
20
|
+
*/
|
|
21
|
+
declare type ProjectionParameters = {
|
|
22
|
+
fov: number;
|
|
23
|
+
aspect: number;
|
|
24
|
+
focalDistance: number;
|
|
25
|
+
near: number;
|
|
26
|
+
far: number;
|
|
27
|
+
};
|
|
28
|
+
/** Logarithimic zoom to linear scale **/
|
|
29
|
+
export declare function zoomToScale(zoom: number): number;
|
|
30
|
+
/** Linear scale to logarithimic zoom **/
|
|
31
|
+
export declare function scaleToZoom(scale: number): number;
|
|
11
32
|
/**
|
|
12
33
|
* Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
|
|
13
34
|
* Performs the nonlinear part of the web mercator projection.
|
|
@@ -18,8 +39,7 @@ export function scaleToZoom(scale: number): number;
|
|
|
18
39
|
* Specifies a point on the sphere to project onto the map.
|
|
19
40
|
* @return [x,y] coordinates.
|
|
20
41
|
*/
|
|
21
|
-
export function lngLatToWorld(lngLat: number[]): number
|
|
22
|
-
|
|
42
|
+
export declare function lngLatToWorld(lngLat: number[]): [number, number];
|
|
23
43
|
/**
|
|
24
44
|
* Unproject world point [x,y] on map onto {lat, lon} on sphere
|
|
25
45
|
*
|
|
@@ -29,72 +49,43 @@ export function lngLatToWorld(lngLat: number[]): number[];
|
|
|
29
49
|
* Has toArray method if you need a GeoJSON Array.
|
|
30
50
|
* Per cartographic tradition, lat and lon are specified as degrees.
|
|
31
51
|
*/
|
|
32
|
-
export function worldToLngLat(xy: number[]): number
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
metersPerUnit: number[];
|
|
41
|
-
unitsPerMeter2?: number[];
|
|
42
|
-
unitsPerDegree: number[];
|
|
43
|
-
degreesPerUnit: number[];
|
|
44
|
-
unitsPerDegree2?: number[];
|
|
45
|
-
};
|
|
46
|
-
|
|
52
|
+
export declare function worldToLngLat(xy: number[]): [number, number];
|
|
53
|
+
/**
|
|
54
|
+
* Returns the zoom level that gives a 1 meter pixel at a certain latitude
|
|
55
|
+
* 1 = C*cos(y)/2^z/TILE_SIZE = C*cos(y)/2^(z+9)
|
|
56
|
+
*/
|
|
57
|
+
export declare function getMeterZoom(options: {
|
|
58
|
+
latitude: number;
|
|
59
|
+
}): number;
|
|
47
60
|
/**
|
|
48
61
|
* Calculate distance scales in meters around current lat/lon, both for
|
|
49
62
|
* degrees and pixels.
|
|
50
63
|
* In mercator projection mode, the distance scales vary significantly
|
|
51
64
|
* with latitude.
|
|
52
65
|
*/
|
|
53
|
-
export function getDistanceScales(options: {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
66
|
+
export declare function getDistanceScales(options: {
|
|
67
|
+
latitude: number;
|
|
68
|
+
longitude: number;
|
|
69
|
+
highPrecision?: boolean;
|
|
57
70
|
}): DistanceScales;
|
|
58
|
-
|
|
59
71
|
/**
|
|
60
72
|
* Offset a lng/lat position by meterOffset (northing, easting)
|
|
61
73
|
*/
|
|
62
|
-
export function addMetersToLngLat(lngLatZ: number[], xyz: number[]): number[];
|
|
63
|
-
|
|
64
|
-
// ATTRIBUTION:
|
|
65
|
-
// view and projection matrix creation is intentionally kept compatible with
|
|
66
|
-
// mapbox-gl's implementation to ensure that seamless interoperation
|
|
67
|
-
// with mapbox and react-map-gl. See: https://github.com/mapbox/mapbox-gl-js
|
|
68
|
-
|
|
69
|
-
export function getViewMatrix(options: {
|
|
70
|
-
// Viewport props
|
|
71
|
-
height: number;
|
|
72
|
-
pitch: number;
|
|
73
|
-
bearing: number;
|
|
74
|
-
altitude: number;
|
|
75
|
-
// Pre-calculated parameters
|
|
76
|
-
scale: number;
|
|
77
|
-
center: number[];
|
|
78
|
-
}): number[];
|
|
79
|
-
|
|
74
|
+
export declare function addMetersToLngLat(lngLatZ: number[], xyz: number[]): number[];
|
|
80
75
|
/**
|
|
81
|
-
* PROJECTION MATRIX PARAMETERS
|
|
82
76
|
*
|
|
83
|
-
*
|
|
84
|
-
*
|
|
85
|
-
*
|
|
86
|
-
* @param focalDistance distance at which visual scale factor is 1
|
|
87
|
-
* @param near near clipping plane
|
|
88
|
-
* @param far far clipping plane
|
|
77
|
+
* view and projection matrix creation is intentionally kept compatible with
|
|
78
|
+
* mapbox-gl's implementation to ensure that seamless interoperation
|
|
79
|
+
* with mapbox and react-map-gl. See: https://github.com/mapbox/mapbox-gl-js
|
|
89
80
|
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
81
|
+
export declare function getViewMatrix(options: {
|
|
82
|
+
height: number;
|
|
83
|
+
pitch: number;
|
|
84
|
+
bearing: number;
|
|
85
|
+
altitude: number;
|
|
86
|
+
scale: number;
|
|
87
|
+
center?: number[];
|
|
88
|
+
}): number[];
|
|
98
89
|
/**
|
|
99
90
|
* Calculates mapbox compatible projection matrix from parameters
|
|
100
91
|
*
|
|
@@ -107,16 +98,15 @@ type ProjectionParameters = {
|
|
|
107
98
|
* @param options.farZMultiplier control z buffer
|
|
108
99
|
* @returns project parameters object
|
|
109
100
|
*/
|
|
110
|
-
export function getProjectionParameters(options: {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
101
|
+
export declare function getProjectionParameters(options: {
|
|
102
|
+
width: number;
|
|
103
|
+
height: number;
|
|
104
|
+
fovy?: number;
|
|
105
|
+
altitude?: number;
|
|
106
|
+
pitch?: number;
|
|
107
|
+
nearZMultiplier?: number;
|
|
108
|
+
farZMultiplier?: number;
|
|
118
109
|
}): ProjectionParameters;
|
|
119
|
-
|
|
120
110
|
/**
|
|
121
111
|
* CALCULATE PROJECTION MATRIX: PROJECTS FROM CAMERA (VIEW) SPACE TO CLIPSPACE
|
|
122
112
|
*
|
|
@@ -134,16 +124,15 @@ export function getProjectionParameters(options: {
|
|
|
134
124
|
* @param options.farZMultiplier control z buffer
|
|
135
125
|
* @returns 4x4 projection matrix
|
|
136
126
|
*/
|
|
137
|
-
export function getProjectionMatrix(options: {
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
127
|
+
export declare function getProjectionMatrix(options: {
|
|
128
|
+
width: number;
|
|
129
|
+
height: number;
|
|
130
|
+
pitch: number;
|
|
131
|
+
fovy?: number;
|
|
132
|
+
altitude?: number;
|
|
133
|
+
nearZMultiplier: number;
|
|
134
|
+
farZMultiplier: number;
|
|
145
135
|
}): number[];
|
|
146
|
-
|
|
147
136
|
/**
|
|
148
137
|
*
|
|
149
138
|
* Convert an altitude to field of view such that the
|
|
@@ -152,8 +141,7 @@ export function getProjectionMatrix(options: {
|
|
|
152
141
|
* @param altitude - altitude of camera in screen units
|
|
153
142
|
* @return fovy field of view in degrees
|
|
154
143
|
*/
|
|
155
|
-
export function altitudeToFovy(altitude: number): number;
|
|
156
|
-
|
|
144
|
+
export declare function altitudeToFovy(altitude: number): number;
|
|
157
145
|
/**
|
|
158
146
|
*
|
|
159
147
|
* Convert an field of view such that the
|
|
@@ -162,8 +150,7 @@ export function altitudeToFovy(altitude: number): number;
|
|
|
162
150
|
* @param fovy - field of view in degrees
|
|
163
151
|
* @return altitude altitude of camera in screen units
|
|
164
152
|
*/
|
|
165
|
-
export function fovyToAltitude(fovy: number): number;
|
|
166
|
-
|
|
153
|
+
export declare function fovyToAltitude(fovy: number): number;
|
|
167
154
|
/**
|
|
168
155
|
* Project flat coordinates to pixels on screen.
|
|
169
156
|
*
|
|
@@ -171,8 +158,7 @@ export function fovyToAltitude(fovy: number): number;
|
|
|
171
158
|
* @param pixelProjectionMatrix - projection matrix 4x4
|
|
172
159
|
* @return [x, y, depth] pixel coordinate on screen.
|
|
173
160
|
*/
|
|
174
|
-
export function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[];
|
|
175
|
-
|
|
161
|
+
export declare function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[];
|
|
176
162
|
/**
|
|
177
163
|
* Unproject pixels on screen to flat coordinates.
|
|
178
164
|
*
|
|
@@ -182,8 +168,6 @@ export function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): n
|
|
|
182
168
|
* targetZ is used as the elevation plane to unproject onto
|
|
183
169
|
* @return [x, y, Z] flat coordinates on 512*512 Mercator Zoom 0 tile.
|
|
184
170
|
*/
|
|
185
|
-
export function pixelsToWorld(
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
targetZ?: number
|
|
189
|
-
): number[];
|
|
171
|
+
export declare function pixelsToWorld(xyz: number[], pixelUnprojectionMatrix: number[], targetZ?: number): number[];
|
|
172
|
+
export {};
|
|
173
|
+
//# sourceMappingURL=web-mercator-utils.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-mercator-utils.d.ts","sourceRoot":"","sources":["../src/web-mercator-utils.ts"],"names":[],"mappings":"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"}
|