@math.gl/geospatial 5.0.0-beta.11 → 5.0.0-beta.12

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 (276) hide show
  1. package/README.md +3 -3
  2. package/dist/index.cjs +725 -229
  3. package/dist/index.cjs.map +3 -3
  4. package/dist/index.d.ts +5 -0
  5. package/dist/index.d.ts.map +1 -1
  6. package/dist/index.js +4 -0
  7. package/dist/index.js.map +1 -1
  8. package/dist/projection/experimental/core.cjs.map +1 -1
  9. package/dist/projection/experimental/crs/spatial-reference.d.ts.map +1 -1
  10. package/dist/projection/experimental/crs/spatial-reference.js.map +1 -1
  11. package/dist/projection/experimental/crs/types.d.ts.map +1 -1
  12. package/dist/projection/experimental/lazy-projections/aea.cjs +4 -1
  13. package/dist/projection/experimental/lazy-projections/aea.cjs.map +1 -1
  14. package/dist/projection/experimental/lazy-projections/aea.d.ts.map +1 -1
  15. package/dist/projection/experimental/lazy-projections/aea.js +4 -1
  16. package/dist/projection/experimental/lazy-projections/aea.js.map +1 -1
  17. package/dist/projection/experimental/lazy-projections/bonne.cjs +4 -1
  18. package/dist/projection/experimental/lazy-projections/bonne.cjs.map +1 -1
  19. package/dist/projection/experimental/lazy-projections/bonne.d.ts.map +1 -1
  20. package/dist/projection/experimental/lazy-projections/bonne.js +4 -1
  21. package/dist/projection/experimental/lazy-projections/bonne.js.map +1 -1
  22. package/dist/projection/experimental/lazy-projections/cass.cjs +4 -1
  23. package/dist/projection/experimental/lazy-projections/cass.cjs.map +1 -1
  24. package/dist/projection/experimental/lazy-projections/cass.d.ts.map +1 -1
  25. package/dist/projection/experimental/lazy-projections/cass.js +4 -1
  26. package/dist/projection/experimental/lazy-projections/cass.js.map +1 -1
  27. package/dist/projection/experimental/lazy-projections/eck6.cjs +4 -1
  28. package/dist/projection/experimental/lazy-projections/eck6.cjs.map +1 -1
  29. package/dist/projection/experimental/lazy-projections/eck6.d.ts.map +1 -1
  30. package/dist/projection/experimental/lazy-projections/eck6.js +4 -1
  31. package/dist/projection/experimental/lazy-projections/eck6.js.map +1 -1
  32. package/dist/projection/experimental/lazy-projections/eqdc.cjs +4 -1
  33. package/dist/projection/experimental/lazy-projections/eqdc.cjs.map +1 -1
  34. package/dist/projection/experimental/lazy-projections/eqdc.d.ts.map +1 -1
  35. package/dist/projection/experimental/lazy-projections/eqdc.js +4 -1
  36. package/dist/projection/experimental/lazy-projections/eqdc.js.map +1 -1
  37. package/dist/projection/experimental/lazy-projections/eqearth.cjs +4 -1
  38. package/dist/projection/experimental/lazy-projections/eqearth.cjs.map +1 -1
  39. package/dist/projection/experimental/lazy-projections/eqearth.d.ts.map +1 -1
  40. package/dist/projection/experimental/lazy-projections/eqearth.js +4 -1
  41. package/dist/projection/experimental/lazy-projections/eqearth.js.map +1 -1
  42. package/dist/projection/experimental/lazy-projections/equi.cjs +4 -1
  43. package/dist/projection/experimental/lazy-projections/equi.cjs.map +1 -1
  44. package/dist/projection/experimental/lazy-projections/equi.d.ts.map +1 -1
  45. package/dist/projection/experimental/lazy-projections/equi.js +4 -1
  46. package/dist/projection/experimental/lazy-projections/equi.js.map +1 -1
  47. package/dist/projection/experimental/lazy-projections/geocent.cjs +4 -1
  48. package/dist/projection/experimental/lazy-projections/geocent.cjs.map +1 -1
  49. package/dist/projection/experimental/lazy-projections/geocent.d.ts.map +1 -1
  50. package/dist/projection/experimental/lazy-projections/geocent.js +4 -1
  51. package/dist/projection/experimental/lazy-projections/geocent.js.map +1 -1
  52. package/dist/projection/experimental/lazy-projections/geos.cjs +4 -1
  53. package/dist/projection/experimental/lazy-projections/geos.cjs.map +1 -1
  54. package/dist/projection/experimental/lazy-projections/geos.d.ts.map +1 -1
  55. package/dist/projection/experimental/lazy-projections/geos.js +4 -1
  56. package/dist/projection/experimental/lazy-projections/geos.js.map +1 -1
  57. package/dist/projection/experimental/lazy-projections/gnom.cjs +4 -1
  58. package/dist/projection/experimental/lazy-projections/gnom.cjs.map +1 -1
  59. package/dist/projection/experimental/lazy-projections/gnom.d.ts.map +1 -1
  60. package/dist/projection/experimental/lazy-projections/gnom.js +4 -1
  61. package/dist/projection/experimental/lazy-projections/gnom.js.map +1 -1
  62. package/dist/projection/experimental/lazy-projections/index.cjs +92 -23
  63. package/dist/projection/experimental/lazy-projections/index.cjs.map +1 -1
  64. package/dist/projection/experimental/lazy-projections/krovak.cjs +4 -1
  65. package/dist/projection/experimental/lazy-projections/krovak.cjs.map +1 -1
  66. package/dist/projection/experimental/lazy-projections/krovak.d.ts.map +1 -1
  67. package/dist/projection/experimental/lazy-projections/krovak.js +4 -1
  68. package/dist/projection/experimental/lazy-projections/krovak.js.map +1 -1
  69. package/dist/projection/experimental/lazy-projections/merc.cjs +4 -1
  70. package/dist/projection/experimental/lazy-projections/merc.cjs.map +1 -1
  71. package/dist/projection/experimental/lazy-projections/merc.d.ts.map +1 -1
  72. package/dist/projection/experimental/lazy-projections/merc.js +4 -1
  73. package/dist/projection/experimental/lazy-projections/merc.js.map +1 -1
  74. package/dist/projection/experimental/lazy-projections/mill.cjs +4 -1
  75. package/dist/projection/experimental/lazy-projections/mill.cjs.map +1 -1
  76. package/dist/projection/experimental/lazy-projections/mill.d.ts.map +1 -1
  77. package/dist/projection/experimental/lazy-projections/mill.js +4 -1
  78. package/dist/projection/experimental/lazy-projections/mill.js.map +1 -1
  79. package/dist/projection/experimental/lazy-projections/moll.cjs +4 -1
  80. package/dist/projection/experimental/lazy-projections/moll.cjs.map +1 -1
  81. package/dist/projection/experimental/lazy-projections/moll.d.ts.map +1 -1
  82. package/dist/projection/experimental/lazy-projections/moll.js +4 -1
  83. package/dist/projection/experimental/lazy-projections/moll.js.map +1 -1
  84. package/dist/projection/experimental/lazy-projections/nzmg.cjs +4 -1
  85. package/dist/projection/experimental/lazy-projections/nzmg.cjs.map +1 -1
  86. package/dist/projection/experimental/lazy-projections/nzmg.d.ts.map +1 -1
  87. package/dist/projection/experimental/lazy-projections/nzmg.js +4 -1
  88. package/dist/projection/experimental/lazy-projections/nzmg.js.map +1 -1
  89. package/dist/projection/experimental/lazy-projections/omerc.cjs +4 -1
  90. package/dist/projection/experimental/lazy-projections/omerc.cjs.map +1 -1
  91. package/dist/projection/experimental/lazy-projections/omerc.d.ts.map +1 -1
  92. package/dist/projection/experimental/lazy-projections/omerc.js +4 -1
  93. package/dist/projection/experimental/lazy-projections/omerc.js.map +1 -1
  94. package/dist/projection/experimental/lazy-projections/ortho.cjs +4 -1
  95. package/dist/projection/experimental/lazy-projections/ortho.cjs.map +1 -1
  96. package/dist/projection/experimental/lazy-projections/ortho.d.ts.map +1 -1
  97. package/dist/projection/experimental/lazy-projections/ortho.js +4 -1
  98. package/dist/projection/experimental/lazy-projections/ortho.js.map +1 -1
  99. package/dist/projection/experimental/lazy-projections/poly.cjs +4 -1
  100. package/dist/projection/experimental/lazy-projections/poly.cjs.map +1 -1
  101. package/dist/projection/experimental/lazy-projections/poly.d.ts.map +1 -1
  102. package/dist/projection/experimental/lazy-projections/poly.js +4 -1
  103. package/dist/projection/experimental/lazy-projections/poly.js.map +1 -1
  104. package/dist/projection/experimental/lazy-projections/robin.cjs +4 -1
  105. package/dist/projection/experimental/lazy-projections/robin.cjs.map +1 -1
  106. package/dist/projection/experimental/lazy-projections/robin.d.ts.map +1 -1
  107. package/dist/projection/experimental/lazy-projections/robin.js +4 -1
  108. package/dist/projection/experimental/lazy-projections/robin.js.map +1 -1
  109. package/dist/projection/experimental/lazy-projections/sinu.cjs +4 -1
  110. package/dist/projection/experimental/lazy-projections/sinu.cjs.map +1 -1
  111. package/dist/projection/experimental/lazy-projections/sinu.d.ts.map +1 -1
  112. package/dist/projection/experimental/lazy-projections/sinu.js +4 -1
  113. package/dist/projection/experimental/lazy-projections/sinu.js.map +1 -1
  114. package/dist/projection/experimental/lazy-projections/stere.cjs +4 -1
  115. package/dist/projection/experimental/lazy-projections/stere.cjs.map +1 -1
  116. package/dist/projection/experimental/lazy-projections/stere.d.ts.map +1 -1
  117. package/dist/projection/experimental/lazy-projections/stere.js +4 -1
  118. package/dist/projection/experimental/lazy-projections/stere.js.map +1 -1
  119. package/dist/projection/experimental/lazy-projections/tpers.cjs +4 -1
  120. package/dist/projection/experimental/lazy-projections/tpers.cjs.map +1 -1
  121. package/dist/projection/experimental/lazy-projections/tpers.d.ts.map +1 -1
  122. package/dist/projection/experimental/lazy-projections/tpers.js +4 -1
  123. package/dist/projection/experimental/lazy-projections/tpers.js.map +1 -1
  124. package/dist/projection/experimental/lazy-projections/vandg.cjs +4 -1
  125. package/dist/projection/experimental/lazy-projections/vandg.cjs.map +1 -1
  126. package/dist/projection/experimental/lazy-projections/vandg.d.ts.map +1 -1
  127. package/dist/projection/experimental/lazy-projections/vandg.js +4 -1
  128. package/dist/projection/experimental/lazy-projections/vandg.js.map +1 -1
  129. package/dist/projection/index.cjs.map +1 -1
  130. package/dist/projection/index.d.ts.map +1 -1
  131. package/dist/projection/index.js.map +1 -1
  132. package/dist/projection/lib/projection.js.map +1 -1
  133. package/dist/projection/pipeline.cjs.map +1 -1
  134. package/dist/projection/transform-analysis.cjs.map +1 -1
  135. package/dist/tasks/index.cjs.map +1 -1
  136. package/dist/terrain/cutout-polygons.d.ts +21 -0
  137. package/dist/terrain/cutout-polygons.d.ts.map +1 -0
  138. package/dist/terrain/cutout-polygons.js +172 -0
  139. package/dist/terrain/cutout-polygons.js.map +1 -0
  140. package/dist/terrain/cutout-region.d.ts +34 -0
  141. package/dist/terrain/cutout-region.d.ts.map +1 -0
  142. package/dist/terrain/cutout-region.js +33 -0
  143. package/dist/terrain/cutout-region.js.map +1 -0
  144. package/dist/terrain/geographic-cutout.d.ts +38 -0
  145. package/dist/terrain/geographic-cutout.d.ts.map +1 -0
  146. package/dist/terrain/geographic-cutout.js +120 -0
  147. package/dist/terrain/geographic-cutout.js.map +1 -0
  148. package/dist/terrain/index.cjs +532 -36
  149. package/dist/terrain/index.cjs.map +3 -3
  150. package/dist/terrain/index.d.ts +5 -0
  151. package/dist/terrain/index.d.ts.map +1 -1
  152. package/dist/terrain/index.js +4 -0
  153. package/dist/terrain/index.js.map +1 -1
  154. package/dist/terrain/mesh-cutout.d.ts +10 -5
  155. package/dist/terrain/mesh-cutout.d.ts.map +1 -1
  156. package/dist/terrain/mesh-cutout.js +62 -20
  157. package/dist/terrain/mesh-cutout.js.map +1 -1
  158. package/dist/terrain/tile-cutout-update.d.ts +73 -0
  159. package/dist/terrain/tile-cutout-update.d.ts.map +1 -0
  160. package/dist/terrain/tile-cutout-update.js +181 -0
  161. package/dist/terrain/tile-cutout-update.js.map +1 -0
  162. package/dist/terrain/tile-cutout.d.ts +33 -0
  163. package/dist/terrain/tile-cutout.d.ts.map +1 -0
  164. package/dist/terrain/tile-cutout.js +93 -0
  165. package/dist/terrain/tile-cutout.js.map +1 -0
  166. package/dist/turf/expressions.cjs +4 -4
  167. package/dist/turf/expressions.cjs.map +2 -2
  168. package/dist/turf/expressions.d.ts +1 -1
  169. package/dist/turf/expressions.d.ts.map +1 -1
  170. package/dist/turf/expressions.js +2 -2
  171. package/dist/turf/expressions.js.map +1 -1
  172. package/dist/turf.cjs +25 -25
  173. package/dist/turf.cjs.map +2 -2
  174. package/dist/turf.d.ts +1 -1
  175. package/dist/turf.d.ts.map +1 -1
  176. package/dist/turf.js +2 -2
  177. package/dist/turf.js.map +1 -1
  178. package/dist/web-mercator/assert.d.ts +2 -0
  179. package/dist/web-mercator/assert.d.ts.map +1 -0
  180. package/dist/web-mercator/assert.js +12 -0
  181. package/dist/web-mercator/assert.js.map +1 -0
  182. package/dist/web-mercator/fit-bounds.d.ts +52 -0
  183. package/dist/web-mercator/fit-bounds.d.ts.map +1 -0
  184. package/dist/web-mercator/fit-bounds.js +70 -0
  185. package/dist/web-mercator/fit-bounds.js.map +1 -0
  186. package/dist/web-mercator/fly-to-viewport.d.ts +19 -0
  187. package/dist/web-mercator/fly-to-viewport.d.ts.map +1 -0
  188. package/dist/web-mercator/fly-to-viewport.js +94 -0
  189. package/dist/web-mercator/fly-to-viewport.js.map +1 -0
  190. package/dist/web-mercator/get-bounds.d.ts +3 -0
  191. package/dist/web-mercator/get-bounds.d.ts.map +1 -0
  192. package/dist/web-mercator/get-bounds.js +56 -0
  193. package/dist/web-mercator/get-bounds.js.map +1 -0
  194. package/dist/web-mercator/index.cjs +705 -0
  195. package/dist/web-mercator/index.cjs.map +6 -0
  196. package/dist/web-mercator/index.d.ts +14 -0
  197. package/dist/web-mercator/index.d.ts.map +1 -0
  198. package/dist/web-mercator/index.js +14 -0
  199. package/dist/web-mercator/index.js.map +1 -0
  200. package/dist/web-mercator/math-utils.d.ts +7 -0
  201. package/dist/web-mercator/math-utils.d.ts.map +1 -0
  202. package/dist/web-mercator/math-utils.js +30 -0
  203. package/dist/web-mercator/math-utils.js.map +1 -0
  204. package/dist/web-mercator/mercator-meters.d.ts +29 -0
  205. package/dist/web-mercator/mercator-meters.d.ts.map +1 -0
  206. package/dist/web-mercator/mercator-meters.js +61 -0
  207. package/dist/web-mercator/mercator-meters.js.map +1 -0
  208. package/dist/web-mercator/normalize-viewport-props.d.ts +16 -0
  209. package/dist/web-mercator/normalize-viewport-props.d.ts.map +1 -0
  210. package/dist/web-mercator/normalize-viewport-props.js +45 -0
  211. package/dist/web-mercator/normalize-viewport-props.js.map +1 -0
  212. package/dist/web-mercator/web-mercator-utils.d.ts +192 -0
  213. package/dist/web-mercator/web-mercator-utils.d.ts.map +1 -0
  214. package/dist/web-mercator/web-mercator-utils.js +321 -0
  215. package/dist/web-mercator/web-mercator-utils.js.map +1 -0
  216. package/dist/web-mercator/web-mercator-viewport.d.ts +177 -0
  217. package/dist/web-mercator/web-mercator-viewport.d.ts.map +1 -0
  218. package/dist/web-mercator/web-mercator-viewport.js +276 -0
  219. package/dist/web-mercator/web-mercator-viewport.js.map +1 -0
  220. package/dist/web-mercator.d.ts +1 -1
  221. package/dist/web-mercator.d.ts.map +1 -1
  222. package/dist/web-mercator.js +1 -1
  223. package/dist/web-mercator.js.map +1 -1
  224. package/package.json +19 -458
  225. package/src/index.ts +36 -5
  226. package/src/projection/experimental/crs/spatial-reference.ts +1 -6
  227. package/src/projection/experimental/crs/types.ts +1 -1
  228. package/src/projection/experimental/crs/wkt.ts +1 -1
  229. package/src/projection/experimental/crs-descriptor.ts +1 -1
  230. package/src/projection/experimental/lazy-projections/aea.ts +4 -1
  231. package/src/projection/experimental/lazy-projections/bonne.ts +4 -1
  232. package/src/projection/experimental/lazy-projections/cass.ts +4 -1
  233. package/src/projection/experimental/lazy-projections/eck6.ts +4 -1
  234. package/src/projection/experimental/lazy-projections/eqdc.ts +4 -1
  235. package/src/projection/experimental/lazy-projections/eqearth.ts +4 -1
  236. package/src/projection/experimental/lazy-projections/equi.ts +4 -1
  237. package/src/projection/experimental/lazy-projections/geocent.ts +4 -1
  238. package/src/projection/experimental/lazy-projections/geos.ts +4 -1
  239. package/src/projection/experimental/lazy-projections/gnom.ts +4 -1
  240. package/src/projection/experimental/lazy-projections/krovak.ts +4 -1
  241. package/src/projection/experimental/lazy-projections/merc.ts +4 -1
  242. package/src/projection/experimental/lazy-projections/mill.ts +4 -1
  243. package/src/projection/experimental/lazy-projections/moll.ts +4 -1
  244. package/src/projection/experimental/lazy-projections/nzmg.ts +4 -1
  245. package/src/projection/experimental/lazy-projections/omerc.ts +4 -1
  246. package/src/projection/experimental/lazy-projections/ortho.ts +4 -1
  247. package/src/projection/experimental/lazy-projections/poly.ts +4 -1
  248. package/src/projection/experimental/lazy-projections/robin.ts +4 -1
  249. package/src/projection/experimental/lazy-projections/sinu.ts +4 -1
  250. package/src/projection/experimental/lazy-projections/stere.ts +4 -1
  251. package/src/projection/experimental/lazy-projections/tpers.ts +4 -1
  252. package/src/projection/experimental/lazy-projections/vandg.ts +4 -1
  253. package/src/projection/index.ts +1 -1
  254. package/src/projection/lib/projection.ts +1 -1
  255. package/src/terrain/cutout-polygons.ts +202 -0
  256. package/src/terrain/cutout-region.ts +54 -0
  257. package/src/terrain/geographic-cutout.ts +154 -0
  258. package/src/terrain/index.ts +24 -0
  259. package/src/terrain/mesh-cutout.ts +85 -23
  260. package/src/terrain/tile-cutout-update.ts +293 -0
  261. package/src/terrain/tile-cutout.ts +123 -0
  262. package/src/turf/expressions.ts +2 -2
  263. package/src/turf.ts +3 -7
  264. package/src/web-mercator/assert.ts +11 -0
  265. package/src/web-mercator/fit-bounds.ts +132 -0
  266. package/src/web-mercator/fly-to-viewport.ts +157 -0
  267. package/src/web-mercator/get-bounds.ts +62 -0
  268. package/src/web-mercator/index.ts +49 -0
  269. package/src/web-mercator/math-utils.ts +35 -0
  270. package/src/web-mercator/mercator-meters.ts +83 -0
  271. package/src/web-mercator/normalize-viewport-props.ts +58 -0
  272. package/src/web-mercator/web-mercator-utils.ts +468 -0
  273. package/src/web-mercator/web-mercator-viewport.ts +406 -0
  274. package/src/web-mercator.ts +1 -1
  275. package/dist/projection/experimental/index.cjs +0 -11707
  276. package/dist/projection/experimental/index.cjs.map +0 -6
