@antv/l7-map 2.21.0 → 2.21.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/es/camera.js +595 -674
  2. package/es/earthmap.js +313 -276
  3. package/es/geo/edge_insets.js +57 -72
  4. package/es/geo/lng_lat.js +50 -64
  5. package/es/geo/lng_lat_bounds.js +101 -137
  6. package/es/geo/mercator.js +23 -35
  7. package/es/geo/point.js +150 -221
  8. package/es/geo/simple.js +22 -34
  9. package/es/geo/transform.js +839 -905
  10. package/es/handler/blockable_map_event.js +46 -66
  11. package/es/handler/box_zoom.js +125 -143
  12. package/es/handler/click_zoom.js +37 -51
  13. package/es/handler/events/event.js +11 -9
  14. package/es/handler/events/map_mouse_event.js +39 -54
  15. package/es/handler/events/map_touch_event.js +54 -73
  16. package/es/handler/events/map_wheel_event.js +22 -38
  17. package/es/handler/events/render_event.js +6 -23
  18. package/es/handler/handler_inertia.js +98 -113
  19. package/es/handler/handler_manager.js +349 -437
  20. package/es/handler/handler_util.js +2 -2
  21. package/es/handler/keyboard.js +98 -110
  22. package/es/handler/map_event.js +81 -117
  23. package/es/handler/mouse/mouse_handler.js +81 -100
  24. package/es/handler/mouse/mousepan_handler.js +16 -39
  25. package/es/handler/mouse/mousepitch_hander.js +18 -40
  26. package/es/handler/mouse/mouserotate_hander.js +18 -40
  27. package/es/handler/mouse/util.js +7 -6
  28. package/es/handler/scroll_zoom.js +221 -231
  29. package/es/handler/shim/dblclick_zoom.js +36 -47
  30. package/es/handler/shim/drag_pan.js +41 -50
  31. package/es/handler/shim/drag_rotate.js +38 -48
  32. package/es/handler/shim/touch_zoom_rotate.js +68 -79
  33. package/es/handler/tap/single_tap_recognizer.js +60 -80
  34. package/es/handler/tap/tap_drag_zoom.js +72 -89
  35. package/es/handler/tap/tap_recognizer.js +37 -45
  36. package/es/handler/tap/tap_zoom.js +67 -95
  37. package/es/handler/touch/touch_pan.js +77 -96
  38. package/es/handler/touch/touch_pitch.js +61 -79
  39. package/es/handler/touch/touch_rotate.js +47 -67
  40. package/es/handler/touch/touch_zoom.js +29 -46
  41. package/es/handler/touch/two_touch.js +79 -104
  42. package/es/hash.js +75 -88
  43. package/es/map.js +318 -284
  44. package/es/util.js +18 -37
  45. package/es/utils/Aabb.js +60 -100
  46. package/es/utils/dom.js +32 -55
  47. package/es/utils/performance.js +25 -29
  48. package/es/utils/primitives.js +33 -43
  49. package/es/utils/task_queue.js +47 -76
  50. package/lib/camera.d.ts +86 -0
  51. package/lib/camera.js +597 -672
  52. package/lib/earthmap.d.ts +69 -0
  53. package/lib/earthmap.js +314 -276
  54. package/lib/geo/edge_insets.d.ts +54 -0
  55. package/lib/geo/edge_insets.js +58 -70
  56. package/lib/geo/lng_lat.d.ts +18 -0
  57. package/lib/geo/lng_lat.js +50 -62
  58. package/lib/geo/lng_lat_bounds.d.ts +25 -0
  59. package/lib/geo/lng_lat_bounds.js +102 -136
  60. package/lib/geo/mercator.d.ts +30 -0
  61. package/lib/geo/mercator.js +26 -37
  62. package/lib/geo/point.d.ts +40 -0
  63. package/lib/geo/point.js +151 -220
  64. package/lib/geo/simple.d.ts +30 -0
  65. package/lib/geo/simple.js +25 -36
  66. package/lib/geo/transform.d.ts +198 -0
  67. package/lib/geo/transform.js +844 -907
  68. package/lib/handler/IHandler.d.ts +34 -0
  69. package/lib/handler/blockable_map_event.d.ts +17 -0
  70. package/lib/handler/blockable_map_event.js +48 -65
  71. package/lib/handler/box_zoom.d.ts +59 -0
  72. package/lib/handler/box_zoom.js +126 -143
  73. package/lib/handler/click_zoom.d.ts +16 -0
  74. package/lib/handler/click_zoom.js +38 -50
  75. package/lib/handler/events/event.d.ts +4 -0
  76. package/lib/handler/events/event.js +12 -9
  77. package/lib/handler/events/index.d.ts +4 -0
  78. package/lib/handler/events/index.js +3 -3
  79. package/lib/handler/events/map_mouse_event.d.ts +34 -0
  80. package/lib/handler/events/map_mouse_event.js +41 -52
  81. package/lib/handler/events/map_touch_event.d.ts +57 -0
  82. package/lib/handler/events/map_touch_event.js +56 -71
  83. package/lib/handler/events/map_wheel_event.d.ts +33 -0
  84. package/lib/handler/events/map_wheel_event.js +23 -37
  85. package/lib/handler/events/render_event.d.ts +5 -0
  86. package/lib/handler/events/render_event.js +7 -22
  87. package/lib/handler/handler_inertia.d.ts +23 -0
  88. package/lib/handler/handler_inertia.js +102 -112
  89. package/lib/handler/handler_manager.d.ts +61 -0
  90. package/lib/handler/handler_manager.js +351 -437
  91. package/lib/handler/handler_util.d.ts +4 -0
  92. package/lib/handler/handler_util.js +2 -2
  93. package/lib/handler/keyboard.d.ts +36 -0
  94. package/lib/handler/keyboard.js +98 -110
  95. package/lib/handler/map_event.d.ts +29 -0
  96. package/lib/handler/map_event.js +83 -116
  97. package/lib/handler/mouse/index.d.ts +4 -0
  98. package/lib/handler/mouse/index.js +3 -3
  99. package/lib/handler/mouse/mouse_handler.d.ts +22 -0
  100. package/lib/handler/mouse/mouse_handler.js +83 -99
  101. package/lib/handler/mouse/mousepan_handler.d.ts +10 -0
  102. package/lib/handler/mouse/mousepan_handler.js +19 -38
  103. package/lib/handler/mouse/mousepitch_hander.d.ts +9 -0
  104. package/lib/handler/mouse/mousepitch_hander.js +21 -39
  105. package/lib/handler/mouse/mouserotate_hander.d.ts +9 -0
  106. package/lib/handler/mouse/mouserotate_hander.js +21 -39
  107. package/lib/handler/mouse/util.d.ts +6 -0
  108. package/lib/handler/mouse/util.js +7 -7
  109. package/lib/handler/scroll_zoom.d.ts +93 -0
  110. package/lib/handler/scroll_zoom.js +221 -231
  111. package/lib/handler/shim/dblclick_zoom.d.ts +40 -0
  112. package/lib/handler/shim/dblclick_zoom.js +37 -46
  113. package/lib/handler/shim/drag_pan.d.ts +61 -0
  114. package/lib/handler/shim/drag_pan.js +42 -49
  115. package/lib/handler/shim/drag_rotate.d.ts +46 -0
  116. package/lib/handler/shim/drag_rotate.js +39 -47
  117. package/lib/handler/shim/touch_zoom_rotate.d.ts +70 -0
  118. package/lib/handler/shim/touch_zoom_rotate.js +69 -78
  119. package/lib/handler/tap/single_tap_recognizer.d.ts +20 -0
  120. package/lib/handler/tap/single_tap_recognizer.js +63 -79
  121. package/lib/handler/tap/tap_drag_zoom.d.ts +22 -0
  122. package/lib/handler/tap/tap_drag_zoom.js +74 -88
  123. package/lib/handler/tap/tap_recognizer.d.ts +17 -0
  124. package/lib/handler/tap/tap_recognizer.js +41 -47
  125. package/lib/handler/tap/tap_zoom.d.ts +22 -0
  126. package/lib/handler/tap/tap_zoom.js +69 -94
  127. package/lib/handler/touch/index.d.ts +5 -0
  128. package/lib/handler/touch/index.js +4 -4
  129. package/lib/handler/touch/touch_pan.d.ts +30 -0
  130. package/lib/handler/touch/touch_pan.js +79 -95
  131. package/lib/handler/touch/touch_pitch.d.ts +13 -0
  132. package/lib/handler/touch/touch_pitch.js +64 -78
  133. package/lib/handler/touch/touch_rotate.d.ts +12 -0
  134. package/lib/handler/touch/touch_rotate.js +50 -66
  135. package/lib/handler/touch/touch_zoom.d.ts +12 -0
  136. package/lib/handler/touch/touch_zoom.js +32 -45
  137. package/lib/handler/touch/two_touch.d.ts +23 -0
  138. package/lib/handler/touch/two_touch.js +81 -103
  139. package/lib/hash.d.ts +14 -0
  140. package/lib/hash.js +75 -88
  141. package/lib/index.d.ts +4 -0
  142. package/lib/index.js +4 -4
  143. package/lib/interface.d.ts +34 -0
  144. package/lib/map.d.ts +70 -0
  145. package/lib/map.js +319 -284
  146. package/lib/util.d.ts +25 -0
  147. package/lib/util.js +20 -36
  148. package/lib/utils/Aabb.d.ts +12 -0
  149. package/lib/utils/Aabb.js +61 -99
  150. package/lib/utils/dom.d.ts +4 -0
  151. package/lib/utils/dom.js +34 -55
  152. package/lib/utils/performance.d.ts +17 -0
  153. package/lib/utils/performance.js +25 -29
  154. package/lib/utils/primitives.d.ts +6 -0
  155. package/lib/utils/primitives.js +34 -42
  156. package/lib/utils/task_queue.d.ts +13 -0
  157. package/lib/utils/task_queue.js +47 -76
  158. package/package.json +25 -32
@@ -1,13 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = exports.EXTENT = void 0;
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
9
  var _glMatrix = require("gl-matrix");
12
10
  var _point = _interopRequireDefault(require("../geo/point"));
13
11
  var _util = require("../util");
@@ -15,15 +13,205 @@ var _edge_insets = _interopRequireDefault(require("./edge_insets"));
15
13
  var _lng_lat = _interopRequireDefault(require("./lng_lat"));
16
14
  var _lng_lat_bounds = _interopRequireDefault(require("./lng_lat_bounds"));
17
15
  var _mercator = _interopRequireWildcard(require("./mercator"));
