@mapgis/mapbox-gl 1.9.12 → 16.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (435) hide show
  1. package/.flowconfig +61 -0
  2. package/LICENSE.txt +84 -0
  3. package/README.md +30 -13
  4. package/build/banner.js +4 -0
  5. package/build/check-bundle-size.js +140 -0
  6. package/build/generate-access-token-script.js +11 -0
  7. package/build/generate-flow-typed-style-spec.js +188 -0
  8. package/build/generate-release-list.js +21 -0
  9. package/build/generate-struct-arrays.js +237 -0
  10. package/build/generate-style-code.js +159 -0
  11. package/build/mapbox-gl.js.flow +3 -0
  12. package/build/print-release-url.js +6 -0
  13. package/build/rollup_plugin_minify_style_spec.js +20 -0
  14. package/build/rollup_plugins.js +80 -0
  15. package/build/run-node +3 -0
  16. package/build/run-tap +8 -0
  17. package/build/test/build-tape.js +19 -0
  18. package/dist/mapbox-gl.js +4 -4
  19. package/dist/mapbox-gl.js.map +1 -0
  20. package/flow-typed/gl.js +5 -0
  21. package/flow-typed/jsdom.js +18 -0
  22. package/flow-typed/mapbox-gl-supported.js +9 -0
  23. package/flow-typed/mapbox-unitbezier.js +14 -0
  24. package/flow-typed/offscreen-canvas.js +9 -0
  25. package/flow-typed/pbf.js +25 -0
  26. package/flow-typed/point-geometry.js +44 -0
  27. package/flow-typed/potpack.js +12 -0
  28. package/flow-typed/sinon.js +28 -0
  29. package/flow-typed/vector-tile.js +41 -0
  30. package/package.json +170 -19
  31. package/src/css/mapbox-gl.css +798 -0
  32. package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
  33. package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
  34. package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
  35. package/src/css/svg/mapboxgl-ctrl-geolocate.svg +5 -0
  36. package/src/css/svg/mapboxgl-ctrl-logo.svg +20 -0
  37. package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
  38. package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
  39. package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
  40. package/src/data/array_types.js +1095 -0
  41. package/src/data/bucket/circle_attributes.js +9 -0
  42. package/src/data/bucket/circle_bucket.js +204 -0
  43. package/src/data/bucket/fill_attributes.js +9 -0
  44. package/src/data/bucket/fill_bucket.js +233 -0
  45. package/src/data/bucket/fill_extrusion_attributes.js +10 -0
  46. package/src/data/bucket/fill_extrusion_bucket.js +289 -0
  47. package/src/data/bucket/heatmap_bucket.js +17 -0
  48. package/src/data/bucket/line_attributes.js +10 -0
  49. package/src/data/bucket/line_bucket.js +556 -0
  50. package/src/data/bucket/pattern_attributes.js +10 -0
  51. package/src/data/bucket/pattern_bucket_features.js +60 -0
  52. package/src/data/bucket/symbol_attributes.js +117 -0
  53. package/src/data/bucket/symbol_bucket.js +972 -0
  54. package/src/data/bucket.js +123 -0
  55. package/src/data/dem_data.js +125 -0
  56. package/src/data/extent.js +18 -0
  57. package/src/data/feature_index.js +321 -0
  58. package/src/data/feature_position_map.js +125 -0
  59. package/src/data/index_array_type.js +16 -0
  60. package/src/data/load_geometry.js +48 -0
  61. package/src/data/pos_attributes.js +6 -0
  62. package/src/data/program_configuration.js +687 -0
  63. package/src/data/raster_bounds_attributes.js +7 -0
  64. package/src/data/segment.js +76 -0
  65. package/src/geo/edge_insets.js +102 -0
  66. package/src/geo/lng_lat.js +165 -0
  67. package/src/geo/lng_lat_bounds.js +267 -0
  68. package/src/geo/mercator_coordinate.js +153 -0
  69. package/src/geo/transform.js +864 -0
  70. package/src/gl/color_mode.js +34 -0
  71. package/src/gl/context.js +298 -0
  72. package/src/gl/cull_face_mode.js +26 -0
  73. package/src/gl/depth_mode.js +29 -0
  74. package/src/gl/framebuffer.js +44 -0
  75. package/src/gl/index_buffer.js +55 -0
  76. package/src/gl/stencil_mode.js +30 -0
  77. package/src/gl/types.js +84 -0
  78. package/src/gl/value.js +520 -0
  79. package/src/gl/vertex_buffer.js +119 -0
  80. package/src/index.js +201 -0
  81. package/src/render/draw_background.js +57 -0
  82. package/src/render/draw_circle.js +113 -0
  83. package/src/render/draw_collision_debug.js +49 -0
  84. package/src/render/draw_custom.js +49 -0
  85. package/src/render/draw_debug.js +127 -0
  86. package/src/render/draw_fill.js +126 -0
  87. package/src/render/draw_fill_extrusion.js +96 -0
  88. package/src/render/draw_heatmap.js +140 -0
  89. package/src/render/draw_hillshade.js +108 -0
  90. package/src/render/draw_line.js +98 -0
  91. package/src/render/draw_raster.js +125 -0
  92. package/src/render/draw_symbol.js +394 -0
  93. package/src/render/glyph_atlas.js +71 -0
  94. package/src/render/glyph_manager.js +182 -0
  95. package/src/render/image_atlas.js +149 -0
  96. package/src/render/image_manager.js +306 -0
  97. package/src/render/line_atlas.js +210 -0
  98. package/src/render/painter.js +653 -0
  99. package/src/render/program/background_program.js +103 -0
  100. package/src/render/program/circle_program.js +69 -0
  101. package/src/render/program/clipping_mask_program.js +20 -0
  102. package/src/render/program/collision_program.js +49 -0
  103. package/src/render/program/debug_program.js +35 -0
  104. package/src/render/program/fill_extrusion_program.js +122 -0
  105. package/src/render/program/fill_program.js +126 -0
  106. package/src/render/program/heatmap_program.js +83 -0
  107. package/src/render/program/hillshade_program.js +122 -0
  108. package/src/render/program/line_program.js +207 -0
  109. package/src/render/program/pattern.js +102 -0
  110. package/src/render/program/program_uniforms.js +42 -0
  111. package/src/render/program/raster_program.js +92 -0
  112. package/src/render/program/symbol_program.js +224 -0
  113. package/src/render/program.js +168 -0
  114. package/src/render/texture.js +122 -0
  115. package/src/render/uniform_binding.js +147 -0
  116. package/src/render/vertex_array_object.js +163 -0
  117. package/src/shaders/README.md +42 -0
  118. package/src/shaders/_prelude.fragment.glsl +17 -0
  119. package/src/shaders/_prelude.vertex.glsl +73 -0
  120. package/src/shaders/background.fragment.glsl +10 -0
  121. package/src/shaders/background.vertex.glsl +7 -0
  122. package/src/shaders/background_pattern.fragment.glsl +28 -0
  123. package/src/shaders/background_pattern.vertex.glsl +20 -0
  124. package/src/shaders/circle.fragment.glsl +39 -0
  125. package/src/shaders/circle.vertex.glsl +64 -0
  126. package/src/shaders/clipping_mask.fragment.glsl +3 -0
  127. package/src/shaders/clipping_mask.vertex.glsl +7 -0
  128. package/src/shaders/collision_box.fragment.glsl +21 -0
  129. package/src/shaders/collision_box.vertex.glsl +27 -0
  130. package/src/shaders/collision_circle.fragment.glsl +34 -0
  131. package/src/shaders/collision_circle.vertex.glsl +36 -0
  132. package/src/shaders/debug.fragment.glsl +9 -0
  133. package/src/shaders/debug.vertex.glsl +12 -0
  134. package/src/shaders/encode_attribute.js +17 -0
  135. package/src/shaders/fill.fragment.glsl +13 -0
  136. package/src/shaders/fill.vertex.glsl +13 -0
  137. package/src/shaders/fill_extrusion.fragment.glsl +9 -0
  138. package/src/shaders/fill_extrusion.vertex.glsl +66 -0
  139. package/src/shaders/fill_extrusion_pattern.fragment.glsl +45 -0
  140. package/src/shaders/fill_extrusion_pattern.vertex.glsl +79 -0
  141. package/src/shaders/fill_outline.fragment.glsl +17 -0
  142. package/src/shaders/fill_outline.vertex.glsl +17 -0
  143. package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
  144. package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
  145. package/src/shaders/fill_pattern.fragment.glsl +36 -0
  146. package/src/shaders/fill_pattern.vertex.glsl +39 -0
  147. package/src/shaders/heatmap.fragment.glsl +22 -0
  148. package/src/shaders/heatmap.vertex.glsl +54 -0
  149. package/src/shaders/heatmap_texture.fragment.glsl +14 -0
  150. package/src/shaders/heatmap_texture.vertex.glsl +11 -0
  151. package/src/shaders/hillshade.fragment.glsl +52 -0
  152. package/src/shaders/hillshade.vertex.glsl +11 -0
  153. package/src/shaders/hillshade_prepare.fragment.glsl +74 -0
  154. package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
  155. package/src/shaders/index.js +20 -0
  156. package/src/shaders/line.fragment.glsl +30 -0
  157. package/src/shaders/line.vertex.glsl +85 -0
  158. package/src/shaders/line_gradient.fragment.glsl +34 -0
  159. package/src/shaders/line_gradient.vertex.glsl +87 -0
  160. package/src/shaders/line_pattern.fragment.glsl +74 -0
  161. package/src/shaders/line_pattern.vertex.glsl +99 -0
  162. package/src/shaders/line_sdf.fragment.glsl +45 -0
  163. package/src/shaders/line_sdf.vertex.glsl +98 -0
  164. package/src/shaders/raster.fragment.glsl +52 -0
  165. package/src/shaders/raster.vertex.glsl +21 -0
  166. package/src/shaders/shaders.js +180 -0
  167. package/src/shaders/symbol_icon.fragment.glsl +17 -0
  168. package/src/shaders/symbol_icon.vertex.glsl +94 -0
  169. package/src/shaders/symbol_sdf.fragment.glsl +52 -0
  170. package/src/shaders/symbol_sdf.vertex.glsl +115 -0
  171. package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
  172. package/src/shaders/symbol_text_and_icon.vertex.glsl +116 -0
  173. package/src/source/canvas_source.js +238 -0
  174. package/src/source/geojson_helper.js +92 -0
  175. package/src/source/geojson_source.js +374 -0
  176. package/src/source/geojson_worker_source.js +357 -0
  177. package/src/source/geojson_wrapper.js +94 -0
  178. package/src/source/image_source.js +307 -0
  179. package/src/source/load_tilejson.js +39 -0
  180. package/src/source/mbtiles_source.js +115 -0
  181. package/src/source/offline_database.js +61 -0
  182. package/src/source/offline_database_root.js +62 -0
  183. package/src/source/pixels_to_tile_units.js +21 -0
  184. package/src/source/query_features.js +208 -0
  185. package/src/source/raster_dem_tile_source.js +138 -0
  186. package/src/source/raster_dem_tile_worker_source.js +62 -0
  187. package/src/source/raster_tile_offline_source.js +136 -0
  188. package/src/source/raster_tile_source.js +177 -0
  189. package/src/source/rtl_text_plugin.js +138 -0
  190. package/src/source/source.js +137 -0
  191. package/src/source/source_cache.js +957 -0
  192. package/src/source/source_state.js +159 -0
  193. package/src/source/tile.js +465 -0
  194. package/src/source/tile_bounds.js +38 -0
  195. package/src/source/tile_cache.js +212 -0
  196. package/src/source/tile_id.js +402 -0
  197. package/src/source/vector_tile_source.js +192 -0
  198. package/src/source/vector_tile_worker_source.js +216 -0
  199. package/src/source/video_source.js +203 -0
  200. package/src/source/worker.js +237 -0
  201. package/src/source/worker_source.js +106 -0
  202. package/src/source/worker_tile.js +224 -0
  203. package/src/style/create_style_layer.js +36 -0
  204. package/src/style/evaluation_parameters.js +62 -0
  205. package/src/style/light.js +130 -0
  206. package/src/style/load_glyph_range.js +38 -0
  207. package/src/style/load_sprite.js +67 -0
  208. package/src/style/parse_glyph_pbf.js +44 -0
  209. package/src/style/pauseable_placement.js +132 -0
  210. package/src/style/properties.js +753 -0
  211. package/src/style/query_utils.js +43 -0
  212. package/src/style/style.js +1361 -0
  213. package/src/style/style_glyph.js +17 -0
  214. package/src/style/style_image.js +137 -0
  215. package/src/style/style_layer/background_style_layer.js +21 -0
  216. package/src/style/style_layer/background_style_layer_properties.js +40 -0
  217. package/src/style/style_layer/circle_style_layer.js +98 -0
  218. package/src/style/style_layer/circle_style_layer_properties.js +63 -0
  219. package/src/style/style_layer/custom_style_layer.js +223 -0
  220. package/src/style/style_layer/fill_extrusion_style_layer.js +224 -0
  221. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +50 -0
  222. package/src/style/style_layer/fill_style_layer.js +67 -0
  223. package/src/style/style_layer/fill_style_layer_properties.js +55 -0
  224. package/src/style/style_layer/heatmap_style_layer.js +69 -0
  225. package/src/style/style_layer/heatmap_style_layer_properties.js +44 -0
  226. package/src/style/style_layer/hillshade_style_layer.js +25 -0
  227. package/src/style/style_layer/hillshade_style_layer_properties.js +46 -0
  228. package/src/style/style_layer/layer_properties.js.ejs +69 -0
  229. package/src/style/style_layer/line_style_layer.js +151 -0
  230. package/src/style/style_layer/line_style_layer_properties.js +71 -0
  231. package/src/style/style_layer/raster_style_layer.js +21 -0
  232. package/src/style/style_layer/raster_style_layer_properties.js +50 -0
  233. package/src/style/style_layer/symbol_style_layer.js +190 -0
  234. package/src/style/style_layer/symbol_style_layer_properties.js +153 -0
  235. package/src/style/style_layer/typed_style_layer.js +17 -0
  236. package/src/style/style_layer.js +281 -0
  237. package/src/style/style_layer_index.js +80 -0
  238. package/src/style/validate_style.js +42 -0
  239. package/src/style/zoom_history.js +44 -0
  240. package/src/style-spec/.eslintrc +5 -0
  241. package/src/style-spec/CHANGELOG.md +438 -0
  242. package/src/style-spec/README.md +59 -0
  243. package/src/style-spec/bin/gl-style-composite +9 -0
  244. package/src/style-spec/bin/gl-style-format +22 -0
  245. package/src/style-spec/bin/gl-style-migrate +9 -0
  246. package/src/style-spec/bin/gl-style-validate +50 -0
  247. package/src/style-spec/composite.js +50 -0
  248. package/src/style-spec/declass.js +42 -0
  249. package/src/style-spec/deref.js +52 -0
  250. package/src/style-spec/diff.js +393 -0
  251. package/src/style-spec/dist/.gitkeep +0 -0
  252. package/src/style-spec/empty.js +29 -0
  253. package/src/style-spec/error/parsing_error.js +16 -0
  254. package/src/style-spec/error/validation_error.js +18 -0
  255. package/src/style-spec/expression/compound_expression.js +162 -0
  256. package/src/style-spec/expression/definitions/assertion.js +130 -0
  257. package/src/style-spec/expression/definitions/at.js +70 -0
  258. package/src/style-spec/expression/definitions/case.js +85 -0
  259. package/src/style-spec/expression/definitions/coalesce.js +93 -0
  260. package/src/style-spec/expression/definitions/coercion.js +133 -0
  261. package/src/style-spec/expression/definitions/collator.js +78 -0
  262. package/src/style-spec/expression/definitions/comparison.js +184 -0
  263. package/src/style-spec/expression/definitions/format.js +144 -0
  264. package/src/style-spec/expression/definitions/format_section_override.js +54 -0
  265. package/src/style-spec/expression/definitions/image.js +52 -0
  266. package/src/style-spec/expression/definitions/in.js +92 -0
  267. package/src/style-spec/expression/definitions/index.js +561 -0
  268. package/src/style-spec/expression/definitions/interpolate.js +267 -0
  269. package/src/style-spec/expression/definitions/length.js +61 -0
  270. package/src/style-spec/expression/definitions/let.js +72 -0
  271. package/src/style-spec/expression/definitions/literal.js +77 -0
  272. package/src/style-spec/expression/definitions/match.js +158 -0
  273. package/src/style-spec/expression/definitions/number_format.js +142 -0
  274. package/src/style-spec/expression/definitions/step.js +120 -0
  275. package/src/style-spec/expression/definitions/var.js +46 -0
  276. package/src/style-spec/expression/definitions/within.js +333 -0
  277. package/src/style-spec/expression/evaluation_context.js +59 -0
  278. package/src/style-spec/expression/expression.js +27 -0
  279. package/src/style-spec/expression/index.js +392 -0
  280. package/src/style-spec/expression/is_constant.js +59 -0
  281. package/src/style-spec/expression/parsing_context.js +233 -0
  282. package/src/style-spec/expression/parsing_error.js +13 -0
  283. package/src/style-spec/expression/runtime_error.js +17 -0
  284. package/src/style-spec/expression/scope.js +36 -0
  285. package/src/style-spec/expression/stops.js +39 -0
  286. package/src/style-spec/expression/types/collator.js +61 -0
  287. package/src/style-spec/expression/types/formatted.js +73 -0
  288. package/src/style-spec/expression/types/resolved_image.js +29 -0
  289. package/src/style-spec/expression/types.js +106 -0
  290. package/src/style-spec/expression/values.js +123 -0
  291. package/src/style-spec/feature_filter/README.md +55 -0
  292. package/src/style-spec/feature_filter/convert.js +208 -0
  293. package/src/style-spec/feature_filter/index.js +165 -0
  294. package/src/style-spec/format.js +51 -0
  295. package/src/style-spec/function/convert.js +254 -0
  296. package/src/style-spec/function/index.js +262 -0
  297. package/src/style-spec/group_by_layout.js +75 -0
  298. package/src/style-spec/migrate/expressions.js +39 -0
  299. package/src/style-spec/migrate/v8.js +203 -0
  300. package/src/style-spec/migrate/v9.js +26 -0
  301. package/src/style-spec/migrate.js +36 -0
  302. package/src/style-spec/package.json +41 -0
  303. package/src/style-spec/read_style.js +14 -0
  304. package/src/style-spec/reference/latest.js +3 -0
  305. package/src/style-spec/reference/v8.json +5808 -0
  306. package/src/style-spec/rollup.config.js +45 -0
  307. package/src/style-spec/style-spec.js +122 -0
  308. package/src/style-spec/types.js +438 -0
  309. package/src/style-spec/util/color.js +95 -0
  310. package/src/style-spec/util/color_spaces.js +139 -0
  311. package/src/style-spec/util/deep_equal.js +28 -0
  312. package/src/style-spec/util/extend.js +10 -0
  313. package/src/style-spec/util/get_type.js +17 -0
  314. package/src/style-spec/util/interpolate.js +22 -0
  315. package/src/style-spec/util/properties.js +15 -0
  316. package/src/style-spec/util/ref_properties.js +2 -0
  317. package/src/style-spec/util/result.js +19 -0
  318. package/src/style-spec/util/unbundle_jsonlint.js +24 -0
  319. package/src/style-spec/validate/latest.js +11 -0
  320. package/src/style-spec/validate/validate.js +75 -0
  321. package/src/style-spec/validate/validate_array.js +52 -0
  322. package/src/style-spec/validate/validate_boolean.js +15 -0
  323. package/src/style-spec/validate/validate_color.js +20 -0
  324. package/src/style-spec/validate/validate_constants.js +13 -0
  325. package/src/style-spec/validate/validate_enum.js +21 -0
  326. package/src/style-spec/validate/validate_expression.js +43 -0
  327. package/src/style-spec/validate/validate_filter.js +111 -0
  328. package/src/style-spec/validate/validate_formatted.js +11 -0
  329. package/src/style-spec/validate/validate_function.js +207 -0
  330. package/src/style-spec/validate/validate_glyphs_url.js +21 -0
  331. package/src/style-spec/validate/validate_image.js +11 -0
  332. package/src/style-spec/validate/validate_layer.js +134 -0
  333. package/src/style-spec/validate/validate_layout_property.js +6 -0
  334. package/src/style-spec/validate/validate_light.js +47 -0
  335. package/src/style-spec/validate/validate_number.js +29 -0
  336. package/src/style-spec/validate/validate_object.js +61 -0
  337. package/src/style-spec/validate/validate_paint_property.js +6 -0
  338. package/src/style-spec/validate/validate_property.js +64 -0
  339. package/src/style-spec/validate/validate_source.js +111 -0
  340. package/src/style-spec/validate/validate_string.js +15 -0
  341. package/src/style-spec/validate_mapbox_api_supported.js +171 -0
  342. package/src/style-spec/validate_style.js +39 -0
  343. package/src/style-spec/validate_style.min.js +78 -0
  344. package/src/style-spec/visit.js +77 -0
  345. package/src/symbol/anchor.js +26 -0
  346. package/src/symbol/check_max_angle.js +81 -0
  347. package/src/symbol/clip_line.js +71 -0
  348. package/src/symbol/collision_feature.js +217 -0
  349. package/src/symbol/collision_index.js +372 -0
  350. package/src/symbol/cross_tile_symbol_index.js +301 -0
  351. package/src/symbol/get_anchors.js +167 -0
  352. package/src/symbol/grid_index.js +335 -0
  353. package/src/symbol/mergelines.js +82 -0
  354. package/src/symbol/one_em.js +4 -0
  355. package/src/symbol/opacity_state.js +27 -0
  356. package/src/symbol/placement.js +1062 -0
  357. package/src/symbol/projection.js +450 -0
  358. package/src/symbol/quads.js +334 -0
  359. package/src/symbol/shaping.js +816 -0
  360. package/src/symbol/symbol_layout.js +772 -0
  361. package/src/symbol/symbol_size.js +113 -0
  362. package/src/symbol/transform_text.js +29 -0
  363. package/src/types/callback.js +17 -0
  364. package/src/types/cancelable.js +3 -0
  365. package/src/types/tilejson.js +17 -0
  366. package/src/types/transferable.js +3 -0
  367. package/src/types/window.js +172 -0
  368. package/src/ui/anchor.js +32 -0
  369. package/src/ui/bind_handlers.js +202 -0
  370. package/src/ui/camera.js +1152 -0
  371. package/src/ui/control/attribution_control.js +189 -0
  372. package/src/ui/control/fps_control.js +185 -0
  373. package/src/ui/control/fullscreen_control.js +147 -0
  374. package/src/ui/control/geolocate_control.js +594 -0
  375. package/src/ui/control/logo_control.js +92 -0
  376. package/src/ui/control/navigation_control.js +148 -0
  377. package/src/ui/control/scale_control.js +142 -0
  378. package/src/ui/crs.js +64 -0
  379. package/src/ui/default_locale.js +20 -0
  380. package/src/ui/events.js +806 -0
  381. package/src/ui/handler/box_zoom.js +175 -0
  382. package/src/ui/handler/dblclick_zoom.js +139 -0
  383. package/src/ui/handler/drag_pan.js +416 -0
  384. package/src/ui/handler/drag_rotate.js +378 -0
  385. package/src/ui/handler/keyboard.js +161 -0
  386. package/src/ui/handler/scroll_zoom.js +333 -0
  387. package/src/ui/handler/touch_zoom_rotate.js +293 -0
  388. package/src/ui/hash.js +147 -0
  389. package/src/ui/map.js +2883 -0
  390. package/src/ui/marker.js +607 -0
  391. package/src/ui/offline_map.js +91 -0
  392. package/src/ui/popup.js +530 -0
  393. package/src/util/actor.js +212 -0
  394. package/src/util/ajax.js +371 -0
  395. package/src/util/browser/web_worker.js +10 -0
  396. package/src/util/browser/window.js +5 -0
  397. package/src/util/browser.js +70 -0
  398. package/src/util/classify_rings.js +52 -0
  399. package/src/util/color_ramp.js +28 -0
  400. package/src/util/config.js +30 -0
  401. package/src/util/debug.js +12 -0
  402. package/src/util/dictionary_coder.js +30 -0
  403. package/src/util/dispatcher.js +70 -0
  404. package/src/util/dom.js +144 -0
  405. package/src/util/evented.js +174 -0
  406. package/src/util/find_pole_of_inaccessibility.js +129 -0
  407. package/src/util/global_worker_pool.js +17 -0
  408. package/src/util/image.js +142 -0
  409. package/src/util/intersection_tests.js +208 -0
  410. package/src/util/is_char_in_unicode_block.js +311 -0
  411. package/src/util/mapbox.js +486 -0
  412. package/src/util/offscreen_canvas_supported.js +14 -0
  413. package/src/util/performance.js +112 -0
  414. package/src/util/primitives.js +145 -0
  415. package/src/util/resolve_tokens.js +16 -0
  416. package/src/util/script_detection.js +328 -0
  417. package/src/util/sku_token.js +42 -0
  418. package/src/util/smart_wrap.js +55 -0
  419. package/src/util/struct_array.js +243 -0
  420. package/src/util/struct_array.js.ejs +112 -0
  421. package/src/util/struct_array_layout.js.ejs +98 -0
  422. package/src/util/task_queue.js +68 -0
  423. package/src/util/throttle.js +28 -0
  424. package/src/util/throttled_invoker.js +46 -0
  425. package/src/util/tile_cover.js +101 -0
  426. package/src/util/tile_request_cache.js +172 -0
  427. package/src/util/util.js +504 -0
  428. package/src/util/vectortile_to_geojson.js +54 -0
  429. package/src/util/verticalize_punctuation.js +114 -0
  430. package/src/util/web_worker.js +91 -0
  431. package/src/util/web_worker_transfer.js +266 -0
  432. package/src/util/webp_supported.js +69 -0
  433. package/src/util/window.js +102 -0
  434. package/src/util/worker_pool.js +47 -0
  435. package/postcss.config.js +0 -16
