@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.
Files changed (92) hide show
  1. package/dist/assert.d.ts +2 -0
  2. package/dist/assert.d.ts.map +1 -0
  3. package/dist/assert.js +8 -0
  4. package/dist/es5/assert.js.map +1 -1
  5. package/dist/es5/fit-bounds.js +40 -50
  6. package/dist/es5/fit-bounds.js.map +1 -1
  7. package/dist/es5/fly-to-viewport.js +82 -98
  8. package/dist/es5/fly-to-viewport.js.map +1 -1
  9. package/dist/es5/get-bounds.js +25 -24
  10. package/dist/es5/get-bounds.js.map +1 -1
  11. package/dist/es5/index.js +23 -25
  12. package/dist/es5/index.js.map +1 -1
  13. package/dist/es5/math-utils.js +5 -11
  14. package/dist/es5/math-utils.js.map +1 -1
  15. package/dist/es5/normalize-viewport-props.js +36 -51
  16. package/dist/es5/normalize-viewport-props.js.map +1 -1
  17. package/dist/es5/web-mercator-utils.js +104 -144
  18. package/dist/es5/web-mercator-utils.js.map +1 -1
  19. package/dist/es5/web-mercator-viewport.js +198 -241
  20. package/dist/es5/web-mercator-viewport.js.map +1 -1
  21. package/dist/esm/assert.js.map +1 -1
  22. package/dist/esm/fit-bounds.js +24 -22
  23. package/dist/esm/fit-bounds.js.map +1 -1
  24. package/dist/esm/fly-to-viewport.js +13 -9
  25. package/dist/esm/fly-to-viewport.js.map +1 -1
  26. package/dist/esm/get-bounds.js.map +1 -1
  27. package/dist/esm/index.js.map +1 -1
  28. package/dist/esm/math-utils.js +3 -3
  29. package/dist/esm/math-utils.js.map +1 -1
  30. package/dist/esm/normalize-viewport-props.js +30 -41
  31. package/dist/esm/normalize-viewport-props.js.map +1 -1
  32. package/dist/esm/web-mercator-utils.js +46 -52
  33. package/dist/esm/web-mercator-utils.js.map +1 -1
  34. package/dist/esm/web-mercator-viewport.js +75 -33
  35. package/dist/esm/web-mercator-viewport.js.map +1 -1
  36. package/dist/fit-bounds.d.ts +49 -0
  37. package/dist/fit-bounds.d.ts.map +1 -0
  38. package/dist/fit-bounds.js +70 -0
  39. package/dist/fly-to-viewport.d.ts +19 -0
  40. package/dist/fly-to-viewport.d.ts.map +1 -0
  41. package/dist/fly-to-viewport.js +87 -0
  42. package/dist/get-bounds.d.ts +3 -0
  43. package/dist/get-bounds.d.ts.map +1 -0
  44. package/dist/get-bounds.js +51 -0
  45. package/dist/index.d.ts +8 -0
  46. package/dist/index.d.ts.map +1 -0
  47. package/dist/index.js +8 -0
  48. package/dist/math-utils.d.ts +6 -0
  49. package/dist/math-utils.d.ts.map +1 -0
  50. package/dist/math-utils.js +23 -0
  51. package/dist/normalize-viewport-props.d.ts +17 -0
  52. package/dist/normalize-viewport-props.d.ts.map +1 -0
  53. package/dist/normalize-viewport-props.js +41 -0
  54. package/dist/{es5/web-mercator-utils.d.ts → web-mercator-utils.d.ts} +77 -94
  55. package/dist/web-mercator-utils.d.ts.map +1 -0
  56. package/dist/web-mercator-utils.js +289 -0
  57. package/dist/web-mercator-viewport.d.ts +183 -0
  58. package/dist/web-mercator-viewport.d.ts.map +1 -0
  59. package/dist/web-mercator-viewport.js +282 -0
  60. package/package.json +4 -4
  61. package/src/{assert.js → assert.ts} +1 -1
  62. package/src/fit-bounds.ts +135 -0
  63. package/src/{fly-to-viewport.js → fly-to-viewport.ts} +33 -10
  64. package/src/{get-bounds.js → get-bounds.ts} +4 -2
  65. package/src/{index.js → index.ts} +0 -0
  66. package/src/{math-utils.js → math-utils.ts} +7 -7
  67. package/src/normalize-viewport-props.ts +55 -0
  68. package/src/{web-mercator-utils.js → web-mercator-utils.ts} +181 -72
  69. package/src/web-mercator-viewport.ts +417 -0
  70. package/dist/es5/fit-bounds.d.ts +0 -64
  71. package/dist/es5/fly-to-viewport.d.ts +0 -31
  72. package/dist/es5/get-bounds.d.ts +0 -3
  73. package/dist/es5/index.d.ts +0 -23
  74. package/dist/es5/normalize-viewport-props.d.ts +0 -16
  75. package/dist/es5/web-mercator-viewport.d.ts +0 -187
  76. package/dist/esm/fit-bounds.d.ts +0 -64
  77. package/dist/esm/fly-to-viewport.d.ts +0 -31
  78. package/dist/esm/get-bounds.d.ts +0 -3
  79. package/dist/esm/index.d.ts +0 -23
  80. package/dist/esm/normalize-viewport-props.d.ts +0 -16
  81. package/dist/esm/web-mercator-utils.d.ts +0 -189
  82. package/dist/esm/web-mercator-viewport.d.ts +0 -187
  83. package/src/fit-bounds.d.ts +0 -64
  84. package/src/fit-bounds.js +0 -84
  85. package/src/fly-to-viewport.d.ts +0 -31
  86. package/src/get-bounds.d.ts +0 -3
  87. package/src/index.d.ts +0 -23
  88. package/src/normalize-viewport-props.d.ts +0 -16
  89. package/src/normalize-viewport-props.js +0 -55
  90. package/src/web-mercator-utils.d.ts +0 -189
  91. package/src/web-mercator-viewport.d.ts +0 -187
  92. package/src/web-mercator-viewport.js +0 -262
