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,216 @@
1
+ // @flow
2
+
3
+ import {getArrayBuffer} from '../util/ajax';
4
+
5
+ import vt from '@mapbox/vector-tile';
6
+ import Protobuf from 'pbf';
7
+ import WorkerTile from './worker_tile';
8
+ import {extend} from '../util/util';
9
+ import {RequestPerformance} from '../util/performance';
10
+
11
+ import type {
12
+ WorkerSource,
13
+ WorkerTileParameters,
14
+ WorkerTileCallback,
15
+ TileParameters
16
+ } from '../source/worker_source';
17
+
18
+ import type Actor from '../util/actor';
19
+ import type StyleLayerIndex from '../style/style_layer_index';
20
+ import type {Callback} from '../types/callback';
21
+
22
+ export type LoadVectorTileResult = {
23
+ vectorTile: VectorTile;
24
+ rawData: ArrayBuffer;
25
+ expires?: any;
26
+ cacheControl?: any;
27
+ resourceTiming?: Array<PerformanceResourceTiming>;
28
+ };
29
+
30
+ /**
31
+ * @callback LoadVectorDataCallback
32
+ * @param error
33
+ * @param vectorTile
34
+ * @private
35
+ */
36
+ export type LoadVectorDataCallback = Callback<?LoadVectorTileResult>;
37
+
38
+ export type AbortVectorData = () => void;
39
+ export type LoadVectorData = (params: WorkerTileParameters, callback: LoadVectorDataCallback) => ?AbortVectorData;
40
+
41
+ /**
42
+ * @private
43
+ */
44
+ function loadVectorTile(params: WorkerTileParameters, callback: LoadVectorDataCallback) {
45
+ const request = getArrayBuffer(params.request, (err: ?Error, data: ?ArrayBuffer, cacheControl: ?string, expires: ?string) => {
46
+ if (err) {
47
+ callback(err);
48
+ } else if (data) {
49
+ callback(null, {
50
+ vectorTile: new vt.VectorTile(new Protobuf(data)),
51
+ rawData: data,
52
+ cacheControl,
53
+ expires
54
+ });
55
+ }
56
+ });
57
+ return () => {
58
+ request.cancel();
59
+ callback();
60
+ };
61
+ }
62
+
63
+ /**
64
+ * The {@link WorkerSource} implementation that supports {@link VectorTileSource}.
65
+ * This class is designed to be easily reused to support custom source types
66
+ * for data formats that can be parsed/converted into an in-memory VectorTile
67
+ * representation. To do so, create it with
68
+ * `new VectorTileWorkerSource(actor, styleLayers, customLoadVectorDataFunction)`.
69
+ *
70
+ * @private
71
+ */
72
+ class VectorTileWorkerSource implements WorkerSource {
73
+ actor: Actor;
74
+ layerIndex: StyleLayerIndex;
75
+ availableImages: Array<string>;
76
+ loadVectorData: LoadVectorData;
77
+ loading: {[_: string]: WorkerTile };
78
+ loaded: {[_: string]: WorkerTile };
79
+
80
+ /**
81
+ * @param [loadVectorData] Optional method for custom loading of a VectorTile
82
+ * object based on parameters passed from the main-thread Source. See
83
+ * {@link VectorTileWorkerSource#loadTile}. The default implementation simply
84
+ * loads the pbf at `params.url`.
85
+ * @private
86
+ */
87
+ constructor(actor: Actor, layerIndex: StyleLayerIndex, availableImages: Array<string>, loadVectorData: ?LoadVectorData) {
88
+ this.actor = actor;
89
+ this.layerIndex = layerIndex;
90
+ this.availableImages = availableImages;
91
+ this.loadVectorData = loadVectorData || loadVectorTile;
92
+ this.loading = {};
93
+ this.loaded = {};
94
+ }
95
+
96
+ /**
97
+ * Implements {@link WorkerSource#loadTile}. Delegates to
98
+ * {@link VectorTileWorkerSource#loadVectorData} (which by default expects
99
+ * a `params.url` property) for fetching and producing a VectorTile object.
100
+ * @private
101
+ */
102
+ loadTile(params: WorkerTileParameters, callback: WorkerTileCallback) {
103
+ const uid = params.uid;
104
+
105
+ if (!this.loading)
106
+ this.loading = {};
107
+
108
+ const perf = (params && params.request && params.request.collectResourceTiming) ?
109
+ new RequestPerformance(params.request) : false;
110
+
111
+ const workerTile = this.loading[uid] = new WorkerTile(params);
112
+ workerTile.abort = this.loadVectorData(params, (err, response) => {
113
+ delete this.loading[uid];
114
+
115
+ if (err || !response) {
116
+ workerTile.status = 'done';
117
+ this.loaded[uid] = workerTile;
118
+ return callback(err);
119
+ }
120
+
121
+ const rawTileData = response.rawData;
122
+ const cacheControl = {};
123
+ if (response.expires) cacheControl.expires = response.expires;
124
+ if (response.cacheControl) cacheControl.cacheControl = response.cacheControl;
125
+
126
+ const resourceTiming = {};
127
+ if (perf) {
128
+ const resourceTimingData = perf.finish();
129
+ // it's necessary to eval the result of getEntriesByName() here via parse/stringify
130
+ // late evaluation in the main thread causes TypeError: illegal invocation
131
+ if (resourceTimingData)
132
+ resourceTiming.resourceTiming = JSON.parse(JSON.stringify(resourceTimingData));
133
+ }
134
+
135
+ workerTile.vectorTile = response.vectorTile;
136
+ workerTile.parse(response.vectorTile, this.layerIndex, this.availableImages, this.actor, (err, result) => {
137
+ if (err || !result) return callback(err);
138
+
139
+ // Transferring a copy of rawTileData because the worker needs to retain its copy.
140
+ callback(null, extend({rawTileData: rawTileData.slice(0)}, result, cacheControl, resourceTiming));
141
+ });
142
+
143
+ this.loaded = this.loaded || {};
144
+ this.loaded[uid] = workerTile;
145
+ });
146
+ }
147
+
148
+ /**
149
+ * Implements {@link WorkerSource#reloadTile}.
150
+ * @private
151
+ */
152
+ reloadTile(params: WorkerTileParameters, callback: WorkerTileCallback) {
153
+ const loaded = this.loaded,
154
+ uid = params.uid,
155
+ vtSource = this;
156
+ if (loaded && loaded[uid]) {
157
+ const workerTile = loaded[uid];
158
+ workerTile.showCollisionBoxes = params.showCollisionBoxes;
159
+
160
+ const done = (err, data) => {
161
+ const reloadCallback = workerTile.reloadCallback;
162
+ if (reloadCallback) {
163
+ delete workerTile.reloadCallback;
164
+ workerTile.parse(workerTile.vectorTile, vtSource.layerIndex, this.availableImages, vtSource.actor, reloadCallback);
165
+ }
166
+ callback(err, data);
167
+ };
168
+
169
+ if (workerTile.status === 'parsing') {
170
+ workerTile.reloadCallback = done;
171
+ } else if (workerTile.status === 'done') {
172
+ // if there was no vector tile data on the initial load, don't try and re-parse tile
173
+ if (workerTile.vectorTile) {
174
+ workerTile.parse(workerTile.vectorTile, this.layerIndex, this.availableImages, this.actor, done);
175
+ } else {
176
+ done();
177
+ }
178
+ }
179
+ }
180
+ }
181
+
182
+ /**
183
+ * Implements {@link WorkerSource#abortTile}.
184
+ *
185
+ * @param params
186
+ * @param params.uid The UID for this tile.
187
+ * @private
188
+ */
189
+ abortTile(params: TileParameters, callback: WorkerTileCallback) {
190
+ const loading = this.loading,
191
+ uid = params.uid;
192
+ if (loading && loading[uid] && loading[uid].abort) {
193
+ loading[uid].abort();
194
+ delete loading[uid];
195
+ }
196
+ callback();
197
+ }
198
+
199
+ /**
200
+ * Implements {@link WorkerSource#removeTile}.
201
+ *
202
+ * @param params
203
+ * @param params.uid The UID for this tile.
204
+ * @private
205
+ */
206
+ removeTile(params: TileParameters, callback: WorkerTileCallback) {
207
+ const loaded = this.loaded,
208
+ uid = params.uid;
209
+ if (loaded && loaded[uid]) {
210
+ delete loaded[uid];
211
+ }
212
+ callback();
213
+ }
214
+ }
215
+
216
+ export default VectorTileWorkerSource;
@@ -0,0 +1,203 @@
1
+ // @flow
2
+
3
+ import {getVideo, ResourceType} from '../util/ajax';
4
+
5
+ import ImageSource from './image_source';
6
+ import rasterBoundsAttributes from '../data/raster_bounds_attributes';
7
+ import SegmentVector from '../data/segment';
8
+ import Texture from '../render/texture';
9
+ import {ErrorEvent} from '../util/evented';
10
+ import ValidationError from '../style-spec/error/validation_error';
11
+
12
+ import type Map from '../ui/map';
13
+ import type Dispatcher from '../util/dispatcher';
14
+ import type {Evented} from '../util/evented';
15
+ import type {VideoSourceSpecification} from '../style-spec/types';
16
+
17
+ /**
18
+ * A data source containing video.
19
+ * (See the [Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#sources-video) for detailed documentation of options.)
20
+ *
21
+ * @example
22
+ * // add to map
23
+ * map.addSource('some id', {
24
+ * type: 'video',
25
+ * url: [
26
+ * 'https://www.mapbox.com/blog/assets/baltimore-smoke.mp4',
27
+ * 'https://www.mapbox.com/blog/assets/baltimore-smoke.webm'
28
+ * ],
29
+ * coordinates: [
30
+ * [-76.54, 39.18],
31
+ * [-76.52, 39.18],
32
+ * [-76.52, 39.17],
33
+ * [-76.54, 39.17]
34
+ * ]
35
+ * });
36
+ *
37
+ * // update
38
+ * var mySource = map.getSource('some id');
39
+ * mySource.setCoordinates([
40
+ * [-76.54335737228394, 39.18579907229748],
41
+ * [-76.52803659439087, 39.1838364847587],
42
+ * [-76.5295386314392, 39.17683392507606],
43
+ * [-76.54520273208618, 39.17876344106642]
44
+ * ]);
45
+ *
46
+ * map.removeSource('some id'); // remove
47
+ * @see [Add a video](https://www.mapbox.com/mapbox-gl-js/example/video-on-a-map/)
48
+ */
49
+ class VideoSource extends ImageSource {
50
+ options: VideoSourceSpecification;
51
+ urls: Array<string>;
52
+ video: HTMLVideoElement;
53
+ roundZoom: boolean;
54
+
55
+ /**
56
+ * @private
57
+ */
58
+ constructor(id: string, options: VideoSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) {
59
+ super(id, options, dispatcher, eventedParent);
60
+ this.roundZoom = true;
61
+ this.type = 'video';
62
+ this.options = options;
63
+ }
64
+
65
+ load() {
66
+ this._loaded = false;
67
+ const options = this.options;
68
+
69
+ this.urls = [];
70
+ for (const url of options.urls) {
71
+ this.urls.push(this.map._requestManager.transformRequest(url, ResourceType.Source).url);
72
+ }
73
+
74
+ getVideo(this.urls, (err, video) => {
75
+ this._loaded = true;
76
+ if (err) {
77
+ this.fire(new ErrorEvent(err));
78
+ } else if (video) {
79
+ this.video = video;
80
+ this.video.loop = true;
81
+
82
+ // Start repainting when video starts playing. hasTransition() will then return
83
+ // true to trigger additional frames as long as the videos continues playing.
84
+ this.video.addEventListener('playing', () => {
85
+ this.map.triggerRepaint();
86
+ });
87
+
88
+ if (this.map) {
89
+ this.video.play();
90
+ }
91
+
92
+ this._finishLoading();
93
+ }
94
+ });
95
+ }
96
+
97
+ /**
98
+ * Pauses the video.
99
+ */
100
+ pause() {
101
+ if (this.video) {
102
+ this.video.pause();
103
+ }
104
+ }
105
+
106
+ /**
107
+ * Plays the video.
108
+ */
109
+ play() {
110
+ if (this.video) {
111
+ this.video.play();
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Sets playback to a timestamp, in seconds.
117
+ * @private
118
+ */
119
+ seek(seconds: number) {
120
+ if (this.video) {
121
+ const seekableRange = this.video.seekable;
122
+ if (seconds < seekableRange.start(0) || seconds > seekableRange.end(0)) {
123
+ this.fire(new ErrorEvent(new ValidationError(`sources.${this.id}`, null, `Playback for this video can be set only between the ${seekableRange.start(0)} and ${seekableRange.end(0)}-second mark.`)));
124
+ } else this.video.currentTime = seconds;
125
+ }
126
+ }
127
+
128
+ /**
129
+ * Returns the HTML `video` element.
130
+ *
131
+ * @returns {HTMLVideoElement} The HTML `video` element.
132
+ */
133
+ getVideo() {
134
+ return this.video;
135
+ }
136
+
137
+ onAdd(map: Map) {
138
+ if (this.map) return;
139
+ this.map = map;
140
+ this.load();
141
+ if (this.video) {
142
+ this.video.play();
143
+ this.setCoordinates(this.coordinates);
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Sets the video's coordinates and re-renders the map.
149
+ *
150
+ * @method setCoordinates
151
+ * @instance
152
+ * @memberof VideoSource
153
+ * @returns {VideoSource} this
154
+ */
155
+ // setCoordinates inherited from ImageSource
156
+
157
+ prepare() {
158
+ if (Object.keys(this.tiles).length === 0 || this.video.readyState < 2) {
159
+ return; // not enough data for current position
160
+ }
161
+
162
+ const context = this.map.painter.context;
163
+ const gl = context.gl;
164
+
165
+ if (!this.boundsBuffer) {
166
+ this.boundsBuffer = context.createVertexBuffer(this._boundsArray, rasterBoundsAttributes.members);
167
+ }
168
+
169
+ if (!this.boundsSegments) {
170
+ this.boundsSegments = SegmentVector.simpleSegment(0, 0, 4, 2);
171
+ }
172
+
173
+ if (!this.texture) {
174
+ this.texture = new Texture(context, this.video, gl.RGBA);
175
+ this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
176
+ } else if (!this.video.paused) {
177
+ this.texture.bind(gl.LINEAR, gl.CLAMP_TO_EDGE);
178
+ gl.texSubImage2D(gl.TEXTURE_2D, 0, 0, 0, gl.RGBA, gl.UNSIGNED_BYTE, this.video);
179
+ }
180
+
181
+ for (const w in this.tiles) {
182
+ const tile = this.tiles[w];
183
+ if (tile.state !== 'loaded') {
184
+ tile.state = 'loaded';
185
+ tile.texture = this.texture;
186
+ }
187
+ }
188
+ }
189
+
190
+ serialize() {
191
+ return {
192
+ type: 'video',
193
+ urls: this.urls,
194
+ coordinates: this.coordinates
195
+ };
196
+ }
197
+
198
+ hasTransition() {
199
+ return this.video && !this.video.paused;
200
+ }
201
+ }
202
+
203
+ export default VideoSource;
@@ -0,0 +1,240 @@
1
+ // @flow
2
+
3
+ import Actor from '../util/actor';
4
+
5
+ import StyleLayerIndex from '../style/style_layer_index';
6
+ import VectorTileWorkerSource from './vector_tile_worker_source';
7
+ import RasterDEMTileWorkerSource from './raster_dem_tile_worker_source';
8
+ import GeoJSONWorkerSource from './geojson_worker_source';
9
+ import assert from 'assert';
10
+ import {plugin as globalRTLTextPlugin} from './rtl_text_plugin';
11
+ import {enforceCacheSizeLimit} from '../util/tile_request_cache';
12
+
13
+ import type {
14
+ WorkerSource,
15
+ WorkerTileParameters,
16
+ WorkerDEMTileParameters,
17
+ WorkerTileCallback,
18
+ WorkerDEMTileCallback,
19
+ TileParameters
20
+ } from '../source/worker_source';
21
+
22
+ import type {WorkerGlobalScopeInterface} from '../util/web_worker';
23
+ import type {Callback} from '../types/callback';
24
+ import type {LayerSpecification} from '../style-spec/types';
25
+ import type {PluginState} from './rtl_text_plugin';
26
+
27
+ /**
28
+ * @private
29
+ */
30
+ export default class Worker {
31
+ self: WorkerGlobalScopeInterface;
32
+ actor: Actor;
33
+ layerIndexes: {[_: string]: StyleLayerIndex };
34
+ availableImages: {[_: string]: Array<string> };
35
+ workerSourceTypes: {[_: string]: Class<WorkerSource> };
36
+ workerSources: {[_: string]: {[_: string]: {[_: string]: WorkerSource } } };
37
+ demWorkerSources: {[_: string]: {[_: string]: RasterDEMTileWorkerSource } };
38
+ referrer: ?string;
39
+
40
+ constructor(self: WorkerGlobalScopeInterface) {
41
+ this.self = self;
42
+ this.actor = new Actor(self, this);
43
+
44
+ this.layerIndexes = {};
45
+ this.availableImages = {};
46
+
47
+ this.workerSourceTypes = {
48
+ vector: VectorTileWorkerSource,
49
+ geojson: GeoJSONWorkerSource
50
+ };
51
+
52
+ // [mapId][sourceType][sourceName] => worker source instance
53
+ this.workerSources = {};
54
+ this.demWorkerSources = {};
55
+
56
+ this.self.registerWorkerSource = (name: string, WorkerSource: Class<WorkerSource>) => {
57
+ if (this.workerSourceTypes[name]) {
58
+ throw new Error(`Worker source with name "${name}" already registered.`);
59
+ }
60
+ this.workerSourceTypes[name] = WorkerSource;
61
+ };
62
+
63
+ // This is invoked by the RTL text plugin when the download via the `importScripts` call has finished, and the code has been parsed.
64
+ this.self.registerRTLTextPlugin = (rtlTextPlugin: {applyArabicShaping: Function, processBidirectionalText: Function, processStyledBidirectionalText?: Function}) => {
65
+ if (globalRTLTextPlugin.isParsed()) {
66
+ throw new Error('RTL text plugin already registered.');
67
+ }
68
+ globalRTLTextPlugin['applyArabicShaping'] = rtlTextPlugin.applyArabicShaping;
69
+ globalRTLTextPlugin['processBidirectionalText'] = rtlTextPlugin.processBidirectionalText;
70
+ globalRTLTextPlugin['processStyledBidirectionalText'] = rtlTextPlugin.processStyledBidirectionalText;
71
+ };
72
+ }
73
+
74
+ setReferrer(mapID: string, referrer: string) {
75
+ this.referrer = referrer;
76
+ }
77
+
78
+ setImages(mapId: string, images: Array<string>, callback: WorkerTileCallback) {
79
+ this.availableImages[mapId] = images;
80
+ for (const workerSource in this.workerSources[mapId]) {
81
+ const ws = this.workerSources[mapId][workerSource];
82
+ for (const source in ws) {
83
+ ws[source].availableImages = images;
84
+ }
85
+ }
86
+ callback();
87
+ }
88
+
89
+ setLayers(mapId: string, layers: Array<LayerSpecification>, callback: WorkerTileCallback) {
90
+ this.getLayerIndex(mapId).replace(layers);
91
+ callback();
92
+ }
93
+
94
+ updateLayers(mapId: string, params: {layers: Array<LayerSpecification>, removedIds: Array<string>}, callback: WorkerTileCallback) {
95
+ this.getLayerIndex(mapId).update(params.layers, params.removedIds);
96
+ callback();
97
+ }
98
+
99
+ loadTile(mapId: string, params: WorkerTileParameters & {type: string}, callback: WorkerTileCallback) {
100
+ assert(params.type);
101
+ this.getWorkerSource(mapId, params.type, params.source).loadTile(params, callback);
102
+ }
103
+
104
+ loadDEMTile(mapId: string, params: WorkerDEMTileParameters, callback: WorkerDEMTileCallback) {
105
+ this.getDEMWorkerSource(mapId, params.source).loadTile(params, callback);
106
+ }
107
+
108
+ reloadTile(mapId: string, params: WorkerTileParameters & {type: string}, callback: WorkerTileCallback) {
109
+ assert(params.type);
110
+ this.getWorkerSource(mapId, params.type, params.source).reloadTile(params, callback);
111
+ }
112
+
113
+ abortTile(mapId: string, params: TileParameters & {type: string}, callback: WorkerTileCallback) {
114
+ assert(params.type);
115
+ this.getWorkerSource(mapId, params.type, params.source).abortTile(params, callback);
116
+ }
117
+
118
+ removeTile(mapId: string, params: TileParameters & {type: string}, callback: WorkerTileCallback) {
119
+ assert(params.type);
120
+ this.getWorkerSource(mapId, params.type, params.source).removeTile(params, callback);
121
+ }
122
+
123
+ removeDEMTile(mapId: string, params: TileParameters) {
124
+ this.getDEMWorkerSource(mapId, params.source).removeTile(params);
125
+ }
126
+
127
+ removeSource(mapId: string, params: {source: string} & {type: string}, callback: WorkerTileCallback) {
128
+ assert(params.type);
129
+ assert(params.source);
130
+
131
+ if (!this.workerSources[mapId] ||
132
+ !this.workerSources[mapId][params.type] ||
133
+ !this.workerSources[mapId][params.type][params.source]) {
134
+ return;
135
+ }
136
+
137
+ const worker = this.workerSources[mapId][params.type][params.source];
138
+ delete this.workerSources[mapId][params.type][params.source];
139
+
140
+ if (worker.removeSource !== undefined) {
141
+ worker.removeSource(params, callback);
142
+ } else {
143
+ callback();
144
+ }
145
+ }
146
+
147
+ /**
148
+ * Load a {@link WorkerSource} script at params.url. The script is run
149
+ * (using importScripts) with `registerWorkerSource` in scope, which is a
150
+ * function taking `(name, workerSourceObject)`.
151
+ * @private
152
+ */
153
+ loadWorkerSource(map: string, params: { url: string }, callback: Callback<void>) {
154
+ try {
155
+ this.self.importScripts(params.url);
156
+ callback();
157
+ } catch (e) {
158
+ callback(e.toString());
159
+ }
160
+ }
161
+
162
+ syncRTLPluginState(map: string, state: PluginState, callback: Callback<boolean>) {
163
+ try {
164
+ globalRTLTextPlugin.setState(state);
165
+ const pluginURL = globalRTLTextPlugin.getPluginURL();
166
+ if (
167
+ globalRTLTextPlugin.isLoaded() &&
168
+ !globalRTLTextPlugin.isParsed() &&
169
+ pluginURL != null // Not possible when `isLoaded` is true, but keeps flow happy
170
+ ) {
171
+ this.self.importScripts(pluginURL);
172
+ const complete = globalRTLTextPlugin.isParsed();
173
+ const error = complete ? undefined : new Error(`RTL Text Plugin failed to import scripts from ${pluginURL}`);
174
+ callback(error, complete);
175
+ }
176
+ } catch (e) {
177
+ callback(e.toString());
178
+ }
179
+ }
180
+
181
+ getAvailableImages(mapId: string) {
182
+ let availableImages = this.availableImages[mapId];
183
+
184
+ if (!availableImages) {
185
+ availableImages = [];
186
+ }
187
+
188
+ return availableImages;
189
+ }
190
+
191
+ getLayerIndex(mapId: string) {
192
+ let layerIndexes = this.layerIndexes[mapId];
193
+ if (!layerIndexes) {
194
+ layerIndexes = this.layerIndexes[mapId] = new StyleLayerIndex();
195
+ }
196
+ return layerIndexes;
197
+ }
198
+
199
+ getWorkerSource(mapId: string, type: string, source: string) {
200
+ if (!this.workerSources[mapId])
201
+ this.workerSources[mapId] = {};
202
+ if (!this.workerSources[mapId][type])
203
+ this.workerSources[mapId][type] = {};
204
+
205
+ if (!this.workerSources[mapId][type][source]) {
206
+ // use a wrapped actor so that we can attach a target mapId param
207
+ // to any messages invoked by the WorkerSource
208
+ const actor = {
209
+ send: (type, data, callback) => {
210
+ this.actor.send(type, data, callback, mapId);
211
+ }
212
+ };
213
+ this.workerSources[mapId][type][source] = new (this.workerSourceTypes[type]: any)((actor: any), this.getLayerIndex(mapId), this.getAvailableImages(mapId));
214
+ }
215
+
216
+ return this.workerSources[mapId][type][source];
217
+ }
218
+
219
+ getDEMWorkerSource(mapId: string, source: string) {
220
+ if (!this.demWorkerSources[mapId])
221
+ this.demWorkerSources[mapId] = {};
222
+
223
+ if (!this.demWorkerSources[mapId][source]) {
224
+ this.demWorkerSources[mapId][source] = new RasterDEMTileWorkerSource();
225
+ }
226
+
227
+ return this.demWorkerSources[mapId][source];
228
+ }
229
+
230
+ enforceCacheSizeLimit(mapId: string, limit: number) {
231
+ enforceCacheSizeLimit(limit);
232
+ }
233
+ }
234
+
235
+ /* global self, WorkerGlobalScope */
236
+ if (typeof WorkerGlobalScope !== 'undefined' &&
237
+ typeof self !== 'undefined' &&
238
+ self instanceof WorkerGlobalScope) {
239
+ self.worker = new Worker(self);
240
+ }