@math.gl/web-mercator 3.6.3 → 4.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{esm/assert.js → assert.js} +0 -0
- package/dist/assert.js.map +1 -0
- package/dist/fit-bounds.d.ts +3 -3
- package/dist/fit-bounds.d.ts.map +1 -1
- package/dist/{esm/fit-bounds.js → fit-bounds.js} +3 -3
- package/dist/fit-bounds.js.map +1 -0
- package/dist/fly-to-viewport.d.ts +1 -1
- package/dist/fly-to-viewport.d.ts.map +1 -1
- package/dist/{esm/fly-to-viewport.js → fly-to-viewport.js} +2 -2
- package/dist/fly-to-viewport.js.map +1 -0
- package/dist/get-bounds.d.ts.map +1 -1
- package/dist/{esm/get-bounds.js → get-bounds.js} +4 -4
- package/dist/get-bounds.js.map +1 -0
- package/dist/index.cjs +630 -0
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -0
- package/dist/{esm/math-utils.js → math-utils.js} +0 -0
- package/dist/math-utils.js.map +1 -0
- package/dist/normalize-viewport-props.d.ts +1 -1
- package/dist/normalize-viewport-props.d.ts.map +1 -1
- package/dist/{esm/normalize-viewport-props.js → normalize-viewport-props.js} +2 -2
- package/dist/normalize-viewport-props.js.map +1 -0
- package/dist/web-mercator-utils.d.ts +2 -2
- package/dist/web-mercator-utils.d.ts.map +1 -1
- package/dist/{esm/web-mercator-utils.js → web-mercator-utils.js} +2 -2
- package/dist/web-mercator-utils.js.map +1 -0
- package/dist/web-mercator-viewport.d.ts +1 -1
- package/dist/web-mercator-viewport.d.ts.map +1 -1
- package/dist/{esm/web-mercator-viewport.js → web-mercator-viewport.js} +4 -4
- package/dist/web-mercator-viewport.js.map +1 -0
- package/package.json +6 -5
- package/src/fly-to-viewport.ts +1 -0
- package/src/get-bounds.ts +4 -3
- package/dist/es5/assert.js +0 -13
- package/dist/es5/assert.js.map +0 -1
- package/dist/es5/fit-bounds.js +0 -73
- package/dist/es5/fit-bounds.js.map +0 -1
- package/dist/es5/fly-to-viewport.js +0 -151
- package/dist/es5/fly-to-viewport.js.map +0 -1
- package/dist/es5/get-bounds.js +0 -59
- package/dist/es5/get-bounds.js.map +0 -1
- package/dist/es5/index.js +0 -164
- package/dist/es5/index.js.map +0 -1
- package/dist/es5/math-utils.js +0 -44
- package/dist/es5/math-utils.js.map +0 -1
- package/dist/es5/normalize-viewport-props.js +0 -63
- package/dist/es5/normalize-viewport-props.js.map +0 -1
- package/dist/es5/web-mercator-utils.js +0 -271
- package/dist/es5/web-mercator-utils.js.map +0 -1
- package/dist/es5/web-mercator-viewport.js +0 -328
- package/dist/es5/web-mercator-viewport.js.map +0 -1
- package/dist/esm/assert.js.map +0 -1
- package/dist/esm/fit-bounds.js.map +0 -1
- package/dist/esm/fly-to-viewport.js.map +0 -1
- package/dist/esm/get-bounds.js.map +0 -1
- package/dist/esm/index.js +0 -8
- package/dist/esm/index.js.map +0 -1
- package/dist/esm/math-utils.js.map +0 -1
- package/dist/esm/normalize-viewport-props.js.map +0 -1
- package/dist/esm/web-mercator-utils.js.map +0 -1
- package/dist/esm/web-mercator-viewport.js.map +0 -1
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/get-bounds.ts"],"names":["DEGREES_TO_RADIANS","Math","PI","getBounds","viewport","z","width","height","unproject","unprojectOps","targetZ","bottomLeft","bottomRight","topLeft","topRight","halfFov","fovy","atan","altitude","angleToGround","pitch","unprojectOnFarPlane","x","pixelUnprojectionMatrix","coord0","coord1","distanceScales","unitsPerMeter","t","coord","vec2","lerp","result","push"],"mappings":";;;;;;;;;AAAA;;AACA;;AACA;;;;;;AAGA,IAAMA,kBAAkB,GAAGC,IAAI,CAACC,EAAL,GAAU,GAArC;;AAOe,SAASC,SAAT,CAAmBC,QAAnB,EAA6E;AAAA,MAA3BC,CAA2B,uEAAf,CAAe;AAE1F,MAAOC,KAAP,GAAmCF,QAAnC,CAAOE,KAAP;AAAA,MAAcC,MAAd,GAAmC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;AACA,MAAMC,MAAM,GAAG,gCAAgBD,uBAAhB,EAAyC,CAACD,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,CAAzC,CAAf;AACA,MAAMG,MAAM,GAAG,gCAAgBF,uBAAhB,EAAyC,CAACD,CAAD,EAAIlB,QAAQ,CAACG,MAAb,EAAqB,CAArB,EAAwB,CAAxB,CAAzC,CAAf;AAEA,MAAMF,CAAC,GAAGK,OAAO,GAAGN,QAAQ,CAACsB,cAAT,CAAwBC,aAAxB,CAAsC,CAAtC,CAApB;AACA,MAAMC,CAAC,GAAG,CAACvB,CAAC,GAAGmB,MAAM,CAAC,CAAD,CAAX,KAAmBC,MAAM,CAAC,CAAD,CAAN,GAAYD,MAAM,CAAC,CAAD,CAArC,CAAV;AACA,MAAMK,KAAK,GAAGC,IAAI,CAACC,IAAL,CAAU,EAAV,EAAcP,MAAd,EAAsBC,MAAtB,EAA8BG,CAA9B,CAAd;AAEA,MAAMI,MAAM,GAAG,qCAAcH,KAAd,CAAf;AACAG,EAAAA,MAAM,CAACC,IAAP,CAAYvB,OAAZ;AACA,SAAOsB,MAAP;AACD","sourcesContent":["import {worldToLngLat} from './web-mercator-utils';\nimport * as vec2 from 'gl-matrix/vec2';\nimport {transformVector} from './math-utils';\nimport type WebMercatorViewport from './web-mercator-viewport';\n\nconst DEGREES_TO_RADIANS = Math.PI / 180;\n\n/*\n * Returns the quad at the intersection of the frustum and the given z plane\n * @param {WebMercatorViewport} viewport\n * @param {Number} z - elevation in meters\n */\nexport default function getBounds(viewport: WebMercatorViewport, z: number = 0): number[][] {\n // eslint-disable-next-line @typescript-eslint/unbound-method\n const {width, height, unproject} = viewport;\n const unprojectOps = {targetZ: z};\n const bottomLeft = unproject([0, height], unprojectOps);\n const bottomRight = unproject([width, height], unprojectOps);\n let topLeft: number[];\n let topRight: number[];\n\n const halfFov = viewport.fovy\n ? 0.5 * viewport.fovy * DEGREES_TO_RADIANS\n : Math.atan(0.5 / viewport.altitude);\n const angleToGround = (90 - viewport.pitch) * DEGREES_TO_RADIANS;\n // The top plane is parallel to the ground if halfFov == angleToGround\n if (halfFov > angleToGround - 0.01) {\n // intersect with the far plane\n topLeft = unprojectOnFarPlane(viewport, 0, z);\n topRight = unprojectOnFarPlane(viewport, width, z);\n } else {\n // intersect with the top plane\n topLeft = unproject([0, 0], unprojectOps);\n topRight = unproject([width, 0], unprojectOps);\n }\n\n return [bottomLeft, bottomRight, topRight, topLeft];\n}\n\n/*\n * Find a point on the far clipping plane of the viewport\n * @param {WebMercatorViewport} viewport\n * @param {Number} x - projected x in screen space\n * @param {Number} targetZ - the elevation of the point in meters\n */\nfunction unprojectOnFarPlane(viewport: WebMercatorViewport, x: number, targetZ: number): number[] {\n const {pixelUnprojectionMatrix} = viewport;\n const coord0 = transformVector(pixelUnprojectionMatrix, [x, 0, 1, 1]);\n const coord1 = transformVector(pixelUnprojectionMatrix, [x, viewport.height, 1, 1]);\n\n const z = targetZ * viewport.distanceScales.unitsPerMeter[2];\n const t = (z - coord0[2]) / (coord1[2] - coord0[2]);\n const coord = vec2.lerp([], coord0, coord1, t);\n\n const result = worldToLngLat(coord);\n result.push(targetZ);\n return result;\n}\n"],"file":"get-bounds.js"}
|
package/dist/es5/index.js
DELETED
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
Object.defineProperty(exports, "default", {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _webMercatorViewport.default;
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
Object.defineProperty(exports, "WebMercatorViewport", {
|
|
17
|
-
enumerable: true,
|
|
18
|
-
get: function get() {
|
|
19
|
-
return _webMercatorViewport.default;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
Object.defineProperty(exports, "getBounds", {
|
|
23
|
-
enumerable: true,
|
|
24
|
-
get: function get() {
|
|
25
|
-
return _getBounds.default;
|
|
26
|
-
}
|
|
27
|
-
});
|
|
28
|
-
Object.defineProperty(exports, "fitBounds", {
|
|
29
|
-
enumerable: true,
|
|
30
|
-
get: function get() {
|
|
31
|
-
return _fitBounds.default;
|
|
32
|
-
}
|
|
33
|
-
});
|
|
34
|
-
Object.defineProperty(exports, "normalizeViewportProps", {
|
|
35
|
-
enumerable: true,
|
|
36
|
-
get: function get() {
|
|
37
|
-
return _normalizeViewportProps.default;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
Object.defineProperty(exports, "flyToViewport", {
|
|
41
|
-
enumerable: true,
|
|
42
|
-
get: function get() {
|
|
43
|
-
return _flyToViewport.default;
|
|
44
|
-
}
|
|
45
|
-
});
|
|
46
|
-
Object.defineProperty(exports, "getFlyToDuration", {
|
|
47
|
-
enumerable: true,
|
|
48
|
-
get: function get() {
|
|
49
|
-
return _flyToViewport.getFlyToDuration;
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
Object.defineProperty(exports, "MAX_LATITUDE", {
|
|
53
|
-
enumerable: true,
|
|
54
|
-
get: function get() {
|
|
55
|
-
return _webMercatorUtils.MAX_LATITUDE;
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
Object.defineProperty(exports, "lngLatToWorld", {
|
|
59
|
-
enumerable: true,
|
|
60
|
-
get: function get() {
|
|
61
|
-
return _webMercatorUtils.lngLatToWorld;
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
Object.defineProperty(exports, "worldToLngLat", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function get() {
|
|
67
|
-
return _webMercatorUtils.worldToLngLat;
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
Object.defineProperty(exports, "worldToPixels", {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
get: function get() {
|
|
73
|
-
return _webMercatorUtils.worldToPixels;
|
|
74
|
-
}
|
|
75
|
-
});
|
|
76
|
-
Object.defineProperty(exports, "pixelsToWorld", {
|
|
77
|
-
enumerable: true,
|
|
78
|
-
get: function get() {
|
|
79
|
-
return _webMercatorUtils.pixelsToWorld;
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
Object.defineProperty(exports, "zoomToScale", {
|
|
83
|
-
enumerable: true,
|
|
84
|
-
get: function get() {
|
|
85
|
-
return _webMercatorUtils.zoomToScale;
|
|
86
|
-
}
|
|
87
|
-
});
|
|
88
|
-
Object.defineProperty(exports, "scaleToZoom", {
|
|
89
|
-
enumerable: true,
|
|
90
|
-
get: function get() {
|
|
91
|
-
return _webMercatorUtils.scaleToZoom;
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
Object.defineProperty(exports, "altitudeToFovy", {
|
|
95
|
-
enumerable: true,
|
|
96
|
-
get: function get() {
|
|
97
|
-
return _webMercatorUtils.altitudeToFovy;
|
|
98
|
-
}
|
|
99
|
-
});
|
|
100
|
-
Object.defineProperty(exports, "fovyToAltitude", {
|
|
101
|
-
enumerable: true,
|
|
102
|
-
get: function get() {
|
|
103
|
-
return _webMercatorUtils.fovyToAltitude;
|
|
104
|
-
}
|
|
105
|
-
});
|
|
106
|
-
Object.defineProperty(exports, "getMeterZoom", {
|
|
107
|
-
enumerable: true,
|
|
108
|
-
get: function get() {
|
|
109
|
-
return _webMercatorUtils.getMeterZoom;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
Object.defineProperty(exports, "unitsPerMeter", {
|
|
113
|
-
enumerable: true,
|
|
114
|
-
get: function get() {
|
|
115
|
-
return _webMercatorUtils.unitsPerMeter;
|
|
116
|
-
}
|
|
117
|
-
});
|
|
118
|
-
Object.defineProperty(exports, "getDistanceScales", {
|
|
119
|
-
enumerable: true,
|
|
120
|
-
get: function get() {
|
|
121
|
-
return _webMercatorUtils.getDistanceScales;
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
Object.defineProperty(exports, "addMetersToLngLat", {
|
|
125
|
-
enumerable: true,
|
|
126
|
-
get: function get() {
|
|
127
|
-
return _webMercatorUtils.addMetersToLngLat;
|
|
128
|
-
}
|
|
129
|
-
});
|
|
130
|
-
Object.defineProperty(exports, "getViewMatrix", {
|
|
131
|
-
enumerable: true,
|
|
132
|
-
get: function get() {
|
|
133
|
-
return _webMercatorUtils.getViewMatrix;
|
|
134
|
-
}
|
|
135
|
-
});
|
|
136
|
-
Object.defineProperty(exports, "getProjectionMatrix", {
|
|
137
|
-
enumerable: true,
|
|
138
|
-
get: function get() {
|
|
139
|
-
return _webMercatorUtils.getProjectionMatrix;
|
|
140
|
-
}
|
|
141
|
-
});
|
|
142
|
-
Object.defineProperty(exports, "getProjectionParameters", {
|
|
143
|
-
enumerable: true,
|
|
144
|
-
get: function get() {
|
|
145
|
-
return _webMercatorUtils.getProjectionParameters;
|
|
146
|
-
}
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
var _webMercatorViewport = _interopRequireDefault(require("./web-mercator-viewport"));
|
|
150
|
-
|
|
151
|
-
var _getBounds = _interopRequireDefault(require("./get-bounds"));
|
|
152
|
-
|
|
153
|
-
var _fitBounds = _interopRequireDefault(require("./fit-bounds"));
|
|
154
|
-
|
|
155
|
-
var _normalizeViewportProps = _interopRequireDefault(require("./normalize-viewport-props"));
|
|
156
|
-
|
|
157
|
-
var _flyToViewport = _interopRequireWildcard(require("./fly-to-viewport"));
|
|
158
|
-
|
|
159
|
-
var _webMercatorUtils = require("./web-mercator-utils");
|
|
160
|
-
|
|
161
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
162
|
-
|
|
163
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
164
|
-
//# sourceMappingURL=index.js.map
|
package/dist/es5/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;;AAGA;;AACA;;AACA;;AACA;;AAEA","sourcesContent":["// Classic web-mercator-project\nexport {default} from './web-mercator-viewport';\nexport {default as WebMercatorViewport} from './web-mercator-viewport';\n\nexport {default as getBounds} from './get-bounds';\nexport {default as fitBounds} from './fit-bounds';\nexport {default as normalizeViewportProps} from './normalize-viewport-props';\nexport {default as flyToViewport, getFlyToDuration} from './fly-to-viewport';\n\nexport {\n MAX_LATITUDE,\n lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n pixelsToWorld,\n zoomToScale,\n scaleToZoom,\n altitudeToFovy,\n fovyToAltitude,\n getMeterZoom,\n unitsPerMeter,\n getDistanceScales,\n addMetersToLngLat,\n getViewMatrix,\n getProjectionMatrix,\n getProjectionParameters\n} from './web-mercator-utils';\n\n/** Types */\nexport type {FitBoundsOptions} from './fit-bounds';\nexport type {DistanceScales} from './web-mercator-utils';\n"],"file":"index.js"}
|
package/dist/es5/math-utils.js
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.createMat4 = createMat4;
|
|
7
|
-
exports.transformVector = transformVector;
|
|
8
|
-
exports.mod = mod;
|
|
9
|
-
exports.lerp = lerp;
|
|
10
|
-
exports.clamp = clamp;
|
|
11
|
-
exports.log2 = void 0;
|
|
12
|
-
|
|
13
|
-
var _vec = require("gl-matrix/vec4");
|
|
14
|
-
|
|
15
|
-
function createMat4() {
|
|
16
|
-
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function transformVector(matrix, vector) {
|
|
20
|
-
var result = (0, _vec.transformMat4)([], vector, matrix);
|
|
21
|
-
(0, _vec.scale)(result, result, 1 / result[3]);
|
|
22
|
-
return result;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
function mod(value, divisor) {
|
|
26
|
-
var modulus = value % divisor;
|
|
27
|
-
return modulus < 0 ? divisor + modulus : modulus;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function lerp(start, end, step) {
|
|
31
|
-
return step * end + (1 - step) * start;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function clamp(x, min, max) {
|
|
35
|
-
return x < min ? min : x > max ? max : x;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
function ieLog2(x) {
|
|
39
|
-
return Math.log(x) * Math.LOG2E;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
var log2 = Math.log2 || ieLog2;
|
|
43
|
-
exports.log2 = log2;
|
|
44
|
-
//# sourceMappingURL=math-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math-utils.ts"],"names":["createMat4","transformVector","matrix","vector","result","mod","value","divisor","modulus","lerp","start","end","step","clamp","x","min","max","ieLog2","Math","log","LOG2E","log2"],"mappings":";;;;;;;;;;;;AAAA;;AAGO,SAASA,UAAT,GAAgC;AACrC,SAAO,CAAC,CAAD,EAAI,CAAJ,EAAO,CAAP,EAAU,CAAV,EAAa,CAAb,EAAgB,CAAhB,EAAmB,CAAnB,EAAsB,CAAtB,EAAyB,CAAzB,EAA4B,CAA5B,EAA+B,CAA/B,EAAkC,CAAlC,EAAqC,CAArC,EAAwC,CAAxC,EAA2C,CAA3C,EAA8C,CAA9C,CAAP;AACD;;AAGM,SAASC,eAAT,CAAyBC,MAAzB,EAA2CC,MAA3C,EAAuE;AAC5E,MAAMC,MAAM,GAAG,wBAAc,EAAd,EAA8BD,MAA9B,EAAsCD,MAAtC,CAAf;AACA,kBAAME,MAAN,EAAcA,MAAd,EAAsB,IAAIA,MAAM,CAAC,CAAD,CAAhC;AACA,SAAOA,MAAP;AACD;;AAEM,SAASC,GAAT,CAAaC,KAAb,EAA4BC,OAA5B,EAAqD;AAC1D,MAAMC,OAAO,GAAGF,KAAK,GAAGC,OAAxB;AACA,SAAOC,OAAO,GAAG,CAAV,GAAcD,OAAO,GAAGC,OAAxB,GAAkCA,OAAzC;AACD;;AAEM,SAASC,IAAT,CAAcC,KAAd,EAA6BC,GAA7B,EAA0CC,IAA1C,EAAgE;AACrE,SAAOA,IAAI,GAAGD,GAAP,GAAa,CAAC,IAAIC,IAAL,IAAaF,KAAjC;AACD;;AAEM,SAASG,KAAT,CAAeC,CAAf,EAA0BC,GAA1B,EAAuCC,GAAvC,EAA4D;AACjE,SAAOF,CAAC,GAAGC,GAAJ,GAAUA,GAAV,GAAgBD,CAAC,GAAGE,GAAJ,GAAUA,GAAV,GAAgBF,CAAvC;AACD;;AAED,SAASG,MAAT,CAAgBH,CAAhB,EAAmC;AACjC,SAAOI,IAAI,CAACC,GAAL,CAASL,CAAT,IAAcI,IAAI,CAACE,KAA1B;AACD;;AAEM,IAAMC,IAAI,GAAGH,IAAI,CAACG,IAAL,IAAaJ,MAA1B","sourcesContent":["import {transformMat4, scale} from 'gl-matrix/vec4';\n\n// Helper, avoids low-precision 32 bit matrices from gl-matrix mat4.create()\nexport function createMat4(): number[] {\n return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];\n}\n\n// Transforms a vec4 with a projection matrix\nexport function transformVector(matrix: number[], vector: number[]): number[] {\n const result = transformMat4([] as number[], vector, matrix);\n scale(result, result, 1 / result[3]);\n return result;\n}\n\nexport function mod(value: number, divisor: number): number {\n const modulus = value % divisor;\n return modulus < 0 ? divisor + modulus : modulus;\n}\n\nexport function lerp(start: number, end: number, step: number): number {\n return step * end + (1 - step) * start;\n}\n\nexport function clamp(x: number, min: number, max: number): number {\n return x < min ? min : x > max ? max : x;\n}\n\nfunction ieLog2(x: number): number {\n return Math.log(x) * Math.LOG2E;\n}\n// Handle missing log2 in IE 11\nexport const log2 = Math.log2 || ieLog2;\n"],"file":"math-utils.js"}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = normalizeViewportProps;
|
|
7
|
-
|
|
8
|
-
var _webMercatorUtils = require("./web-mercator-utils");
|
|
9
|
-
|
|
10
|
-
var _mathUtils = require("./math-utils");
|
|
11
|
-
|
|
12
|
-
var TILE_SIZE = 512;
|
|
13
|
-
|
|
14
|
-
function normalizeViewportProps(props) {
|
|
15
|
-
var width = props.width,
|
|
16
|
-
height = props.height,
|
|
17
|
-
_props$pitch = props.pitch,
|
|
18
|
-
pitch = _props$pitch === void 0 ? 0 : _props$pitch;
|
|
19
|
-
var longitude = props.longitude,
|
|
20
|
-
latitude = props.latitude,
|
|
21
|
-
zoom = props.zoom,
|
|
22
|
-
_props$bearing = props.bearing,
|
|
23
|
-
bearing = _props$bearing === void 0 ? 0 : _props$bearing;
|
|
24
|
-
|
|
25
|
-
if (longitude < -180 || longitude > 180) {
|
|
26
|
-
longitude = (0, _mathUtils.mod)(longitude + 180, 360) - 180;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
if (bearing < -180 || bearing > 180) {
|
|
30
|
-
bearing = (0, _mathUtils.mod)(bearing + 180, 360) - 180;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
var minZoom = (0, _mathUtils.log2)(height / TILE_SIZE);
|
|
34
|
-
|
|
35
|
-
if (zoom <= minZoom) {
|
|
36
|
-
zoom = minZoom;
|
|
37
|
-
latitude = 0;
|
|
38
|
-
} else {
|
|
39
|
-
var halfHeightPixels = height / 2 / Math.pow(2, zoom);
|
|
40
|
-
var minLatitude = (0, _webMercatorUtils.worldToLngLat)([0, halfHeightPixels])[1];
|
|
41
|
-
|
|
42
|
-
if (latitude < minLatitude) {
|
|
43
|
-
latitude = minLatitude;
|
|
44
|
-
} else {
|
|
45
|
-
var maxLatitude = (0, _webMercatorUtils.worldToLngLat)([0, TILE_SIZE - halfHeightPixels])[1];
|
|
46
|
-
|
|
47
|
-
if (latitude > maxLatitude) {
|
|
48
|
-
latitude = maxLatitude;
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
return {
|
|
54
|
-
width: width,
|
|
55
|
-
height: height,
|
|
56
|
-
longitude: longitude,
|
|
57
|
-
latitude: latitude,
|
|
58
|
-
zoom: zoom,
|
|
59
|
-
pitch: pitch,
|
|
60
|
-
bearing: bearing
|
|
61
|
-
};
|
|
62
|
-
}
|
|
63
|
-
//# sourceMappingURL=normalize-viewport-props.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/normalize-viewport-props.ts"],"names":["TILE_SIZE","normalizeViewportProps","props","width","height","pitch","longitude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,CAAd,EAAqC,CAArC,CAApB;;AACA,QAAIJ,QAAQ,GAAGO,WAAf,EAA4B;AAC1BP,MAAAA,QAAQ,GAAGO,WAAX;AACD,KAFD,MAEO;AACL,UAAMC,WAAW,GAAG,qCAAc,CAAC,CAAD,EAAIf,SAAS,GAAGW,gBAAhB,CAAd,EAAiD,CAAjD,CAApB;;AACA,UAAIJ,QAAQ,GAAGQ,WAAf,EAA4B;AAC1BR,QAAAA,QAAQ,GAAGQ,WAAX;AACD;AACF;AACF;;AAED,SAAO;AAACZ,IAAAA,KAAK,EAALA,KAAD;AAAQC,IAAAA,MAAM,EAANA,MAAR;AAAgBE,IAAAA,SAAS,EAATA,SAAhB;AAA2BC,IAAAA,QAAQ,EAARA,QAA3B;AAAqCC,IAAAA,IAAI,EAAJA,IAArC;AAA2CH,IAAAA,KAAK,EAALA,KAA3C;AAAkDI,IAAAA,OAAO,EAAPA;AAAlD,GAAP;AACD","sourcesContent":["import {worldToLngLat} from './web-mercator-utils';\nimport {mod, log2} from './math-utils';\n\n// defined by mapbox-gl\nconst TILE_SIZE = 512;\n\n/** Description of viewport */\nexport type ViewportProps = {\n width: number;\n height: number;\n longitude: number;\n latitude: number;\n zoom: number;\n pitch?: number;\n bearing?: number;\n};\n\n/**\n * Apply mathematical constraints to viewport props\n * @param props\n */\n// eslint-disable-next-line complexity\nexport default function normalizeViewportProps(props: ViewportProps): ViewportProps {\n const {width, height, pitch = 0} = props;\n let {longitude, latitude, zoom, bearing = 0} = props;\n\n // Normalize degrees\n if (longitude < -180 || longitude > 180) {\n longitude = mod(longitude + 180, 360) - 180;\n }\n if (bearing < -180 || bearing > 180) {\n bearing = mod(bearing + 180, 360) - 180;\n }\n\n // Constrain zoom and shift center at low zoom levels\n const minZoom = log2(height / TILE_SIZE);\n if (zoom <= minZoom) {\n zoom = minZoom;\n latitude = 0;\n } else {\n // Eliminate white space above and below the map\n const halfHeightPixels = height / 2 / Math.pow(2, zoom);\n const minLatitude = worldToLngLat([0, halfHeightPixels])[1];\n if (latitude < minLatitude) {\n latitude = minLatitude;\n } else {\n const maxLatitude = worldToLngLat([0, TILE_SIZE - halfHeightPixels])[1];\n if (latitude > maxLatitude) {\n latitude = maxLatitude;\n }\n }\n }\n\n return {width, height, longitude, latitude, zoom, pitch, bearing};\n}\n"],"file":"normalize-viewport-props.js"}
|
|
@@ -1,271 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
|
-
Object.defineProperty(exports, "__esModule", {
|
|
8
|
-
value: true
|
|
9
|
-
});
|
|
10
|
-
exports.zoomToScale = zoomToScale;
|
|
11
|
-
exports.scaleToZoom = scaleToZoom;
|
|
12
|
-
exports.lngLatToWorld = lngLatToWorld;
|
|
13
|
-
exports.worldToLngLat = worldToLngLat;
|
|
14
|
-
exports.getMeterZoom = getMeterZoom;
|
|
15
|
-
exports.unitsPerMeter = unitsPerMeter;
|
|
16
|
-
exports.getDistanceScales = getDistanceScales;
|
|
17
|
-
exports.addMetersToLngLat = addMetersToLngLat;
|
|
18
|
-
exports.getViewMatrix = getViewMatrix;
|
|
19
|
-
exports.getProjectionParameters = getProjectionParameters;
|
|
20
|
-
exports.getProjectionMatrix = getProjectionMatrix;
|
|
21
|
-
exports.altitudeToFovy = altitudeToFovy;
|
|
22
|
-
exports.fovyToAltitude = fovyToAltitude;
|
|
23
|
-
exports.worldToPixels = worldToPixels;
|
|
24
|
-
exports.pixelsToWorld = pixelsToWorld;
|
|
25
|
-
exports.DEFAULT_ALTITUDE = exports.MAX_LATITUDE = void 0;
|
|
26
|
-
|
|
27
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
28
|
-
|
|
29
|
-
var _mathUtils = require("./math-utils");
|
|
30
|
-
|
|
31
|
-
var mat4 = _interopRequireWildcard(require("gl-matrix/mat4"));
|
|
32
|
-
|
|
33
|
-
var vec2 = _interopRequireWildcard(require("gl-matrix/vec2"));
|
|
34
|
-
|
|
35
|
-
var vec3 = _interopRequireWildcard(require("gl-matrix/vec3"));
|
|
36
|
-
|
|
37
|
-
var _assert = _interopRequireDefault(require("./assert"));
|
|
38
|
-
|
|
39
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
40
|
-
|
|
41
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
42
|
-
|
|
43
|
-
var PI = Math.PI;
|
|
44
|
-
var PI_4 = PI / 4;
|
|
45
|
-
var DEGREES_TO_RADIANS = PI / 180;
|
|
46
|
-
var RADIANS_TO_DEGREES = 180 / PI;
|
|
47
|
-
var TILE_SIZE = 512;
|
|
48
|
-
var EARTH_CIRCUMFERENCE = 40.03e6;
|
|
49
|
-
var MAX_LATITUDE = 85.051129;
|
|
50
|
-
exports.MAX_LATITUDE = MAX_LATITUDE;
|
|
51
|
-
var DEFAULT_ALTITUDE = 1.5;
|
|
52
|
-
exports.DEFAULT_ALTITUDE = DEFAULT_ALTITUDE;
|
|
53
|
-
|
|
54
|
-
function zoomToScale(zoom) {
|
|
55
|
-
return Math.pow(2, zoom);
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
function scaleToZoom(scale) {
|
|
59
|
-
return (0, _mathUtils.log2)(scale);
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function lngLatToWorld(lngLat) {
|
|
63
|
-
var _lngLat = (0, _slicedToArray2.default)(lngLat, 2),
|
|
64
|
-
lng = _lngLat[0],
|
|
65
|
-
lat = _lngLat[1];
|
|
66
|
-
|
|
67
|
-
(0, _assert.default)(Number.isFinite(lng));
|
|
68
|
-
(0, _assert.default)(Number.isFinite(lat) && lat >= -90 && lat <= 90, 'invalid latitude');
|
|
69
|
-
var lambda2 = lng * DEGREES_TO_RADIANS;
|
|
70
|
-
var phi2 = lat * DEGREES_TO_RADIANS;
|
|
71
|
-
var x = TILE_SIZE * (lambda2 + PI) / (2 * PI);
|
|
72
|
-
var y = TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5))) / (2 * PI);
|
|
73
|
-
return [x, y];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function worldToLngLat(xy) {
|
|
77
|
-
var _xy = (0, _slicedToArray2.default)(xy, 2),
|
|
78
|
-
x = _xy[0],
|
|
79
|
-
y = _xy[1];
|
|
80
|
-
|
|
81
|
-
var lambda2 = x / TILE_SIZE * (2 * PI) - PI;
|
|
82
|
-
var phi2 = 2 * (Math.atan(Math.exp(y / TILE_SIZE * (2 * PI) - PI)) - PI_4);
|
|
83
|
-
return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
function getMeterZoom(options) {
|
|
87
|
-
var latitude = options.latitude;
|
|
88
|
-
(0, _assert.default)(Number.isFinite(latitude));
|
|
89
|
-
var latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
|
|
90
|
-
return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
function unitsPerMeter(latitude) {
|
|
94
|
-
var latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
|
|
95
|
-
return TILE_SIZE / EARTH_CIRCUMFERENCE / latCosine;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
function getDistanceScales(options) {
|
|
99
|
-
var latitude = options.latitude,
|
|
100
|
-
longitude = options.longitude,
|
|
101
|
-
_options$highPrecisio = options.highPrecision,
|
|
102
|
-
highPrecision = _options$highPrecisio === void 0 ? false : _options$highPrecisio;
|
|
103
|
-
(0, _assert.default)(Number.isFinite(latitude) && Number.isFinite(longitude));
|
|
104
|
-
var worldSize = TILE_SIZE;
|
|
105
|
-
var latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);
|
|
106
|
-
var unitsPerDegreeX = worldSize / 360;
|
|
107
|
-
var unitsPerDegreeY = unitsPerDegreeX / latCosine;
|
|
108
|
-
var altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;
|
|
109
|
-
var result = {
|
|
110
|
-
unitsPerMeter: [altUnitsPerMeter, altUnitsPerMeter, altUnitsPerMeter],
|
|
111
|
-
metersPerUnit: [1 / altUnitsPerMeter, 1 / altUnitsPerMeter, 1 / altUnitsPerMeter],
|
|
112
|
-
unitsPerDegree: [unitsPerDegreeX, unitsPerDegreeY, altUnitsPerMeter],
|
|
113
|
-
degreesPerUnit: [1 / unitsPerDegreeX, 1 / unitsPerDegreeY, 1 / altUnitsPerMeter]
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
if (highPrecision) {
|
|
117
|
-
var latCosine2 = DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS) / latCosine;
|
|
118
|
-
var unitsPerDegreeY2 = unitsPerDegreeX * latCosine2 / 2;
|
|
119
|
-
var altUnitsPerDegree2 = worldSize / EARTH_CIRCUMFERENCE * latCosine2;
|
|
120
|
-
var altUnitsPerMeter2 = altUnitsPerDegree2 / unitsPerDegreeY * altUnitsPerMeter;
|
|
121
|
-
result.unitsPerDegree2 = [0, unitsPerDegreeY2, altUnitsPerDegree2];
|
|
122
|
-
result.unitsPerMeter2 = [altUnitsPerMeter2, 0, altUnitsPerMeter2];
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function addMetersToLngLat(lngLatZ, xyz) {
|
|
129
|
-
var _lngLatZ = (0, _slicedToArray2.default)(lngLatZ, 3),
|
|
130
|
-
longitude = _lngLatZ[0],
|
|
131
|
-
latitude = _lngLatZ[1],
|
|
132
|
-
z0 = _lngLatZ[2];
|
|
133
|
-
|
|
134
|
-
var _xyz = (0, _slicedToArray2.default)(xyz, 3),
|
|
135
|
-
x = _xyz[0],
|
|
136
|
-
y = _xyz[1],
|
|
137
|
-
z = _xyz[2];
|
|
138
|
-
|
|
139
|
-
var _getDistanceScales = getDistanceScales({
|
|
140
|
-
longitude: longitude,
|
|
141
|
-
latitude: latitude,
|
|
142
|
-
highPrecision: true
|
|
143
|
-
}),
|
|
144
|
-
unitsPerMeter = _getDistanceScales.unitsPerMeter,
|
|
145
|
-
unitsPerMeter2 = _getDistanceScales.unitsPerMeter2;
|
|
146
|
-
|
|
147
|
-
var worldspace = lngLatToWorld(lngLatZ);
|
|
148
|
-
worldspace[0] += x * (unitsPerMeter[0] + unitsPerMeter2[0] * y);
|
|
149
|
-
worldspace[1] += y * (unitsPerMeter[1] + unitsPerMeter2[1] * y);
|
|
150
|
-
var newLngLat = worldToLngLat(worldspace);
|
|
151
|
-
var newZ = (z0 || 0) + (z || 0);
|
|
152
|
-
return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
function getViewMatrix(options) {
|
|
156
|
-
var height = options.height,
|
|
157
|
-
pitch = options.pitch,
|
|
158
|
-
bearing = options.bearing,
|
|
159
|
-
altitude = options.altitude,
|
|
160
|
-
scale = options.scale,
|
|
161
|
-
center = options.center;
|
|
162
|
-
var vm = (0, _mathUtils.createMat4)();
|
|
163
|
-
mat4.translate(vm, vm, [0, 0, -altitude]);
|
|
164
|
-
mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);
|
|
165
|
-
mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);
|
|
166
|
-
var relativeScale = scale / height;
|
|
167
|
-
mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);
|
|
168
|
-
|
|
169
|
-
if (center) {
|
|
170
|
-
mat4.translate(vm, vm, vec3.negate([], center));
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
return vm;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
function getProjectionParameters(options) {
|
|
177
|
-
var width = options.width,
|
|
178
|
-
height = options.height,
|
|
179
|
-
altitude = options.altitude,
|
|
180
|
-
_options$pitch = options.pitch,
|
|
181
|
-
pitch = _options$pitch === void 0 ? 0 : _options$pitch,
|
|
182
|
-
offset = options.offset,
|
|
183
|
-
center = options.center,
|
|
184
|
-
scale = options.scale,
|
|
185
|
-
_options$nearZMultipl = options.nearZMultiplier,
|
|
186
|
-
nearZMultiplier = _options$nearZMultipl === void 0 ? 1 : _options$nearZMultipl,
|
|
187
|
-
_options$farZMultipli = options.farZMultiplier,
|
|
188
|
-
farZMultiplier = _options$farZMultipli === void 0 ? 1 : _options$farZMultipli;
|
|
189
|
-
var _options$fovy = options.fovy,
|
|
190
|
-
fovy = _options$fovy === void 0 ? altitudeToFovy(DEFAULT_ALTITUDE) : _options$fovy;
|
|
191
|
-
|
|
192
|
-
if (altitude !== undefined) {
|
|
193
|
-
fovy = altitudeToFovy(altitude);
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
var fovRadians = fovy * DEGREES_TO_RADIANS;
|
|
197
|
-
var pitchRadians = pitch * DEGREES_TO_RADIANS;
|
|
198
|
-
var focalDistance = fovyToAltitude(fovy);
|
|
199
|
-
var cameraToSeaLevelDistance = focalDistance;
|
|
200
|
-
|
|
201
|
-
if (center) {
|
|
202
|
-
cameraToSeaLevelDistance += center[2] * scale / Math.cos(pitchRadians) / height;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
var fovAboveCenter = fovRadians * (0.5 + (offset ? offset[1] : 0) / height);
|
|
206
|
-
var topHalfSurfaceDistance = Math.sin(fovAboveCenter) * cameraToSeaLevelDistance / Math.sin((0, _mathUtils.clamp)(Math.PI / 2 - pitchRadians - fovAboveCenter, 0.01, Math.PI - 0.01));
|
|
207
|
-
var furthestDistance = Math.sin(pitchRadians) * topHalfSurfaceDistance + cameraToSeaLevelDistance;
|
|
208
|
-
var horizonDistance = cameraToSeaLevelDistance * 10;
|
|
209
|
-
var farZ = Math.min(furthestDistance * farZMultiplier, horizonDistance);
|
|
210
|
-
return {
|
|
211
|
-
fov: fovRadians,
|
|
212
|
-
aspect: width / height,
|
|
213
|
-
focalDistance: focalDistance,
|
|
214
|
-
near: nearZMultiplier,
|
|
215
|
-
far: farZ
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
function getProjectionMatrix(options) {
|
|
220
|
-
var _getProjectionParamet = getProjectionParameters(options),
|
|
221
|
-
fov = _getProjectionParamet.fov,
|
|
222
|
-
aspect = _getProjectionParamet.aspect,
|
|
223
|
-
near = _getProjectionParamet.near,
|
|
224
|
-
far = _getProjectionParamet.far;
|
|
225
|
-
|
|
226
|
-
var projectionMatrix = mat4.perspective([], fov, aspect, near, far);
|
|
227
|
-
return projectionMatrix;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
function altitudeToFovy(altitude) {
|
|
231
|
-
return 2 * Math.atan(0.5 / altitude) * RADIANS_TO_DEGREES;
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
function fovyToAltitude(fovy) {
|
|
235
|
-
return 0.5 / Math.tan(0.5 * fovy * DEGREES_TO_RADIANS);
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
function worldToPixels(xyz, pixelProjectionMatrix) {
|
|
239
|
-
var _xyz2 = (0, _slicedToArray2.default)(xyz, 3),
|
|
240
|
-
x = _xyz2[0],
|
|
241
|
-
y = _xyz2[1],
|
|
242
|
-
_xyz2$ = _xyz2[2],
|
|
243
|
-
z = _xyz2$ === void 0 ? 0 : _xyz2$;
|
|
244
|
-
|
|
245
|
-
(0, _assert.default)(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));
|
|
246
|
-
return (0, _mathUtils.transformVector)(pixelProjectionMatrix, [x, y, z, 1]);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
function pixelsToWorld(xyz, pixelUnprojectionMatrix) {
|
|
250
|
-
var targetZ = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 0;
|
|
251
|
-
|
|
252
|
-
var _xyz3 = (0, _slicedToArray2.default)(xyz, 3),
|
|
253
|
-
x = _xyz3[0],
|
|
254
|
-
y = _xyz3[1],
|
|
255
|
-
z = _xyz3[2];
|
|
256
|
-
|
|
257
|
-
(0, _assert.default)(Number.isFinite(x) && Number.isFinite(y), 'invalid pixel coordinate');
|
|
258
|
-
|
|
259
|
-
if (Number.isFinite(z)) {
|
|
260
|
-
var coord = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, z, 1]);
|
|
261
|
-
return coord;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
var coord0 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 0, 1]);
|
|
265
|
-
var coord1 = (0, _mathUtils.transformVector)(pixelUnprojectionMatrix, [x, y, 1, 1]);
|
|
266
|
-
var z0 = coord0[2];
|
|
267
|
-
var z1 = coord1[2];
|
|
268
|
-
var t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);
|
|
269
|
-
return vec2.lerp([], coord0, coord1, t);
|
|
270
|
-
}
|
|
271
|
-
//# sourceMappingURL=web-mercator-utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/web-mercator-utils.ts"],"names":["PI","Math","PI_4","DEGREES_TO_RADIANS","RADIANS_TO_DEGREES","TILE_SIZE","EARTH_CIRCUMFERENCE","MAX_LATITUDE","DEFAULT_ALTITUDE","zoomToScale","zoom","pow","scaleToZoom","scale","lngLatToWorld","lngLat","lng","lat","Number","isFinite","lambda2","phi2","x","y","log","tan","worldToLngLat","xy","atan","exp","getMeterZoom","options","latitude","latCosine","cos","unitsPerMeter","getDistanceScales","longitude","highPrecision","worldSize","unitsPerDegreeX","unitsPerDegreeY","altUnitsPerMeter","result","metersPerUnit","unitsPerDegree","degreesPerUnit","latCosine2","unitsPerDegreeY2","altUnitsPerDegree2","altUnitsPerMeter2","unitsPerDegree2","unitsPerMeter2","addMetersToLngLat","lngLatZ","xyz","z0","z","worldspace","newLngLat","newZ","getViewMatrix","height","pitch","bearing","altitude","center","vm","mat4","translate","rotateX","rotateZ","relativeScale","vec3","negate","getProjectionParameters","width","offset","nearZMultiplier","farZMultiplier","fovy","altitudeToFovy","undefined","fovRadians","pitchRadians","focalDistance","fovyToAltitude","cameraToSeaLevelDistance","fovAboveCenter","topHalfSurfaceDistance","sin","furthestDistance","horizonDistance","farZ","min","fov","aspect","near","far","getProjectionMatrix","projectionMatrix","perspective","worldToPixels","pixelProjectionMatrix","pixelsToWorld","pixelUnprojectionMatrix","targetZ","coord","coord0","coord1","z1","t","vec2","lerp"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA;;AAEA;;AACA;;AACA;;AACA;;;;;;AAGA,IAAMA,EAAE,GAAGC,IAAI,CAACD,EAAhB;AACA,IAAME,IAAI,GAAGF,EAAE,GAAG,CAAlB;AACA,IAAMG,kBAAkB,GAAGH,EAAE,GAAG,GAAhC;AACA,IAAMI,kBAAkB,GAAG,MAAMJ,EAAjC;AACA,IAAMK,SAAS,GAAG,GAAlB;AAEA,IAAMC,mB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,EAELkD,uBAFK,EAIK;AAAA,MADVC,OACU,uEADQ,CACR;;AACV,2CAAkBnD,GAAlB;AAAA,MAAOjC,CAAP;AAAA,MAAUC,CAAV;AAAA,MAAakC,CAAb;;AACA,uBAAOvC,MAAM,CAACC,QAAP,CAAgBG,CAAhB,KAAsBJ,MAAM,CAACC,QAAP,CAAgBI,CAAhB,CAA7B,EAAiD,0BAAjD;;AAEA,MAAIL,MAAM,CAACC,QAAP,CAAgBsC,CAAhB,CAAJ,EAAwB;AAEtB,QAAMkD,KAAK,GAAG,gCAAgBF,uBAAhB,EAAyC,CAACnF,CAAD,EAAIC,CAAJ,EAAOkC,CAAP,EAAU,CAAV,CAAzC,CAAd;AACA,WAAOkD,KAAP;AACD;;AAID,MAAMC,MAAM,GAAG,gCAAgBH,uBAAhB,EAAyC,CAACnF,CAAD,EAAIC,CAAJ,EAAO,CAAP,EAAU,CAAV,CAAzC,CAAf;AACA,MAAMsF,MAAM,GAAG,gCAAgBJ,uBAAhB,EAAyC,CAACnF,CAAD,EAAIC,CAAJ,EAAO,CAAP,EAAU,CAAV,CAAzC,CAAf;AAEA,MAAMiC,EAAE,GAAGoD,MAAM,CAAC,CAAD,CAAjB;AACA,MAAME,EAAE,GAAGD,MAAM,CAAC,CAAD,CAAjB;AAEA,MAAME,CAAC,GAAGvD,EAAE,KAAKsD,EAAP,GAAY,CAAZ,GAAgB,CAAC,CAACJ,OAAO,IAAI,CAAZ,IAAiBlD,EAAlB,KAAyBsD,EAAE,GAAGtD,EAA9B,CAA1B;AACA,SAAOwD,IAAI,CAACC,IAAL,CAAU,EAAV,EAA0BL,MAA1B,EAAkCC,MAAlC,EAA0CE,CAA1C,CAAP;AACD","sourcesContent":["// TODO - THE UTILITIES IN THIS FILE SHOULD BE IMPORTED FROM WEB-MERCATOR-VIEWPORT MODULE\n\nimport {createMat4, transformVector, clamp, log2} from './math-utils';\n\nimport * as mat4 from 'gl-matrix/mat4';\nimport * as vec2 from 'gl-matrix/vec2';\nimport * as vec3 from 'gl-matrix/vec3';\nimport assert from './assert';\n\n// CONSTANTS\nconst PI = Math.PI;\nconst PI_4 = PI / 4;\nconst DEGREES_TO_RADIANS = PI / 180;\nconst RADIANS_TO_DEGREES = 180 / PI;\nconst TILE_SIZE = 512;\n// Average circumference (40075 km equatorial, 40007 km meridional)\nconst EARTH_CIRCUMFERENCE = 40.03e6;\n// Latitude that makes a square world, 2 * atan(E ** PI) - PI / 2\nexport const MAX_LATITUDE = 85.051129;\n\n// Mapbox default altitude\nexport const DEFAULT_ALTITUDE = 1.5;\n\nexport type DistanceScales = {\n unitsPerMeter: number[];\n metersPerUnit: number[];\n unitsPerMeter2?: number[];\n unitsPerDegree: number[];\n degreesPerUnit: number[];\n unitsPerDegree2?: number[];\n};\n\n/**\n * PROJECTION MATRIX PARAMETERS\n *\n * TODO how to document mebers\n * @param fov in radians. fov is variable, depends on pitch and altitude\n * @param aspect width/height\n * @param focalDistance distance at which visual scale factor is 1\n * @param near near clipping plane\n * @param far far clipping plane\n */\ntype ProjectionParameters = {\n fov: number;\n aspect: number;\n focalDistance: number;\n near: number;\n far: number;\n};\n\n/** Logarithimic zoom to linear scale **/\nexport function zoomToScale(zoom: number): number {\n return Math.pow(2, zoom);\n}\n\n/** Linear scale to logarithimic zoom **/\nexport function scaleToZoom(scale: number): number {\n return log2(scale);\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 */\nexport function lngLatToWorld(lngLat: number[]): [number, number] {\n const [lng, lat] = lngLat;\n assert(Number.isFinite(lng));\n assert(Number.isFinite(lat) && lat >= -90 && lat <= 90, 'invalid latitude');\n\n const lambda2 = lng * DEGREES_TO_RADIANS;\n const phi2 = lat * DEGREES_TO_RADIANS;\n const x = (TILE_SIZE * (lambda2 + PI)) / (2 * PI);\n const y = (TILE_SIZE * (PI + Math.log(Math.tan(PI_4 + phi2 * 0.5)))) / (2 * PI);\n return [x, y];\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 [x,y] 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 */\nexport function worldToLngLat(xy: number[]): [number, number] {\n const [x, y] = xy;\n const lambda2 = (x / TILE_SIZE) * (2 * PI) - PI;\n const phi2 = 2 * (Math.atan(Math.exp((y / TILE_SIZE) * (2 * PI) - PI)) - PI_4);\n return [lambda2 * RADIANS_TO_DEGREES, phi2 * RADIANS_TO_DEGREES];\n}\n\n/**\n * Returns the zoom level that gives a 1 meter pixel at a certain latitude\n * 1 = C*cos(y)/2^z/TILE_SIZE = C*cos(y)/2^(z+9)\n */\nexport function getMeterZoom(options: {latitude: number}): number {\n const {latitude} = options;\n assert(Number.isFinite(latitude));\n const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);\n return scaleToZoom(EARTH_CIRCUMFERENCE * latCosine) - 9;\n}\n\n/**\n * Calculate the conversion from meter to common units at a given latitude\n * This is a cheaper version of `getDistanceScales`\n * @param latitude center latitude in degrees\n * @returns common units per meter\n */\nexport function unitsPerMeter(latitude: number): number {\n const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);\n return TILE_SIZE / EARTH_CIRCUMFERENCE / latCosine;\n}\n\n/**\n * Calculate distance scales in meters around current lat/lon, both for\n * degrees and pixels.\n * In mercator projection mode, the distance scales vary significantly\n * with latitude.\n */\nexport function getDistanceScales(options: {\n latitude: number;\n longitude: number;\n highPrecision?: boolean;\n}): DistanceScales {\n const {latitude, longitude, highPrecision = false} = options;\n assert(Number.isFinite(latitude) && Number.isFinite(longitude));\n\n const worldSize = TILE_SIZE;\n const latCosine = Math.cos(latitude * DEGREES_TO_RADIANS);\n\n /**\n * Number of pixels occupied by one degree longitude around current lat/lon:\n unitsPerDegreeX = d(lngLatToWorld([lng, lat])[0])/d(lng)\n = scale * TILE_SIZE * DEGREES_TO_RADIANS / (2 * PI)\n unitsPerDegreeY = d(lngLatToWorld([lng, lat])[1])/d(lat)\n = -scale * TILE_SIZE * DEGREES_TO_RADIANS / cos(lat * DEGREES_TO_RADIANS) / (2 * PI)\n */\n const unitsPerDegreeX = worldSize / 360;\n const unitsPerDegreeY = unitsPerDegreeX / latCosine;\n\n /**\n * Number of pixels occupied by one meter around current lat/lon:\n */\n const altUnitsPerMeter = worldSize / EARTH_CIRCUMFERENCE / latCosine;\n\n /**\n * LngLat: longitude -> east and latitude -> north (bottom left)\n * UTM meter offset: x -> east and y -> north (bottom left)\n * World space: x -> east and y -> south (top left)\n *\n * Y needs to be flipped when converting delta degree/meter to delta pixels\n */\n const result: DistanceScales = {\n unitsPerMeter: [altUnitsPerMeter, altUnitsPerMeter, altUnitsPerMeter],\n metersPerUnit: [1 / altUnitsPerMeter, 1 / altUnitsPerMeter, 1 / altUnitsPerMeter],\n\n unitsPerDegree: [unitsPerDegreeX, unitsPerDegreeY, altUnitsPerMeter],\n degreesPerUnit: [1 / unitsPerDegreeX, 1 / unitsPerDegreeY, 1 / altUnitsPerMeter]\n };\n\n /**\n * Taylor series 2nd order for 1/latCosine\n f'(a) * (x - a)\n = d(1/cos(lat * DEGREES_TO_RADIANS))/d(lat) * dLat\n = DEGREES_TO_RADIANS * tan(lat * DEGREES_TO_RADIANS) / cos(lat * DEGREES_TO_RADIANS) * dLat\n */\n if (highPrecision) {\n const latCosine2 = (DEGREES_TO_RADIANS * Math.tan(latitude * DEGREES_TO_RADIANS)) / latCosine;\n const unitsPerDegreeY2 = (unitsPerDegreeX * latCosine2) / 2;\n const altUnitsPerDegree2 = (worldSize / EARTH_CIRCUMFERENCE) * latCosine2;\n const altUnitsPerMeter2 = (altUnitsPerDegree2 / unitsPerDegreeY) * altUnitsPerMeter;\n\n result.unitsPerDegree2 = [0, unitsPerDegreeY2, altUnitsPerDegree2];\n result.unitsPerMeter2 = [altUnitsPerMeter2, 0, altUnitsPerMeter2];\n }\n\n // Main results, used for converting meters to latlng deltas and scaling offsets\n return result;\n}\n\n/**\n * Offset a lng/lat position by meterOffset (northing, easting)\n */\nexport function addMetersToLngLat(lngLatZ: number[], xyz: number[]): number[] {\n const [longitude, latitude, z0] = lngLatZ;\n const [x, y, z] = xyz;\n\n const {unitsPerMeter, unitsPerMeter2} = getDistanceScales({\n longitude,\n latitude,\n highPrecision: true\n });\n\n const worldspace = lngLatToWorld(lngLatZ);\n worldspace[0] += x * (unitsPerMeter[0] + unitsPerMeter2[0] * y);\n worldspace[1] += y * (unitsPerMeter[1] + unitsPerMeter2[1] * y);\n\n const newLngLat = worldToLngLat(worldspace);\n const newZ = (z0 || 0) + (z || 0);\n\n return Number.isFinite(z0) || Number.isFinite(z) ? [newLngLat[0], newLngLat[1], newZ] : newLngLat;\n}\n\n/**\n *\n * view and projection matrix creation is intentionally kept compatible with\n * mapbox-gl's implementation to ensure that seamless interoperation\n * with mapbox and react-map-gl. See: https://github.com/mapbox/mapbox-gl-js\n */\nexport function getViewMatrix(options: {\n // Viewport props\n height: number;\n pitch: number;\n bearing: number;\n altitude: number;\n // Pre-calculated parameters\n scale: number;\n center?: number[];\n}): number[] {\n const {\n // Viewport props\n height,\n pitch,\n bearing,\n altitude,\n // Pre-calculated parameters\n scale,\n center\n } = options;\n // VIEW MATRIX: PROJECTS MERCATOR WORLD COORDINATES\n // Note that mercator world coordinates typically need to be flipped\n //\n // Note: As usual, matrix operation orders should be read in reverse\n // since vectors will be multiplied from the right during transformation\n const vm = createMat4();\n\n // Move camera to altitude (along the pitch & bearing direction)\n mat4.translate(vm, vm, [0, 0, -altitude]);\n\n // Rotate by bearing, and then by pitch (which tilts the view)\n mat4.rotateX(vm, vm, -pitch * DEGREES_TO_RADIANS);\n mat4.rotateZ(vm, vm, bearing * DEGREES_TO_RADIANS);\n\n const relativeScale = scale / height;\n mat4.scale(vm, vm, [relativeScale, relativeScale, relativeScale]);\n\n if (center) {\n mat4.translate(vm, vm, vec3.negate([], center));\n }\n\n return vm;\n}\n\n/**\n * Calculates mapbox compatible projection matrix from parameters\n *\n * @param options.width Width of \"viewport\" or window\n * @param options.height Height of \"viewport\" or window\n * @param options.scale Scale at the current zoom\n * @param options.center Offset of the target, vec3 in world space\n * @param options.offset Offset of the focal point, vec2 in screen space\n * @param options.pitch Camera angle in degrees (0 is straight down)\n * @param options.fovy field of view in degrees\n * @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`\n * @param options.nearZMultiplier control z buffer\n * @param options.farZMultiplier control z buffer\n * @returns project parameters object\n */\nexport function getProjectionParameters(options: {\n width: number;\n height: number;\n scale?: number;\n center?: number[];\n offset?: [number, number];\n fovy?: number;\n altitude?: number;\n pitch?: number;\n nearZMultiplier?: number;\n farZMultiplier?: number;\n}): ProjectionParameters {\n const {\n width,\n height,\n altitude,\n pitch = 0,\n offset,\n center,\n scale,\n nearZMultiplier = 1,\n farZMultiplier = 1\n } = options;\n let {fovy = altitudeToFovy(DEFAULT_ALTITUDE)} = options;\n\n // For back-compatibility allow field of view to be\n // derived from altitude\n if (altitude !== undefined) {\n fovy = altitudeToFovy(altitude);\n }\n\n const fovRadians = fovy * DEGREES_TO_RADIANS;\n const pitchRadians = pitch * DEGREES_TO_RADIANS;\n\n // Distance from camera to the target\n const focalDistance = fovyToAltitude(fovy);\n\n let cameraToSeaLevelDistance = focalDistance;\n\n if (center) {\n cameraToSeaLevelDistance += (center[2] * scale) / Math.cos(pitchRadians) / height;\n }\n\n const fovAboveCenter = fovRadians * (0.5 + (offset ? offset[1] : 0) / height);\n\n // Find the distance from the center point to the center top\n // in focal distance units using law of sines.\n const topHalfSurfaceDistance =\n (Math.sin(fovAboveCenter) * cameraToSeaLevelDistance) /\n Math.sin(clamp(Math.PI / 2 - pitchRadians - fovAboveCenter, 0.01, Math.PI - 0.01));\n\n // Calculate z distance of the farthest fragment that should be rendered.\n const furthestDistance =\n Math.sin(pitchRadians) * topHalfSurfaceDistance + cameraToSeaLevelDistance;\n // Matches mapbox limit\n const horizonDistance = cameraToSeaLevelDistance * 10;\n\n // Calculate z value of the farthest fragment that should be rendered.\n const farZ = Math.min(furthestDistance * farZMultiplier, horizonDistance);\n\n return {\n fov: fovRadians,\n aspect: width / height,\n focalDistance,\n near: nearZMultiplier,\n far: farZ\n };\n}\n\n/**\n * CALCULATE PROJECTION MATRIX: PROJECTS FROM CAMERA (VIEW) SPACE TO CLIPSPACE\n *\n * To match mapbox's z buffer:\n * - \\<= 0.28: nearZMultiplier: 0.1, farZmultiplier: 1\n * - \\>= 0.29: nearZMultiplier: 1 / height, farZMultiplier: 1.01\n *\n * @param options Viewport options\n * @param options.width Width of \"viewport\" or window\n * @param options.height Height of \"viewport\" or window\n * @param options.scale Scale at the current zoom\n * @param options.center Offset of the target, vec3 in world space\n * @param options.offset Offset of the focal point, vec2 in screen space\n * @param options.pitch Camera angle in degrees (0 is straight down)\n * @param options.fovy field of view in degrees\n * @param options.altitude if provided, field of view is calculated using `altitudeToFovy()`\n * @param options.nearZMultiplier control z buffer\n * @param options.farZMultiplier control z buffer\n * @returns 4x4 projection matrix\n */\nexport function getProjectionMatrix(options: {\n width: number;\n height: number;\n pitch: number;\n scale?: number;\n center?: number[];\n offset?: [number, number];\n fovy?: number;\n altitude?: number;\n nearZMultiplier: number;\n farZMultiplier: number;\n}): number[] {\n const {fov, aspect, near, far} = getProjectionParameters(options);\n\n const projectionMatrix = mat4.perspective(\n [] as number[],\n fov, // fov in radians\n aspect, // aspect ratio\n near, // near plane\n far // far plane\n );\n\n return projectionMatrix;\n}\n\n/**\n *\n * Convert an altitude to field of view such that the\n * focal distance is equal to the altitude\n *\n * @param altitude - altitude of camera in screen units\n * @return fovy field of view in degrees\n */\nexport function altitudeToFovy(altitude: number): number {\n return 2 * Math.atan(0.5 / altitude) * RADIANS_TO_DEGREES;\n}\n\n/**\n *\n * Convert an field of view such that the\n * focal distance is equal to the altitude\n *\n * @param fovy - field of view in degrees\n * @return altitude altitude of camera in screen units\n */\nexport function fovyToAltitude(fovy: number): number {\n return 0.5 / Math.tan(0.5 * fovy * DEGREES_TO_RADIANS);\n}\n\n/**\n * Project flat coordinates to pixels on screen.\n *\n * @param xyz - flat coordinate on 512*512 Mercator Zoom 0 tile\n * @param pixelProjectionMatrix - projection matrix 4x4\n * @return [x, y, depth] pixel coordinate on screen.\n */\nexport function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[];\n\n// Project flat coordinates to pixels on screen.\nexport function worldToPixels(xyz: number[], pixelProjectionMatrix: number[]): number[] {\n const [x, y, z = 0] = xyz;\n assert(Number.isFinite(x) && Number.isFinite(y) && Number.isFinite(z));\n\n return transformVector(pixelProjectionMatrix, [x, y, z, 1]);\n}\n\n/**\n * Unproject pixels on screen to flat coordinates.\n *\n * @param xyz - pixel coordinate on screen.\n * @param pixelUnprojectionMatrix - unprojection matrix 4x4\n * @param targetZ - if pixel coordinate does not have a 3rd component (depth),\n * targetZ is used as the elevation plane to unproject onto\n * @return [x, y, Z] flat coordinates on 512*512 Mercator Zoom 0 tile.\n */\nexport function pixelsToWorld(\n xyz: number[],\n pixelUnprojectionMatrix: number[],\n targetZ: number = 0\n): number[] {\n const [x, y, z] = xyz;\n assert(Number.isFinite(x) && Number.isFinite(y), 'invalid pixel coordinate');\n\n if (Number.isFinite(z)) {\n // Has depth component\n const coord = transformVector(pixelUnprojectionMatrix, [x, y, z, 1]);\n return coord;\n }\n\n // since we don't know the correct projected z value for the point,\n // unproject two points to get a line and then find the point on that line with z=0\n const coord0 = transformVector(pixelUnprojectionMatrix, [x, y, 0, 1]);\n const coord1 = transformVector(pixelUnprojectionMatrix, [x, y, 1, 1]);\n\n const z0 = coord0[2];\n const z1 = coord1[2];\n\n const t = z0 === z1 ? 0 : ((targetZ || 0) - z0) / (z1 - z0);\n return vec2.lerp([] as number[], coord0, coord1, t);\n}\n"],"file":"web-mercator-utils.js"}
|