@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,417 @@
1
+ // View and Projection Matrix calculations for mapbox-js style map view properties
2
+ import {createMat4} from './math-utils';
3
+
4
+ import {
5
+ zoomToScale,
6
+ pixelsToWorld,
7
+ lngLatToWorld,
8
+ worldToLngLat,
9
+ worldToPixels,
10
+ altitudeToFovy,
11
+ fovyToAltitude,
12
+ DEFAULT_ALTITUDE,
13
+ getProjectionMatrix,
14
+ getDistanceScales,
15
+ getViewMatrix
16
+ } from './web-mercator-utils';
17
+ import fitBounds from './fit-bounds';
18
+ import getBounds from './get-bounds';
19
+ import type {Bounds, FitBoundsOptions} from './fit-bounds';
20
+
21
+ import * as mat4 from 'gl-matrix/mat4';
22
+ import * as vec2 from 'gl-matrix/vec2';
23
+ import * as vec3 from 'gl-matrix/vec3';
24
+
25
+ /**
26
+ * @param width=1 - Width of "viewport" or window
27
+ * @param height=1 - Height of "viewport" or window
28
+ * @param scale=1 - Either use scale or zoom
29
+ * @param pitch=0 - Camera angle in degrees (0 is straight down)
30
+ * @param bearing=0 - Map rotation in degrees (0 means north is up)
31
+ * @param fovy= - Field of view of camera in degrees
32
+ * @param altitude= - Altitude of camera in screen units
33
+ *
34
+ * Web mercator projection short-hand parameters
35
+ * @param latitude - Center of viewport on map
36
+ * @param longitude - Center of viewport on map
37
+ * @param zoom - Scale = Math.pow(2,zoom) on map
38
+
39
+ * Notes:
40
+ * - Only one of center or [latitude, longitude] can be specified
41
+ * - [latitude, longitude] can only be specified when "mercator" is true
42
+ * - Altitude has a default value that matches assumptions in mapbox-gl
43
+ * - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl
44
+ * - width and height are forced to 1 if supplied as 0, to avoid
45
+ * division by zero. This is intended to reduce the burden of apps to
46
+ * to check values before instantiating a Viewport.
47
+ */
48
+ export type WebMercatorViewportProps = {
49
+ // Map state
50
+ width: number;
51
+ height: number;
52
+ latitude?: number;
53
+ longitude?: number;
54
+ position?: number[];
55
+ zoom?: number;
56
+ pitch?: number;
57
+ bearing?: number;
58
+ altitude?: number;
59
+ fovy?: number;
60
+ nearZMultiplier?: number;
61
+ farZMultiplier?: number;
62
+ };
63
+
64
+ /**
65
+ * The WebMercatorViewport class creates
66
+ * - view/projection matrices
67
+ * - "uniform values" (for shaders) from mercator params
68
+ *
69
+ * Note: Instances are immutable in the sense that they only have accessors.
70
+ * A new viewport instance should be created if any parameters have changed.
71
+ */
72
+ export default class WebMercatorViewport {
73
+ readonly latitude: number;
74
+ readonly longitude: number;
75
+ readonly zoom: number;
76
+ readonly pitch: number;
77
+ readonly bearing: number;
78
+ readonly altitude: number;
79
+ readonly fovy: number;
80
+
81
+ readonly meterOffset: number[];
82
+ readonly center: number[];
83
+
84
+ readonly width: number;
85
+ readonly height: number;
86
+ readonly scale: number;
87
+ readonly distanceScales: {
88
+ unitsPerMeter: number[];
89
+ };
90
+
91
+ readonly viewMatrix: number[];
92
+ readonly projectionMatrix: number[];
93
+
94
+ viewProjectionMatrix: number[];
95
+ pixelProjectionMatrix: number[];
96
+ pixelUnprojectionMatrix: number[];
97
+
98
+ /**
99
+ * @classdesc
100
+ * Creates view/projection matrices from mercator params
101
+ * Note: The Viewport is immutable in the sense that it only has accessors.
102
+ * A new viewport instance should be created if any parameters have changed.
103
+ */
104
+ // eslint-disable-next-line max-statements
105
+ constructor(props: WebMercatorViewportProps = {width: 1, height: 1}) {
106
+ let {
107
+ // Map state
108
+ width,
109
+ height,
110
+ altitude = null,
111
+ fovy = null
112
+ } = props;
113
+ const {
114
+ latitude = 0,
115
+ longitude = 0,
116
+ zoom = 0,
117
+ pitch = 0,
118
+ bearing = 0,
119
+ position = null,
120
+ nearZMultiplier = 0.02,
121
+ farZMultiplier = 1.01
122
+ } = props;
123
+
124
+ // Silently allow apps to send in 0,0 to facilitate isomorphic render etc
125
+ width = width || 1;
126
+ height = height || 1;
127
+
128
+ // `fovy` & `altitude` are independent parameters, one for the
129
+ // projection and the latter for the view matrix. In the past,
130
+ // the `fovy` was always derived from the `altitude`
131
+ if (fovy === null && altitude === null) {
132
+ altitude = DEFAULT_ALTITUDE;
133
+ fovy = altitudeToFovy(altitude);
134
+ } else if (fovy === null) {
135
+ fovy = altitudeToFovy(altitude);
136
+ } else if (altitude === null) {
137
+ altitude = fovyToAltitude(fovy);
138
+ }
139
+
140
+ const scale = zoomToScale(zoom);
141
+ // Altitude - prevent division by 0
142
+ // TODO - just throw an Error instead?
143
+ altitude = Math.max(0.75, altitude);
144
+
145
+ const distanceScales = getDistanceScales({longitude, latitude});
146
+
147
+ const center = lngLatToWorld([longitude, latitude]);
148
+ center[2] = 0;
149
+
150
+ if (position) {
151
+ vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));
152
+ }
153
+
154
+ this.projectionMatrix = getProjectionMatrix({
155
+ width,
156
+ height,
157
+ pitch,
158
+ fovy,
159
+ nearZMultiplier,
160
+ farZMultiplier
161
+ });
162
+
163
+ this.viewMatrix = getViewMatrix({
164
+ height,
165
+ scale,
166
+ center,
167
+ pitch,
168
+ bearing,
169
+ altitude
170
+ });
171
+
172
+ // Save parameters
173
+ this.width = width;
174
+ this.height = height;
175
+ this.scale = scale;
176
+
177
+ this.latitude = latitude;
178
+ this.longitude = longitude;
179
+ this.zoom = zoom;
180
+ this.pitch = pitch;
181
+ this.bearing = bearing;
182
+ this.altitude = altitude;
183
+ this.fovy = fovy;
184
+ this.center = center;
185
+ this.meterOffset = position || [0, 0, 0];
186
+
187
+ this.distanceScales = distanceScales;
188
+
189
+ this._initMatrices();
190
+
191
+ // Bind methods for easy access
192
+ this.equals = this.equals.bind(this);
193
+ this.project = this.project.bind(this);
194
+ this.unproject = this.unproject.bind(this);
195
+ this.projectPosition = this.projectPosition.bind(this);
196
+ this.unprojectPosition = this.unprojectPosition.bind(this);
197
+
198
+ Object.freeze(this);
199
+ }
200
+
201
+ _initMatrices() {
202
+ const {width, height, projectionMatrix, viewMatrix} = this;
203
+
204
+ // Note: As usual, matrix operations should be applied in "reverse" order
205
+ // since vectors will be multiplied in from the right during transformation
206
+ const vpm = createMat4();
207
+ mat4.multiply(vpm, vpm, projectionMatrix);
208
+ mat4.multiply(vpm, vpm, viewMatrix);
209
+ this.viewProjectionMatrix = vpm;
210
+
211
+ // Calculate matrices and scales needed for projection
212
+ /**
213
+ * Builds matrices that converts preprojected lngLats to screen pixels
214
+ * and vice versa.
215
+ * Note: Currently returns bottom-left coordinates!
216
+ * Note: Starts with the GL projection matrix and adds steps to the
217
+ * scale and translate that matrix onto the window.
218
+ * Note: WebGL controls clip space to screen projection with gl.viewport
219
+ * and does not need this step.
220
+ */
221
+ const m = createMat4();
222
+
223
+ // matrix for conversion from location to screen coordinates
224
+ mat4.scale(m, m, [width / 2, -height / 2, 1]);
225
+ mat4.translate(m, m, [1, -1, 0]);
226
+ mat4.multiply(m, m, vpm);
227
+
228
+ const mInverse = mat4.invert(createMat4(), m);
229
+ if (!mInverse) {
230
+ throw new Error('Pixel project matrix not invertible');
231
+ }
232
+
233
+ this.pixelProjectionMatrix = m;
234
+ this.pixelUnprojectionMatrix = mInverse;
235
+ }
236
+
237
+ /** Two viewports are equal if width and height are identical, and if
238
+ * their view and projection matrices are (approximately) equal.
239
+ */
240
+ equals(viewport: WebMercatorViewport | null): boolean {
241
+ if (!(viewport instanceof WebMercatorViewport)) {
242
+ return false;
243
+ }
244
+
245
+ return (
246
+ viewport.width === this.width &&
247
+ viewport.height === this.height &&
248
+ mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&
249
+ mat4.equals(viewport.viewMatrix, this.viewMatrix)
250
+ );
251
+ }
252
+
253
+ /**
254
+ * Projects xyz (possibly latitude and longitude) to pixel coordinates in window
255
+ * using viewport projection parameters
256
+ * - [longitude, latitude] to [x, y]
257
+ * - [longitude, latitude, Z] => [x, y, z]
258
+ * Note: By default, returns top-left coordinates for canvas/SVG type render
259
+ *
260
+ * @param lngLatZ - [lng, lat] or [lng, lat, Z]
261
+ * @param options - options
262
+ * @param options.topLeft=true - Whether projected coords are top left
263
+ * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth
264
+ */
265
+ project(lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] {
266
+ const {topLeft = true} = options;
267
+ const worldPosition = this.projectPosition(lngLatZ);
268
+ const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);
269
+
270
+ const [x, y] = coord;
271
+ const y2 = topLeft ? y : this.height - y;
272
+ return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
273
+ }
274
+
275
+ /**
276
+ * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.
277
+ *
278
+ * - [x, y] => [lng, lat]
279
+ * - [x, y, z] => [lng, lat, Z]
280
+ *
281
+ * @param xyz - screen coordinates, z as pixel depth
282
+ * @param options - options
283
+ * @param options.topLeft=true - Whether projected coords are top left
284
+ * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as
285
+ * the elevation plane to unproject onto
286
+ * @return - [lng, lat, Z] or [X, Y, Z]
287
+ */
288
+ unproject(xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] {
289
+ const {topLeft = true, targetZ = undefined} = options;
290
+ const [x, y, z] = xyz;
291
+
292
+ const y2 = topLeft ? y : this.height - y;
293
+ const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
294
+ const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);
295
+ const [X, Y, Z] = this.unprojectPosition(coord);
296
+
297
+ if (Number.isFinite(z)) {
298
+ return [X, Y, Z];
299
+ }
300
+ return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
301
+ }
302
+
303
+ // NON_LINEAR PROJECTION HOOKS
304
+ // Used for web meractor projection
305
+
306
+ projectPosition(xyz) {
307
+ const [X, Y] = lngLatToWorld(xyz);
308
+ const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
309
+ return [X, Y, Z];
310
+ }
311
+
312
+ unprojectPosition(xyz) {
313
+ const [X, Y] = worldToLngLat(xyz);
314
+ // @ts-expect-error
315
+ const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
316
+ return [X, Y, Z];
317
+ }
318
+
319
+ /**
320
+ * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
321
+ * Performs the nonlinear part of the web mercator projection.
322
+ * Remaining projection is done with 4x4 matrices which also handles
323
+ * perspective.
324
+ *
325
+ * @param lngLat - [lng, lat] coordinates
326
+ * Specifies a point on the sphere to project onto the map.
327
+ * @return [x,y] coordinates.
328
+ */
329
+ projectFlat(lngLat: number[]): number[] {
330
+ return lngLatToWorld(lngLat);
331
+ }
332
+
333
+ /**
334
+ * Unproject world point [x,y] on map onto {lat, lon} on sphere
335
+ *
336
+ * @param xy - array with [x,y] members
337
+ * representing point on projected map plane
338
+ * @return - array with [lat,lon] of point on sphere.
339
+ * Has toArray method if you need a GeoJSON Array.
340
+ * Per cartographic tradition, lat and lon are specified as degrees.
341
+ */
342
+ unprojectFlat(xy: number[]): number[] {
343
+ return worldToLngLat(xy);
344
+ }
345
+
346
+ /**
347
+ * Get the map center that place a given [lng, lat] coordinate at screen point [x, y]
348
+ * @param opt
349
+ * @param opt.lngLat - [lng,lat] coordinates
350
+ * Specifies a point on the sphere.
351
+ * @param opt.pos - [x,y] coordinates
352
+ * Specifies a point on the screen.
353
+ * @return [lng,lat] new map center.
354
+ */
355
+ getMapCenterByLngLatPosition({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {
356
+ const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);
357
+ const toLocation = lngLatToWorld(lngLat);
358
+ const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));
359
+ const newCenter = vec2.add([], this.center, translate);
360
+ return worldToLngLat(newCenter);
361
+ }
362
+
363
+ /**
364
+ * Returns a new viewport that fit around the given rectangle.
365
+ * Only supports non-perspective mode.
366
+ * @param bounds - [[lon, lat], [lon, lat]]
367
+ * @param [options]
368
+ * @param [options.padding] - The amount of padding in pixels to add to the given bounds.
369
+ * @param [options.offset] - The center of the given bounds relative to the map's center,
370
+ * [x, y] measured in pixels.
371
+ * @returns {WebMercatorViewport}
372
+ */
373
+ fitBounds(
374
+ bounds: [[number, number], [number, number]],
375
+ options: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'> = {}
376
+ ): WebMercatorViewport {
377
+ const {width, height} = this;
378
+ const {longitude, latitude, zoom} = fitBounds(Object.assign({width, height, bounds}, options));
379
+ return new WebMercatorViewport({width, height, longitude, latitude, zoom});
380
+ }
381
+
382
+ /**
383
+ * Returns the bounding box of the viewport.
384
+ * @param [options]
385
+ * @param [options.z] - The altitude at which the bounds should be calculated.
386
+ * @returns {Array} bounds - [[lon, lat], [lon, lat]]
387
+ */
388
+ getBounds(options?: {z?: number}): number[][] {
389
+ const corners = this.getBoundingRegion(options);
390
+
391
+ const west = Math.min(...corners.map((p) => p[0]));
392
+ const east = Math.max(...corners.map((p) => p[0]));
393
+ const south = Math.min(...corners.map((p) => p[1]));
394
+ const north = Math.max(...corners.map((p) => p[1]));
395
+ return [
396
+ [west, south],
397
+ [east, north]
398
+ ];
399
+ }
400
+
401
+ /**
402
+ * Returns the bounding box of the viewport.
403
+ * @param [options]
404
+ * @param [options.z] - The altitude at which the bounds should be calculated.
405
+ * @returns {Array} an array of 4 points that define the visible region
406
+ */
407
+ getBoundingRegion(options: {z?: number} = {}): number[][] {
408
+ return getBounds(this, options.z || 0);
409
+ }
410
+
411
+ // DEPRECATED
412
+
413
+ /** @deprecated Legacy method name */
414
+ getLocationAtPoint({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {
415
+ return this.getMapCenterByLngLatPosition({lngLat, pos});
416
+ }
417
+ }
@@ -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;
@@ -1,3 +0,0 @@
1
- import WebMercatorViewport from './web-mercator-viewport';
2
-
3
- export default function getBounds(viewport : WebMercatorViewport, z? : number) : Array<number[]>;
@@ -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;