mapbox-gl 1.13.2

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