@antv/l7-map 2.21.11-beta.4 → 2.21.11-beta.6

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