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