@math.gl/web-mercator 3.6.0-alpha.3 → 3.6.0-alpha.6

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.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fly-to-viewport.ts"],"names":["EPSILON","VIEWPORT_TRANSITION_PROPS","DEFAULT_OPTS","curve","speed","flyToViewport","startProps","endProps","t","options","getFlyToTransitionParams","startZoom","startCenterXY","uDelta","w0","u1","S","rho","rho2","r0","viewport","key","startValue","endValue","s","w","Math","cosh","u","tanh","sinh","scaleIncrement","newZoom","newCenterWorld","vec2","scale","add","newCenter","longitude","latitude","zoom","getFlyToDuration","opts","screenSpeed","maxDuration","length","duration","Number","isFinite","Object","assign","startCenter","startScale","endZoom","endCenter","endCenterXY","sub","max","width","height","w1","_u1","b0","b1","log","sqrt","r1"],"mappings":";;;;;;;;;;;;;;AAAA;;AACA;;AACA;;;;;;;;;;;;;;;;AAIA,IAAMA,OAAO,GAAG,IAAhB;AACA,IAAMC,yBAAyB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,MAA1B,CAAlC;AACA,IAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,KADY;AAEnBC,EAAAA,KAAK,EAAE;AAFY,CAArB;;AAkBe,SAASC,aAAT,CACbC,UADa,EAEbC,QAFa,EAGbC,CAHa,EAIbC,OAJa,EASb;AAGA,8BAAqEC,wBAAwB,CAC3FJ,UAD2F,EAE3FC,QAF2F,EAG3FE,OAH2F,CAA7F;AAAA,MAAOE,SAAP,yBAAOA,SAAP;AAAA,MAAkBC,aAAlB,yBAAkBA,aAAlB;AAAA,MAAiCC,MAAjC,yBAAiCA,MAAjC;AAAA,MAAyCC,EAAzC,yBAAyCA,EAAzC;AAAA,MAA6CC,EAA7C,yBAA6CA,EAA7C;AAAA,MAAiDC,CAAjD,yBAAiDA,CAAjD;AAAA,MAAoDC,GAApD,yBAAoDA,GAApD;AAAA,MAAyDC,I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C,GAAjE,CAAX;AACA,MAAM1C,EAAE,GAAGO,IAAI,CAACsC,GAAL,CAAStC,IAAI,CAACuC,IAAL,CAAUH,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,MAAMI,EAAE,GAAGxC,IAAI,CAACsC,GAAL,CAAStC,IAAI,CAACuC,IAAL,CAAUF,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,MAAM/C,CAAC,GAAG,CAACkD,EAAE,GAAG/C,EAAN,IAAYF,GAAtB;AAEA,SAAO;AAACN,IAAAA,SAAS,EAATA,SAAD;AAAYC,IAAAA,aAAa,EAAbA,aAAZ;AAA2BC,IAAAA,MAAM,EAANA,MAA3B;AAAmCC,IAAAA,EAAE,EAAFA,EAAnC;AAAuCC,IAAAA,EAAE,EAAFA,EAAvC;AAA2CC,IAAAA,CAAC,EAADA,CAA3C;AAA8CC,IAAAA,GAAG,EAAHA,GAA9C;AAAmDC,IAAAA,IAAI,EAAJA,IAAnD;AAAyDC,IAAAA,EAAE,EAAFA,EAAzD;AAA6D+C,IAAAA,EAAE,EAAFA;AAA7D,GAAP;AACD","sourcesContent":["import {lerp} from './math-utils';\nimport {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';\nimport * as vec2 from 'gl-matrix/vec2';\n\nimport type {ViewportProps} from './normalize-viewport-props';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;\nconst DEFAULT_OPTS = {\n curve: 1.414,\n speed: 1.2\n // screenSpeed and maxDuration are used only if specified\n};\n\nexport type FlytoTransitionOptions = {\n curve?: number;\n speed?: number;\n screenSpeed?: number;\n maxDuration?: number;\n};\n\n/**\n * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.\n * It implements “Smooth and efficient zooming and panning.” algorithm by\n * \"Jarke J. van Wijk and Wim A.A. Nuij\"\n */\nexport default function flyToViewport(\n startProps: ViewportProps,\n endProps: ViewportProps,\n t: number,\n options?: FlytoTransitionOptions\n): {\n longitude: number;\n latitude: number;\n zoom: number;\n} {\n // Equations from above paper are referred where needed.\n\n const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(\n startProps,\n endProps,\n options\n );\n\n // If change in center is too small, do linear interpolaiton.\n if (u1 < EPSILON) {\n const viewport = {};\n for (const key of VIEWPORT_TRANSITION_PROPS) {\n const startValue = startProps[key];\n const endValue = endProps[key];\n viewport[key] = lerp(startValue, endValue, t);\n }\n // @ts-expect-error\n return viewport;\n }\n\n const s = t * S;\n\n const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);\n const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;\n\n const scaleIncrement = 1 / w; // Using w method for scaling.\n const newZoom = startZoom + scaleToZoom(scaleIncrement);\n\n const newCenterWorld = vec2.scale([], uDelta, u);\n vec2.add(newCenterWorld, newCenterWorld, startCenterXY);\n\n const newCenter = worldToLngLat(newCenterWorld);\n return {\n longitude: newCenter[0],\n latitude: newCenter[1],\n zoom: newZoom\n };\n}\n\n// returns transition duration in milliseconds\nexport function getFlyToDuration(\n startProps: ViewportProps,\n endProps: ViewportProps,\n options?: FlytoTransitionOptions\n): number {\n const opts = {...DEFAULT_OPTS, ...options};\n const {screenSpeed, speed, maxDuration} = opts;\n const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);\n const length = 1000 * S;\n let duration: number;\n if (Number.isFinite(screenSpeed)) {\n duration = length / (screenSpeed / rho);\n } else {\n duration = length / speed;\n }\n\n return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;\n}\n\n// Private Methods\n\n// Calculate all parameters that are static for given startProps and endProps\nfunction getFlyToTransitionParams(\n startProps: ViewportProps,\n endProps: ViewportProps,\n opts: FlytoTransitionOptions\n): {\n startZoom: number;\n startCenterXY: number[];\n uDelta: number[];\n w0: number;\n u1: number;\n S: number;\n rho: number;\n rho2: number;\n r0: number;\n r1: number;\n} {\n opts = Object.assign({}, DEFAULT_OPTS, opts);\n const rho = opts.curve;\n const startZoom = startProps.zoom;\n const startCenter = [startProps.longitude, startProps.latitude];\n const startScale = zoomToScale(startZoom);\n const endZoom = endProps.zoom;\n const endCenter = [endProps.longitude, endProps.latitude];\n const scale = zoomToScale(endZoom - startZoom);\n\n const startCenterXY = lngLatToWorld(startCenter);\n const endCenterXY = lngLatToWorld(endCenter);\n const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);\n\n const w0 = Math.max(startProps.width, startProps.height);\n const w1 = w0 / scale;\n const u1 = vec2.length(uDelta) * startScale;\n // u0 is treated as '0' in Eq (9).\n\n // If u1 is too small, will generate invalid number\n const _u1 = Math.max(u1, EPSILON);\n\n // Implement Equation (9) from above algorithm.\n const rho2 = rho * rho;\n const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);\n const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);\n const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);\n const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n const S = (r1 - r0) / rho;\n\n return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};\n}\n"],"file":"fly-to-viewport.js"}
1
+ {"version":3,"sources":["../../src/fly-to-viewport.ts"],"names":["EPSILON","VIEWPORT_TRANSITION_PROPS","DEFAULT_OPTS","curve","speed","flyToViewport","startProps","endProps","t","options","getFlyToTransitionParams","startZoom","startCenterXY","uDelta","w0","u1","S","rho","rho2","r0","viewport","key","startValue","endValue","s","w","Math","cosh","u","tanh","sinh","scaleIncrement","newZoom","newCenterWorld","vec2","scale","add","newCenter","longitude","latitude","zoom","getFlyToDuration","opts","screenSpeed","maxDuration","length","duration","Number","isFinite","Object","assign","startCenter","startScale","endZ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EAAFA,EAAnC;AAAuCC,IAAAA,EAAE,EAAFA,EAAvC;AAA2CC,IAAAA,CAAC,EAADA,CAA3C;AAA8CC,IAAAA,GAAG,EAAHA,GAA9C;AAAmDC,IAAAA,IAAI,EAAJA,IAAnD;AAAyDC,IAAAA,EAAE,EAAFA,EAAzD;AAA6D+C,IAAAA,EAAE,EAAFA;AAA7D,GAAP;AACD","sourcesContent":["import {lerp} from './math-utils';\nimport {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';\nimport * as vec2 from 'gl-matrix/vec2';\n\nimport type {ViewportProps} from './normalize-viewport-props';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;\nconst DEFAULT_OPTS = {\n curve: 1.414,\n speed: 1.2\n // screenSpeed and maxDuration are used only if specified\n};\n\nexport type FlytoTransitionOptions = {\n curve?: number;\n speed?: number;\n screenSpeed?: number;\n maxDuration?: number;\n};\n\n/**\n * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.\n * It implements “Smooth and efficient zooming and panning.” algorithm by\n * \"Jarke J. van Wijk and Wim A.A. Nuij\"\n */\nexport default function flyToViewport(\n startProps: ViewportProps,\n endProps: ViewportProps,\n t: number,\n options?: FlytoTransitionOptions\n): {\n longitude: number;\n latitude: number;\n zoom: number;\n} {\n // Equations from above paper are referred where needed.\n\n const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(\n startProps,\n endProps,\n options\n );\n\n // If change in center is too small, do linear interpolaiton.\n if (u1 < EPSILON) {\n const viewport = {};\n for (const key of VIEWPORT_TRANSITION_PROPS) {\n const startValue = startProps[key];\n const endValue = endProps[key];\n viewport[key] = lerp(startValue, endValue, t);\n }\n // @ts-expect-error properties are populated dynamically\n return viewport;\n }\n\n const s = t * S;\n\n const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);\n const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;\n\n const scaleIncrement = 1 / w; // Using w method for scaling.\n const newZoom = startZoom + scaleToZoom(scaleIncrement);\n\n const newCenterWorld = vec2.scale([], uDelta, u);\n vec2.add(newCenterWorld, newCenterWorld, startCenterXY);\n\n const newCenter = worldToLngLat(newCenterWorld);\n return {\n longitude: newCenter[0],\n latitude: newCenter[1],\n zoom: newZoom\n };\n}\n\n// returns transition duration in milliseconds\nexport function getFlyToDuration(\n startProps: ViewportProps,\n endProps: ViewportProps,\n options?: FlytoTransitionOptions\n): number {\n const opts = {...DEFAULT_OPTS, ...options};\n const {screenSpeed, speed, maxDuration} = opts;\n const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);\n const length = 1000 * S;\n let duration: number;\n if (Number.isFinite(screenSpeed)) {\n duration = length / (screenSpeed / rho);\n } else {\n duration = length / speed;\n }\n\n return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;\n}\n\n// Private Methods\n\n// Calculate all parameters that are static for given startProps and endProps\nfunction getFlyToTransitionParams(\n startProps: ViewportProps,\n endProps: ViewportProps,\n opts: FlytoTransitionOptions\n): {\n startZoom: number;\n startCenterXY: number[];\n uDelta: number[];\n w0: number;\n u1: number;\n S: number;\n rho: number;\n rho2: number;\n r0: number;\n r1: number;\n} {\n opts = Object.assign({}, DEFAULT_OPTS, opts);\n const rho = opts.curve;\n const startZoom = startProps.zoom;\n const startCenter = [startProps.longitude, startProps.latitude];\n const startScale = zoomToScale(startZoom);\n const endZoom = endProps.zoom;\n const endCenter = [endProps.longitude, endProps.latitude];\n const scale = zoomToScale(endZoom - startZoom);\n\n const startCenterXY = lngLatToWorld(startCenter);\n const endCenterXY = lngLatToWorld(endCenter);\n const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);\n\n const w0 = Math.max(startProps.width, startProps.height);\n const w1 = w0 / scale;\n const u1 = vec2.length(uDelta) * startScale;\n // u0 is treated as '0' in Eq (9).\n\n // If u1 is too small, will generate invalid number\n const _u1 = Math.max(u1, EPSILON);\n\n // Implement Equation (9) from above algorithm.\n const rho2 = rho * rho;\n const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);\n const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);\n const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);\n const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n const S = (r1 - r0) / rho;\n\n return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};\n}\n"],"file":"fly-to-viewport.js"}
@@ -39,6 +39,8 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
39
39
 
40
40
  var WebMercatorViewport = function () {
41
41
  function WebMercatorViewport() {
42
+ var _this = this;
43
+
42
44
  var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
43
45
  width: 1,
44
46
  height: 1
@@ -62,6 +64,75 @@ var WebMercatorViewport = function () {
62
64
  (0, _defineProperty2.default)(this, "viewProjectionMatrix", void 0);
63
65
  (0, _defineProperty2.default)(this, "pixelProjectionMatrix", void 0);
64
66
  (0, _defineProperty2.default)(this, "pixelUnprojectionMatrix", void 0);
67
+ (0, _defineProperty2.default)(this, "equals", function (viewport) {
68
+ if (!(viewport instanceof WebMercatorViewport)) {
69
+ return false;
70
+ }
71
+
72
+ return viewport.width === _this.width && viewport.height === _this.height && mat4.equals(viewport.projectionMatrix, _this.projectionMatrix) && mat4.equals(viewport.viewMatrix, _this.viewMatrix);
73
+ });
74
+ (0, _defineProperty2.default)(this, "project", function (lngLatZ) {
75
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
76
+ var _options$topLeft = options.topLeft,
77
+ topLeft = _options$topLeft === void 0 ? true : _options$topLeft;
78
+
79
+ var worldPosition = _this.projectPosition(lngLatZ);
80
+
81
+ var coord = (0, _webMercatorUtils.worldToPixels)(worldPosition, _this.pixelProjectionMatrix);
82
+
83
+ var _coord = (0, _slicedToArray2.default)(coord, 2),
84
+ x = _coord[0],
85
+ y = _coord[1];
86
+
87
+ var y2 = topLeft ? y : _this.height - y;
88
+ return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
89
+ });
90
+ (0, _defineProperty2.default)(this, "unproject", function (xyz) {
91
+ var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
92
+ var _options$topLeft2 = options.topLeft,
93
+ topLeft = _options$topLeft2 === void 0 ? true : _options$topLeft2,
94
+ _options$targetZ = options.targetZ,
95
+ targetZ = _options$targetZ === void 0 ? undefined : _options$targetZ;
96
+
97
+ var _xyz = (0, _slicedToArray2.default)(xyz, 3),
98
+ x = _xyz[0],
99
+ y = _xyz[1],
100
+ z = _xyz[2];
101
+
102
+ var y2 = topLeft ? y : _this.height - y;
103
+ var targetZWorld = targetZ && targetZ * _this.distanceScales.unitsPerMeter[2];
104
+ var coord = (0, _webMercatorUtils.pixelsToWorld)([x, y2, z], _this.pixelUnprojectionMatrix, targetZWorld);
105
+
106
+ var _this$unprojectPositi = _this.unprojectPosition(coord),
107
+ _this$unprojectPositi2 = (0, _slicedToArray2.default)(_this$unprojectPositi, 3),
108
+ X = _this$unprojectPositi2[0],
109
+ Y = _this$unprojectPositi2[1],
110
+ Z = _this$unprojectPositi2[2];
111
+
112
+ if (Number.isFinite(z)) {
113
+ return [X, Y, Z];
114
+ }
115
+
116
+ return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
117
+ });
118
+ (0, _defineProperty2.default)(this, "projectPosition", function (xyz) {
119
+ var _lngLatToWorld = (0, _webMercatorUtils.lngLatToWorld)(xyz),
120
+ _lngLatToWorld2 = (0, _slicedToArray2.default)(_lngLatToWorld, 2),
121
+ X = _lngLatToWorld2[0],
122
+ Y = _lngLatToWorld2[1];
123
+
124
+ var Z = (xyz[2] || 0) * _this.distanceScales.unitsPerMeter[2];
125
+ return [X, Y, Z];
126
+ });
127
+ (0, _defineProperty2.default)(this, "unprojectPosition", function (xyz) {
128
+ var _worldToLngLat = (0, _webMercatorUtils.worldToLngLat)(xyz),
129
+ _worldToLngLat2 = (0, _slicedToArray2.default)(_worldToLngLat, 2),
130
+ X = _worldToLngLat2[0],
131
+ Y = _worldToLngLat2[1];
132
+
133
+ var Z = (xyz[2] || 0) * _this.distanceScales.metersPerUnit[2];
134
+ return [X, Y, Z];
135
+ });
65
136
  var width = props.width,
66
137
  height = props.height,
67
138
  _props$altitude = props.altitude,
@@ -141,11 +212,6 @@ var WebMercatorViewport = function () {
141
212
 
142
213
  this._initMatrices();
143
214
 
144
- this.equals = this.equals.bind(this);
145
- this.project = this.project.bind(this);
146
- this.unproject = this.unproject.bind(this);
147
- this.projectPosition = this.projectPosition.bind(this);
148
- this.unprojectPosition = this.unprojectPosition.bind(this);
149
215
  Object.freeze(this);
150
216
  }
151
217
 
@@ -173,83 +239,6 @@ var WebMercatorViewport = function () {
173
239
  this.pixelProjectionMatrix = m;
174
240
  this.pixelUnprojectionMatrix = mInverse;
175
241
  }
176
- }, {
177
- key: "equals",
178
- value: function equals(viewport) {
179
- if (!(viewport instanceof WebMercatorViewport)) {
180
- return false;
181
- }
182
-
183
- return viewport.width === this.width && viewport.height === this.height && mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && mat4.equals(viewport.viewMatrix, this.viewMatrix);
184
- }
185
- }, {
186
- key: "project",
187
- value: function project(lngLatZ) {
188
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
189
- var _options$topLeft = options.topLeft,
190
- topLeft = _options$topLeft === void 0 ? true : _options$topLeft;
191
- var worldPosition = this.projectPosition(lngLatZ);
192
- var coord = (0, _webMercatorUtils.worldToPixels)(worldPosition, this.pixelProjectionMatrix);
193
-
194
- var _coord = (0, _slicedToArray2.default)(coord, 2),
195
- x = _coord[0],
196
- y = _coord[1];
197
-
198
- var y2 = topLeft ? y : this.height - y;
199
- return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
200
- }
201
- }, {
202
- key: "unproject",
203
- value: function unproject(xyz) {
204
- var options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
205
- var _options$topLeft2 = options.topLeft,
206
- topLeft = _options$topLeft2 === void 0 ? true : _options$topLeft2,
207
- _options$targetZ = options.targetZ,
208
- targetZ = _options$targetZ === void 0 ? undefined : _options$targetZ;
209
-
210
- var _xyz = (0, _slicedToArray2.default)(xyz, 3),
211
- x = _xyz[0],
212
- y = _xyz[1],
213
- z = _xyz[2];
214
-
215
- var y2 = topLeft ? y : this.height - y;
216
- var targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
217
- var coord = (0, _webMercatorUtils.pixelsToWorld)([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);
218
-
219
- var _this$unprojectPositi = this.unprojectPosition(coord),
220
- _this$unprojectPositi2 = (0, _slicedToArray2.default)(_this$unprojectPositi, 3),
221
- X = _this$unprojectPositi2[0],
222
- Y = _this$unprojectPositi2[1],
223
- Z = _this$unprojectPositi2[2];
224
-
225
- if (Number.isFinite(z)) {
226
- return [X, Y, Z];
227
- }
228
-
229
- return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
230
- }
231
- }, {
232
- key: "projectPosition",
233
- value: function projectPosition(xyz) {
234
- var _lngLatToWorld = (0, _webMercatorUtils.lngLatToWorld)(xyz),
235
- _lngLatToWorld2 = (0, _slicedToArray2.default)(_lngLatToWorld, 2),
236
- X = _lngLatToWorld2[0],
237
- Y = _lngLatToWorld2[1];
238
-
239
- var Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
240
- return [X, Y, Z];
241
- }
242
- }, {
243
- key: "unprojectPosition",
244
- value: function unprojectPosition(xyz) {
245
- var _worldToLngLat = (0, _webMercatorUtils.worldToLngLat)(xyz),
246
- _worldToLngLat2 = (0, _slicedToArray2.default)(_worldToLngLat, 2),
247
- X = _worldToLngLat2[0],
248
- Y = _worldToLngLat2[1];
249
-
250
- var Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
251
- return [X, Y, Z];
252
- }
253
242
  }, {
254
243
  key: "projectFlat",
255
244
  value: function projectFlat(lngLat) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/web-mercator-viewport.ts"],"names":["WebMercatorViewport","props","width","height","altitude","fovy","latitude","longitude","zoom","pitch","bearing","position","nearZMultiplier","farZMultiplier","DEFAULT_ALTITUDE","scale","Math","max","distanceScales","center","push","vec3","add","mul","unitsPerMeter","projectionMatrix","viewMatrix","meterOffset","_initMatrices","equals","bind","project","unproject","projectPosition","unprojectPosition","Object","freeze","vpm","mat4","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","pixelProjectionMatrix","pixelUnprojectionMatrix","viewport","lngLatZ","options","topLeft","worldPosition","coord","x","y","y2","length","xyz","targetZ","undefined","z","targetZWorld","X","Y","Z","Number","isFinite","metersPerUnit","lngLat","xy","pos","fromLocation","toLocation","vec2","negate","newCenter","bounds","assign","corners","getBoundingRegion","west","min","map","p","east","south","north","getMapCenterByLngLatPosition"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;AAEA;;AAcA;;AACA;;AAGA;;AACA;;AACA;;;;;;IAiDqBA,mB;AA+BnB,iCAAqE;AAAA,QAAzDC,KAAyD,uEAAvB;AAACC,MAAAA,KAAK,EAAE,CAAR;AAAWC,MAAAA,MAAM,EAAE;AAAnB,KAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACnE,QAEED,KAFF,GAMID,KANJ,CAEEC,KAFF;AAAA,QAGEC,MAHF,GAMIF,KANJ,CAGEE,MAHF;AAAA,0BAMIF,KANJ,CAIEG,QAJF;AAAA,QAIEA,QAJF,gCAIa,IAJb;AAAA,sBAMIH,KANJ,CAKEI,IALF;AAAA,QAKEA,IALF,4BAK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A,aAAO,CACL,CAACH,IAAD,EAAOK,KAAP,CADK,EAEL,CAACD,IAAD,EAAOE,KAAP,CAFK,CAAP;AAID;;;WAQD,6BAA0D;AAAA,UAAxCrC,OAAwC,uEAAhB,EAAgB;AACxD,aAAO,wBAAU,IAAV,EAAgBA,OAAO,CAACW,CAAR,IAAa,CAA7B,CAAP;AACD;;;WAKD,mCAA+E;AAAA,UAA3DQ,MAA2D,SAA3DA,MAA2D;AAAA,UAAnDE,GAAmD,SAAnDA,GAAmD;AAC7E,aAAO,KAAKiB,4BAAL,CAAkC;AAACnB,QAAAA,MAAM,EAANA,MAAD;AAASE,QAAAA,GAAG,EAAHA;AAAT,OAAlC,CAAP;AACD","sourcesContent":["// View and Projection Matrix calculations for mapbox-js style map view properties\nimport {createMat4} from './math-utils';\n\nimport {\n zoomToScale,\n pixelsToWorld,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n altitudeToFovy,\n fovyToAltitude,\n DEFAULT_ALTITUDE,\n getProjectionMatrix,\n getDistanceScales,\n getViewMatrix,\n DistanceScales\n} from './web-mercator-utils';\nimport fitBounds from './fit-bounds';\nimport getBounds from './get-bounds';\nimport type {FitBoundsOptions} from './fit-bounds';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\n\n/**\n * @param width=1 - Width of \"viewport\" or window\n * @param height=1 - Height of \"viewport\" or window\n * @param scale=1 - Either use scale or zoom\n * @param pitch=0 - Camera angle in degrees (0 is straight down)\n * @param bearing=0 - Map rotation in degrees (0 means north is up)\n * @param fovy= - Field of view of camera in degrees\n * @param altitude= - Altitude of camera in screen units \n *\n * Web mercator projection short-hand parameters\n * @param latitude - Center of viewport on map\n * @param longitude - Center of viewport on map\n * @param zoom - Scale = Math.pow(2,zoom) on map\n\n * Notes:\n * - Only one of center or [latitude, longitude] can be specified\n * - [latitude, longitude] can only be specified when \"mercator\" is true\n * - Altitude has a default value that matches assumptions in mapbox-gl\n * - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl\n * - width and height are forced to 1 if supplied as 0, to avoid\n * division by zero. This is intended to reduce the burden of apps to\n * to check values before instantiating a Viewport.\n */\nexport type WebMercatorViewportProps = {\n // Map state\n width: number;\n height: number;\n latitude?: number;\n longitude?: number;\n position?: number[];\n zoom?: number;\n pitch?: number;\n bearing?: number;\n altitude?: number;\n fovy?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n};\n\n/**\n * The WebMercatorViewport class creates\n * - view/projection matrices\n * - \"uniform values\" (for shaders) from mercator params\n *\n * Note: Instances are immutable in the sense that they only have accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\nexport default class WebMercatorViewport {\n readonly latitude: number;\n readonly longitude: number;\n readonly zoom: number;\n readonly pitch: number;\n readonly bearing: number;\n readonly altitude: number;\n readonly fovy: number;\n\n readonly meterOffset: number[];\n readonly center: number[];\n\n readonly width: number;\n readonly height: number;\n readonly scale: number;\n readonly distanceScales: DistanceScales;\n\n readonly viewMatrix: number[];\n readonly projectionMatrix: number[];\n\n viewProjectionMatrix: number[];\n pixelProjectionMatrix: number[];\n pixelUnprojectionMatrix: number[];\n\n /**\n * @classdesc\n * Creates view/projection matrices from mercator params\n * Note: The Viewport is immutable in the sense that it only has accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\n // eslint-disable-next-line max-statements\n constructor(props: WebMercatorViewportProps = {width: 1, height: 1}) {\n let {\n // Map state\n width,\n height,\n altitude = null,\n fovy = null\n } = props;\n const {\n latitude = 0,\n longitude = 0,\n zoom = 0,\n pitch = 0,\n bearing = 0,\n position = null,\n nearZMultiplier = 0.02,\n farZMultiplier = 1.01\n } = props;\n\n // Silently allow apps to send in 0,0 to facilitate isomorphic render etc\n width = width || 1;\n height = height || 1;\n\n // `fovy` & `altitude` are independent parameters, one for the\n // projection and the latter for the view matrix. In the past,\n // the `fovy` was always derived from the `altitude`\n if (fovy === null && altitude === null) {\n altitude = DEFAULT_ALTITUDE;\n fovy = altitudeToFovy(altitude);\n } else if (fovy === null) {\n fovy = altitudeToFovy(altitude);\n } else if (altitude === null) {\n altitude = fovyToAltitude(fovy);\n }\n\n const scale = zoomToScale(zoom);\n // Altitude - prevent division by 0\n // TODO - just throw an Error instead?\n altitude = Math.max(0.75, altitude);\n\n const distanceScales = getDistanceScales({longitude, latitude});\n\n const center = lngLatToWorld([longitude, latitude]);\n center.push(0);\n\n if (position) {\n vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));\n }\n\n this.projectionMatrix = getProjectionMatrix({\n width,\n height,\n pitch,\n fovy,\n nearZMultiplier,\n farZMultiplier\n });\n\n this.viewMatrix = getViewMatrix({\n height,\n scale,\n center,\n pitch,\n bearing,\n altitude\n });\n\n // Save parameters\n this.width = width;\n this.height = height;\n this.scale = scale;\n\n this.latitude = latitude;\n this.longitude = longitude;\n this.zoom = zoom;\n this.pitch = pitch;\n this.bearing = bearing;\n this.altitude = altitude;\n this.fovy = fovy;\n this.center = center;\n this.meterOffset = position || [0, 0, 0];\n\n this.distanceScales = distanceScales;\n\n this._initMatrices();\n\n // Bind methods for easy access\n this.equals = this.equals.bind(this);\n this.project = this.project.bind(this);\n this.unproject = this.unproject.bind(this);\n this.projectPosition = this.projectPosition.bind(this);\n this.unprojectPosition = this.unprojectPosition.bind(this);\n\n Object.freeze(this);\n }\n\n _initMatrices(): void {\n const {width, height, projectionMatrix, viewMatrix} = this;\n\n // Note: As usual, matrix operations should be applied in \"reverse\" order\n // since vectors will be multiplied in from the right during transformation\n const vpm = createMat4();\n mat4.multiply(vpm, vpm, projectionMatrix);\n mat4.multiply(vpm, vpm, viewMatrix);\n this.viewProjectionMatrix = vpm;\n\n // Calculate matrices and scales needed for projection\n /**\n * Builds matrices that converts preprojected lngLats to screen pixels\n * and vice versa.\n * Note: Currently returns bottom-left coordinates!\n * Note: Starts with the GL projection matrix and adds steps to the\n * scale and translate that matrix onto the window.\n * Note: WebGL controls clip space to screen projection with gl.viewport\n * and does not need this step.\n */\n const m = createMat4();\n\n // matrix for conversion from location to screen coordinates\n mat4.scale(m, m, [width / 2, -height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n mat4.multiply(m, m, vpm);\n\n const mInverse = mat4.invert(createMat4(), m);\n if (!mInverse) {\n throw new Error('Pixel project matrix not invertible');\n }\n\n this.pixelProjectionMatrix = m;\n this.pixelUnprojectionMatrix = mInverse;\n }\n\n /** Two viewports are equal if width and height are identical, and if\n * their view and projection matrices are (approximately) equal.\n */\n equals(viewport: WebMercatorViewport | null): boolean {\n if (!(viewport instanceof WebMercatorViewport)) {\n return false;\n }\n\n return (\n viewport.width === this.width &&\n viewport.height === this.height &&\n mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&\n mat4.equals(viewport.viewMatrix, this.viewMatrix)\n );\n }\n\n /**\n * Projects xyz (possibly latitude and longitude) to pixel coordinates in window\n * using viewport projection parameters\n * - [longitude, latitude] to [x, y]\n * - [longitude, latitude, Z] => [x, y, z]\n * Note: By default, returns top-left coordinates for canvas/SVG type render\n *\n * @param lngLatZ - [lng, lat] or [lng, lat, Z]\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth\n */\n project(lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] {\n const {topLeft = true} = options;\n const worldPosition = this.projectPosition(lngLatZ);\n const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);\n\n const [x, y] = coord;\n const y2 = topLeft ? y : this.height - y;\n return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];\n }\n\n /**\n * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.\n *\n * - [x, y] => [lng, lat]\n * - [x, y, z] => [lng, lat, Z]\n *\n * @param xyz - screen coordinates, z as pixel depth\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as\n * the elevation plane to unproject onto\n * @return - [lng, lat, Z] or [X, Y, Z]\n */\n unproject(xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] {\n const {topLeft = true, targetZ = undefined} = options;\n const [x, y, z] = xyz;\n\n const y2 = topLeft ? y : this.height - y;\n const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];\n const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);\n const [X, Y, Z] = this.unprojectPosition(coord);\n\n if (Number.isFinite(z)) {\n return [X, Y, Z];\n }\n return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];\n }\n\n // NON_LINEAR PROJECTION HOOKS\n // Used for web meractor projection\n\n projectPosition(xyz: number[]): [number, number, number] {\n const [X, Y] = lngLatToWorld(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];\n return [X, Y, Z];\n }\n\n unprojectPosition(xyz: number[]): [number, number, number] {\n const [X, Y] = worldToLngLat(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];\n return [X, Y, Z];\n }\n\n /**\n * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n * Performs the nonlinear part of the web mercator projection.\n * Remaining projection is done with 4x4 matrices which also handles\n * perspective.\n *\n * @param lngLat - [lng, lat] coordinates\n * Specifies a point on the sphere to project onto the map.\n * @return [x,y] coordinates.\n */\n projectFlat(lngLat: number[]): number[] {\n return lngLatToWorld(lngLat);\n }\n\n /**\n * Unproject world point [x,y] on map onto {lat, lon} on sphere\n *\n * @param xy - array with [x,y] members\n * representing point on projected map plane\n * @return - array with [lat,lon] of point on sphere.\n * Has toArray method if you need a GeoJSON Array.\n * Per cartographic tradition, lat and lon are specified as degrees.\n */\n unprojectFlat(xy: number[]): number[] {\n return worldToLngLat(xy);\n }\n\n /**\n * Get the map center that place a given [lng, lat] coordinate at screen point [x, y]\n * @param opt\n * @param opt.lngLat - [lng,lat] coordinates\n * Specifies a point on the sphere.\n * @param opt.pos - [x,y] coordinates\n * Specifies a point on the screen.\n * @return [lng,lat] new map center.\n */\n getMapCenterByLngLatPosition({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);\n const toLocation = lngLatToWorld(lngLat);\n const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));\n const newCenter = vec2.add([], this.center, translate);\n return worldToLngLat(newCenter);\n }\n\n /**\n * Returns a new viewport that fit around the given rectangle.\n * Only supports non-perspective mode.\n * @param bounds - [[lon, lat], [lon, lat]]\n * @param [options]\n * @param [options.padding] - The amount of padding in pixels to add to the given bounds.\n * @param [options.offset] - The center of the given bounds relative to the map's center,\n * [x, y] measured in pixels.\n * @returns {WebMercatorViewport}\n */\n fitBounds(\n bounds: [[number, number], [number, number]],\n options: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'> = {}\n ): WebMercatorViewport {\n const {width, height} = this;\n const {longitude, latitude, zoom} = fitBounds(Object.assign({width, height, bounds}, options));\n return new WebMercatorViewport({width, height, longitude, latitude, zoom});\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} bounds - [[lon, lat], [lon, lat]]\n */\n getBounds(options?: {z?: number}): number[][] {\n const corners = this.getBoundingRegion(options);\n\n const west = Math.min(...corners.map((p) => p[0]));\n const east = Math.max(...corners.map((p) => p[0]));\n const south = Math.min(...corners.map((p) => p[1]));\n const north = Math.max(...corners.map((p) => p[1]));\n return [\n [west, south],\n [east, north]\n ];\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} an array of 4 points that define the visible region\n */\n getBoundingRegion(options: {z?: number} = {}): number[][] {\n return getBounds(this, options.z || 0);\n }\n\n // DEPRECATED\n\n /** @deprecated Legacy method name */\n getLocationAtPoint({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n return this.getMapCenterByLngLatPosition({lngLat, pos});\n }\n}\n"],"file":"web-mercator-viewport.js"}
1
+ {"version":3,"sources":["../../src/web-mercator-viewport.ts"],"names":["WebMercatorViewport","props","width","height","viewport","mat4","equals","projectionMatrix","viewMatrix","lngLatZ","options","topLeft","worldPosition","projectPosition","coord","pixelProjectionMatrix","x","y","y2","length","xyz","targetZ","undefined","z","targetZWorld","distanceScales","unitsPerMeter","pixelUnprojectionMatrix","unprojectPosition","X","Y","Z","Number","isFinite","metersPerUnit","altitude","fovy","latitude","longitude","zoom","pitch","bearing","position","nearZMultiplier","farZMultiplier","DEFAULT_ALTITUDE","scale","Math","max","center","push","vec3","add","mul","meterOffset","_initMatrices","Object","freeze","vpm","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","lngLat","xy","pos","fromLocation","toLocation","vec2","negate","newCenter","bounds","assign","corners","getBoundingRegion","west","min","map","p","east","south","north","getMapCenterByLngLatPosition"],"mappings":";;;;;;;;;;;;;;;;;;;;;AACA;;AAEA;;AAcA;;AACA;;AAGA;;AACA;;AACA;;;;;;IAiDqBA,mB;AA+BnB,iCAAqE;AAAA;;AAAA,QAAzDC,KAAyD,uEAAvB;AAACC,MAAAA,KAAK,EAAE,CAAR;AAAWC,MAAAA,MAAM,EAAE;AAAnB,KAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kDAgI5D,UAACC,QAAD,EAAmD;AAC1D,UAAI,EAAEA,QAAQ,YAAYJ,mBAAtB,CAAJ,EAAgD;AAC9C,eAAO,KAAP;AACD;;AAED,aACEI,QAAQ,CAACF,KAAT,KAAmB,KAAI,CAACA,KAAxB,IACAE,QAAQ,CAACD,MAAT,KAAoB,KAAI,CAACA,MADzB,IAEAE,IAAI,CAACC,MAAL,CAAYF,QAAQ,CAACG,gBAArB,EAAuC,KAAI,CAACA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AAnDA,GAAmD;AAC7E,aAAO,KAAKiB,4BAAL,CAAkC;AAACnB,QAAAA,MAAM,EAANA,MAAD;AAASE,QAAAA,GAAG,EAAHA;AAAT,OAAlC,CAAP;AACD","sourcesContent":["// View and Projection Matrix calculations for mapbox-js style map view properties\nimport {createMat4} from './math-utils';\n\nimport {\n zoomToScale,\n pixelsToWorld,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n altitudeToFovy,\n fovyToAltitude,\n DEFAULT_ALTITUDE,\n getProjectionMatrix,\n getDistanceScales,\n getViewMatrix,\n DistanceScales\n} from './web-mercator-utils';\nimport fitBounds from './fit-bounds';\nimport getBounds from './get-bounds';\nimport type {FitBoundsOptions} from './fit-bounds';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\n\n/**\n * @param width=1 - Width of \"viewport\" or window\n * @param height=1 - Height of \"viewport\" or window\n * @param scale=1 - Either use scale or zoom\n * @param pitch=0 - Camera angle in degrees (0 is straight down)\n * @param bearing=0 - Map rotation in degrees (0 means north is up)\n * @param fovy= - Field of view of camera in degrees\n * @param altitude= - Altitude of camera in screen units \n *\n * Web mercator projection short-hand parameters\n * @param latitude - Center of viewport on map\n * @param longitude - Center of viewport on map\n * @param zoom - Scale = Math.pow(2,zoom) on map\n\n * Notes:\n * - Only one of center or [latitude, longitude] can be specified\n * - [latitude, longitude] can only be specified when \"mercator\" is true\n * - Altitude has a default value that matches assumptions in mapbox-gl\n * - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl\n * - width and height are forced to 1 if supplied as 0, to avoid\n * division by zero. This is intended to reduce the burden of apps to\n * to check values before instantiating a Viewport.\n */\nexport type WebMercatorViewportProps = {\n // Map state\n width: number;\n height: number;\n latitude?: number;\n longitude?: number;\n position?: number[];\n zoom?: number;\n pitch?: number;\n bearing?: number;\n altitude?: number;\n fovy?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n};\n\n/**\n * The WebMercatorViewport class creates\n * - view/projection matrices\n * - \"uniform values\" (for shaders) from mercator params\n *\n * Note: Instances are immutable in the sense that they only have accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\nexport default class WebMercatorViewport {\n readonly latitude: number;\n readonly longitude: number;\n readonly zoom: number;\n readonly pitch: number;\n readonly bearing: number;\n readonly altitude: number;\n readonly fovy: number;\n\n readonly meterOffset: number[];\n readonly center: number[];\n\n readonly width: number;\n readonly height: number;\n readonly scale: number;\n readonly distanceScales: DistanceScales;\n\n readonly viewMatrix: number[];\n readonly projectionMatrix: number[];\n\n viewProjectionMatrix: number[];\n pixelProjectionMatrix: number[];\n pixelUnprojectionMatrix: number[];\n\n /**\n * @classdesc\n * Creates view/projection matrices from mercator params\n * Note: The Viewport is immutable in the sense that it only has accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\n // eslint-disable-next-line max-statements\n constructor(props: WebMercatorViewportProps = {width: 1, height: 1}) {\n let {\n // Map state\n width,\n height,\n altitude = null,\n fovy = null\n } = props;\n const {\n latitude = 0,\n longitude = 0,\n zoom = 0,\n pitch = 0,\n bearing = 0,\n position = null,\n nearZMultiplier = 0.02,\n farZMultiplier = 1.01\n } = props;\n\n // Silently allow apps to send in 0,0 to facilitate isomorphic render etc\n width = width || 1;\n height = height || 1;\n\n // `fovy` & `altitude` are independent parameters, one for the\n // projection and the latter for the view matrix. In the past,\n // the `fovy` was always derived from the `altitude`\n if (fovy === null && altitude === null) {\n altitude = DEFAULT_ALTITUDE;\n fovy = altitudeToFovy(altitude);\n } else if (fovy === null) {\n fovy = altitudeToFovy(altitude);\n } else if (altitude === null) {\n altitude = fovyToAltitude(fovy);\n }\n\n const scale = zoomToScale(zoom);\n // Altitude - prevent division by 0\n // TODO - just throw an Error instead?\n altitude = Math.max(0.75, altitude);\n\n const distanceScales = getDistanceScales({longitude, latitude});\n\n const center = lngLatToWorld([longitude, latitude]);\n center.push(0);\n\n if (position) {\n vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));\n }\n\n this.projectionMatrix = getProjectionMatrix({\n width,\n height,\n pitch,\n fovy,\n nearZMultiplier,\n farZMultiplier\n });\n\n this.viewMatrix = getViewMatrix({\n height,\n scale,\n center,\n pitch,\n bearing,\n altitude\n });\n\n // Save parameters\n this.width = width;\n this.height = height;\n this.scale = scale;\n\n this.latitude = latitude;\n this.longitude = longitude;\n this.zoom = zoom;\n this.pitch = pitch;\n this.bearing = bearing;\n this.altitude = altitude;\n this.fovy = fovy;\n this.center = center;\n this.meterOffset = position || [0, 0, 0];\n\n this.distanceScales = distanceScales;\n\n this._initMatrices();\n\n Object.freeze(this);\n }\n\n _initMatrices(): void {\n const {width, height, projectionMatrix, viewMatrix} = this;\n\n // Note: As usual, matrix operations should be applied in \"reverse\" order\n // since vectors will be multiplied in from the right during transformation\n const vpm = createMat4();\n mat4.multiply(vpm, vpm, projectionMatrix);\n mat4.multiply(vpm, vpm, viewMatrix);\n this.viewProjectionMatrix = vpm;\n\n // Calculate matrices and scales needed for projection\n /**\n * Builds matrices that converts preprojected lngLats to screen pixels\n * and vice versa.\n * Note: Currently returns bottom-left coordinates!\n * Note: Starts with the GL projection matrix and adds steps to the\n * scale and translate that matrix onto the window.\n * Note: WebGL controls clip space to screen projection with gl.viewport\n * and does not need this step.\n */\n const m = createMat4();\n\n // matrix for conversion from location to screen coordinates\n mat4.scale(m, m, [width / 2, -height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n mat4.multiply(m, m, vpm);\n\n const mInverse = mat4.invert(createMat4(), m);\n if (!mInverse) {\n throw new Error('Pixel project matrix not invertible');\n }\n\n this.pixelProjectionMatrix = m;\n this.pixelUnprojectionMatrix = mInverse;\n }\n\n /** Two viewports are equal if width and height are identical, and if\n * their view and projection matrices are (approximately) equal.\n */\n equals = (viewport: WebMercatorViewport | null): boolean => {\n if (!(viewport instanceof WebMercatorViewport)) {\n return false;\n }\n\n return (\n viewport.width === this.width &&\n viewport.height === this.height &&\n mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&\n mat4.equals(viewport.viewMatrix, this.viewMatrix)\n );\n };\n\n /**\n * Projects xyz (possibly latitude and longitude) to pixel coordinates in window\n * using viewport projection parameters\n * - [longitude, latitude] to [x, y]\n * - [longitude, latitude, Z] => [x, y, z]\n * Note: By default, returns top-left coordinates for canvas/SVG type render\n *\n * @param lngLatZ - [lng, lat] or [lng, lat, Z]\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth\n */\n project = (lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] => {\n const {topLeft = true} = options;\n const worldPosition = this.projectPosition(lngLatZ);\n const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);\n\n const [x, y] = coord;\n const y2 = topLeft ? y : this.height - y;\n return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];\n };\n\n /**\n * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.\n *\n * - [x, y] => [lng, lat]\n * - [x, y, z] => [lng, lat, Z]\n *\n * @param xyz - screen coordinates, z as pixel depth\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as\n * the elevation plane to unproject onto\n * @return - [lng, lat, Z] or [X, Y, Z]\n */\n unproject = (xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] => {\n const {topLeft = true, targetZ = undefined} = options;\n const [x, y, z] = xyz;\n\n const y2 = topLeft ? y : this.height - y;\n const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];\n const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);\n const [X, Y, Z] = this.unprojectPosition(coord);\n\n if (Number.isFinite(z)) {\n return [X, Y, Z];\n }\n return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];\n };\n\n // NON_LINEAR PROJECTION HOOKS\n // Used for web meractor projection\n\n projectPosition = (xyz: number[]): [number, number, number] => {\n const [X, Y] = lngLatToWorld(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];\n return [X, Y, Z];\n };\n\n unprojectPosition = (xyz: number[]): [number, number, number] => {\n const [X, Y] = worldToLngLat(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];\n return [X, Y, Z];\n };\n\n /**\n * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n * Performs the nonlinear part of the web mercator projection.\n * Remaining projection is done with 4x4 matrices which also handles\n * perspective.\n *\n * @param lngLat - [lng, lat] coordinates\n * Specifies a point on the sphere to project onto the map.\n * @return [x,y] coordinates.\n */\n projectFlat(lngLat: number[]): number[] {\n return lngLatToWorld(lngLat);\n }\n\n /**\n * Unproject world point [x,y] on map onto {lat, lon} on sphere\n *\n * @param xy - array with [x,y] members\n * representing point on projected map plane\n * @return - array with [lat,lon] of point on sphere.\n * Has toArray method if you need a GeoJSON Array.\n * Per cartographic tradition, lat and lon are specified as degrees.\n */\n unprojectFlat(xy: number[]): number[] {\n return worldToLngLat(xy);\n }\n\n /**\n * Get the map center that place a given [lng, lat] coordinate at screen point [x, y]\n * @param opt\n * @param opt.lngLat - [lng,lat] coordinates\n * Specifies a point on the sphere.\n * @param opt.pos - [x,y] coordinates\n * Specifies a point on the screen.\n * @return [lng,lat] new map center.\n */\n getMapCenterByLngLatPosition({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);\n const toLocation = lngLatToWorld(lngLat);\n const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));\n const newCenter = vec2.add([], this.center, translate);\n return worldToLngLat(newCenter);\n }\n\n /**\n * Returns a new viewport that fit around the given rectangle.\n * Only supports non-perspective mode.\n * @param bounds - [[lon, lat], [lon, lat]]\n * @param [options]\n * @param [options.padding] - The amount of padding in pixels to add to the given bounds.\n * @param [options.offset] - The center of the given bounds relative to the map's center,\n * [x, y] measured in pixels.\n * @returns {WebMercatorViewport}\n */\n fitBounds(\n bounds: [[number, number], [number, number]],\n options: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'> = {}\n ): WebMercatorViewport {\n const {width, height} = this;\n const {longitude, latitude, zoom} = fitBounds(Object.assign({width, height, bounds}, options));\n return new WebMercatorViewport({width, height, longitude, latitude, zoom});\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} bounds - [[lon, lat], [lon, lat]]\n */\n getBounds(options?: {z?: number}): number[][] {\n const corners = this.getBoundingRegion(options);\n\n const west = Math.min(...corners.map((p) => p[0]));\n const east = Math.max(...corners.map((p) => p[0]));\n const south = Math.min(...corners.map((p) => p[1]));\n const north = Math.max(...corners.map((p) => p[1]));\n return [\n [west, south],\n [east, north]\n ];\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} an array of 4 points that define the visible region\n */\n getBoundingRegion(options: {z?: number} = {}): number[][] {\n return getBounds(this, options.z || 0);\n }\n\n // DEPRECATED\n\n /** @deprecated Legacy method name */\n getLocationAtPoint({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n return this.getMapCenterByLngLatPosition({lngLat, pos});\n }\n}\n"],"file":"web-mercator-viewport.js"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/fly-to-viewport.ts"],"names":["lerp","scaleToZoom","zoomToScale","lngLatToWorld","worldToLngLat","vec2","EPSILON","VIEWPORT_TRANSITION_PROPS","DEFAULT_OPTS","curve","speed","flyToViewport","startProps","endProps","t","options","startZoom","startCenterXY","uDelta","w0","u1","S","rho","rho2","r0","getFlyToTransitionParams","viewport","key","startValue","endValue","s","w","Math","cosh","u","tanh","sinh","scaleIncrement","newZoom","newCenterWorld","scale","add","newCenter","longitude","latitude","zoom","getFlyToDuration","opts","screenSpeed","maxDuration","length","duration","Number","isFinite","Object","assign","startCenter","startScale","endZoom","endCenter","endCenterXY","sub","max","width","height","w1","_u1","b0","b1","log","sqrt","r1"],"mappings":"AAAA,SAAQA,IAAR,QAAmB,cAAnB;AACA,SAAQC,WAAR,EAAqBC,WAArB,EAAkCC,aAAlC,EAAiDC,aAAjD,QAAqE,sBAArE;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAIA,MAAMC,OAAO,GAAG,IAAhB;AACA,MAAMC,yBAAyB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,MAA1B,CAAlC;AACA,MAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,KADY;AAEnBC,EAAAA,KAAK,EAAE;AAFY,CAArB;AAkBA,eAAe,SAASC,aAAT,CACbC,UADa,EAEbC,QAFa,EAGbC,CAHa,EAIbC,OAJa,EASb;AAGA,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,aAAZ;AAA2BC,IAAAA,MAA3B;AAAmCC,IAAAA,EAAnC;AAAuCC,IAAAA,EAAvC;AAA2CC,IAAAA,CAA3C;AAA8CC,IAAAA,GAA9C;AAAmDC,IAAAA,IAAnD;AAAyDC,IAAAA;AAAzD,MAA+DC,wBAAwB,CAC3Fb,UAD2F,EAE3FC,QAF2F,EAG3FE,OAH2F,CAA7F;;AAOA,MAAIK,EAAE,GAAGd,OAAT,EAAkB;AAChB,UAAMoB,QAAQ,GAAG,EAAjB;;AACA,SAAK,MAAMC,GAAX,IAAkBpB,yBAAlB,EAA6C;AAC3C,YAAMqB,UAAU,GAAGhB,UAAU,CAACe,GAAD,CAA7B;AACA,YAAME,QAAQ,GAAGhB,QAAQ,CAACc,GAAD,CAAzB;AACAD,MAAAA,QAAQ,CAACC,GAAD,CAAR,GAAgB3B,IAAI,CAAC4B,UAAD,EAAaC,QAAb,EAAuBf,CAAvB,CAApB;AACD;;AAED,WAAOY,QAAP;AACD;;AAED,QAAMI,CAAC,GAAGhB,CAAC,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AyDC,IAAAA,EAAzD;AAA6D+C,IAAAA;AAA7D,GAAP;AACD","sourcesContent":["import {lerp} from './math-utils';\nimport {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';\nimport * as vec2 from 'gl-matrix/vec2';\n\nimport type {ViewportProps} from './normalize-viewport-props';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;\nconst DEFAULT_OPTS = {\n curve: 1.414,\n speed: 1.2\n // screenSpeed and maxDuration are used only if specified\n};\n\nexport type FlytoTransitionOptions = {\n curve?: number;\n speed?: number;\n screenSpeed?: number;\n maxDuration?: number;\n};\n\n/**\n * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.\n * It implements “Smooth and efficient zooming and panning.” algorithm by\n * \"Jarke J. van Wijk and Wim A.A. Nuij\"\n */\nexport default function flyToViewport(\n startProps: ViewportProps,\n endProps: ViewportProps,\n t: number,\n options?: FlytoTransitionOptions\n): {\n longitude: number;\n latitude: number;\n zoom: number;\n} {\n // Equations from above paper are referred where needed.\n\n const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(\n startProps,\n endProps,\n options\n );\n\n // If change in center is too small, do linear interpolaiton.\n if (u1 < EPSILON) {\n const viewport = {};\n for (const key of VIEWPORT_TRANSITION_PROPS) {\n const startValue = startProps[key];\n const endValue = endProps[key];\n viewport[key] = lerp(startValue, endValue, t);\n }\n // @ts-expect-error\n return viewport;\n }\n\n const s = t * S;\n\n const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);\n const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;\n\n const scaleIncrement = 1 / w; // Using w method for scaling.\n const newZoom = startZoom + scaleToZoom(scaleIncrement);\n\n const newCenterWorld = vec2.scale([], uDelta, u);\n vec2.add(newCenterWorld, newCenterWorld, startCenterXY);\n\n const newCenter = worldToLngLat(newCenterWorld);\n return {\n longitude: newCenter[0],\n latitude: newCenter[1],\n zoom: newZoom\n };\n}\n\n// returns transition duration in milliseconds\nexport function getFlyToDuration(\n startProps: ViewportProps,\n endProps: ViewportProps,\n options?: FlytoTransitionOptions\n): number {\n const opts = {...DEFAULT_OPTS, ...options};\n const {screenSpeed, speed, maxDuration} = opts;\n const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);\n const length = 1000 * S;\n let duration: number;\n if (Number.isFinite(screenSpeed)) {\n duration = length / (screenSpeed / rho);\n } else {\n duration = length / speed;\n }\n\n return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;\n}\n\n// Private Methods\n\n// Calculate all parameters that are static for given startProps and endProps\nfunction getFlyToTransitionParams(\n startProps: ViewportProps,\n endProps: ViewportProps,\n opts: FlytoTransitionOptions\n): {\n startZoom: number;\n startCenterXY: number[];\n uDelta: number[];\n w0: number;\n u1: number;\n S: number;\n rho: number;\n rho2: number;\n r0: number;\n r1: number;\n} {\n opts = Object.assign({}, DEFAULT_OPTS, opts);\n const rho = opts.curve;\n const startZoom = startProps.zoom;\n const startCenter = [startProps.longitude, startProps.latitude];\n const startScale = zoomToScale(startZoom);\n const endZoom = endProps.zoom;\n const endCenter = [endProps.longitude, endProps.latitude];\n const scale = zoomToScale(endZoom - startZoom);\n\n const startCenterXY = lngLatToWorld(startCenter);\n const endCenterXY = lngLatToWorld(endCenter);\n const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);\n\n const w0 = Math.max(startProps.width, startProps.height);\n const w1 = w0 / scale;\n const u1 = vec2.length(uDelta) * startScale;\n // u0 is treated as '0' in Eq (9).\n\n // If u1 is too small, will generate invalid number\n const _u1 = Math.max(u1, EPSILON);\n\n // Implement Equation (9) from above algorithm.\n const rho2 = rho * rho;\n const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);\n const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);\n const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);\n const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n const S = (r1 - r0) / rho;\n\n return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};\n}\n"],"file":"fly-to-viewport.js"}
1
+ {"version":3,"sources":["../../src/fly-to-viewport.ts"],"names":["lerp","scaleToZoom","zoomToScale","lngLatToWorld","worldToLngLat","vec2","EPSILON","VIEWPORT_TRANSITION_PROPS","DEFAULT_OPTS","curve","speed","flyToViewport","startProps","endProps","t","options","startZoom","startCenterXY","uDelta","w0","u1","S","rho","rho2","r0","getFlyToTransitionParams","viewport","key","startValue","endValue","s","w","Math","cosh","u","tanh","sinh","scaleIncrement","newZoom","newCenterWorld","scale","add","newCenter","longitude","latitude","zoom","getFlyToDuration","opts","screenSpeed","maxDuration","length","duration","Number","isFinite","Object","assign","startCenter","startScale","endZoom","endCenter","endCenterXY","sub","max","width","height","w1","_u1","b0","b1","log","sqrt","r1"],"mappings":"AAAA,SAAQA,IAAR,QAAmB,cAAnB;AACA,SAAQC,WAAR,EAAqBC,WAArB,EAAkCC,aAAlC,EAAiDC,aAAjD,QAAqE,sBAArE;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAIA,MAAMC,OAAO,GAAG,IAAhB;AACA,MAAMC,yBAAyB,GAAG,CAAC,WAAD,EAAc,UAAd,EAA0B,MAA1B,CAAlC;AACA,MAAMC,YAAY,GAAG;AACnBC,EAAAA,KAAK,EAAE,KADY;AAEnBC,EAAAA,KAAK,EAAE;AAFY,CAArB;AAkBA,eAAe,SAASC,aAAT,CACbC,UADa,EAEbC,QAFa,EAGbC,CAHa,EAIbC,OAJa,EASb;AAGA,QAAM;AAACC,IAAAA,SAAD;AAAYC,IAAAA,aAAZ;AAA2BC,IAAAA,MAA3B;AAAmCC,IAAAA,EAAnC;AAAuCC,IAAAA,EAAvC;AAA2C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1C,IAAT,GAAgB2C,GAAjE,CAAX;AACA,QAAM1C,EAAE,GAAGQ,IAAI,CAACqC,GAAL,CAASrC,IAAI,CAACsC,IAAL,CAAUH,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,QAAMI,EAAE,GAAGvC,IAAI,CAACqC,GAAL,CAASrC,IAAI,CAACsC,IAAL,CAAUF,EAAE,GAAGA,EAAL,GAAU,CAApB,IAAyBA,EAAlC,CAAX;AACA,QAAM/C,CAAC,GAAG,CAACkD,EAAE,GAAG/C,EAAN,IAAYF,GAAtB;AAEA,SAAO;AAACN,IAAAA,SAAD;AAAYC,IAAAA,aAAZ;AAA2BC,IAAAA,MAA3B;AAAmCC,IAAAA,EAAnC;AAAuCC,IAAAA,EAAvC;AAA2CC,IAAAA,CAA3C;AAA8CC,IAAAA,GAA9C;AAAmDC,IAAAA,IAAnD;AAAyDC,IAAAA,EAAzD;AAA6D+C,IAAAA;AAA7D,GAAP;AACD","sourcesContent":["import {lerp} from './math-utils';\nimport {scaleToZoom, zoomToScale, lngLatToWorld, worldToLngLat} from './web-mercator-utils';\nimport * as vec2 from 'gl-matrix/vec2';\n\nimport type {ViewportProps} from './normalize-viewport-props';\n\nconst EPSILON = 0.01;\nconst VIEWPORT_TRANSITION_PROPS = ['longitude', 'latitude', 'zoom'] as const;\nconst DEFAULT_OPTS = {\n curve: 1.414,\n speed: 1.2\n // screenSpeed and maxDuration are used only if specified\n};\n\nexport type FlytoTransitionOptions = {\n curve?: number;\n speed?: number;\n screenSpeed?: number;\n maxDuration?: number;\n};\n\n/**\n * mapbox-gl-js flyTo : https://www.mapbox.com/mapbox-gl-js/api/#map#flyto.\n * It implements “Smooth and efficient zooming and panning.” algorithm by\n * \"Jarke J. van Wijk and Wim A.A. Nuij\"\n */\nexport default function flyToViewport(\n startProps: ViewportProps,\n endProps: ViewportProps,\n t: number,\n options?: FlytoTransitionOptions\n): {\n longitude: number;\n latitude: number;\n zoom: number;\n} {\n // Equations from above paper are referred where needed.\n\n const {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0} = getFlyToTransitionParams(\n startProps,\n endProps,\n options\n );\n\n // If change in center is too small, do linear interpolaiton.\n if (u1 < EPSILON) {\n const viewport = {};\n for (const key of VIEWPORT_TRANSITION_PROPS) {\n const startValue = startProps[key];\n const endValue = endProps[key];\n viewport[key] = lerp(startValue, endValue, t);\n }\n // @ts-expect-error properties are populated dynamically\n return viewport;\n }\n\n const s = t * S;\n\n const w = Math.cosh(r0) / Math.cosh(r0 + rho * s);\n const u = (w0 * ((Math.cosh(r0) * Math.tanh(r0 + rho * s) - Math.sinh(r0)) / rho2)) / u1;\n\n const scaleIncrement = 1 / w; // Using w method for scaling.\n const newZoom = startZoom + scaleToZoom(scaleIncrement);\n\n const newCenterWorld = vec2.scale([], uDelta, u);\n vec2.add(newCenterWorld, newCenterWorld, startCenterXY);\n\n const newCenter = worldToLngLat(newCenterWorld);\n return {\n longitude: newCenter[0],\n latitude: newCenter[1],\n zoom: newZoom\n };\n}\n\n// returns transition duration in milliseconds\nexport function getFlyToDuration(\n startProps: ViewportProps,\n endProps: ViewportProps,\n options?: FlytoTransitionOptions\n): number {\n const opts = {...DEFAULT_OPTS, ...options};\n const {screenSpeed, speed, maxDuration} = opts;\n const {S, rho} = getFlyToTransitionParams(startProps, endProps, opts);\n const length = 1000 * S;\n let duration: number;\n if (Number.isFinite(screenSpeed)) {\n duration = length / (screenSpeed / rho);\n } else {\n duration = length / speed;\n }\n\n return Number.isFinite(maxDuration) && duration > maxDuration ? 0 : duration;\n}\n\n// Private Methods\n\n// Calculate all parameters that are static for given startProps and endProps\nfunction getFlyToTransitionParams(\n startProps: ViewportProps,\n endProps: ViewportProps,\n opts: FlytoTransitionOptions\n): {\n startZoom: number;\n startCenterXY: number[];\n uDelta: number[];\n w0: number;\n u1: number;\n S: number;\n rho: number;\n rho2: number;\n r0: number;\n r1: number;\n} {\n opts = Object.assign({}, DEFAULT_OPTS, opts);\n const rho = opts.curve;\n const startZoom = startProps.zoom;\n const startCenter = [startProps.longitude, startProps.latitude];\n const startScale = zoomToScale(startZoom);\n const endZoom = endProps.zoom;\n const endCenter = [endProps.longitude, endProps.latitude];\n const scale = zoomToScale(endZoom - startZoom);\n\n const startCenterXY = lngLatToWorld(startCenter);\n const endCenterXY = lngLatToWorld(endCenter);\n const uDelta = vec2.sub([] as number[], endCenterXY, startCenterXY);\n\n const w0 = Math.max(startProps.width, startProps.height);\n const w1 = w0 / scale;\n const u1 = vec2.length(uDelta) * startScale;\n // u0 is treated as '0' in Eq (9).\n\n // If u1 is too small, will generate invalid number\n const _u1 = Math.max(u1, EPSILON);\n\n // Implement Equation (9) from above algorithm.\n const rho2 = rho * rho;\n const b0 = (w1 * w1 - w0 * w0 + rho2 * rho2 * _u1 * _u1) / (2 * w0 * rho2 * _u1);\n const b1 = (w1 * w1 - w0 * w0 - rho2 * rho2 * _u1 * _u1) / (2 * w1 * rho2 * _u1);\n const r0 = Math.log(Math.sqrt(b0 * b0 + 1) - b0);\n const r1 = Math.log(Math.sqrt(b1 * b1 + 1) - b1);\n const S = (r1 - r0) / rho;\n\n return {startZoom, startCenterXY, uDelta, w0, u1, S, rho, rho2, r0, r1};\n}\n"],"file":"fly-to-viewport.js"}
@@ -47,6 +47,55 @@ export default class WebMercatorViewport {
47
47
 
48
48
  _defineProperty(this, "pixelUnprojectionMatrix", void 0);
49
49
 
50
+ _defineProperty(this, "equals", viewport => {
51
+ if (!(viewport instanceof WebMercatorViewport)) {
52
+ return false;
53
+ }
54
+
55
+ return viewport.width === this.width && viewport.height === this.height && mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && mat4.equals(viewport.viewMatrix, this.viewMatrix);
56
+ });
57
+
58
+ _defineProperty(this, "project", (lngLatZ, options = {}) => {
59
+ const {
60
+ topLeft = true
61
+ } = options;
62
+ const worldPosition = this.projectPosition(lngLatZ);
63
+ const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);
64
+ const [x, y] = coord;
65
+ const y2 = topLeft ? y : this.height - y;
66
+ return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
67
+ });
68
+
69
+ _defineProperty(this, "unproject", (xyz, options = {}) => {
70
+ const {
71
+ topLeft = true,
72
+ targetZ = undefined
73
+ } = options;
74
+ const [x, y, z] = xyz;
75
+ const y2 = topLeft ? y : this.height - y;
76
+ const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
77
+ const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);
78
+ const [X, Y, Z] = this.unprojectPosition(coord);
79
+
80
+ if (Number.isFinite(z)) {
81
+ return [X, Y, Z];
82
+ }
83
+
84
+ return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
85
+ });
86
+
87
+ _defineProperty(this, "projectPosition", xyz => {
88
+ const [X, Y] = lngLatToWorld(xyz);
89
+ const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
90
+ return [X, Y, Z];
91
+ });
92
+
93
+ _defineProperty(this, "unprojectPosition", xyz => {
94
+ const [X, Y] = worldToLngLat(xyz);
95
+ const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
96
+ return [X, Y, Z];
97
+ });
98
+
50
99
  let {
51
100
  width,
52
101
  height,
@@ -120,11 +169,6 @@ export default class WebMercatorViewport {
120
169
 
121
170
  this._initMatrices();
122
171
 
123
- this.equals = this.equals.bind(this);
124
- this.project = this.project.bind(this);
125
- this.unproject = this.unproject.bind(this);
126
- this.projectPosition = this.projectPosition.bind(this);
127
- this.unprojectPosition = this.unprojectPosition.bind(this);
128
172
  Object.freeze(this);
129
173
  }
130
174
 
@@ -153,55 +197,6 @@ export default class WebMercatorViewport {
153
197
  this.pixelUnprojectionMatrix = mInverse;
154
198
  }
155
199
 
156
- equals(viewport) {
157
- if (!(viewport instanceof WebMercatorViewport)) {
158
- return false;
159
- }
160
-
161
- return viewport.width === this.width && viewport.height === this.height && mat4.equals(viewport.projectionMatrix, this.projectionMatrix) && mat4.equals(viewport.viewMatrix, this.viewMatrix);
162
- }
163
-
164
- project(lngLatZ, options = {}) {
165
- const {
166
- topLeft = true
167
- } = options;
168
- const worldPosition = this.projectPosition(lngLatZ);
169
- const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);
170
- const [x, y] = coord;
171
- const y2 = topLeft ? y : this.height - y;
172
- return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
173
- }
174
-
175
- unproject(xyz, options = {}) {
176
- const {
177
- topLeft = true,
178
- targetZ = undefined
179
- } = options;
180
- const [x, y, z] = xyz;
181
- const y2 = topLeft ? y : this.height - y;
182
- const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
183
- const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);
184
- const [X, Y, Z] = this.unprojectPosition(coord);
185
-
186
- if (Number.isFinite(z)) {
187
- return [X, Y, Z];
188
- }
189
-
190
- return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
191
- }
192
-
193
- projectPosition(xyz) {
194
- const [X, Y] = lngLatToWorld(xyz);
195
- const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
196
- return [X, Y, Z];
197
- }
198
-
199
- unprojectPosition(xyz) {
200
- const [X, Y] = worldToLngLat(xyz);
201
- const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
202
- return [X, Y, Z];
203
- }
204
-
205
200
  projectFlat(lngLat) {
206
201
  return lngLatToWorld(lngLat);
207
202
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/web-mercator-viewport.ts"],"names":["createMat4","zoomToScale","pixelsToWorld","lngLatToWorld","worldToLngLat","worldToPixels","altitudeToFovy","fovyToAltitude","DEFAULT_ALTITUDE","getProjectionMatrix","getDistanceScales","getViewMatrix","fitBounds","getBounds","mat4","vec2","vec3","WebMercatorViewport","constructor","props","width","height","altitude","fovy","latitude","longitude","zoom","pitch","bearing","position","nearZMultiplier","farZMultiplier","scale","Math","max","distanceScales","center","push","add","mul","unitsPerMeter","projectionMatrix","viewMatrix","meterOffset","_initMatrices","equals","bind","project","unproject","projectPosition","unprojectPosition","Object","freeze","vpm","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","pixelProjectionMatrix","pixelUnprojectionMatrix","viewport","lngLatZ","options","topLeft","worldPosition","coord","x","y","y2","length","xyz","targetZ","undefined","z","targetZWorld","X","Y","Z","Number","isFinite","metersPerUnit","projectFlat","lngLat","unprojectFlat","xy","getMapCenterByLngLatPosition","pos","fromLocation","toLocation","negate","newCenter","bounds","assign","corners","getBoundingRegion","west","min","map","p","east","south","north","getLocationAtPoint"],"mappings":";AACA,SAAQA,UAAR,QAAyB,cAAzB;AAEA,SACEC,WADF,EAEEC,aAFF,EAGEC,aAHF,EAIEC,aAJF,EAKEC,aALF,EAMEC,cANF,EAOEC,cAPF,EAQEC,gBARF,EASEC,mBATF,EAUEC,iBAVF,EAWEC,aAXF,QAaO,sBAbP;AAcA,OAAOC,SAAP,MAAsB,cAAtB;AACA,OAAOC,SAAP,MAAsB,cAAtB;AAGA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AACA,OAAO,KAAKC,IAAZ,MAAsB,gBAAtB;AAiDA,eAAe,MAAMC,mBAAN,CAA0B;AA+BvCC,EAAAA,WAAW,CAACC,KAA+B,GAAG;AAACC,IAAAA,KAAK,EAAE,CAAR;AAAWC,IAAAA,MAAM,EAAE;AAAnB,GAAnC,EAA0D;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AAAA;;AACnE,QAAI;AAEFD,MAAAA,KAFE;AAGFC,MAAAA,MAHE;AAIFC,MAAAA,QAAQ,GAAG,IAJT;AAKFC,MAAAA,IAAI,GAAG;AALL,QAMAJ,KAN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B,CAAhB;AAEA,UAAMiC,IAAI,GAAGjE,IAAI,CAACkE,GAAL,CAAS,GAAGH,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAb;AACA,UAAMC,IAAI,GAAGrE,IAAI,CAACC,GAAL,CAAS,GAAG8D,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAb;AACA,UAAME,KAAK,GAAGtE,IAAI,CAACkE,GAAL,CAAS,GAAGH,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAd;AACA,UAAMG,KAAK,GAAGvE,IAAI,CAACC,GAAL,CAAS,GAAG8D,OAAO,CAACI,GAAR,CAAaC,CAAD,IAAOA,CAAC,CAAC,CAAD,CAApB,CAAZ,CAAd;AACA,WAAO,CACL,CAACH,IAAD,EAAOK,KAAP,CADK,EAEL,CAACD,IAAD,EAAOE,KAAP,CAFK,CAAP;AAID;;AAQDP,EAAAA,iBAAiB,CAAChC,OAAqB,GAAG,EAAzB,EAAyC;AACxD,WAAOpD,SAAS,CAAC,IAAD,EAAOoD,OAAO,CAACW,CAAR,IAAa,CAApB,CAAhB;AACD;;AAKD6B,EAAAA,kBAAkB,CAAC;AAACpB,IAAAA,MAAD;AAASI,IAAAA;AAAT,GAAD,EAA6D;AAC7E,WAAO,KAAKD,4BAAL,CAAkC;AAACH,MAAAA,MAAD;AAASI,MAAAA;AAAT,KAAlC,CAAP;AACD;;AArVsC","sourcesContent":["// View and Projection Matrix calculations for mapbox-js style map view properties\nimport {createMat4} from './math-utils';\n\nimport {\n zoomToScale,\n pixelsToWorld,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n altitudeToFovy,\n fovyToAltitude,\n DEFAULT_ALTITUDE,\n getProjectionMatrix,\n getDistanceScales,\n getViewMatrix,\n DistanceScales\n} from './web-mercator-utils';\nimport fitBounds from './fit-bounds';\nimport getBounds from './get-bounds';\nimport type {FitBoundsOptions} from './fit-bounds';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\n\n/**\n * @param width=1 - Width of \"viewport\" or window\n * @param height=1 - Height of \"viewport\" or window\n * @param scale=1 - Either use scale or zoom\n * @param pitch=0 - Camera angle in degrees (0 is straight down)\n * @param bearing=0 - Map rotation in degrees (0 means north is up)\n * @param fovy= - Field of view of camera in degrees\n * @param altitude= - Altitude of camera in screen units \n *\n * Web mercator projection short-hand parameters\n * @param latitude - Center of viewport on map\n * @param longitude - Center of viewport on map\n * @param zoom - Scale = Math.pow(2,zoom) on map\n\n * Notes:\n * - Only one of center or [latitude, longitude] can be specified\n * - [latitude, longitude] can only be specified when \"mercator\" is true\n * - Altitude has a default value that matches assumptions in mapbox-gl\n * - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl\n * - width and height are forced to 1 if supplied as 0, to avoid\n * division by zero. This is intended to reduce the burden of apps to\n * to check values before instantiating a Viewport.\n */\nexport type WebMercatorViewportProps = {\n // Map state\n width: number;\n height: number;\n latitude?: number;\n longitude?: number;\n position?: number[];\n zoom?: number;\n pitch?: number;\n bearing?: number;\n altitude?: number;\n fovy?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n};\n\n/**\n * The WebMercatorViewport class creates\n * - view/projection matrices\n * - \"uniform values\" (for shaders) from mercator params\n *\n * Note: Instances are immutable in the sense that they only have accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\nexport default class WebMercatorViewport {\n readonly latitude: number;\n readonly longitude: number;\n readonly zoom: number;\n readonly pitch: number;\n readonly bearing: number;\n readonly altitude: number;\n readonly fovy: number;\n\n readonly meterOffset: number[];\n readonly center: number[];\n\n readonly width: number;\n readonly height: number;\n readonly scale: number;\n readonly distanceScales: DistanceScales;\n\n readonly viewMatrix: number[];\n readonly projectionMatrix: number[];\n\n viewProjectionMatrix: number[];\n pixelProjectionMatrix: number[];\n pixelUnprojectionMatrix: number[];\n\n /**\n * @classdesc\n * Creates view/projection matrices from mercator params\n * Note: The Viewport is immutable in the sense that it only has accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\n // eslint-disable-next-line max-statements\n constructor(props: WebMercatorViewportProps = {width: 1, height: 1}) {\n let {\n // Map state\n width,\n height,\n altitude = null,\n fovy = null\n } = props;\n const {\n latitude = 0,\n longitude = 0,\n zoom = 0,\n pitch = 0,\n bearing = 0,\n position = null,\n nearZMultiplier = 0.02,\n farZMultiplier = 1.01\n } = props;\n\n // Silently allow apps to send in 0,0 to facilitate isomorphic render etc\n width = width || 1;\n height = height || 1;\n\n // `fovy` & `altitude` are independent parameters, one for the\n // projection and the latter for the view matrix. In the past,\n // the `fovy` was always derived from the `altitude`\n if (fovy === null && altitude === null) {\n altitude = DEFAULT_ALTITUDE;\n fovy = altitudeToFovy(altitude);\n } else if (fovy === null) {\n fovy = altitudeToFovy(altitude);\n } else if (altitude === null) {\n altitude = fovyToAltitude(fovy);\n }\n\n const scale = zoomToScale(zoom);\n // Altitude - prevent division by 0\n // TODO - just throw an Error instead?\n altitude = Math.max(0.75, altitude);\n\n const distanceScales = getDistanceScales({longitude, latitude});\n\n const center = lngLatToWorld([longitude, latitude]);\n center.push(0);\n\n if (position) {\n vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));\n }\n\n this.projectionMatrix = getProjectionMatrix({\n width,\n height,\n pitch,\n fovy,\n nearZMultiplier,\n farZMultiplier\n });\n\n this.viewMatrix = getViewMatrix({\n height,\n scale,\n center,\n pitch,\n bearing,\n altitude\n });\n\n // Save parameters\n this.width = width;\n this.height = height;\n this.scale = scale;\n\n this.latitude = latitude;\n this.longitude = longitude;\n this.zoom = zoom;\n this.pitch = pitch;\n this.bearing = bearing;\n this.altitude = altitude;\n this.fovy = fovy;\n this.center = center;\n this.meterOffset = position || [0, 0, 0];\n\n this.distanceScales = distanceScales;\n\n this._initMatrices();\n\n // Bind methods for easy access\n this.equals = this.equals.bind(this);\n this.project = this.project.bind(this);\n this.unproject = this.unproject.bind(this);\n this.projectPosition = this.projectPosition.bind(this);\n this.unprojectPosition = this.unprojectPosition.bind(this);\n\n Object.freeze(this);\n }\n\n _initMatrices(): void {\n const {width, height, projectionMatrix, viewMatrix} = this;\n\n // Note: As usual, matrix operations should be applied in \"reverse\" order\n // since vectors will be multiplied in from the right during transformation\n const vpm = createMat4();\n mat4.multiply(vpm, vpm, projectionMatrix);\n mat4.multiply(vpm, vpm, viewMatrix);\n this.viewProjectionMatrix = vpm;\n\n // Calculate matrices and scales needed for projection\n /**\n * Builds matrices that converts preprojected lngLats to screen pixels\n * and vice versa.\n * Note: Currently returns bottom-left coordinates!\n * Note: Starts with the GL projection matrix and adds steps to the\n * scale and translate that matrix onto the window.\n * Note: WebGL controls clip space to screen projection with gl.viewport\n * and does not need this step.\n */\n const m = createMat4();\n\n // matrix for conversion from location to screen coordinates\n mat4.scale(m, m, [width / 2, -height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n mat4.multiply(m, m, vpm);\n\n const mInverse = mat4.invert(createMat4(), m);\n if (!mInverse) {\n throw new Error('Pixel project matrix not invertible');\n }\n\n this.pixelProjectionMatrix = m;\n this.pixelUnprojectionMatrix = mInverse;\n }\n\n /** Two viewports are equal if width and height are identical, and if\n * their view and projection matrices are (approximately) equal.\n */\n equals(viewport: WebMercatorViewport | null): boolean {\n if (!(viewport instanceof WebMercatorViewport)) {\n return false;\n }\n\n return (\n viewport.width === this.width &&\n viewport.height === this.height &&\n mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&\n mat4.equals(viewport.viewMatrix, this.viewMatrix)\n );\n }\n\n /**\n * Projects xyz (possibly latitude and longitude) to pixel coordinates in window\n * using viewport projection parameters\n * - [longitude, latitude] to [x, y]\n * - [longitude, latitude, Z] => [x, y, z]\n * Note: By default, returns top-left coordinates for canvas/SVG type render\n *\n * @param lngLatZ - [lng, lat] or [lng, lat, Z]\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth\n */\n project(lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] {\n const {topLeft = true} = options;\n const worldPosition = this.projectPosition(lngLatZ);\n const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);\n\n const [x, y] = coord;\n const y2 = topLeft ? y : this.height - y;\n return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];\n }\n\n /**\n * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.\n *\n * - [x, y] => [lng, lat]\n * - [x, y, z] => [lng, lat, Z]\n *\n * @param xyz - screen coordinates, z as pixel depth\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as\n * the elevation plane to unproject onto\n * @return - [lng, lat, Z] or [X, Y, Z]\n */\n unproject(xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] {\n const {topLeft = true, targetZ = undefined} = options;\n const [x, y, z] = xyz;\n\n const y2 = topLeft ? y : this.height - y;\n const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];\n const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);\n const [X, Y, Z] = this.unprojectPosition(coord);\n\n if (Number.isFinite(z)) {\n return [X, Y, Z];\n }\n return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];\n }\n\n // NON_LINEAR PROJECTION HOOKS\n // Used for web meractor projection\n\n projectPosition(xyz: number[]): [number, number, number] {\n const [X, Y] = lngLatToWorld(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];\n return [X, Y, Z];\n }\n\n unprojectPosition(xyz: number[]): [number, number, number] {\n const [X, Y] = worldToLngLat(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];\n return [X, Y, Z];\n }\n\n /**\n * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n * Performs the nonlinear part of the web mercator projection.\n * Remaining projection is done with 4x4 matrices which also handles\n * perspective.\n *\n * @param lngLat - [lng, lat] coordinates\n * Specifies a point on the sphere to project onto the map.\n * @return [x,y] coordinates.\n */\n projectFlat(lngLat: number[]): number[] {\n return lngLatToWorld(lngLat);\n }\n\n /**\n * Unproject world point [x,y] on map onto {lat, lon} on sphere\n *\n * @param xy - array with [x,y] members\n * representing point on projected map plane\n * @return - array with [lat,lon] of point on sphere.\n * Has toArray method if you need a GeoJSON Array.\n * Per cartographic tradition, lat and lon are specified as degrees.\n */\n unprojectFlat(xy: number[]): number[] {\n return worldToLngLat(xy);\n }\n\n /**\n * Get the map center that place a given [lng, lat] coordinate at screen point [x, y]\n * @param opt\n * @param opt.lngLat - [lng,lat] coordinates\n * Specifies a point on the sphere.\n * @param opt.pos - [x,y] coordinates\n * Specifies a point on the screen.\n * @return [lng,lat] new map center.\n */\n getMapCenterByLngLatPosition({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);\n const toLocation = lngLatToWorld(lngLat);\n const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));\n const newCenter = vec2.add([], this.center, translate);\n return worldToLngLat(newCenter);\n }\n\n /**\n * Returns a new viewport that fit around the given rectangle.\n * Only supports non-perspective mode.\n * @param bounds - [[lon, lat], [lon, lat]]\n * @param [options]\n * @param [options.padding] - The amount of padding in pixels to add to the given bounds.\n * @param [options.offset] - The center of the given bounds relative to the map's center,\n * [x, y] measured in pixels.\n * @returns {WebMercatorViewport}\n */\n fitBounds(\n bounds: [[number, number], [number, number]],\n options: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'> = {}\n ): WebMercatorViewport {\n const {width, height} = this;\n const {longitude, latitude, zoom} = fitBounds(Object.assign({width, height, bounds}, options));\n return new WebMercatorViewport({width, height, longitude, latitude, zoom});\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} bounds - [[lon, lat], [lon, lat]]\n */\n getBounds(options?: {z?: number}): number[][] {\n const corners = this.getBoundingRegion(options);\n\n const west = Math.min(...corners.map((p) => p[0]));\n const east = Math.max(...corners.map((p) => p[0]));\n const south = Math.min(...corners.map((p) => p[1]));\n const north = Math.max(...corners.map((p) => p[1]));\n return [\n [west, south],\n [east, north]\n ];\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} an array of 4 points that define the visible region\n */\n getBoundingRegion(options: {z?: number} = {}): number[][] {\n return getBounds(this, options.z || 0);\n }\n\n // DEPRECATED\n\n /** @deprecated Legacy method name */\n getLocationAtPoint({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n return this.getMapCenterByLngLatPosition({lngLat, pos});\n }\n}\n"],"file":"web-mercator-viewport.js"}
1
+ {"version":3,"sources":["../../src/web-mercator-viewport.ts"],"names":["createMat4","zoomToScale","pixelsToWorld","lngLatToWorld","worldToLngLat","worldToPixels","altitudeToFovy","fovyToAltitude","DEFAULT_ALTITUDE","getProjectionMatrix","getDistanceScales","getViewMatrix","fitBounds","getBounds","mat4","vec2","vec3","WebMercatorViewport","constructor","props","width","height","viewport","equals","projectionMatrix","viewMatrix","lngLatZ","options","topLeft","worldPosition","projectPosition","coord","pixelProjectionMatrix","x","y","y2","length","xyz","targetZ","undefined","z","targetZWorld","distanceScales","unitsPerMeter","pixelUnprojectionMatrix","X","Y","Z","unprojectPosition","Number","isFinite","metersPerUnit","altitude","fovy","latitude","longitude","zoom","pitch","bearing","position","nearZMultiplier","farZMultiplier","scale","Math","max","center","push","add","mul","meterOffset","_initMatrices","Object","freeze","vpm","multiply","viewProjectionMatrix","m","translate","mInverse","invert","Error","projectFlat","lngLat","unprojectFlat","xy","getMapCenterByLngLatPosition","pos","fromLocation","toLocation","negate","newC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,OAAO,CAACa,CAAR,IAAa,CAApB,CAAhB;AACD;;AAKD8D,EAAAA,kBAAkB,CAAC;AAACpB,IAAAA,MAAD;AAASI,IAAAA;AAAT,GAAD,EAA6D;AAC7E,WAAO,KAAKD,4BAAL,CAAkC;AAACH,MAAAA,MAAD;AAASI,MAAAA;AAAT,KAAlC,CAAP;AACD;;AA9UsC","sourcesContent":["// View and Projection Matrix calculations for mapbox-js style map view properties\nimport {createMat4} from './math-utils';\n\nimport {\n zoomToScale,\n pixelsToWorld,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n altitudeToFovy,\n fovyToAltitude,\n DEFAULT_ALTITUDE,\n getProjectionMatrix,\n getDistanceScales,\n getViewMatrix,\n DistanceScales\n} from './web-mercator-utils';\nimport fitBounds from './fit-bounds';\nimport getBounds from './get-bounds';\nimport type {FitBoundsOptions} from './fit-bounds';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\n\n/**\n * @param width=1 - Width of \"viewport\" or window\n * @param height=1 - Height of \"viewport\" or window\n * @param scale=1 - Either use scale or zoom\n * @param pitch=0 - Camera angle in degrees (0 is straight down)\n * @param bearing=0 - Map rotation in degrees (0 means north is up)\n * @param fovy= - Field of view of camera in degrees\n * @param altitude= - Altitude of camera in screen units \n *\n * Web mercator projection short-hand parameters\n * @param latitude - Center of viewport on map\n * @param longitude - Center of viewport on map\n * @param zoom - Scale = Math.pow(2,zoom) on map\n\n * Notes:\n * - Only one of center or [latitude, longitude] can be specified\n * - [latitude, longitude] can only be specified when \"mercator\" is true\n * - Altitude has a default value that matches assumptions in mapbox-gl\n * - Field of view is independent from altitude, provide `altitudeToFovy(1.5)` (default value) to match assumptions in mapbox-gl\n * - width and height are forced to 1 if supplied as 0, to avoid\n * division by zero. This is intended to reduce the burden of apps to\n * to check values before instantiating a Viewport.\n */\nexport type WebMercatorViewportProps = {\n // Map state\n width: number;\n height: number;\n latitude?: number;\n longitude?: number;\n position?: number[];\n zoom?: number;\n pitch?: number;\n bearing?: number;\n altitude?: number;\n fovy?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n};\n\n/**\n * The WebMercatorViewport class creates\n * - view/projection matrices\n * - \"uniform values\" (for shaders) from mercator params\n *\n * Note: Instances are immutable in the sense that they only have accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\nexport default class WebMercatorViewport {\n readonly latitude: number;\n readonly longitude: number;\n readonly zoom: number;\n readonly pitch: number;\n readonly bearing: number;\n readonly altitude: number;\n readonly fovy: number;\n\n readonly meterOffset: number[];\n readonly center: number[];\n\n readonly width: number;\n readonly height: number;\n readonly scale: number;\n readonly distanceScales: DistanceScales;\n\n readonly viewMatrix: number[];\n readonly projectionMatrix: number[];\n\n viewProjectionMatrix: number[];\n pixelProjectionMatrix: number[];\n pixelUnprojectionMatrix: number[];\n\n /**\n * @classdesc\n * Creates view/projection matrices from mercator params\n * Note: The Viewport is immutable in the sense that it only has accessors.\n * A new viewport instance should be created if any parameters have changed.\n */\n // eslint-disable-next-line max-statements\n constructor(props: WebMercatorViewportProps = {width: 1, height: 1}) {\n let {\n // Map state\n width,\n height,\n altitude = null,\n fovy = null\n } = props;\n const {\n latitude = 0,\n longitude = 0,\n zoom = 0,\n pitch = 0,\n bearing = 0,\n position = null,\n nearZMultiplier = 0.02,\n farZMultiplier = 1.01\n } = props;\n\n // Silently allow apps to send in 0,0 to facilitate isomorphic render etc\n width = width || 1;\n height = height || 1;\n\n // `fovy` & `altitude` are independent parameters, one for the\n // projection and the latter for the view matrix. In the past,\n // the `fovy` was always derived from the `altitude`\n if (fovy === null && altitude === null) {\n altitude = DEFAULT_ALTITUDE;\n fovy = altitudeToFovy(altitude);\n } else if (fovy === null) {\n fovy = altitudeToFovy(altitude);\n } else if (altitude === null) {\n altitude = fovyToAltitude(fovy);\n }\n\n const scale = zoomToScale(zoom);\n // Altitude - prevent division by 0\n // TODO - just throw an Error instead?\n altitude = Math.max(0.75, altitude);\n\n const distanceScales = getDistanceScales({longitude, latitude});\n\n const center = lngLatToWorld([longitude, latitude]);\n center.push(0);\n\n if (position) {\n vec3.add(center, center, vec3.mul([], position, distanceScales.unitsPerMeter));\n }\n\n this.projectionMatrix = getProjectionMatrix({\n width,\n height,\n pitch,\n fovy,\n nearZMultiplier,\n farZMultiplier\n });\n\n this.viewMatrix = getViewMatrix({\n height,\n scale,\n center,\n pitch,\n bearing,\n altitude\n });\n\n // Save parameters\n this.width = width;\n this.height = height;\n this.scale = scale;\n\n this.latitude = latitude;\n this.longitude = longitude;\n this.zoom = zoom;\n this.pitch = pitch;\n this.bearing = bearing;\n this.altitude = altitude;\n this.fovy = fovy;\n this.center = center;\n this.meterOffset = position || [0, 0, 0];\n\n this.distanceScales = distanceScales;\n\n this._initMatrices();\n\n Object.freeze(this);\n }\n\n _initMatrices(): void {\n const {width, height, projectionMatrix, viewMatrix} = this;\n\n // Note: As usual, matrix operations should be applied in \"reverse\" order\n // since vectors will be multiplied in from the right during transformation\n const vpm = createMat4();\n mat4.multiply(vpm, vpm, projectionMatrix);\n mat4.multiply(vpm, vpm, viewMatrix);\n this.viewProjectionMatrix = vpm;\n\n // Calculate matrices and scales needed for projection\n /**\n * Builds matrices that converts preprojected lngLats to screen pixels\n * and vice versa.\n * Note: Currently returns bottom-left coordinates!\n * Note: Starts with the GL projection matrix and adds steps to the\n * scale and translate that matrix onto the window.\n * Note: WebGL controls clip space to screen projection with gl.viewport\n * and does not need this step.\n */\n const m = createMat4();\n\n // matrix for conversion from location to screen coordinates\n mat4.scale(m, m, [width / 2, -height / 2, 1]);\n mat4.translate(m, m, [1, -1, 0]);\n mat4.multiply(m, m, vpm);\n\n const mInverse = mat4.invert(createMat4(), m);\n if (!mInverse) {\n throw new Error('Pixel project matrix not invertible');\n }\n\n this.pixelProjectionMatrix = m;\n this.pixelUnprojectionMatrix = mInverse;\n }\n\n /** Two viewports are equal if width and height are identical, and if\n * their view and projection matrices are (approximately) equal.\n */\n equals = (viewport: WebMercatorViewport | null): boolean => {\n if (!(viewport instanceof WebMercatorViewport)) {\n return false;\n }\n\n return (\n viewport.width === this.width &&\n viewport.height === this.height &&\n mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&\n mat4.equals(viewport.viewMatrix, this.viewMatrix)\n );\n };\n\n /**\n * Projects xyz (possibly latitude and longitude) to pixel coordinates in window\n * using viewport projection parameters\n * - [longitude, latitude] to [x, y]\n * - [longitude, latitude, Z] => [x, y, z]\n * Note: By default, returns top-left coordinates for canvas/SVG type render\n *\n * @param lngLatZ - [lng, lat] or [lng, lat, Z]\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth\n */\n project = (lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] => {\n const {topLeft = true} = options;\n const worldPosition = this.projectPosition(lngLatZ);\n const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);\n\n const [x, y] = coord;\n const y2 = topLeft ? y : this.height - y;\n return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];\n };\n\n /**\n * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.\n *\n * - [x, y] => [lng, lat]\n * - [x, y, z] => [lng, lat, Z]\n *\n * @param xyz - screen coordinates, z as pixel depth\n * @param options - options\n * @param options.topLeft=true - Whether projected coords are top left\n * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as\n * the elevation plane to unproject onto\n * @return - [lng, lat, Z] or [X, Y, Z]\n */\n unproject = (xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] => {\n const {topLeft = true, targetZ = undefined} = options;\n const [x, y, z] = xyz;\n\n const y2 = topLeft ? y : this.height - y;\n const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];\n const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);\n const [X, Y, Z] = this.unprojectPosition(coord);\n\n if (Number.isFinite(z)) {\n return [X, Y, Z];\n }\n return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];\n };\n\n // NON_LINEAR PROJECTION HOOKS\n // Used for web meractor projection\n\n projectPosition = (xyz: number[]): [number, number, number] => {\n const [X, Y] = lngLatToWorld(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];\n return [X, Y, Z];\n };\n\n unprojectPosition = (xyz: number[]): [number, number, number] => {\n const [X, Y] = worldToLngLat(xyz);\n const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];\n return [X, Y, Z];\n };\n\n /**\n * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.\n * Performs the nonlinear part of the web mercator projection.\n * Remaining projection is done with 4x4 matrices which also handles\n * perspective.\n *\n * @param lngLat - [lng, lat] coordinates\n * Specifies a point on the sphere to project onto the map.\n * @return [x,y] coordinates.\n */\n projectFlat(lngLat: number[]): number[] {\n return lngLatToWorld(lngLat);\n }\n\n /**\n * Unproject world point [x,y] on map onto {lat, lon} on sphere\n *\n * @param xy - array with [x,y] members\n * representing point on projected map plane\n * @return - array with [lat,lon] of point on sphere.\n * Has toArray method if you need a GeoJSON Array.\n * Per cartographic tradition, lat and lon are specified as degrees.\n */\n unprojectFlat(xy: number[]): number[] {\n return worldToLngLat(xy);\n }\n\n /**\n * Get the map center that place a given [lng, lat] coordinate at screen point [x, y]\n * @param opt\n * @param opt.lngLat - [lng,lat] coordinates\n * Specifies a point on the sphere.\n * @param opt.pos - [x,y] coordinates\n * Specifies a point on the screen.\n * @return [lng,lat] new map center.\n */\n getMapCenterByLngLatPosition({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n const fromLocation = pixelsToWorld(pos, this.pixelUnprojectionMatrix);\n const toLocation = lngLatToWorld(lngLat);\n const translate = vec2.add([], toLocation, vec2.negate([], fromLocation));\n const newCenter = vec2.add([], this.center, translate);\n return worldToLngLat(newCenter);\n }\n\n /**\n * Returns a new viewport that fit around the given rectangle.\n * Only supports non-perspective mode.\n * @param bounds - [[lon, lat], [lon, lat]]\n * @param [options]\n * @param [options.padding] - The amount of padding in pixels to add to the given bounds.\n * @param [options.offset] - The center of the given bounds relative to the map's center,\n * [x, y] measured in pixels.\n * @returns {WebMercatorViewport}\n */\n fitBounds(\n bounds: [[number, number], [number, number]],\n options: Omit<FitBoundsOptions, 'width' | 'height' | 'bounds'> = {}\n ): WebMercatorViewport {\n const {width, height} = this;\n const {longitude, latitude, zoom} = fitBounds(Object.assign({width, height, bounds}, options));\n return new WebMercatorViewport({width, height, longitude, latitude, zoom});\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} bounds - [[lon, lat], [lon, lat]]\n */\n getBounds(options?: {z?: number}): number[][] {\n const corners = this.getBoundingRegion(options);\n\n const west = Math.min(...corners.map((p) => p[0]));\n const east = Math.max(...corners.map((p) => p[0]));\n const south = Math.min(...corners.map((p) => p[1]));\n const north = Math.max(...corners.map((p) => p[1]));\n return [\n [west, south],\n [east, north]\n ];\n }\n\n /**\n * Returns the bounding box of the viewport.\n * @param [options]\n * @param [options.z] - The altitude at which the bounds should be calculated.\n * @returns {Array} an array of 4 points that define the visible region\n */\n getBoundingRegion(options: {z?: number} = {}): number[][] {\n return getBounds(this, options.z || 0);\n }\n\n // DEPRECATED\n\n /** @deprecated Legacy method name */\n getLocationAtPoint({lngLat, pos}: {lngLat: number[]; pos: number[]}): number[] {\n return this.getMapCenterByLngLatPosition({lngLat, pos});\n }\n}\n"],"file":"web-mercator-viewport.js"}
@@ -24,7 +24,7 @@ export default function flyToViewport(startProps, endProps, t, options) {
24
24
  const endValue = endProps[key];
25
25
  viewport[key] = lerp(startValue, endValue, t);
26
26
  }
27
- // @ts-expect-error
27
+ // @ts-expect-error properties are populated dynamically
28
28
  return viewport;
29
29
  }
30
30
  const s = t * S;
@@ -75,7 +75,7 @@ export default class WebMercatorViewport {
75
75
  /** Two viewports are equal if width and height are identical, and if
76
76
  * their view and projection matrices are (approximately) equal.
77
77
  */
78
- equals(viewport: WebMercatorViewport | null): boolean;
78
+ equals: (viewport: WebMercatorViewport | null) => boolean;
79
79
  /**
80
80
  * Projects xyz (possibly latitude and longitude) to pixel coordinates in window
81
81
  * using viewport projection parameters
@@ -88,9 +88,9 @@ export default class WebMercatorViewport {
88
88
  * @param options.topLeft=true - Whether projected coords are top left
89
89
  * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth
90
90
  */
91
- project(lngLatZ: number[], options?: {
91
+ project: (lngLatZ: number[], options?: {
92
92
  topLeft?: boolean;
93
- }): number[];
93
+ }) => number[];
94
94
  /**
95
95
  * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.
96
96
  *
@@ -104,12 +104,12 @@ export default class WebMercatorViewport {
104
104
  * the elevation plane to unproject onto
105
105
  * @return - [lng, lat, Z] or [X, Y, Z]
106
106
  */
107
- unproject(xyz: number[], options?: {
107
+ unproject: (xyz: number[], options?: {
108
108
  topLeft?: boolean;
109
109
  targetZ?: number;
110
- }): number[];
111
- projectPosition(xyz: number[]): [number, number, number];
112
- unprojectPosition(xyz: number[]): [number, number, number];
110
+ }) => number[];
111
+ projectPosition: (xyz: number[]) => [number, number, number];
112
+ unprojectPosition: (xyz: number[]) => [number, number, number];
113
113
  /**
114
114
  * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
115
115
  * Performs the nonlinear part of the web mercator projection.
@@ -1 +1 @@
1
- {"version":3,"file":"web-mercator-viewport.d.ts","sourceRoot":"","sources":["../src/web-mercator-viewport.ts"],"names":[],"mappings":"AAGA,OAAO,EAYL,cAAc,EACf,MAAM,sBAAsB,CAAC;AAG9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAMnD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,oBAAY,wBAAwB,GAAG;IAErC,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,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EAAE,MAAM,CAAC,CAIzD;IAEF,iBAAiB,QAAS,MAAM,EAAE,KAAG,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAI3D;IAEF;;;;;;;;;OASG;IACH,WAAW,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAIvC;;;;;;;;OAQG;IACH,aAAa,CAAC,EAAE,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAIrC;;;;;;;;OAQG;IACH,4BAA4B,CAAC,EAAC,MAAM,EAAE,GAAG,EAAC,EAAE;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,EAAE,CAAA;KAAC,GAAG,MAAM,EAAE;IAQxF;;;;;;;;;OASG;IACH,SAAS,CACP,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,EAC5C,OAAO,GAAE,IAAI,CAAC,gBAAgB,EAAE,OAAO,GAAG,QAAQ,GAAG,QAAQ,CAAM,GAClE,mBAAmB;IAMtB;;;;;OAKG;IACH,SAAS,CAAC,OAAO,CAAC,EAAE;QAAC,CAAC,CAAC,EAAE,MAAM,CAAA;KAAC,GAAG,MAAM,EAAE,EAAE;IAa7C;;;;;OAKG;IACH,iBAAiB,CAAC,OAAO,GAAE;QAAC,CAAC,CAAC,EAAE,MAAM,CAAA;KAAM,GAAG,MAAM,EAAE,EAAE;IAMzD,qCAAqC;IACrC,kBAAkB,CAAC,EAAC,MAAM,EAAE,GAAG,EAAC,EAAE;QAAC,MAAM,EAAE,MAAM,EAAE,CAAC;QAAC,GAAG,EAAE,MAAM,EAAE,CAAA;KAAC,GAAG,MAAM,EAAE;CAG/E"}
@@ -23,6 +23,75 @@ export default class WebMercatorViewport {
23
23
  */
24
24
  // eslint-disable-next-line max-statements
25
25
  constructor(props = { width: 1, height: 1 }) {
26
+ /** Two viewports are equal if width and height are identical, and if
27
+ * their view and projection matrices are (approximately) equal.
28
+ */
29
+ this.equals = (viewport) => {
30
+ if (!(viewport instanceof WebMercatorViewport)) {
31
+ return false;
32
+ }
33
+ return (viewport.width === this.width &&
34
+ viewport.height === this.height &&
35
+ mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&
36
+ mat4.equals(viewport.viewMatrix, this.viewMatrix));
37
+ };
38
+ /**
39
+ * Projects xyz (possibly latitude and longitude) to pixel coordinates in window
40
+ * using viewport projection parameters
41
+ * - [longitude, latitude] to [x, y]
42
+ * - [longitude, latitude, Z] => [x, y, z]
43
+ * Note: By default, returns top-left coordinates for canvas/SVG type render
44
+ *
45
+ * @param lngLatZ - [lng, lat] or [lng, lat, Z]
46
+ * @param options - options
47
+ * @param options.topLeft=true - Whether projected coords are top left
48
+ * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth
49
+ */
50
+ this.project = (lngLatZ, options = {}) => {
51
+ const { topLeft = true } = options;
52
+ const worldPosition = this.projectPosition(lngLatZ);
53
+ const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);
54
+ const [x, y] = coord;
55
+ const y2 = topLeft ? y : this.height - y;
56
+ return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
57
+ };
58
+ /**
59
+ * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.
60
+ *
61
+ * - [x, y] => [lng, lat]
62
+ * - [x, y, z] => [lng, lat, Z]
63
+ *
64
+ * @param xyz - screen coordinates, z as pixel depth
65
+ * @param options - options
66
+ * @param options.topLeft=true - Whether projected coords are top left
67
+ * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as
68
+ * the elevation plane to unproject onto
69
+ * @return - [lng, lat, Z] or [X, Y, Z]
70
+ */
71
+ this.unproject = (xyz, options = {}) => {
72
+ const { topLeft = true, targetZ = undefined } = options;
73
+ const [x, y, z] = xyz;
74
+ const y2 = topLeft ? y : this.height - y;
75
+ const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
76
+ const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);
77
+ const [X, Y, Z] = this.unprojectPosition(coord);
78
+ if (Number.isFinite(z)) {
79
+ return [X, Y, Z];
80
+ }
81
+ return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
82
+ };
83
+ // NON_LINEAR PROJECTION HOOKS
84
+ // Used for web meractor projection
85
+ this.projectPosition = (xyz) => {
86
+ const [X, Y] = lngLatToWorld(xyz);
87
+ const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
88
+ return [X, Y, Z];
89
+ };
90
+ this.unprojectPosition = (xyz) => {
91
+ const [X, Y] = worldToLngLat(xyz);
92
+ const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
93
+ return [X, Y, Z];
94
+ };
26
95
  let {
27
96
  // Map state
28
97
  width, height, altitude = null, fovy = null } = props;
@@ -84,12 +153,6 @@ export default class WebMercatorViewport {
84
153
  this.meterOffset = position || [0, 0, 0];
85
154
  this.distanceScales = distanceScales;
86
155
  this._initMatrices();
87
- // Bind methods for easy access
88
- this.equals = this.equals.bind(this);
89
- this.project = this.project.bind(this);
90
- this.unproject = this.unproject.bind(this);
91
- this.projectPosition = this.projectPosition.bind(this);
92
- this.unprojectPosition = this.unprojectPosition.bind(this);
93
156
  Object.freeze(this);
94
157
  }
95
158
  _initMatrices() {
@@ -122,75 +185,6 @@ export default class WebMercatorViewport {
122
185
  this.pixelProjectionMatrix = m;
123
186
  this.pixelUnprojectionMatrix = mInverse;
124
187
  }
125
- /** Two viewports are equal if width and height are identical, and if
126
- * their view and projection matrices are (approximately) equal.
127
- */
128
- equals(viewport) {
129
- if (!(viewport instanceof WebMercatorViewport)) {
130
- return false;
131
- }
132
- return (viewport.width === this.width &&
133
- viewport.height === this.height &&
134
- mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&
135
- mat4.equals(viewport.viewMatrix, this.viewMatrix));
136
- }
137
- /**
138
- * Projects xyz (possibly latitude and longitude) to pixel coordinates in window
139
- * using viewport projection parameters
140
- * - [longitude, latitude] to [x, y]
141
- * - [longitude, latitude, Z] => [x, y, z]
142
- * Note: By default, returns top-left coordinates for canvas/SVG type render
143
- *
144
- * @param lngLatZ - [lng, lat] or [lng, lat, Z]
145
- * @param options - options
146
- * @param options.topLeft=true - Whether projected coords are top left
147
- * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth
148
- */
149
- project(lngLatZ, options = {}) {
150
- const { topLeft = true } = options;
151
- const worldPosition = this.projectPosition(lngLatZ);
152
- const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);
153
- const [x, y] = coord;
154
- const y2 = topLeft ? y : this.height - y;
155
- return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
156
- }
157
- /**
158
- * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.
159
- *
160
- * - [x, y] => [lng, lat]
161
- * - [x, y, z] => [lng, lat, Z]
162
- *
163
- * @param xyz - screen coordinates, z as pixel depth
164
- * @param options - options
165
- * @param options.topLeft=true - Whether projected coords are top left
166
- * @param options.targetZ=0 - If pixel depth is unknown, targetZ is used as
167
- * the elevation plane to unproject onto
168
- * @return - [lng, lat, Z] or [X, Y, Z]
169
- */
170
- unproject(xyz, options = {}) {
171
- const { topLeft = true, targetZ = undefined } = options;
172
- const [x, y, z] = xyz;
173
- const y2 = topLeft ? y : this.height - y;
174
- const targetZWorld = targetZ && targetZ * this.distanceScales.unitsPerMeter[2];
175
- const coord = pixelsToWorld([x, y2, z], this.pixelUnprojectionMatrix, targetZWorld);
176
- const [X, Y, Z] = this.unprojectPosition(coord);
177
- if (Number.isFinite(z)) {
178
- return [X, Y, Z];
179
- }
180
- return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
181
- }
182
- // NON_LINEAR PROJECTION HOOKS
183
- // Used for web meractor projection
184
- projectPosition(xyz) {
185
- const [X, Y] = lngLatToWorld(xyz);
186
- const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
187
- return [X, Y, Z];
188
- }
189
- unprojectPosition(xyz) {
190
- const [X, Y] = worldToLngLat(xyz);
191
- const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
192
- return [X, Y, Z];
193
- }
194
188
  /**
195
189
  * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.
196
190
  * Performs the nonlinear part of the web mercator projection.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "description": "Utilities for perspective-enabled Web Mercator projections",
4
4
  "author": "Uber Technologies, Inc.",
5
5
  "license": "MIT",
6
- "version": "3.6.0-alpha.3",
6
+ "version": "3.6.0-alpha.6",
7
7
  "keywords": [
8
8
  "webgl",
9
9
  "javascript",
@@ -33,5 +33,5 @@
33
33
  "mapbox-gl": "^1.0.0",
34
34
  "mock-browser": "^0.92.14"
35
35
  },
36
- "gitHead": "ec2a4af3e64b97f0354a75c370d23d3de0aa3b43"
36
+ "gitHead": "3b19564c634dc2c0255708b024425050c7fb2b9f"
37
37
  }
@@ -50,7 +50,7 @@ export default function flyToViewport(
50
50
  const endValue = endProps[key];
51
51
  viewport[key] = lerp(startValue, endValue, t);
52
52
  }
53
- // @ts-expect-error
53
+ // @ts-expect-error properties are populated dynamically
54
54
  return viewport;
55
55
  }
56
56
 
@@ -187,13 +187,6 @@ export default class WebMercatorViewport {
187
187
 
188
188
  this._initMatrices();
189
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
190
  Object.freeze(this);
198
191
  }
199
192
 
@@ -236,7 +229,7 @@ export default class WebMercatorViewport {
236
229
  /** Two viewports are equal if width and height are identical, and if
237
230
  * their view and projection matrices are (approximately) equal.
238
231
  */
239
- equals(viewport: WebMercatorViewport | null): boolean {
232
+ equals = (viewport: WebMercatorViewport | null): boolean => {
240
233
  if (!(viewport instanceof WebMercatorViewport)) {
241
234
  return false;
242
235
  }
@@ -247,7 +240,7 @@ export default class WebMercatorViewport {
247
240
  mat4.equals(viewport.projectionMatrix, this.projectionMatrix) &&
248
241
  mat4.equals(viewport.viewMatrix, this.viewMatrix)
249
242
  );
250
- }
243
+ };
251
244
 
252
245
  /**
253
246
  * Projects xyz (possibly latitude and longitude) to pixel coordinates in window
@@ -261,7 +254,7 @@ export default class WebMercatorViewport {
261
254
  * @param options.topLeft=true - Whether projected coords are top left
262
255
  * @return - screen coordinates [x, y] or [x, y, z], z as pixel depth
263
256
  */
264
- project(lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] {
257
+ project = (lngLatZ: number[], options: {topLeft?: boolean} = {}): number[] => {
265
258
  const {topLeft = true} = options;
266
259
  const worldPosition = this.projectPosition(lngLatZ);
267
260
  const coord = worldToPixels(worldPosition, this.pixelProjectionMatrix);
@@ -269,7 +262,7 @@ export default class WebMercatorViewport {
269
262
  const [x, y] = coord;
270
263
  const y2 = topLeft ? y : this.height - y;
271
264
  return lngLatZ.length === 2 ? [x, y2] : [x, y2, coord[2]];
272
- }
265
+ };
273
266
 
274
267
  /**
275
268
  * Unproject pixel coordinates on screen onto world coordinates, possibly `[lon, lat]` on map.
@@ -284,7 +277,7 @@ export default class WebMercatorViewport {
284
277
  * the elevation plane to unproject onto
285
278
  * @return - [lng, lat, Z] or [X, Y, Z]
286
279
  */
287
- unproject(xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] {
280
+ unproject = (xyz: number[], options: {topLeft?: boolean; targetZ?: number} = {}): number[] => {
288
281
  const {topLeft = true, targetZ = undefined} = options;
289
282
  const [x, y, z] = xyz;
290
283
 
@@ -297,22 +290,22 @@ export default class WebMercatorViewport {
297
290
  return [X, Y, Z];
298
291
  }
299
292
  return Number.isFinite(targetZ) ? [X, Y, targetZ] : [X, Y];
300
- }
293
+ };
301
294
 
302
295
  // NON_LINEAR PROJECTION HOOKS
303
296
  // Used for web meractor projection
304
297
 
305
- projectPosition(xyz: number[]): [number, number, number] {
298
+ projectPosition = (xyz: number[]): [number, number, number] => {
306
299
  const [X, Y] = lngLatToWorld(xyz);
307
300
  const Z = (xyz[2] || 0) * this.distanceScales.unitsPerMeter[2];
308
301
  return [X, Y, Z];
309
- }
302
+ };
310
303
 
311
- unprojectPosition(xyz: number[]): [number, number, number] {
304
+ unprojectPosition = (xyz: number[]): [number, number, number] => {
312
305
  const [X, Y] = worldToLngLat(xyz);
313
306
  const Z = (xyz[2] || 0) * this.distanceScales.metersPerUnit[2];
314
307
  return [X, Y, Z];
315
- }
308
+ };
316
309
 
317
310
  /**
318
311
  * Project [lng,lat] on sphere onto [x,y] on 512*512 Mercator Zoom 0 tile.