@mapwhit/tilerenderer 0.47.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (356) hide show
  1. package/LICENSE.txt +87 -0
  2. package/README.md +25 -0
  3. package/build/min/.dir +0 -0
  4. package/build/min/package.json +3 -0
  5. package/build/min/src/shaders/_prelude.fragment.glsl.txt +13 -0
  6. package/build/min/src/shaders/_prelude.vertex.glsl.txt +14 -0
  7. package/build/min/src/shaders/background.fragment.glsl.txt +5 -0
  8. package/build/min/src/shaders/background.vertex.glsl.txt +1 -0
  9. package/build/min/src/shaders/background_pattern.fragment.glsl.txt +5 -0
  10. package/build/min/src/shaders/background_pattern.vertex.glsl.txt +1 -0
  11. package/build/min/src/shaders/circle.fragment.glsl.txt +20 -0
  12. package/build/min/src/shaders/circle.vertex.glsl.txt +17 -0
  13. package/build/min/src/shaders/clipping_mask.fragment.glsl.txt +1 -0
  14. package/build/min/src/shaders/clipping_mask.vertex.glsl.txt +1 -0
  15. package/build/min/src/shaders/collision_box.fragment.glsl.txt +1 -0
  16. package/build/min/src/shaders/collision_box.vertex.glsl.txt +1 -0
  17. package/build/min/src/shaders/collision_circle.fragment.glsl.txt +1 -0
  18. package/build/min/src/shaders/collision_circle.vertex.glsl.txt +1 -0
  19. package/build/min/src/shaders/debug.fragment.glsl.txt +1 -0
  20. package/build/min/src/shaders/debug.vertex.glsl.txt +1 -0
  21. package/build/min/src/shaders/fill.fragment.glsl.txt +10 -0
  22. package/build/min/src/shaders/fill.vertex.glsl.txt +7 -0
  23. package/build/min/src/shaders/fill_extrusion.fragment.glsl.txt +13 -0
  24. package/build/min/src/shaders/fill_extrusion.vertex.glsl.txt +9 -0
  25. package/build/min/src/shaders/fill_extrusion_pattern.fragment.glsl.txt +15 -0
  26. package/build/min/src/shaders/fill_extrusion_pattern.vertex.glsl.txt +11 -0
  27. package/build/min/src/shaders/fill_outline.fragment.glsl.txt +10 -0
  28. package/build/min/src/shaders/fill_outline.vertex.glsl.txt +7 -0
  29. package/build/min/src/shaders/fill_outline_pattern.fragment.glsl.txt +13 -0
  30. package/build/min/src/shaders/fill_outline_pattern.vertex.glsl.txt +9 -0
  31. package/build/min/src/shaders/fill_pattern.fragment.glsl.txt +13 -0
  32. package/build/min/src/shaders/fill_pattern.vertex.glsl.txt +9 -0
  33. package/build/min/src/shaders/heatmap.fragment.glsl.txt +10 -0
  34. package/build/min/src/shaders/heatmap.vertex.glsl.txt +8 -0
  35. package/build/min/src/shaders/heatmap_texture.fragment.glsl.txt +5 -0
  36. package/build/min/src/shaders/heatmap_texture.vertex.glsl.txt +1 -0
  37. package/build/min/src/shaders/hillshade.fragment.glsl.txt +7 -0
  38. package/build/min/src/shaders/hillshade.vertex.glsl.txt +1 -0
  39. package/build/min/src/shaders/hillshade_prepare.fragment.glsl.txt +8 -0
  40. package/build/min/src/shaders/hillshade_prepare.vertex.glsl.txt +1 -0
  41. package/build/min/src/shaders/line.fragment.glsl.txt +12 -0
  42. package/build/min/src/shaders/line.vertex.glsl.txt +17 -0
  43. package/build/min/src/shaders/line_gradient.fragment.glsl.txt +10 -0
  44. package/build/min/src/shaders/line_gradient.vertex.glsl.txt +16 -0
  45. package/build/min/src/shaders/line_pattern.fragment.glsl.txt +15 -0
  46. package/build/min/src/shaders/line_pattern.vertex.glsl.txt +20 -0
  47. package/build/min/src/shaders/line_sdf.fragment.glsl.txt +17 -0
  48. package/build/min/src/shaders/line_sdf.vertex.glsl.txt +20 -0
  49. package/build/min/src/shaders/raster.fragment.glsl.txt +5 -0
  50. package/build/min/src/shaders/raster.vertex.glsl.txt +1 -0
  51. package/build/min/src/shaders/symbol_icon.fragment.glsl.txt +9 -0
  52. package/build/min/src/shaders/symbol_icon.vertex.glsl.txt +5 -0
  53. package/build/min/src/shaders/symbol_sdf.fragment.glsl.txt +19 -0
  54. package/build/min/src/shaders/symbol_sdf.vertex.glsl.txt +13 -0
  55. package/package.json +44 -0
  56. package/src/css/mapbox-gl.css +506 -0
  57. package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
  58. package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
  59. package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
  60. package/src/css/svg/mapboxgl-ctrl-geolocate-background.svg +3 -0
  61. package/src/css/svg/mapboxgl-ctrl-geolocate.svg +3 -0
  62. package/src/css/svg/mapboxgl-ctrl-logo-compact.svg +2 -0
  63. package/src/css/svg/mapboxgl-ctrl-logo.svg +1 -0
  64. package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
  65. package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
  66. package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
  67. package/src/data/array_types.js +1138 -0
  68. package/src/data/bucket/circle_attributes.js +5 -0
  69. package/src/data/bucket/circle_bucket.js +118 -0
  70. package/src/data/bucket/fill_attributes.js +5 -0
  71. package/src/data/bucket/fill_bucket.js +166 -0
  72. package/src/data/bucket/fill_extrusion_attributes.js +11 -0
  73. package/src/data/bucket/fill_extrusion_bucket.js +247 -0
  74. package/src/data/bucket/heatmap_bucket.js +12 -0
  75. package/src/data/bucket/line_attributes.js +11 -0
  76. package/src/data/bucket/line_bucket.js +625 -0
  77. package/src/data/bucket/pattern_attributes.js +9 -0
  78. package/src/data/bucket/pattern_bucket_features.js +44 -0
  79. package/src/data/bucket/symbol_attributes.js +95 -0
  80. package/src/data/bucket/symbol_bucket.js +697 -0
  81. package/src/data/bucket.js +53 -0
  82. package/src/data/dem_data.js +126 -0
  83. package/src/data/extent.js +17 -0
  84. package/src/data/feature_index.js +254 -0
  85. package/src/data/index_array_type.js +14 -0
  86. package/src/data/load_geometry.js +42 -0
  87. package/src/data/pos_attributes.js +3 -0
  88. package/src/data/program_configuration.js +782 -0
  89. package/src/data/raster_bounds_attributes.js +6 -0
  90. package/src/data/segment.js +63 -0
  91. package/src/geo/coordinate.js +78 -0
  92. package/src/geo/lng_lat.js +129 -0
  93. package/src/geo/lng_lat_bounds.js +253 -0
  94. package/src/geo/transform.js +605 -0
  95. package/src/gl/color_mode.js +21 -0
  96. package/src/gl/context.js +193 -0
  97. package/src/gl/cull_face_mode.js +22 -0
  98. package/src/gl/depth_mode.js +18 -0
  99. package/src/gl/framebuffer.js +28 -0
  100. package/src/gl/index_buffer.js +52 -0
  101. package/src/gl/stencil_mode.js +17 -0
  102. package/src/gl/types.js +0 -0
  103. package/src/gl/value.js +676 -0
  104. package/src/gl/vertex_buffer.js +101 -0
  105. package/src/index.js +50 -0
  106. package/src/render/draw_background.js +60 -0
  107. package/src/render/draw_circle.js +55 -0
  108. package/src/render/draw_collision_debug.js +45 -0
  109. package/src/render/draw_debug.js +429 -0
  110. package/src/render/draw_fill.js +143 -0
  111. package/src/render/draw_fill_extrusion.js +101 -0
  112. package/src/render/draw_heatmap.js +159 -0
  113. package/src/render/draw_hillshade.js +144 -0
  114. package/src/render/draw_line.js +99 -0
  115. package/src/render/draw_raster.js +151 -0
  116. package/src/render/draw_symbol.js +231 -0
  117. package/src/render/glyph_atlas.js +55 -0
  118. package/src/render/glyph_manager.js +145 -0
  119. package/src/render/image_atlas.js +97 -0
  120. package/src/render/image_manager.js +183 -0
  121. package/src/render/line_atlas.js +139 -0
  122. package/src/render/painter.js +483 -0
  123. package/src/render/program/background_program.js +46 -0
  124. package/src/render/program/circle_program.js +40 -0
  125. package/src/render/program/clipping_mask_program.js +11 -0
  126. package/src/render/program/collision_program.js +28 -0
  127. package/src/render/program/debug_program.js +13 -0
  128. package/src/render/program/fill_extrusion_program.js +76 -0
  129. package/src/render/program/fill_program.js +60 -0
  130. package/src/render/program/heatmap_program.js +46 -0
  131. package/src/render/program/hillshade_program.js +77 -0
  132. package/src/render/program/line_program.js +119 -0
  133. package/src/render/program/pattern.js +57 -0
  134. package/src/render/program/program_uniforms.js +46 -0
  135. package/src/render/program/raster_program.js +50 -0
  136. package/src/render/program/symbol_program.js +112 -0
  137. package/src/render/program.js +133 -0
  138. package/src/render/texture.js +88 -0
  139. package/src/render/tile_mask.js +108 -0
  140. package/src/render/uniform_binding.js +129 -0
  141. package/src/render/vertex_array_object.js +155 -0
  142. package/src/shaders/README.md +42 -0
  143. package/src/shaders/_prelude.fragment.glsl +17 -0
  144. package/src/shaders/_prelude.vertex.glsl +73 -0
  145. package/src/shaders/background.fragment.glsl +10 -0
  146. package/src/shaders/background.vertex.glsl +7 -0
  147. package/src/shaders/background_pattern.fragment.glsl +28 -0
  148. package/src/shaders/background_pattern.vertex.glsl +20 -0
  149. package/src/shaders/circle.fragment.glsl +39 -0
  150. package/src/shaders/circle.vertex.glsl +63 -0
  151. package/src/shaders/clipping_mask.fragment.glsl +3 -0
  152. package/src/shaders/clipping_mask.vertex.glsl +7 -0
  153. package/src/shaders/collision_box.fragment.glsl +21 -0
  154. package/src/shaders/collision_box.vertex.glsl +26 -0
  155. package/src/shaders/collision_circle.fragment.glsl +34 -0
  156. package/src/shaders/collision_circle.vertex.glsl +36 -0
  157. package/src/shaders/debug.fragment.glsl +5 -0
  158. package/src/shaders/debug.vertex.glsl +7 -0
  159. package/src/shaders/encode_attribute.js +19 -0
  160. package/src/shaders/fill.fragment.glsl +13 -0
  161. package/src/shaders/fill.vertex.glsl +13 -0
  162. package/src/shaders/fill_extrusion.fragment.glsl +16 -0
  163. package/src/shaders/fill_extrusion.vertex.glsl +66 -0
  164. package/src/shaders/fill_extrusion_pattern.fragment.glsl +41 -0
  165. package/src/shaders/fill_extrusion_pattern.vertex.glsl +76 -0
  166. package/src/shaders/fill_outline.fragment.glsl +17 -0
  167. package/src/shaders/fill_outline.vertex.glsl +17 -0
  168. package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
  169. package/src/shaders/fill_outline_pattern.vertex.glsl +41 -0
  170. package/src/shaders/fill_pattern.fragment.glsl +36 -0
  171. package/src/shaders/fill_pattern.vertex.glsl +36 -0
  172. package/src/shaders/heatmap.fragment.glsl +21 -0
  173. package/src/shaders/heatmap.vertex.glsl +53 -0
  174. package/src/shaders/heatmap_texture.fragment.glsl +14 -0
  175. package/src/shaders/heatmap_texture.vertex.glsl +11 -0
  176. package/src/shaders/hillshade.fragment.glsl +52 -0
  177. package/src/shaders/hillshade.vertex.glsl +11 -0
  178. package/src/shaders/hillshade_prepare.fragment.glsl +72 -0
  179. package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
  180. package/src/shaders/index.js +194 -0
  181. package/src/shaders/line.fragment.glsl +28 -0
  182. package/src/shaders/line.vertex.glsl +84 -0
  183. package/src/shaders/line_gradient.fragment.glsl +34 -0
  184. package/src/shaders/line_gradient.vertex.glsl +84 -0
  185. package/src/shaders/line_pattern.fragment.glsl +69 -0
  186. package/src/shaders/line_pattern.vertex.glsl +88 -0
  187. package/src/shaders/line_sdf.fragment.glsl +44 -0
  188. package/src/shaders/line_sdf.vertex.glsl +95 -0
  189. package/src/shaders/raster.fragment.glsl +52 -0
  190. package/src/shaders/raster.vertex.glsl +21 -0
  191. package/src/shaders/symbol_icon.fragment.glsl +17 -0
  192. package/src/shaders/symbol_icon.vertex.glsl +91 -0
  193. package/src/shaders/symbol_sdf.fragment.glsl +50 -0
  194. package/src/shaders/symbol_sdf.vertex.glsl +117 -0
  195. package/src/source/geojson_source.js +267 -0
  196. package/src/source/geojson_worker_source.js +210 -0
  197. package/src/source/geojson_wrapper.js +67 -0
  198. package/src/source/image_source.js +213 -0
  199. package/src/source/load_tilejson.js +40 -0
  200. package/src/source/pixels_to_tile_units.js +17 -0
  201. package/src/source/query_features.js +198 -0
  202. package/src/source/raster_dem_tile_source.js +140 -0
  203. package/src/source/raster_dem_tile_worker_source.js +26 -0
  204. package/src/source/raster_tile_source.js +126 -0
  205. package/src/source/rtl_text_plugin.js +63 -0
  206. package/src/source/source.js +75 -0
  207. package/src/source/source_cache.js +794 -0
  208. package/src/source/source_state.js +55 -0
  209. package/src/source/tile.js +332 -0
  210. package/src/source/tile_bounds.js +40 -0
  211. package/src/source/tile_cache.js +122 -0
  212. package/src/source/tile_id.js +150 -0
  213. package/src/source/vector_tile_source.js +144 -0
  214. package/src/source/vector_tile_worker_source.js +126 -0
  215. package/src/source/worker.js +175 -0
  216. package/src/source/worker_source.js +14 -0
  217. package/src/source/worker_tile.js +199 -0
  218. package/src/style/create_style_layer.js +25 -0
  219. package/src/style/evaluation_parameters.js +45 -0
  220. package/src/style/light.js +112 -0
  221. package/src/style/load_glyph_range.js +17 -0
  222. package/src/style/load_sprite.js +26 -0
  223. package/src/style/parse_glyph_pbf.js +45 -0
  224. package/src/style/pauseable_placement.js +88 -0
  225. package/src/style/properties.js +691 -0
  226. package/src/style/query_utils.js +39 -0
  227. package/src/style/style.js +955 -0
  228. package/src/style/style_layer/background_style_layer.js +11 -0
  229. package/src/style/style_layer/background_style_layer_properties.js +25 -0
  230. package/src/style/style_layer/circle_style_layer.js +93 -0
  231. package/src/style/style_layer/circle_style_layer_properties.js +76 -0
  232. package/src/style/style_layer/fill_extrusion_style_layer.js +194 -0
  233. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +56 -0
  234. package/src/style/style_layer/fill_style_layer.js +46 -0
  235. package/src/style/style_layer/fill_style_layer_properties.js +45 -0
  236. package/src/style/style_layer/heatmap_style_layer.js +51 -0
  237. package/src/style/style_layer/heatmap_style_layer_properties.js +52 -0
  238. package/src/style/style_layer/hillshade_style_layer.js +15 -0
  239. package/src/style/style_layer/hillshade_style_layer_properties.js +43 -0
  240. package/src/style/style_layer/line_style_layer.js +129 -0
  241. package/src/style/style_layer/line_style_layer_properties.js +104 -0
  242. package/src/style/style_layer/raster_style_layer.js +11 -0
  243. package/src/style/style_layer/raster_style_layer_properties.js +55 -0
  244. package/src/style/style_layer/symbol_style_layer.js +66 -0
  245. package/src/style/style_layer/symbol_style_layer_properties.js +288 -0
  246. package/src/style/style_layer.js +183 -0
  247. package/src/style/style_layer_index.js +61 -0
  248. package/src/style/zoom_history.js +36 -0
  249. package/src/style-spec/deref.js +51 -0
  250. package/src/style-spec/error/parsing_error.js +8 -0
  251. package/src/style-spec/error/validation_error.js +10 -0
  252. package/src/style-spec/expression/compound_expression.js +118 -0
  253. package/src/style-spec/expression/definitions/array.js +82 -0
  254. package/src/style-spec/expression/definitions/assertion.js +69 -0
  255. package/src/style-spec/expression/definitions/at.js +57 -0
  256. package/src/style-spec/expression/definitions/case.js +73 -0
  257. package/src/style-spec/expression/definitions/coalesce.js +68 -0
  258. package/src/style-spec/expression/definitions/coercion.js +96 -0
  259. package/src/style-spec/expression/definitions/collator.js +102 -0
  260. package/src/style-spec/expression/definitions/equals.js +93 -0
  261. package/src/style-spec/expression/definitions/index.js +407 -0
  262. package/src/style-spec/expression/definitions/interpolate.js +235 -0
  263. package/src/style-spec/expression/definitions/length.js +54 -0
  264. package/src/style-spec/expression/definitions/let.js +60 -0
  265. package/src/style-spec/expression/definitions/literal.js +64 -0
  266. package/src/style-spec/expression/definitions/match.js +142 -0
  267. package/src/style-spec/expression/definitions/step.js +116 -0
  268. package/src/style-spec/expression/definitions/var.js +38 -0
  269. package/src/style-spec/expression/evaluation_context.js +35 -0
  270. package/src/style-spec/expression/index.js +329 -0
  271. package/src/style-spec/expression/is_constant.js +63 -0
  272. package/src/style-spec/expression/parsing_context.js +213 -0
  273. package/src/style-spec/expression/parsing_error.js +9 -0
  274. package/src/style-spec/expression/runtime_error.js +12 -0
  275. package/src/style-spec/expression/scope.js +34 -0
  276. package/src/style-spec/expression/stops.js +37 -0
  277. package/src/style-spec/expression/types.js +77 -0
  278. package/src/style-spec/expression/values.js +126 -0
  279. package/src/style-spec/feature_filter/README.md +55 -0
  280. package/src/style-spec/feature_filter/index.js +158 -0
  281. package/src/style-spec/function/convert.js +256 -0
  282. package/src/style-spec/function/index.js +299 -0
  283. package/src/style-spec/group_by_layout.js +68 -0
  284. package/src/style-spec/reference/v8.json +5356 -0
  285. package/src/style-spec/util/color.js +73 -0
  286. package/src/style-spec/util/color_spaces.js +128 -0
  287. package/src/style-spec/util/eval_support.js +8 -0
  288. package/src/style-spec/util/get_type.js +18 -0
  289. package/src/style-spec/util/interpolate.js +21 -0
  290. package/src/style-spec/util/properties.js +17 -0
  291. package/src/style-spec/util/ref_properties.js +1 -0
  292. package/src/style-spec/util/result.js +19 -0
  293. package/src/symbol/anchor.js +21 -0
  294. package/src/symbol/check_max_angle.js +75 -0
  295. package/src/symbol/clip_line.js +73 -0
  296. package/src/symbol/collision_feature.js +230 -0
  297. package/src/symbol/collision_index.js +379 -0
  298. package/src/symbol/cross_tile_symbol_index.js +270 -0
  299. package/src/symbol/get_anchors.js +177 -0
  300. package/src/symbol/grid_index.js +318 -0
  301. package/src/symbol/mergelines.js +75 -0
  302. package/src/symbol/opacity_state.js +21 -0
  303. package/src/symbol/placement.js +563 -0
  304. package/src/symbol/projection.js +601 -0
  305. package/src/symbol/quads.js +173 -0
  306. package/src/symbol/shaping.js +347 -0
  307. package/src/symbol/symbol_layout.js +519 -0
  308. package/src/symbol/symbol_size.js +110 -0
  309. package/src/symbol/transform_text.js +16 -0
  310. package/src/ui/anchor.js +24 -0
  311. package/src/ui/bind_handlers.js +199 -0
  312. package/src/ui/camera.js +954 -0
  313. package/src/ui/events.js +210 -0
  314. package/src/ui/handler/box_zoom.js +151 -0
  315. package/src/ui/handler/dblclick_zoom.js +91 -0
  316. package/src/ui/handler/drag_pan.js +285 -0
  317. package/src/ui/handler/drag_rotate.js +290 -0
  318. package/src/ui/handler/frame.js +28 -0
  319. package/src/ui/handler/inertia.js +45 -0
  320. package/src/ui/handler/keyboard.js +148 -0
  321. package/src/ui/handler/scroll_zoom.js +284 -0
  322. package/src/ui/handler/touch_zoom_rotate.js +263 -0
  323. package/src/ui/map.js +1645 -0
  324. package/src/util/actor.js +104 -0
  325. package/src/util/async.js +23 -0
  326. package/src/util/browser.js +61 -0
  327. package/src/util/callback.js +26 -0
  328. package/src/util/classify_rings.js +43 -0
  329. package/src/util/color_ramp.js +24 -0
  330. package/src/util/config.js +24 -0
  331. package/src/util/dictionary_coder.js +25 -0
  332. package/src/util/dispatcher.js +68 -0
  333. package/src/util/dom.js +102 -0
  334. package/src/util/evented.js +182 -0
  335. package/src/util/find_pole_of_inaccessibility.js +129 -0
  336. package/src/util/global_worker_pool.js +15 -0
  337. package/src/util/image.js +124 -0
  338. package/src/util/interpolate.js +5 -0
  339. package/src/util/intersection_tests.js +207 -0
  340. package/src/util/is_char_in_unicode_block.js +287 -0
  341. package/src/util/loader/image.js +32 -0
  342. package/src/util/object.js +178 -0
  343. package/src/util/script_detection.js +337 -0
  344. package/src/util/struct_array.js +197 -0
  345. package/src/util/task_queue.js +57 -0
  346. package/src/util/throttle.js +26 -0
  347. package/src/util/tile_cover.js +114 -0
  348. package/src/util/token.js +13 -0
  349. package/src/util/unique_id.js +12 -0
  350. package/src/util/util.js +192 -0
  351. package/src/util/vectortile_to_geojson.js +44 -0
  352. package/src/util/verticalize_punctuation.js +112 -0
  353. package/src/util/warn.js +21 -0
  354. package/src/util/web_worker.js +5 -0
  355. package/src/util/web_worker_transfer.js +228 -0
  356. package/src/util/worker_pool.js +41 -0
