@mapgis/mapbox-gl 1.9.12 → 16.0.0

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 (442) 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-csp-worker.js +2 -0
  19. package/dist/mapbox-gl-csp-worker.js.map +1 -0
  20. package/dist/mapbox-gl-csp.js +2 -0
  21. package/dist/mapbox-gl-csp.js.map +1 -0
  22. package/dist/mapbox-gl-dev.js +68798 -0
  23. package/dist/mapbox-gl-unminified.js +45076 -0
  24. package/dist/mapbox-gl-unminified.js.map +1 -0
  25. package/dist/mapbox-gl.js +4 -4
  26. package/dist/mapbox-gl.js.map +1 -0
  27. package/flow-typed/gl.js +5 -0
  28. package/flow-typed/jsdom.js +18 -0
  29. package/flow-typed/mapbox-gl-supported.js +9 -0
  30. package/flow-typed/mapbox-unitbezier.js +14 -0
  31. package/flow-typed/offscreen-canvas.js +9 -0
  32. package/flow-typed/pbf.js +25 -0
  33. package/flow-typed/point-geometry.js +44 -0
  34. package/flow-typed/potpack.js +12 -0
  35. package/flow-typed/sinon.js +28 -0
  36. package/flow-typed/vector-tile.js +41 -0
  37. package/package.json +171 -19
  38. package/src/css/mapbox-gl.css +798 -0
  39. package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
  40. package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
  41. package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
  42. package/src/css/svg/mapboxgl-ctrl-geolocate.svg +5 -0
  43. package/src/css/svg/mapboxgl-ctrl-logo.svg +20 -0
  44. package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
  45. package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
  46. package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
  47. package/src/data/array_types.js +1095 -0
  48. package/src/data/bucket/circle_attributes.js +9 -0
  49. package/src/data/bucket/circle_bucket.js +204 -0
  50. package/src/data/bucket/fill_attributes.js +9 -0
  51. package/src/data/bucket/fill_bucket.js +233 -0
  52. package/src/data/bucket/fill_extrusion_attributes.js +10 -0
  53. package/src/data/bucket/fill_extrusion_bucket.js +289 -0
  54. package/src/data/bucket/heatmap_bucket.js +17 -0
  55. package/src/data/bucket/line_attributes.js +10 -0
  56. package/src/data/bucket/line_bucket.js +556 -0
  57. package/src/data/bucket/pattern_attributes.js +10 -0
  58. package/src/data/bucket/pattern_bucket_features.js +60 -0
  59. package/src/data/bucket/symbol_attributes.js +117 -0
  60. package/src/data/bucket/symbol_bucket.js +972 -0
  61. package/src/data/bucket.js +123 -0
  62. package/src/data/dem_data.js +125 -0
  63. package/src/data/extent.js +18 -0
  64. package/src/data/feature_index.js +321 -0
  65. package/src/data/feature_position_map.js +125 -0
  66. package/src/data/index_array_type.js +16 -0
  67. package/src/data/load_geometry.js +48 -0
  68. package/src/data/pos_attributes.js +6 -0
  69. package/src/data/program_configuration.js +687 -0
  70. package/src/data/raster_bounds_attributes.js +7 -0
  71. package/src/data/segment.js +76 -0
  72. package/src/geo/edge_insets.js +102 -0
  73. package/src/geo/lng_lat.js +165 -0
  74. package/src/geo/lng_lat_bounds.js +267 -0
  75. package/src/geo/mercator_coordinate.js +153 -0
  76. package/src/geo/transform.js +864 -0
  77. package/src/gl/color_mode.js +34 -0
  78. package/src/gl/context.js +298 -0
  79. package/src/gl/cull_face_mode.js +26 -0
  80. package/src/gl/depth_mode.js +29 -0
  81. package/src/gl/framebuffer.js +44 -0
  82. package/src/gl/index_buffer.js +55 -0
  83. package/src/gl/stencil_mode.js +30 -0
  84. package/src/gl/types.js +84 -0
  85. package/src/gl/value.js +520 -0
  86. package/src/gl/vertex_buffer.js +119 -0
  87. package/src/index.js +201 -0
  88. package/src/render/draw_background.js +57 -0
  89. package/src/render/draw_circle.js +113 -0
  90. package/src/render/draw_collision_debug.js +49 -0
  91. package/src/render/draw_custom.js +49 -0
  92. package/src/render/draw_debug.js +127 -0
  93. package/src/render/draw_fill.js +126 -0
  94. package/src/render/draw_fill_extrusion.js +96 -0
  95. package/src/render/draw_heatmap.js +140 -0
  96. package/src/render/draw_hillshade.js +108 -0
  97. package/src/render/draw_line.js +98 -0
  98. package/src/render/draw_raster.js +125 -0
  99. package/src/render/draw_symbol.js +394 -0
  100. package/src/render/glyph_atlas.js +71 -0
  101. package/src/render/glyph_manager.js +182 -0
  102. package/src/render/image_atlas.js +149 -0
  103. package/src/render/image_manager.js +306 -0
  104. package/src/render/line_atlas.js +210 -0
  105. package/src/render/painter.js +653 -0
  106. package/src/render/program/background_program.js +103 -0
  107. package/src/render/program/circle_program.js +69 -0
  108. package/src/render/program/clipping_mask_program.js +20 -0
  109. package/src/render/program/collision_program.js +49 -0
  110. package/src/render/program/debug_program.js +35 -0
  111. package/src/render/program/fill_extrusion_program.js +122 -0
  112. package/src/render/program/fill_program.js +126 -0
  113. package/src/render/program/heatmap_program.js +83 -0
  114. package/src/render/program/hillshade_program.js +122 -0
  115. package/src/render/program/line_program.js +207 -0
  116. package/src/render/program/pattern.js +102 -0
  117. package/src/render/program/program_uniforms.js +42 -0
  118. package/src/render/program/raster_program.js +92 -0
  119. package/src/render/program/symbol_program.js +224 -0
  120. package/src/render/program.js +168 -0
  121. package/src/render/texture.js +122 -0
  122. package/src/render/uniform_binding.js +147 -0
  123. package/src/render/vertex_array_object.js +163 -0
  124. package/src/shaders/README.md +42 -0
  125. package/src/shaders/_prelude.fragment.glsl +17 -0
  126. package/src/shaders/_prelude.vertex.glsl +73 -0
  127. package/src/shaders/background.fragment.glsl +10 -0
  128. package/src/shaders/background.vertex.glsl +7 -0
  129. package/src/shaders/background_pattern.fragment.glsl +28 -0
  130. package/src/shaders/background_pattern.vertex.glsl +20 -0
  131. package/src/shaders/circle.fragment.glsl +39 -0
  132. package/src/shaders/circle.vertex.glsl +64 -0
  133. package/src/shaders/clipping_mask.fragment.glsl +3 -0
  134. package/src/shaders/clipping_mask.vertex.glsl +7 -0
  135. package/src/shaders/collision_box.fragment.glsl +21 -0
  136. package/src/shaders/collision_box.vertex.glsl +27 -0
  137. package/src/shaders/collision_circle.fragment.glsl +34 -0
  138. package/src/shaders/collision_circle.vertex.glsl +36 -0
  139. package/src/shaders/debug.fragment.glsl +9 -0
  140. package/src/shaders/debug.vertex.glsl +12 -0
  141. package/src/shaders/encode_attribute.js +17 -0
  142. package/src/shaders/fill.fragment.glsl +13 -0
  143. package/src/shaders/fill.vertex.glsl +13 -0
  144. package/src/shaders/fill_extrusion.fragment.glsl +9 -0
  145. package/src/shaders/fill_extrusion.vertex.glsl +66 -0
  146. package/src/shaders/fill_extrusion_pattern.fragment.glsl +45 -0
  147. package/src/shaders/fill_extrusion_pattern.vertex.glsl +79 -0
  148. package/src/shaders/fill_outline.fragment.glsl +17 -0
  149. package/src/shaders/fill_outline.vertex.glsl +17 -0
  150. package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
  151. package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
  152. package/src/shaders/fill_pattern.fragment.glsl +36 -0
  153. package/src/shaders/fill_pattern.vertex.glsl +39 -0
  154. package/src/shaders/heatmap.fragment.glsl +22 -0
  155. package/src/shaders/heatmap.vertex.glsl +54 -0
  156. package/src/shaders/heatmap_texture.fragment.glsl +14 -0
  157. package/src/shaders/heatmap_texture.vertex.glsl +11 -0
  158. package/src/shaders/hillshade.fragment.glsl +52 -0
  159. package/src/shaders/hillshade.vertex.glsl +11 -0
  160. package/src/shaders/hillshade_prepare.fragment.glsl +74 -0
  161. package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
  162. package/src/shaders/index.js +20 -0
  163. package/src/shaders/line.fragment.glsl +30 -0
  164. package/src/shaders/line.vertex.glsl +85 -0
  165. package/src/shaders/line_gradient.fragment.glsl +34 -0
  166. package/src/shaders/line_gradient.vertex.glsl +87 -0
  167. package/src/shaders/line_pattern.fragment.glsl +74 -0
  168. package/src/shaders/line_pattern.vertex.glsl +99 -0
  169. package/src/shaders/line_sdf.fragment.glsl +45 -0
  170. package/src/shaders/line_sdf.vertex.glsl +98 -0
  171. package/src/shaders/raster.fragment.glsl +52 -0
  172. package/src/shaders/raster.vertex.glsl +21 -0
  173. package/src/shaders/shaders.js +180 -0
  174. package/src/shaders/symbol_icon.fragment.glsl +17 -0
  175. package/src/shaders/symbol_icon.vertex.glsl +94 -0
  176. package/src/shaders/symbol_sdf.fragment.glsl +52 -0
  177. package/src/shaders/symbol_sdf.vertex.glsl +115 -0
  178. package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
  179. package/src/shaders/symbol_text_and_icon.vertex.glsl +116 -0
  180. package/src/source/canvas_source.js +238 -0
  181. package/src/source/geojson_helper.js +92 -0
  182. package/src/source/geojson_source.js +374 -0
  183. package/src/source/geojson_worker_source.js +357 -0
  184. package/src/source/geojson_wrapper.js +94 -0
  185. package/src/source/image_source.js +307 -0
  186. package/src/source/load_tilejson.js +39 -0
  187. package/src/source/mbtiles_source.js +115 -0
  188. package/src/source/offline_database.js +61 -0
  189. package/src/source/offline_database_root.js +62 -0
  190. package/src/source/pixels_to_tile_units.js +21 -0
  191. package/src/source/query_features.js +208 -0
  192. package/src/source/raster_dem_tile_source.js +138 -0
  193. package/src/source/raster_dem_tile_worker_source.js +62 -0
  194. package/src/source/raster_tile_offline_source.js +136 -0
  195. package/src/source/raster_tile_source.js +177 -0
  196. package/src/source/rtl_text_plugin.js +138 -0
  197. package/src/source/source.js +137 -0
  198. package/src/source/source_cache.js +957 -0
  199. package/src/source/source_state.js +159 -0
  200. package/src/source/tile.js +465 -0
  201. package/src/source/tile_bounds.js +38 -0
  202. package/src/source/tile_cache.js +212 -0
  203. package/src/source/tile_id.js +402 -0
  204. package/src/source/vector_tile_source.js +192 -0
  205. package/src/source/vector_tile_worker_source.js +216 -0
  206. package/src/source/video_source.js +203 -0
  207. package/src/source/worker.js +237 -0
  208. package/src/source/worker_source.js +106 -0
  209. package/src/source/worker_tile.js +224 -0
  210. package/src/style/create_style_layer.js +36 -0
  211. package/src/style/evaluation_parameters.js +62 -0
  212. package/src/style/light.js +130 -0
  213. package/src/style/load_glyph_range.js +38 -0
  214. package/src/style/load_sprite.js +67 -0
  215. package/src/style/parse_glyph_pbf.js +44 -0
  216. package/src/style/pauseable_placement.js +132 -0
  217. package/src/style/properties.js +753 -0
  218. package/src/style/query_utils.js +43 -0
  219. package/src/style/style.js +1361 -0
  220. package/src/style/style_glyph.js +17 -0
  221. package/src/style/style_image.js +137 -0
  222. package/src/style/style_layer/background_style_layer.js +21 -0
  223. package/src/style/style_layer/background_style_layer_properties.js +40 -0
  224. package/src/style/style_layer/circle_style_layer.js +98 -0
  225. package/src/style/style_layer/circle_style_layer_properties.js +63 -0
  226. package/src/style/style_layer/custom_style_layer.js +223 -0
  227. package/src/style/style_layer/fill_extrusion_style_layer.js +224 -0
  228. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +50 -0
  229. package/src/style/style_layer/fill_style_layer.js +67 -0
  230. package/src/style/style_layer/fill_style_layer_properties.js +55 -0
  231. package/src/style/style_layer/heatmap_style_layer.js +69 -0
  232. package/src/style/style_layer/heatmap_style_layer_properties.js +44 -0
  233. package/src/style/style_layer/hillshade_style_layer.js +25 -0
  234. package/src/style/style_layer/hillshade_style_layer_properties.js +46 -0
  235. package/src/style/style_layer/layer_properties.js.ejs +69 -0
  236. package/src/style/style_layer/line_style_layer.js +151 -0
  237. package/src/style/style_layer/line_style_layer_properties.js +71 -0
  238. package/src/style/style_layer/raster_style_layer.js +21 -0
  239. package/src/style/style_layer/raster_style_layer_properties.js +50 -0
  240. package/src/style/style_layer/symbol_style_layer.js +190 -0
  241. package/src/style/style_layer/symbol_style_layer_properties.js +153 -0
  242. package/src/style/style_layer/typed_style_layer.js +17 -0
  243. package/src/style/style_layer.js +281 -0
  244. package/src/style/style_layer_index.js +80 -0
  245. package/src/style/validate_style.js +42 -0
  246. package/src/style/zoom_history.js +44 -0
  247. package/src/style-spec/.eslintrc +5 -0
  248. package/src/style-spec/CHANGELOG.md +438 -0
  249. package/src/style-spec/README.md +59 -0
  250. package/src/style-spec/bin/gl-style-composite +9 -0
  251. package/src/style-spec/bin/gl-style-format +22 -0
  252. package/src/style-spec/bin/gl-style-migrate +9 -0
  253. package/src/style-spec/bin/gl-style-validate +50 -0
  254. package/src/style-spec/composite.js +50 -0
  255. package/src/style-spec/declass.js +42 -0
  256. package/src/style-spec/deref.js +52 -0
  257. package/src/style-spec/diff.js +393 -0
  258. package/src/style-spec/dist/.gitkeep +0 -0
  259. package/src/style-spec/empty.js +29 -0
  260. package/src/style-spec/error/parsing_error.js +16 -0
  261. package/src/style-spec/error/validation_error.js +18 -0
  262. package/src/style-spec/expression/compound_expression.js +162 -0
  263. package/src/style-spec/expression/definitions/assertion.js +130 -0
  264. package/src/style-spec/expression/definitions/at.js +70 -0
  265. package/src/style-spec/expression/definitions/case.js +85 -0
  266. package/src/style-spec/expression/definitions/coalesce.js +93 -0
  267. package/src/style-spec/expression/definitions/coercion.js +133 -0
  268. package/src/style-spec/expression/definitions/collator.js +78 -0
  269. package/src/style-spec/expression/definitions/comparison.js +184 -0
  270. package/src/style-spec/expression/definitions/format.js +144 -0
  271. package/src/style-spec/expression/definitions/format_section_override.js +54 -0
  272. package/src/style-spec/expression/definitions/image.js +52 -0
  273. package/src/style-spec/expression/definitions/in.js +92 -0
  274. package/src/style-spec/expression/definitions/index.js +561 -0
  275. package/src/style-spec/expression/definitions/interpolate.js +267 -0
  276. package/src/style-spec/expression/definitions/length.js +61 -0
  277. package/src/style-spec/expression/definitions/let.js +72 -0
  278. package/src/style-spec/expression/definitions/literal.js +77 -0
  279. package/src/style-spec/expression/definitions/match.js +158 -0
  280. package/src/style-spec/expression/definitions/number_format.js +142 -0
  281. package/src/style-spec/expression/definitions/step.js +120 -0
  282. package/src/style-spec/expression/definitions/var.js +46 -0
  283. package/src/style-spec/expression/definitions/within.js +333 -0
  284. package/src/style-spec/expression/evaluation_context.js +59 -0
  285. package/src/style-spec/expression/expression.js +27 -0
  286. package/src/style-spec/expression/index.js +392 -0
  287. package/src/style-spec/expression/is_constant.js +59 -0
  288. package/src/style-spec/expression/parsing_context.js +233 -0
  289. package/src/style-spec/expression/parsing_error.js +13 -0
  290. package/src/style-spec/expression/runtime_error.js +17 -0
  291. package/src/style-spec/expression/scope.js +36 -0
  292. package/src/style-spec/expression/stops.js +39 -0
  293. package/src/style-spec/expression/types/collator.js +61 -0
  294. package/src/style-spec/expression/types/formatted.js +73 -0
  295. package/src/style-spec/expression/types/resolved_image.js +29 -0
  296. package/src/style-spec/expression/types.js +106 -0
  297. package/src/style-spec/expression/values.js +123 -0
  298. package/src/style-spec/feature_filter/README.md +55 -0
  299. package/src/style-spec/feature_filter/convert.js +208 -0
  300. package/src/style-spec/feature_filter/index.js +165 -0
  301. package/src/style-spec/format.js +51 -0
  302. package/src/style-spec/function/convert.js +254 -0
  303. package/src/style-spec/function/index.js +262 -0
  304. package/src/style-spec/group_by_layout.js +75 -0
  305. package/src/style-spec/migrate/expressions.js +39 -0
  306. package/src/style-spec/migrate/v8.js +203 -0
  307. package/src/style-spec/migrate/v9.js +26 -0
  308. package/src/style-spec/migrate.js +36 -0
  309. package/src/style-spec/package.json +41 -0
  310. package/src/style-spec/read_style.js +14 -0
  311. package/src/style-spec/reference/latest.js +3 -0
  312. package/src/style-spec/reference/v8.json +5808 -0
  313. package/src/style-spec/rollup.config.js +45 -0
  314. package/src/style-spec/style-spec.js +122 -0
  315. package/src/style-spec/types.js +438 -0
  316. package/src/style-spec/util/color.js +95 -0
  317. package/src/style-spec/util/color_spaces.js +139 -0
  318. package/src/style-spec/util/deep_equal.js +28 -0
  319. package/src/style-spec/util/extend.js +10 -0
  320. package/src/style-spec/util/get_type.js +17 -0
  321. package/src/style-spec/util/interpolate.js +22 -0
  322. package/src/style-spec/util/properties.js +15 -0
  323. package/src/style-spec/util/ref_properties.js +2 -0
  324. package/src/style-spec/util/result.js +19 -0
  325. package/src/style-spec/util/unbundle_jsonlint.js +24 -0
  326. package/src/style-spec/validate/latest.js +11 -0
  327. package/src/style-spec/validate/validate.js +75 -0
  328. package/src/style-spec/validate/validate_array.js +52 -0
  329. package/src/style-spec/validate/validate_boolean.js +15 -0
  330. package/src/style-spec/validate/validate_color.js +20 -0
  331. package/src/style-spec/validate/validate_constants.js +13 -0
  332. package/src/style-spec/validate/validate_enum.js +21 -0
  333. package/src/style-spec/validate/validate_expression.js +43 -0
  334. package/src/style-spec/validate/validate_filter.js +111 -0
  335. package/src/style-spec/validate/validate_formatted.js +11 -0
  336. package/src/style-spec/validate/validate_function.js +207 -0
  337. package/src/style-spec/validate/validate_glyphs_url.js +21 -0
  338. package/src/style-spec/validate/validate_image.js +11 -0
  339. package/src/style-spec/validate/validate_layer.js +134 -0
  340. package/src/style-spec/validate/validate_layout_property.js +6 -0
  341. package/src/style-spec/validate/validate_light.js +47 -0
  342. package/src/style-spec/validate/validate_number.js +29 -0
  343. package/src/style-spec/validate/validate_object.js +61 -0
  344. package/src/style-spec/validate/validate_paint_property.js +6 -0
  345. package/src/style-spec/validate/validate_property.js +64 -0
  346. package/src/style-spec/validate/validate_source.js +111 -0
  347. package/src/style-spec/validate/validate_string.js +15 -0
  348. package/src/style-spec/validate_mapbox_api_supported.js +171 -0
  349. package/src/style-spec/validate_style.js +39 -0
  350. package/src/style-spec/validate_style.min.js +78 -0
  351. package/src/style-spec/visit.js +77 -0
  352. package/src/symbol/anchor.js +26 -0
  353. package/src/symbol/check_max_angle.js +81 -0
  354. package/src/symbol/clip_line.js +71 -0
  355. package/src/symbol/collision_feature.js +217 -0
  356. package/src/symbol/collision_index.js +372 -0
  357. package/src/symbol/cross_tile_symbol_index.js +301 -0
  358. package/src/symbol/get_anchors.js +167 -0
  359. package/src/symbol/grid_index.js +335 -0
  360. package/src/symbol/mergelines.js +82 -0
  361. package/src/symbol/one_em.js +4 -0
  362. package/src/symbol/opacity_state.js +27 -0
  363. package/src/symbol/placement.js +1062 -0
  364. package/src/symbol/projection.js +450 -0
  365. package/src/symbol/quads.js +334 -0
  366. package/src/symbol/shaping.js +816 -0
  367. package/src/symbol/symbol_layout.js +772 -0
  368. package/src/symbol/symbol_size.js +113 -0
  369. package/src/symbol/transform_text.js +29 -0
  370. package/src/types/callback.js +17 -0
  371. package/src/types/cancelable.js +3 -0
  372. package/src/types/tilejson.js +17 -0
  373. package/src/types/transferable.js +3 -0
  374. package/src/types/window.js +172 -0
  375. package/src/ui/anchor.js +32 -0
  376. package/src/ui/bind_handlers.js +202 -0
  377. package/src/ui/camera.js +1152 -0
  378. package/src/ui/control/attribution_control.js +189 -0
  379. package/src/ui/control/fps_control.js +185 -0
  380. package/src/ui/control/fullscreen_control.js +147 -0
  381. package/src/ui/control/geolocate_control.js +594 -0
  382. package/src/ui/control/logo_control.js +92 -0
  383. package/src/ui/control/navigation_control.js +148 -0
  384. package/src/ui/control/scale_control.js +142 -0
  385. package/src/ui/crs.js +64 -0
  386. package/src/ui/default_locale.js +20 -0
  387. package/src/ui/events.js +806 -0
  388. package/src/ui/handler/box_zoom.js +175 -0
  389. package/src/ui/handler/dblclick_zoom.js +139 -0
  390. package/src/ui/handler/drag_pan.js +416 -0
  391. package/src/ui/handler/drag_rotate.js +378 -0
  392. package/src/ui/handler/keyboard.js +161 -0
  393. package/src/ui/handler/scroll_zoom.js +333 -0
  394. package/src/ui/handler/touch_zoom_rotate.js +293 -0
  395. package/src/ui/hash.js +147 -0
  396. package/src/ui/map.js +2883 -0
  397. package/src/ui/marker.js +607 -0
  398. package/src/ui/offline_map.js +91 -0
  399. package/src/ui/popup.js +530 -0
  400. package/src/util/actor.js +212 -0
  401. package/src/util/ajax.js +371 -0
  402. package/src/util/browser/web_worker.js +10 -0
  403. package/src/util/browser/window.js +5 -0
  404. package/src/util/browser.js +70 -0
  405. package/src/util/classify_rings.js +52 -0
  406. package/src/util/color_ramp.js +28 -0
  407. package/src/util/config.js +30 -0
  408. package/src/util/debug.js +12 -0
  409. package/src/util/dictionary_coder.js +30 -0
  410. package/src/util/dispatcher.js +70 -0
  411. package/src/util/dom.js +144 -0
  412. package/src/util/evented.js +174 -0
  413. package/src/util/find_pole_of_inaccessibility.js +129 -0
  414. package/src/util/global_worker_pool.js +17 -0
  415. package/src/util/image.js +142 -0
  416. package/src/util/intersection_tests.js +208 -0
  417. package/src/util/is_char_in_unicode_block.js +311 -0
  418. package/src/util/mapbox.js +486 -0
  419. package/src/util/offscreen_canvas_supported.js +14 -0
  420. package/src/util/performance.js +112 -0
  421. package/src/util/primitives.js +145 -0
  422. package/src/util/resolve_tokens.js +16 -0
  423. package/src/util/script_detection.js +328 -0
  424. package/src/util/sku_token.js +42 -0
  425. package/src/util/smart_wrap.js +55 -0
  426. package/src/util/struct_array.js +243 -0
  427. package/src/util/struct_array.js.ejs +112 -0
  428. package/src/util/struct_array_layout.js.ejs +98 -0
  429. package/src/util/task_queue.js +68 -0
  430. package/src/util/throttle.js +28 -0
  431. package/src/util/throttled_invoker.js +46 -0
  432. package/src/util/tile_cover.js +101 -0
  433. package/src/util/tile_request_cache.js +172 -0
  434. package/src/util/util.js +504 -0
  435. package/src/util/vectortile_to_geojson.js +54 -0
  436. package/src/util/verticalize_punctuation.js +114 -0
  437. package/src/util/web_worker.js +91 -0
  438. package/src/util/web_worker_transfer.js +266 -0
  439. package/src/util/webp_supported.js +69 -0
  440. package/src/util/window.js +102 -0
  441. package/src/util/worker_pool.js +47 -0
  442. package/postcss.config.js +0 -16