18
- function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
19
- function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
- function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
21
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
22
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; } // @ts-ignore
23
- var EXTENT = exports.EXTENT = 8192;
24
- var Transform = exports.default = /*#__PURE__*/function () {
25
- function Transform(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies) {
26
- (0, _classCallCheck2.default)(this, Transform);
16
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
17
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
18
+ // @ts-ignore
19
+
20
+ const EXTENT = exports.EXTENT = 8192;
21
+ class Transform {
22
+ get minZoom() {
23
+ return this._minZoom;
24
+ }
25
+ set minZoom(zoom) {
26
+ if (this._minZoom === zoom) {
27
+ return;
28
+ }
29
+ this._minZoom = zoom;
30
+ this.zoom = Math.max(this.zoom, zoom);
31
+ }
32
+ get maxZoom() {
33
+ return this._maxZoom;
34
+ }
35
+ set maxZoom(zoom) {
36
+ if (this._maxZoom === zoom) {
37
+ return;
38
+ }
39
+ this._maxZoom = zoom;
40
+ this.zoom = Math.min(this.zoom, zoom);
41
+ }
42
+ get minPitch() {
43
+ return this._minPitch;
44
+ }
45
+ set minPitch(pitch) {
46
+ if (this._minPitch === pitch) {
47
+ return;
48
+ }
49
+ this._minPitch = pitch;
50
+ this._pitch = Math.max(this._pitch, pitch);
51
+ }
52
+ get maxPitch() {
53
+ return this._maxPitch;
54
+ }
55
+ set maxPitch(pitch) {
56
+ if (this._maxPitch === pitch) {
57
+ return;
58
+ }
59
+ this._maxPitch = pitch;
60
+ this._pitch = Math.min(this._pitch, pitch);
61
+ }
62
+ get renderWorldCopies() {
63
+ return this._renderWorldCopies;
64
+ }
65
+ set renderWorldCopies(renderWorldCopies) {
66
+ if (renderWorldCopies === undefined) {
67
+ renderWorldCopies = true;
68
+ } else if (renderWorldCopies === null) {
69
+ renderWorldCopies = false;
70
+ }
71
+ this._renderWorldCopies = renderWorldCopies;
72
+ }
73
+ get worldSize() {
74
+ return this.tileSize * this.scale;
75
+ }
76
+ get centerOffset() {
77
+ return this.centerPoint._sub(this.size._div(2));
78
+ }
79
+ get size() {
80
+ return new _point.default(this.width, this.height);
81
+ }
82
+ get bearing() {
83
+ return -this.angle / Math.PI * 180;
84
+ }
85
+ set bearing(bearing) {
86
+ const b = -(0, _util.wrap)(bearing, -180, 180) * Math.PI / 180;
87
+ if (this.angle === b) {
88
+ return;
89
+ }
90
+ this.unmodified = false;
91
+ this.angle = b;
92
+ this.calcMatrices();
93
+
94
+ // 2x2 matrix for rotating points
95
+ this.rotationMatrix = _glMatrix.mat2.create();
96
+ _glMatrix.mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);
97
+ }
98
+ get pitch() {
99
+ return this._pitch / Math.PI * 180;
100
+ }
101
+ set pitch(pitch) {
102
+ const p = (0, _util.clamp)(pitch, this._minPitch, this._maxPitch) / 180 * Math.PI;
103
+ if (this._pitch === p) {
104
+ return;
105
+ }
106
+ this.unmodified = false;
107
+ this._pitch = p;
108
+ this.calcMatrices();
109
+ }
110
+ get fov() {
111
+ return this._fov / Math.PI * 180;
112
+ }
113
+ set fov(fov) {
114
+ fov = Math.max(0.01, Math.min(60, fov));
115
+ if (this._fov === fov) {
116
+ return;
117
+ }
118
+ this.unmodified = false;
119
+ this._fov = fov / 180 * Math.PI;
120
+ this.calcMatrices();
121
+ }
122
+ get zoom() {
123
+ return this._zoom;
124
+ }
125
+ set zoom(zoom) {
126
+ const z = Math.min(Math.max(zoom, this._minZoom), this._maxZoom);
127
+ if (this._zoom === z) {
128
+ return;
129
+ }
130
+ this.unmodified = false;
131
+ this._zoom = z;
132
+ this.scale = this.zoomScale(z);
133
+ this.tileZoom = Math.floor(z);
134
+ this.zoomFraction = z - this.tileZoom;
135
+ this.constrain();
136
+ this.calcMatrices();
137
+ }
138
+ get center() {
139
+ return this._center;
140
+ }
141
+ set center(center) {
142
+ if (center.lat === this._center.lat && center.lng === this._center.lng) {
143
+ return;
144
+ }
145
+ this.unmodified = false;
146
+ this._center = center;
147
+ this.constrain();
148
+ this.calcMatrices();
149
+ }
150
+ get padding() {
151
+ return this.edgeInsets.toJSON();
152
+ }
153
+ set padding(padding) {
154
+ if (this.edgeInsets.equals(padding)) {
155
+ return;
156
+ }
157
+ this.unmodified = false;
158
+ // Update edge-insets inplace
159
+ this.edgeInsets.interpolate(this.edgeInsets, padding, 1);
160
+ this.calcMatrices();
161
+ }
162
+
163
+ /**
164
+ * The center of the screen in pixels with the top-left corner being (0,0)
165
+ * and +y axis pointing downwards. This accounts for padding.
166
+ *
167
+ * @readonly
168
+ * @type {Point}
169
+ * @memberof Transform
170
+ */
171
+ get centerPoint() {
172
+ return this.edgeInsets.getCenter(this.width, this.height);
173
+ }
174
+ get point() {
175
+ return this.project(this.center);
176
+ }
177
+ constructor(minZoom, maxZoom, minPitch, maxPitch, renderWorldCopies) {
178
+ (0, _defineProperty2.default)(this, "tileSize", void 0);
179
+ (0, _defineProperty2.default)(this, "tileZoom", void 0);
180
+ (0, _defineProperty2.default)(this, "lngRange", void 0);
181
+ (0, _defineProperty2.default)(this, "latRange", void 0);
182
+ (0, _defineProperty2.default)(this, "maxValidLatitude", void 0);
183
+ (0, _defineProperty2.default)(this, "scale", void 0);
184
+ (0, _defineProperty2.default)(this, "width", void 0);
185
+ (0, _defineProperty2.default)(this, "height", void 0);
186
+ (0, _defineProperty2.default)(this, "angle", void 0);
187
+ (0, _defineProperty2.default)(this, "rotationMatrix", void 0);
188
+ (0, _defineProperty2.default)(this, "pixelsToGLUnits", void 0);
189
+ (0, _defineProperty2.default)(this, "cameraToCenterDistance", void 0);
190
+ (0, _defineProperty2.default)(this, "mercatorMatrix", void 0);
191
+ (0, _defineProperty2.default)(this, "projMatrix", void 0);
192
+ (0, _defineProperty2.default)(this, "invProjMatrix", void 0);
193
+ (0, _defineProperty2.default)(this, "alignedProjMatrix", void 0);
194
+ (0, _defineProperty2.default)(this, "pixelMatrix", void 0);
195
+ (0, _defineProperty2.default)(this, "pixelMatrixInverse", void 0);
196
+ (0, _defineProperty2.default)(this, "glCoordMatrix", void 0);
197
+ (0, _defineProperty2.default)(this, "labelPlaneMatrix", void 0);
198
+ // tslint:disable:variable-name
199
+ (0, _defineProperty2.default)(this, "_fov", void 0);
200
+ (0, _defineProperty2.default)(this, "_pitch", void 0);
201
+ (0, _defineProperty2.default)(this, "_zoom", void 0);
202
+ (0, _defineProperty2.default)(this, "_renderWorldCopies", void 0);
203
+ (0, _defineProperty2.default)(this, "_minZoom", void 0);
204
+ (0, _defineProperty2.default)(this, "_maxZoom", void 0);
205
+ (0, _defineProperty2.default)(this, "_minPitch", void 0);
206
+ (0, _defineProperty2.default)(this, "_maxPitch", void 0);
207
+ (0, _defineProperty2.default)(this, "_center", void 0);
208
+ // tslint:enable
209
+ (0, _defineProperty2.default)(this, "zoomFraction", void 0);
210
+ (0, _defineProperty2.default)(this, "unmodified", void 0);
211
+ (0, _defineProperty2.default)(this, "edgeInsets", void 0);
212
+ (0, _defineProperty2.default)(this, "constraining", void 0);
213
+ (0, _defineProperty2.default)(this, "posMatrixCache", void 0);
214
+ (0, _defineProperty2.default)(this, "alignedPosMatrixCache", void 0);
27
215
  this.tileSize = 512; // constant
28
216
  this.maxValidLatitude = 85.051129; // constant
29
217
 
@@ -45,925 +233,674 @@ var Transform = exports.default = /*#__PURE__*/function () {
45
233
  this.posMatrixCache = {};
46
234
  this.alignedPosMatrixCache = {};
47
235
  }
48
- (0, _createClass2.default)(Transform, [{
49
- key: "minZoom",
50
- get: function get() {
51
- return this._minZoom;
52
- },
53
- set: function set(zoom) {
54
- if (this._minZoom === zoom) {
55
- return;
56
- }
57
- this._minZoom = zoom;
58
- this.zoom = Math.max(this.zoom, zoom);
59
- }
60
- }, {
61
- key: "maxZoom",
62
- get: function get() {
63
- return this._maxZoom;
64
- },
65
- set: function set(zoom) {
66
- if (this._maxZoom === zoom) {
67
- return;
68
- }
69
- this._maxZoom = zoom;
70
- this.zoom = Math.min(this.zoom, zoom);
71
- }
72
- }, {
73
- key: "minPitch",
74
- get: function get() {
75
- return this._minPitch;
76
- },
77
- set: function set(pitch) {
78
- if (this._minPitch === pitch) {
79
- return;
80
- }
81
- this._minPitch = pitch;
82
- this._pitch = Math.max(this._pitch, pitch);
83
- }
84
- }, {
85
- key: "maxPitch",
86
- get: function get() {
87
- return this._maxPitch;
88
- },
89
- set: function set(pitch) {
90
- if (this._maxPitch === pitch) {
91
- return;
92
- }
93
- this._maxPitch = pitch;
94
- this._pitch = Math.min(this._pitch, pitch);
95
- }
96
- }, {
97
- key: "renderWorldCopies",
98
- get: function get() {
99
- return this._renderWorldCopies;
100
- },
101
- set: function set(renderWorldCopies) {
102
- if (renderWorldCopies === undefined) {
103
- renderWorldCopies = true;
104
- } else if (renderWorldCopies === null) {
105
- renderWorldCopies = false;
106
- }
107
- this._renderWorldCopies = renderWorldCopies;
108
- }
109
- }, {
110
- key: "worldSize",
111
- get: function get() {
112
- return this.tileSize * this.scale;
113
- }
114
- }, {
115
- key: "centerOffset",
116
- get: function get() {
117
- return this.centerPoint._sub(this.size._div(2));
118
- }
119
- }, {
120
- key: "size",
121
- get: function get() {
122
- return new _point.default(this.width, this.height);
123
- }
124
- }, {
125
- key: "bearing",
126
- get: function get() {
127
- return -this.angle / Math.PI * 180;
128
- },
129
- set: function set(bearing) {
130
- var b = -(0, _util.wrap)(bearing, -180, 180) * Math.PI / 180;
131
- if (this.angle === b) {
132
- return;
133
- }
134
- this.unmodified = false;
135
- this.angle = b;
136
- this.calcMatrices();
137
-
138
- // 2x2 matrix for rotating points
139
- this.rotationMatrix = _glMatrix.mat2.create();
140
- _glMatrix.mat2.rotate(this.rotationMatrix, this.rotationMatrix, this.angle);
141
- }
142
- }, {
143
- key: "pitch",
144
- get: function get() {
145
- return this._pitch / Math.PI * 180;
146
- },
147
- set: function set(pitch) {
148
- var p = (0, _util.clamp)(pitch, this._minPitch, this._maxPitch) / 180 * Math.PI;
149
- if (this._pitch === p) {
150
- return;
151
- }
152
- this.unmodified = false;
153
- this._pitch = p;
154
- this.calcMatrices();
155
- }
156
- }, {
157
- key: "fov",
158
- get: function get() {
159
- return this._fov / Math.PI * 180;
160
- },
161
- set: function set(fov) {
162
- fov = Math.max(0.01, Math.min(60, fov));
163
- if (this._fov === fov) {
164
- return;
165
- }
166
- this.unmodified = false;
167
- this._fov = fov / 180 * Math.PI;
168
- this.calcMatrices();
169
- }
170
- }, {
171
- key: "zoom",
172
- get: function get() {
173
- return this._zoom;
174
- },
175
- set: function set(zoom) {
176
- var z = Math.min(Math.max(zoom, this._minZoom), this._maxZoom);
177
- if (this._zoom === z) {
178
- return;
179
- }
180
- this.unmodified = false;
181
- this._zoom = z;
182
- this.scale = this.zoomScale(z);
183
- this.tileZoom = Math.floor(z);
184
- this.zoomFraction = z - this.tileZoom;
185
- this.constrain();
186
- this.calcMatrices();
187
- }
188
- }, {
189
- key: "center",
190
- get: function get() {
191
- return this._center;
192
- },
193
- set: function set(center) {
194
- if (center.lat === this._center.lat && center.lng === this._center.lng) {
195
- return;
196
- }
197
- this.unmodified = false;
198
- this._center = center;
199
- this.constrain();
200
- this.calcMatrices();
201
- }
202
- }, {
203
- key: "padding",
204
- get: function get() {
205
- return this.edgeInsets.toJSON();
206
- },
207
- set: function set(padding) {
208
- if (this.edgeInsets.equals(padding)) {
209
- return;
210
- }
211
- this.unmodified = false;
212
- // Update edge-insets inplace
213
- this.edgeInsets.interpolate(this.edgeInsets, padding, 1);
214
- this.calcMatrices();
215
- }
236
+ clone() {
237
+ const clone = new Transform(this._minZoom, this._maxZoom, this._minPitch, this._maxPitch, this._renderWorldCopies);
238
+ clone.tileSize = this.tileSize;
239
+ clone.latRange = this.latRange;
240
+ clone.width = this.width;
241
+ clone.height = this.height;
242
+ clone.center = this._center;
243
+ clone.zoom = this.zoom;
244
+ clone.angle = this.angle;
245
+ clone.fov = this._fov;
246
+ clone.pitch = this._pitch;
247
+ clone.unmodified = this.unmodified;
248
+ clone.edgeInsets = this.edgeInsets.clone();
249
+ clone.calcMatrices();
250
+ return clone;
251
+ }
216
252
 
217
- /**
218
- * The center of the screen in pixels with the top-left corner being (0,0)
219
- * and +y axis pointing downwards. This accounts for padding.
220
- *
221
- * @readonly
222
- * @type {Point}
223
- * @memberof Transform
224
- */
225
- }, {
226
- key: "centerPoint",
227
- get: function get() {
228
- return this.edgeInsets.getCenter(this.width, this.height);
229
- }
230
- }, {
231
- key: "point",
232
- get: function get() {
233
- return this.project(this.center);
234
- }
253
+ /**
254
+ * Returns if the padding params match
255
+ *
256
+ * @param {IPaddingOptions} padding
257
+ * @returns {boolean}
258
+ * @memberof Transform
259
+ */
260
+ isPaddingEqual(padding) {
261
+ return this.edgeInsets.equals(padding);
262
+ }
235
263
 
236
- // tslint:disable:variable-name
264
+ /**
265
+ * Helper method to upadte edge-insets inplace
266
+ *
267
+ * @param {IPaddingOptions} target
268
+ * @param {number} t
269
+ * @memberof Transform
270
+ */
271
+ interpolatePadding(start, target, t) {
272
+ this.unmodified = false;
273
+ this.edgeInsets.interpolate(start, target, t);
274
+ this.constrain();
275
+ this.calcMatrices();
276
+ }
237
277
 
238
- // tslint:enable
239
- }, {
240
- key: "clone",
241
- value: function clone() {
242
- var clone = new Transform(this._minZoom, this._maxZoom, this._minPitch, this._maxPitch, this._renderWorldCopies);
243
- clone.tileSize = this.tileSize;
244
- clone.latRange = this.latRange;
245
- clone.width = this.width;
246
- clone.height = this.height;
247
- clone.center = this._center;
248
- clone.zoom = this.zoom;
249
- clone.angle = this.angle;
250
- clone.fov = this._fov;
251
- clone.pitch = this._pitch;
252
- clone.unmodified = this.unmodified;
253
- clone.edgeInsets = this.edgeInsets.clone();
254
- clone.calcMatrices();
255
- return clone;
256
- }
278
+ /**
279
+ * Return a zoom level that will cover all tiles the transform
280
+ * @param {Object} options options
281
+ * @param {number} options.tileSize Tile size, expressed in screen pixels.
282
+ * @param {boolean} options.roundZoom Target zoom level. If true, the value will be rounded to the closest integer. Otherwise the value will be floored.
283
+ * @returns {number} zoom level An integer zoom level at which all tiles will be visible.
284
+ */
285
+ coveringZoomLevel(options) {
286
+ const z = (options.roundZoom ? Math.round : Math.floor)(this.zoom + this.scaleZoom(this.tileSize / options.tileSize));
287
+ // At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist.
288
+ return Math.max(0, z);
289
+ }
257
290
 
258
- /**
259
- * Returns if the padding params match
260
- *
261
- * @param {IPaddingOptions} padding
262
- * @returns {boolean}
263
- * @memberof Transform
264
- */
265
- }, {
266
- key: "isPaddingEqual",
267
- value: function isPaddingEqual(padding) {
268
- return this.edgeInsets.equals(padding);
291
+ /**
292
+ * Return any "wrapped" copies of a given tile coordinate that are visible
293
+ * in the current view.
294
+ *
295
+ * @private
296
+ */
297
+ // public getVisibleUnwrappedCoordinates(tileID: CanonicalTileID) {
298
+ // const result = [new UnwrappedTileID(0, tileID)];
299
+ // if (this._renderWorldCopies) {
300
+ // const utl = this.pointCoordinate(new Point(0, 0));
301
+ // const utr = this.pointCoordinate(new Point(this.width, 0));
302
+ // const ubl = this.pointCoordinate(new Point(this.width, this.height));
303
+ // const ubr = this.pointCoordinate(new Point(0, this.height));
304
+ // const w0 = Math.floor(Math.min(utl.x, utr.x, ubl.x, ubr.x));
305
+ // const w1 = Math.floor(Math.max(utl.x, utr.x, ubl.x, ubr.x));
306
+
307
+ // // Add an extra copy of the world on each side to properly render ImageSources and CanvasSources.
308
+ // // Both sources draw outside the tile boundaries of the tile that "contains them" so we need
309
+ // // to add extra copies on both sides in case offscreen tiles need to draw into on-screen ones.
310
+ // const extraWorldCopy = 1;
311
+
312
+ // for (let w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {
313
+ // if (w === 0) {
314
+ // continue;
315
+ // }
316
+ // result.push(new UnwrappedTileID(w, tileID));
317
+ // }
318
+ // }
319
+ // return result;
320
+ // }
321
+
322
+ /**
323
+ * Return all coordinates that could cover this transform for a covering
324
+ * zoom level.
325
+ * @param {Object} options
326
+ * @param {number} options.tileSize
327
+ * @param {number} options.minzoom
328
+ * @param {number} options.maxzoom
329
+ * @param {boolean} options.roundZoom
330
+ * @param {boolean} options.reparseOverscaled
331
+ * @param {boolean} options.renderWorldCopies
332
+ * @returns {Array<OverscaledTileID>} OverscaledTileIDs
333
+ * @private
334
+ */
335
+ // public coveringTiles(options: {
336
+ // tileSize: number;
337
+ // minzoom?: number;
338
+ // maxzoom?: number;
339
+ // roundZoom?: boolean;
340
+ // reparseOverscaled?: boolean;
341
+ // renderWorldCopies?: boolean;
342
+ // }): OverscaledTileID[] {
343
+ // let z = this.coveringZoomLevel(options);
344
+ // const actualZ = z;
345
+
346
+ // if (options.minzoom !== undefined && z < options.minzoom) {
347
+ // return [];
348
+ // }
349
+ // if (options.maxzoom !== undefined && z > options.maxzoom) {
350
+ // z = options.maxzoom;
351
+ // }
352
+
353
+ // const centerCoord = MercatorCoordinate.fromLngLat(this.center);
354
+ // const numTiles = Math.pow(2, z);
355
+ // const centerPoint = [numTiles * centerCoord.x, numTiles * centerCoord.y, 0];
356
+ // const cameraFrustum = Frustum.fromInvProjectionMatrix(
357
+ // this.invProjMatrix,
358
+ // this.worldSize,
359
+ // z,
360
+ // );
361
+
362
+ // // No change of LOD behavior for pitch lower than 60 and when there is no top padding: return only tile ids from the requested zoom level
363
+ // let minZoom = options.minzoom || 0;
364
+ // // Use 0.1 as an epsilon to avoid for explicit == 0.0 floating point checks
365
+ // if (this._pitch <= 60.0 && this.edgeInsets.top < 0.1) {
366
+ // minZoom = z;
367
+ // }
368
+
369
+ // // There should always be a certain number of maximum zoom level tiles surrounding the center location
370
+ // const radiusOfMaxLvlLodInTiles = 3;
371
+
372
+ // const newRootTile = (wrap: number): any => {
373
+ // return {
374
+ // // All tiles are on zero elevation plane => z difference is zero
375
+ // aabb: new Aabb(
376
+ // [wrap * numTiles, 0, 0],
377
+ // [(wrap + 1) * numTiles, numTiles, 0],
378
+ // ),
379
+ // zoom: 0,
380
+ // x: 0,
381
+ // y: 0,
382
+ // wrap,
383
+ // fullyVisible: false,
384
+ // };
385
+ // };
386
+
387
+ // // Do a depth-first traversal to find visible tiles and proper levels of detail
388
+ // const stack = [];
389
+ // const result = [];
390
+ // const maxZoom = z;
391
+ // const overscaledZ = options.reparseOverscaled ? actualZ : z;
392
+
393
+ // if (this._renderWorldCopies) {
394
+ // // Render copy of the globe thrice on both sides
395
+ // for (let i = 1; i <= 3; i++) {
396
+ // stack.push(newRootTile(-i));
397
+ // stack.push(newRootTile(i));
398
+ // }
399
+ // }
400
+
401
+ // stack.push(newRootTile(0));
402
+
403
+ // while (stack.length > 0) {
404
+ // const it = stack.pop();
405
+ // const x = it.x;
406
+ // const y = it.y;
407
+ // let fullyVisible = it.fullyVisible;
408
+
409
+ // // Visibility of a tile is not required if any of its ancestor if fully inside the frustum
410
+ // if (!fullyVisible) {
411
+ // const intersectResult = it.aabb.intersects(cameraFrustum);
412
+
413
+ // if (intersectResult === 0) {
414
+ // continue;
415
+ // }
416
+
417
+ // fullyVisible = intersectResult === 2;
418
+ // }
419
+
420
+ // const distanceX = it.aabb.distanceX(centerPoint);
421
+ // const distanceY = it.aabb.distanceY(centerPoint);
422
+ // const longestDim = Math.max(Math.abs(distanceX), Math.abs(distanceY));
423
+
424
+ // // We're using distance based heuristics to determine if a tile should be split into quadrants or not.
425
+ // // radiusOfMaxLvlLodInTiles defines that there's always a certain number of maxLevel tiles next to the map center.
426
+ // // Using the fact that a parent node in quadtree is twice the size of its children (per dimension)
427
+ // // we can define distance thresholds for each relative level:
428
+ // // f(k) = offset + 2 + 4 + 8 + 16 + ... + 2^k. This is the same as "offset+2^(k+1)-2"
429
+ // const distToSplit =
430
+ // radiusOfMaxLvlLodInTiles + (1 << (maxZoom - it.zoom)) - 2;
431
+
432
+ // // Have we reached the target depth or is the tile too far away to be any split further?
433
+ // if (
434
+ // it.zoom === maxZoom ||
435
+ // (longestDim > distToSplit && it.zoom >= minZoom)
436
+ // ) {
437
+ // result.push({
438
+ // tileID: new OverscaledTileID(
439
+ // it.zoom === maxZoom ? overscaledZ : it.zoom,
440
+ // it.wrap,
441
+ // it.zoom,
442
+ // x,
443
+ // y,
444
+ // ),
445
+ // distanceSq: vec2.sqrLen([
446
+ // centerPoint[0] - 0.5 - x,
447
+ // centerPoint[1] - 0.5 - y,
448
+ // ]),
449
+ // });
450
+ // continue;
451
+ // }
452
+
453
+ // for (let i = 0; i < 4; i++) {
454
+ // const childX = (x << 1) + (i % 2);
455
+ // const childY = (y << 1) + (i >> 1);
456
+
457
+ // stack.push({
458
+ // aabb: it.aabb.quadrant(i),
459
+ // zoom: it.zoom + 1,
460
+ // x: childX,
461
+ // y: childY,
462
+ // wrap: it.wrap,
463
+ // fullyVisible,
464
+ // });
465
+ // }
466
+ // }
467
+
468
+ // return result
469
+ // .sort((a, b) => a.distanceSq - b.distanceSq)
470
+ // .map((a) => a.tileID);
471
+ // }
472
+
473
+ resize(width, height) {
474
+ this.width = width;
475
+ this.height = height;
476
+ this.pixelsToGLUnits = [2 / width, -2 / height];
477
+ this.constrain();
478
+ this.calcMatrices();
479
+ }
480
+ zoomScale(zoom) {
481
+ return Math.pow(2, zoom);
482
+ }
483
+ scaleZoom(scale) {
484
+ return Math.log(scale) / Math.LN2;
485
+ }
486
+ project(lnglat) {
487
+ const lat = (0, _util.clamp)(lnglat.lat, -this.maxValidLatitude, this.maxValidLatitude);
488
+ return new _point.default((0, _mercator.mercatorXfromLng)(lnglat.lng) * this.worldSize, (0, _mercator.mercatorYfromLat)(lat) * this.worldSize);
489
+ }
490
+ unproject(point) {
491
+ return new _mercator.default(point.x / this.worldSize, point.y / this.worldSize).toLngLat();
492
+ }
493
+ setLocationAtPoint(lnglat, point) {
494
+ const a = this.pointCoordinate(point);
495
+ const b = this.pointCoordinate(this.centerPoint);
496
+ const loc = this.locationCoordinate(lnglat);
497
+ const newCenter = new _mercator.default(loc.x - (a.x - b.x), loc.y - (a.y - b.y));
498
+ this.center = this.coordinateLocation(newCenter);
499
+ if (this._renderWorldCopies) {
500
+ this.center = this.center.wrap();
269
501
  }
502
+ }
503
+ pointCoordinate(p) {
504
+ const targetZ = 0;
505
+ // since we don't know the correct projected z value for the point,
506
+ // unproject two points to get a line and then find the point on that
507
+ // line with z=0
508
+
509
+ const coord0 = new Float64Array([p.x, p.y, 0, 1]);
510
+ const coord1 = new Float64Array([p.x, p.y, 1, 1]);
511
+
512
+ // @ts-ignore
513
+ _glMatrix.vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);
514
+ // @ts-ignore
515
+ _glMatrix.vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);
516
+ const w0 = coord0[3];
517
+ const w1 = coord1[3];
518
+ const x0 = coord0[0] / w0;
519
+ const x1 = coord1[0] / w1;
520
+ const y0 = coord0[1] / w0;
521
+ const y1 = coord1[1] / w1;
522
+ const z0 = coord0[2] / w0;
523
+ const z1 = coord1[2] / w1;
524
+ const t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);
525
+ return new _mercator.default((0, _util.interpolate)(x0, x1, t) / this.worldSize, (0, _util.interpolate)(y0, y1, t) / this.worldSize);
526
+ }
270
527
 
271
- /**
272
- * Helper method to upadte edge-insets inplace
273
- *
274
- * @param {IPaddingOptions} target
275
- * @param {number} t
276
- * @memberof Transform
277
- */
278
- }, {
279
- key: "interpolatePadding",
280
- value: function interpolatePadding(start, target, t) {
281
- this.unmodified = false;
282
- this.edgeInsets.interpolate(start, target, t);
283
- this.constrain();
284
- this.calcMatrices();
285
- }
528
+ /**
529
+ * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
530
+ * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
531
+ * @returns {LngLatBounds} Returns a {@link LngLatBounds} object describing the map's geographical bounds.
532
+ */
533
+ getBounds() {
534
+ return new _lng_lat_bounds.default().extend(this.pointLocation(new _point.default(0, 0))).extend(this.pointLocation(new _point.default(this.width, 0))).extend(this.pointLocation(new _point.default(this.width, this.height))).extend(this.pointLocation(new _point.default(0, this.height)));
535
+ }
286
536
 
287
- /**
288
- * Return a zoom level that will cover all tiles the transform
289
- * @param {Object} options options
290
- * @param {number} options.tileSize Tile size, expressed in screen pixels.
291
- * @param {boolean} options.roundZoom Target zoom level. If true, the value will be rounded to the closest integer. Otherwise the value will be floored.
292
- * @returns {number} zoom level An integer zoom level at which all tiles will be visible.
293
- */
294
- }, {
295
- key: "coveringZoomLevel",
296
- value: function coveringZoomLevel(options) {
297
- var z = (options.roundZoom ? Math.round : Math.floor)(this.zoom + this.scaleZoom(this.tileSize / options.tileSize));
298
- // At negative zoom levels load tiles from z0 because negative tile zoom levels don't exist.
299
- return Math.max(0, z);
537
+ /**
538
+ * Returns the maximum geographical bounds the map is constrained to, or `null` if none set.
539
+ * @returns {LngLatBounds} {@link LngLatBounds}
540
+ */
541
+ getMaxBounds() {
542
+ if (!this.latRange || this.latRange.length !== 2 || !this.lngRange || this.lngRange.length !== 2) {
543
+ return null;
300
544
  }
545
+ return new _lng_lat_bounds.default([this.lngRange[0], this.latRange[0]], [this.lngRange[1], this.latRange[1]]);
546
+ }
301
547
 
302
- /**
303
- * Return any "wrapped" copies of a given tile coordinate that are visible
304
- * in the current view.
305
- *
306
- * @private
307
- */
308
- // public getVisibleUnwrappedCoordinates(tileID: CanonicalTileID) {
309
- // const result = [new UnwrappedTileID(0, tileID)];
310
- // if (this._renderWorldCopies) {
311
- // const utl = this.pointCoordinate(new Point(0, 0));
312
- // const utr = this.pointCoordinate(new Point(this.width, 0));
313
- // const ubl = this.pointCoordinate(new Point(this.width, this.height));
314
- // const ubr = this.pointCoordinate(new Point(0, this.height));
315
- // const w0 = Math.floor(Math.min(utl.x, utr.x, ubl.x, ubr.x));
316
- // const w1 = Math.floor(Math.max(utl.x, utr.x, ubl.x, ubr.x));
317
-
318
- // // Add an extra copy of the world on each side to properly render ImageSources and CanvasSources.
319
- // // Both sources draw outside the tile boundaries of the tile that "contains them" so we need
320
- // // to add extra copies on both sides in case offscreen tiles need to draw into on-screen ones.
321
- // const extraWorldCopy = 1;
322
-
323
- // for (let w = w0 - extraWorldCopy; w <= w1 + extraWorldCopy; w++) {
324
- // if (w === 0) {
325
- // continue;
326
- // }
327
- // result.push(new UnwrappedTileID(w, tileID));
328
- // }
329
- // }
330
- // return result;
331
- // }
332
-
333
- /**
334
- * Return all coordinates that could cover this transform for a covering
335
- * zoom level.
336
- * @param {Object} options
337
- * @param {number} options.tileSize
338
- * @param {number} options.minzoom
339
- * @param {number} options.maxzoom
340
- * @param {boolean} options.roundZoom
341
- * @param {boolean} options.reparseOverscaled
342
- * @param {boolean} options.renderWorldCopies
343
- * @returns {Array<OverscaledTileID>} OverscaledTileIDs
344
- * @private
345
- */
346
- // public coveringTiles(options: {
347
- // tileSize: number;
348
- // minzoom?: number;
349
- // maxzoom?: number;
350
- // roundZoom?: boolean;
351
- // reparseOverscaled?: boolean;
352
- // renderWorldCopies?: boolean;
353
- // }): OverscaledTileID[] {
354
- // let z = this.coveringZoomLevel(options);
355
- // const actualZ = z;
356
-
357
- // if (options.minzoom !== undefined && z < options.minzoom) {
358
- // return [];
359
- // }
360
- // if (options.maxzoom !== undefined && z > options.maxzoom) {
361
- // z = options.maxzoom;
362
- // }
363
-
364
- // const centerCoord = MercatorCoordinate.fromLngLat(this.center);
365
- // const numTiles = Math.pow(2, z);
366
- // const centerPoint = [numTiles * centerCoord.x, numTiles * centerCoord.y, 0];
367
- // const cameraFrustum = Frustum.fromInvProjectionMatrix(
368
- // this.invProjMatrix,
369
- // this.worldSize,
370
- // z,
371
- // );
372
-
373
- // // No change of LOD behavior for pitch lower than 60 and when there is no top padding: return only tile ids from the requested zoom level
374
- // let minZoom = options.minzoom || 0;
375
- // // Use 0.1 as an epsilon to avoid for explicit == 0.0 floating point checks
376
- // if (this._pitch <= 60.0 && this.edgeInsets.top < 0.1) {
377
- // minZoom = z;
378
- // }
379
-
380
- // // There should always be a certain number of maximum zoom level tiles surrounding the center location
381
- // const radiusOfMaxLvlLodInTiles = 3;
382
-
383
- // const newRootTile = (wrap: number): any => {
384
- // return {
385
- // // All tiles are on zero elevation plane => z difference is zero
386
- // aabb: new Aabb(
387
- // [wrap * numTiles, 0, 0],
388
- // [(wrap + 1) * numTiles, numTiles, 0],
389
- // ),
390
- // zoom: 0,
391
- // x: 0,
392
- // y: 0,
393
- // wrap,
394
- // fullyVisible: false,
395
- // };
396
- // };
397
-
398
- // // Do a depth-first traversal to find visible tiles and proper levels of detail
399
- // const stack = [];
400
- // const result = [];
401
- // const maxZoom = z;
402
- // const overscaledZ = options.reparseOverscaled ? actualZ : z;
403
-
404
- // if (this._renderWorldCopies) {
405
- // // Render copy of the globe thrice on both sides
406
- // for (let i = 1; i <= 3; i++) {
407
- // stack.push(newRootTile(-i));
408
- // stack.push(newRootTile(i));
409
- // }
410
- // }
411
-
412
- // stack.push(newRootTile(0));
413
-
414
- // while (stack.length > 0) {
415
- // const it = stack.pop();
416
- // const x = it.x;
417
- // const y = it.y;
418
- // let fullyVisible = it.fullyVisible;
419
-
420
- // // Visibility of a tile is not required if any of its ancestor if fully inside the frustum
421
- // if (!fullyVisible) {
422
- // const intersectResult = it.aabb.intersects(cameraFrustum);
423
-
424
- // if (intersectResult === 0) {
425
- // continue;
426
- // }
427
-
428
- // fullyVisible = intersectResult === 2;
429
- // }
430
-
431
- // const distanceX = it.aabb.distanceX(centerPoint);
432
- // const distanceY = it.aabb.distanceY(centerPoint);
433
- // const longestDim = Math.max(Math.abs(distanceX), Math.abs(distanceY));
434
-
435
- // // We're using distance based heuristics to determine if a tile should be split into quadrants or not.
436
- // // radiusOfMaxLvlLodInTiles defines that there's always a certain number of maxLevel tiles next to the map center.
437
- // // Using the fact that a parent node in quadtree is twice the size of its children (per dimension)
438
- // // we can define distance thresholds for each relative level:
439
- // // f(k) = offset + 2 + 4 + 8 + 16 + ... + 2^k. This is the same as "offset+2^(k+1)-2"
440
- // const distToSplit =
441
- // radiusOfMaxLvlLodInTiles + (1 << (maxZoom - it.zoom)) - 2;
442
-
443
- // // Have we reached the target depth or is the tile too far away to be any split further?
444
- // if (
445
- // it.zoom === maxZoom ||
446
- // (longestDim > distToSplit && it.zoom >= minZoom)
447
- // ) {
448
- // result.push({
449
- // tileID: new OverscaledTileID(
450
- // it.zoom === maxZoom ? overscaledZ : it.zoom,
451
- // it.wrap,
452
- // it.zoom,
453
- // x,
454
- // y,
455
- // ),
456
- // distanceSq: vec2.sqrLen([
457
- // centerPoint[0] - 0.5 - x,
458
- // centerPoint[1] - 0.5 - y,
459
- // ]),
460
- // });
461
- // continue;
462
- // }
463
-
464
- // for (let i = 0; i < 4; i++) {
465
- // const childX = (x << 1) + (i % 2);
466
- // const childY = (y << 1) + (i >> 1);
467
-
468
- // stack.push({
469
- // aabb: it.aabb.quadrant(i),
470
- // zoom: it.zoom + 1,
471
- // x: childX,
472
- // y: childY,
473
- // wrap: it.wrap,
474
- // fullyVisible,
475
- // });
476
- // }
477
- // }
478
-
479
- // return result
480
- // .sort((a, b) => a.distanceSq - b.distanceSq)
481
- // .map((a) => a.tileID);
482
- // }
483
- }, {
484
- key: "resize",
485
- value: function resize(width, height) {
486
- this.width = width;
487
- this.height = height;
488
- this.pixelsToGLUnits = [2 / width, -2 / height];
548
+ /**
549
+ * Sets or clears the map's geographical constraints.
550
+ * @param {LngLatBounds} bounds A {@link LngLatBounds} object describing the new geographic boundaries of the map.
551
+ */
552
+ setMaxBounds(bounds) {
553
+ if (bounds) {
554
+ this.lngRange = [bounds.getWest(), bounds.getEast()];
555
+ this.latRange = [bounds.getSouth(), bounds.getNorth()];
489
556
  this.constrain();
490
- this.calcMatrices();
491
- }
492
- }, {
493
- key: "zoomScale",
494
- value: function zoomScale(zoom) {
495
- return Math.pow(2, zoom);
496
- }
497
- }, {
498
- key: "scaleZoom",
499
- value: function scaleZoom(scale) {
500
- return Math.log(scale) / Math.LN2;
501
- }
502
- }, {
503
- key: "project",
504
- value: function project(lnglat) {
505
- var lat = (0, _util.clamp)(lnglat.lat, -this.maxValidLatitude, this.maxValidLatitude);
506
- return new _point.default((0, _mercator.mercatorXfromLng)(lnglat.lng) * this.worldSize, (0, _mercator.mercatorYfromLat)(lat) * this.worldSize);
507
- }
508
- }, {
509
- key: "unproject",
510
- value: function unproject(point) {
511
- return new _mercator.default(point.x / this.worldSize, point.y / this.worldSize).toLngLat();
512
- }
513
- }, {
514
- key: "setLocationAtPoint",
515
- value: function setLocationAtPoint(lnglat, point) {
516
- var a = this.pointCoordinate(point);
517
- var b = this.pointCoordinate(this.centerPoint);
518
- var loc = this.locationCoordinate(lnglat);
519
- var newCenter = new _mercator.default(loc.x - (a.x - b.x), loc.y - (a.y - b.y));
520
- this.center = this.coordinateLocation(newCenter);
521
- if (this._renderWorldCopies) {
522
- this.center = this.center.wrap();
523
- }
524
- }
525
- }, {
526
- key: "pointCoordinate",
527
- value: function pointCoordinate(p) {
528
- var targetZ = 0;
529
- // since we don't know the correct projected z value for the point,
530
- // unproject two points to get a line and then find the point on that
531
- // line with z=0
532
-
533
- var coord0 = new Float64Array([p.x, p.y, 0, 1]);
534
- var coord1 = new Float64Array([p.x, p.y, 1, 1]);
535
-
536
- // @ts-ignore
537
- _glMatrix.vec4.transformMat4(coord0, coord0, this.pixelMatrixInverse);
538
- // @ts-ignore
539
- _glMatrix.vec4.transformMat4(coord1, coord1, this.pixelMatrixInverse);
540
- var w0 = coord0[3];
541
- var w1 = coord1[3];
542
- var x0 = coord0[0] / w0;
543
- var x1 = coord1[0] / w1;
544
- var y0 = coord0[1] / w0;
545
- var y1 = coord1[1] / w1;
546
- var z0 = coord0[2] / w0;
547
- var z1 = coord1[2] / w1;
548
- var t = z0 === z1 ? 0 : (targetZ - z0) / (z1 - z0);
549
- return new _mercator.default((0, _util.interpolate)(x0, x1, t) / this.worldSize, (0, _util.interpolate)(y0, y1, t) / this.worldSize);
550
- }
551
-
552
- /**
553
- * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
554
- * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
555
- * @returns {LngLatBounds} Returns a {@link LngLatBounds} object describing the map's geographical bounds.
556
- */
557
- }, {
558
- key: "getBounds",
559
- value: function getBounds() {
560
- return new _lng_lat_bounds.default().extend(this.pointLocation(new _point.default(0, 0))).extend(this.pointLocation(new _point.default(this.width, 0))).extend(this.pointLocation(new _point.default(this.width, this.height))).extend(this.pointLocation(new _point.default(0, this.height)));
557
+ } else {
558
+ this.lngRange = undefined;
559
+ this.latRange = [-this.maxValidLatitude, this.maxValidLatitude];
561
560
  }
561
+ }
562
+ customLayerMatrix() {
563
+ return this.mercatorMatrix.slice();
564
+ }
565
+ maxPitchScaleFactor() {
566
+ // calcMatrices hasn't run yet
567
+ if (!this.pixelMatrixInverse) {
568
+ return 1;
569
+ }
570
+ const coord = this.pointCoordinate(new _point.default(0, 0));
571
+ const p = new Float32Array([coord.x * this.worldSize, coord.y * this.worldSize, 0, 1]);
572
+ const topPoint = _glMatrix.vec4.transformMat4(p, p, this.pixelMatrix);
573
+ return topPoint[3] / this.cameraToCenterDistance;
574
+ }
562
575
 
563
- /**
564
- * Returns the maximum geographical bounds the map is constrained to, or `null` if none set.
565
- * @returns {LngLatBounds} {@link LngLatBounds}
566
- */
567
- }, {
568
- key: "getMaxBounds",
569
- value: function getMaxBounds() {
570
- if (!this.latRange || this.latRange.length !== 2 || !this.lngRange || this.lngRange.length !== 2) {
571
- return null;
572
- }
573
- return new _lng_lat_bounds.default([this.lngRange[0], this.latRange[0]], [this.lngRange[1], this.latRange[1]]);
574
- }
576
+ /*
577
+ * The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`
578
+ * as the name for the location under the camera and on the surface of the earth (lng, lat, 0).
579
+ * `cameraPoint` is the projected position of the `cameraLocation`.
580
+ *
581
+ * This point is useful to us because only fill-extrusions that are between `cameraPoint` and
582
+ * the query point on the surface of the earth can extend and intersect the query.
583
+ *
584
+ * When the map is not pitched the `cameraPoint` is equivalent to the center of the map because
585
+ * the camera is right above the center of the map.
586
+ */
587
+ getCameraPoint() {
588
+ const pitch = this._pitch;
589
+ const yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);
590
+ return this.centerPoint.add(new _point.default(0, yOffset));
591
+ }
575
592
 
576
- /**
577
- * Sets or clears the map's geographical constraints.
578
- * @param {LngLatBounds} bounds A {@link LngLatBounds} object describing the new geographic boundaries of the map.
579
- */
580
- }, {
581
- key: "setMaxBounds",
582
- value: function setMaxBounds(bounds) {
583
- if (bounds) {
584
- this.lngRange = [bounds.getWest(), bounds.getEast()];
585
- this.latRange = [bounds.getSouth(), bounds.getNorth()];
586
- this.constrain();
587
- } else {
588
- this.lngRange = undefined;
589
- this.latRange = [-this.maxValidLatitude, this.maxValidLatitude];
590
- }
591
- }
592
- }, {
593
- key: "customLayerMatrix",
594
- value: function customLayerMatrix() {
595
- return this.mercatorMatrix.slice();
596
- }
597
- }, {
598
- key: "maxPitchScaleFactor",
599
- value: function maxPitchScaleFactor() {
600
- // calcMatrices hasn't run yet
601
- if (!this.pixelMatrixInverse) {
602
- return 1;
593
+ /*
594
+ * When the map is pitched, some of the 3D features that intersect a query will not intersect
595
+ * the query at the surface of the earth. Instead the feature may be closer and only intersect
596
+ * the query because it extrudes into the air.
597
+ *
598
+ * This returns a geometry that includes all of the original query as well as all possible ares of the
599
+ * screen where the *base* of a visible extrusion could be.
600
+ * - For point queries, the line from the query point to the "camera point"
601
+ * - For other geometries, the envelope of the query geometry and the "camera point"
602
+ */
603
+ getCameraQueryGeometry(queryGeometry) {
604
+ const c = this.getCameraPoint();
605
+ if (queryGeometry.length === 1) {
606
+ return [queryGeometry[0], c];
607
+ } else {
608
+ let minX = c.x;
609
+ let minY = c.y;
610
+ let maxX = c.x;
611
+ let maxY = c.y;
612
+ for (const p of queryGeometry) {
613
+ minX = Math.min(minX, p.x);
614
+ minY = Math.min(minY, p.y);
615
+ maxX = Math.max(maxX, p.x);
616
+ maxY = Math.max(maxY, p.y);
603
617
  }
604
- var coord = this.pointCoordinate(new _point.default(0, 0));
605
- var p = new Float32Array([coord.x * this.worldSize, coord.y * this.worldSize, 0, 1]);
606
- var topPoint = _glMatrix.vec4.transformMat4(p, p, this.pixelMatrix);
607
- return topPoint[3] / this.cameraToCenterDistance;
608
- }
609
-
610
- /*
611
- * The camera looks at the map from a 3D (lng, lat, altitude) location. Let's use `cameraLocation`
612
- * as the name for the location under the camera and on the surface of the earth (lng, lat, 0).
613
- * `cameraPoint` is the projected position of the `cameraLocation`.
614
- *
615
- * This point is useful to us because only fill-extrusions that are between `cameraPoint` and
616
- * the query point on the surface of the earth can extend and intersect the query.
617
- *
618
- * When the map is not pitched the `cameraPoint` is equivalent to the center of the map because
619
- * the camera is right above the center of the map.
620
- */
621
- }, {
622
- key: "getCameraPoint",
623
- value: function getCameraPoint() {
624
- var pitch = this._pitch;
625
- var yOffset = Math.tan(pitch) * (this.cameraToCenterDistance || 1);
626
- return this.centerPoint.add(new _point.default(0, yOffset));
618
+ return [new _point.default(minX, minY), new _point.default(maxX, minY), new _point.default(maxX, maxY), new _point.default(minX, maxY), new _point.default(minX, minY)];
627
619
  }
620
+ }
628
621
 
629
- /*
630
- * When the map is pitched, some of the 3D features that intersect a query will not intersect
631
- * the query at the surface of the earth. Instead the feature may be closer and only intersect
632
- * the query because it extrudes into the air.
633
- *
634
- * This returns a geometry that includes all of the original query as well as all possible ares of the
635
- * screen where the *base* of a visible extrusion could be.
636
- * - For point queries, the line from the query point to the "camera point"
637
- * - For other geometries, the envelope of the query geometry and the "camera point"
638
- */
639
- }, {
640
- key: "getCameraQueryGeometry",
641
- value: function getCameraQueryGeometry(queryGeometry) {
642
- var c = this.getCameraPoint();
643
- if (queryGeometry.length === 1) {
644
- return [queryGeometry[0], c];
645
- } else {
646
- var minX = c.x;
647
- var minY = c.y;
648
- var maxX = c.x;
649
- var maxY = c.y;
650
- var _iterator = _createForOfIteratorHelper(queryGeometry),
651
- _step;
652
- try {
653
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
654
- var p = _step.value;
655
- minX = Math.min(minX, p.x);
656
- minY = Math.min(minY, p.y);
657
- maxX = Math.max(maxX, p.x);
658
- maxY = Math.max(maxY, p.y);
659
- }
660
- } catch (err) {
661
- _iterator.e(err);
662
- } finally {
663
- _iterator.f();
664
- }
665
- return [new _point.default(minX, minY), new _point.default(maxX, minY), new _point.default(maxX, maxY), new _point.default(minX, maxY), new _point.default(minX, minY)];
666
- }
667
- }
622
+ /**
623
+ * Given a coordinate, return the screen point that corresponds to it
624
+ * @param {Coordinate} coord
625
+ * @returns {Point} screen point
626
+ * @private
627
+ */
628
+ coordinatePoint(coord) {
629
+ const p = _glMatrix.vec4.fromValues(coord.x * this.worldSize, coord.y * this.worldSize, 0, 1);
630
+ _glMatrix.vec4.transformMat4(p, p, this.pixelMatrix);
631
+ return new _point.default(p[0] / p[3], p[1] / p[3]);
632
+ }
633
+ /**
634
+ * Given a location, return the screen point that corresponds to it
635
+ * @param {LngLat} lnglat location
636
+ * @returns {Point} screen point
637
+ * @private
638
+ */
639
+ locationPoint(lnglat) {
640
+ return this.coordinatePoint(this.locationCoordinate(lnglat));
641
+ }
668
642
 
669
- /**
670
- * Given a coordinate, return the screen point that corresponds to it
671
- * @param {Coordinate} coord
672
- * @returns {Point} screen point
673
- * @private
674
- */
675
- }, {
676
- key: "coordinatePoint",
677
- value: function coordinatePoint(coord) {
678
- var p = _glMatrix.vec4.fromValues(coord.x * this.worldSize, coord.y * this.worldSize, 0, 1);
679
- _glMatrix.vec4.transformMat4(p, p, this.pixelMatrix);
680
- return new _point.default(p[0] / p[3], p[1] / p[3]);
681
- }
682
- /**
683
- * Given a location, return the screen point that corresponds to it
684
- * @param {LngLat} lnglat location
685
- * @returns {Point} screen point
686
- * @private
687
- */
688
- }, {
689
- key: "locationPoint",
690
- value: function locationPoint(lnglat) {
691
- return this.coordinatePoint(this.locationCoordinate(lnglat));
692
- }
643
+ /**
644
+ * Given a point on screen, return its lnglat
645
+ * @param {Point} p screen point
646
+ * @returns {LngLat} lnglat location
647
+ * @private
648
+ */
649
+ pointLocation(p) {
650
+ // if(p.x !== 0 && p.x !== 1001) {
651
+ // console.log(p.x)
652
+ // }
693
653
 
694
- /**
695
- * Given a point on screen, return its lnglat
696
- * @param {Point} p screen point
697
- * @returns {LngLat} lnglat location
698
- * @private
699
- */
700
- }, {
701
- key: "pointLocation",
702
- value: function pointLocation(p) {
703
- // if(p.x !== 0 && p.x !== 1001) {
704
- // console.log(p.x)
705
- // }
706
-
707
- return this.coordinateLocation(this.pointCoordinate(p));
708
- }
654
+ return this.coordinateLocation(this.pointCoordinate(p));
655
+ }
709
656
 
710
- /**
711
- * Given a geographical lnglat, return an unrounded
712
- * coordinate that represents it at this transform's zoom level.
713
- * @param {LngLat} lnglat
714
- * @returns {Coordinate}
715
- * @private
716
- */
717
- }, {
718
- key: "locationCoordinate",
719
- value: function locationCoordinate(lnglat) {
720
- return _mercator.default.fromLngLat(lnglat);
721
- }
657
+ /**
658
+ * Given a geographical lnglat, return an unrounded
659
+ * coordinate that represents it at this transform's zoom level.
660
+ * @param {LngLat} lnglat
661
+ * @returns {Coordinate}
662
+ * @private
663
+ */
664
+ locationCoordinate(lnglat) {
665
+ return _mercator.default.fromLngLat(lnglat);
666
+ }
722
667
 
723
- /**
724
- * Given a Coordinate, return its geographical position.
725
- * @param {Coordinate} coord
726
- * @returns {LngLat} lnglat
727
- * @private
728
- */
729
- }, {
730
- key: "coordinateLocation",
731
- value: function coordinateLocation(coord) {
732
- return coord.toLngLat();
733
- }
734
- }, {
735
- key: "getProjectionMatrix",
736
- value: function getProjectionMatrix() {
737
- return this.projMatrix;
668
+ /**
669
+ * Given a Coordinate, return its geographical position.
670
+ * @param {Coordinate} coord
671
+ * @returns {LngLat} lnglat
672
+ * @private
673
+ */
674
+ coordinateLocation(coord) {
675
+ return coord.toLngLat();
676
+ }
677
+ getProjectionMatrix() {
678
+ return this.projMatrix;
679
+ }
680
+ /**
681
+ * Calculate the posMatrix that, given a tile coordinate, would be used to display the tile on a map.
682
+ * @param {UnwrappedTileID} unwrappedTileID;
683
+ * @private
684
+ */
685
+ // private calculatePosMatrix(
686
+ // unwrappedTileID: UnwrappedTileID,
687
+ // aligned: boolean = false,
688
+ // ): Float32Array {
689
+ // const posMatrixKey = unwrappedTileID.key;
690
+ // const cache = aligned ? this.alignedPosMatrixCache : this.posMatrixCache;
691
+ // if (cache[posMatrixKey]) {
692
+ // return cache[posMatrixKey];
693
+ // }
694
+
695
+ // const canonical = unwrappedTileID.canonical;
696
+ // const scale = this.worldSize / this.zoomScale(canonical.z);
697
+ // const unwrappedX =
698
+ // canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;
699
+
700
+ // const posMatrix = mat4.identity(new Float64Array(16));
701
+ // mat4.translate(posMatrix, posMatrix, [
702
+ // unwrappedX * scale,
703
+ // canonical.y * scale,
704
+ // 0,
705
+ // ]);
706
+ // mat4.scale(posMatrix, posMatrix, [scale / EXTENT, scale / EXTENT, 1]);
707
+ // mat4.multiply(
708
+ // posMatrix,
709
+ // aligned ? this.alignedProjMatrix : this.projMatrix,
710
+ // posMatrix,
711
+ // );
712
+
713
+ // cache[posMatrixKey] = new Float32Array(posMatrix);
714
+ // return cache[posMatrixKey];
715
+ // }
716
+
717
+ constrain() {
718
+ if (!this.center || !this.width || !this.height || this.constraining) {
719
+ return;
720
+ }
721
+ this.constraining = true;
722
+ let minY = -90;
723
+ let maxY = 90;
724
+ let minX = -180;
725
+ let maxX = 180;
726
+ let sy;
727
+ let sx;
728
+ let x2;
729
+ let y2;
730
+ const size = this.size;
731
+ const unmodified = this.unmodified;
732
+ if (this.latRange) {
733
+ const latRange = this.latRange;
734
+ minY = (0, _mercator.mercatorYfromLat)(latRange[1]) * this.worldSize;
735
+ maxY = (0, _mercator.mercatorYfromLat)(latRange[0]) * this.worldSize;
736
+ sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;
737
+ }
738
+ if (this.lngRange) {
739
+ const lngRange = this.lngRange;
740
+ minX = (0, _mercator.mercatorXfromLng)(lngRange[0]) * this.worldSize;
741
+ maxX = (0, _mercator.mercatorXfromLng)(lngRange[1]) * this.worldSize;
742
+ sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;
743
+ }
744
+ const point = this.point;
745
+
746
+ // how much the map should scale to fit the screen into given latitude/longitude ranges
747
+ const s = Math.max(sx || 0, sy || 0);
748
+ if (s) {
749
+ this.center = this.unproject(new _point.default(sx ? (maxX + minX) / 2 : point.x, sy ? (maxY + minY) / 2 : point.y));
750
+ this.zoom += this.scaleZoom(s);
751
+ this.unmodified = unmodified;
752
+ this.constraining = false;
753
+ return;
738
754
  }
739
- /**
740
- * Calculate the posMatrix that, given a tile coordinate, would be used to display the tile on a map.
741
- * @param {UnwrappedTileID} unwrappedTileID;
742
- * @private
743
- */
744
- // private calculatePosMatrix(
745
- // unwrappedTileID: UnwrappedTileID,
746
- // aligned: boolean = false,
747
- // ): Float32Array {
748
- // const posMatrixKey = unwrappedTileID.key;
749
- // const cache = aligned ? this.alignedPosMatrixCache : this.posMatrixCache;
750
- // if (cache[posMatrixKey]) {
751
- // return cache[posMatrixKey];
752
- // }
753
-
754
- // const canonical = unwrappedTileID.canonical;
755
- // const scale = this.worldSize / this.zoomScale(canonical.z);
756
- // const unwrappedX =
757
- // canonical.x + Math.pow(2, canonical.z) * unwrappedTileID.wrap;
758
-
759
- // const posMatrix = mat4.identity(new Float64Array(16));
760
- // mat4.translate(posMatrix, posMatrix, [
761
- // unwrappedX * scale,
762
- // canonical.y * scale,
763
- // 0,
764
- // ]);
765
- // mat4.scale(posMatrix, posMatrix, [scale / EXTENT, scale / EXTENT, 1]);
766
- // mat4.multiply(
767
- // posMatrix,
768
- // aligned ? this.alignedProjMatrix : this.projMatrix,
769
- // posMatrix,
770
- // );
771
-
772
- // cache[posMatrixKey] = new Float32Array(posMatrix);
773
- // return cache[posMatrixKey];
774
- // }
775
- }, {
776
- key: "constrain",
777
- value: function constrain() {
778
- if (!this.center || !this.width || !this.height || this.constraining) {
779
- return;
780
- }
781
- this.constraining = true;
782
- var minY = -90;
783
- var maxY = 90;
784
- var minX = -180;
785
- var maxX = 180;
786
- var sy;
787
- var sx;
788
- var x2;
789
- var y2;
790
- var size = this.size;
791
- var unmodified = this.unmodified;
792
- if (this.latRange) {
793
- var latRange = this.latRange;
794
- minY = (0, _mercator.mercatorYfromLat)(latRange[1]) * this.worldSize;
795
- maxY = (0, _mercator.mercatorYfromLat)(latRange[0]) * this.worldSize;
796
- sy = maxY - minY < size.y ? size.y / (maxY - minY) : 0;
797
- }
798
- if (this.lngRange) {
799
- var lngRange = this.lngRange;
800
- minX = (0, _mercator.mercatorXfromLng)(lngRange[0]) * this.worldSize;
801
- maxX = (0, _mercator.mercatorXfromLng)(lngRange[1]) * this.worldSize;
802
- sx = maxX - minX < size.x ? size.x / (maxX - minX) : 0;
755
+ if (this.latRange) {
756
+ const y = point.y;
757
+ const h2 = size.y / 2;
758
+ if (y - h2 < minY) {
759
+ y2 = minY + h2;
803
760
  }
804
- var point = this.point;
805
-
806
- // how much the map should scale to fit the screen into given latitude/longitude ranges
807
- var s = Math.max(sx || 0, sy || 0);
808
- if (s) {
809
- this.center = this.unproject(new _point.default(sx ? (maxX + minX) / 2 : point.x, sy ? (maxY + minY) / 2 : point.y));
810
- this.zoom += this.scaleZoom(s);
811
- this.unmodified = unmodified;
812
- this.constraining = false;
813
- return;
814
- }
815
- if (this.latRange) {
816
- var y = point.y;
817
- var h2 = size.y / 2;
818
- if (y - h2 < minY) {
819
- y2 = minY + h2;
820
- }
821
- if (y + h2 > maxY) {
822
- y2 = maxY - h2;
823
- }
824
- }
825
- if (this.lngRange) {
826
- var x = point.x;
827
- var w2 = size.x / 2;
828
- if (x - w2 < minX) {
829
- x2 = minX + w2;
830
- }
831
- if (x + w2 > maxX) {
832
- x2 = maxX - w2;
833
- }
834
- }
835
-
836
- // pan the map if the screen goes off the range
837
- if (x2 !== undefined || y2 !== undefined) {
838
- this.center = this.unproject(new _point.default(x2 !== undefined ? x2 : point.x, y2 !== undefined ? y2 : point.y));
761
+ if (y + h2 > maxY) {
762
+ y2 = maxY - h2;
839
763
  }
840
- this.unmodified = unmodified;
841
- this.constraining = false;
842
764
  }
843
- }, {
844
- key: "calcMatrices",
845
- value: function calcMatrices() {
846
- if (!this.height) {
847
- return;
765
+ if (this.lngRange) {
766
+ const x = point.x;
767
+ const w2 = size.x / 2;
768
+ if (x - w2 < minX) {
769
+ x2 = minX + w2;
848
770
  }
849
- var halfFov = this._fov / 2;
850
- var offset = this.centerOffset;
851
- this.cameraToCenterDistance = 0.5 / Math.tan(halfFov) * this.height;
852
-
853
- // Find the distance from the center point [width/2 + offset.x, height/2 + offset.y] to the
854
- // center top point [width/2 + offset.x, 0] in Z units, using the law of sines.
855
- // 1 Z unit is equivalent to 1 horizontal px at the center of the map
856
- // (the distance between[width/2, height/2] and [width/2 + 1, height/2])
857
- var groundAngle = Math.PI / 2 + this._pitch;
858
- var fovAboveCenter = this._fov * (0.5 + offset.y / this.height);
859
- var topHalfSurfaceDistance = Math.sin(fovAboveCenter) * this.cameraToCenterDistance / Math.sin((0, _util.clamp)(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01));
860
- var point = this.point;
861
- var x = point.x;
862
- var y = point.y;
863
-
864
- // Calculate z distance of the farthest fragment that should be rendered.
865
- var furthestDistance = Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance + this.cameraToCenterDistance;
866
- // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
867
- var farZ = furthestDistance * 1.01;
868
-
869
- // The larger the value of nearZ is
870
- // - the more depth precision is available for features (good)
871
- // - clipping starts appearing sooner when the camera is close to 3d features (bad)
872
- //
873
- // Smaller values worked well for mapbox-gl-js but deckgl was encountering precision issues
874
- // when rendering it's layers using custom layers. This value was experimentally chosen and
875
- // seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.
876
- var nearZ = this.height / 50;
877
-
878
- // matrix for conversion from location to GL coordinates (-1 .. 1)
879
- // 使用 Float64Array 的原因是为了避免计算精度问题、 mat4.create() 默认使用 Float32Array
880
- var m = new Float64Array(16);
881
- // @ts-ignore
882
- _glMatrix.mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);
883
-
884
- // Apply center of perspective offset
885
- m[8] = -offset.x * 2 / this.width;
886
- m[9] = offset.y * 2 / this.height;
887
-
888
- // @ts-ignore
889
- _glMatrix.mat4.scale(m, m, [1, -1, 1]);
890
- // @ts-ignore
891
- _glMatrix.mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);
892
- // @ts-ignore
893
- _glMatrix.mat4.rotateX(m, m, this._pitch);
894
- // @ts-ignore
895
- _glMatrix.mat4.rotateZ(m, m, this.angle);
896
- // @ts-ignore
897
- _glMatrix.mat4.translate(m, m, [-x, -y, 0]);
898
-
899
- // The mercatorMatrix can be used to transform points from mercator coordinates
900
- // ([0, 0] nw, [1, 1] se) to GL coordinates.
901
- // @ts-ignore
902
- this.mercatorMatrix = _glMatrix.mat4.scale([], m, [this.worldSize, this.worldSize, this.worldSize]);
903
- // scale vertically to meters per pixel (inverse of ground resolution):
904
-
905
- // @ts-ignore
906
- _glMatrix.mat4.scale(m, m, [1, 1, (0, _mercator.mercatorZfromAltitude)(1, this.center.lat) * this.worldSize, 1]);
907
- // @ts-ignore
908
- this.projMatrix = m;
909
- // @ts-ignore
910
- this.invProjMatrix = _glMatrix.mat4.invert([], this.projMatrix);
911
-
912
- // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.
913
- // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional
914
- // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension
915
- // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle
916
- // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that
917
- // it is always <= 0.5 pixels.
918
- var xShift = this.width % 2 / 2;
919
- var yShift = this.height % 2 / 2;
920
- var angleCos = Math.cos(this.angle);
921
- var angleSin = Math.sin(this.angle);
922
- var dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;
923
- var dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;
924
- // const alignedM = mat4.clone(m);
925
- var alignedM = new Float64Array(m);
926
- // @ts-ignore
927
- _glMatrix.mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]);
928
- // @ts-ignore
929
- this.alignedProjMatrix = alignedM;
930
-
931
- // @ts-ignore
932
- m = _glMatrix.mat4.create();
933
- // @ts-ignore
934
- _glMatrix.mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);
935
- // @ts-ignore
936
- _glMatrix.mat4.translate(m, m, [1, -1, 0]);
937
- // @ts-ignore
938
- this.labelPlaneMatrix = m;
939
-
940
- // @ts-ignore
941
- m = _glMatrix.mat4.create();
942
- // @ts-ignore
943
- _glMatrix.mat4.scale(m, m, [1, -1, 1]);
944
- // @ts-ignore
945
- _glMatrix.mat4.translate(m, m, [-1, -1, 0]);
946
- // @ts-ignore
947
- _glMatrix.mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);
948
- // @ts-ignore
949
- this.glCoordMatrix = m;
950
-
951
- // matrix for conversion from location to screen coordinates
952
- this.pixelMatrix = _glMatrix.mat4.multiply(
953
- // @ts-ignore
954
- new Float64Array(16), this.labelPlaneMatrix, this.projMatrix);
955
-
956
- // inverse matrix for conversion from screen coordinaes to location
957
- // @ts-ignore
958
- m = _glMatrix.mat4.invert(new Float64Array(16), this.pixelMatrix);
959
- if (!m) {
960
- throw new Error('failed to invert matrix');
771
+ if (x + w2 > maxX) {
772
+ x2 = maxX - w2;
961
773
  }
962
- // @ts-ignore
963
- this.pixelMatrixInverse = m;
964
- this.posMatrixCache = {};
965
- this.alignedPosMatrixCache = {};
966
774
  }
967
- }]);
968
- return Transform;
969
- }();
775
+
776
+ // pan the map if the screen goes off the range
777
+ if (x2 !== undefined || y2 !== undefined) {
778
+ this.center = this.unproject(new _point.default(x2 !== undefined ? x2 : point.x, y2 !== undefined ? y2 : point.y));
779
+ }
780
+ this.unmodified = unmodified;
781
+ this.constraining = false;
782
+ }
783
+ calcMatrices() {
784
+ if (!this.height) {
785
+ return;
786
+ }
787
+ const halfFov = this._fov / 2;
788
+ const offset = this.centerOffset;
789
+ this.cameraToCenterDistance = 0.5 / Math.tan(halfFov) * this.height;
790
+
791
+ // Find the distance from the center point [width/2 + offset.x, height/2 + offset.y] to the
792
+ // center top point [width/2 + offset.x, 0] in Z units, using the law of sines.
793
+ // 1 Z unit is equivalent to 1 horizontal px at the center of the map
794
+ // (the distance between[width/2, height/2] and [width/2 + 1, height/2])
795
+ const groundAngle = Math.PI / 2 + this._pitch;
796
+ const fovAboveCenter = this._fov * (0.5 + offset.y / this.height);
797
+ const topHalfSurfaceDistance = Math.sin(fovAboveCenter) * this.cameraToCenterDistance / Math.sin((0, _util.clamp)(Math.PI - groundAngle - fovAboveCenter, 0.01, Math.PI - 0.01));
798
+ const point = this.point;
799
+ const x = point.x;
800
+ const y = point.y;
801
+
802
+ // Calculate z distance of the farthest fragment that should be rendered.
803
+ const furthestDistance = Math.cos(Math.PI / 2 - this._pitch) * topHalfSurfaceDistance + this.cameraToCenterDistance;
804
+ // Add a bit extra to avoid precision problems when a fragment's distance is exactly `furthestDistance`
805
+ const farZ = furthestDistance * 1.01;
806
+
807
+ // The larger the value of nearZ is
808
+ // - the more depth precision is available for features (good)
809
+ // - clipping starts appearing sooner when the camera is close to 3d features (bad)
810
+ //
811
+ // Smaller values worked well for mapbox-gl-js but deckgl was encountering precision issues
812
+ // when rendering it's layers using custom layers. This value was experimentally chosen and
813
+ // seems to solve z-fighting issues in deckgl while not clipping buildings too close to the camera.
814
+ const nearZ = this.height / 50;
815
+
816
+ // matrix for conversion from location to GL coordinates (-1 .. 1)
817
+ // 使用 Float64Array 的原因是为了避免计算精度问题、 mat4.create() 默认使用 Float32Array
818
+ let m = new Float64Array(16);
819
+ // @ts-ignore
820
+ _glMatrix.mat4.perspective(m, this._fov, this.width / this.height, nearZ, farZ);
821
+
822
+ // Apply center of perspective offset
823
+ m[8] = -offset.x * 2 / this.width;
824
+ m[9] = offset.y * 2 / this.height;
825
+
826
+ // @ts-ignore
827
+ _glMatrix.mat4.scale(m, m, [1, -1, 1]);
828
+ // @ts-ignore
829
+ _glMatrix.mat4.translate(m, m, [0, 0, -this.cameraToCenterDistance]);
830
+ // @ts-ignore
831
+ _glMatrix.mat4.rotateX(m, m, this._pitch);
832
+ // @ts-ignore
833
+ _glMatrix.mat4.rotateZ(m, m, this.angle);
834
+ // @ts-ignore
835
+ _glMatrix.mat4.translate(m, m, [-x, -y, 0]);
836
+
837
+ // The mercatorMatrix can be used to transform points from mercator coordinates
838
+ // ([0, 0] nw, [1, 1] se) to GL coordinates.
839
+ // @ts-ignore
840
+ this.mercatorMatrix = _glMatrix.mat4.scale([], m, [this.worldSize, this.worldSize, this.worldSize]);
841
+ // scale vertically to meters per pixel (inverse of ground resolution):
842
+
843
+ // @ts-ignore
844
+ _glMatrix.mat4.scale(m, m, [1, 1, (0, _mercator.mercatorZfromAltitude)(1, this.center.lat) * this.worldSize, 1]);
845
+ // @ts-ignore
846
+ this.projMatrix = m;
847
+ // @ts-ignore
848
+ this.invProjMatrix = _glMatrix.mat4.invert([], this.projMatrix);
849
+
850
+ // Make a second projection matrix that is aligned to a pixel grid for rendering raster tiles.
851
+ // We're rounding the (floating point) x/y values to achieve to avoid rendering raster images to fractional
852
+ // coordinates. Additionally, we adjust by half a pixel in either direction in case that viewport dimension
853
+ // is an odd integer to preserve rendering to the pixel grid. We're rotating this shift based on the angle
854
+ // of the transformation so that 0°, 90°, 180°, and 270° rasters are crisp, and adjust the shift so that
855
+ // it is always <= 0.5 pixels.
856
+ const xShift = this.width % 2 / 2;
857
+ const yShift = this.height % 2 / 2;
858
+ const angleCos = Math.cos(this.angle);
859
+ const angleSin = Math.sin(this.angle);
860
+ const dx = x - Math.round(x) + angleCos * xShift + angleSin * yShift;
861
+ const dy = y - Math.round(y) + angleCos * yShift + angleSin * xShift;
862
+ // const alignedM = mat4.clone(m);
863
+ const alignedM = new Float64Array(m);
864
+ // @ts-ignore
865
+ _glMatrix.mat4.translate(alignedM, alignedM, [dx > 0.5 ? dx - 1 : dx, dy > 0.5 ? dy - 1 : dy, 0]);
866
+ // @ts-ignore
867
+ this.alignedProjMatrix = alignedM;
868
+
869
+ // @ts-ignore
870
+ m = _glMatrix.mat4.create();
871
+ // @ts-ignore
872
+ _glMatrix.mat4.scale(m, m, [this.width / 2, -this.height / 2, 1]);
873
+ // @ts-ignore
874
+ _glMatrix.mat4.translate(m, m, [1, -1, 0]);
875
+ // @ts-ignore
876
+ this.labelPlaneMatrix = m;
877
+
878
+ // @ts-ignore
879
+ m = _glMatrix.mat4.create();
880
+ // @ts-ignore
881
+ _glMatrix.mat4.scale(m, m, [1, -1, 1]);
882
+ // @ts-ignore
883
+ _glMatrix.mat4.translate(m, m, [-1, -1, 0]);
884
+ // @ts-ignore
885
+ _glMatrix.mat4.scale(m, m, [2 / this.width, 2 / this.height, 1]);
886
+ // @ts-ignore
887
+ this.glCoordMatrix = m;
888
+
889
+ // matrix for conversion from location to screen coordinates
890
+ this.pixelMatrix = _glMatrix.mat4.multiply(
891
+ // @ts-ignore
892
+ new Float64Array(16), this.labelPlaneMatrix, this.projMatrix);
893
+
894
+ // inverse matrix for conversion from screen coordinaes to location
895
+ // @ts-ignore
896
+ m = _glMatrix.mat4.invert(new Float64Array(16), this.pixelMatrix);
897
+ if (!m) {
898
+ throw new Error('failed to invert matrix');
899
+ }
900
+ // @ts-ignore
901
+ this.pixelMatrixInverse = m;
902
+ this.posMatrixCache = {};
903
+ this.alignedPosMatrixCache = {};
904
+ }
905
+ }
906
+ exports.default = Transform;