@math.gl/web-mercator 3.5.6 → 3.6.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/assert.d.ts +2 -0
- package/dist/assert.d.ts.map +1 -0
- package/dist/assert.js +8 -0
- package/dist/es5/assert.js.map +1 -1
- package/dist/es5/fit-bounds.js +40 -50
- package/dist/es5/fit-bounds.js.map +1 -1
- package/dist/es5/fly-to-viewport.js +82 -98
- package/dist/es5/fly-to-viewport.js.map +1 -1
- package/dist/es5/get-bounds.js +25 -24
- package/dist/es5/get-bounds.js.map +1 -1
- package/dist/es5/index.js +23 -25
- package/dist/es5/index.js.map +1 -1
- package/dist/es5/math-utils.js +5 -11
- package/dist/es5/math-utils.js.map +1 -1
- package/dist/es5/normalize-viewport-props.js +25 -23
- package/dist/es5/normalize-viewport-props.js.map +1 -1
- package/dist/es5/web-mercator-utils.js +104 -144
- package/dist/es5/web-mercator-utils.js.map +1 -1
- package/dist/es5/web-mercator-viewport.js +198 -241
- package/dist/es5/web-mercator-viewport.js.map +1 -1
- package/dist/esm/assert.js.map +1 -1
- package/dist/esm/fit-bounds.js +24 -22
- package/dist/esm/fit-bounds.js.map +1 -1
- package/dist/esm/fly-to-viewport.js +13 -9
- package/dist/esm/fly-to-viewport.js.map +1 -1
- package/dist/esm/get-bounds.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/math-utils.js +3 -3
- package/dist/esm/math-utils.js.map +1 -1
- package/dist/esm/normalize-viewport-props.js +13 -9
- package/dist/esm/normalize-viewport-props.js.map +1 -1
- package/dist/esm/web-mercator-utils.js +46 -52
- package/dist/esm/web-mercator-utils.js.map +1 -1
- package/dist/esm/web-mercator-viewport.js +75 -33
- package/dist/esm/web-mercator-viewport.js.map +1 -1
- package/dist/fit-bounds.d.ts +49 -0
- package/dist/fit-bounds.d.ts.map +1 -0
- package/dist/fit-bounds.js +70 -0
- package/dist/fly-to-viewport.d.ts +19 -0
- package/dist/fly-to-viewport.d.ts.map +1 -0
- package/dist/fly-to-viewport.js +87 -0
- package/dist/get-bounds.d.ts +3 -0
- package/dist/get-bounds.d.ts.map +1 -0
- package/dist/get-bounds.js +51 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/math-utils.d.ts +6 -0
- package/dist/math-utils.d.ts.map +1 -0
- package/dist/math-utils.js +23 -0
- package/dist/normalize-viewport-props.d.ts +17 -0
- package/dist/normalize-viewport-props.d.ts.map +1 -0
- package/dist/normalize-viewport-props.js +41 -0
- package/dist/{es5/web-mercator-utils.d.ts → web-mercator-utils.d.ts} +77 -94
- package/dist/web-mercator-utils.d.ts.map +1 -0
- package/dist/web-mercator-utils.js +289 -0
- package/dist/web-mercator-viewport.d.ts +183 -0
- package/dist/web-mercator-viewport.d.ts.map +1 -0
- package/dist/web-mercator-viewport.js +282 -0
- package/package.json +3 -3
- package/src/{assert.js → assert.ts} +1 -1
- package/src/fit-bounds.ts +135 -0
- package/src/{fly-to-viewport.js → fly-to-viewport.ts} +33 -10
- package/src/{get-bounds.js → get-bounds.ts} +4 -2
- package/src/{index.js → index.ts} +0 -0
- package/src/{math-utils.js → math-utils.ts} +7 -7
- package/src/{normalize-viewport-props.js → normalize-viewport-props.ts} +19 -10
- package/src/{web-mercator-utils.js → web-mercator-utils.ts} +181 -72
- package/src/web-mercator-viewport.ts +417 -0
- package/dist/es5/fit-bounds.d.ts +0 -64
- package/dist/es5/fly-to-viewport.d.ts +0 -31
- package/dist/es5/get-bounds.d.ts +0 -3
- package/dist/es5/index.d.ts +0 -23
- package/dist/es5/normalize-viewport-props.d.ts +0 -16
- package/dist/es5/web-mercator-viewport.d.ts +0 -187
- package/dist/esm/fit-bounds.d.ts +0 -64
- package/dist/esm/fly-to-viewport.d.ts +0 -31
- package/dist/esm/get-bounds.d.ts +0 -3
- package/dist/esm/index.d.ts +0 -23
- package/dist/esm/normalize-viewport-props.d.ts +0 -16
- package/dist/esm/web-mercator-utils.d.ts +0 -189
- package/dist/esm/web-mercator-viewport.d.ts +0 -187
- package/src/fit-bounds.d.ts +0 -64
- package/src/fit-bounds.js +0 -84
- package/src/fly-to-viewport.d.ts +0 -31
- package/src/get-bounds.d.ts +0 -3
- package/src/index.d.ts +0 -23
- package/src/normalize-viewport-props.d.ts +0 -16
- package/src/web-mercator-utils.d.ts +0 -189
- package/src/web-mercator-viewport.d.ts +0 -187
- package/src/web-mercator-viewport.js +0 -262
package/dist/es5/index.js
CHANGED
|
@@ -2,134 +2,132 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
-
|
|
7
5
|
Object.defineProperty(exports, "__esModule", {
|
|
8
6
|
value: true
|
|
9
7
|
});
|
|
10
8
|
Object.defineProperty(exports, "default", {
|
|
11
9
|
enumerable: true,
|
|
12
|
-
get: function
|
|
10
|
+
get: function () {
|
|
13
11
|
return _webMercatorViewport.default;
|
|
14
12
|
}
|
|
15
13
|
});
|
|
16
14
|
Object.defineProperty(exports, "WebMercatorViewport", {
|
|
17
15
|
enumerable: true,
|
|
18
|
-
get: function
|
|
16
|
+
get: function () {
|
|
19
17
|
return _webMercatorViewport.default;
|
|
20
18
|
}
|
|
21
19
|
});
|
|
22
20
|
Object.defineProperty(exports, "getBounds", {
|
|
23
21
|
enumerable: true,
|
|
24
|
-
get: function
|
|
22
|
+
get: function () {
|
|
25
23
|
return _getBounds.default;
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
26
|
Object.defineProperty(exports, "fitBounds", {
|
|
29
27
|
enumerable: true,
|
|
30
|
-
get: function
|
|
28
|
+
get: function () {
|
|
31
29
|
return _fitBounds.default;
|
|
32
30
|
}
|
|
33
31
|
});
|
|
34
32
|
Object.defineProperty(exports, "normalizeViewportProps", {
|
|
35
33
|
enumerable: true,
|
|
36
|
-
get: function
|
|
34
|
+
get: function () {
|
|
37
35
|
return _normalizeViewportProps.default;
|
|
38
36
|
}
|
|
39
37
|
});
|
|
40
38
|
Object.defineProperty(exports, "flyToViewport", {
|
|
41
39
|
enumerable: true,
|
|
42
|
-
get: function
|
|
40
|
+
get: function () {
|
|
43
41
|
return _flyToViewport.default;
|
|
44
42
|
}
|
|
45
43
|
});
|
|
46
44
|
Object.defineProperty(exports, "getFlyToDuration", {
|
|
47
45
|
enumerable: true,
|
|
48
|
-
get: function
|
|
46
|
+
get: function () {
|
|
49
47
|
return _flyToViewport.getFlyToDuration;
|
|
50
48
|
}
|
|
51
49
|
});
|
|
52
50
|
Object.defineProperty(exports, "lngLatToWorld", {
|
|
53
51
|
enumerable: true,
|
|
54
|
-
get: function
|
|
52
|
+
get: function () {
|
|
55
53
|
return _webMercatorUtils.lngLatToWorld;
|
|
56
54
|
}
|
|
57
55
|
});
|
|
58
56
|
Object.defineProperty(exports, "worldToLngLat", {
|
|
59
57
|
enumerable: true,
|
|
60
|
-
get: function
|
|
58
|
+
get: function () {
|
|
61
59
|
return _webMercatorUtils.worldToLngLat;
|
|
62
60
|
}
|
|
63
61
|
});
|
|
64
62
|
Object.defineProperty(exports, "worldToPixels", {
|
|
65
63
|
enumerable: true,
|
|
66
|
-
get: function
|
|
64
|
+
get: function () {
|
|
67
65
|
return _webMercatorUtils.worldToPixels;
|
|
68
66
|
}
|
|
69
67
|
});
|
|
70
68
|
Object.defineProperty(exports, "pixelsToWorld", {
|
|
71
69
|
enumerable: true,
|
|
72
|
-
get: function
|
|
70
|
+
get: function () {
|
|
73
71
|
return _webMercatorUtils.pixelsToWorld;
|
|
74
72
|
}
|
|
75
73
|
});
|
|
76
74
|
Object.defineProperty(exports, "zoomToScale", {
|
|
77
75
|
enumerable: true,
|
|
78
|
-
get: function
|
|
76
|
+
get: function () {
|
|
79
77
|
return _webMercatorUtils.zoomToScale;
|
|
80
78
|
}
|
|
81
79
|
});
|
|
82
80
|
Object.defineProperty(exports, "scaleToZoom", {
|
|
83
81
|
enumerable: true,
|
|
84
|
-
get: function
|
|
82
|
+
get: function () {
|
|
85
83
|
return _webMercatorUtils.scaleToZoom;
|
|
86
84
|
}
|
|
87
85
|
});
|
|
88
86
|
Object.defineProperty(exports, "altitudeToFovy", {
|
|
89
87
|
enumerable: true,
|
|
90
|
-
get: function
|
|
88
|
+
get: function () {
|
|
91
89
|
return _webMercatorUtils.altitudeToFovy;
|
|
92
90
|
}
|
|
93
91
|
});
|
|
94
92
|
Object.defineProperty(exports, "fovyToAltitude", {
|
|
95
93
|
enumerable: true,
|
|
96
|
-
get: function
|
|
94
|
+
get: function () {
|
|
97
95
|
return _webMercatorUtils.fovyToAltitude;
|
|
98
96
|
}
|
|
99
97
|
});
|
|
100
98
|
Object.defineProperty(exports, "getMeterZoom", {
|
|
101
99
|
enumerable: true,
|
|
102
|
-
get: function
|
|
100
|
+
get: function () {
|
|
103
101
|
return _webMercatorUtils.getMeterZoom;
|
|
104
102
|
}
|
|
105
103
|
});
|
|
106
104
|
Object.defineProperty(exports, "getDistanceScales", {
|
|
107
105
|
enumerable: true,
|
|
108
|
-
get: function
|
|
106
|
+
get: function () {
|
|
109
107
|
return _webMercatorUtils.getDistanceScales;
|
|
110
108
|
}
|
|
111
109
|
});
|
|
112
110
|
Object.defineProperty(exports, "addMetersToLngLat", {
|
|
113
111
|
enumerable: true,
|
|
114
|
-
get: function
|
|
112
|
+
get: function () {
|
|
115
113
|
return _webMercatorUtils.addMetersToLngLat;
|
|
116
114
|
}
|
|
117
115
|
});
|
|
118
116
|
Object.defineProperty(exports, "getViewMatrix", {
|
|
119
117
|
enumerable: true,
|
|
120
|
-
get: function
|
|
118
|
+
get: function () {
|
|
121
119
|
return _webMercatorUtils.getViewMatrix;
|
|
122
120
|
}
|
|
123
121
|
});
|
|
124
122
|
Object.defineProperty(exports, "getProjectionMatrix", {
|
|
125
123
|
enumerable: true,
|
|
126
|
-
get: function
|
|
124
|
+
get: function () {
|
|
127
125
|
return _webMercatorUtils.getProjectionMatrix;
|
|
128
126
|
}
|
|
129
127
|
});
|
|
130
128
|
Object.defineProperty(exports, "getProjectionParameters", {
|
|
131
129
|
enumerable: true,
|
|
132
|
-
get: function
|
|
130
|
+
get: function () {
|
|
133
131
|
return _webMercatorUtils.getProjectionParameters;
|
|
134
132
|
}
|
|
135
133
|
});
|
|
@@ -146,7 +144,7 @@ var _flyToViewport = _interopRequireWildcard(require("./fly-to-viewport"));
|
|
|
146
144
|
|
|
147
145
|
var _webMercatorUtils = require("./web-mercator-utils");
|
|
148
146
|
|
|
149
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function
|
|
147
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
150
148
|
|
|
151
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null ||
|
|
149
|
+
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; }
|
|
152
150
|
//# sourceMappingURL=index.js.map
|
package/dist/es5/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/index.
|
|
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 lngLatToWorld,\n worldToLngLat,\n worldToPixels,\n pixelsToWorld,\n zoomToScale,\n scaleToZoom,\n altitudeToFovy,\n fovyToAltitude,\n getMeterZoom,\n getDistanceScales,\n addMetersToLngLat,\n getViewMatrix,\n getProjectionMatrix,\n getProjectionParameters\n} from './web-mercator-utils';\n"],"file":"index.js"}
|
package/dist/es5/math-utils.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
@@ -11,24 +9,20 @@ exports.mod = mod;
|
|
|
11
9
|
exports.lerp = lerp;
|
|
12
10
|
exports.log2 = void 0;
|
|
13
11
|
|
|
14
|
-
var
|
|
15
|
-
|
|
16
|
-
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); }
|
|
17
|
-
|
|
18
|
-
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; }
|
|
12
|
+
var _vec = require("gl-matrix/vec4");
|
|
19
13
|
|
|
20
14
|
function createMat4() {
|
|
21
15
|
return [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1];
|
|
22
16
|
}
|
|
23
17
|
|
|
24
18
|
function transformVector(matrix, vector) {
|
|
25
|
-
|
|
26
|
-
|
|
19
|
+
const result = (0, _vec.transformMat4)([], vector, matrix);
|
|
20
|
+
(0, _vec.scale)(result, result, 1 / result[3]);
|
|
27
21
|
return result;
|
|
28
22
|
}
|
|
29
23
|
|
|
30
24
|
function mod(value, divisor) {
|
|
31
|
-
|
|
25
|
+
const modulus = value % divisor;
|
|
32
26
|
return modulus < 0 ? divisor + modulus : modulus;
|
|
33
27
|
}
|
|
34
28
|
|
|
@@ -40,6 +34,6 @@ function ieLog2(x) {
|
|
|
40
34
|
return Math.log(x) * Math.LOG2E;
|
|
41
35
|
}
|
|
42
36
|
|
|
43
|
-
|
|
37
|
+
const log2 = Math.log2 || ieLog2;
|
|
44
38
|
exports.log2 = log2;
|
|
45
39
|
//# sourceMappingURL=math-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/math-utils.
|
|
1
|
+
{"version":3,"sources":["../../src/math-utils.ts"],"names":["createMat4","transformVector","matrix","vector","result","mod","value","divisor","modulus","lerp","start","end","step","ieLog2","x","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,EAAiCC,MAAjC,EAAyC;AAC9C,QAAMC,MAAM,GAAG,wBAAc,EAAd,EAAkBD,MAAlB,EAA0BD,MAA1B,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,QAAMC,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;;AAED,SAASG,MAAT,CAAgBC,CAAhB,EAAmC;AACjC,SAAOC,IAAI,CAACC,GAAL,CAASF,CAAT,IAAcC,IAAI,CAACE,KAA1B;AACD;;AAEM,MAAMC,IAAI,GAAGH,IAAI,CAACG,IAAL,IAAaL,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, vector) {\n const result = transformMat4([], 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\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"}
|
|
@@ -9,18 +9,20 @@ var _webMercatorUtils = require("./web-mercator-utils");
|
|
|
9
9
|
|
|
10
10
|
var _mathUtils = require("./math-utils");
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
function normalizeViewportProps(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
12
|
+
const TILE_SIZE = 512;
|
|
13
|
+
|
|
14
|
+
function normalizeViewportProps(props) {
|
|
15
|
+
const {
|
|
16
|
+
width,
|
|
17
|
+
height,
|
|
18
|
+
pitch = 0
|
|
19
|
+
} = props;
|
|
20
|
+
let {
|
|
21
|
+
longitude,
|
|
22
|
+
latitude,
|
|
23
|
+
zoom,
|
|
24
|
+
bearing = 0
|
|
25
|
+
} = props;
|
|
24
26
|
|
|
25
27
|
if (longitude < -180 || longitude > 180) {
|
|
26
28
|
longitude = (0, _mathUtils.mod)(longitude + 180, 360) - 180;
|
|
@@ -30,19 +32,19 @@ function normalizeViewportProps(_ref) {
|
|
|
30
32
|
bearing = (0, _mathUtils.mod)(bearing + 180, 360) - 180;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
|
|
35
|
+
const minZoom = (0, _mathUtils.log2)(height / TILE_SIZE);
|
|
34
36
|
|
|
35
37
|
if (zoom <= minZoom) {
|
|
36
38
|
zoom = minZoom;
|
|
37
39
|
latitude = 0;
|
|
38
40
|
} else {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
+
const halfHeightPixels = height / 2 / Math.pow(2, zoom);
|
|
42
|
+
const minLatitude = (0, _webMercatorUtils.worldToLngLat)([0, halfHeightPixels])[1];
|
|
41
43
|
|
|
42
44
|
if (latitude < minLatitude) {
|
|
43
45
|
latitude = minLatitude;
|
|
44
46
|
} else {
|
|
45
|
-
|
|
47
|
+
const maxLatitude = (0, _webMercatorUtils.worldToLngLat)([0, TILE_SIZE - halfHeightPixels])[1];
|
|
46
48
|
|
|
47
49
|
if (latitude > maxLatitude) {
|
|
48
50
|
latitude = maxLatitude;
|
|
@@ -51,13 +53,13 @@ function normalizeViewportProps(_ref) {
|
|
|
51
53
|
}
|
|
52
54
|
|
|
53
55
|
return {
|
|
54
|
-
width
|
|
55
|
-
height
|
|
56
|
-
longitude
|
|
57
|
-
latitude
|
|
58
|
-
zoom
|
|
59
|
-
pitch
|
|
60
|
-
bearing
|
|
56
|
+
width,
|
|
57
|
+
height,
|
|
58
|
+
longitude,
|
|
59
|
+
latitude,
|
|
60
|
+
zoom,
|
|
61
|
+
pitch,
|
|
62
|
+
bearing
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
65
|
//# sourceMappingURL=normalize-viewport-props.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/normalize-viewport-props.
|
|
1
|
+
{"version":3,"sources":["../../src/normalize-viewport-props.ts"],"names":["TILE_SIZE","normalizeViewportProps","props","width","height","pitch","longitude","latitude","zoom","bearing","minZoom","halfHeightPixels","Math","pow","minLatitude","maxLatitude"],"mappings":";;;;;;;AAAA;;AACA;;AAGA,MAAMA,SAAS,GAAG,GAAlB;;AAkBe,SAASC,sBAAT,CAAgCC,KAAhC,EAAqE;AAClF,QAAM;AAACC,IAAAA,KAAD;AAAQC,IAAAA,MAAR;AAAgBC,IAAAA,KAAK,GAAG;AAAxB,MAA6BH,KAAnC;AACA,MAAI;AAACI,IAAAA,SAAD;AAAYC,IAAAA,QAAZ;AAAsBC,IAAAA,IAAtB;AAA4BC,IAAAA,OAAO,GAAG;AAAtC,MAA2CP,KAA/C;;AAGA,MAAII,SAAS,GAAG,CAAC,GAAb,IAAoBA,SAAS,GAAG,GAApC,EAAyC;AACvCA,IAAAA,SAAS,GAAG,oBAAIA,SAAS,GAAG,GAAhB,EAAqB,GAArB,IAA4B,GAAxC;AACD;;AACD,MAAIG,OAAO,GAAG,CAAC,GAAX,IAAkBA,OAAO,GAAG,GAAhC,EAAqC;AACnCA,IAAAA,OAAO,GAAG,oBAAIA,OAAO,GAAG,GAAd,EAAmB,GAAnB,IAA0B,GAApC;AACD;;AAGD,QAAMC,OAAO,GAAG,qBAAKN,MAAM,GAAGJ,SAAd,CAAhB;;AACA,MAAIQ,IAAI,IAAIE,OAAZ,EAAqB;AACnBF,IAAAA,IAAI,GAAGE,OAAP;AACAH,IAAAA,QAAQ,GAAG,CAAX;AACD,GAHD,MAGO;AAEL,UAAMI,gBAAgB,GAAGP,MAAM,GAAG,CAAT,GAAaQ,IAAI,CAACC,GAAL,CAAS,CAAT,EAAYL,IAAZ,CAAtC;AACA,UAAMM,WAAW,GAAG,qCAAc,CAAC,CAAD,EAAIH,gBAAJ,CAAd,EAAqC,CAArC,CAApB;;AACA,QAAIJ,QAAQ,GAAGO,WAAf,EAA4B;AAC1BP,MAAAA,QAAQ,GAAGO,WAAX;AACD,KAFD,MAEO;AACL,YAAMC,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,KAAD;AAAQC,IAAAA,MAAR;AAAgBE,IAAAA,SAAhB;AAA2BC,IAAAA,QAA3B;AAAqCC,IAAAA,IAArC;AAA2CH,IAAAA,KAA3C;AAAkDI,IAAAA;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 */\ntype 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"}
|