@@ -0,0 +1,1361 @@
1
+ // @flow
2
+
3
+ import assert from 'assert';
4
+
5
+ import {Event, ErrorEvent, Evented} from '../util/evented';
6
+ import StyleLayer from './style_layer';
7
+ import createStyleLayer from './create_style_layer';
8
+ import loadSprite from './load_sprite';
9
+ import ImageManager from '../render/image_manager';
10
+ import GlyphManager from '../render/glyph_manager';
11
+ import Light from './light';
12
+ import LineAtlas from '../render/line_atlas';
13
+ import {pick, clone, extend, deepEqual, filterObject, mapObject} from '../util/util';
14
+ import {getJSON, getReferrer, makeRequest, ResourceType} from '../util/ajax';
15
+ import {isMapboxURL} from '../util/mapbox';
16
+ import browser from '../util/browser';
17
+ import Dispatcher from '../util/dispatcher';
18
+ import {validateStyle, emitValidationErrors as _emitValidationErrors} from './validate_style';
19
+ import {
20
+ getType as getSourceType,
21
+ setType as setSourceType,
22
+ type SourceClass
23
+ } from '../source/source';
24
+ import {queryRenderedFeatures, queryRenderedSymbols, querySourceFeatures} from '../source/query_features';
25
+ import SourceCache from '../source/source_cache';
26
+ import GeoJSONSource from '../source/geojson_source';
27
+ import styleSpec from '../style-spec/reference/latest';
28
+ import getWorkerPool from '../util/global_worker_pool';
29
+ import deref from '../style-spec/deref';
30
+ import emptyStyle from '../style-spec/empty';
31
+ import diffStyles, {operations as diffOperations} from '../style-spec/diff';
32
+ import {
33
+ registerForPluginStateChange,
34
+ evented as rtlTextPluginEvented,
35
+ triggerPluginCompletionEvent
36
+ } from '../source/rtl_text_plugin';
37
+ import PauseablePlacement from './pauseable_placement';
38
+ import ZoomHistory from './zoom_history';
39
+ import CrossTileSymbolIndex from '../symbol/cross_tile_symbol_index';
40
+ import {validateCustomStyleLayer} from './style_layer/custom_style_layer';
41
+
42
+ // We're skipping validation errors with the `source.canvas` identifier in order
43
+ // to continue to allow canvas sources to be added at runtime/updated in
44
+ // smart setStyle (see https://github.com/mapbox/mapbox-gl-js/pull/6424):
45
+ const emitValidationErrors = (evented: Evented, errors: ?$ReadOnlyArray<{message: string, identifier?: string}>) =>
46
+ _emitValidationErrors(evented, errors && errors.filter(error => error.identifier !== 'source.canvas'));
47
+
48
+ import type Map from '../ui/map';
49
+ import type Transform from '../geo/transform';
50
+ import type {StyleImage} from './style_image';
51
+ import type {StyleGlyph} from './style_glyph';
52
+ import type {Callback} from '../types/callback';
53
+ import type EvaluationParameters from './evaluation_parameters';
54
+ import type {Placement} from '../symbol/placement';
55
+ import type {Cancelable} from '../types/cancelable';
56
+ import type {RequestParameters, ResponseCallback} from '../util/ajax';
57
+ import type {GeoJSON} from '@mapbox/geojson-types';
58
+ import type {
59
+ LayerSpecification,
60
+ FilterSpecification,
61
+ StyleSpecification,
62
+ LightSpecification,
63
+ SourceSpecification
64
+ } from '../style-spec/types';
65
+ import type {CustomLayerInterface} from './style_layer/custom_style_layer';
66
+ import type {Validator} from './validate_style';
67
+ import type {OverscaledTileID} from '../source/tile_id';
68
+
69
+ const supportedDiffOperations = pick(diffOperations, [
70
+ 'addLayer',
71
+ 'removeLayer',
72
+ 'setPaintProperty',
73
+ 'setLayoutProperty',
74
+ 'setFilter',
75
+ 'addSource',
76
+ 'removeSource',
77
+ 'setLayerZoomRange',
78
+ 'setLight',
79
+ 'setTransition',
80
+ 'setGeoJSONSourceData'
81
+ // 'setGlyphs',
82
+ // 'setSprite',
83
+ ]);
84
+
85
+ const ignoredDiffOperations = pick(diffOperations, [
86
+ 'setCenter',
87
+ 'setZoom',
88
+ 'setBearing',
89
+ 'setPitch'
90
+ ]);
91
+
92
+ const empty = emptyStyle();
93
+
94
+ export type StyleOptions = {
95
+ validate?: boolean,
96
+ localIdeographFontFamily?: string
97
+ };
98
+
99
+ export type StyleSetterOptions = {
100
+ validate?: boolean
101
+ };
102
+ /**
103
+ * @private
104
+ */
105
+ class Style extends Evented {
106
+ map: Map;
107
+ stylesheet: StyleSpecification;
108
+ dispatcher: Dispatcher;
109
+ imageManager: ImageManager;
110
+ glyphManager: GlyphManager;
111
+ lineAtlas: LineAtlas;
112
+ light: Light;
113
+
114
+ _request: ?Cancelable;
115
+ _spriteRequest: ?Cancelable;
116
+ _layers: {[_: string]: StyleLayer};
117
+ _serializedLayers: {[_: string]: Object};
118
+ _order: Array<string>;
119
+ sourceCaches: {[_: string]: SourceCache};
120
+ zoomHistory: ZoomHistory;
121
+ _loaded: boolean;
122
+ _rtlTextPluginCallback: Function;
123
+ _changed: boolean;
124
+ _updatedSources: {[_: string]: 'clear' | 'reload'};
125
+ _updatedLayers: {[_: string]: true};
126
+ _removedLayers: {[_: string]: StyleLayer};
127
+ _changedImages: {[_: string]: true};
128
+ _updatedPaintProps: {[layer: string]: true};
129
+ _layerOrderChanged: boolean;
130
+ _availableImages: Array<string>;
131
+
132
+ crossTileSymbolIndex: CrossTileSymbolIndex;
133
+ pauseablePlacement: PauseablePlacement;
134
+ placement: Placement;
135
+ z: number;
136
+
137
+ // exposed to allow stubbing by unit tests
138
+ static getSourceType: typeof getSourceType;
139
+ static setSourceType: typeof setSourceType;
140
+ static registerForPluginStateChange: typeof registerForPluginStateChange;
141
+
142
+ constructor(map: Map, options: StyleOptions = {}) {
143
+ super();
144
+
145
+ this.map = map;
146
+ this.dispatcher = new Dispatcher(getWorkerPool(), this);
147
+ this.imageManager = new ImageManager();
148
+ this.imageManager.setEventedParent(this);
149
+ this.glyphManager = new GlyphManager(map._requestManager, options.localIdeographFontFamily);
150
+ this.lineAtlas = new LineAtlas(256, 512);
151
+ this.crossTileSymbolIndex = new CrossTileSymbolIndex();
152
+
153
+ this._layers = {};
154
+ this._serializedLayers = {};
155
+ this._order = [];
156
+ this.sourceCaches = {};
157
+ this.zoomHistory = new ZoomHistory();
158
+ this._loaded = false;
159
+ this._availableImages = [];
160
+
161
+ this._resetUpdates();
162
+
163
+ this.dispatcher.broadcast('setReferrer', getReferrer());
164
+
165
+ const self = this;
166
+ this._rtlTextPluginCallback = Style.registerForPluginStateChange((event) => {
167
+ const state = {
168
+ pluginStatus: event.pluginStatus,
169
+ pluginURL: event.pluginURL
170
+ };
171
+ self.dispatcher.broadcast('syncRTLPluginState', state, (err, results) => {
172
+ triggerPluginCompletionEvent(err);
173
+ if (results) {
174
+ const allComplete = results.every((elem) => elem);
175
+ if (allComplete) {
176
+ for (const id in self.sourceCaches) {
177
+ self.sourceCaches[id].reload(); // Should be a no-op if the plugin loads before any tiles load
178
+ }
179
+ }
180
+ }
181
+
182
+ });
183
+ });
184
+
185
+ this.on('data', (event) => {
186
+ if (event.dataType !== 'source' || event.sourceDataType !== 'metadata') {
187
+ return;
188
+ }
189
+
190
+ const sourceCache = this.sourceCaches[event.sourceId];
191
+ if (!sourceCache) {
192
+ return;
193
+ }
194
+
195
+ const source = sourceCache.getSource();
196
+ if (!source || !source.vectorLayerIds) {
197
+ return;
198
+ }
199
+
200
+ for (const layerId in this._layers) {
201
+ const layer = this._layers[layerId];
202
+ if (layer.source === source.id) {
203
+ this._validateLayer(layer);
204
+ }
205
+ }
206
+ });
207
+ }
208
+
209
+ loadURL(url: string, options: {
210
+ validate?: boolean,
211
+ accessToken?: string
212
+ } = {}) {
213
+ this.fire(new Event('dataloading', {dataType: 'style'}));
214
+
215
+ const validate = typeof options.validate === 'boolean' ?
216
+ options.validate : !isMapboxURL(url);
217
+
218
+ url = this.map._requestManager.normalizeStyleURL(url, options.accessToken);
219
+ const request = this.map._requestManager.transformRequest(url, ResourceType.Style);
220
+ this._request = getJSON(request, (error: ?Error, json: ?Object) => {
221
+ this._request = null;
222
+ if (error) {
223
+ this.fire(new ErrorEvent(error));
224
+ } else if (json) {
225
+ this._load(json, validate);
226
+ }
227
+ });
228
+ }
229
+
230
+ loadJSON(json: StyleSpecification, options: StyleSetterOptions = {}) {
231
+ this.fire(new Event('dataloading', {dataType: 'style'}));
232
+
233
+ this._request = browser.frame(() => {
234
+ this._request = null;
235
+ this._load(json, options.validate !== false);
236
+ });
237
+ }
238
+
239
+ loadEmpty() {
240
+ this.fire(new Event('dataloading', {dataType: 'style'}));
241
+ this._load(empty, false);
242
+ }
243
+
244
+ _load(json: StyleSpecification, validate: boolean) {
245
+ if (validate && emitValidationErrors(this, validateStyle(json))) {
246
+ return;
247
+ }
248
+
249
+ this._loaded = true;
250
+ this.stylesheet = json;
251
+
252
+ for (const id in json.sources) {
253
+ this.addSource(id, json.sources[id], {validate: false});
254
+ }
255
+
256
+ if (json.sprite) {
257
+ this._loadSprite(json.sprite);
258
+ } else {
259
+ this.imageManager.setLoaded(true);
260
+ }
261
+
262
+ this.glyphManager.setURL(json.glyphs);
263
+
264
+ const layers = deref(this.stylesheet.layers);
265
+
266
+ this._order = layers.map((layer) => layer.id);
267
+
268
+ this._layers = {};
269
+ this._serializedLayers = {};
270
+ for (let layer of layers) {
271
+ layer = createStyleLayer(layer);
272
+ layer.setEventedParent(this, {layer: {id: layer.id}});
273
+ this._layers[layer.id] = layer;
274
+ this._serializedLayers[layer.id] = layer.serialize();
275
+ }
276
+ this.dispatcher.broadcast('setLayers', this._serializeLayers(this._order));
277
+
278
+ this.light = new Light(this.stylesheet.light);
279
+
280
+ this.fire(new Event('data', {dataType: 'style'}));
281
+ this.fire(new Event('style.load'));
282
+ }
283
+
284
+ _loadSprite(url: string) {
285
+ this._spriteRequest = loadSprite(url, this.map._requestManager, (err, images) => {
286
+ this._spriteRequest = null;
287
+ if (err) {
288
+ this.fire(new ErrorEvent(err));
289
+ } else if (images) {
290
+ for (const id in images) {
291
+ this.imageManager.addImage(id, images[id]);
292
+ }
293
+ }
294
+
295
+ this.imageManager.setLoaded(true);
296
+ this._availableImages = this.imageManager.listImages();
297
+ this.dispatcher.broadcast('setImages', this._availableImages);
298
+ this.fire(new Event('data', {dataType: 'style'}));
299
+ });
300
+ }
301
+
302
+ _validateLayer(layer: StyleLayer) {
303
+ const sourceCache = this.sourceCaches[layer.source];
304
+ if (!sourceCache) {
305
+ return;
306
+ }
307
+
308
+ const sourceLayer = layer.sourceLayer;
309
+ if (!sourceLayer) {
310
+ return;
311
+ }
312
+
313
+ const source = sourceCache.getSource();
314
+ if (source.type === 'geojson' || (source.vectorLayerIds && source.vectorLayerIds.indexOf(sourceLayer) === -1)) {
315
+ this.fire(new ErrorEvent(new Error(
316
+ `Source layer "${sourceLayer}" ` +
317
+ `does not exist on source "${source.id}" ` +
318
+ `as specified by style layer "${layer.id}"`
319
+ )));
320
+ }
321
+ }
322
+
323
+ loaded() {
324
+ if (!this._loaded)
325
+ return false;
326
+
327
+ if (Object.keys(this._updatedSources).length)
328
+ return false;
329
+
330
+ for (const id in this.sourceCaches)
331
+ if (!this.sourceCaches[id].loaded())
332
+ return false;
333
+
334
+ if (!this.imageManager.isLoaded())
335
+ return false;
336
+
337
+ return true;
338
+ }
339
+
340
+ _serializeLayers(ids: Array<string>): Array<Object> {
341
+ const serializedLayers = [];
342
+ for (const id of ids) {
343
+ const layer = this._layers[id];
344
+ if (layer.type !== 'custom') {
345
+ serializedLayers.push(layer.serialize());
346
+ }
347
+ }
348
+ return serializedLayers;
349
+ }
350
+
351
+ hasTransitions() {
352
+ if (this.light && this.light.hasTransition()) {
353
+ return true;
354
+ }
355
+
356
+ for (const id in this.sourceCaches) {
357
+ if (this.sourceCaches[id].hasTransition()) {
358
+ return true;
359
+ }
360
+ }
361
+
362
+ for (const id in this._layers) {
363
+ if (this._layers[id].hasTransition()) {
364
+ return true;
365
+ }
366
+ }
367
+
368
+ return false;
369
+ }
370
+
371
+ _checkLoaded() {
372
+ if (!this._loaded) {
373
+ throw new Error('Style is not done loading');
374
+ }
375
+ }
376
+
377
+ /**
378
+ * Apply queued style updates in a batch and recalculate zoom-dependent paint properties.
379
+ * @private
380
+ */
381
+ update(parameters: EvaluationParameters) {
382
+ if (!this._loaded) {
383
+ return;
384
+ }
385
+
386
+ const changed = this._changed;
387
+ if (this._changed) {
388
+ const updatedIds = Object.keys(this._updatedLayers);
389
+ const removedIds = Object.keys(this._removedLayers);
390
+
391
+ if (updatedIds.length || removedIds.length) {
392
+ this._updateWorkerLayers(updatedIds, removedIds);
393
+ }
394
+ for (const id in this._updatedSources) {
395
+ const action = this._updatedSources[id];
396
+ assert(action === 'reload' || action === 'clear');
397
+ if (action === 'reload') {
398
+ this._reloadSource(id);
399
+ } else if (action === 'clear') {
400
+ this._clearSource(id);
401
+ }
402
+ }
403
+
404
+ this._updateTilesForChangedImages();
405
+
406
+ for (const id in this._updatedPaintProps) {
407
+ this._layers[id].updateTransitions(parameters);
408
+ }
409
+
410
+ this.light.updateTransitions(parameters);
411
+
412
+ this._resetUpdates();
413
+ }
414
+
415
+ for (const sourceId in this.sourceCaches) {
416
+ this.sourceCaches[sourceId].used = false;
417
+ }
418
+
419
+ for (const layerId of this._order) {
420
+ const layer = this._layers[layerId];
421
+
422
+ layer.recalculate(parameters, this._availableImages);
423
+ if (!layer.isHidden(parameters.zoom) && layer.source) {
424
+ this.sourceCaches[layer.source].used = true;
425
+ }
426
+ }
427
+
428
+ this.light.recalculate(parameters);
429
+ this.z = parameters.zoom;
430
+
431
+ if (changed) {
432
+ this.fire(new Event('data', {dataType: 'style'}));
433
+ }
434
+
435
+ }
436
+
437
+ /*
438
+ * Apply any queued image changes.
439
+ */
440
+ _updateTilesForChangedImages() {
441
+ const changedImages = Object.keys(this._changedImages);
442
+ if (changedImages.length) {
443
+ for (const name in this.sourceCaches) {
444
+ this.sourceCaches[name].reloadTilesForDependencies(['icons', 'patterns'], changedImages);
445
+ }
446
+ this._changedImages = {};
447
+ }
448
+ }
449
+
450
+ _updateWorkerLayers(updatedIds: Array<string>, removedIds: Array<string>) {
451
+ this.dispatcher.broadcast('updateLayers', {
452
+ layers: this._serializeLayers(updatedIds),
453
+ removedIds
454
+ });
455
+ }
456
+
457
+ _resetUpdates() {
458
+ this._changed = false;
459
+
460
+ this._updatedLayers = {};
461
+ this._removedLayers = {};
462
+
463
+ this._updatedSources = {};
464
+ this._updatedPaintProps = {};
465
+
466
+ this._changedImages = {};
467
+ }
468
+
469
+ /**
470
+ * Update this style's state to match the given style JSON, performing only
471
+ * the necessary mutations.
472
+ *
473
+ * May throw an Error ('Unimplemented: METHOD') if the mapbox-gl-style-spec
474
+ * diff algorithm produces an operation that is not supported.
475
+ *
476
+ * @returns {boolean} true if any changes were made; false otherwise
477
+ * @private
478
+ */
479
+ setState(nextState: StyleSpecification) {
480
+ this._checkLoaded();
481
+
482
+ if (emitValidationErrors(this, validateStyle(nextState))) return false;
483
+
484
+ nextState = clone(nextState);
485
+ nextState.layers = deref(nextState.layers);
486
+
487
+ const changes = diffStyles(this.serialize(), nextState)
488
+ .filter(op => !(op.command in ignoredDiffOperations));
489
+
490
+ if (changes.length === 0) {
491
+ return false;
492
+ }
493
+
494
+ const unimplementedOps = changes.filter(op => !(op.command in supportedDiffOperations));
495
+ if (unimplementedOps.length > 0) {
496
+ throw new Error(`Unimplemented: ${unimplementedOps.map(op => op.command).join(', ')}.`);
497
+ }
498
+
499
+ changes.forEach((op) => {
500
+ if (op.command === 'setTransition') {
501
+ // `transition` is always read directly off of
502
+ // `this.stylesheet`, which we update below
503
+ return;
504
+ }
505
+ (this: any)[op.command].apply(this, op.args);
506
+ });
507
+
508
+ this.stylesheet = nextState;
509
+
510
+ return true;
511
+ }
512
+
513
+ addImage(id: string, image: StyleImage) {
514
+ if (this.getImage(id)) {
515
+ return this.fire(new ErrorEvent(new Error('An image with this name already exists.')));
516
+ }
517
+ this.imageManager.addImage(id, image);
518
+ this._availableImages = this.imageManager.listImages();
519
+ this._changedImages[id] = true;
520
+ this._changed = true;
521
+ this.fire(new Event('data', {dataType: 'style'}));
522
+ }
523
+
524
+ updateImage(id: string, image: StyleImage) {
525
+ this.imageManager.updateImage(id, image);
526
+ }
527
+
528
+ getImage(id: string): ?StyleImage {
529
+ return this.imageManager.getImage(id);
530
+ }
531
+
532
+ removeImage(id: string) {
533
+ if (!this.getImage(id)) {
534
+ return this.fire(new ErrorEvent(new Error('No image with this name exists.')));
535
+ }
536
+ this.imageManager.removeImage(id);
537
+ this._availableImages = this.imageManager.listImages();
538
+ this._changedImages[id] = true;
539
+ this._changed = true;
540
+ this.fire(new Event('data', {dataType: 'style'}));
541
+ }
542
+
543
+ listImages() {
544
+ this._checkLoaded();
545
+
546
+ return this.imageManager.listImages();
547
+ }
548
+
549
+ addSource(id: string, source: SourceSpecification, options: StyleSetterOptions = {}) {
550
+ this._checkLoaded();
551
+
552
+ if (this.sourceCaches[id] !== undefined) {
553
+ throw new Error('There is already a source with this ID');
554
+ }
555
+
556
+ if (!source.type) {
557
+ throw new Error(`The type property must be defined, but the only the following properties were given: ${Object.keys(source).join(', ')}.`);
558
+ }
559
+
560
+ const builtIns = ['vector', 'raster', 'geojson', 'video', 'image'];
561
+ const shouldValidate = builtIns.indexOf(source.type) >= 0;
562
+ if (shouldValidate && this._validate(validateStyle.source, `sources.${id}`, source, null, options)) return;
563
+
564
+ if (this.map && this.map._collectResourceTiming) (source: any).collectResourceTiming = true;
565
+ const sourceCache = this.sourceCaches[id] = new SourceCache(id, source, this.dispatcher);
566
+ sourceCache.style = this;
567
+ sourceCache.setEventedParent(this, () => ({
568
+ isSourceLoaded: this.loaded(),
569
+ source: sourceCache.serialize(),
570
+ sourceId: id
571
+ }));
572
+
573
+ sourceCache.onAdd(this.map);
574
+ this._changed = true;
575
+ }
576
+
577
+ /**
578
+ * Remove a source from this stylesheet, given its id.
579
+ * @param {string} id id of the source to remove
580
+ * @throws {Error} if no source is found with the given ID
581
+ * @returns {Map} The {@link Map} object.
582
+ */
583
+ removeSource(id: string) {
584
+ this._checkLoaded();
585
+
586
+ if (this.sourceCaches[id] === undefined) {
587
+ throw new Error('There is no source with this ID');
588
+ }
589
+ for (const layerId in this._layers) {
590
+ if (this._layers[layerId].source === id) {
591
+ return this.fire(new ErrorEvent(new Error(`Source "${id}" cannot be removed while layer "${layerId}" is using it.`)));
592
+ }
593
+ }
594
+
595
+ const sourceCache = this.sourceCaches[id];
596
+ delete this.sourceCaches[id];
597
+ delete this._updatedSources[id];
598
+ sourceCache.fire(new Event('data', {sourceDataType: 'metadata', dataType:'source', sourceId: id}));
599
+ sourceCache.setEventedParent(null);
600
+ sourceCache.clearTiles();
601
+
602
+ if (sourceCache.onRemove) sourceCache.onRemove(this.map);
603
+ this._changed = true;
604
+ }
605
+
606
+ /**
607
+ * Set the data of a GeoJSON source, given its id.
608
+ * @param {string} id id of the source
609
+ * @param {GeoJSON|string} data GeoJSON source
610
+ */
611
+ setGeoJSONSourceData(id: string, data: GeoJSON | string) {
612
+ this._checkLoaded();
613
+
614
+ assert(this.sourceCaches[id] !== undefined, 'There is no source with this ID');
615
+ const geojsonSource: GeoJSONSource = (this.sourceCaches[id].getSource(): any);
616
+ assert(geojsonSource.type === 'geojson');
617
+
618
+ geojsonSource.setData(data);
619
+ this._changed = true;
620
+ }
621
+
622
+ /**
623
+ * Get a source by id.
624
+ * @param {string} id id of the desired source
625
+ * @returns {Object} source
626
+ */
627
+ getSource(id: string): Object {
628
+ return this.sourceCaches[id] && this.sourceCaches[id].getSource();
629
+ }
630
+
631
+ /**
632
+ * Add a layer to the map style. The layer will be inserted before the layer with
633
+ * ID `before`, or appended if `before` is omitted.
634
+ * @param {Object | CustomLayerInterface} layerObject The style layer to add.
635
+ * @param {string} [before] ID of an existing layer to insert before
636
+ * @param {Object} options Style setter options.
637
+ * @returns {Map} The {@link Map} object.
638
+ */
639
+ addLayer(layerObject: LayerSpecification | CustomLayerInterface, before?: string, options: StyleSetterOptions = {}) {
640
+ this._checkLoaded();
641
+
642
+ const id = layerObject.id;
643
+
644
+ if (this.getLayer(id)) {
645
+ this.fire(new ErrorEvent(new Error(`Layer with id "${id}" already exists on this map`)));
646
+ return;
647
+ }
648
+
649
+ let layer;
650
+ if (layerObject.type === 'custom') {
651
+
652
+ if (emitValidationErrors(this, validateCustomStyleLayer(layerObject))) return;
653
+
654
+ layer = createStyleLayer(layerObject);
655
+
656
+ } else {
657
+ if (typeof layerObject.source === 'object') {
658
+ this.addSource(id, layerObject.source);
659
+ layerObject = clone(layerObject);
660
+ layerObject = (extend(layerObject, {source: id}): any);
661
+ }
662
+
663
+ // this layer is not in the style.layers array, so we pass an impossible array index
664
+ if (this._validate(validateStyle.layer,
665
+ `layers.${id}`, layerObject, {arrayIndex: -1}, options)) return;
666
+
667
+ layer = createStyleLayer(layerObject);
668
+ this._validateLayer(layer);
669
+
670
+ layer.setEventedParent(this, {layer: {id}});
671
+ this._serializedLayers[layer.id] = layer.serialize();
672
+ }
673
+
674
+ const index = before ? this._order.indexOf(before) : this._order.length;
675
+ if (before && index === -1) {
676
+ this.fire(new ErrorEvent(new Error(`Layer with id "${before}" does not exist on this map.`)));
677
+ return;
678
+ }
679
+
680
+ this._order.splice(index, 0, id);
681
+ this._layerOrderChanged = true;
682
+
683
+ this._layers[id] = layer;
684
+
685
+ if (this._removedLayers[id] && layer.source && layer.type !== 'custom') {
686
+ // If, in the current batch, we have already removed this layer
687
+ // and we are now re-adding it with a different `type`, then we
688
+ // need to clear (rather than just reload) the underyling source's
689
+ // tiles. Otherwise, tiles marked 'reloading' will have buckets /
690
+ // buffers that are set up for the _previous_ version of this
691
+ // layer, causing, e.g.:
692
+ // https://github.com/mapbox/mapbox-gl-js/issues/3633
693
+ const removed = this._removedLayers[id];
694
+ delete this._removedLayers[id];
695
+ if (removed.type !== layer.type) {
696
+ this._updatedSources[layer.source] = 'clear';
697
+ } else {
698
+ this._updatedSources[layer.source] = 'reload';
699
+ this.sourceCaches[layer.source].pause();
700
+ }
701
+ }
702
+ this._updateLayer(layer);
703
+
704
+ if (layer.onAdd) {
705
+ layer.onAdd(this.map);
706
+ }
707
+ }
708
+
709
+ /**
710
+ * Moves a layer to a different z-position. The layer will be inserted before the layer with
711
+ * ID `before`, or appended if `before` is omitted.
712
+ * @param {string} id ID of the layer to move
713
+ * @param {string} [before] ID of an existing layer to insert before
714
+ */
715
+ moveLayer(id: string, before?: string) {
716
+ this._checkLoaded();
717
+ this._changed = true;
718
+
719
+ const layer = this._layers[id];
720
+ if (!layer) {
721
+ this.fire(new ErrorEvent(new Error(`The layer '${id}' does not exist in the map's style and cannot be moved.`)));
722
+ return;
723
+ }
724
+
725
+ if (id === before) {
726
+ return;
727
+ }
728
+
729
+ const index = this._order.indexOf(id);
730
+ this._order.splice(index, 1);
731
+
732
+ const newIndex = before ? this._order.indexOf(before) : this._order.length;
733
+ if (before && newIndex === -1) {
734
+ this.fire(new ErrorEvent(new Error(`Layer with id "${before}" does not exist on this map.`)));
735
+ return;
736
+ }
737
+ this._order.splice(newIndex, 0, id);
738
+
739
+ this._layerOrderChanged = true;
740
+ }
741
+
742
+ /**
743
+ * Remove the layer with the given id from the style.
744
+ *
745
+ * If no such layer exists, an `error` event is fired.
746
+ *
747
+ * @param {string} id id of the layer to remove
748
+ * @fires error
749
+ */
750
+ removeLayer(id: string) {
751
+ this._checkLoaded();
752
+
753
+ const layer = this._layers[id];
754
+ if (!layer) {
755
+ this.fire(new ErrorEvent(new Error(`The layer '${id}' does not exist in the map's style and cannot be removed.`)));
756
+ return;
757
+ }
758
+
759
+ layer.setEventedParent(null);
760
+
761
+ const index = this._order.indexOf(id);
762
+ this._order.splice(index, 1);
763
+
764
+ this._layerOrderChanged = true;
765
+ this._changed = true;
766
+ this._removedLayers[id] = layer;
767
+ delete this._layers[id];
768
+ delete this._serializedLayers[id];
769
+ delete this._updatedLayers[id];
770
+ delete this._updatedPaintProps[id];
771
+
772
+ if (layer.onRemove) {
773
+ layer.onRemove(this.map);
774
+ }
775
+ }
776
+
777
+ /**
778
+ * Return the style layer object with the given `id`.
779
+ *
780
+ * @param {string} id - id of the desired layer
781
+ * @returns {?Object} a layer, if one with the given `id` exists
782
+ */
783
+ getLayer(id: string): Object {
784
+ return this._layers[id];
785
+ }
786
+
787
+ /**
788
+ * checks if a specific layer is present within the style.
789
+ *
790
+ * @param {string} id - id of the desired layer
791
+ * @returns {boolean} a boolean specifying if the given layer is present
792
+ */
793
+ hasLayer(id: string): boolean {
794
+ return id in this._layers;
795
+ }
796
+
797
+ setLayerZoomRange(layerId: string, minzoom: ?number, maxzoom: ?number) {
798
+ this._checkLoaded();
799
+
800
+ const layer = this.getLayer(layerId);
801
+ if (!layer) {
802
+ this.fire(new ErrorEvent(new Error(`The layer '${layerId}' does not exist in the map's style and cannot have zoom extent.`)));
803
+ return;
804
+ }
805
+
806
+ if (layer.minzoom === minzoom && layer.maxzoom === maxzoom) return;
807
+
808
+ if (minzoom != null) {
809
+ layer.minzoom = minzoom;
810
+ }
811
+ if (maxzoom != null) {
812
+ layer.maxzoom = maxzoom;
813
+ }
814
+ this._updateLayer(layer);
815
+ }
816
+
817
+ setFilter(layerId: string, filter: ?FilterSpecification, options: StyleSetterOptions = {}) {
818
+ this._checkLoaded();
819
+
820
+ const layer = this.getLayer(layerId);
821
+ if (!layer) {
822
+ this.fire(new ErrorEvent(new Error(`The layer '${layerId}' does not exist in the map's style and cannot be filtered.`)));
823
+ return;
824
+ }
825
+
826
+ if (deepEqual(layer.filter, filter)) {
827
+ return;
828
+ }
829
+
830
+ if (filter === null || filter === undefined) {
831
+ layer.filter = undefined;
832
+ this._updateLayer(layer);
833
+ return;
834
+ }
835
+
836
+ if (this._validate(validateStyle.filter, `layers.${layer.id}.filter`, filter, null, options)) {
837
+ return;
838
+ }
839
+
840
+ layer.filter = clone(filter);
841
+ this._updateLayer(layer);
842
+ }
843
+
844
+ /**
845
+ * Get a layer's filter object
846
+ * @param {string} layer the layer to inspect
847
+ * @returns {*} the layer's filter, if any
848
+ */
849
+ getFilter(layer: string) {
850
+ return clone(this.getLayer(layer).filter);
851
+ }
852
+
853
+ setLayoutProperty(layerId: string, name: string, value: any, options: StyleSetterOptions = {}) {
854
+ this._checkLoaded();
855
+
856
+ const layer = this.getLayer(layerId);
857
+ if (!layer) {
858
+ this.fire(new ErrorEvent(new Error(`The layer '${layerId}' does not exist in the map's style and cannot be styled.`)));
859
+ return;
860
+ }
861
+
862
+ if (deepEqual(layer.getLayoutProperty(name), value)) return;
863
+
864
+ layer.setLayoutProperty(name, value, options);
865
+ this._updateLayer(layer);
866
+ }
867
+
868
+ /**
869
+ * Get a layout property's value from a given layer
870
+ * @param {string} layerId the layer to inspect
871
+ * @param {string} name the name of the layout property
872
+ * @returns {*} the property value
873
+ */
874
+ getLayoutProperty(layerId: string, name: string) {
875
+ const layer = this.getLayer(layerId);
876
+ if (!layer) {
877
+ this.fire(new ErrorEvent(new Error(`The layer '${layerId}' does not exist in the map's style.`)));
878
+ return;
879
+ }
880
+
881
+ return layer.getLayoutProperty(name);
882
+ }
883
+
884
+ setPaintProperty(layerId: string, name: string, value: any, options: StyleSetterOptions = {}) {
885
+ this._checkLoaded();
886
+
887
+ const layer = this.getLayer(layerId);
888
+ if (!layer) {
889
+ this.fire(new ErrorEvent(new Error(`The layer '${layerId}' does not exist in the map's style and cannot be styled.`)));
890
+ return;
891
+ }
892
+
893
+ if (deepEqual(layer.getPaintProperty(name), value)) return;
894
+
895
+ const requiresRelayout = layer.setPaintProperty(name, value, options);
896
+ if (requiresRelayout) {
897
+ this._updateLayer(layer);
898
+ }
899
+
900
+ this._changed = true;
901
+ this._updatedPaintProps[layerId] = true;
902
+ }
903
+
904
+ getPaintProperty(layer: string, name: string) {
905
+ return this.getLayer(layer).getPaintProperty(name);
906
+ }
907
+
908
+ setFeatureState(target: { source: string; sourceLayer?: string; id: string | number; }, state: Object) {
909
+ this._checkLoaded();
910
+ const sourceId = target.source;
911
+ const sourceLayer = target.sourceLayer;
912
+ const sourceCache = this.sourceCaches[sourceId];
913
+
914
+ if (sourceCache === undefined) {
915
+ this.fire(new ErrorEvent(new Error(`The source '${sourceId}' does not exist in the map's style.`)));
916
+ return;
917
+ }
918
+ const sourceType = sourceCache.getSource().type;
919
+ if (sourceType === 'geojson' && sourceLayer) {
920
+ this.fire(new ErrorEvent(new Error(`GeoJSON sources cannot have a sourceLayer parameter.`)));
921
+ return;
922
+ }
923
+ if (sourceType === 'vector' && !sourceLayer) {
924
+ this.fire(new ErrorEvent(new Error(`The sourceLayer parameter must be provided for vector source types.`)));
925
+ return;
926
+ }
927
+ if (target.id === undefined) {
928
+ this.fire(new ErrorEvent(new Error(`The feature id parameter must be provided.`)));
929
+ }
930
+
931
+ sourceCache.setFeatureState(sourceLayer, target.id, state);
932
+ }
933
+
934
+ removeFeatureState(target: { source: string; sourceLayer?: string; id?: string | number; }, key?: string) {
935
+ this._checkLoaded();
936
+ const sourceId = target.source;
937
+ const sourceCache = this.sourceCaches[sourceId];
938
+
939
+ if (sourceCache === undefined) {
940
+ this.fire(new ErrorEvent(new Error(`The source '${sourceId}' does not exist in the map's style.`)));
941
+ return;
942
+ }
943
+
944
+ const sourceType = sourceCache.getSource().type;
945
+ const sourceLayer = sourceType === 'vector' ? target.sourceLayer : undefined;
946
+
947
+ if (sourceType === 'vector' && !sourceLayer) {
948
+ this.fire(new ErrorEvent(new Error(`The sourceLayer parameter must be provided for vector source types.`)));
949
+ return;
950
+ }
951
+
952
+ if (key && (typeof target.id !== 'string' && typeof target.id !== 'number')) {
953
+ this.fire(new ErrorEvent(new Error(`A feature id is requred to remove its specific state property.`)));
954
+ return;
955
+ }
956
+
957
+ sourceCache.removeFeatureState(sourceLayer, target.id, key);
958
+ }
959
+
960
+ getFeatureState(target: { source: string; sourceLayer?: string; id: string | number; }) {
961
+ this._checkLoaded();
962
+ const sourceId = target.source;
963
+ const sourceLayer = target.sourceLayer;
964
+ const sourceCache = this.sourceCaches[sourceId];
965
+
966
+ if (sourceCache === undefined) {
967
+ this.fire(new ErrorEvent(new Error(`The source '${sourceId}' does not exist in the map's style.`)));
968
+ return;
969
+ }
970
+ const sourceType = sourceCache.getSource().type;
971
+ if (sourceType === 'vector' && !sourceLayer) {
972
+ this.fire(new ErrorEvent(new Error(`The sourceLayer parameter must be provided for vector source types.`)));
973
+ return;
974
+ }
975
+ if (target.id === undefined) {
976
+ this.fire(new ErrorEvent(new Error(`The feature id parameter must be provided.`)));
977
+ }
978
+
979
+ return sourceCache.getFeatureState(sourceLayer, target.id);
980
+ }
981
+
982
+ getTransition() {
983
+ return extend({duration: 300, delay: 0}, this.stylesheet && this.stylesheet.transition);
984
+ }
985
+
986
+ serialize() {
987
+ return filterObject({
988
+ version: this.stylesheet.version,
989
+ name: this.stylesheet.name,
990
+ metadata: this.stylesheet.metadata,
991
+ light: this.stylesheet.light,
992
+ center: this.stylesheet.center,
993
+ zoom: this.stylesheet.zoom,
994
+ bearing: this.stylesheet.bearing,
995
+ pitch: this.stylesheet.pitch,
996
+ sprite: this.stylesheet.sprite,
997
+ glyphs: this.stylesheet.glyphs,
998
+ transition: this.stylesheet.transition,
999
+ sources: mapObject(this.sourceCaches, (source) => source.serialize()),
1000
+ layers: this._serializeLayers(this._order)
1001
+ }, (value) => { return value !== undefined; });
1002
+ }
1003
+
1004
+ _updateLayer(layer: StyleLayer) {
1005
+ this._updatedLayers[layer.id] = true;
1006
+ if (layer.source && !this._updatedSources[layer.source] &&
1007
+ //Skip for raster layers (https://github.com/mapbox/mapbox-gl-js/issues/7865)
1008
+ this.sourceCaches[layer.source].getSource().type !== 'raster') {
1009
+ this._updatedSources[layer.source] = 'reload';
1010
+ this.sourceCaches[layer.source].pause();
1011
+ }
1012
+ this._changed = true;
1013
+ }
1014
+
1015
+ _flattenAndSortRenderedFeatures(sourceResults: Array<any>) {
1016
+ // Feature order is complicated.
1017
+ // The order between features in two 2D layers is always determined by layer order.
1018
+ // The order between features in two 3D layers is always determined by depth.
1019
+ // The order between a feature in a 2D layer and a 3D layer is tricky:
1020
+ // Most often layer order determines the feature order in this case. If
1021
+ // a line layer is above a extrusion layer the line feature will be rendered
1022
+ // above the extrusion. If the line layer is below the extrusion layer,
1023
+ // it will be rendered below it.
1024
+ //
1025
+ // There is a weird case though.
1026
+ // You have layers in this order: extrusion_layer_a, line_layer, extrusion_layer_b
1027
+ // Each layer has a feature that overlaps the other features.
1028
+ // The feature in extrusion_layer_a is closer than the feature in extrusion_layer_b so it is rendered above.
1029
+ // The feature in line_layer is rendered above extrusion_layer_a.
1030
+ // This means that that the line_layer feature is above the extrusion_layer_b feature despite
1031
+ // it being in an earlier layer.
1032
+
1033
+ const isLayer3D = layerId => this._layers[layerId].type === 'fill-extrusion';
1034
+
1035
+ const layerIndex = {};
1036
+ const features3D = [];
1037
+ for (let l = this._order.length - 1; l >= 0; l--) {
1038
+ const layerId = this._order[l];
1039
+ if (isLayer3D(layerId)) {
1040
+ layerIndex[layerId] = l;
1041
+ for (const sourceResult of sourceResults) {
1042
+ const layerFeatures = sourceResult[layerId];
1043
+ if (layerFeatures) {
1044
+ for (const featureWrapper of layerFeatures) {
1045
+ features3D.push(featureWrapper);
1046
+ }
1047
+ }
1048
+ }
1049
+ }
1050
+ }
1051
+
1052
+ features3D.sort((a, b) => {
1053
+ return b.intersectionZ - a.intersectionZ;
1054
+ });
1055
+
1056
+ const features = [];
1057
+ for (let l = this._order.length - 1; l >= 0; l--) {
1058
+ const layerId = this._order[l];
1059
+
1060
+ if (isLayer3D(layerId)) {
1061
+ // add all 3D features that are in or above the current layer
1062
+ for (let i = features3D.length - 1; i >= 0; i--) {
1063
+ const topmost3D = features3D[i].feature;
1064
+ if (layerIndex[topmost3D.layer.id] < l) break;
1065
+ features.push(topmost3D);
1066
+ features3D.pop();
1067
+ }
1068
+ } else {
1069
+ for (const sourceResult of sourceResults) {
1070
+ const layerFeatures = sourceResult[layerId];
1071
+ if (layerFeatures) {
1072
+ for (const featureWrapper of layerFeatures) {
1073
+ features.push(featureWrapper.feature);
1074
+ }
1075
+ }
1076
+ }
1077
+ }
1078
+ }
1079
+
1080
+ return features;
1081
+ }
1082
+
1083
+ queryRenderedFeatures(queryGeometry: any, params: any, transform: Transform) {
1084
+ if (params && params.filter) {
1085
+ this._validate(validateStyle.filter, 'queryRenderedFeatures.filter', params.filter, null, params);
1086
+ }
1087
+
1088
+ const includedSources = {};
1089
+ if (params && params.layers) {
1090
+ if (!Array.isArray(params.layers)) {
1091
+ this.fire(new ErrorEvent(new Error('parameters.layers must be an Array.')));
1092
+ return [];
1093
+ }
1094
+ for (const layerId of params.layers) {
1095
+ const layer = this._layers[layerId];
1096
+ if (!layer) {
1097
+ // this layer is not in the style.layers array
1098
+ this.fire(new ErrorEvent(new Error(`The layer '${layerId}' does not exist in the map's style and cannot be queried for features.`)));
1099
+ return [];
1100
+ }
1101
+ includedSources[layer.source] = true;
1102
+ }
1103
+ }
1104
+
1105
+ const sourceResults = [];
1106
+
1107
+ params.availableImages = this._availableImages;
1108
+
1109
+ for (const id in this.sourceCaches) {
1110
+ if (params.layers && !includedSources[id]) continue;
1111
+ sourceResults.push(
1112
+ queryRenderedFeatures(
1113
+ this.sourceCaches[id],
1114
+ this._layers,
1115
+ this._serializedLayers,
1116
+ queryGeometry,
1117
+ params,
1118
+ transform)
1119
+ );
1120
+ }
1121
+
1122
+ if (this.placement) {
1123
+ // If a placement has run, query against its CollisionIndex
1124
+ // for symbol results, and treat it as an extra source to merge
1125
+ sourceResults.push(
1126
+ queryRenderedSymbols(
1127
+ this._layers,
1128
+ this._serializedLayers,
1129
+ this.sourceCaches,
1130
+ queryGeometry,
1131
+ params,
1132
+ this.placement.collisionIndex,
1133
+ this.placement.retainedQueryData)
1134
+ );
1135
+ }
1136
+
1137
+ return this._flattenAndSortRenderedFeatures(sourceResults);
1138
+ }
1139
+
1140
+ querySourceFeatures(sourceID: string, params: ?{sourceLayer: ?string, filter: ?Array<any>, validate?: boolean}) {
1141
+ if (params && params.filter) {
1142
+ this._validate(validateStyle.filter, 'querySourceFeatures.filter', params.filter, null, params);
1143
+ }
1144
+ const sourceCache = this.sourceCaches[sourceID];
1145
+ return sourceCache ? querySourceFeatures(sourceCache, params) : [];
1146
+ }
1147
+
1148
+ addSourceType(name: string, SourceType: SourceClass, callback: Callback<void>) {
1149
+ if (Style.getSourceType(name)) {
1150
+ return callback(new Error(`A source type called "${name}" already exists.`));
1151
+ }
1152
+
1153
+ Style.setSourceType(name, SourceType);
1154
+
1155
+ if (!SourceType.workerSourceURL) {
1156
+ return callback(null, null);
1157
+ }
1158
+
1159
+ this.dispatcher.broadcast('loadWorkerSource', {
1160
+ name,
1161
+ url: SourceType.workerSourceURL
1162
+ }, callback);
1163
+ }
1164
+
1165
+ getLight() {
1166
+ return this.light.getLight();
1167
+ }
1168
+
1169
+ setLight(lightOptions: LightSpecification, options: StyleSetterOptions = {}) {
1170
+ this._checkLoaded();
1171
+
1172
+ const light = this.light.getLight();
1173
+ let _update = false;
1174
+ for (const key in lightOptions) {
1175
+ if (!deepEqual(lightOptions[key], light[key])) {
1176
+ _update = true;
1177
+ break;
1178
+ }
1179
+ }
1180
+ if (!_update) return;
1181
+
1182
+ const parameters = {
1183
+ now: browser.now(),
1184
+ transition: extend({
1185
+ duration: 300,
1186
+ delay: 0
1187
+ }, this.stylesheet.transition)
1188
+ };
1189
+
1190
+ this.light.setLight(lightOptions, options);
1191
+ this.light.updateTransitions(parameters);
1192
+ }
1193
+
1194
+ _validate(validate: Validator, key: string, value: any, props: any, options: { validate?: boolean } = {}) {
1195
+ if (options && options.validate === false) {
1196
+ return false;
1197
+ }
1198
+ return emitValidationErrors(this, validate.call(validateStyle, extend({
1199
+ key,
1200
+ style: this.serialize(),
1201
+ value,
1202
+ styleSpec
1203
+ }, props)));
1204
+ }
1205
+
1206
+ _remove() {
1207
+ if (this._request) {
1208
+ this._request.cancel();
1209
+ this._request = null;
1210
+ }
1211
+ if (this._spriteRequest) {
1212
+ this._spriteRequest.cancel();
1213
+ this._spriteRequest = null;
1214
+ }
1215
+ rtlTextPluginEvented.off('pluginStateChange', this._rtlTextPluginCallback);
1216
+ for (const layerId in this._layers) {
1217
+ const layer: StyleLayer = this._layers[layerId];
1218
+ layer.setEventedParent(null);
1219
+ }
1220
+ for (const id in this.sourceCaches) {
1221
+ this.sourceCaches[id].clearTiles();
1222
+ this.sourceCaches[id].setEventedParent(null);
1223
+ }
1224
+ this.imageManager.setEventedParent(null);
1225
+ this.setEventedParent(null);
1226
+ this.dispatcher.remove();
1227
+ }
1228
+
1229
+ _clearSource(id: string) {
1230
+ this.sourceCaches[id].clearTiles();
1231
+ }
1232
+
1233
+ _reloadSource(id: string) {
1234
+ this.sourceCaches[id].resume();
1235
+ this.sourceCaches[id].reload();
1236
+ }
1237
+
1238
+ _updateSources(transform: Transform) {
1239
+ for (const id in this.sourceCaches) {
1240
+ this.sourceCaches[id].update(transform);
1241
+ }
1242
+ }
1243
+
1244
+ _generateCollisionBoxes() {
1245
+ for (const id in this.sourceCaches) {
1246
+ this._reloadSource(id);
1247
+ }
1248
+ }
1249
+
1250
+ _updatePlacement(transform: Transform, showCollisionBoxes: boolean, fadeDuration: number, crossSourceCollisions: boolean, forceFullPlacement: boolean = false) {
1251
+ let symbolBucketsChanged = false;
1252
+ let placementCommitted = false;
1253
+
1254
+ const layerTiles = {};
1255
+
1256
+ for (const layerID of this._order) {
1257
+ const styleLayer = this._layers[layerID];
1258
+ if (styleLayer.type !== 'symbol') continue;
1259
+
1260
+ if (!layerTiles[styleLayer.source]) {
1261
+ const sourceCache = this.sourceCaches[styleLayer.source];
1262
+ layerTiles[styleLayer.source] = sourceCache.getRenderableIds(true)
1263
+ .map((id) => sourceCache.getTileByID(id))
1264
+ .sort((a, b) => (b.tileID.overscaledZ - a.tileID.overscaledZ) || (a.tileID.isLessThan(b.tileID) ? -1 : 1));
1265
+ }
1266
+
1267
+ const layerBucketsChanged = this.crossTileSymbolIndex.addLayer(styleLayer, layerTiles[styleLayer.source], transform.center.lng);
1268
+ symbolBucketsChanged = symbolBucketsChanged || layerBucketsChanged;
1269
+ }
1270
+ this.crossTileSymbolIndex.pruneUnusedLayers(this._order);
1271
+
1272
+ // Anything that changes our "in progress" layer and tile indices requires us
1273
+ // to start over. When we start over, we do a full placement instead of incremental
1274
+ // to prevent starvation.
1275
+ // We need to restart placement to keep layer indices in sync.
1276
+ // Also force full placement when fadeDuration === 0 to ensure that newly loaded
1277
+ // tiles will fully display symbols in their first frame
1278
+ forceFullPlacement = forceFullPlacement || this._layerOrderChanged || fadeDuration === 0;
1279
+
1280
+ if (forceFullPlacement || !this.pauseablePlacement || (this.pauseablePlacement.isDone() && !this.placement.stillRecent(browser.now(), transform.zoom))) {
1281
+ this.pauseablePlacement = new PauseablePlacement(transform, this._order, forceFullPlacement, showCollisionBoxes, fadeDuration, crossSourceCollisions, this.placement);
1282
+ this._layerOrderChanged = false;
1283
+ }
1284
+
1285
+ if (this.pauseablePlacement.isDone()) {
1286
+ // the last placement finished running, but the next one hasn’t
1287
+ // started yet because of the `stillRecent` check immediately
1288
+ // above, so mark it stale to ensure that we request another
1289
+ // render frame
1290
+ this.placement.setStale();
1291
+ } else {
1292
+ this.pauseablePlacement.continuePlacement(this._order, this._layers, layerTiles);
1293
+
1294
+ if (this.pauseablePlacement.isDone()) {
1295
+ this.placement = this.pauseablePlacement.commit(browser.now());
1296
+ placementCommitted = true;
1297
+ }
1298
+
1299
+ if (symbolBucketsChanged) {
1300
+ // since the placement gets split over multiple frames it is possible
1301
+ // these buckets were processed before they were changed and so the
1302
+ // placement is already stale while it is in progress
1303
+ this.pauseablePlacement.placement.setStale();
1304
+ }
1305
+ }
1306
+
1307
+ if (placementCommitted || symbolBucketsChanged) {
1308
+ for (const layerID of this._order) {
1309
+ const styleLayer = this._layers[layerID];
1310
+ if (styleLayer.type !== 'symbol') continue;
1311
+ this.placement.updateLayerOpacities(styleLayer, layerTiles[styleLayer.source]);
1312
+ }
1313
+ }
1314
+
1315
+ // needsRender is false when we have just finished a placement that didn't change the visibility of any symbols
1316
+ const needsRerender = !this.pauseablePlacement.isDone() || this.placement.hasTransitions(browser.now());
1317
+ return needsRerender;
1318
+ }
1319
+
1320
+ _releaseSymbolFadeTiles() {
1321
+ for (const id in this.sourceCaches) {
1322
+ this.sourceCaches[id].releaseSymbolFadeTiles();
1323
+ }
1324
+ }
1325
+
1326
+ // Callbacks from web workers
1327
+
1328
+ getImages(mapId: string, params: {icons: Array<string>, source: string, tileID: OverscaledTileID, type: string}, callback: Callback<{[_: string]: StyleImage}>) {
1329
+
1330
+ this.imageManager.getImages(params.icons, callback);
1331
+
1332
+ // Apply queued image changes before setting the tile's dependencies so that the tile
1333
+ // is not reloaded unecessarily. Without this forced update the reload could happen in cases
1334
+ // like this one:
1335
+ // - icons contains "my-image"
1336
+ // - imageManager.getImages(...) triggers `onstyleimagemissing`
1337
+ // - the user adds "my-image" within the callback
1338
+ // - addImage adds "my-image" to this._changedImages
1339
+ // - the next frame triggers a reload of this tile even though it already has the latest version
1340
+ this._updateTilesForChangedImages();
1341
+
1342
+ const sourceCache = this.sourceCaches[params.source];
1343
+ if (sourceCache) {
1344
+ sourceCache.setDependencies(params.tileID.key, params.type, params.icons);
1345
+ }
1346
+ }
1347
+
1348
+ getGlyphs(mapId: string, params: {stacks: {[_: string]: Array<number>}}, callback: Callback<{[_: string]: {[_: number]: ?StyleGlyph}}>) {
1349
+ this.glyphManager.getGlyphs(params.stacks, callback);
1350
+ }
1351
+
1352
+ getResource(mapId: string, params: RequestParameters, callback: ResponseCallback<any>): Cancelable {
1353
+ return makeRequest(params, callback);
1354
+ }
1355
+ }
1356
+
1357
+ Style.getSourceType = getSourceType;
1358
+ Style.setSourceType = setSourceType;
1359
+ Style.registerForPluginStateChange = registerForPluginStateChange;
1360
+
1361
+ export default Style;