@@ -0,0 +1,157 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ import {lerp} from './math-utils';
5
+ import {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';
6
+ import {vec2} from '@math.gl/core';
7
+
8
+ import type {ViewportProps} from './normalize-viewport-props';
9
+
10
+ const EPSILON = 0.01;
11
+ const VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;
12
+ const DEFAULT_OPTS = {
13
+ curve: 1.414,
14
+ speed: 1.2
15
+ // screenSpeed and maxDuration are used only if specified
16
+ };
17
+
18
+ export type FlytoTransitionOptions = {
19
+ curve?: number;
20
+ speed?: number;
21
+ screenSpeed?: number;
22
+ maxDuration?: number;
23
+ };
24
+
25
+ type TransitionViewport = {
26
+ longitude: number;
27
+ latitude: number;
28
+ zoom: number;
29
+ };
30
+
31
+ /**
32
+ * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.
33
+ * It implements “Smooth and efficient zooming and panning.” algorithm by
34
+ * "Jarke J. van Wijk and Wim A.A. Nuij"
35
+ */
36
+ export function flyToViewport(
37
+ startProps: ViewportProps,
38
+ endProps: ViewportProps,
39
+ t: number,
40
+ options?: FlytoTransitionOptions
41
+ ): {
42
+ longitude: number;
43
+ latitude: number;
44
+ zoom: number;
45
+ } {
46
+ // Equations from above paper are referred where needed.
47
+
48
+ const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(
49
+ startProps,
50
+ endProps,
51
+ options
52
+ );
53
+
54
+ // If change in center is too small, do linear interpolaiton.
55
+ if (u1 < EPSILON) {
56
+ const viewport: TransitionViewport = {
57
+ longitude: 0,
58
+ latitude: 0,
59
+ zoom: 0
60
+ };
61
+ for (const key of VIEWPORT_TRANSITION_PROPS) {
62
+ const startValue = startProps[key];
63
+ const endValue = endProps[key];
64
+ viewport[key] = lerp(startValue, endValue, t);
65
+ }
66
+ return viewport;
67
+ }
68
+
69
+ const s = t * S;
70
+
71
+ const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);
72
+ const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;
73
+
74
+ const scaleIncrement = 1 / w; // Using w method for scaling.
75
+ const newZoom = startZoom + scaleToZoom(scaleIncrement);
76
+
77
+ const newCenterWorld = vec2.scale([] as number[], uDelta, u) as [number, number];
78
+ vec2.add(newCenterWorld, newCenterWorld, startCenterXY);
79
+
80
+ const newCenter = worldToLngLat(newCenterWorld);
81
+ return {
82
+ longitude: newCenter[0],
83
+ latitude: newCenter[1],
84
+ zoom: newZoom
85
+ };
86
+ }
87
+
88
+ // returns transition duration in milliseconds
89
+ export function getFlyToDuration(
90
+ startProps: ViewportProps,
91
+ endProps: ViewportProps,
92
+ options?: FlytoTransitionOptions
93
+ ): number {
94
+ const opts = {...DEFAULT_OPTS, ...options};
95
+ const {screenSpeed, speed, maxDuration} = opts;
96
+ const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);
97
+ const length = 1000 * S;
98
+ let duration: number;
99
+ if (Number.isFinite(screenSpeed)) {
100
+ duration = length / (screenSpeed / rho);
101
+ } else {
102
+ duration = length / speed;
103
+ }
104
+
105
+ return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;
106
+ }
107
+
108
+ // Private Methods
109
+
110
+ // Calculate all parameters that are static for given startProps and endProps
111
+ function getFlyToTransitionParams(
112
+ startProps: ViewportProps,
113
+ endProps: ViewportProps,
114
+ opts: FlytoTransitionOptions
115
+ ): {
116
+ startZoom: number;
117
+ startCenterXY: [number, number];
118
+ uDelta: [number, number];
119
+ w0: number;
120
+ u1: number;
121
+ S: number;
122
+ rho: number;
123
+ rho2: number;
124
+ r0: number;
125
+ r1: number;
126
+ } {
127
+ opts = Object.assign({}, DEFAULT_OPTS, opts);
128
+ const rho = opts.curve;
129
+ const startZoom = startProps.zoom;
130
+ const startCenter: [number, number] = [startProps.longitude, startProps.latitude];
131
+ const startScale = zoomToScale(startZoom);
132
+ const endZoom = endProps.zoom;
133
+ const endCenter: [number, number] = [endProps.longitude, endProps.latitude];
134
+ const scale = zoomToScale(endZoom - startZoom);
135
+
136
+ const startCenterXY: [number, number] = lngLatToWorld(startCenter);
137
+ const endCenterXY: [number, number] = lngLatToWorld(endCenter);
138
+ const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY) as [number, number];
139
+
140
+ const w0 = Math.max(startProps.width, startProps.height);
141
+ const w1 = w0 / scale;
142
+ const u1 = vec2.length(uDelta) * startScale;
143
+ // u0 is treated as '0' in Eq (9).
144
+
145
+ // If u1 is too small, will generate invalid number
146
+ const _u1 = Math.max(u1, EPSILON);
147
+
148
+ // Implement Equation (9) from above algorithm.
149
+ const rho2 = rho * rho;
150
+ const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);
151
+ const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);
152
+ const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);
153
+ const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);
154
+ const S = (r1 - r0) / rho;
155
+
156
+ return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};
157
+ }
@@ -0,0 +1,62 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ /* eslint-disable camelcase */
5
+ import {vec2} from '@math.gl/core';
6
+ import type {WebMercatorViewport} from './web-mercator-viewport';
7
+ import {worldToLngLat} from './web-mercator-utils';
8
+ import {transformVector} from './math-utils';
9
+
10
+ const DEGREES_TO_RADIANS = Math.PI / 180;
11
+
12
+ /*
13
+ * Returns the quad at the intersection of the frustum and the given z plane
14
+ * @param {WebMercatorViewport} viewport
15
+ * @param {Number} z - elevation in meters
16
+ */
17
+ export function getBounds(viewport: WebMercatorViewport, z: number = 0): number[][] {
18
+ // eslint-disable-next-line @typescript-eslint/unbound-method
19
+ const {width, height, unproject} = viewport;
20
+ const unprojectOps = {targetZ: z};
21
+ const bottomLeft = unproject([0, height], unprojectOps);
22
+ const bottomRight = unproject([width, height], unprojectOps);
23
+ let topLeft: number[];
24
+ let topRight: number[];
25
+
26
+ const halfFov = viewport.fovy
27
+ ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS
28
+ : Math.atan(0.5 / viewport.altitude);
29
+ const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;
30
+ // The top plane is parallel to the ground if halfFov == angleToGround
31
+ if (halfFov > angleToGround - 0.01) {
32
+ // intersect with the far plane
33
+ topLeft = unprojectOnFarPlane(viewport, 0, z);
34
+ topRight = unprojectOnFarPlane(viewport, width, z);
35
+ } else {
36
+ // intersect with the top plane
37
+ topLeft = unproject([0, 0], unprojectOps);
38
+ topRight = unproject([width, 0], unprojectOps);
39
+ }
40
+
41
+ return [bottomLeft, bottomRight, topRight, topLeft];
42
+ }
43
+
44
+ /*
45
+ * Find a point on the far clipping plane of the viewport
46
+ * @param {WebMercatorViewport} viewport
47
+ * @param {Number} x - projected x in screen space
48
+ * @param {Number} targetZ - the elevation of the point in meters
49
+ */
50
+ function unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ: number): number[] {
51
+ const {pixelUnprojectionMatrix} = viewport;
52
+ const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);
53
+ const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);
54
+
55
+ const z = targetZ * viewport.distanceScales.unitsPerMeter[2];
56
+ const t = (z - coord0[2]) / (coord1[2] - coord0[2]);
57
+ const coord = vec2.lerp([], coord0, coord1, t);
58
+
59
+ const result = worldToLngLat(coord);
60
+ result.push(targetZ);
61
+ return result;
62
+ }
@@ -0,0 +1,49 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ // Classic web-mercator-project
5
+ export {WebMercatorViewport} from './web-mercator-viewport';
6
+
7
+ export {getBounds} from './get-bounds';
8
+ export {fitBounds} from './fit-bounds';
9
+ export {normalizeViewportProps} from './normalize-viewport-props';
10
+ export {flyToViewport, getFlyToDuration} from './fly-to-viewport';
11
+
12
+ export {
13
+ MAX_LATITUDE,
14
+ lngLatToWorld,
15
+ worldToLngLat,
16
+ worldToPixels,
17
+ pixelsToWorld,
18
+ zoomToScale,
19
+ scaleToZoom,
20
+ altitudeToFovy,
21
+ fovyToAltitude,
22
+ getMeterZoom,
23
+ unitsPerMeter,
24
+ getDistanceScales,
25
+ addMetersToLngLat,
26
+ getViewMatrix,
27
+ getProjectionMatrix,
28
+ getProjectionParameters
29
+ } from './web-mercator-utils';
30
+
31
+ export {
32
+ EPSG3857_EARTH_RADIUS,
33
+ EPSG3857_HALF_CIRCUMFERENCE,
34
+ EPSG3857_MAX_LATITUDE,
35
+ EPSG3857_UNITS_PER_METER,
36
+ lngLatToEPSG3857,
37
+ EPSG3857ToLngLat,
38
+ EPSG4326ToEPSG3857,
39
+ EPSG3857ToEPSG4326
40
+ } from './mercator-meters';
41
+
42
+ export type {EPSG3857Options} from './mercator-meters';
43
+
44
+ /** Types */
45
+ export type {FitBoundsOptions} from './fit-bounds';
46
+ export type {DistanceScales} from './web-mercator-utils';
47
+
48
+ /** @deprecated default export */
49
+ export {WebMercatorViewport as default} from './web-mercator-viewport';
@@ -0,0 +1,35 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ import {vec4} from '@math.gl/core';
5
+
6
+ // Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()
7
+ export function createMat4(): number[] {
8
+ return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
9
+ }
10
+
11
+ // Transforms a vec4 with a projection matrix
12
+ export function transformVector(matrix: number[], vector: number[]): number[] {
13
+ const result = vec4.transformMat4([] as number[], vector, matrix);
14
+ vec4.scale(result, result, 1 / result[3]);
15
+ return result;
16
+ }
17
+
18
+ export function mod(value: number, divisor: number): number {
19
+ const modulus = value % divisor;
20
+ return modulus < 0 ? divisor + modulus : modulus;
21
+ }
22
+
23
+ export function lerp(start: number, end: number, step: number): number {
24
+ return step * end + (1 - step) * start;
25
+ }
26
+
27
+ export function clamp(x: number, min: number, max: number): number {
28
+ return x < min ? min : x > max ? max : x;
29
+ }
30
+
31
+ function ieLog2(x: number): number {
32
+ return Math.log(x) * Math.LOG2E;
33
+ }
34
+ // Handle missing log2 in IE 11
35
+ export const log2 = Math.log2 || ieLog2;
@@ -0,0 +1,83 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+
5
+ const PI = Math.PI;
6
+ const DEGREES_TO_RADIANS = PI / 180;
7
+ const RADIANS_TO_DEGREES = 180 / PI;
8
+
9
+ /** Radius of the sphere used by EPSG:3857, in meters. */
10
+ export const EPSG3857_EARTH_RADIUS = 6378137;
11
+
12
+ /** Half the circumference of the EPSG:3857 sphere, in meters. */
13
+ export const EPSG3857_HALF_CIRCUMFERENCE = PI * EPSG3857_EARTH_RADIUS;
14
+
15
+ /** Maximum latitude with a finite value in the spherical Mercator projection. */
16
+ export const EPSG3857_MAX_LATITUDE = Math.atan(Math.sinh(PI)) * RADIANS_TO_DEGREES;
17
+
18
+ /** EPSG:3857 meters per 512-unit world coordinate at the equator. */
19
+ export const EPSG3857_UNITS_PER_METER = 512 / (2 * EPSG3857_HALF_CIRCUMFERENCE);
20
+
21
+ export type EPSG3857Options = {
22
+ /** Clamp latitude to the finite Web Mercator range. Defaults to true. */
23
+ clampLatitude?: boolean;
24
+ };
25
+
26
+ /**
27
+ * Convert WGS84 longitude/latitude coordinates to EPSG:3857 meters.
28
+ *
29
+ * The optional third coordinate is preserved as an elevation in meters.
30
+ */
31
+ export function lngLatToEPSG3857(lngLatZ: number[], options: EPSG3857Options = {}): number[] {
32
+ const [longitude, latitude, z] = lngLatZ;
33
+ const {clampLatitude = true} = options;
34
+
35
+ if (!Number.isFinite(longitude) || !Number.isFinite(latitude)) {
36
+ throw new Error('Invalid longitude or latitude');
37
+ }
38
+ if (lngLatZ.length >= 3 && !Number.isFinite(z)) {
39
+ throw new Error('Invalid elevation');
40
+ }
41
+
42
+ const projectedLatitude = clampLatitude
43
+ ? Math.max(-EPSG3857_MAX_LATITUDE, Math.min(EPSG3857_MAX_LATITUDE, latitude))
44
+ : latitude;
45
+
46
+ if (projectedLatitude < -EPSG3857_MAX_LATITUDE || projectedLatitude > EPSG3857_MAX_LATITUDE) {
47
+ throw new Error('Latitude is outside the finite EPSG:3857 range');
48
+ }
49
+
50
+ const x = EPSG3857_EARTH_RADIUS * longitude * DEGREES_TO_RADIANS;
51
+ const y =
52
+ EPSG3857_EARTH_RADIUS *
53
+ Math.log(Math.tan(PI / 4 + (projectedLatitude * DEGREES_TO_RADIANS) / 2));
54
+
55
+ return lngLatZ.length >= 3 ? [x, y, z] : [x, y];
56
+ }
57
+
58
+ /**
59
+ * Convert EPSG:3857 meters to WGS84 longitude/latitude coordinates.
60
+ *
61
+ * The optional third coordinate is preserved as an elevation in meters.
62
+ */
63
+ export function EPSG3857ToLngLat(xyz: number[]): number[] {
64
+ const [x, y, z] = xyz;
65
+
66
+ if (!Number.isFinite(x) || !Number.isFinite(y)) {
67
+ throw new Error('Invalid EPSG:3857 coordinate');
68
+ }
69
+ if (xyz.length >= 3 && !Number.isFinite(z)) {
70
+ throw new Error('Invalid elevation');
71
+ }
72
+
73
+ const longitude = (x / EPSG3857_EARTH_RADIUS) * RADIANS_TO_DEGREES;
74
+ const latitude = Math.atan(Math.sinh(y / EPSG3857_EARTH_RADIUS)) * RADIANS_TO_DEGREES;
75
+
76
+ return xyz.length >= 3 ? [longitude, latitude, z] : [longitude, latitude];
77
+ }
78
+
79
+ /** Explicit EPSG:4326 to EPSG:3857 alias. */
80
+ export const EPSG4326ToEPSG3857 = lngLatToEPSG3857;
81
+
82
+ /** Explicit EPSG:3857 to EPSG:4326 alias. */
83
+ export const EPSG3857ToEPSG4326 = EPSG3857ToLngLat;
@@ -0,0 +1,58 @@
1
+ // math.gl
2
+ // SPDX-License-Identifier: MIT
3
+ // SPDX-FileCopyrightText: Copyright (c) vis.gl contributors
4
+ import {worldToLngLat} from './web-mercator-utils';
5
+ import {mod, log2} from './math-utils';
6
+
7
+ // defined by mapbox-gl
8
+ const TILE_SIZE = 512;
9
+
10
+ /** Description of viewport */
11
+ export type ViewportProps = {
12
+ width: number;
13
+ height: number;
14
+ longitude: number;
15
+ latitude: number;
16
+ zoom: number;
17
+ pitch?: number;
18
+ bearing?: number;
19
+ };
20
+
21
+ /**
22
+ * Apply mathematical constraints to viewport props
23
+ * @param props
24
+ */
25
+ // eslint-disable-next-line complexity
26
+ export function normalizeViewportProps(props: ViewportProps): ViewportProps {
27
+ const {width, height, pitch = 0} = props;
28
+ let {longitude, latitude, zoom, bearing = 0} = props;
29
+
30
+ // Normalize degrees
31
+ if (longitude < -180 || longitude > 180) {
32
+ longitude = mod(longitude + 180, 360) - 180;
33
+ }
34
+ if (bearing < -180 || bearing > 180) {
35
+ bearing = mod(bearing + 180, 360) - 180;
36
+ }
37
+
38
+ // Constrain zoom and shift center at low zoom levels
39
+ const minZoom = log2(height / TILE_SIZE);
40
+ if (zoom <= minZoom) {
41
+ zoom = minZoom;
42
+ latitude = 0;
43
+ } else {
44
+ // Eliminate white space above and below the map
45
+ const halfHeightPixels = height / 2 / Math.pow(2, zoom);
46
+ const minLatitude = worldToLngLat([0, halfHeightPixels])[1];
47
+ if (latitude < minLatitude) {
48
+ latitude = minLatitude;
49
+ } else {
50
+ const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];
51
+ if (latitude > maxLatitude) {
52
+ latitude = maxLatitude;
53
+ }
54
+ }
55
+ }
56
+
57
+ return {width, height, longitude, latitude, zoom, pitch, bearing};
58
+ }