@mapgis/mapbox-gl 1.9.12 → 16.0.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 (435) hide show
  1. package/.flowconfig +61 -0
  2. package/LICENSE.txt +84 -0
  3. package/README.md +30 -13
  4. package/build/banner.js +4 -0
  5. package/build/check-bundle-size.js +140 -0
  6. package/build/generate-access-token-script.js +11 -0
  7. package/build/generate-flow-typed-style-spec.js +188 -0
  8. package/build/generate-release-list.js +21 -0
  9. package/build/generate-struct-arrays.js +237 -0
  10. package/build/generate-style-code.js +159 -0
  11. package/build/mapbox-gl.js.flow +3 -0
  12. package/build/print-release-url.js +6 -0
  13. package/build/rollup_plugin_minify_style_spec.js +20 -0
  14. package/build/rollup_plugins.js +80 -0
  15. package/build/run-node +3 -0
  16. package/build/run-tap +8 -0
  17. package/build/test/build-tape.js +19 -0
  18. package/dist/mapbox-gl.js +4 -4
  19. package/dist/mapbox-gl.js.map +1 -0
  20. package/flow-typed/gl.js +5 -0
  21. package/flow-typed/jsdom.js +18 -0
  22. package/flow-typed/mapbox-gl-supported.js +9 -0
  23. package/flow-typed/mapbox-unitbezier.js +14 -0
  24. package/flow-typed/offscreen-canvas.js +9 -0
  25. package/flow-typed/pbf.js +25 -0
  26. package/flow-typed/point-geometry.js +44 -0
  27. package/flow-typed/potpack.js +12 -0
  28. package/flow-typed/sinon.js +28 -0
  29. package/flow-typed/vector-tile.js +41 -0
  30. package/package.json +170 -19
  31. package/src/css/mapbox-gl.css +798 -0
  32. package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
  33. package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
  34. package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
  35. package/src/css/svg/mapboxgl-ctrl-geolocate.svg +5 -0
  36. package/src/css/svg/mapboxgl-ctrl-logo.svg +20 -0
  37. package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
  38. package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
  39. package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
  40. package/src/data/array_types.js +1095 -0
  41. package/src/data/bucket/circle_attributes.js +9 -0
  42. package/src/data/bucket/circle_bucket.js +204 -0
  43. package/src/data/bucket/fill_attributes.js +9 -0
  44. package/src/data/bucket/fill_bucket.js +233 -0
  45. package/src/data/bucket/fill_extrusion_attributes.js +10 -0
  46. package/src/data/bucket/fill_extrusion_bucket.js +289 -0
  47. package/src/data/bucket/heatmap_bucket.js +17 -0
  48. package/src/data/bucket/line_attributes.js +10 -0
  49. package/src/data/bucket/line_bucket.js +556 -0
  50. package/src/data/bucket/pattern_attributes.js +10 -0
  51. package/src/data/bucket/pattern_bucket_features.js +60 -0
  52. package/src/data/bucket/symbol_attributes.js +117 -0
  53. package/src/data/bucket/symbol_bucket.js +972 -0
  54. package/src/data/bucket.js +123 -0
  55. package/src/data/dem_data.js +125 -0
  56. package/src/data/extent.js +18 -0
  57. package/src/data/feature_index.js +321 -0
  58. package/src/data/feature_position_map.js +125 -0
  59. package/src/data/index_array_type.js +16 -0
  60. package/src/data/load_geometry.js +48 -0
  61. package/src/data/pos_attributes.js +6 -0
  62. package/src/data/program_configuration.js +687 -0
  63. package/src/data/raster_bounds_attributes.js +7 -0
  64. package/src/data/segment.js +76 -0
  65. package/src/geo/edge_insets.js +102 -0
  66. package/src/geo/lng_lat.js +165 -0
  67. package/src/geo/lng_lat_bounds.js +267 -0
  68. package/src/geo/mercator_coordinate.js +153 -0
  69. package/src/geo/transform.js +864 -0
  70. package/src/gl/color_mode.js +34 -0
  71. package/src/gl/context.js +298 -0
  72. package/src/gl/cull_face_mode.js +26 -0
  73. package/src/gl/depth_mode.js +29 -0
  74. package/src/gl/framebuffer.js +44 -0
  75. package/src/gl/index_buffer.js +55 -0
  76. package/src/gl/stencil_mode.js +30 -0
  77. package/src/gl/types.js +84 -0
  78. package/src/gl/value.js +520 -0
  79. package/src/gl/vertex_buffer.js +119 -0
  80. package/src/index.js +201 -0
  81. package/src/render/draw_background.js +57 -0
  82. package/src/render/draw_circle.js +113 -0
  83. package/src/render/draw_collision_debug.js +49 -0
  84. package/src/render/draw_custom.js +49 -0
  85. package/src/render/draw_debug.js +127 -0
  86. package/src/render/draw_fill.js +126 -0
  87. package/src/render/draw_fill_extrusion.js +96 -0
  88. package/src/render/draw_heatmap.js +140 -0
  89. package/src/render/draw_hillshade.js +108 -0
  90. package/src/render/draw_line.js +98 -0
  91. package/src/render/draw_raster.js +125 -0
  92. package/src/render/draw_symbol.js +394 -0
  93. package/src/render/glyph_atlas.js +71 -0
  94. package/src/render/glyph_manager.js +182 -0
  95. package/src/render/image_atlas.js +149 -0
  96. package/src/render/image_manager.js +306 -0
  97. package/src/render/line_atlas.js +210 -0
  98. package/src/render/painter.js +653 -0
  99. package/src/render/program/background_program.js +103 -0
  100. package/src/render/program/circle_program.js +69 -0
  101. package/src/render/program/clipping_mask_program.js +20 -0
  102. package/src/render/program/collision_program.js +49 -0
  103. package/src/render/program/debug_program.js +35 -0
  104. package/src/render/program/fill_extrusion_program.js +122 -0
  105. package/src/render/program/fill_program.js +126 -0
  106. package/src/render/program/heatmap_program.js +83 -0
  107. package/src/render/program/hillshade_program.js +122 -0
  108. package/src/render/program/line_program.js +207 -0
  109. package/src/render/program/pattern.js +102 -0
  110. package/src/render/program/program_uniforms.js +42 -0
  111. package/src/render/program/raster_program.js +92 -0
  112. package/src/render/program/symbol_program.js +224 -0
  113. package/src/render/program.js +168 -0
  114. package/src/render/texture.js +122 -0
  115. package/src/render/uniform_binding.js +147 -0
  116. package/src/render/vertex_array_object.js +163 -0
  117. package/src/shaders/README.md +42 -0
  118. package/src/shaders/_prelude.fragment.glsl +17 -0
  119. package/src/shaders/_prelude.vertex.glsl +73 -0
  120. package/src/shaders/background.fragment.glsl +10 -0
  121. package/src/shaders/background.vertex.glsl +7 -0
  122. package/src/shaders/background_pattern.fragment.glsl +28 -0
  123. package/src/shaders/background_pattern.vertex.glsl +20 -0
  124. package/src/shaders/circle.fragment.glsl +39 -0
  125. package/src/shaders/circle.vertex.glsl +64 -0
  126. package/src/shaders/clipping_mask.fragment.glsl +3 -0
  127. package/src/shaders/clipping_mask.vertex.glsl +7 -0
  128. package/src/shaders/collision_box.fragment.glsl +21 -0
  129. package/src/shaders/collision_box.vertex.glsl +27 -0
  130. package/src/shaders/collision_circle.fragment.glsl +34 -0
  131. package/src/shaders/collision_circle.vertex.glsl +36 -0
  132. package/src/shaders/debug.fragment.glsl +9 -0
  133. package/src/shaders/debug.vertex.glsl +12 -0
  134. package/src/shaders/encode_attribute.js +17 -0
  135. package/src/shaders/fill.fragment.glsl +13 -0
  136. package/src/shaders/fill.vertex.glsl +13 -0
  137. package/src/shaders/fill_extrusion.fragment.glsl +9 -0
  138. package/src/shaders/fill_extrusion.vertex.glsl +66 -0
  139. package/src/shaders/fill_extrusion_pattern.fragment.glsl +45 -0
  140. package/src/shaders/fill_extrusion_pattern.vertex.glsl +79 -0
  141. package/src/shaders/fill_outline.fragment.glsl +17 -0
  142. package/src/shaders/fill_outline.vertex.glsl +17 -0
  143. package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
  144. package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
  145. package/src/shaders/fill_pattern.fragment.glsl +36 -0
  146. package/src/shaders/fill_pattern.vertex.glsl +39 -0
  147. package/src/shaders/heatmap.fragment.glsl +22 -0
  148. package/src/shaders/heatmap.vertex.glsl +54 -0
  149. package/src/shaders/heatmap_texture.fragment.glsl +14 -0
  150. package/src/shaders/heatmap_texture.vertex.glsl +11 -0
  151. package/src/shaders/hillshade.fragment.glsl +52 -0
  152. package/src/shaders/hillshade.vertex.glsl +11 -0
  153. package/src/shaders/hillshade_prepare.fragment.glsl +74 -0
  154. package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
  155. package/src/shaders/index.js +20 -0
  156. package/src/shaders/line.fragment.glsl +30 -0
  157. package/src/shaders/line.vertex.glsl +85 -0
  158. package/src/shaders/line_gradient.fragment.glsl +34 -0
  159. package/src/shaders/line_gradient.vertex.glsl +87 -0
  160. package/src/shaders/line_pattern.fragment.glsl +74 -0
  161. package/src/shaders/line_pattern.vertex.glsl +99 -0
  162. package/src/shaders/line_sdf.fragment.glsl +45 -0
  163. package/src/shaders/line_sdf.vertex.glsl +98 -0
  164. package/src/shaders/raster.fragment.glsl +52 -0
  165. package/src/shaders/raster.vertex.glsl +21 -0
  166. package/src/shaders/shaders.js +180 -0
  167. package/src/shaders/symbol_icon.fragment.glsl +17 -0
  168. package/src/shaders/symbol_icon.vertex.glsl +94 -0
  169. package/src/shaders/symbol_sdf.fragment.glsl +52 -0
  170. package/src/shaders/symbol_sdf.vertex.glsl +115 -0
  171. package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
  172. package/src/shaders/symbol_text_and_icon.vertex.glsl +116 -0
  173. package/src/source/canvas_source.js +238 -0
  174. package/src/source/geojson_helper.js +92 -0
  175. package/src/source/geojson_source.js +374 -0
  176. package/src/source/geojson_worker_source.js +357 -0
  177. package/src/source/geojson_wrapper.js +94 -0
  178. package/src/source/image_source.js +307 -0
  179. package/src/source/load_tilejson.js +39 -0
  180. package/src/source/mbtiles_source.js +115 -0
  181. package/src/source/offline_database.js +61 -0
  182. package/src/source/offline_database_root.js +62 -0
  183. package/src/source/pixels_to_tile_units.js +21 -0
  184. package/src/source/query_features.js +208 -0
  185. package/src/source/raster_dem_tile_source.js +138 -0
  186. package/src/source/raster_dem_tile_worker_source.js +62 -0
  187. package/src/source/raster_tile_offline_source.js +136 -0
  188. package/src/source/raster_tile_source.js +177 -0
  189. package/src/source/rtl_text_plugin.js +138 -0
  190. package/src/source/source.js +137 -0
  191. package/src/source/source_cache.js +957 -0
  192. package/src/source/source_state.js +159 -0
  193. package/src/source/tile.js +465 -0
  194. package/src/source/tile_bounds.js +38 -0
  195. package/src/source/tile_cache.js +212 -0
  196. package/src/source/tile_id.js +402 -0
  197. package/src/source/vector_tile_source.js +192 -0
  198. package/src/source/vector_tile_worker_source.js +216 -0
  199. package/src/source/video_source.js +203 -0
  200. package/src/source/worker.js +237 -0
  201. package/src/source/worker_source.js +106 -0
  202. package/src/source/worker_tile.js +224 -0
  203. package/src/style/create_style_layer.js +36 -0
  204. package/src/style/evaluation_parameters.js +62 -0
  205. package/src/style/light.js +130 -0
  206. package/src/style/load_glyph_range.js +38 -0
  207. package/src/style/load_sprite.js +67 -0
  208. package/src/style/parse_glyph_pbf.js +44 -0
  209. package/src/style/pauseable_placement.js +132 -0
  210. package/src/style/properties.js +753 -0
  211. package/src/style/query_utils.js +43 -0
  212. package/src/style/style.js +1361 -0
  213. package/src/style/style_glyph.js +17 -0
  214. package/src/style/style_image.js +137 -0
  215. package/src/style/style_layer/background_style_layer.js +21 -0
  216. package/src/style/style_layer/background_style_layer_properties.js +40 -0
  217. package/src/style/style_layer/circle_style_layer.js +98 -0
  218. package/src/style/style_layer/circle_style_layer_properties.js +63 -0
  219. package/src/style/style_layer/custom_style_layer.js +223 -0
  220. package/src/style/style_layer/fill_extrusion_style_layer.js +224 -0
  221. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +50 -0
  222. package/src/style/style_layer/fill_style_layer.js +67 -0
  223. package/src/style/style_layer/fill_style_layer_properties.js +55 -0
  224. package/src/style/style_layer/heatmap_style_layer.js +69 -0
  225. package/src/style/style_layer/heatmap_style_layer_properties.js +44 -0
  226. package/src/style/style_layer/hillshade_style_layer.js +25 -0
  227. package/src/style/style_layer/hillshade_style_layer_properties.js +46 -0
  228. package/src/style/style_layer/layer_properties.js.ejs +69 -0
  229. package/src/style/style_layer/line_style_layer.js +151 -0
  230. package/src/style/style_layer/line_style_layer_properties.js +71 -0
  231. package/src/style/style_layer/raster_style_layer.js +21 -0
  232. package/src/style/style_layer/raster_style_layer_properties.js +50 -0
  233. package/src/style/style_layer/symbol_style_layer.js +190 -0
  234. package/src/style/style_layer/symbol_style_layer_properties.js +153 -0
  235. package/src/style/style_layer/typed_style_layer.js +17 -0
  236. package/src/style/style_layer.js +281 -0
  237. package/src/style/style_layer_index.js +80 -0
  238. package/src/style/validate_style.js +42 -0
  239. package/src/style/zoom_history.js +44 -0
  240. package/src/style-spec/.eslintrc +5 -0
  241. package/src/style-spec/CHANGELOG.md +438 -0
  242. package/src/style-spec/README.md +59 -0
  243. package/src/style-spec/bin/gl-style-composite +9 -0
  244. package/src/style-spec/bin/gl-style-format +22 -0
  245. package/src/style-spec/bin/gl-style-migrate +9 -0
  246. package/src/style-spec/bin/gl-style-validate +50 -0
  247. package/src/style-spec/composite.js +50 -0
  248. package/src/style-spec/declass.js +42 -0
  249. package/src/style-spec/deref.js +52 -0
  250. package/src/style-spec/diff.js +393 -0
  251. package/src/style-spec/dist/.gitkeep +0 -0
  252. package/src/style-spec/empty.js +29 -0
  253. package/src/style-spec/error/parsing_error.js +16 -0
  254. package/src/style-spec/error/validation_error.js +18 -0
  255. package/src/style-spec/expression/compound_expression.js +162 -0
  256. package/src/style-spec/expression/definitions/assertion.js +130 -0
  257. package/src/style-spec/expression/definitions/at.js +70 -0
  258. package/src/style-spec/expression/definitions/case.js +85 -0
  259. package/src/style-spec/expression/definitions/coalesce.js +93 -0
  260. package/src/style-spec/expression/definitions/coercion.js +133 -0
  261. package/src/style-spec/expression/definitions/collator.js +78 -0
  262. package/src/style-spec/expression/definitions/comparison.js +184 -0
  263. package/src/style-spec/expression/definitions/format.js +144 -0
  264. package/src/style-spec/expression/definitions/format_section_override.js +54 -0
  265. package/src/style-spec/expression/definitions/image.js +52 -0
  266. package/src/style-spec/expression/definitions/in.js +92 -0
  267. package/src/style-spec/expression/definitions/index.js +561 -0
  268. package/src/style-spec/expression/definitions/interpolate.js +267 -0
  269. package/src/style-spec/expression/definitions/length.js +61 -0
  270. package/src/style-spec/expression/definitions/let.js +72 -0
  271. package/src/style-spec/expression/definitions/literal.js +77 -0
  272. package/src/style-spec/expression/definitions/match.js +158 -0
  273. package/src/style-spec/expression/definitions/number_format.js +142 -0
  274. package/src/style-spec/expression/definitions/step.js +120 -0
  275. package/src/style-spec/expression/definitions/var.js +46 -0
  276. package/src/style-spec/expression/definitions/within.js +333 -0
  277. package/src/style-spec/expression/evaluation_context.js +59 -0
  278. package/src/style-spec/expression/expression.js +27 -0
  279. package/src/style-spec/expression/index.js +392 -0
  280. package/src/style-spec/expression/is_constant.js +59 -0
  281. package/src/style-spec/expression/parsing_context.js +233 -0
  282. package/src/style-spec/expression/parsing_error.js +13 -0
  283. package/src/style-spec/expression/runtime_error.js +17 -0
  284. package/src/style-spec/expression/scope.js +36 -0
  285. package/src/style-spec/expression/stops.js +39 -0
  286. package/src/style-spec/expression/types/collator.js +61 -0
  287. package/src/style-spec/expression/types/formatted.js +73 -0
  288. package/src/style-spec/expression/types/resolved_image.js +29 -0
  289. package/src/style-spec/expression/types.js +106 -0
  290. package/src/style-spec/expression/values.js +123 -0
  291. package/src/style-spec/feature_filter/README.md +55 -0
  292. package/src/style-spec/feature_filter/convert.js +208 -0
  293. package/src/style-spec/feature_filter/index.js +165 -0
  294. package/src/style-spec/format.js +51 -0
  295. package/src/style-spec/function/convert.js +254 -0
  296. package/src/style-spec/function/index.js +262 -0
  297. package/src/style-spec/group_by_layout.js +75 -0
  298. package/src/style-spec/migrate/expressions.js +39 -0
  299. package/src/style-spec/migrate/v8.js +203 -0
  300. package/src/style-spec/migrate/v9.js +26 -0
  301. package/src/style-spec/migrate.js +36 -0
  302. package/src/style-spec/package.json +41 -0
  303. package/src/style-spec/read_style.js +14 -0
  304. package/src/style-spec/reference/latest.js +3 -0
  305. package/src/style-spec/reference/v8.json +5808 -0
  306. package/src/style-spec/rollup.config.js +45 -0
  307. package/src/style-spec/style-spec.js +122 -0
  308. package/src/style-spec/types.js +438 -0
  309. package/src/style-spec/util/color.js +95 -0
  310. package/src/style-spec/util/color_spaces.js +139 -0
  311. package/src/style-spec/util/deep_equal.js +28 -0
  312. package/src/style-spec/util/extend.js +10 -0
  313. package/src/style-spec/util/get_type.js +17 -0
  314. package/src/style-spec/util/interpolate.js +22 -0
  315. package/src/style-spec/util/properties.js +15 -0
  316. package/src/style-spec/util/ref_properties.js +2 -0
  317. package/src/style-spec/util/result.js +19 -0
  318. package/src/style-spec/util/unbundle_jsonlint.js +24 -0
  319. package/src/style-spec/validate/latest.js +11 -0
  320. package/src/style-spec/validate/validate.js +75 -0
  321. package/src/style-spec/validate/validate_array.js +52 -0
  322. package/src/style-spec/validate/validate_boolean.js +15 -0
  323. package/src/style-spec/validate/validate_color.js +20 -0
  324. package/src/style-spec/validate/validate_constants.js +13 -0
  325. package/src/style-spec/validate/validate_enum.js +21 -0
  326. package/src/style-spec/validate/validate_expression.js +43 -0
  327. package/src/style-spec/validate/validate_filter.js +111 -0
  328. package/src/style-spec/validate/validate_formatted.js +11 -0
  329. package/src/style-spec/validate/validate_function.js +207 -0
  330. package/src/style-spec/validate/validate_glyphs_url.js +21 -0
  331. package/src/style-spec/validate/validate_image.js +11 -0
  332. package/src/style-spec/validate/validate_layer.js +134 -0
  333. package/src/style-spec/validate/validate_layout_property.js +6 -0
  334. package/src/style-spec/validate/validate_light.js +47 -0
  335. package/src/style-spec/validate/validate_number.js +29 -0
  336. package/src/style-spec/validate/validate_object.js +61 -0
  337. package/src/style-spec/validate/validate_paint_property.js +6 -0
  338. package/src/style-spec/validate/validate_property.js +64 -0
  339. package/src/style-spec/validate/validate_source.js +111 -0
  340. package/src/style-spec/validate/validate_string.js +15 -0
  341. package/src/style-spec/validate_mapbox_api_supported.js +171 -0
  342. package/src/style-spec/validate_style.js +39 -0
  343. package/src/style-spec/validate_style.min.js +78 -0
  344. package/src/style-spec/visit.js +77 -0
  345. package/src/symbol/anchor.js +26 -0
  346. package/src/symbol/check_max_angle.js +81 -0
  347. package/src/symbol/clip_line.js +71 -0
  348. package/src/symbol/collision_feature.js +217 -0
  349. package/src/symbol/collision_index.js +372 -0
  350. package/src/symbol/cross_tile_symbol_index.js +301 -0
  351. package/src/symbol/get_anchors.js +167 -0
  352. package/src/symbol/grid_index.js +335 -0
  353. package/src/symbol/mergelines.js +82 -0
  354. package/src/symbol/one_em.js +4 -0
  355. package/src/symbol/opacity_state.js +27 -0
  356. package/src/symbol/placement.js +1062 -0
  357. package/src/symbol/projection.js +450 -0
  358. package/src/symbol/quads.js +334 -0
  359. package/src/symbol/shaping.js +816 -0
  360. package/src/symbol/symbol_layout.js +772 -0
  361. package/src/symbol/symbol_size.js +113 -0
  362. package/src/symbol/transform_text.js +29 -0
  363. package/src/types/callback.js +17 -0
  364. package/src/types/cancelable.js +3 -0
  365. package/src/types/tilejson.js +17 -0
  366. package/src/types/transferable.js +3 -0
  367. package/src/types/window.js +172 -0
  368. package/src/ui/anchor.js +32 -0
  369. package/src/ui/bind_handlers.js +202 -0
  370. package/src/ui/camera.js +1152 -0
  371. package/src/ui/control/attribution_control.js +189 -0
  372. package/src/ui/control/fps_control.js +185 -0
  373. package/src/ui/control/fullscreen_control.js +147 -0
  374. package/src/ui/control/geolocate_control.js +594 -0
  375. package/src/ui/control/logo_control.js +92 -0
  376. package/src/ui/control/navigation_control.js +148 -0
  377. package/src/ui/control/scale_control.js +142 -0
  378. package/src/ui/crs.js +64 -0
  379. package/src/ui/default_locale.js +20 -0
  380. package/src/ui/events.js +806 -0
  381. package/src/ui/handler/box_zoom.js +175 -0
  382. package/src/ui/handler/dblclick_zoom.js +139 -0
  383. package/src/ui/handler/drag_pan.js +416 -0
  384. package/src/ui/handler/drag_rotate.js +378 -0
  385. package/src/ui/handler/keyboard.js +161 -0
  386. package/src/ui/handler/scroll_zoom.js +333 -0
  387. package/src/ui/handler/touch_zoom_rotate.js +293 -0
  388. package/src/ui/hash.js +147 -0
  389. package/src/ui/map.js +2883 -0
  390. package/src/ui/marker.js +607 -0
  391. package/src/ui/offline_map.js +91 -0
  392. package/src/ui/popup.js +530 -0
  393. package/src/util/actor.js +212 -0
  394. package/src/util/ajax.js +371 -0
  395. package/src/util/browser/web_worker.js +10 -0
  396. package/src/util/browser/window.js +5 -0
  397. package/src/util/browser.js +70 -0
  398. package/src/util/classify_rings.js +52 -0
  399. package/src/util/color_ramp.js +28 -0
  400. package/src/util/config.js +30 -0
  401. package/src/util/debug.js +12 -0
  402. package/src/util/dictionary_coder.js +30 -0
  403. package/src/util/dispatcher.js +70 -0
  404. package/src/util/dom.js +144 -0
  405. package/src/util/evented.js +174 -0
  406. package/src/util/find_pole_of_inaccessibility.js +129 -0
  407. package/src/util/global_worker_pool.js +17 -0
  408. package/src/util/image.js +142 -0
  409. package/src/util/intersection_tests.js +208 -0
  410. package/src/util/is_char_in_unicode_block.js +311 -0
  411. package/src/util/mapbox.js +486 -0
  412. package/src/util/offscreen_canvas_supported.js +14 -0
  413. package/src/util/performance.js +112 -0
  414. package/src/util/primitives.js +145 -0
  415. package/src/util/resolve_tokens.js +16 -0
  416. package/src/util/script_detection.js +328 -0
  417. package/src/util/sku_token.js +42 -0
  418. package/src/util/smart_wrap.js +55 -0
  419. package/src/util/struct_array.js +243 -0
  420. package/src/util/struct_array.js.ejs +112 -0
  421. package/src/util/struct_array_layout.js.ejs +98 -0
  422. package/src/util/task_queue.js +68 -0
  423. package/src/util/throttle.js +28 -0
  424. package/src/util/throttled_invoker.js +46 -0
  425. package/src/util/tile_cover.js +101 -0
  426. package/src/util/tile_request_cache.js +172 -0
  427. package/src/util/util.js +504 -0
  428. package/src/util/vectortile_to_geojson.js +54 -0
  429. package/src/util/verticalize_punctuation.js +114 -0
  430. package/src/util/web_worker.js +91 -0
  431. package/src/util/web_worker_transfer.js +266 -0
  432. package/src/util/webp_supported.js +69 -0
  433. package/src/util/window.js +102 -0
  434. package/src/util/worker_pool.js +47 -0
  435. package/postcss.config.js +0 -16