@@ -0,0 +1,794 @@
1
+ const { create: createSource } = require('./source');
2
+ const Tile = require('./tile');
3
+ const { Event, ErrorEvent, Evented } = require('../util/evented');
4
+ const TileCache = require('./tile_cache');
5
+ const Coordinate = require('../geo/coordinate');
6
+ const { keysDifference } = require('../util/object');
7
+ const EXTENT = require('../data/extent');
8
+ const Point = require('@mapbox/point-geometry');
9
+ const browser = require('../util/browser');
10
+ const { OverscaledTileID } = require('./tile_id');
11
+ const assert = require('assert');
12
+ const SourceFeatureState = require('./source_state');
13
+
14
+ /**
15
+ * `SourceCache` is responsible for
16
+ *
17
+ * - creating an instance of `Source`
18
+ * - forwarding events from `Source`
19
+ * - caching tiles loaded from an instance of `Source`
20
+ * - loading the tiles needed to render a given viewport
21
+ * - unloading the cached tiles not needed to render a given viewport
22
+ *
23
+ * @private
24
+ */
25
+ class SourceCache extends Evented {
26
+ constructor(id, options, dispatcher) {
27
+ super();
28
+ this.id = id;
29
+ this.dispatcher = dispatcher;
30
+
31
+ this.on('data', e => {
32
+ // this._sourceLoaded signifies that the TileJSON is loaded if applicable.
33
+ // if the source type does not come with a TileJSON, the flag signifies the
34
+ // source data has loaded (i.e geojson has been tiled on the worker and is ready)
35
+ if (e.dataType === 'source' && e.sourceDataType === 'metadata') this._sourceLoaded = true;
36
+
37
+ // for sources with mutable data, this event fires when the underlying data
38
+ // to a source is changed. (i.e. GeoJSONSource#setData and ImageSource#serCoordinates)
39
+ if (this._sourceLoaded && !this._paused && e.dataType === 'source' && e.sourceDataType === 'content') {
40
+ this.reload();
41
+ if (this.transform) {
42
+ this.update(this.transform);
43
+ }
44
+ }
45
+ });
46
+
47
+ this.on('error', () => {
48
+ this._sourceErrored = true;
49
+ });
50
+
51
+ this._source = createSource(id, options, dispatcher, this);
52
+
53
+ this._tiles = {};
54
+ this._cache = new TileCache(0, this._unloadTile.bind(this));
55
+ this._maxTileCacheSize = null;
56
+
57
+ this._isIdRenderable = this._isIdRenderable.bind(this);
58
+ this._isIdRenderableForSymbols = this._isIdRenderableForSymbols.bind(this);
59
+
60
+ this._coveredTiles = {};
61
+ this._state = new SourceFeatureState();
62
+ }
63
+
64
+ onAdd(map) {
65
+ this.map = map;
66
+ this._maxTileCacheSize = map ? map._maxTileCacheSize : null;
67
+ if (this._source?.onAdd) {
68
+ this._source.onAdd(map);
69
+ }
70
+ }
71
+
72
+ onRemove(map) {
73
+ if (this._source?.onRemove) {
74
+ this._source.onRemove(map);
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Return true if no tile data is pending, tiles will not change unless
80
+ * an additional API call is received.
81
+ */
82
+ loaded() {
83
+ if (this._sourceErrored) {
84
+ return true;
85
+ }
86
+ if (!this._sourceLoaded) {
87
+ return false;
88
+ }
89
+ for (const t in this._tiles) {
90
+ const tile = this._tiles[t];
91
+ if (tile.state !== 'loaded' && tile.state !== 'errored') return false;
92
+ }
93
+ return true;
94
+ }
95
+
96
+ getSource() {
97
+ return this._source;
98
+ }
99
+
100
+ pause() {
101
+ this._paused = true;
102
+ }
103
+
104
+ resume() {
105
+ if (!this._paused) return;
106
+ const shouldReload = this._shouldReloadOnResume;
107
+ this._paused = false;
108
+ this._shouldReloadOnResume = false;
109
+ if (shouldReload) this.reload();
110
+ if (this.transform) this.update(this.transform);
111
+ }
112
+
113
+ _loadTile(tile, callback) {
114
+ return this._source.loadTile(tile, callback);
115
+ }
116
+
117
+ _unloadTile(tile) {
118
+ if (this._source.unloadTile) return this._source.unloadTile(tile, () => {});
119
+ }
120
+
121
+ _abortTile(tile) {
122
+ if (this._source.abortTile) return this._source.abortTile(tile, () => {});
123
+ }
124
+
125
+ serialize() {
126
+ return this._source.serialize();
127
+ }
128
+
129
+ prepare(context) {
130
+ if (this._source.prepare) {
131
+ this._source.prepare();
132
+ }
133
+
134
+ this._state.coalesceChanges(this._tiles, this.map ? this.map.painter : null);
135
+ for (const i in this._tiles) {
136
+ this._tiles[i].upload(context);
137
+ }
138
+ }
139
+
140
+ /**
141
+ * Return all tile ids ordered with z-order, and cast to numbers
142
+ */
143
+ getIds() {
144
+ const compareKeyZoom = (a_, b_) => {
145
+ const a = this._tiles[a_].tileID;
146
+ const b = this._tiles[b_].tileID;
147
+ const rotatedA = new Point(a.canonical.x, a.canonical.y).rotate(this.transform.angle);
148
+ const rotatedB = new Point(b.canonical.x, b.canonical.y).rotate(this.transform.angle);
149
+ return a.overscaledZ - b.overscaledZ || rotatedB.y - rotatedA.y || rotatedB.x - rotatedA.x;
150
+ };
151
+
152
+ return Object.keys(this._tiles).map(Number).sort(compareKeyZoom);
153
+ }
154
+
155
+ getRenderableIds(symbolLayer) {
156
+ return symbolLayer
157
+ ? this.getIds().filter(this._isIdRenderableForSymbols)
158
+ : this.getIds().filter(this._isIdRenderable);
159
+ }
160
+
161
+ hasRenderableParent(tileID) {
162
+ const parentTile = this.findLoadedParent(tileID, 0);
163
+ if (parentTile) {
164
+ return this._isIdRenderable(parentTile.tileID.key);
165
+ }
166
+ return false;
167
+ }
168
+
169
+ _isIdRenderable(id) {
170
+ return this._tiles[id]?.hasData() && !this._coveredTiles[id] && !this._tiles[id].holdingForFade();
171
+ }
172
+
173
+ _isIdRenderableForSymbols(id) {
174
+ return this._tiles[id]?.hasData() && !this._coveredTiles[id];
175
+ }
176
+
177
+ reload() {
178
+ if (this._paused) {
179
+ this._shouldReloadOnResume = true;
180
+ return;
181
+ }
182
+
183
+ this._cache.reset();
184
+
185
+ for (const i in this._tiles) {
186
+ this._reloadTile(i, 'reloading');
187
+ }
188
+ }
189
+
190
+ _reloadTile(id, state) {
191
+ const tile = this._tiles[id];
192
+
193
+ // this potentially does not address all underlying
194
+ // issues https://github.com/mapbox/mapbox-gl-js/issues/4252
195
+ // - hard to tell without repro steps
196
+ if (!tile) return;
197
+
198
+ // The difference between "loading" tiles and "reloading" or "expired"
199
+ // tiles is that "reloading"/"expired" tiles are "renderable".
200
+ // Therefore, a "loading" tile cannot become a "reloading" tile without
201
+ // first becoming a "loaded" tile.
202
+ if (tile.state !== 'loading') {
203
+ tile.state = state;
204
+ }
205
+
206
+ this._loadTile(tile, this._tileLoaded.bind(this, tile, id, state));
207
+ }
208
+
209
+ _tileLoaded(tile, id, previousState, err) {
210
+ if (err) {
211
+ tile.state = 'errored';
212
+ // ignore do nothing strategy
213
+ if (err.doNothing) return;
214
+ if (err.status !== 404) this._source.fire(new ErrorEvent(err, { tile }));
215
+ // continue to try loading parent/children tiles if a tile doesn't exist (404)
216
+ else this.update(this.transform);
217
+ return;
218
+ }
219
+
220
+ tile.timeAdded = browser.now();
221
+ if (this.getSource().type === 'raster-dem' && tile.dem) this._backfillDEM(tile);
222
+ this._state.initializeTileState(tile, this.map ? this.map.painter : null);
223
+
224
+ this._source.fire(new Event('data', { dataType: 'source', tile: tile, coord: tile.tileID }));
225
+ }
226
+
227
+ /**
228
+ * For raster terrain source, backfill DEM to eliminate visible tile boundaries
229
+ * @private
230
+ */
231
+ _backfillDEM(tile) {
232
+ const renderables = this.getRenderableIds();
233
+ for (let i = 0; i < renderables.length; i++) {
234
+ const borderId = renderables[i];
235
+ if (tile.neighboringTiles?.[borderId]) {
236
+ const borderTile = this.getTileByID(borderId);
237
+ fillBorder(tile, borderTile);
238
+ fillBorder(borderTile, tile);
239
+ }
240
+ }
241
+
242
+ function fillBorder(tile, borderTile) {
243
+ tile.needsHillshadePrepare = true;
244
+ let dx = borderTile.tileID.canonical.x - tile.tileID.canonical.x;
245
+ const dy = borderTile.tileID.canonical.y - tile.tileID.canonical.y;
246
+ const dim = 2 ** tile.tileID.canonical.z;
247
+ const borderId = borderTile.tileID.key;
248
+ if (dx === 0 && dy === 0) return;
249
+
250
+ if (Math.abs(dy) > 1) {
251
+ return;
252
+ }
253
+ if (Math.abs(dx) > 1) {
254
+ // Adjust the delta coordinate for world wraparound.
255
+ if (Math.abs(dx + dim) === 1) {
256
+ dx += dim;
257
+ } else if (Math.abs(dx - dim) === 1) {
258
+ dx -= dim;
259
+ }
260
+ }
261
+ if (!borderTile.dem || !tile.dem) return;
262
+ tile.dem.backfillBorder(borderTile.dem, dx, dy);
263
+ if (tile.neighboringTiles?.[borderId]) tile.neighboringTiles[borderId].backfilled = true;
264
+ }
265
+ }
266
+ /**
267
+ * Get a specific tile by TileID
268
+ */
269
+ getTile(tileID) {
270
+ return this.getTileByID(tileID.key);
271
+ }
272
+
273
+ /**
274
+ * Get a specific tile by id
275
+ */
276
+ getTileByID(id) {
277
+ return this._tiles[id];
278
+ }
279
+
280
+ /**
281
+ * get the zoom level adjusted for the difference in map and source tilesizes
282
+ */
283
+ getZoom(transform) {
284
+ return transform.zoom + transform.scaleZoom(transform.tileSize / this._source.tileSize);
285
+ }
286
+
287
+ /**
288
+ * For a given set of tiles, retain children that are loaded and have a zoom
289
+ * between `zoom` (exclusive) and `maxCoveringZoom` (inclusive)
290
+ */
291
+ _retainLoadedChildren(idealTiles, zoom, maxCoveringZoom, retain) {
292
+ for (const id in this._tiles) {
293
+ let tile = this._tiles[id];
294
+
295
+ // only consider renderable tiles up to maxCoveringZoom
296
+ if (retain[id] || !tile.hasData() || tile.tileID.overscaledZ <= zoom || tile.tileID.overscaledZ > maxCoveringZoom)
297
+ continue;
298
+
299
+ // loop through parents and retain the topmost loaded one if found
300
+ let topmostLoadedID = tile.tileID;
301
+ while (tile && tile.tileID.overscaledZ > zoom + 1) {
302
+ const parentID = tile.tileID.scaledTo(tile.tileID.overscaledZ - 1);
303
+
304
+ tile = this._tiles[parentID.key];
305
+
306
+ if (tile?.hasData()) {
307
+ topmostLoadedID = parentID;
308
+ }
309
+ }
310
+
311
+ // loop through ancestors of the topmost loaded child to see if there's one that needed it
312
+ let tileID = topmostLoadedID;
313
+ while (tileID.overscaledZ > zoom) {
314
+ tileID = tileID.scaledTo(tileID.overscaledZ - 1);
315
+
316
+ if (idealTiles[tileID.key]) {
317
+ // found a parent that needed a loaded child; retain that child
318
+ retain[topmostLoadedID.key] = topmostLoadedID;
319
+ break;
320
+ }
321
+ }
322
+ }
323
+ }
324
+
325
+ /**
326
+ * Find a loaded parent of the given tile (up to minCoveringZoom)
327
+ */
328
+ findLoadedParent(tileID, minCoveringZoom) {
329
+ for (let z = tileID.overscaledZ - 1; z >= minCoveringZoom; z--) {
330
+ const parent = tileID.scaledTo(z);
331
+ if (!parent) return;
332
+ const id = String(parent.key);
333
+ const tile = this._tiles[id];
334
+ if (tile?.hasData()) {
335
+ return tile;
336
+ }
337
+ const pp = this._cache.get(parent);
338
+ if (pp) {
339
+ return pp;
340
+ }
341
+ }
342
+ }
343
+
344
+ /**
345
+ * Resizes the tile cache based on the current viewport's size
346
+ * or the maxTileCacheSize option passed during map creation
347
+ *
348
+ * Larger viewports use more tiles and need larger caches. Larger viewports
349
+ * are more likely to be found on devices with more memory and on pages where
350
+ * the map is more important.
351
+ */
352
+ updateCacheSize(transform) {
353
+ const widthInTiles = Math.ceil(transform.width / this._source.tileSize) + 1;
354
+ const heightInTiles = Math.ceil(transform.height / this._source.tileSize) + 1;
355
+ const approxTilesInView = widthInTiles * heightInTiles;
356
+ const commonZoomRange = 5;
357
+
358
+ const viewDependentMaxSize = Math.floor(approxTilesInView * commonZoomRange);
359
+ const maxSize =
360
+ typeof this._maxTileCacheSize === 'number'
361
+ ? Math.min(this._maxTileCacheSize, viewDependentMaxSize)
362
+ : viewDependentMaxSize;
363
+
364
+ this._cache.setMaxSize(maxSize);
365
+ }
366
+
367
+ handleWrapJump(lng) {
368
+ // On top of the regular z/x/y values, TileIDs have a `wrap` value that specify
369
+ // which cppy of the world the tile belongs to. For example, at `lng: 10` you
370
+ // might render z/x/y/0 while at `lng: 370` you would render z/x/y/1.
371
+ //
372
+ // When lng values get wrapped (going from `lng: 370` to `long: 10`) you expect
373
+ // to see the same thing on the screen (370 degrees and 10 degrees is the same
374
+ // place in the world) but all the TileIDs will have different wrap values.
375
+ //
376
+ // In order to make this transition seamless, we calculate the rounded difference of
377
+ // "worlds" between the last frame and the current frame. If the map panned by
378
+ // a world, then we can assign all the tiles new TileIDs with updated wrap values.
379
+ // For example, assign z/x/y/1 a new id: z/x/y/0. It is the same tile, just rendered
380
+ // in a different position.
381
+ //
382
+ // This enables us to reuse the tiles at more ideal locations and prevent flickering.
383
+ const prevLng = this._prevLng === undefined ? lng : this._prevLng;
384
+ const lngDifference = lng - prevLng;
385
+ const worldDifference = lngDifference / 360;
386
+ const wrapDelta = Math.round(worldDifference);
387
+ this._prevLng = lng;
388
+
389
+ if (wrapDelta) {
390
+ const tiles = {};
391
+ for (const key in this._tiles) {
392
+ const tile = this._tiles[key];
393
+ tile.tileID = tile.tileID.unwrapTo(tile.tileID.wrap + wrapDelta);
394
+ tiles[tile.tileID.key] = tile;
395
+ }
396
+ this._tiles = tiles;
397
+ }
398
+ }
399
+
400
+ /**
401
+ * Removes tiles that are outside the viewport and adds new tiles that
402
+ * are inside the viewport.
403
+ */
404
+ update(transform) {
405
+ this.transform = transform;
406
+ if (!this._sourceLoaded || this._paused) {
407
+ return;
408
+ }
409
+
410
+ this.updateCacheSize(transform);
411
+ this.handleWrapJump(this.transform.center.lng);
412
+
413
+ // Covered is a list of retained tiles who's areas are fully covered by other,
414
+ // better, retained tiles. They are not drawn separately.
415
+ this._coveredTiles = {};
416
+
417
+ let idealTileIDs;
418
+ if (!this.used) {
419
+ idealTileIDs = [];
420
+ } else if (this._source.tileID) {
421
+ idealTileIDs = transform
422
+ .getVisibleUnwrappedCoordinates(this._source.tileID)
423
+ .map(
424
+ unwrapped =>
425
+ new OverscaledTileID(
426
+ unwrapped.canonical.z,
427
+ unwrapped.wrap,
428
+ unwrapped.canonical.z,
429
+ unwrapped.canonical.x,
430
+ unwrapped.canonical.y
431
+ )
432
+ );
433
+ } else {
434
+ idealTileIDs = transform.coveringTiles({
435
+ tileSize: this._source.tileSize,
436
+ minzoom: this._source.minzoom,
437
+ maxzoom: this._source.maxzoom,
438
+ roundZoom: this._source.roundZoom,
439
+ reparseOverscaled: this._source.reparseOverscaled
440
+ });
441
+
442
+ if (this._source.hasTile) {
443
+ idealTileIDs = idealTileIDs.filter(coord => this._source.hasTile(coord));
444
+ }
445
+ }
446
+
447
+ // Determine the overzooming/underzooming amounts.
448
+ const zoom = (this._source.roundZoom ? Math.round : Math.floor)(this.getZoom(transform));
449
+ const minCoveringZoom = Math.max(zoom - SourceCache.maxOverzooming, this._source.minzoom);
450
+ const maxCoveringZoom = Math.max(zoom + SourceCache.maxUnderzooming, this._source.minzoom);
451
+
452
+ // Retain is a list of tiles that we shouldn't delete, even if they are not
453
+ // the most ideal tile for the current viewport. This may include tiles like
454
+ // parent or child tiles that are *already* loaded.
455
+ const retain = this._updateRetainedTiles(idealTileIDs, zoom);
456
+
457
+ if (isRasterType(this._source.type)) {
458
+ const parentsForFading = {};
459
+ const fadingTiles = {};
460
+ const ids = Object.keys(retain);
461
+ for (const id of ids) {
462
+ const tileID = retain[id];
463
+ assert(tileID.key === +id);
464
+
465
+ const tile = this._tiles[id];
466
+ if (!tile || (tile.fadeEndTime && tile.fadeEndTime <= browser.now())) continue;
467
+
468
+ // if the tile is loaded but still fading in, find parents to cross-fade with it
469
+ const parentTile = this.findLoadedParent(tileID, minCoveringZoom);
470
+ if (parentTile) {
471
+ this._addTile(parentTile.tileID);
472
+ parentsForFading[parentTile.tileID.key] = parentTile.tileID;
473
+ }
474
+
475
+ fadingTiles[id] = tileID;
476
+ }
477
+
478
+ // for tiles that are still fading in, also find children to cross-fade with
479
+ this._retainLoadedChildren(fadingTiles, zoom, maxCoveringZoom, retain);
480
+
481
+ for (const id in parentsForFading) {
482
+ if (!retain[id]) {
483
+ // If a tile is only needed for fading, mark it as covered so that it isn't rendered on it's own.
484
+ this._coveredTiles[id] = true;
485
+ retain[id] = parentsForFading[id];
486
+ }
487
+ }
488
+ }
489
+
490
+ for (const retainedId in retain) {
491
+ // Make sure retained tiles always clear any existing fade holds
492
+ // so that if they're removed again their fade timer starts fresh.
493
+ this._tiles[retainedId].clearFadeHold();
494
+ }
495
+
496
+ // Remove the tiles we don't need anymore.
497
+ const remove = keysDifference(this._tiles, retain);
498
+ for (const tileID of remove) {
499
+ const tile = this._tiles[tileID];
500
+ if (tile.hasSymbolBuckets && !tile.holdingForFade()) {
501
+ tile.setHoldDuration(this.map._fadeDuration);
502
+ } else if (!tile.hasSymbolBuckets || tile.symbolFadeFinished()) {
503
+ this._removeTile(tileID);
504
+ }
505
+ }
506
+ }
507
+
508
+ releaseSymbolFadeTiles() {
509
+ for (const id in this._tiles) {
510
+ if (this._tiles[id].holdingForFade()) {
511
+ this._removeTile(id);
512
+ }
513
+ }
514
+ }
515
+
516
+ _updateRetainedTiles(idealTileIDs, zoom) {
517
+ const retain = {};
518
+ const checked = {};
519
+ const minCoveringZoom = Math.max(zoom - SourceCache.maxOverzooming, this._source.minzoom);
520
+ const maxCoveringZoom = Math.max(zoom + SourceCache.maxUnderzooming, this._source.minzoom);
521
+
522
+ const missingTiles = {};
523
+ for (const tileID of idealTileIDs) {
524
+ const tile = this._addTile(tileID);
525
+
526
+ // retain the tile even if it's not loaded because it's an ideal tile.
527
+ retain[tileID.key] = tileID;
528
+
529
+ if (tile.hasData()) continue;
530
+
531
+ if (zoom < this._source.maxzoom) {
532
+ // save missing tiles that potentially have loaded children
533
+ missingTiles[tileID.key] = tileID;
534
+ }
535
+ }
536
+
537
+ // retain any loaded children of ideal tiles up to maxCoveringZoom
538
+ this._retainLoadedChildren(missingTiles, zoom, maxCoveringZoom, retain);
539
+
540
+ for (const tileID of idealTileIDs) {
541
+ let tile = this._tiles[tileID.key];
542
+
543
+ if (tile.hasData()) continue;
544
+
545
+ // The tile we require is not yet loaded or does not exist;
546
+ // Attempt to find children that fully cover it.
547
+
548
+ if (zoom + 1 > this._source.maxzoom) {
549
+ // We're looking for an overzoomed child tile.
550
+ const childCoord = tileID.children(this._source.maxzoom)[0];
551
+ const childTile = this.getTile(childCoord);
552
+ if (!!childTile && childTile.hasData()) {
553
+ retain[childCoord.key] = childCoord;
554
+ continue; // tile is covered by overzoomed child
555
+ }
556
+ } else {
557
+ // check if all 4 immediate children are loaded (i.e. the missing ideal tile is covered)
558
+ const children = tileID.children(this._source.maxzoom);
559
+
560
+ if (retain[children[0].key] && retain[children[1].key] && retain[children[2].key] && retain[children[3].key])
561
+ continue; // tile is covered by children
562
+ }
563
+
564
+ // We couldn't find child tiles that entirely cover the ideal tile; look for parents now.
565
+
566
+ // As we ascend up the tile pyramid of the ideal tile, we check whether the parent
567
+ // tile has been previously requested (and errored because we only loop over tiles with no data)
568
+ // in order to determine if we need to request its parent.
569
+ let parentWasRequested = tile.wasRequested();
570
+
571
+ for (let overscaledZ = tileID.overscaledZ - 1; overscaledZ >= minCoveringZoom; --overscaledZ) {
572
+ const parentId = tileID.scaledTo(overscaledZ);
573
+
574
+ // Break parent tile ascent if this route has been previously checked by another child.
575
+ if (checked[parentId.key]) break;
576
+ checked[parentId.key] = true;
577
+
578
+ tile = this.getTile(parentId);
579
+ if (!tile && parentWasRequested) {
580
+ tile = this._addTile(parentId);
581
+ }
582
+ if (tile) {
583
+ retain[parentId.key] = parentId;
584
+ // Save the current values, since they're the parent of the next iteration
585
+ // of the parent tile ascent loop.
586
+ parentWasRequested = tile.wasRequested();
587
+ if (tile.hasData()) break;
588
+ }
589
+ }
590
+ }
591
+
592
+ return retain;
593
+ }
594
+
595
+ /**
596
+ * Add a tile, given its coordinate, to the pyramid.
597
+ * @private
598
+ */
599
+ _addTile(tileID) {
600
+ let tile = this._tiles[tileID.key];
601
+ if (tile) return tile;
602
+
603
+ tile = this._cache.getAndRemove(tileID);
604
+ if (tile) {
605
+ // set the tileID because the cached tile could have had a different wrap value
606
+ tile.tileID = tileID;
607
+ this._state.initializeTileState(tile, this.map ? this.map.painter : null);
608
+ }
609
+
610
+ const cached = Boolean(tile);
611
+ if (!cached) {
612
+ tile = new Tile(tileID, this._source.tileSize * tileID.overscaleFactor());
613
+ this._loadTile(tile, this._tileLoaded.bind(this, tile, tileID.key, tile.state));
614
+ }
615
+
616
+ // Impossible, but silence flow.
617
+ if (!tile) return null;
618
+
619
+ tile.uses++;
620
+ this._tiles[tileID.key] = tile;
621
+ if (!cached) this._source.fire(new Event('dataloading', { tile: tile, coord: tile.tileID, dataType: 'source' }));
622
+
623
+ return tile;
624
+ }
625
+
626
+ /**
627
+ * Remove a tile, given its id, from the pyramid
628
+ * @private
629
+ */
630
+ _removeTile(id) {
631
+ const tile = this._tiles[id];
632
+ if (!tile) return;
633
+
634
+ tile.uses--;
635
+ delete this._tiles[id];
636
+
637
+ if (tile.uses > 0) return;
638
+
639
+ if (tile.hasData()) {
640
+ this._cache.add(tile);
641
+ } else {
642
+ tile.aborted = true;
643
+ this._abortTile(tile);
644
+ this._unloadTile(tile);
645
+ }
646
+ }
647
+
648
+ /**
649
+ * Remove all tiles from this pyramid
650
+ */
651
+ clearTiles() {
652
+ this._shouldReloadOnResume = false;
653
+ this._paused = false;
654
+
655
+ for (const id in this._tiles) this._removeTile(id);
656
+
657
+ this._cache.reset();
658
+ }
659
+
660
+ /**
661
+ * Search through our current tiles and attempt to find the tiles that
662
+ * cover the given bounds.
663
+ * @param pointQueryGeometry coordinates of the corners of bounding rectangle
664
+ * @returns {Array<Object>} result items have {tile, minX, maxX, minY, maxY}, where min/max bounding values are the given bounds transformed in into the coordinate space of this tile.
665
+ */
666
+ tilesIn(pointQueryGeometry, maxPitchScaleFactor, has3DLayer) {
667
+ const tileResults = [];
668
+
669
+ const transform = this.transform;
670
+ if (!transform) return tileResults;
671
+
672
+ const cameraPointQueryGeometry = has3DLayer
673
+ ? transform.getCameraQueryGeometry(pointQueryGeometry)
674
+ : pointQueryGeometry;
675
+
676
+ const queryGeometry = pointQueryGeometry.map(p => transform.pointCoordinate(p));
677
+ const cameraQueryGeometry = cameraPointQueryGeometry.map(p => transform.pointCoordinate(p));
678
+
679
+ const ids = this.getIds();
680
+
681
+ let minX = Number.POSITIVE_INFINITY;
682
+ let minY = Number.POSITIVE_INFINITY;
683
+ let maxX = Number.NEGATIVE_INFINITY;
684
+ let maxY = Number.NEGATIVE_INFINITY;
685
+ const z = queryGeometry[0].zoom;
686
+
687
+ for (const p of cameraQueryGeometry) {
688
+ minX = Math.min(minX, p.column);
689
+ minY = Math.min(minY, p.row);
690
+ maxX = Math.max(maxX, p.column);
691
+ maxY = Math.max(maxY, p.row);
692
+ }
693
+
694
+ for (let i = 0; i < ids.length; i++) {
695
+ const tile = this._tiles[ids[i]];
696
+ if (tile.holdingForFade()) {
697
+ // Tiles held for fading are covered by tiles that are closer to ideal
698
+ continue;
699
+ }
700
+ const tileID = tile.tileID;
701
+ const scale = 2 ** (transform.zoom - tile.tileID.overscaledZ);
702
+ const queryPadding = (maxPitchScaleFactor * tile.queryPadding * EXTENT) / tile.tileSize / scale;
703
+
704
+ const tileSpaceBounds = [
705
+ coordinateToTilePoint(tileID, new Coordinate(minX, minY, z)),
706
+ coordinateToTilePoint(tileID, new Coordinate(maxX, maxY, z))
707
+ ];
708
+
709
+ if (
710
+ tileSpaceBounds[0].x - queryPadding < EXTENT &&
711
+ tileSpaceBounds[0].y - queryPadding < EXTENT &&
712
+ tileSpaceBounds[1].x + queryPadding >= 0 &&
713
+ tileSpaceBounds[1].y + queryPadding >= 0
714
+ ) {
715
+ const tileSpaceQueryGeometry = queryGeometry.map(c => coordinateToTilePoint(tileID, c));
716
+ const tileSpaceCameraQueryGeometry = cameraQueryGeometry.map(c => coordinateToTilePoint(tileID, c));
717
+
718
+ tileResults.push({
719
+ tile,
720
+ tileID,
721
+ queryGeometry: tileSpaceQueryGeometry,
722
+ cameraQueryGeometry: tileSpaceCameraQueryGeometry,
723
+ scale
724
+ });
725
+ }
726
+ }
727
+
728
+ return tileResults;
729
+ }
730
+
731
+ getVisibleCoordinates(symbolLayer) {
732
+ const coords = this.getRenderableIds(symbolLayer).map(id => this._tiles[id].tileID);
733
+ for (const coord of coords) {
734
+ coord.posMatrix = this.transform.calculatePosMatrix(coord.toUnwrapped());
735
+ }
736
+ return coords;
737
+ }
738
+
739
+ hasTransition() {
740
+ if (this._source.hasTransition()) {
741
+ return true;
742
+ }
743
+
744
+ if (isRasterType(this._source.type)) {
745
+ for (const id in this._tiles) {
746
+ const tile = this._tiles[id];
747
+ if (tile.fadeEndTime !== undefined && tile.fadeEndTime >= browser.now()) {
748
+ return true;
749
+ }
750
+ }
751
+ }
752
+
753
+ return false;
754
+ }
755
+
756
+ /**
757
+ * Set the value of a particular state for a feature
758
+ * @private
759
+ */
760
+ setFeatureState(sourceLayer, feature, state) {
761
+ sourceLayer = sourceLayer || '_geojsonTileLayer';
762
+ this._state.updateState(sourceLayer, feature, state);
763
+ }
764
+
765
+ /**
766
+ * Get the entire state object for a feature
767
+ * @private
768
+ */
769
+ getFeatureState(sourceLayer, feature) {
770
+ sourceLayer = sourceLayer || '_geojsonTileLayer';
771
+ return this._state.getState(sourceLayer, feature);
772
+ }
773
+ }
774
+
775
+ SourceCache.maxOverzooming = 10;
776
+ SourceCache.maxUnderzooming = 3;
777
+
778
+ /**
779
+ * Convert a coordinate to a point in a tile's coordinate space.
780
+ * @private
781
+ */
782
+ function coordinateToTilePoint(tileID, coord) {
783
+ const zoomedCoord = coord.zoomTo(tileID.canonical.z);
784
+ return new Point(
785
+ (zoomedCoord.column - (tileID.canonical.x + tileID.wrap * 2 ** tileID.canonical.z)) * EXTENT,
786
+ (zoomedCoord.row - tileID.canonical.y) * EXTENT
787
+ );
788
+ }
789
+
790
+ function isRasterType(type) {
791
+ return type === 'raster' || type === 'image';
792
+ }
793
+
794
+ module.exports = SourceCache;