@@ -0,0 +1,238 @@
1
+ // @flow
2
+
3
+ import ImageSource from './image_source';
4
+
5
+ import window from '../util/window';
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
+
16
+ export type CanvasSourceSpecification = {|
17
+ "type": "canvas",
18
+ "coordinates": [[number, number], [number, number], [number, number], [number, number]],
19
+ "animate"?: boolean,
20
+ "canvas": string | HTMLCanvasElement
21
+ |};
22
+
23
+ /**
24
+ * Options to add a canvas source type to the map.
25
+ *
26
+ * @typedef {Object} CanvasSourceOptions
27
+ * @property {string} type Source type. Must be `"canvas"`.
28
+ * @property {string|HTMLCanvasElement} canvas Canvas source from which to read pixels. Can be a string representing the ID of the canvas element, or the `HTMLCanvasElement` itself.
29
+ * @property {Array<Array<number>>} coordinates Four geographical coordinates denoting where to place the corners of the canvas, specified in `[longitude, latitude]` pairs.
30
+ * @property {boolean} [animate=true] Whether the canvas source is animated. If the canvas is static (i.e. pixels do not need to be re-read on every frame), `animate` should be set to `false` to improve performance.
31
+ */
32
+
33
+ /**
34
+ * A data source containing the contents of an HTML canvas. See {@link CanvasSourceOptions} for detailed documentation of options.
35
+ *
36
+ * @example
37
+ * // add to map
38
+ * map.addSource('some id', {
39
+ * type: 'canvas',
40
+ * canvas: 'idOfMyHTMLCanvas',
41
+ * animate: true,
42
+ * coordinates: [
43
+ * [-76.54, 39.18],
44
+ * [-76.52, 39.18],
45
+ * [-76.52, 39.17],
46
+ * [-76.54, 39.17]
47
+ * ]
48
+ * });
49
+ *
50
+ * // update
51
+ * var mySource = map.getSource('some id');
52
+ * mySource.setCoordinates([
53
+ * [-76.54335737228394, 39.18579907229748],
54
+ * [-76.52803659439087, 39.1838364847587],
55
+ * [-76.5295386314392, 39.17683392507606],
56
+ * [-76.54520273208618, 39.17876344106642]
57
+ * ]);
58
+ *
59
+ * map.removeSource('some id'); // remove
60
+ */
61
+ class CanvasSource extends ImageSource {
62
+ options: CanvasSourceSpecification;
63
+ animate: boolean;
64
+ canvas: HTMLCanvasElement;
65
+ width: number;
66
+ height: number;
67
+ play: () => void;
68
+ pause: () => void;
69
+ _playing: boolean;
70
+
71
+ /**
72
+ * @private
73
+ */
74
+ constructor(id: string, options: CanvasSourceSpecification, dispatcher: Dispatcher, eventedParent: Evented) {
75
+ super(id, options, dispatcher, eventedParent);
76
+
77
+ // We build in some validation here, since canvas sources aren't included in the style spec:
78
+ if (!options.coordinates) {
79
+ this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, 'missing required property "coordinates"')));
80
+ } else if (!Array.isArray(options.coordinates) || options.coordinates.length !== 4 ||
81
+ options.coordinates.some(c => !Array.isArray(c) || c.length !== 2 || c.some(l => typeof l !== 'number'))) {
82
+ this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, '"coordinates" property must be an array of 4 longitude/latitude array pairs')));
83
+ }
84
+
85
+ if (options.animate && typeof options.animate !== 'boolean') {
86
+ this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, 'optional "animate" property must be a boolean value')));
87
+ }
88
+
89
+ if (!options.canvas) {
90
+ this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, 'missing required property "canvas"')));
91
+ } else if (typeof options.canvas !== 'string' && !(options.canvas instanceof window.HTMLCanvasElement)) {
92
+ this.fire(new ErrorEvent(new ValidationError(`sources.${id}`, null, '"canvas" must be either a string representing the ID of the canvas element from which to read, or an HTMLCanvasElement instance')));
93
+ }
94
+
95
+ this.options = options;
96
+ this.animate = options.animate !== undefined ? options.animate : true;
97
+ }
98
+
99
+ /**
100
+ * Enables animation. The image will be copied from the canvas to the map on each frame.
101
+ * @method play
102
+ * @instance
103
+ * @memberof CanvasSource
104
+ */
105
+
106
+ /**
107
+ * Disables animation. The map will display a static copy of the canvas image.
108
+ * @method pause
109
+ * @instance
110
+ * @memberof CanvasSource
111
+ */
112
+
113
+ load() {
114
+ this._loaded = true;
115
+ if (!this.canvas) {
116
+ this.canvas = (this.options.canvas instanceof window.HTMLCanvasElement) ?
117
+ this.options.canvas :
118
+ window.document.getElementById(this.options.canvas);
119
+ }
120
+ this.width = this.canvas.width;
121
+ this.height = this.canvas.height;
122
+
123
+ if (this._hasInvalidDimensions()) {
124
+ this.fire(new ErrorEvent(new Error('Canvas dimensions cannot be less than or equal to zero.')));
125
+ return;
126
+ }
127
+
128
+ this.play = function() {
129
+ this._playing = true;
130
+ this.map.triggerRepaint();
131
+ };
132
+
133
+ this.pause = function() {
134
+ if (this._playing) {
135
+ this.prepare();
136
+ this._playing = false;
137
+ }
138
+ };
139
+
140
+ this._finishLoading();
141
+ }
142
+
143
+ /**
144
+ * Returns the HTML `canvas` element.
145
+ *
146
+ * @returns {HTMLCanvasElement} The HTML `canvas` element.
147
+ */
148
+ getCanvas() {
149
+ return this.canvas;
150
+ }
151
+
152
+ onAdd(map: Map) {
153
+ this.map = map;
154
+ this.load();
155
+ if (this.canvas) {
156
+ if (this.animate) this.play();
157
+ }
158
+ }
159
+
160
+ onRemove() {
161
+ this.pause();
162
+ }
163
+
164
+ /**
165
+ * Sets the canvas's coordinates and re-renders the map.
166
+ *
167
+ * @method setCoordinates
168
+ * @instance
169
+ * @memberof CanvasSource
170
+ * @param {Array<Array<number>>} coordinates Four geographical coordinates,
171
+ * represented as arrays of longitude and latitude numbers, which define the corners of the canvas.
172
+ * The coordinates start at the top left corner of the canvas and proceed in clockwise order.
173
+ * They do not have to represent a rectangle.
174
+ * @returns {CanvasSource} this
175
+ */
176
+ // setCoordinates inherited from ImageSource
177
+
178
+ prepare() {
179
+ let resize = false;
180
+ if (this.canvas.width !== this.width) {
181
+ this.width = this.canvas.width;
182
+ resize = true;
183
+ }
184
+ if (this.canvas.height !== this.height) {
185
+ this.height = this.canvas.height;
186
+ resize = true;
187
+ }
188
+
189
+ if (this._hasInvalidDimensions()) return;
190
+
191
+ if (Object.keys(this.tiles).length === 0) return; // not enough data for current position
192
+
193
+ const context = this.map.painter.context;
194
+ const gl = context.gl;
195
+
196
+ if (!this.boundsBuffer) {
197
+ this.boundsBuffer = context.createVertexBuffer(this._boundsArray, rasterBoundsAttributes.members);
198
+ }
199
+
200
+ if (!this.boundsSegments) {
201
+ this.boundsSegments = SegmentVector.simpleSegment(0, 0, 4, 2);
202
+ }
203
+
204
+ if (!this.texture) {
205
+ this.texture = new Texture(context, this.canvas, gl.RGBA, {premultiply: true});
206
+ } else if (resize || this._playing) {
207
+ this.texture.update(this.canvas, {premultiply: true});
208
+ }
209
+
210
+ for (const w in this.tiles) {
211
+ const tile = this.tiles[w];
212
+ if (tile.state !== 'loaded') {
213
+ tile.state = 'loaded';
214
+ tile.texture = this.texture;
215
+ }
216
+ }
217
+ }
218
+
219
+ serialize(): Object {
220
+ return {
221
+ type: 'canvas',
222
+ coordinates: this.coordinates
223
+ };
224
+ }
225
+
226
+ hasTransition() {
227
+ return this._playing;
228
+ }
229
+
230
+ _hasInvalidDimensions() {
231
+ for (const x of [this.canvas.width, this.canvas.height]) {
232
+ if (isNaN(x) || x <= 0) return true;
233
+ }
234
+ return false;
235
+ }
236
+ }
237
+
238
+ export default CanvasSource;
@@ -0,0 +1,92 @@
1
+ /**
2
+ *
3
+ * @param {*} data
4
+ * @param {*} crs
5
+ */
6
+ export function loopData(data, crs) {
7
+ if (data.type === "FeatureCollection") {
8
+ data = loopFeatureCollection(data);
9
+ } else if (data.type === "Point") {
10
+ data = oopPoint(data);
11
+ } else if (data.type === "LineString" || data.type === "MultiPoint") {
12
+ data = loopLine(data);
13
+ } else if (data.type === "Polygon" || data.type === "MultiLineString") {
14
+ data = loopPolygon(data);
15
+ } else if (data.type === "MultiPolygon") {
16
+ data = loopMultiPolygon(data);
17
+ }
18
+ console.log("loopdata", data);
19
+ return data;
20
+ }
21
+
22
+ /**
23
+ * 原先的 90 ~ -90 -> 90 ~ -270, 按照对应的百分比处理
24
+ * @param {*} lat
25
+ */
26
+ function fixLat(lat) {
27
+ let percent = (90 + lat) / 180;
28
+ let zero = 90 * percent;
29
+ return zero || (45 + zero / 2);
30
+ }
31
+
32
+ function loopFeatureCollection(data) {
33
+ data.features = data.features.map(f => {
34
+ if (f.geometry.type === "Point") {
35
+ f = loopPoint(f);
36
+ } else if (
37
+ f.geometry.type === "LineString" ||
38
+ data.type === "MultiPoint"
39
+ ) {
40
+ f = loopLine(f);
41
+ } else if (
42
+ f.geometry.type === "Polygon" ||
43
+ data.type === "MultiLineString"
44
+ ) {
45
+ f = loopPolygon(f);
46
+ } else if (f.geometry.type === "MultiPolygon") {
47
+ f = loopMultiPolygon(f);
48
+ }
49
+ return f;
50
+ });
51
+ return data;
52
+ }
53
+
54
+ // "coordinates": [102,0.5]
55
+ function loopPoint(feature) {
56
+ feature.geometry.coordinates[1] = fixLat(feature.geometry.coordinates[1]);
57
+ return feature;
58
+ }
59
+
60
+ // "coordinates": [[102, 0], [103, 1], [104, 0],[105, 1]]
61
+ function loopLine(feature) {
62
+ feature.geometry.coordinates = feature.geometry.coordinates.map(p => {
63
+ p[1] = fixLat(p[1]);
64
+ return p;
65
+ });
66
+ return feature;
67
+ }
68
+
69
+ function loopPolygon(feature) {
70
+ feature.geometry.coordinates = feature.geometry.coordinates.map(r => {
71
+ r = r.map(p => {
72
+ p[1] = fixLat(p[1]);
73
+ return p;
74
+ });
75
+ return r;
76
+ });
77
+ return feature;
78
+ }
79
+
80
+ function loopMultiPolygon(feature) {
81
+ feature.geometry.coordinates = feature.geometry.coordinates.map(m => {
82
+ m.map(r => {
83
+ r = r.map(p => {
84
+ p[1] = fixLat(p[1]);
85
+ return p;
86
+ });
87
+ return r;
88
+ });
89
+ return m;
90
+ });
91
+ return feature;
92
+ }
@@ -0,0 +1,374 @@
1
+ // @flow
2
+
3
+ import {Event, ErrorEvent, Evented} from '../util/evented';
4
+
5
+ import {extend} from '../util/util';
6
+ import EXTENT from '../data/extent';
7
+ import {ResourceType} from '../util/ajax';
8
+ import browser from '../util/browser';
9
+
10
+ import type {Source} from './source';
11
+ import type Map from '../ui/map';
12
+ import type Dispatcher from '../util/dispatcher';
13
+ import type Tile from './tile';
14
+ import type Actor from '../util/actor';
15
+ import type {Callback} from '../types/callback';
16
+ import type {GeoJSON, GeoJSONFeature} from '@mapbox/geojson-types';
17
+ import type {GeoJSONSourceSpecification, PromoteIdSpecification} from '../style-spec/types';
18
+
19
+ import {loopData} from './geojson_helper';
20
+ import CRS from '../ui/crs';
21
+
22
+ /**
23
+ * A source containing GeoJSON.
24
+ * (See the [Style Specification](https://www.mapbox.com/mapbox-gl-style-spec/#sources-geojson) for detailed documentation of options.)
25
+ *
26
+ * @example
27
+ * map.addSource('some id', {
28
+ * type: 'geojson',
29
+ * data: 'https://d2ad6b4ur7yvpq.cloudfront.net/naturalearth-3.3.0/ne_10m_ports.geojson'
30
+ * });
31
+ *
32
+ * @example
33
+ * map.addSource('some id', {
34
+ * type: 'geojson',
35
+ * data: {
36
+ * "type": "FeatureCollection",
37
+ * "features": [{
38
+ * "type": "Feature",
39
+ * "properties": {},
40
+ * "geometry": {
41
+ * "type": "Point",
42
+ * "coordinates": [
43
+ * -76.53063297271729,
44
+ * 39.18174077994108
45
+ * ]
46
+ * }
47
+ * }]
48
+ * }
49
+ * });
50
+ *
51
+ * @example
52
+ * map.getSource('some id').setData({
53
+ * "type": "FeatureCollection",
54
+ * "features": [{
55
+ * "type": "Feature",
56
+ * "properties": { "name": "Null Island" },
57
+ * "geometry": {
58
+ * "type": "Point",
59
+ * "coordinates": [ 0, 0 ]
60
+ * }
61
+ * }]
62
+ * });
63
+ * @see [Draw GeoJSON points](https://www.mapbox.com/mapbox-gl-js/example/geojson-markers/)
64
+ * @see [Add a GeoJSON line](https://www.mapbox.com/mapbox-gl-js/example/geojson-line/)
65
+ * @see [Create a heatmap from points](https://www.mapbox.com/mapbox-gl-js/example/heatmap/)
66
+ * @see [Create and style clusters](https://www.mapbox.com/mapbox-gl-js/example/cluster/)
67
+ */
68
+ class GeoJSONSource extends Evented implements Source {
69
+ crs: string;
70
+
71
+ type: 'geojson';
72
+ id: string;
73
+ minzoom: number;
74
+ maxzoom: number;
75
+ tileSize: number;
76
+ attribution: string;
77
+ promoteId: ?PromoteIdSpecification;
78
+
79
+ isTileClipped: boolean;
80
+ reparseOverscaled: boolean;
81
+ _data: GeoJSON | string;
82
+ _options: any;
83
+ workerOptions: any;
84
+ map: Map;
85
+ actor: Actor;
86
+ _loaded: boolean;
87
+ _collectResourceTiming: boolean;
88
+ _resourceTiming: Array<PerformanceResourceTiming>;
89
+ _removed: boolean;
90
+
91
+ /**
92
+ * @private
93
+ */
94
+ constructor(id: string, options: GeoJSONSourceSpecification & {workerOptions?: any, collectResourceTiming: boolean}, dispatcher: Dispatcher, eventedParent: Evented) {
95
+ super();
96
+
97
+ this.id = id;
98
+
99
+ // `type` is a property rather than a constant to make it easy for 3rd
100
+ // parties to use GeoJSONSource to build their own source types.
101
+ this.type = 'geojson';
102
+
103
+ this.minzoom = 0;
104
+ this.maxzoom = 18;
105
+ this.tileSize = 512;
106
+ this.isTileClipped = true;
107
+ this.reparseOverscaled = true;
108
+ this._removed = false;
109
+ this._loaded = false;
110
+
111
+ this.actor = dispatcher.getActor();
112
+ this.setEventedParent(eventedParent);
113
+
114
+ this.crs = this.getCrs();
115
+ this._data = options.data;// this.fixCrsData(options.data);
116
+ this._options = extend({}, options);
117
+
118
+ this._collectResourceTiming = options.collectResourceTiming;
119
+ this._resourceTiming = [];
120
+
121
+ if (options.maxzoom !== undefined) this.maxzoom = options.maxzoom;
122
+ if (options.type) this.type = options.type;
123
+ if (options.attribution) this.attribution = options.attribution;
124
+ this.promoteId = options.promoteId;
125
+
126
+ const scale = EXTENT / this.tileSize;
127
+
128
+ // sent to the worker, along with `url: ...` or `data: literal geojson`,
129
+ // so that it can load/parse/index the geojson data
130
+ // extending with `options.workerOptions` helps to make it easy for
131
+ // third-party sources to hack/reuse GeoJSONSource.
132
+ this.workerOptions = extend({
133
+ crs: this.crs,
134
+ source: this.id,
135
+ cluster: options.cluster || false,
136
+ geojsonVtOptions: {
137
+ buffer: (options.buffer !== undefined ? options.buffer : 128) * scale,
138
+ tolerance: (options.tolerance !== undefined ? options.tolerance : 0.375) * scale,
139
+ extent: EXTENT,
140
+ maxZoom: this.maxzoom,
141
+ lineMetrics: options.lineMetrics || false,
142
+ generateId: options.generateId || false,
143
+ crs: this.getCrs(),
144
+ },
145
+ superclusterOptions: {
146
+ maxZoom: options.clusterMaxZoom !== undefined ?
147
+ Math.min(options.clusterMaxZoom, this.maxzoom - 1) :
148
+ (this.maxzoom - 1),
149
+ extent: EXTENT,
150
+ radius: (options.clusterRadius || 50) * scale,
151
+ log: false,
152
+ generateId: options.generateId || false,
153
+ crs: this.getCrs(),
154
+ },
155
+ clusterProperties: options.clusterProperties
156
+ }, options.workerOptions);
157
+ }
158
+
159
+ getCrs() {
160
+ return 'EPSG:3857';
161
+ }
162
+
163
+ fixCrsData(data) {
164
+ if (this.getCrs() !== CRS.EPSG3857.getEpsgCode()) {
165
+ // console.log('before loop', data);
166
+ data = loopData(data);
167
+ // console.log('after loop', data);
168
+ }
169
+ return data;
170
+ }
171
+
172
+ load() {
173
+ this.fire(new Event('dataloading', {dataType: 'source'}));
174
+ this._updateWorkerData((err) => {
175
+ if (err) {
176
+ this.fire(new ErrorEvent(err));
177
+ return;
178
+ }
179
+
180
+ const data: Object = {dataType: 'source', sourceDataType: 'metadata'};
181
+ if (this._collectResourceTiming && this._resourceTiming && (this._resourceTiming.length > 0)) {
182
+ data.resourceTiming = this._resourceTiming;
183
+ this._resourceTiming = [];
184
+ }
185
+
186
+ // although GeoJSON sources contain no metadata, we fire this event to let the SourceCache
187
+ // know its ok to start requesting tiles.
188
+ this.fire(new Event('data', data));
189
+ });
190
+ }
191
+
192
+ onAdd(map: Map) {
193
+ this.map = map;
194
+ this.load();
195
+ }
196
+
197
+ /**
198
+ * Sets the GeoJSON data and re-renders the map.
199
+ *
200
+ * @param {Object|string} data A GeoJSON data object or a URL to one. The latter is preferable in the case of large GeoJSON files.
201
+ * @returns {GeoJSONSource} this
202
+ */
203
+ setData(data: GeoJSON | string) {
204
+ this._data = data;
205
+ this.fire(new Event('dataloading', {dataType: 'source'}));
206
+ this._updateWorkerData((err) => {
207
+ if (err) {
208
+ this.fire(new ErrorEvent(err));
209
+ return;
210
+ }
211
+
212
+ const data: Object = {dataType: 'source', sourceDataType: 'content'};
213
+ if (this._collectResourceTiming && this._resourceTiming && (this._resourceTiming.length > 0)) {
214
+ data.resourceTiming = this._resourceTiming;
215
+ this._resourceTiming = [];
216
+ }
217
+ this.fire(new Event('data', data));
218
+ });
219
+
220
+ return this;
221
+ }
222
+
223
+ /**
224
+ * For clustered sources, fetches the zoom at which the given cluster expands.
225
+ *
226
+ * @param clusterId The value of the cluster's `cluster_id` property.
227
+ * @param callback A callback to be called when the zoom value is retrieved (`(error, zoom) => { ... }`).
228
+ * @returns {GeoJSONSource} this
229
+ */
230
+ getClusterExpansionZoom(clusterId: number, callback: Callback<number>) {
231
+ this.actor.send('geojson.getClusterExpansionZoom', {clusterId, source: this.id}, callback);
232
+ return this;
233
+ }
234
+
235
+ /**
236
+ * For clustered sources, fetches the children of the given cluster on the next zoom level (as an array of GeoJSON features).
237
+ *
238
+ * @param clusterId The value of the cluster's `cluster_id` property.
239
+ * @param callback A callback to be called when the features are retrieved (`(error, features) => { ... }`).
240
+ * @returns {GeoJSONSource} this
241
+ */
242
+ getClusterChildren(clusterId: number, callback: Callback<Array<GeoJSONFeature>>) {
243
+ this.actor.send('geojson.getClusterChildren', {clusterId, source: this.id}, callback);
244
+ return this;
245
+ }
246
+
247
+ /**
248
+ * For clustered sources, fetches the original points that belong to the cluster (as an array of GeoJSON features).
249
+ *
250
+ * @param clusterId The value of the cluster's `cluster_id` property.
251
+ * @param limit The maximum number of features to return.
252
+ * @param offset The number of features to skip (e.g. for pagination).
253
+ * @param callback A callback to be called when the features are retrieved (`(error, features) => { ... }`).
254
+ * @returns {GeoJSONSource} this
255
+ */
256
+ getClusterLeaves(clusterId: number, limit: number, offset: number, callback: Callback<Array<GeoJSONFeature>>) {
257
+ this.actor.send('geojson.getClusterLeaves', {
258
+ source: this.id,
259
+ clusterId,
260
+ limit,
261
+ offset
262
+ }, callback);
263
+ return this;
264
+ }
265
+
266
+ /*
267
+ * Responsible for invoking WorkerSource's geojson.loadData target, which
268
+ * handles loading the geojson data and preparing to serve it up as tiles,
269
+ * using geojson-vt or supercluster as appropriate.
270
+ */
271
+ _updateWorkerData(callback: Callback<void>) {
272
+ this._loaded = false;
273
+ const options = extend({}, this.workerOptions);
274
+ let data = this._data;
275
+
276
+ if (typeof data === 'string') {
277
+ options.request = this.map._requestManager.transformRequest(browser.resolveURL(data), ResourceType.Source);
278
+ options.request.collectResourceTiming = this._collectResourceTiming;
279
+ } else {
280
+ options.data = JSON.stringify(data);
281
+ }
282
+ // target {this.type}.loadData rather than literally geojson.loadData,
283
+ // so that other geojson-like source types can easily reuse this
284
+ // implementation
285
+ this.actor.send(`${this.type}.loadData`, options, (err, result) => {
286
+ if (this._removed || (result && result.abandoned)) {
287
+ return;
288
+ }
289
+
290
+ this._loaded = true;
291
+
292
+ if (result && result.resourceTiming && result.resourceTiming[this.id])
293
+ this._resourceTiming = result.resourceTiming[this.id].slice(0);
294
+ // Any `loadData` calls that piled up while we were processing
295
+ // this one will get coalesced into a single call when this
296
+ // 'coalesce' message is processed.
297
+ // We would self-send from the worker if we had access to its
298
+ // message queue. Waiting instead for the 'coalesce' to round-trip
299
+ // through the foreground just means we're throttling the worker
300
+ // to run at a little less than full-throttle.
301
+ this.actor.send(`${this.type}.coalesce`, {source: options.source}, null);
302
+ callback(err);
303
+ });
304
+ }
305
+
306
+ loaded(): boolean {
307
+ return this._loaded;
308
+ }
309
+
310
+ loadTile(tile: Tile, callback: Callback<void>) {
311
+ const message = !tile.actor ? 'loadTile' : 'reloadTile';
312
+ tile.actor = this.actor;
313
+ const params = {
314
+ type: this.type,
315
+ uid: tile.uid,
316
+ tileID: tile.tileID,
317
+ zoom: tile.tileID.overscaledZ,
318
+ maxZoom: this.maxzoom,
319
+ tileSize: this.tileSize,
320
+ source: this.id,
321
+ pixelRatio: browser.devicePixelRatio,
322
+ showCollisionBoxes: this.map.showCollisionBoxes,
323
+ promoteId: this.promoteId
324
+ };
325
+
326
+ tile.request = this.actor.send(message, params, (err, data) => {
327
+ delete tile.request;
328
+ tile.unloadVectorData();
329
+
330
+ if (tile.aborted) {
331
+ return callback(null);
332
+ }
333
+
334
+ if (err) {
335
+ return callback(err);
336
+ }
337
+
338
+ tile.loadVectorData(data, this.map.painter, message === 'reloadTile');
339
+
340
+ return callback(null);
341
+ });
342
+ }
343
+
344
+ abortTile(tile: Tile) {
345
+ if (tile.request) {
346
+ tile.request.cancel();
347
+ delete tile.request;
348
+ }
349
+ tile.aborted = true;
350
+ }
351
+
352
+ unloadTile(tile: Tile) {
353
+ tile.unloadVectorData();
354
+ this.actor.send('removeTile', {uid: tile.uid, type: this.type, source: this.id});
355
+ }
356
+
357
+ onRemove() {
358
+ this._removed = true;
359
+ this.actor.send('removeSource', {type: this.type, source: this.id});
360
+ }
361
+
362
+ serialize() {
363
+ return extend({}, this._options, {
364
+ type: this.type,
365
+ data: this._data
366
+ });
367
+ }
368
+
369
+ hasTransition() {
370
+ return false;
371
+ }
372
+ }
373
+
374
+ export default GeoJSONSource;