@@ -0,0 +1,1062 @@
1
+ // @flow
2
+
3
+ import CollisionIndex from './collision_index';
4
+ import EXTENT from '../data/extent';
5
+ import * as symbolSize from './symbol_size';
6
+ import * as projection from './projection';
7
+ import {getAnchorJustification, evaluateVariableOffset} from './symbol_layout';
8
+ import {getAnchorAlignment, WritingMode} from './shaping';
9
+ import assert from 'assert';
10
+ import pixelsToTileUnits from '../source/pixels_to_tile_units';
11
+ import Point from '@mapbox/point-geometry';
12
+ import type Transform from '../geo/transform';
13
+ import type StyleLayer from '../style/style_layer';
14
+
15
+ import type Tile from '../source/tile';
16
+ import type SymbolBucket, {CollisionArrays, SingleCollisionBox} from '../data/bucket/symbol_bucket';
17
+ import type {mat4} from 'gl-matrix';
18
+ import type {CollisionBoxArray, CollisionVertexArray, SymbolInstance} from '../data/array_types';
19
+ import type FeatureIndex from '../data/feature_index';
20
+ import type {OverscaledTileID} from '../source/tile_id';
21
+ import type {TextAnchor} from './symbol_layout';
22
+
23
+ class OpacityState {
24
+ opacity: number;
25
+ placed: boolean;
26
+ constructor(prevState: ?OpacityState, increment: number, placed: boolean, skipFade: ?boolean) {
27
+ if (prevState) {
28
+ this.opacity = Math.max(0, Math.min(1, prevState.opacity + (prevState.placed ? increment : -increment)));
29
+ } else {
30
+ this.opacity = (skipFade && placed) ? 1 : 0;
31
+ }
32
+ this.placed = placed;
33
+ }
34
+ isHidden() {
35
+ return this.opacity === 0 && !this.placed;
36
+ }
37
+ }
38
+
39
+ class JointOpacityState {
40
+ text: OpacityState;
41
+ icon: OpacityState;
42
+ constructor(prevState: ?JointOpacityState, increment: number, placedText: boolean, placedIcon: boolean, skipFade: ?boolean) {
43
+ this.text = new OpacityState(prevState ? prevState.text : null, increment, placedText, skipFade);
44
+ this.icon = new OpacityState(prevState ? prevState.icon : null, increment, placedIcon, skipFade);
45
+ }
46
+ isHidden() {
47
+ return this.text.isHidden() && this.icon.isHidden();
48
+ }
49
+ }
50
+
51
+ class JointPlacement {
52
+ text: boolean;
53
+ icon: boolean;
54
+ // skipFade = outside viewport, but within CollisionIndex::viewportPadding px of the edge
55
+ // Because these symbols aren't onscreen yet, we can skip the "fade in" animation,
56
+ // and if a subsequent viewport change brings them into view, they'll be fully
57
+ // visible right away.
58
+ skipFade: boolean;
59
+ constructor(text: boolean, icon: boolean, skipFade: boolean) {
60
+ this.text = text;
61
+ this.icon = icon;
62
+ this.skipFade = skipFade;
63
+ }
64
+ }
65
+
66
+ export class RetainedQueryData {
67
+ bucketInstanceId: number;
68
+ featureIndex: FeatureIndex;
69
+ sourceLayerIndex: number;
70
+ bucketIndex: number;
71
+ tileID: OverscaledTileID;
72
+ featureSortOrder: ?Array<number>
73
+ constructor(bucketInstanceId: number,
74
+ featureIndex: FeatureIndex,
75
+ sourceLayerIndex: number,
76
+ bucketIndex: number,
77
+ tileID: OverscaledTileID) {
78
+ this.bucketInstanceId = bucketInstanceId;
79
+ this.featureIndex = featureIndex;
80
+ this.sourceLayerIndex = sourceLayerIndex;
81
+ this.bucketIndex = bucketIndex;
82
+ this.tileID = tileID;
83
+ }
84
+ }
85
+
86
+ type CollisionGroup = { ID: number, predicate?: any };
87
+
88
+ class CollisionGroups {
89
+ collisionGroups: {[groupName: string]: CollisionGroup};
90
+ maxGroupID: number;
91
+ crossSourceCollisions: boolean;
92
+
93
+ constructor(crossSourceCollisions: boolean) {
94
+ this.crossSourceCollisions = crossSourceCollisions;
95
+ this.maxGroupID = 0;
96
+ this.collisionGroups = {};
97
+ }
98
+
99
+ get(sourceID: string) {
100
+ // The predicate/groupID mechanism allows for arbitrary grouping,
101
+ // but the current interface defines one source == one group when
102
+ // crossSourceCollisions == true.
103
+ if (!this.crossSourceCollisions) {
104
+ if (!this.collisionGroups[sourceID]) {
105
+ const nextGroupID = ++this.maxGroupID;
106
+ this.collisionGroups[sourceID] = {
107
+ ID: nextGroupID,
108
+ predicate: (key) => {
109
+ return key.collisionGroupID === nextGroupID;
110
+ }
111
+ };
112
+ }
113
+ return this.collisionGroups[sourceID];
114
+ } else {
115
+ return {ID: 0, predicate: null};
116
+ }
117
+ }
118
+ }
119
+
120
+ function calculateVariableLayoutShift(anchor: TextAnchor, width: number, height: number, textOffset: [number, number], textBoxScale: number): Point {
121
+ const {horizontalAlign, verticalAlign} = getAnchorAlignment(anchor);
122
+ const shiftX = -(horizontalAlign - 0.5) * width;
123
+ const shiftY = -(verticalAlign - 0.5) * height;
124
+ const offset = evaluateVariableOffset(anchor, textOffset);
125
+ return new Point(
126
+ shiftX + offset[0] * textBoxScale,
127
+ shiftY + offset[1] * textBoxScale
128
+ );
129
+ }
130
+
131
+ function shiftVariableCollisionBox(collisionBox: SingleCollisionBox,
132
+ shiftX: number, shiftY: number,
133
+ rotateWithMap: boolean, pitchWithMap: boolean,
134
+ angle: number) {
135
+ const {x1, x2, y1, y2, anchorPointX, anchorPointY} = collisionBox;
136
+ const rotatedOffset = new Point(shiftX, shiftY);
137
+ if (rotateWithMap) {
138
+ rotatedOffset._rotate(pitchWithMap ? angle : -angle);
139
+ }
140
+ return {
141
+ x1: x1 + rotatedOffset.x,
142
+ y1: y1 + rotatedOffset.y,
143
+ x2: x2 + rotatedOffset.x,
144
+ y2: y2 + rotatedOffset.y,
145
+ // symbol anchor point stays the same regardless of text-anchor
146
+ anchorPointX,
147
+ anchorPointY
148
+ };
149
+ }
150
+
151
+ export type VariableOffset = {
152
+ textOffset: [number, number],
153
+ width: number,
154
+ height: number,
155
+ anchor: TextAnchor,
156
+ textBoxScale: number,
157
+ prevAnchor?: TextAnchor
158
+ };
159
+
160
+ type TileLayerParameters = {
161
+ bucket: SymbolBucket,
162
+ layout: any,
163
+ posMatrix: mat4,
164
+ textLabelPlaneMatrix: mat4,
165
+ scale: number,
166
+ textPixelRatio: number,
167
+ holdingForFade: boolean,
168
+ collisionBoxArray: ?CollisionBoxArray,
169
+ partiallyEvaluatedTextSize: any,
170
+ collisionGroup: any
171
+ };
172
+
173
+ export type BucketPart = {
174
+ sortKey?: number | void,
175
+ symbolInstanceStart: number,
176
+ symbolInstanceEnd: number,
177
+ parameters: TileLayerParameters
178
+ };
179
+
180
+ export type CrossTileID = string | number;
181
+
182
+ export class Placement {
183
+ transform: Transform;
184
+ collisionIndex: CollisionIndex;
185
+ placements: { [_: CrossTileID]: JointPlacement };
186
+ opacities: { [_: CrossTileID]: JointOpacityState };
187
+ variableOffsets: {[_: CrossTileID]: VariableOffset };
188
+ placedOrientations: {[_: CrossTileID]: number };
189
+ commitTime: number;
190
+ prevZoomAdjustment: number;
191
+ lastPlacementChangeTime: number;
192
+ stale: boolean;
193
+ fadeDuration: number;
194
+ retainedQueryData: {[_: number]: RetainedQueryData};
195
+ collisionGroups: CollisionGroups;
196
+ prevPlacement: ?Placement;
197
+ zoomAtLastRecencyCheck: number;
198
+
199
+ constructor(transform: Transform, fadeDuration: number, crossSourceCollisions: boolean, prevPlacement?: Placement) {
200
+ this.transform = transform.clone();
201
+ this.collisionIndex = new CollisionIndex(this.transform);
202
+ this.placements = {};
203
+ this.opacities = {};
204
+ this.variableOffsets = {};
205
+ this.stale = false;
206
+ this.commitTime = 0;
207
+ this.fadeDuration = fadeDuration;
208
+ this.retainedQueryData = {};
209
+ this.collisionGroups = new CollisionGroups(crossSourceCollisions);
210
+
211
+ this.prevPlacement = prevPlacement;
212
+ if (prevPlacement) {
213
+ prevPlacement.prevPlacement = undefined; // Only hold on to one placement back
214
+ }
215
+
216
+ this.placedOrientations = {};
217
+ }
218
+
219
+ getBucketParts(results: Array<BucketPart>, styleLayer: StyleLayer, tile: Tile, sortAcrossTiles: boolean) {
220
+ const symbolBucket = ((tile.getBucket(styleLayer): any): SymbolBucket);
221
+ const bucketFeatureIndex = tile.latestFeatureIndex;
222
+ if (!symbolBucket || !bucketFeatureIndex || styleLayer.id !== symbolBucket.layerIds[0])
223
+ return;
224
+
225
+ const collisionBoxArray = tile.collisionBoxArray;
226
+
227
+ const layout = symbolBucket.layers[0].layout;
228
+
229
+ const scale = Math.pow(2, this.transform.zoom - tile.tileID.overscaledZ);
230
+ const textPixelRatio = tile.tileSize / EXTENT;
231
+
232
+ const posMatrix = this.transform.calculatePosMatrix(tile.tileID.toUnwrapped());
233
+
234
+ const textLabelPlaneMatrix = projection.getLabelPlaneMatrix(posMatrix,
235
+ layout.get('text-pitch-alignment') === 'map',
236
+ layout.get('text-rotation-alignment') === 'map',
237
+ this.transform,
238
+ pixelsToTileUnits(tile, 1, this.transform.zoom));
239
+
240
+ // As long as this placement lives, we have to hold onto this bucket's
241
+ // matching FeatureIndex/data for querying purposes
242
+ this.retainedQueryData[symbolBucket.bucketInstanceId] = new RetainedQueryData(
243
+ symbolBucket.bucketInstanceId,
244
+ bucketFeatureIndex,
245
+ symbolBucket.sourceLayerIndex,
246
+ symbolBucket.index,
247
+ tile.tileID
248
+ );
249
+
250
+ const parameters = {
251
+ bucket: symbolBucket,
252
+ layout,
253
+ posMatrix,
254
+ textLabelPlaneMatrix,
255
+ scale,
256
+ textPixelRatio,
257
+ holdingForFade: tile.holdingForFade(),
258
+ collisionBoxArray,
259
+ partiallyEvaluatedTextSize: symbolSize.evaluateSizeForZoom(symbolBucket.textSizeData, this.transform.zoom),
260
+ collisionGroup: this.collisionGroups.get(symbolBucket.sourceID)
261
+ };
262
+
263
+ if (sortAcrossTiles) {
264
+ for (const range of symbolBucket.sortKeyRanges) {
265
+ const {sortKey, symbolInstanceStart, symbolInstanceEnd} = range;
266
+ results.push({sortKey, symbolInstanceStart, symbolInstanceEnd, parameters});
267
+ }
268
+ } else {
269
+ results.push({
270
+ symbolInstanceStart: 0,
271
+ symbolInstanceEnd: symbolBucket.symbolInstances.length,
272
+ parameters
273
+ });
274
+ }
275
+ }
276
+
277
+ attemptAnchorPlacement(anchor: TextAnchor, textBox: SingleCollisionBox, width: number, height: number,
278
+ textBoxScale: number, rotateWithMap: boolean,
279
+ pitchWithMap: boolean, textPixelRatio: number, posMatrix: mat4, collisionGroup: CollisionGroup,
280
+ textAllowOverlap: boolean, symbolInstance: SymbolInstance, bucket: SymbolBucket, orientation: number, iconBox: ?SingleCollisionBox): ?{ shift: Point, placedGlyphBoxes: { box: Array<number>, offscreen: boolean } } {
281
+
282
+ const textOffset = [symbolInstance.textOffset0, symbolInstance.textOffset1];
283
+ const shift = calculateVariableLayoutShift(anchor, width, height, textOffset, textBoxScale);
284
+
285
+ const placedGlyphBoxes = this.collisionIndex.placeCollisionBox(
286
+ shiftVariableCollisionBox(
287
+ textBox, shift.x, shift.y,
288
+ rotateWithMap, pitchWithMap, this.transform.angle),
289
+ textAllowOverlap, textPixelRatio, posMatrix, collisionGroup.predicate);
290
+
291
+ if (iconBox) {
292
+ const placedIconBoxes = this.collisionIndex.placeCollisionBox(
293
+ shiftVariableCollisionBox(
294
+ iconBox, shift.x, shift.y,
295
+ rotateWithMap, pitchWithMap, this.transform.angle),
296
+ textAllowOverlap, textPixelRatio, posMatrix, collisionGroup.predicate);
297
+ if (placedIconBoxes.box.length === 0) return;
298
+ }
299
+
300
+ if (placedGlyphBoxes.box.length > 0) {
301
+ let prevAnchor;
302
+ // If this label was placed in the previous placement, record the anchor position
303
+ // to allow us to animate the transition
304
+ if (this.prevPlacement &&
305
+ this.prevPlacement.variableOffsets[symbolInstance.crossTileID] &&
306
+ this.prevPlacement.placements[symbolInstance.crossTileID] &&
307
+ this.prevPlacement.placements[symbolInstance.crossTileID].text) {
308
+ prevAnchor = this.prevPlacement.variableOffsets[symbolInstance.crossTileID].anchor;
309
+ }
310
+ assert(symbolInstance.crossTileID !== 0);
311
+ this.variableOffsets[symbolInstance.crossTileID] = {
312
+ textOffset,
313
+ width,
314
+ height,
315
+ anchor,
316
+ textBoxScale,
317
+ prevAnchor
318
+ };
319
+ this.markUsedJustification(bucket, anchor, symbolInstance, orientation);
320
+
321
+ if (bucket.allowVerticalPlacement) {
322
+ this.markUsedOrientation(bucket, orientation, symbolInstance);
323
+ this.placedOrientations[symbolInstance.crossTileID] = orientation;
324
+ }
325
+
326
+ return {shift, placedGlyphBoxes};
327
+ }
328
+ }
329
+
330
+ placeLayerBucketPart(bucketPart: Object, seenCrossTileIDs: { [string | number]: boolean }, showCollisionBoxes: boolean) {
331
+
332
+ const {
333
+ bucket,
334
+ layout,
335
+ posMatrix,
336
+ textLabelPlaneMatrix,
337
+ scale,
338
+ textPixelRatio,
339
+ holdingForFade,
340
+ collisionBoxArray,
341
+ partiallyEvaluatedTextSize,
342
+ collisionGroup
343
+ } = bucketPart.parameters;
344
+
345
+ const textOptional = layout.get('text-optional');
346
+ const iconOptional = layout.get('icon-optional');
347
+ const textAllowOverlap = layout.get('text-allow-overlap');
348
+ const iconAllowOverlap = layout.get('icon-allow-overlap');
349
+ const rotateWithMap = layout.get('text-rotation-alignment') === 'map';
350
+ const pitchWithMap = layout.get('text-pitch-alignment') === 'map';
351
+ const hasIconTextFit = layout.get('icon-text-fit') !== 'none';
352
+ const zOrderByViewportY = layout.get('symbol-z-order') === 'viewport-y';
353
+
354
+ // This logic is similar to the "defaultOpacityState" logic below in updateBucketOpacities
355
+ // If we know a symbol is always supposed to show, force it to be marked visible even if
356
+ // it wasn't placed into the collision index (because some or all of it was outside the range
357
+ // of the collision grid).
358
+ // There is a subtle edge case here we're accepting:
359
+ // Symbol A has text-allow-overlap: true, icon-allow-overlap: true, icon-optional: false
360
+ // A's icon is outside the grid, so doesn't get placed
361
+ // A's text would be inside grid, but doesn't get placed because of icon-optional: false
362
+ // We still show A because of the allow-overlap settings.
363
+ // Symbol B has allow-overlap: false, and gets placed where A's text would be
364
+ // On panning in, there is a short period when Symbol B and Symbol A will overlap
365
+ // This is the reverse of our normal policy of "fade in on pan", but should look like any other
366
+ // collision and hopefully not be too noticeable.
367
+ // See https://github.com/mapbox/mapbox-gl-js/issues/7172
368
+ const alwaysShowText = textAllowOverlap && (iconAllowOverlap || !bucket.hasIconData() || iconOptional);
369
+ const alwaysShowIcon = iconAllowOverlap && (textAllowOverlap || !bucket.hasTextData() || textOptional);
370
+
371
+ if (!bucket.collisionArrays && collisionBoxArray) {
372
+ bucket.deserializeCollisionBoxes(collisionBoxArray);
373
+ }
374
+
375
+ const placeSymbol = (symbolInstance: SymbolInstance, collisionArrays: CollisionArrays) => {
376
+ if (seenCrossTileIDs[symbolInstance.crossTileID]) return;
377
+ if (holdingForFade) {
378
+ // Mark all symbols from this tile as "not placed", but don't add to seenCrossTileIDs, because we don't
379
+ // know yet if we have a duplicate in a parent tile that _should_ be placed.
380
+ this.placements[symbolInstance.crossTileID] = new JointPlacement(false, false, false);
381
+ return;
382
+ }
383
+
384
+ let placeText = false;
385
+ let placeIcon = false;
386
+ let offscreen = true;
387
+ let shift = null;
388
+
389
+ let placed = {box: null, offscreen: null};
390
+ let placedVerticalText = {box: null, offscreen: null};
391
+
392
+ let placedGlyphBoxes = null;
393
+ let placedGlyphCircles = null;
394
+ let placedIconBoxes = null;
395
+ let textFeatureIndex = 0;
396
+ let verticalTextFeatureIndex = 0;
397
+ let iconFeatureIndex = 0;
398
+
399
+ if (collisionArrays.textFeatureIndex) {
400
+ textFeatureIndex = collisionArrays.textFeatureIndex;
401
+ }
402
+ if (collisionArrays.verticalTextFeatureIndex) {
403
+ verticalTextFeatureIndex = collisionArrays.verticalTextFeatureIndex;
404
+ }
405
+
406
+ const textBox = collisionArrays.textBox;
407
+ if (textBox) {
408
+
409
+ const updatePreviousOrientationIfNotPlaced = (isPlaced) => {
410
+ let previousOrientation = WritingMode.horizontal;
411
+ if (bucket.allowVerticalPlacement && !isPlaced && this.prevPlacement) {
412
+ const prevPlacedOrientation = this.prevPlacement.placedOrientations[symbolInstance.crossTileID];
413
+ if (prevPlacedOrientation) {
414
+ this.placedOrientations[symbolInstance.crossTileID] = prevPlacedOrientation;
415
+ previousOrientation = prevPlacedOrientation;
416
+ this.markUsedOrientation(bucket, previousOrientation, symbolInstance);
417
+ }
418
+ }
419
+ return previousOrientation;
420
+ };
421
+
422
+ const placeTextForPlacementModes = (placeHorizontalFn, placeVerticalFn) => {
423
+ if (bucket.allowVerticalPlacement && symbolInstance.numVerticalGlyphVertices > 0 && collisionArrays.verticalTextBox) {
424
+ for (const placementMode of bucket.writingModes) {
425
+ if (placementMode === WritingMode.vertical) {
426
+ placed = placeVerticalFn();
427
+ placedVerticalText = placed;
428
+ } else {
429
+ placed = placeHorizontalFn();
430
+ }
431
+ if (placed && placed.box && placed.box.length) break;
432
+ }
433
+ } else {
434
+ placed = placeHorizontalFn();
435
+ }
436
+ };
437
+
438
+ if (!layout.get('text-variable-anchor')) {
439
+ const placeBox = (collisionTextBox, orientation) => {
440
+ const placedFeature = this.collisionIndex.placeCollisionBox(collisionTextBox, textAllowOverlap,
441
+ textPixelRatio, posMatrix, collisionGroup.predicate);
442
+ if (placedFeature && placedFeature.box && placedFeature.box.length) {
443
+ this.markUsedOrientation(bucket, orientation, symbolInstance);
444
+ this.placedOrientations[symbolInstance.crossTileID] = orientation;
445
+ }
446
+ return placedFeature;
447
+ };
448
+
449
+ const placeHorizontal = () => {
450
+ return placeBox(textBox, WritingMode.horizontal);
451
+ };
452
+
453
+ const placeVertical = () => {
454
+ const verticalTextBox = collisionArrays.verticalTextBox;
455
+ if (bucket.allowVerticalPlacement && symbolInstance.numVerticalGlyphVertices > 0 && verticalTextBox) {
456
+ return placeBox(verticalTextBox, WritingMode.vertical);
457
+ }
458
+ return {box: null, offscreen: null};
459
+ };
460
+
461
+ placeTextForPlacementModes(placeHorizontal, placeVertical);
462
+ updatePreviousOrientationIfNotPlaced(placed && placed.box && placed.box.length);
463
+
464
+ } else {
465
+ let anchors = layout.get('text-variable-anchor');
466
+
467
+ // If this symbol was in the last placement, shift the previously used
468
+ // anchor to the front of the anchor list, only if the previous anchor
469
+ // is still in the anchor list
470
+ if (this.prevPlacement && this.prevPlacement.variableOffsets[symbolInstance.crossTileID]) {
471
+ const prevOffsets = this.prevPlacement.variableOffsets[symbolInstance.crossTileID];
472
+ if (anchors.indexOf(prevOffsets.anchor) > 0) {
473
+ anchors = anchors.filter(anchor => anchor !== prevOffsets.anchor);
474
+ anchors.unshift(prevOffsets.anchor);
475
+ }
476
+ }
477
+
478
+ const placeBoxForVariableAnchors = (collisionTextBox, collisionIconBox, orientation) => {
479
+ const width = collisionTextBox.x2 - collisionTextBox.x1;
480
+ const height = collisionTextBox.y2 - collisionTextBox.y1;
481
+ const textBoxScale = symbolInstance.textBoxScale;
482
+
483
+ const variableIconBox = hasIconTextFit && !iconAllowOverlap ? collisionIconBox : null;
484
+
485
+ let placedBox: ?{ box: Array<number>, offscreen: boolean } = {box: [], offscreen: false};
486
+ const placementAttempts = textAllowOverlap ? anchors.length * 2 : anchors.length;
487
+ for (let i = 0; i < placementAttempts; ++i) {
488
+ const anchor = anchors[i % anchors.length];
489
+ const allowOverlap = (i >= anchors.length);
490
+ const result = this.attemptAnchorPlacement(
491
+ anchor, collisionTextBox, width, height,
492
+ textBoxScale, rotateWithMap, pitchWithMap, textPixelRatio, posMatrix,
493
+ collisionGroup, allowOverlap, symbolInstance, bucket, orientation, variableIconBox);
494
+
495
+ if (result) {
496
+ placedBox = result.placedGlyphBoxes;
497
+ if (placedBox && placedBox.box && placedBox.box.length) {
498
+ placeText = true;
499
+ shift = result.shift;
500
+ break;
501
+ }
502
+ }
503
+ }
504
+
505
+ return placedBox;
506
+ };
507
+
508
+ const placeHorizontal = () => {
509
+ return placeBoxForVariableAnchors(textBox, collisionArrays.iconBox, WritingMode.horizontal);
510
+ };
511
+
512
+ const placeVertical = () => {
513
+ const verticalTextBox = collisionArrays.verticalTextBox;
514
+ const wasPlaced = placed && placed.box && placed.box.length;
515
+ if (bucket.allowVerticalPlacement && !wasPlaced && symbolInstance.numVerticalGlyphVertices > 0 && verticalTextBox) {
516
+ return placeBoxForVariableAnchors(verticalTextBox, collisionArrays.verticalIconBox, WritingMode.vertical);
517
+ }
518
+ return {box: null, offscreen: null};
519
+ };
520
+
521
+ placeTextForPlacementModes(placeHorizontal, placeVertical);
522
+
523
+ if (placed) {
524
+ placeText = placed.box;
525
+ offscreen = placed.offscreen;
526
+ }
527
+
528
+ const prevOrientation = updatePreviousOrientationIfNotPlaced(placed && placed.box);
529
+
530
+ // If we didn't get placed, we still need to copy our position from the last placement for
531
+ // fade animations
532
+ if (!placeText && this.prevPlacement) {
533
+ const prevOffset = this.prevPlacement.variableOffsets[symbolInstance.crossTileID];
534
+ if (prevOffset) {
535
+ this.variableOffsets[symbolInstance.crossTileID] = prevOffset;
536
+ this.markUsedJustification(bucket, prevOffset.anchor, symbolInstance, prevOrientation);
537
+ }
538
+ }
539
+
540
+ }
541
+ }
542
+
543
+ placedGlyphBoxes = placed;
544
+ placeText = placedGlyphBoxes && placedGlyphBoxes.box && placedGlyphBoxes.box.length > 0;
545
+
546
+ offscreen = placedGlyphBoxes && placedGlyphBoxes.offscreen;
547
+ const textCircles = collisionArrays.textCircles;
548
+ if (textCircles) {
549
+ const placedSymbol = bucket.text.placedSymbolArray.get(symbolInstance.centerJustifiedTextSymbolIndex);
550
+ const fontSize = symbolSize.evaluateSizeForFeature(bucket.textSizeData, partiallyEvaluatedTextSize, placedSymbol);
551
+ placedGlyphCircles = this.collisionIndex.placeCollisionCircles(textCircles,
552
+ textAllowOverlap,
553
+ scale,
554
+ textPixelRatio,
555
+ placedSymbol,
556
+ bucket.lineVertexArray,
557
+ bucket.glyphOffsetArray,
558
+ fontSize,
559
+ posMatrix,
560
+ textLabelPlaneMatrix,
561
+ showCollisionBoxes,
562
+ pitchWithMap,
563
+ collisionGroup.predicate);
564
+ // If text-allow-overlap is set, force "placedCircles" to true
565
+ // In theory there should always be at least one circle placed
566
+ // in this case, but for now quirks in text-anchor
567
+ // and text-offset may prevent that from being true.
568
+ placeText = textAllowOverlap || placedGlyphCircles.circles.length > 0;
569
+ offscreen = offscreen && placedGlyphCircles.offscreen;
570
+ }
571
+
572
+ if (collisionArrays.iconFeatureIndex) {
573
+ iconFeatureIndex = collisionArrays.iconFeatureIndex;
574
+ }
575
+
576
+ if (collisionArrays.iconBox) {
577
+
578
+ const placeIconFeature = iconBox => {
579
+ const shiftedIconBox = hasIconTextFit && shift ?
580
+ shiftVariableCollisionBox(
581
+ iconBox, shift.x, shift.y,
582
+ rotateWithMap, pitchWithMap, this.transform.angle) :
583
+ iconBox;
584
+ return this.collisionIndex.placeCollisionBox(shiftedIconBox,
585
+ iconAllowOverlap, textPixelRatio, posMatrix, collisionGroup.predicate);
586
+ };
587
+
588
+ if (placedVerticalText && placedVerticalText.box && placedVerticalText.box.length && collisionArrays.verticalIconBox) {
589
+ placedIconBoxes = placeIconFeature(collisionArrays.verticalIconBox);
590
+ placeIcon = placedIconBoxes.box.length > 0;
591
+ } else {
592
+ placedIconBoxes = placeIconFeature(collisionArrays.iconBox);
593
+ placeIcon = placedIconBoxes.box.length > 0;
594
+ }
595
+ offscreen = offscreen && placedIconBoxes.offscreen;
596
+ }
597
+
598
+ const iconWithoutText = textOptional ||
599
+ (symbolInstance.numHorizontalGlyphVertices === 0 && symbolInstance.numVerticalGlyphVertices === 0);
600
+ const textWithoutIcon = iconOptional || symbolInstance.numIconVertices === 0;
601
+
602
+ // Combine the scales for icons and text.
603
+ if (!iconWithoutText && !textWithoutIcon) {
604
+ placeIcon = placeText = placeIcon && placeText;
605
+ } else if (!textWithoutIcon) {
606
+ placeText = placeIcon && placeText;
607
+ } else if (!iconWithoutText) {
608
+ placeIcon = placeIcon && placeText;
609
+ }
610
+
611
+ if (placeText && placedGlyphBoxes && placedGlyphBoxes.box) {
612
+ if (placedVerticalText && placedVerticalText.box && verticalTextFeatureIndex) {
613
+ this.collisionIndex.insertCollisionBox(placedGlyphBoxes.box, layout.get('text-ignore-placement'),
614
+ bucket.bucketInstanceId, verticalTextFeatureIndex, collisionGroup.ID);
615
+ } else {
616
+ this.collisionIndex.insertCollisionBox(placedGlyphBoxes.box, layout.get('text-ignore-placement'),
617
+ bucket.bucketInstanceId, textFeatureIndex, collisionGroup.ID);
618
+ }
619
+
620
+ }
621
+ if (placeIcon && placedIconBoxes) {
622
+ this.collisionIndex.insertCollisionBox(placedIconBoxes.box, layout.get('icon-ignore-placement'),
623
+ bucket.bucketInstanceId, iconFeatureIndex, collisionGroup.ID);
624
+ }
625
+ if (placeText && placedGlyphCircles) {
626
+ this.collisionIndex.insertCollisionCircles(placedGlyphCircles.circles, layout.get('text-ignore-placement'),
627
+ bucket.bucketInstanceId, textFeatureIndex, collisionGroup.ID);
628
+ }
629
+
630
+ assert(symbolInstance.crossTileID !== 0);
631
+ assert(bucket.bucketInstanceId !== 0);
632
+
633
+ this.placements[symbolInstance.crossTileID] = new JointPlacement(placeText || alwaysShowText, placeIcon || alwaysShowIcon, offscreen || bucket.justReloaded);
634
+ seenCrossTileIDs[symbolInstance.crossTileID] = true;
635
+ };
636
+
637
+ if (zOrderByViewportY) {
638
+ assert(bucketPart.symbolInstanceStart === 0);
639
+ const symbolIndexes = bucket.getSortedSymbolIndexes(this.transform.angle);
640
+ for (let i = symbolIndexes.length - 1; i >= 0; --i) {
641
+ const symbolIndex = symbolIndexes[i];
642
+ placeSymbol(bucket.symbolInstances.get(symbolIndex), bucket.collisionArrays[symbolIndex]);
643
+ }
644
+ } else {
645
+ for (let i = bucketPart.symbolInstanceStart; i < bucketPart.symbolInstanceEnd; i++) {
646
+ placeSymbol(bucket.symbolInstances.get(i), bucket.collisionArrays[i]);
647
+ }
648
+ }
649
+
650
+ bucket.justReloaded = false;
651
+ }
652
+
653
+ markUsedJustification(bucket: SymbolBucket, placedAnchor: TextAnchor, symbolInstance: SymbolInstance, orientation: number) {
654
+ const justifications = {
655
+ "left": symbolInstance.leftJustifiedTextSymbolIndex,
656
+ "center": symbolInstance.centerJustifiedTextSymbolIndex,
657
+ "right": symbolInstance.rightJustifiedTextSymbolIndex
658
+ };
659
+
660
+ let autoIndex;
661
+ if (orientation === WritingMode.vertical) {
662
+ autoIndex = symbolInstance.verticalPlacedTextSymbolIndex;
663
+ } else {
664
+ autoIndex = justifications[getAnchorJustification(placedAnchor)];
665
+ }
666
+
667
+ const indexes = [
668
+ symbolInstance.leftJustifiedTextSymbolIndex,
669
+ symbolInstance.centerJustifiedTextSymbolIndex,
670
+ symbolInstance.rightJustifiedTextSymbolIndex,
671
+ symbolInstance.verticalPlacedTextSymbolIndex
672
+ ];
673
+
674
+ for (const index of indexes) {
675
+ if (index >= 0) {
676
+ if (autoIndex >= 0 && index !== autoIndex) {
677
+ // There are multiple justifications and this one isn't it: shift offscreen
678
+ bucket.text.placedSymbolArray.get(index).crossTileID = 0;
679
+ } else {
680
+ // Either this is the chosen justification or the justification is hardwired: use this one
681
+ bucket.text.placedSymbolArray.get(index).crossTileID = symbolInstance.crossTileID;
682
+ }
683
+ }
684
+ }
685
+ }
686
+
687
+ markUsedOrientation(bucket: SymbolBucket, orientation: number, symbolInstance: SymbolInstance) {
688
+ const horizontal = (orientation === WritingMode.horizontal || orientation === WritingMode.horizontalOnly) ? orientation : 0;
689
+ const vertical = orientation === WritingMode.vertical ? orientation : 0;
690
+
691
+ const horizontalIndexes = [
692
+ symbolInstance.leftJustifiedTextSymbolIndex,
693
+ symbolInstance.centerJustifiedTextSymbolIndex,
694
+ symbolInstance.rightJustifiedTextSymbolIndex
695
+ ];
696
+
697
+ for (const index of horizontalIndexes) {
698
+ bucket.text.placedSymbolArray.get(index).placedOrientation = horizontal;
699
+ }
700
+
701
+ if (symbolInstance.verticalPlacedTextSymbolIndex) {
702
+ bucket.text.placedSymbolArray.get(symbolInstance.verticalPlacedTextSymbolIndex).placedOrientation = vertical;
703
+ }
704
+ }
705
+
706
+ commit(now: number): void {
707
+ this.commitTime = now;
708
+ this.zoomAtLastRecencyCheck = this.transform.zoom;
709
+
710
+ const prevPlacement = this.prevPlacement;
711
+ let placementChanged = false;
712
+
713
+ this.prevZoomAdjustment = prevPlacement ? prevPlacement.zoomAdjustment(this.transform.zoom) : 0;
714
+ const increment = prevPlacement ? prevPlacement.symbolFadeChange(now) : 1;
715
+
716
+ const prevOpacities = prevPlacement ? prevPlacement.opacities : {};
717
+ const prevOffsets = prevPlacement ? prevPlacement.variableOffsets : {};
718
+ const prevOrientations = prevPlacement ? prevPlacement.placedOrientations : {};
719
+
720
+ // add the opacities from the current placement, and copy their current values from the previous placement
721
+ for (const crossTileID in this.placements) {
722
+ const jointPlacement = this.placements[crossTileID];
723
+ const prevOpacity = prevOpacities[crossTileID];
724
+ if (prevOpacity) {
725
+ this.opacities[crossTileID] = new JointOpacityState(prevOpacity, increment, jointPlacement.text, jointPlacement.icon);
726
+ placementChanged = placementChanged ||
727
+ jointPlacement.text !== prevOpacity.text.placed ||
728
+ jointPlacement.icon !== prevOpacity.icon.placed;
729
+ } else {
730
+ this.opacities[crossTileID] = new JointOpacityState(null, increment, jointPlacement.text, jointPlacement.icon, jointPlacement.skipFade);
731
+ placementChanged = placementChanged || jointPlacement.text || jointPlacement.icon;
732
+ }
733
+ }
734
+
735
+ // copy and update values from the previous placement that aren't in the current placement but haven't finished fading
736
+ for (const crossTileID in prevOpacities) {
737
+ const prevOpacity = prevOpacities[crossTileID];
738
+ if (!this.opacities[crossTileID]) {
739
+ const jointOpacity = new JointOpacityState(prevOpacity, increment, false, false);
740
+ if (!jointOpacity.isHidden()) {
741
+ this.opacities[crossTileID] = jointOpacity;
742
+ placementChanged = placementChanged || prevOpacity.text.placed || prevOpacity.icon.placed;
743
+ }
744
+ }
745
+ }
746
+ for (const crossTileID in prevOffsets) {
747
+ if (!this.variableOffsets[crossTileID] && this.opacities[crossTileID] && !this.opacities[crossTileID].isHidden()) {
748
+ this.variableOffsets[crossTileID] = prevOffsets[crossTileID];
749
+ }
750
+ }
751
+
752
+ for (const crossTileID in prevOrientations) {
753
+ if (!this.placedOrientations[crossTileID] && this.opacities[crossTileID] && !this.opacities[crossTileID].isHidden()) {
754
+ this.placedOrientations[crossTileID] = prevOrientations[crossTileID];
755
+ }
756
+ }
757
+
758
+ // this.lastPlacementChangeTime is the time of the last commit() that
759
+ // resulted in a placement change -- in other words, the start time of
760
+ // the last symbol fade animation
761
+ assert(!prevPlacement || prevPlacement.lastPlacementChangeTime !== undefined);
762
+ if (placementChanged) {
763
+ this.lastPlacementChangeTime = now;
764
+ } else if (typeof this.lastPlacementChangeTime !== 'number') {
765
+ this.lastPlacementChangeTime = prevPlacement ? prevPlacement.lastPlacementChangeTime : now;
766
+ }
767
+ }
768
+
769
+ updateLayerOpacities(styleLayer: StyleLayer, tiles: Array<Tile>) {
770
+ const seenCrossTileIDs = {};
771
+ for (const tile of tiles) {
772
+ const symbolBucket = ((tile.getBucket(styleLayer): any): SymbolBucket);
773
+ if (symbolBucket && tile.latestFeatureIndex && styleLayer.id === symbolBucket.layerIds[0]) {
774
+ this.updateBucketOpacities(symbolBucket, seenCrossTileIDs, tile.collisionBoxArray);
775
+ }
776
+ }
777
+ }
778
+
779
+ updateBucketOpacities(bucket: SymbolBucket, seenCrossTileIDs: { [string | number]: boolean }, collisionBoxArray: ?CollisionBoxArray) {
780
+ if (bucket.hasTextData()) bucket.text.opacityVertexArray.clear();
781
+ if (bucket.hasIconData()) bucket.icon.opacityVertexArray.clear();
782
+ if (bucket.hasIconCollisionBoxData()) bucket.iconCollisionBox.collisionVertexArray.clear();
783
+ if (bucket.hasTextCollisionBoxData()) bucket.textCollisionBox.collisionVertexArray.clear();
784
+ if (bucket.hasIconCollisionCircleData()) bucket.iconCollisionCircle.collisionVertexArray.clear();
785
+ if (bucket.hasTextCollisionCircleData()) bucket.textCollisionCircle.collisionVertexArray.clear();
786
+
787
+ const layout = bucket.layers[0].layout;
788
+ const duplicateOpacityState = new JointOpacityState(null, 0, false, false, true);
789
+ const textAllowOverlap = layout.get('text-allow-overlap');
790
+ const iconAllowOverlap = layout.get('icon-allow-overlap');
791
+ const variablePlacement = layout.get('text-variable-anchor');
792
+ const rotateWithMap = layout.get('text-rotation-alignment') === 'map';
793
+ const pitchWithMap = layout.get('text-pitch-alignment') === 'map';
794
+ const hasIconTextFit = layout.get('icon-text-fit') !== 'none';
795
+ // If allow-overlap is true, we can show symbols before placement runs on them
796
+ // But we have to wait for placement if we potentially depend on a paired icon/text
797
+ // with allow-overlap: false.
798
+ // See https://github.com/mapbox/mapbox-gl-js/issues/7032
799
+ const defaultOpacityState = new JointOpacityState(null, 0,
800
+ textAllowOverlap && (iconAllowOverlap || !bucket.hasIconData() || layout.get('icon-optional')),
801
+ iconAllowOverlap && (textAllowOverlap || !bucket.hasTextData() || layout.get('text-optional')),
802
+ true);
803
+
804
+ if (!bucket.collisionArrays && collisionBoxArray && ((bucket.hasIconCollisionBoxData() || bucket.hasIconCollisionCircleData() ||
805
+ bucket.hasTextCollisionBoxData() || bucket.hasTextCollisionCircleData()))) {
806
+ bucket.deserializeCollisionBoxes(collisionBoxArray);
807
+ }
808
+
809
+ const addOpacities = (iconOrText, numVertices: number, opacity: number) => {
810
+ for (let i = 0; i < numVertices / 4; i++) {
811
+ iconOrText.opacityVertexArray.emplaceBack(opacity);
812
+ }
813
+ };
814
+
815
+ for (let s = 0; s < bucket.symbolInstances.length; s++) {
816
+ const symbolInstance = bucket.symbolInstances.get(s);
817
+ const {
818
+ numHorizontalGlyphVertices,
819
+ numVerticalGlyphVertices,
820
+ crossTileID
821
+ } = symbolInstance;
822
+
823
+ const isDuplicate = seenCrossTileIDs[crossTileID];
824
+
825
+ let opacityState = this.opacities[crossTileID];
826
+ if (isDuplicate) {
827
+ opacityState = duplicateOpacityState;
828
+ } else if (!opacityState) {
829
+ opacityState = defaultOpacityState;
830
+ // store the state so that future placements use it as a starting point
831
+ this.opacities[crossTileID] = opacityState;
832
+ }
833
+
834
+ seenCrossTileIDs[crossTileID] = true;
835
+
836
+ const hasText = numHorizontalGlyphVertices > 0 || numVerticalGlyphVertices > 0;
837
+ const hasIcon = symbolInstance.numIconVertices > 0;
838
+
839
+ const placedOrientation = this.placedOrientations[symbolInstance.crossTileID];
840
+ const horizontalHidden = placedOrientation === WritingMode.vertical;
841
+ const verticalHidden = placedOrientation === WritingMode.horizontal || placedOrientation === WritingMode.horizontalOnly;
842
+
843
+ if (hasText) {
844
+ const packedOpacity = packOpacity(opacityState.text);
845
+ // Vertical text fades in/out on collision the same way as corresponding
846
+ // horizontal text. Switch between vertical/horizontal should be instantaneous
847
+ const horizontalOpacity = horizontalHidden ? PACKED_HIDDEN_OPACITY : packedOpacity;
848
+ addOpacities(bucket.text, numHorizontalGlyphVertices, horizontalOpacity);
849
+ const verticalOpacity = verticalHidden ? PACKED_HIDDEN_OPACITY : packedOpacity;
850
+ addOpacities(bucket.text, numVerticalGlyphVertices, verticalOpacity);
851
+
852
+ // If this label is completely faded, mark it so that we don't have to calculate
853
+ // its position at render time. If this layer has variable placement, shift the various
854
+ // symbol instances appropriately so that symbols from buckets that have yet to be placed
855
+ // offset appropriately.
856
+ const symbolHidden = opacityState.text.isHidden();
857
+ [
858
+ symbolInstance.rightJustifiedTextSymbolIndex,
859
+ symbolInstance.centerJustifiedTextSymbolIndex,
860
+ symbolInstance.leftJustifiedTextSymbolIndex
861
+ ].forEach(index => {
862
+ if (index >= 0) {
863
+ bucket.text.placedSymbolArray.get(index).hidden = symbolHidden || horizontalHidden ? 1 : 0;
864
+ }
865
+ });
866
+
867
+ if (symbolInstance.verticalPlacedTextSymbolIndex >= 0) {
868
+ bucket.text.placedSymbolArray.get(symbolInstance.verticalPlacedTextSymbolIndex).hidden = symbolHidden || verticalHidden ? 1 : 0;
869
+ }
870
+
871
+ const prevOffset = this.variableOffsets[symbolInstance.crossTileID];
872
+ if (prevOffset) {
873
+ this.markUsedJustification(bucket, prevOffset.anchor, symbolInstance, placedOrientation);
874
+ }
875
+
876
+ const prevOrientation = this.placedOrientations[symbolInstance.crossTileID];
877
+ if (prevOrientation) {
878
+ this.markUsedJustification(bucket, 'left', symbolInstance, prevOrientation);
879
+ this.markUsedOrientation(bucket, prevOrientation, symbolInstance);
880
+ }
881
+ }
882
+
883
+ if (hasIcon) {
884
+ const packedOpacity = packOpacity(opacityState.icon);
885
+
886
+ const useHorizontal = !(hasIconTextFit && symbolInstance.verticalPlacedIconSymbolIndex && horizontalHidden);
887
+
888
+ if (symbolInstance.placedIconSymbolIndex >= 0) {
889
+ const horizontalOpacity = useHorizontal ? packedOpacity : PACKED_HIDDEN_OPACITY;
890
+ addOpacities(bucket.icon, symbolInstance.numIconVertices, horizontalOpacity);
891
+ bucket.icon.placedSymbolArray.get(symbolInstance.placedIconSymbolIndex).hidden =
892
+ (opacityState.icon.isHidden(): any);
893
+ }
894
+
895
+ if (symbolInstance.verticalPlacedIconSymbolIndex >= 0) {
896
+ const verticalOpacity = !useHorizontal ? packedOpacity : PACKED_HIDDEN_OPACITY;
897
+ addOpacities(bucket.icon, symbolInstance.numVerticalIconVertices, verticalOpacity);
898
+ bucket.icon.placedSymbolArray.get(symbolInstance.verticalPlacedIconSymbolIndex).hidden =
899
+ (opacityState.icon.isHidden(): any);
900
+ }
901
+ }
902
+
903
+ if (bucket.hasIconCollisionBoxData() || bucket.hasIconCollisionCircleData() ||
904
+ bucket.hasTextCollisionBoxData() || bucket.hasTextCollisionCircleData()) {
905
+ const collisionArrays = bucket.collisionArrays[s];
906
+ if (collisionArrays) {
907
+ let shift = new Point(0, 0);
908
+ if (collisionArrays.textBox || collisionArrays.verticalTextBox) {
909
+ let used = true;
910
+ if (variablePlacement) {
911
+ const variableOffset = this.variableOffsets[crossTileID];
912
+ if (variableOffset) {
913
+ // This will show either the currently placed position or the last
914
+ // successfully placed position (so you can visualize what collision
915
+ // just made the symbol disappear, and the most likely place for the
916
+ // symbol to come back)
917
+ shift = calculateVariableLayoutShift(variableOffset.anchor,
918
+ variableOffset.width,
919
+ variableOffset.height,
920
+ variableOffset.textOffset,
921
+ variableOffset.textBoxScale);
922
+ if (rotateWithMap) {
923
+ shift._rotate(pitchWithMap ? this.transform.angle : -this.transform.angle);
924
+ }
925
+ } else {
926
+ // No offset -> this symbol hasn't been placed since coming on-screen
927
+ // No single box is particularly meaningful and all of them would be too noisy
928
+ // Use the center box just to show something's there, but mark it "not used"
929
+ used = false;
930
+ }
931
+ }
932
+
933
+ if (collisionArrays.textBox) {
934
+ updateCollisionVertices(bucket.textCollisionBox.collisionVertexArray, opacityState.text.placed, !used || horizontalHidden, shift.x, shift.y);
935
+ }
936
+ if (collisionArrays.verticalTextBox) {
937
+ updateCollisionVertices(bucket.textCollisionBox.collisionVertexArray, opacityState.text.placed, !used || verticalHidden, shift.x, shift.y);
938
+ }
939
+ }
940
+
941
+ const verticalIconUsed = Boolean(!verticalHidden && collisionArrays.verticalIconBox);
942
+
943
+ if (collisionArrays.iconBox) {
944
+ updateCollisionVertices(bucket.iconCollisionBox.collisionVertexArray, opacityState.icon.placed, verticalIconUsed,
945
+ hasIconTextFit ? shift.x : 0,
946
+ hasIconTextFit ? shift.y : 0);
947
+ }
948
+
949
+ if (collisionArrays.verticalIconBox) {
950
+ updateCollisionVertices(bucket.iconCollisionBox.collisionVertexArray, opacityState.icon.placed, !verticalIconUsed,
951
+ hasIconTextFit ? shift.x : 0,
952
+ hasIconTextFit ? shift.y : 0);
953
+ }
954
+
955
+ const textCircles = collisionArrays.textCircles;
956
+ if (textCircles && bucket.hasTextCollisionCircleData()) {
957
+ for (let k = 0; k < textCircles.length; k += 5) {
958
+ const notUsed = isDuplicate || textCircles[k + 4] === 0;
959
+ updateCollisionVertices(bucket.textCollisionCircle.collisionVertexArray, opacityState.text.placed, notUsed);
960
+ }
961
+ }
962
+ }
963
+ }
964
+ }
965
+
966
+ bucket.sortFeatures(this.transform.angle);
967
+ if (this.retainedQueryData[bucket.bucketInstanceId]) {
968
+ this.retainedQueryData[bucket.bucketInstanceId].featureSortOrder = bucket.featureSortOrder;
969
+ }
970
+
971
+ if (bucket.hasTextData() && bucket.text.opacityVertexBuffer) {
972
+ bucket.text.opacityVertexBuffer.updateData(bucket.text.opacityVertexArray);
973
+ }
974
+ if (bucket.hasIconData() && bucket.icon.opacityVertexBuffer) {
975
+ bucket.icon.opacityVertexBuffer.updateData(bucket.icon.opacityVertexArray);
976
+ }
977
+ if (bucket.hasIconCollisionBoxData() && bucket.iconCollisionBox.collisionVertexBuffer) {
978
+ bucket.iconCollisionBox.collisionVertexBuffer.updateData(bucket.iconCollisionBox.collisionVertexArray);
979
+ }
980
+ if (bucket.hasTextCollisionBoxData() && bucket.textCollisionBox.collisionVertexBuffer) {
981
+ bucket.textCollisionBox.collisionVertexBuffer.updateData(bucket.textCollisionBox.collisionVertexArray);
982
+ }
983
+ if (bucket.hasIconCollisionCircleData() && bucket.iconCollisionCircle.collisionVertexBuffer) {
984
+ bucket.iconCollisionCircle.collisionVertexBuffer.updateData(bucket.iconCollisionCircle.collisionVertexArray);
985
+ }
986
+ if (bucket.hasTextCollisionCircleData() && bucket.textCollisionCircle.collisionVertexBuffer) {
987
+ bucket.textCollisionCircle.collisionVertexBuffer.updateData(bucket.textCollisionCircle.collisionVertexArray);
988
+ }
989
+
990
+ assert(bucket.text.opacityVertexArray.length === bucket.text.layoutVertexArray.length / 4);
991
+ assert(bucket.icon.opacityVertexArray.length === bucket.icon.layoutVertexArray.length / 4);
992
+ }
993
+
994
+ symbolFadeChange(now: number) {
995
+ return this.fadeDuration === 0 ?
996
+ 1 :
997
+ ((now - this.commitTime) / this.fadeDuration + this.prevZoomAdjustment);
998
+ }
999
+
1000
+ zoomAdjustment(zoom: number) {
1001
+ // When zooming out quickly, labels can overlap each other. This
1002
+ // adjustment is used to reduce the interval between placement calculations
1003
+ // and to reduce the fade duration when zooming out quickly. Discovering the
1004
+ // collisions more quickly and fading them more quickly reduces the unwanted effect.
1005
+ return Math.max(0, (this.transform.zoom - zoom) / 1.5);
1006
+ }
1007
+
1008
+ hasTransitions(now: number) {
1009
+ return this.stale ||
1010
+ now - this.lastPlacementChangeTime < this.fadeDuration;
1011
+ }
1012
+
1013
+ stillRecent(now: number, zoom: number) {
1014
+ // The adjustment makes placement more frequent when zooming.
1015
+ // This condition applies the adjustment only after the map has
1016
+ // stopped zooming. This avoids adding extra jank while zooming.
1017
+ const durationAdjustment = this.zoomAtLastRecencyCheck === zoom ?
1018
+ (1 - this.zoomAdjustment(zoom)) :
1019
+ 1;
1020
+ this.zoomAtLastRecencyCheck = zoom;
1021
+
1022
+ return this.commitTime + this.fadeDuration * durationAdjustment > now;
1023
+ }
1024
+
1025
+ setStale() {
1026
+ this.stale = true;
1027
+ }
1028
+ }
1029
+
1030
+ function updateCollisionVertices(collisionVertexArray: CollisionVertexArray, placed: boolean, notUsed: boolean | number, shiftX?: number, shiftY?: number) {
1031
+ collisionVertexArray.emplaceBack(placed ? 1 : 0, notUsed ? 1 : 0, shiftX || 0, shiftY || 0);
1032
+ collisionVertexArray.emplaceBack(placed ? 1 : 0, notUsed ? 1 : 0, shiftX || 0, shiftY || 0);
1033
+ collisionVertexArray.emplaceBack(placed ? 1 : 0, notUsed ? 1 : 0, shiftX || 0, shiftY || 0);
1034
+ collisionVertexArray.emplaceBack(placed ? 1 : 0, notUsed ? 1 : 0, shiftX || 0, shiftY || 0);
1035
+ }
1036
+
1037
+ // All four vertices for a glyph will have the same opacity state
1038
+ // So we pack the opacity into a uint8, and then repeat it four times
1039
+ // to make a single uint32 that we can upload for each glyph in the
1040
+ // label.
1041
+ const shift25 = Math.pow(2, 25);
1042
+ const shift24 = Math.pow(2, 24);
1043
+ const shift17 = Math.pow(2, 17);
1044
+ const shift16 = Math.pow(2, 16);
1045
+ const shift9 = Math.pow(2, 9);
1046
+ const shift8 = Math.pow(2, 8);
1047
+ const shift1 = Math.pow(2, 1);
1048
+ function packOpacity(opacityState: OpacityState): number {
1049
+ if (opacityState.opacity === 0 && !opacityState.placed) {
1050
+ return 0;
1051
+ } else if (opacityState.opacity === 1 && opacityState.placed) {
1052
+ return 4294967295;
1053
+ }
1054
+ const targetBit = opacityState.placed ? 1 : 0;
1055
+ const opacityBits = Math.floor(opacityState.opacity * 127);
1056
+ return opacityBits * shift25 + targetBit * shift24 +
1057
+ opacityBits * shift17 + targetBit * shift16 +
1058
+ opacityBits * shift9 + targetBit * shift8 +
1059
+ opacityBits * shift1 + targetBit;
1060
+ }
1061
+
1062
+ const PACKED_HIDDEN_OPACITY = 0;