@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
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
import { Bounds, FitBoundsOptions } from "./fit-bounds";
|
|
2
|
-
|
|
3
|
-
type WebMercatorViewportOptions = {
|
|
4
|
-
// Map state
|
|
5
|
-
width: number;
|
|
6
|
-
height: number;
|
|
7
|
-
latitude?: number;
|
|
8
|
-
longitude?: number;
|
|
9
|
-
position?: number[];
|
|
10
|
-
zoom?: number;
|
|
11
|
-
pitch?: number;
|
|
12
|
-
bearing?: number;
|
|
13
|
-
altitude?: number;
|
|
14
|
-
fovy?: number;
|
|
15
|
-
nearZMultiplier?: number;
|
|
16
|
-
farZMultiplier?: number;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Creates view/projection matrices and "uniform values" from mercator params
|
|
21
|
-
*
|
|
22
|
-
* Note: `Viewport` instances are immutable in the sense that they only have accessors.
|
|
23
|
-
* A new viewport instance should be created if any parameters have changed.
|
|
24
|
-
*/
|
|
25
|
-
export default class WebMercatorViewport {
|
|
26
|
-
latitude: number;
|
|
27
|
-
longitude: number;
|
|
28
|
-
zoom: number;
|
|
29
|
-
pitch: number;
|
|
30
|
-
bearing: number;
|
|
31
|
-
altitude: number;
|
|
32
|
-
fovy: number;
|
|
33
|
-
|
|
34
|
-
meterOffset: number[];
|
|
35
|
-
center: number[];
|
|
36
|
-
|
|
37
|
-
width: number;
|
|
38
|
-
height: number;
|
|
39
|
-
scale: number;
|
|
40
|
-
distanceScales: {
|
|
41
|
-
unitsPerMeter: number[]
|
|
42
|
-
};
|
|
43
|
-
|
|
44
|
-
viewMatrix: number[];
|
|
45
|
-
projectionMatrix: number[];
|
|
46
|
-
|
|
47
|
-
viewProjectionMatrix: number[];
|
|
48
|
-
pixelProjectionMatrix: number[];
|
|
49
|
-
pixelUnprojectionMatrix: number[];
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @classdesc
|
|
53
|
-
* Creates view/projection matrices from mercator params
|
|
54
|
-
* Note: The Viewport is immutable in the sense that it only has accessors.
|
|
55
|
-
* A new viewport instance should be created if any parameters have changed.
|
|
56
|
-
*
|
|
57
|
-
* @class
|
|
58
|
-
* @param {WebMercatorViewportOptions} opt - options
|
|
59
|
-
*
|
|
60
|
-
* @param [opt.width=1] - Width of "viewport" or window
|
|
61
|
-
* @param [opt.height=1] - Height of "viewport" or window
|
|
62
|
-
* @param [opt.scale=1] - Either use scale or zoom
|
|
63
|
-
* @param [opt.pitch=0] - Camera angle in degrees (0 is straight down)
|
|
64
|
-
* @param [opt.bearing=0] - Map rotation in degrees (0 means north is up)
|
|
65
|
-
* @param [opt.fovy=] - Field of view of camera in degrees
|
|
66
|
-
* @param [opt.altitude=] - Altitude of camera in screen units
|
|
67
|
-
*
|
|
68
|
-
* Web mercator projection short-hand parameters
|
|
69
|
-
* @param [opt.latitude] - Center of viewport on map
|
|
70
|
-
* @param [opt.longitude] - Center of viewport on map
|
|
71
|
-
* @param [opt.zoom] - Scale = Math.pow(2,zoom) on map
|
|
72
|
-
|
|
73
|
-
* Notes:
|
|
74
|
-
* - Only one of center or [latitude, longitude] can be specified
|
|
75
|
-
* - [latitude, longitude] can only be specified when "mercator" is true
|
|
76
|
-
* - Altitude has a default value that matches assumptions in mapbox-gl
|
|
77
|
-
* - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl
|
|
78
|
-
* - width and height are forced to 1 if supplied as 0, to avoid
|
|
79
|
-
* division by zero. This is intended to reduce the burden of apps to
|
|
80
|
-
* to check values before instantiating a Viewport.
|
|
81
|
-
*/
|
|
82
|
-
constructor(options?: WebMercatorViewportOptions);
|
|
83
|
-
|
|
84
|
-
/** Two viewports are equal if width and height are identical, and if
|
|
85
|
-
* their view and projection matrices are (approximately) equal.
|
|
86
|
-
*/
|
|
87
|
-
equals(viewport: WebMercatorViewport | null): boolean;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* Projects xyz (possibly latitude and longitude) to pixel coordinates in window
|
|
91
|
-
* using viewport projection parameters
|
|
92
|
-
* - [longitude, latitude] to [x, y]
|
|
93
|
-
* - [longitude, latitude, Z] => [x, y, z]
|
|
94
|
-
* Note: By default, returns top-left coordinates for canvas/SVG type render
|
|
95
|
-
*
|
|
96
|
-
* @param lngLatZ - [lng, lat] or [lng, lat, Z]
|
|
97
|
-
* @param options - options
|
|
98
|
-
* @param options.topLeft=true - Whether projected coords are top left
|
|
99
|
-
* @return - screen coordinates [x, y] or [x, y, z], z as pixel depth
|
|
100
|
-
*/
|
|
101
|
-
project(lngLatZ: number[], options?: {topLeft?: boolean}): number[];
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.
|
|
105
|
-
*
|
|
106
|
-
* - [x, y] => [lng, lat]
|
|
107
|
-
* - [x, y, z] => [lng, lat, Z]
|
|
108
|
-
*
|
|
109
|
-
* @param xyz - screen coordinates, z as pixel depth
|
|
110
|
-
* @param options - options
|
|
111
|
-
* @param options.topLeft=true - Whether projected coords are top left
|
|
112
|
-
* @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as
|
|
113
|
-
* the elevation plane to unproject onto
|
|
114
|
-
* @return - [lng, lat, Z] or [X, Y, Z]
|
|
115
|
-
*/
|
|
116
|
-
unproject(xyz: number[], options?: {topLeft?: boolean; targetZ?: number}): number[];
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
|
|
120
|
-
* Performs the nonlinear part of the web mercator projection.
|
|
121
|
-
* Remaining projection is done with 4x4 matrices which also handles
|
|
122
|
-
* perspective.
|
|
123
|
-
*
|
|
124
|
-
* @param lngLat - [lng, lat] coordinates
|
|
125
|
-
* Specifies a point on the sphere to project onto the map.
|
|
126
|
-
* @return [x,y] coordinates.
|
|
127
|
-
*/
|
|
128
|
-
projectFlat(lngLat: number[]): number[];
|
|
129
|
-
|
|
130
|
-
/**
|
|
131
|
-
* Unproject world point [x,y] on map onto {lat, lon} on sphere
|
|
132
|
-
*
|
|
133
|
-
* @param xy - array with [x,y] members
|
|
134
|
-
* representing point on projected map plane
|
|
135
|
-
* @return - array with [lat,lon] of point on sphere.
|
|
136
|
-
* Has toArray method if you need a GeoJSON Array.
|
|
137
|
-
* Per cartographic tradition, lat and lon are specified as degrees.
|
|
138
|
-
*/
|
|
139
|
-
unprojectFlat(xy: number[]): number[];
|
|
140
|
-
|
|
141
|
-
/**
|
|
142
|
-
* Get the map center that place a given [lng, lat] coordinate at screen
|
|
143
|
-
* point [x, y]
|
|
144
|
-
*
|
|
145
|
-
* @param {object} opt
|
|
146
|
-
* @param opt.lngLat - [lng,lat] coordinates
|
|
147
|
-
* Specifies a point on the sphere.
|
|
148
|
-
* @param opt.pos - [x,y] coordinates
|
|
149
|
-
* Specifies a point on the screen.
|
|
150
|
-
* @return [lng,lat] new map center.
|
|
151
|
-
*/
|
|
152
|
-
getMapCenterByLngLatPosition({lngLat, pos}: {lngLat: number[], pos: number[]}): number[];
|
|
153
|
-
|
|
154
|
-
/** @deprecated Legacy method name */
|
|
155
|
-
getLocationAtPoint({lngLat, pos}: {lngLat: number[], pos: number[]}): number[];
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
* Returns a new viewport that fit around the given rectangle.
|
|
159
|
-
* Only supports non-perspective mode.
|
|
160
|
-
* @param {Array} bounds - [[lon, lat], [lon, lat]]
|
|
161
|
-
* @param {Object} [options]
|
|
162
|
-
* @param {Number} [options.padding] - The amount of padding in pixels to add to the given bounds.
|
|
163
|
-
* @param {Array} [options.offset] - The center of the given bounds relative to the map's center,
|
|
164
|
-
* [x, y] measured in pixels.
|
|
165
|
-
* @returns {WebMercatorViewport}
|
|
166
|
-
*/
|
|
167
|
-
fitBounds(
|
|
168
|
-
bounds: [[number, number], [number, number]],
|
|
169
|
-
options?: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'>,
|
|
170
|
-
): WebMercatorViewport;
|
|
171
|
-
|
|
172
|
-
/**
|
|
173
|
-
* Returns the bounding box of the viewport.
|
|
174
|
-
* @param {Object} [options]
|
|
175
|
-
* @param {Number} [options.z] - The altitude at which the bounds should be calculated.
|
|
176
|
-
* @returns {Array} bounds - [[lon, lat], [lon, lat]]
|
|
177
|
-
*/
|
|
178
|
-
getBounds(options?: {z?: number}) : Array<number[]>;
|
|
179
|
-
|
|
180
|
-
/**
|
|
181
|
-
* Returns the bounding box of the viewport.
|
|
182
|
-
* @param {Object} [options]
|
|
183
|
-
* @param {Number} [options.z] - The altitude at which the bounds should be calculated.
|
|
184
|
-
* @returns {Array} an array of 4 points that define the visible region
|
|
185
|
-
*/
|
|
186
|
-
getBoundingRegion(options?: {z?: number}) : Array<number[]>;
|
|
187
|
-
}
|
package/dist/esm/fit-bounds.d.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* An object describing the padding to add to the bounds.
|
|
3
|
-
*
|
|
4
|
-
* @property top - Padding from top in pixels to add to the given bounds
|
|
5
|
-
* @property bottom - Padding from bottom in pixels to add to the given bounds
|
|
6
|
-
* @property left - Padding from left in pixels to add to the given bounds
|
|
7
|
-
* @property right - Padding from right in pixels to add to the given bounds
|
|
8
|
-
*/
|
|
9
|
-
export type Padding = {
|
|
10
|
-
top: number;
|
|
11
|
-
bottom: number;
|
|
12
|
-
left: number;
|
|
13
|
-
right: number;
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Options for fitBounds
|
|
18
|
-
*
|
|
19
|
-
* @param options fit bounds parameters
|
|
20
|
-
* @param options.width - viewport width
|
|
21
|
-
* @param options.height - viewport height
|
|
22
|
-
* @param options.bounds - [[lon, lat], [lon, lat]]
|
|
23
|
-
* @param options.minExtent - The width/height of the bounded area will never be smaller than this
|
|
24
|
-
* @param options.padding - The amount of padding in pixels
|
|
25
|
-
* to add to the given bounds. Can also be an object with top, bottom, left and right
|
|
26
|
-
* properties defining the padding.
|
|
27
|
-
* @param [options.offset] - The center of the given bounds relative to the map's center,
|
|
28
|
-
*/
|
|
29
|
-
export type FitBoundsOptions = {
|
|
30
|
-
width: number;
|
|
31
|
-
height: number;
|
|
32
|
-
bounds: [[number, number], [number, number]];
|
|
33
|
-
minExtent?: number; // 0.01 would be about 1000 meters (degree is ~110KM)
|
|
34
|
-
maxZoom?: number; // ~x4,000,000 => About 10 meter extents
|
|
35
|
-
// options
|
|
36
|
-
padding?: number | Padding;
|
|
37
|
-
offset?: number[];
|
|
38
|
-
};
|
|
39
|
-
|
|
40
|
-
export type Bounds = {
|
|
41
|
-
longitude: number;
|
|
42
|
-
latitude: number;
|
|
43
|
-
zoom: number;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Returns map settings {latitude, longitude, zoom}
|
|
48
|
-
* that will contain the provided corners within the provided width.
|
|
49
|
-
*
|
|
50
|
-
* > _Note: Only supports non-perspective mode._
|
|
51
|
-
*
|
|
52
|
-
* @param options fit bounds parameters
|
|
53
|
-
* @param options.width - viewport width
|
|
54
|
-
* @param options.height - viewport height
|
|
55
|
-
* @param options.bounds - [[lon, lat], [lon, lat]]
|
|
56
|
-
* @param options.minExtent - The width/height of the bounded area will never be smaller than this
|
|
57
|
-
* @param options.padding - The amount of padding in pixels
|
|
58
|
-
* to add to the given bounds. Can also be an object with top, bottom, left and right
|
|
59
|
-
* properties defining the padding.
|
|
60
|
-
* @param [options.offset] - The center of the given bounds relative to the map's center,
|
|
61
|
-
* [x, y] measured in pixels.
|
|
62
|
-
* @returns {Object} - latitude, longitude and zoom
|
|
63
|
-
*/
|
|
64
|
-
export default function fitBounds(options: FitBoundsOptions): Bounds;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
type FlytoTransitionOptions = {
|
|
2
|
-
curve?: number;
|
|
3
|
-
speed?: number;
|
|
4
|
-
screenSpeed?: number;
|
|
5
|
-
maxDuration?: number;
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
type ViewportProps = {
|
|
9
|
-
longitude: number;
|
|
10
|
-
latitude: number;
|
|
11
|
-
zoom: number;
|
|
12
|
-
};
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.
|
|
16
|
-
* It implements “Smooth and efficient zooming and panning.” algorithm by
|
|
17
|
-
* "Jarke J. van Wijk and Wim A.A. Nuij"
|
|
18
|
-
*/
|
|
19
|
-
export default function flyToViewport(
|
|
20
|
-
startProps: ViewportProps,
|
|
21
|
-
endProps: ViewportProps,
|
|
22
|
-
t: number,
|
|
23
|
-
options?: FlytoTransitionOptions
|
|
24
|
-
): ViewportProps;
|
|
25
|
-
|
|
26
|
-
// returns transition duration in milliseconds
|
|
27
|
-
export function getFlyToDuration(
|
|
28
|
-
startProps: ViewportProps,
|
|
29
|
-
endProps: ViewportProps,
|
|
30
|
-
options?: FlytoTransitionOptions
|
|
31
|
-
): number;
|
package/dist/esm/get-bounds.d.ts
DELETED
package/dist/esm/index.d.ts
DELETED
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
// Classic web-mercator-project
|
|
2
|
-
export {default} from './web-mercator-viewport';
|
|
3
|
-
export {default as WebMercatorViewport} from './web-mercator-viewport';
|
|
4
|
-
|
|
5
|
-
export {default as getBounds} from './get-bounds';
|
|
6
|
-
export {default as fitBounds} from './fit-bounds';
|
|
7
|
-
export {default as normalizeViewportProps} from './normalize-viewport-props';
|
|
8
|
-
export {default as flyToViewport, getFlyToDuration} from './fly-to-viewport';
|
|
9
|
-
|
|
10
|
-
export {
|
|
11
|
-
lngLatToWorld,
|
|
12
|
-
worldToLngLat,
|
|
13
|
-
worldToPixels,
|
|
14
|
-
pixelsToWorld,
|
|
15
|
-
zoomToScale,
|
|
16
|
-
scaleToZoom,
|
|
17
|
-
getMeterZoom,
|
|
18
|
-
getDistanceScales,
|
|
19
|
-
addMetersToLngLat,
|
|
20
|
-
getViewMatrix,
|
|
21
|
-
getProjectionMatrix,
|
|
22
|
-
getProjectionParameters
|
|
23
|
-
} from './web-mercator-utils';
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/** Description of viewport */
|
|
2
|
-
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
|
-
/**
|
|
13
|
-
* Apply mathematical constraints to viewport props
|
|
14
|
-
* @param props
|
|
15
|
-
*/
|
|
16
|
-
export default function normalizeViewportProps(props: ViewportProps): ViewportProps;
|
|
@@ -1,189 +0,0 @@
|
|
|
1
|
-
// TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE
|
|
2
|
-
|
|
3
|
-
/** Mapbox default altitude */
|
|
4
|
-
export const DEFAULT_ALTITUDE: number;
|
|
5
|
-
|
|
6
|
-
/** Util functions **/
|
|
7
|
-
export function zoomToScale(zoom: number): number;
|
|
8
|
-
|
|
9
|
-
export function scaleToZoom(scale: number): number;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
|
|
13
|
-
* Performs the nonlinear part of the web mercator projection.
|
|
14
|
-
* Remaining projection is done with 4x4 matrices which also handles
|
|
15
|
-
* perspective.
|
|
16
|
-
*
|
|
17
|
-
* @param lngLat - [lng, lat] coordinates
|
|
18
|
-
* Specifies a point on the sphere to project onto the map.
|
|
19
|
-
* @return [x,y] coordinates.
|
|
20
|
-
*/
|
|
21
|
-
export function lngLatToWorld(lngLat: number[]): number[];
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Unproject world point [x,y] on map onto {lat, lon} on sphere
|
|
25
|
-
*
|
|
26
|
-
* @param xy - array with [x,y] members
|
|
27
|
-
* representing point on projected map plane
|
|
28
|
-
* @return - array with [x,y] of point on sphere.
|
|
29
|
-
* Has toArray method if you need a GeoJSON Array.
|
|
30
|
-
* Per cartographic tradition, lat and lon are specified as degrees.
|
|
31
|
-
*/
|
|
32
|
-
export function worldToLngLat(xy: number[]): number[];
|
|
33
|
-
|
|
34
|
-
// Returns the zoom level that gives a 1 meter pixel at a certain latitude
|
|
35
|
-
// 1 = C*cos(y)/2^z/TILE_SIZE = C*cos(y)/2^(z+9)
|
|
36
|
-
export function getMeterZoom(options: {latitude: number}): number;
|
|
37
|
-
|
|
38
|
-
export type DistanceScales = {
|
|
39
|
-
unitsPerMeter: number[];
|
|
40
|
-
metersPerUnit: number[];
|
|
41
|
-
unitsPerMeter2?: number[];
|
|
42
|
-
unitsPerDegree: number[];
|
|
43
|
-
degreesPerUnit: number[];
|
|
44
|
-
unitsPerDegree2?: number[];
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Calculate distance scales in meters around current lat/lon, both for
|
|
49
|
-
* degrees and pixels.
|
|
50
|
-
* In mercator projection mode, the distance scales vary significantly
|
|
51
|
-
* with latitude.
|
|
52
|
-
*/
|
|
53
|
-
export function getDistanceScales(options: {
|
|
54
|
-
latitude: number;
|
|
55
|
-
longitude: number;
|
|
56
|
-
highPrecision?: boolean;
|
|
57
|
-
}): DistanceScales;
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
* Offset a lng/lat position by meterOffset (northing, easting)
|
|
61
|
-
*/
|
|
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
|
-
|
|
80
|
-
/**
|
|
81
|
-
* PROJECTION MATRIX PARAMETERS
|
|
82
|
-
*
|
|
83
|
-
* TODO how to document mebers
|
|
84
|
-
* @param fov in radians. fov is variable, depends on pitch and altitude
|
|
85
|
-
* @param aspect width/height
|
|
86
|
-
* @param focalDistance distance at which visual scale factor is 1
|
|
87
|
-
* @param near near clipping plane
|
|
88
|
-
* @param far far clipping plane
|
|
89
|
-
*/
|
|
90
|
-
type ProjectionParameters = {
|
|
91
|
-
fov: number;
|
|
92
|
-
aspect: number;
|
|
93
|
-
focalDistance: number;
|
|
94
|
-
near: number;
|
|
95
|
-
far: number;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
/**
|
|
99
|
-
* Calculates mapbox compatible projection matrix from parameters
|
|
100
|
-
*
|
|
101
|
-
* @param options.width Width of "viewport" or window
|
|
102
|
-
* @param options.height Height of "viewport" or window
|
|
103
|
-
* @param options.pitch Camera angle in degrees (0 is straight down)
|
|
104
|
-
* @param options.fovy field of view in degrees
|
|
105
|
-
* @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`
|
|
106
|
-
* @param options.nearZMultiplier control z buffer
|
|
107
|
-
* @param options.farZMultiplier control z buffer
|
|
108
|
-
* @returns project parameters object
|
|
109
|
-
*/
|
|
110
|
-
export function getProjectionParameters(options: {
|
|
111
|
-
width: number;
|
|
112
|
-
height: number;
|
|
113
|
-
fovy?: number;
|
|
114
|
-
altitude?: number;
|
|
115
|
-
pitch?: number;
|
|
116
|
-
nearZMultiplier?: number;
|
|
117
|
-
farZMultiplier?: number;
|
|
118
|
-
}): ProjectionParameters;
|
|
119
|
-
|
|
120
|
-
/**
|
|
121
|
-
* CALCULATE PROJECTION MATRIX: PROJECTS FROM CAMERA (VIEW) SPACE TO CLIPSPACE
|
|
122
|
-
*
|
|
123
|
-
* To match mapbox's z buffer:
|
|
124
|
-
* - \<= 0.28: nearZMultiplier: 0.1, farZmultiplier: 1
|
|
125
|
-
* - \>= 0.29: nearZMultiplier: 1 / height, farZMultiplier: 1.01
|
|
126
|
-
*
|
|
127
|
-
* @param options Viewport options
|
|
128
|
-
* @param options.width Width of "viewport" or window
|
|
129
|
-
* @param options.height Height of "viewport" or window
|
|
130
|
-
* @param options.pitch Camera angle in degrees (0 is straight down)
|
|
131
|
-
* @param options.fovy field of view in degrees
|
|
132
|
-
* @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`
|
|
133
|
-
* @param options.nearZMultiplier control z buffer
|
|
134
|
-
* @param options.farZMultiplier control z buffer
|
|
135
|
-
* @returns 4x4 projection matrix
|
|
136
|
-
*/
|
|
137
|
-
export function getProjectionMatrix(options: {
|
|
138
|
-
width: number;
|
|
139
|
-
height: number;
|
|
140
|
-
pitch: number;
|
|
141
|
-
fovy?: number;
|
|
142
|
-
altitude?: number;
|
|
143
|
-
nearZMultiplier: number;
|
|
144
|
-
farZMultiplier: number;
|
|
145
|
-
}): number[];
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
*
|
|
149
|
-
* Convert an altitude to field of view such that the
|
|
150
|
-
* focal distance is equal to the altitude
|
|
151
|
-
*
|
|
152
|
-
* @param altitude - altitude of camera in screen units
|
|
153
|
-
* @return fovy field of view in degrees
|
|
154
|
-
*/
|
|
155
|
-
export function altitudeToFovy(altitude: number): number;
|
|
156
|
-
|
|
157
|
-
/**
|
|
158
|
-
*
|
|
159
|
-
* Convert an field of view such that the
|
|
160
|
-
* focal distance is equal to the altitude
|
|
161
|
-
*
|
|
162
|
-
* @param fovy - field of view in degrees
|
|
163
|
-
* @return altitude altitude of camera in screen units
|
|
164
|
-
*/
|
|
165
|
-
export function fovyToAltitude(fovy: number): number;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* Project flat coordinates to pixels on screen.
|
|
169
|
-
*
|
|
170
|
-
* @param xyz - flat coordinate on 512*512 Mercator Zoom 0 tile
|
|
171
|
-
* @param pixelProjectionMatrix - projection matrix 4x4
|
|
172
|
-
* @return [x, y, depth] pixel coordinate on screen.
|
|
173
|
-
*/
|
|
174
|
-
export function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[];
|
|
175
|
-
|
|
176
|
-
/**
|
|
177
|
-
* Unproject pixels on screen to flat coordinates.
|
|
178
|
-
*
|
|
179
|
-
* @param xyz - pixel coordinate on screen.
|
|
180
|
-
* @param pixelUnprojectionMatrix - unprojection matrix 4x4
|
|
181
|
-
* @param targetZ - if pixel coordinate does not have a 3rd component (depth),
|
|
182
|
-
* targetZ is used as the elevation plane to unproject onto
|
|
183
|
-
* @return [x, y, Z] flat coordinates on 512*512 Mercator Zoom 0 tile.
|
|
184
|
-
*/
|
|
185
|
-
export function pixelsToWorld(
|
|
186
|
-
xyz: number[],
|
|
187
|
-
pixelUnprojectionMatrix: number[],
|
|
188
|
-
targetZ?: number
|
|
189
|
-
): number[];
|