@@ -0,0 +1,289 @@
1
+ // TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE
2
+ import { createMat4, transformVector, log2 } from './math-utils';
3
+ import * as mat4 from 'gl-matrix/mat4';
4
+ import * as vec2 from 'gl-matrix/vec2';
5
+ import * as vec3 from 'gl-matrix/vec3';
6
+ import assert from './assert';
7
+ // CONSTANTS
8
+ const PI = Math.PI;
9
+ const PI_4 = PI / 4;
10
+ const DEGREES_TO_RADIANS = PI / 180;
11
+ const RADIANS_TO_DEGREES = 180 / PI;
12
+ const TILE_SIZE = 512;
13
+ // Average circumference (40075 km equatorial, 40007 km meridional)
14
+ const EARTH_CIRCUMFERENCE = 40.03e6;
15
+ // Mapbox default altitude
16
+ export const DEFAULT_ALTITUDE = 1.5;
17
+ /** Logarithimic zoom to linear scale **/
18
+ export function zoomToScale(zoom) {
19
+ return Math.pow(2, zoom);
20
+ }
21
+ /** Linear scale to logarithimic zoom **/
22
+ export function scaleToZoom(scale) {
23
+ return log2(scale);
24
+ }
25
+ /**
26
+ * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
27
+ * Performs the nonlinear part of the web mercator projection.
28
+ * Remaining projection is done with 4x4 matrices which also handles
29
+ * perspective.
30
+ *
31
+ * @param lngLat - [lng, lat] coordinates
32
+ * Specifies a point on the sphere to project onto the map.
33
+ * @return [x,y] coordinates.
34
+ */
35
+ export function lngLatToWorld(lngLat) {
36
+ const [lng, lat] = lngLat;
37
+ assert(Number.isFinite(lng));
38
+ assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, 'invalid latitude');
39
+ const lambda2 = lng * DEGREES_TO_RADIANS;
40
+ const phi2 = lat * DEGREES_TO_RADIANS;
41
+ const x = (TILE_SIZE * (lambda2 + PI)) / (2 * PI);
42
+ const y = (TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5)))) / (2 * PI);
43
+ return [x, y];
44
+ }
45
+ /**
46
+ * Unproject world point [x,y] on map onto {lat, lon} on sphere
47
+ *
48
+ * @param xy - array with [x,y] members
49
+ * representing point on projected map plane
50
+ * @return - array with [x,y] of point on sphere.
51
+ * Has toArray method if you need a GeoJSON Array.
52
+ * Per cartographic tradition, lat and lon are specified as degrees.
53
+ */
54
+ export function worldToLngLat(xy) {
55
+ const [x, y] = xy;
56
+ const lambda2 = (x / TILE_SIZE) * (2 * PI) - PI;
57
+ const phi2 = 2 * (Math.atan(Math.exp((y / TILE_SIZE) * (2 * PI) - PI)) - PI_4);
58
+ return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
59
+ }
60
+ /**
61
+ * Returns the zoom level that gives a 1 meter pixel at a certain latitude
62
+ * 1 = C*cos(y)/2^z/TILE_SIZE = C*cos(y)/2^(z+9)
63
+ */
64
+ export function getMeterZoom(options) {
65
+ const { latitude } = options;
66
+ assert(Number.isFinite(latitude));
67
+ const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
68
+ return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;
69
+ }
70
+ /**
71
+ * Calculate distance scales in meters around current lat/lon, both for
72
+ * degrees and pixels.
73
+ * In mercator projection mode, the distance scales vary significantly
74
+ * with latitude.
75
+ */
76
+ export function getDistanceScales(options) {
77
+ const { latitude, longitude, highPrecision = false } = options;
78
+ assert(Number.isFinite(latitude) && Number.isFinite(longitude));
79
+ const worldSize = TILE_SIZE;
80
+ const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
81
+ /**
82
+ * Number of pixels occupied by one degree longitude around current lat/lon:
83
+ unitsPerDegreeX = d(lngLatToWorld([lng, lat])[0])/d(lng)
84
+ = scale * TILE_SIZE * DEGREES_TO_RADIANS / (2 * PI)
85
+ unitsPerDegreeY = d(lngLatToWorld([lng, lat])[1])/d(lat)
86
+ = -scale * TILE_SIZE * DEGREES_TO_RADIANS / cos(lat * DEGREES_TO_RADIANS) / (2 * PI)
87
+ */
88
+ const unitsPerDegreeX = worldSize / 360;
89
+ const unitsPerDegreeY = unitsPerDegreeX / latCosine;
90
+ /**
91
+ * Number of pixels occupied by one meter around current lat/lon:
92
+ */
93
+ const altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;
94
+ /**
95
+ * LngLat: longitude -> east and latitude -> north (bottom left)
96
+ * UTM meter offset: x -> east and y -> north (bottom left)
97
+ * World space: x -> east and y -> south (top left)
98
+ *
99
+ * Y needs to be flipped when converting delta degree/meter to delta pixels
100
+ */
101
+ const result = {
102
+ unitsPerMeter: [altUnitsPerMeter, altUnitsPerMeter, altUnitsPerMeter],
103
+ metersPerUnit: [1 / altUnitsPerMeter, 1 / altUnitsPerMeter, 1 / altUnitsPerMeter],
104
+ unitsPerDegree: [unitsPerDegreeX, unitsPerDegreeY, altUnitsPerMeter],
105
+ degreesPerUnit: [1 / unitsPerDegreeX, 1 / unitsPerDegreeY, 1 / altUnitsPerMeter]
106
+ };
107
+ /**
108
+ * Taylor series 2nd order for 1/latCosine
109
+ f'(a) * (x - a)
110
+ = d(1/cos(lat * DEGREES_TO_RADIANS))/d(lat) * dLat
111
+ = DEGREES_TO_RADIANS * tan(lat * DEGREES_TO_RADIANS) / cos(lat * DEGREES_TO_RADIANS) * dLat
112
+ */
113
+ if (highPrecision) {
114
+ const latCosine2 = (DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS)) / latCosine;
115
+ const unitsPerDegreeY2 = (unitsPerDegreeX * latCosine2) / 2;
116
+ const altUnitsPerDegree2 = (worldSize / EARTH_CIRCUMFERENCE) * latCosine2;
117
+ const altUnitsPerMeter2 = (altUnitsPerDegree2 / unitsPerDegreeY) * altUnitsPerMeter;
118
+ result.unitsPerDegree2 = [0, unitsPerDegreeY2, altUnitsPerDegree2];
119
+ result.unitsPerMeter2 = [altUnitsPerMeter2, 0, altUnitsPerMeter2];
120
+ }
121
+ // Main results, used for converting meters to latlng deltas and scaling offsets
122
+ return result;
123
+ }
124
+ /**
125
+ * Offset a lng/lat position by meterOffset (northing, easting)
126
+ */
127
+ export function addMetersToLngLat(lngLatZ, xyz) {
128
+ const [longitude, latitude, z0] = lngLatZ;
129
+ const [x, y, z] = xyz;
130
+ const { unitsPerMeter, unitsPerMeter2 } = getDistanceScales({
131
+ longitude,
132
+ latitude,
133
+ highPrecision: true
134
+ });
135
+ const worldspace = lngLatToWorld(lngLatZ);
136
+ worldspace[0] += x * (unitsPerMeter[0] + unitsPerMeter2[0] * y);
137
+ worldspace[1] += y * (unitsPerMeter[1] + unitsPerMeter2[1] * y);
138
+ // @ts-ignore
139
+ const newLngLat = worldToLngLat(worldspace);
140
+ const newZ = (z0 || 0) + (z || 0);
141
+ return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;
142
+ }
143
+ /**
144
+ *
145
+ * view and projection matrix creation is intentionally kept compatible with
146
+ * mapbox-gl's implementation to ensure that seamless interoperation
147
+ * with mapbox and react-map-gl. See: https://github.com/mapbox/mapbox-gl-js
148
+ */
149
+ export function getViewMatrix(options) {
150
+ const {
151
+ // Viewport props
152
+ height, pitch, bearing, altitude,
153
+ // Pre-calculated parameters
154
+ scale, center = null } = options;
155
+ // VIEW MATRIX: PROJECTS MERCATOR WORLD COORDINATES
156
+ // Note that mercator world coordinates typically need to be flipped
157
+ //
158
+ // Note: As usual, matrix operation orders should be read in reverse
159
+ // since vectors will be multiplied from the right during transformation
160
+ const vm = createMat4();
161
+ // Move camera to altitude (along the pitch & bearing direction)
162
+ mat4.translate(vm, vm, [0, 0, -altitude]);
163
+ // Rotate by bearing, and then by pitch (which tilts the view)
164
+ mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
165
+ mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
166
+ const relativeScale = scale / height;
167
+ mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);
168
+ if (center) {
169
+ mat4.translate(vm, vm, vec3.negate([], center));
170
+ }
171
+ return vm;
172
+ }
173
+ /**
174
+ * Calculates mapbox compatible projection matrix from parameters
175
+ *
176
+ * @param options.width Width of "viewport" or window
177
+ * @param options.height Height of "viewport" or window
178
+ * @param options.pitch Camera angle in degrees (0 is straight down)
179
+ * @param options.fovy field of view in degrees
180
+ * @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`
181
+ * @param options.nearZMultiplier control z buffer
182
+ * @param options.farZMultiplier control z buffer
183
+ * @returns project parameters object
184
+ */
185
+ export function getProjectionParameters(options) {
186
+ const { width, height, altitude, pitch = 0, nearZMultiplier = 1, farZMultiplier = 1 } = options;
187
+ let { fovy = altitudeToFovy(DEFAULT_ALTITUDE) } = options;
188
+ // For back-compatibility allow field of view to be
189
+ // derived from altitude
190
+ if (altitude !== undefined) {
191
+ fovy = altitudeToFovy(altitude);
192
+ }
193
+ const halfFov = 0.5 * fovy * DEGREES_TO_RADIANS;
194
+ const focalDistance = fovyToAltitude(fovy);
195
+ // Find the distance from the center point to the center top
196
+ // in focal distance units using law of sines.
197
+ const pitchRadians = pitch * DEGREES_TO_RADIANS;
198
+ const topHalfSurfaceDistance = (Math.sin(halfFov) * focalDistance) /
199
+ Math.sin(Math.min(Math.max(Math.PI / 2 - pitchRadians - halfFov, 0.01), Math.PI - 0.01));
200
+ // Calculate z value of the farthest fragment that should be rendered.
201
+ const farZ = Math.sin(pitchRadians) * topHalfSurfaceDistance + focalDistance;
202
+ return {
203
+ fov: 2 * halfFov,
204
+ aspect: width / height,
205
+ focalDistance,
206
+ near: nearZMultiplier,
207
+ far: farZ * farZMultiplier
208
+ };
209
+ }
210
+ /**
211
+ * CALCULATE PROJECTION MATRIX: PROJECTS FROM CAMERA (VIEW) SPACE TO CLIPSPACE
212
+ *
213
+ * To match mapbox's z buffer:
214
+ * - \<= 0.28: nearZMultiplier: 0.1, farZmultiplier: 1
215
+ * - \>= 0.29: nearZMultiplier: 1 / height, farZMultiplier: 1.01
216
+ *
217
+ * @param options Viewport options
218
+ * @param options.width Width of "viewport" or window
219
+ * @param options.height Height of "viewport" or window
220
+ * @param options.pitch Camera angle in degrees (0 is straight down)
221
+ * @param options.fovy field of view in degrees
222
+ * @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`
223
+ * @param options.nearZMultiplier control z buffer
224
+ * @param options.farZMultiplier control z buffer
225
+ * @returns 4x4 projection matrix
226
+ */
227
+ export function getProjectionMatrix(options) {
228
+ const { fov, aspect, near, far } = getProjectionParameters(options);
229
+ const projectionMatrix = mat4.perspective([], fov, // fov in radians
230
+ aspect, // aspect ratio
231
+ near, // near plane
232
+ far // far plane
233
+ );
234
+ return projectionMatrix;
235
+ }
236
+ /**
237
+ *
238
+ * Convert an altitude to field of view such that the
239
+ * focal distance is equal to the altitude
240
+ *
241
+ * @param altitude - altitude of camera in screen units
242
+ * @return fovy field of view in degrees
243
+ */
244
+ export function altitudeToFovy(altitude) {
245
+ return 2 * Math.atan(0.5 / altitude) * RADIANS_TO_DEGREES;
246
+ }
247
+ /**
248
+ *
249
+ * Convert an field of view such that the
250
+ * focal distance is equal to the altitude
251
+ *
252
+ * @param fovy - field of view in degrees
253
+ * @return altitude altitude of camera in screen units
254
+ */
255
+ export function fovyToAltitude(fovy) {
256
+ return 0.5 / Math.tan(0.5 * fovy * DEGREES_TO_RADIANS);
257
+ }
258
+ // Project flat coordinates to pixels on screen.
259
+ export function worldToPixels(xyz, pixelProjectionMatrix) {
260
+ const [x, y, z = 0] = xyz;
261
+ assert(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));
262
+ return transformVector(pixelProjectionMatrix, [x, y, z, 1]);
263
+ }
264
+ /**
265
+ * Unproject pixels on screen to flat coordinates.
266
+ *
267
+ * @param xyz - pixel coordinate on screen.
268
+ * @param pixelUnprojectionMatrix - unprojection matrix 4x4
269
+ * @param targetZ - if pixel coordinate does not have a 3rd component (depth),
270
+ * targetZ is used as the elevation plane to unproject onto
271
+ * @return [x, y, Z] flat coordinates on 512*512 Mercator Zoom 0 tile.
272
+ */
273
+ export function pixelsToWorld(xyz, pixelUnprojectionMatrix, targetZ = 0) {
274
+ const [x, y, z] = xyz;
275
+ assert(Number.isFinite(x) && Number.isFinite(y), 'invalid pixel coordinate');
276
+ if (Number.isFinite(z)) {
277
+ // Has depth component
278
+ const coord = transformVector(pixelUnprojectionMatrix, [x, y, z, 1]);
279
+ return coord;
280
+ }
281
+ // since we don't know the correct projected z value for the point,
282
+ // unproject two points to get a line and then find the point on that line with z=0
283
+ const coord0 = transformVector(pixelUnprojectionMatrix, [x, y, 0, 1]);
284
+ const coord1 = transformVector(pixelUnprojectionMatrix, [x, y, 1, 1]);
285
+ const z0 = coord0[2];
286
+ const z1 = coord1[2];
287
+ const t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
288
+ return vec2.lerp([], coord0, coord1, t);
289
+ }
@@ -0,0 +1,183 @@
1
+ import type { FitBoundsOptions } from './fit-bounds';
2
+ /**
3
+ * @param width=1 - Width of "viewport" or window
4
+ * @param height=1 - Height of "viewport" or window
5
+ * @param scale=1 - Either use scale or zoom
6
+ * @param pitch=0 - Camera angle in degrees (0 is straight down)
7
+ * @param bearing=0 - Map rotation in degrees (0 means north is up)
8
+ * @param fovy= - Field of view of camera in degrees
9
+ * @param altitude= - Altitude of camera in screen units
10
+ *
11
+ * Web mercator projection short-hand parameters
12
+ * @param latitude - Center of viewport on map
13
+ * @param longitude - Center of viewport on map
14
+ * @param zoom - Scale = Math.pow(2,zoom) on map
15
+
16
+ * Notes:
17
+ * - Only one of center or [latitude, longitude] can be specified
18
+ * - [latitude, longitude] can only be specified when "mercator" is true
19
+ * - Altitude has a default value that matches assumptions in mapbox-gl
20
+ * - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl
21
+ * - width and height are forced to 1 if supplied as 0, to avoid
22
+ * division by zero. This is intended to reduce the burden of apps to
23
+ * to check values before instantiating a Viewport.
24
+ */
25
+ export declare type WebMercatorViewportProps = {
26
+ width: number;
27
+ height: number;
28
+ latitude?: number;
29
+ longitude?: number;
30
+ position?: number[];
31
+ zoom?: number;
32
+ pitch?: number;
33
+ bearing?: number;
34
+ altitude?: number;
35
+ fovy?: number;
36
+ nearZMultiplier?: number;
37
+ farZMultiplier?: number;
38
+ };
39
+ /**
40
+ * The WebMercatorViewport class creates
41
+ * - view/projection matrices
42
+ * - "uniform values" (for shaders) from mercator params
43
+ *
44
+ * Note: Instances are immutable in the sense that they only have accessors.
45
+ * A new viewport instance should be created if any parameters have changed.
46
+ */
47
+ export default class WebMercatorViewport {
48
+ readonly latitude: number;
49
+ readonly longitude: number;
50
+ readonly zoom: number;
51
+ readonly pitch: number;
52
+ readonly bearing: number;
53
+ readonly altitude: number;
54
+ readonly fovy: number;
55
+ readonly meterOffset: number[];
56
+ readonly center: number[];
57
+ readonly width: number;
58
+ readonly height: number;
59
+ readonly scale: number;
60
+ readonly distanceScales: {
61
+ unitsPerMeter: number[];
62
+ };
63
+ readonly viewMatrix: number[];
64
+ readonly projectionMatrix: number[];
65
+ viewProjectionMatrix: number[];
66
+ pixelProjectionMatrix: number[];
67
+ pixelUnprojectionMatrix: number[];
68
+ /**
69
+ * @classdesc
70
+ * Creates view/projection matrices from mercator params
71
+ * Note: The Viewport is immutable in the sense that it only has accessors.
72
+ * A new viewport instance should be created if any parameters have changed.
73
+ */
74
+ constructor(props?: WebMercatorViewportProps);
75
+ _initMatrices(): void;
76
+ /** Two viewports are equal if width and height are identical, and if
77
+ * their view and projection matrices are (approximately) equal.
78
+ */
79
+ equals(viewport: WebMercatorViewport | null): boolean;
80
+ /**
81
+ * Projects xyz (possibly latitude and longitude) to pixel coordinates in window
82
+ * using viewport projection parameters
83
+ * - [longitude, latitude] to [x, y]
84
+ * - [longitude, latitude, Z] => [x, y, z]
85
+ * Note: By default, returns top-left coordinates for canvas/SVG type render
86
+ *
87
+ * @param lngLatZ - [lng, lat] or [lng, lat, Z]
88
+ * @param options - options
89
+ * @param options.topLeft=true - Whether projected coords are top left
90
+ * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth
91
+ */
92
+ project(lngLatZ: number[], options?: {
93
+ topLeft?: boolean;
94
+ }): number[];
95
+ /**
96
+ * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.
97
+ *
98
+ * - [x, y] => [lng, lat]
99
+ * - [x, y, z] => [lng, lat, Z]
100
+ *
101
+ * @param xyz - screen coordinates, z as pixel depth
102
+ * @param options - options
103
+ * @param options.topLeft=true - Whether projected coords are top left
104
+ * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as
105
+ * the elevation plane to unproject onto
106
+ * @return - [lng, lat, Z] or [X, Y, Z]
107
+ */
108
+ unproject(xyz: number[], options?: {
109
+ topLeft?: boolean;
110
+ targetZ?: number;
111
+ }): number[];
112
+ projectPosition(xyz: any): number[];
113
+ unprojectPosition(xyz: any): number[];
114
+ /**
115
+ * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
116
+ * Performs the nonlinear part of the web mercator projection.
117
+ * Remaining projection is done with 4x4 matrices which also handles
118
+ * perspective.
119
+ *
120
+ * @param lngLat - [lng, lat] coordinates
121
+ * Specifies a point on the sphere to project onto the map.
122
+ * @return [x,y] coordinates.
123
+ */
124
+ projectFlat(lngLat: number[]): number[];
125
+ /**
126
+ * Unproject world point [x,y] on map onto {lat, lon} on sphere
127
+ *
128
+ * @param xy - array with [x,y] members
129
+ * representing point on projected map plane
130
+ * @return - array with [lat,lon] of point on sphere.
131
+ * Has toArray method if you need a GeoJSON Array.
132
+ * Per cartographic tradition, lat and lon are specified as degrees.
133
+ */
134
+ unprojectFlat(xy: number[]): number[];
135
+ /**
136
+ * Get the map center that place a given [lng, lat] coordinate at screen point [x, y]
137
+ * @param opt
138
+ * @param opt.lngLat - [lng,lat] coordinates
139
+ * Specifies a point on the sphere.
140
+ * @param opt.pos - [x,y] coordinates
141
+ * Specifies a point on the screen.
142
+ * @return [lng,lat] new map center.
143
+ */
144
+ getMapCenterByLngLatPosition({ lngLat, pos }: {
145
+ lngLat: number[];
146
+ pos: number[];
147
+ }): number[];
148
+ /**
149
+ * Returns a new viewport that fit around the given rectangle.
150
+ * Only supports non-perspective mode.
151
+ * @param bounds - [[lon, lat], [lon, lat]]
152
+ * @param [options]
153
+ * @param [options.padding] - The amount of padding in pixels to add to the given bounds.
154
+ * @param [options.offset] - The center of the given bounds relative to the map's center,
155
+ * [x, y] measured in pixels.
156
+ * @returns {WebMercatorViewport}
157
+ */
158
+ fitBounds(bounds: [[number, number], [number, number]], options?: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'>): WebMercatorViewport;
159
+ /**
160
+ * Returns the bounding box of the viewport.
161
+ * @param [options]
162
+ * @param [options.z] - The altitude at which the bounds should be calculated.
163
+ * @returns {Array} bounds - [[lon, lat], [lon, lat]]
164
+ */
165
+ getBounds(options?: {
166
+ z?: number;
167
+ }): number[][];
168
+ /**
169
+ * Returns the bounding box of the viewport.
170
+ * @param [options]
171
+ * @param [options.z] - The altitude at which the bounds should be calculated.
172
+ * @returns {Array} an array of 4 points that define the visible region
173
+ */
174
+ getBoundingRegion(options?: {
175
+ z?: number;
176
+ }): number[][];
177
+ /** @deprecated Legacy method name */
178
+ getLocationAtPoint({ lngLat, pos }: {
179
+ lngLat: number[];
180
+ pos: number[];
181
+ }): number[];
182
+ }
183
+ //# sourceMappingURL=web-mercator-viewport.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"web-mercator-viewport.d.ts","sourceRoot":"","sources":["../src/web-mercator-viewport.ts"],"names":[],"mappings":"AAkBA,OAAO,KAAK,EAAS,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAM3D;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,oBAAY,wBAAwB,GAAG;IAErC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB,CAAC;AAEF;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,OAAO,mBAAmB;IACtC,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAC3B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAEtB,QAAQ,CAAC,WA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