@mapgis/mapbox-gl 1.9.10 → 16.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (442) hide show
  1. package/.flowconfig +61 -0
  2. package/LICENSE.txt +84 -0
  3. package/README.md +30 -13
  4. package/build/banner.js +4 -0
  5. package/build/check-bundle-size.js +140 -0
  6. package/build/generate-access-token-script.js +11 -0
  7. package/build/generate-flow-typed-style-spec.js +188 -0
  8. package/build/generate-release-list.js +21 -0
  9. package/build/generate-struct-arrays.js +237 -0
  10. package/build/generate-style-code.js +159 -0
  11. package/build/mapbox-gl.js.flow +3 -0
  12. package/build/print-release-url.js +6 -0
  13. package/build/rollup_plugin_minify_style_spec.js +20 -0
  14. package/build/rollup_plugins.js +80 -0
  15. package/build/run-node +3 -0
  16. package/build/run-tap +8 -0
  17. package/build/test/build-tape.js +19 -0
  18. package/dist/mapbox-gl-csp-worker.js +2 -0
  19. package/dist/mapbox-gl-csp-worker.js.map +1 -0
  20. package/dist/mapbox-gl-csp.js +2 -0
  21. package/dist/mapbox-gl-csp.js.map +1 -0
  22. package/dist/mapbox-gl-dev.js +68798 -0
  23. package/dist/mapbox-gl-unminified.js +45076 -0
  24. package/dist/mapbox-gl-unminified.js.map +1 -0
  25. package/dist/mapbox-gl.js +4 -4
  26. package/dist/mapbox-gl.js.map +1 -0
  27. package/flow-typed/gl.js +5 -0
  28. package/flow-typed/jsdom.js +18 -0
  29. package/flow-typed/mapbox-gl-supported.js +9 -0
  30. package/flow-typed/mapbox-unitbezier.js +14 -0
  31. package/flow-typed/offscreen-canvas.js +9 -0
  32. package/flow-typed/pbf.js +25 -0
  33. package/flow-typed/point-geometry.js +44 -0
  34. package/flow-typed/potpack.js +12 -0
  35. package/flow-typed/sinon.js +28 -0
  36. package/flow-typed/vector-tile.js +41 -0
  37. package/package.json +171 -19
  38. package/src/css/mapbox-gl.css +798 -0
  39. package/src/css/svg/mapboxgl-ctrl-attrib.svg +3 -0
  40. package/src/css/svg/mapboxgl-ctrl-compass.svg +4 -0
  41. package/src/css/svg/mapboxgl-ctrl-fullscreen.svg +3 -0
  42. package/src/css/svg/mapboxgl-ctrl-geolocate.svg +5 -0
  43. package/src/css/svg/mapboxgl-ctrl-logo.svg +20 -0
  44. package/src/css/svg/mapboxgl-ctrl-shrink.svg +3 -0
  45. package/src/css/svg/mapboxgl-ctrl-zoom-in.svg +3 -0
  46. package/src/css/svg/mapboxgl-ctrl-zoom-out.svg +3 -0
  47. package/src/data/array_types.js +1095 -0
  48. package/src/data/bucket/circle_attributes.js +9 -0
  49. package/src/data/bucket/circle_bucket.js +204 -0
  50. package/src/data/bucket/fill_attributes.js +9 -0
  51. package/src/data/bucket/fill_bucket.js +233 -0
  52. package/src/data/bucket/fill_extrusion_attributes.js +10 -0
  53. package/src/data/bucket/fill_extrusion_bucket.js +289 -0
  54. package/src/data/bucket/heatmap_bucket.js +17 -0
  55. package/src/data/bucket/line_attributes.js +10 -0
  56. package/src/data/bucket/line_bucket.js +556 -0
  57. package/src/data/bucket/pattern_attributes.js +10 -0
  58. package/src/data/bucket/pattern_bucket_features.js +60 -0
  59. package/src/data/bucket/symbol_attributes.js +117 -0
  60. package/src/data/bucket/symbol_bucket.js +972 -0
  61. package/src/data/bucket.js +123 -0
  62. package/src/data/dem_data.js +125 -0
  63. package/src/data/extent.js +18 -0
  64. package/src/data/feature_index.js +321 -0
  65. package/src/data/feature_position_map.js +125 -0
  66. package/src/data/index_array_type.js +16 -0
  67. package/src/data/load_geometry.js +48 -0
  68. package/src/data/pos_attributes.js +6 -0
  69. package/src/data/program_configuration.js +687 -0
  70. package/src/data/raster_bounds_attributes.js +7 -0
  71. package/src/data/segment.js +76 -0
  72. package/src/geo/edge_insets.js +102 -0
  73. package/src/geo/lng_lat.js +165 -0
  74. package/src/geo/lng_lat_bounds.js +267 -0
  75. package/src/geo/mercator_coordinate.js +153 -0
  76. package/src/geo/transform.js +864 -0
  77. package/src/gl/color_mode.js +34 -0
  78. package/src/gl/context.js +298 -0
  79. package/src/gl/cull_face_mode.js +26 -0
  80. package/src/gl/depth_mode.js +29 -0
  81. package/src/gl/framebuffer.js +44 -0
  82. package/src/gl/index_buffer.js +55 -0
  83. package/src/gl/stencil_mode.js +30 -0
  84. package/src/gl/types.js +84 -0
  85. package/src/gl/value.js +520 -0
  86. package/src/gl/vertex_buffer.js +119 -0
  87. package/src/index.js +201 -0
  88. package/src/render/draw_background.js +57 -0
  89. package/src/render/draw_circle.js +113 -0
  90. package/src/render/draw_collision_debug.js +49 -0
  91. package/src/render/draw_custom.js +49 -0
  92. package/src/render/draw_debug.js +127 -0
  93. package/src/render/draw_fill.js +126 -0
  94. package/src/render/draw_fill_extrusion.js +96 -0
  95. package/src/render/draw_heatmap.js +140 -0
  96. package/src/render/draw_hillshade.js +108 -0
  97. package/src/render/draw_line.js +98 -0
  98. package/src/render/draw_raster.js +125 -0
  99. package/src/render/draw_symbol.js +394 -0
  100. package/src/render/glyph_atlas.js +71 -0
  101. package/src/render/glyph_manager.js +182 -0
  102. package/src/render/image_atlas.js +149 -0
  103. package/src/render/image_manager.js +306 -0
  104. package/src/render/line_atlas.js +210 -0
  105. package/src/render/painter.js +653 -0
  106. package/src/render/program/background_program.js +103 -0
  107. package/src/render/program/circle_program.js +69 -0
  108. package/src/render/program/clipping_mask_program.js +20 -0
  109. package/src/render/program/collision_program.js +49 -0
  110. package/src/render/program/debug_program.js +35 -0
  111. package/src/render/program/fill_extrusion_program.js +122 -0
  112. package/src/render/program/fill_program.js +126 -0
  113. package/src/render/program/heatmap_program.js +83 -0
  114. package/src/render/program/hillshade_program.js +122 -0
  115. package/src/render/program/line_program.js +207 -0
  116. package/src/render/program/pattern.js +102 -0
  117. package/src/render/program/program_uniforms.js +42 -0
  118. package/src/render/program/raster_program.js +92 -0
  119. package/src/render/program/symbol_program.js +224 -0
  120. package/src/render/program.js +168 -0
  121. package/src/render/texture.js +122 -0
  122. package/src/render/uniform_binding.js +147 -0
  123. package/src/render/vertex_array_object.js +163 -0
  124. package/src/shaders/README.md +42 -0
  125. package/src/shaders/_prelude.fragment.glsl +17 -0
  126. package/src/shaders/_prelude.vertex.glsl +73 -0
  127. package/src/shaders/background.fragment.glsl +10 -0
  128. package/src/shaders/background.vertex.glsl +7 -0
  129. package/src/shaders/background_pattern.fragment.glsl +28 -0
  130. package/src/shaders/background_pattern.vertex.glsl +20 -0
  131. package/src/shaders/circle.fragment.glsl +39 -0
  132. package/src/shaders/circle.vertex.glsl +64 -0
  133. package/src/shaders/clipping_mask.fragment.glsl +3 -0
  134. package/src/shaders/clipping_mask.vertex.glsl +7 -0
  135. package/src/shaders/collision_box.fragment.glsl +21 -0
  136. package/src/shaders/collision_box.vertex.glsl +27 -0
  137. package/src/shaders/collision_circle.fragment.glsl +34 -0
  138. package/src/shaders/collision_circle.vertex.glsl +36 -0
  139. package/src/shaders/debug.fragment.glsl +9 -0
  140. package/src/shaders/debug.vertex.glsl +12 -0
  141. package/src/shaders/encode_attribute.js +17 -0
  142. package/src/shaders/fill.fragment.glsl +13 -0
  143. package/src/shaders/fill.vertex.glsl +13 -0
  144. package/src/shaders/fill_extrusion.fragment.glsl +9 -0
  145. package/src/shaders/fill_extrusion.vertex.glsl +66 -0
  146. package/src/shaders/fill_extrusion_pattern.fragment.glsl +45 -0
  147. package/src/shaders/fill_extrusion_pattern.vertex.glsl +79 -0
  148. package/src/shaders/fill_outline.fragment.glsl +17 -0
  149. package/src/shaders/fill_outline.vertex.glsl +17 -0
  150. package/src/shaders/fill_outline_pattern.fragment.glsl +43 -0
  151. package/src/shaders/fill_outline_pattern.vertex.glsl +44 -0
  152. package/src/shaders/fill_pattern.fragment.glsl +36 -0
  153. package/src/shaders/fill_pattern.vertex.glsl +39 -0
  154. package/src/shaders/heatmap.fragment.glsl +22 -0
  155. package/src/shaders/heatmap.vertex.glsl +54 -0
  156. package/src/shaders/heatmap_texture.fragment.glsl +14 -0
  157. package/src/shaders/heatmap_texture.vertex.glsl +11 -0
  158. package/src/shaders/hillshade.fragment.glsl +52 -0
  159. package/src/shaders/hillshade.vertex.glsl +11 -0
  160. package/src/shaders/hillshade_prepare.fragment.glsl +74 -0
  161. package/src/shaders/hillshade_prepare.vertex.glsl +15 -0
  162. package/src/shaders/index.js +20 -0
  163. package/src/shaders/line.fragment.glsl +30 -0
  164. package/src/shaders/line.vertex.glsl +85 -0
  165. package/src/shaders/line_gradient.fragment.glsl +34 -0
  166. package/src/shaders/line_gradient.vertex.glsl +87 -0
  167. package/src/shaders/line_pattern.fragment.glsl +74 -0
  168. package/src/shaders/line_pattern.vertex.glsl +99 -0
  169. package/src/shaders/line_sdf.fragment.glsl +45 -0
  170. package/src/shaders/line_sdf.vertex.glsl +98 -0
  171. package/src/shaders/raster.fragment.glsl +52 -0
  172. package/src/shaders/raster.vertex.glsl +21 -0
  173. package/src/shaders/shaders.js +180 -0
  174. package/src/shaders/symbol_icon.fragment.glsl +17 -0
  175. package/src/shaders/symbol_icon.vertex.glsl +94 -0
  176. package/src/shaders/symbol_sdf.fragment.glsl +52 -0
  177. package/src/shaders/symbol_sdf.vertex.glsl +115 -0
  178. package/src/shaders/symbol_text_and_icon.fragment.glsl +68 -0
  179. package/src/shaders/symbol_text_and_icon.vertex.glsl +116 -0
  180. package/src/source/canvas_source.js +238 -0
  181. package/src/source/geojson_helper.js +92 -0
  182. package/src/source/geojson_source.js +374 -0
  183. package/src/source/geojson_worker_source.js +357 -0
  184. package/src/source/geojson_wrapper.js +94 -0
  185. package/src/source/image_source.js +307 -0
  186. package/src/source/load_tilejson.js +39 -0
  187. package/src/source/mbtiles_source.js +115 -0
  188. package/src/source/offline_database.js +61 -0
  189. package/src/source/offline_database_root.js +62 -0
  190. package/src/source/pixels_to_tile_units.js +21 -0
  191. package/src/source/query_features.js +208 -0
  192. package/src/source/raster_dem_tile_source.js +138 -0
  193. package/src/source/raster_dem_tile_worker_source.js +62 -0
  194. package/src/source/raster_tile_offline_source.js +136 -0
  195. package/src/source/raster_tile_source.js +177 -0
  196. package/src/source/rtl_text_plugin.js +138 -0
  197. package/src/source/source.js +137 -0
  198. package/src/source/source_cache.js +957 -0
  199. package/src/source/source_state.js +159 -0
  200. package/src/source/tile.js +465 -0
  201. package/src/source/tile_bounds.js +38 -0
  202. package/src/source/tile_cache.js +212 -0
  203. package/src/source/tile_id.js +402 -0
  204. package/src/source/vector_tile_source.js +192 -0
  205. package/src/source/vector_tile_worker_source.js +216 -0
  206. package/src/source/video_source.js +203 -0
  207. package/src/source/worker.js +237 -0
  208. package/src/source/worker_source.js +106 -0
  209. package/src/source/worker_tile.js +224 -0
  210. package/src/style/create_style_layer.js +36 -0
  211. package/src/style/evaluation_parameters.js +62 -0
  212. package/src/style/light.js +130 -0
  213. package/src/style/load_glyph_range.js +38 -0
  214. package/src/style/load_sprite.js +67 -0
  215. package/src/style/parse_glyph_pbf.js +44 -0
  216. package/src/style/pauseable_placement.js +132 -0
  217. package/src/style/properties.js +753 -0
  218. package/src/style/query_utils.js +43 -0
  219. package/src/style/style.js +1361 -0
  220. package/src/style/style_glyph.js +17 -0
  221. package/src/style/style_image.js +137 -0
  222. package/src/style/style_layer/background_style_layer.js +21 -0
  223. package/src/style/style_layer/background_style_layer_properties.js +40 -0
  224. package/src/style/style_layer/circle_style_layer.js +98 -0
  225. package/src/style/style_layer/circle_style_layer_properties.js +63 -0
  226. package/src/style/style_layer/custom_style_layer.js +223 -0
  227. package/src/style/style_layer/fill_extrusion_style_layer.js +224 -0
  228. package/src/style/style_layer/fill_extrusion_style_layer_properties.js +50 -0
  229. package/src/style/style_layer/fill_style_layer.js +67 -0
  230. package/src/style/style_layer/fill_style_layer_properties.js +55 -0
  231. package/src/style/style_layer/heatmap_style_layer.js +69 -0
  232. package/src/style/style_layer/heatmap_style_layer_properties.js +44 -0
  233. package/src/style/style_layer/hillshade_style_layer.js +25 -0
  234. package/src/style/style_layer/hillshade_style_layer_properties.js +46 -0
  235. package/src/style/style_layer/layer_properties.js.ejs +69 -0
  236. package/src/style/style_layer/line_style_layer.js +151 -0
  237. package/src/style/style_layer/line_style_layer_properties.js +71 -0
  238. package/src/style/style_layer/raster_style_layer.js +21 -0
  239. package/src/style/style_layer/raster_style_layer_properties.js +50 -0
  240. package/src/style/style_layer/symbol_style_layer.js +190 -0
  241. package/src/style/style_layer/symbol_style_layer_properties.js +153 -0
  242. package/src/style/style_layer/typed_style_layer.js +17 -0
  243. package/src/style/style_layer.js +281 -0
  244. package/src/style/style_layer_index.js +80 -0
  245. package/src/style/validate_style.js +42 -0
  246. package/src/style/zoom_history.js +44 -0
  247. package/src/style-spec/.eslintrc +5 -0
  248. package/src/style-spec/CHANGELOG.md +438 -0
  249. package/src/style-spec/README.md +59 -0
  250. package/src/style-spec/bin/gl-style-composite +9 -0
  251. package/src/style-spec/bin/gl-style-format +22 -0
  252. package/src/style-spec/bin/gl-style-migrate +9 -0
  253. package/src/style-spec/bin/gl-style-validate +50 -0
  254. package/src/style-spec/composite.js +50 -0
  255. package/src/style-spec/declass.js +42 -0
  256. package/src/style-spec/deref.js +52 -0
  257. package/src/style-spec/diff.js +393 -0
  258. package/src/style-spec/dist/.gitkeep +0 -0
  259. package/src/style-spec/empty.js +29 -0
  260. package/src/style-spec/error/parsing_error.js +16 -0
  261. package/src/style-spec/error/validation_error.js +18 -0
  262. package/src/style-spec/expression/compound_expression.js +162 -0
  263. package/src/style-spec/expression/definitions/assertion.js +130 -0
  264. package/src/style-spec/expression/definitions/at.js +70 -0
  265. package/src/style-spec/expression/definitions/case.js +85 -0
  266. package/src/style-spec/expression/definitions/coalesce.js +93 -0
  267. package/src/style-spec/expression/definitions/coercion.js +133 -0
  268. package/src/style-spec/expression/definitions/collator.js +78 -0
  269. package/src/style-spec/expression/definitions/comparison.js +184 -0
  270. package/src/style-spec/expression/definitions/format.js +144 -0
  271. package/src/style-spec/expression/definitions/format_section_override.js +54 -0
  272. package/src/style-spec/expression/definitions/image.js +52 -0
  273. package/src/style-spec/expression/definitions/in.js +92 -0
  274. package/src/style-spec/expression/definitions/index.js +561 -0
  275. package/src/style-spec/expression/definitions/interpolate.js +267 -0
  276. package/src/style-spec/expression/definitions/length.js +61 -0
  277. package/src/style-spec/expression/definitions/let.js +72 -0
  278. package/src/style-spec/expression/definitions/literal.js +77 -0
  279. package/src/style-spec/expression/definitions/match.js +158 -0
  280. package/src/style-spec/expression/definitions/number_format.js +142 -0
  281. package/src/style-spec/expression/definitions/step.js +120 -0
  282. package/src/style-spec/expression/definitions/var.js +46 -0
  283. package/src/style-spec/expression/definitions/within.js +333 -0
  284. package/src/style-spec/expression/evaluation_context.js +59 -0
  285. package/src/style-spec/expression/expression.js +27 -0
  286. package/src/style-spec/expression/index.js +392 -0
  287. package/src/style-spec/expression/is_constant.js +59 -0
  288. package/src/style-spec/expression/parsing_context.js +233 -0
  289. package/src/style-spec/expression/parsing_error.js +13 -0
  290. package/src/style-spec/expression/runtime_error.js +17 -0
  291. package/src/style-spec/expression/scope.js +36 -0
  292. package/src/style-spec/expression/stops.js +39 -0
  293. package/src/style-spec/expression/types/collator.js +61 -0
  294. package/src/style-spec/expression/types/formatted.js +73 -0
  295. package/src/style-spec/expression/types/resolved_image.js +29 -0
  296. package/src/style-spec/expression/types.js +106 -0
  297. package/src/style-spec/expression/values.js +123 -0
  298. package/src/style-spec/feature_filter/README.md +55 -0
  299. package/src/style-spec/feature_filter/convert.js +208 -0
  300. package/src/style-spec/feature_filter/index.js +165 -0
  301. package/src/style-spec/format.js +51 -0
  302. package/src/style-spec/function/convert.js +254 -0
  303. package/src/style-spec/function/index.js +262 -0
  304. package/src/style-spec/group_by_layout.js +75 -0
  305. package/src/style-spec/migrate/expressions.js +39 -0
  306. package/src/style-spec/migrate/v8.js +203 -0
  307. package/src/style-spec/migrate/v9.js +26 -0
  308. package/src/style-spec/migrate.js +36 -0
  309. package/src/style-spec/package.json +41 -0
  310. package/src/style-spec/read_style.js +14 -0
  311. package/src/style-spec/reference/latest.js +3 -0
  312. package/src/style-spec/reference/v8.json +5808 -0
  313. package/src/style-spec/rollup.config.js +45 -0
  314. package/src/style-spec/style-spec.js +122 -0
  315. package/src/style-spec/types.js +438 -0
  316. package/src/style-spec/util/color.js +95 -0
  317. package/src/style-spec/util/color_spaces.js +139 -0
  318. package/src/style-spec/util/deep_equal.js +28 -0
  319. package/src/style-spec/util/extend.js +10 -0
  320. package/src/style-spec/util/get_type.js +17 -0
  321. package/src/style-spec/util/interpolate.js +22 -0
  322. package/src/style-spec/util/properties.js +15 -0
  323. package/src/style-spec/util/ref_properties.js +2 -0
  324. package/src/style-spec/util/result.js +19 -0
  325. package/src/style-spec/util/unbundle_jsonlint.js +24 -0
  326. package/src/style-spec/validate/latest.js +11 -0
  327. package/src/style-spec/validate/validate.js +75 -0
  328. package/src/style-spec/validate/validate_array.js +52 -0
  329. package/src/style-spec/validate/validate_boolean.js +15 -0
  330. package/src/style-spec/validate/validate_color.js +20 -0
  331. package/src/style-spec/validate/validate_constants.js +13 -0
  332. package/src/style-spec/validate/validate_enum.js +21 -0
  333. package/src/style-spec/validate/validate_expression.js +43 -0
  334. package/src/style-spec/validate/validate_filter.js +111 -0
  335. package/src/style-spec/validate/validate_formatted.js +11 -0
  336. package/src/style-spec/validate/validate_function.js +207 -0
  337. package/src/style-spec/validate/validate_glyphs_url.js +21 -0
  338. package/src/style-spec/validate/validate_image.js +11 -0
  339. package/src/style-spec/validate/validate_layer.js +134 -0
  340. package/src/style-spec/validate/validate_layout_property.js +6 -0
  341. package/src/style-spec/validate/validate_light.js +47 -0
  342. package/src/style-spec/validate/validate_number.js +29 -0
  343. package/src/style-spec/validate/validate_object.js +61 -0
  344. package/src/style-spec/validate/validate_paint_property.js +6 -0
  345. package/src/style-spec/validate/validate_property.js +64 -0
  346. package/src/style-spec/validate/validate_source.js +111 -0
  347. package/src/style-spec/validate/validate_string.js +15 -0
  348. package/src/style-spec/validate_mapbox_api_supported.js +171 -0
  349. package/src/style-spec/validate_style.js +39 -0
  350. package/src/style-spec/validate_style.min.js +78 -0
  351. package/src/style-spec/visit.js +77 -0
  352. package/src/symbol/anchor.js +26 -0
  353. package/src/symbol/check_max_angle.js +81 -0
  354. package/src/symbol/clip_line.js +71 -0
  355. package/src/symbol/collision_feature.js +217 -0
  356. package/src/symbol/collision_index.js +372 -0
  357. package/src/symbol/cross_tile_symbol_index.js +301 -0
  358. package/src/symbol/get_anchors.js +167 -0
  359. package/src/symbol/grid_index.js +335 -0
  360. package/src/symbol/mergelines.js +82 -0
  361. package/src/symbol/one_em.js +4 -0
  362. package/src/symbol/opacity_state.js +27 -0
  363. package/src/symbol/placement.js +1062 -0
  364. package/src/symbol/projection.js +450 -0
  365. package/src/symbol/quads.js +334 -0
  366. package/src/symbol/shaping.js +816 -0
  367. package/src/symbol/symbol_layout.js +772 -0
  368. package/src/symbol/symbol_size.js +113 -0
  369. package/src/symbol/transform_text.js +29 -0
  370. package/src/types/callback.js +17 -0
  371. package/src/types/cancelable.js +3 -0
  372. package/src/types/tilejson.js +17 -0
  373. package/src/types/transferable.js +3 -0
  374. package/src/types/window.js +172 -0
  375. package/src/ui/anchor.js +32 -0
  376. package/src/ui/bind_handlers.js +202 -0
  377. package/src/ui/camera.js +1152 -0
  378. package/src/ui/control/attribution_control.js +189 -0
  379. package/src/ui/control/fps_control.js +185 -0
  380. package/src/ui/control/fullscreen_control.js +147 -0
  381. package/src/ui/control/geolocate_control.js +594 -0
  382. package/src/ui/control/logo_control.js +92 -0
  383. package/src/ui/control/navigation_control.js +148 -0
  384. package/src/ui/control/scale_control.js +142 -0
  385. package/src/ui/crs.js +64 -0
  386. package/src/ui/default_locale.js +20 -0
  387. package/src/ui/events.js +806 -0
  388. package/src/ui/handler/box_zoom.js +175 -0
  389. package/src/ui/handler/dblclick_zoom.js +139 -0
  390. package/src/ui/handler/drag_pan.js +416 -0
  391. package/src/ui/handler/drag_rotate.js +378 -0
  392. package/src/ui/handler/keyboard.js +161 -0
  393. package/src/ui/handler/scroll_zoom.js +333 -0
  394. package/src/ui/handler/touch_zoom_rotate.js +293 -0
  395. package/src/ui/hash.js +147 -0
  396. package/src/ui/map.js +2883 -0
  397. package/src/ui/marker.js +607 -0
  398. package/src/ui/offline_map.js +91 -0
  399. package/src/ui/popup.js +530 -0
  400. package/src/util/actor.js +212 -0
  401. package/src/util/ajax.js +371 -0
  402. package/src/util/browser/web_worker.js +10 -0
  403. package/src/util/browser/window.js +5 -0
  404. package/src/util/browser.js +70 -0
  405. package/src/util/classify_rings.js +52 -0
  406. package/src/util/color_ramp.js +28 -0
  407. package/src/util/config.js +30 -0
  408. package/src/util/debug.js +12 -0
  409. package/src/util/dictionary_coder.js +30 -0
  410. package/src/util/dispatcher.js +70 -0
  411. package/src/util/dom.js +144 -0
  412. package/src/util/evented.js +174 -0
  413. package/src/util/find_pole_of_inaccessibility.js +129 -0
  414. package/src/util/global_worker_pool.js +17 -0
  415. package/src/util/image.js +142 -0
  416. package/src/util/intersection_tests.js +208 -0
  417. package/src/util/is_char_in_unicode_block.js +311 -0
  418. package/src/util/mapbox.js +486 -0
  419. package/src/util/offscreen_canvas_supported.js +14 -0
  420. package/src/util/performance.js +112 -0
  421. package/src/util/primitives.js +145 -0
  422. package/src/util/resolve_tokens.js +16 -0
  423. package/src/util/script_detection.js +328 -0
  424. package/src/util/sku_token.js +42 -0
  425. package/src/util/smart_wrap.js +55 -0
  426. package/src/util/struct_array.js +243 -0
  427. package/src/util/struct_array.js.ejs +112 -0
  428. package/src/util/struct_array_layout.js.ejs +98 -0
  429. package/src/util/task_queue.js +68 -0
  430. package/src/util/throttle.js +28 -0
  431. package/src/util/throttled_invoker.js +46 -0
  432. package/src/util/tile_cover.js +101 -0
  433. package/src/util/tile_request_cache.js +172 -0
  434. package/src/util/util.js +504 -0
  435. package/src/util/vectortile_to_geojson.js +54 -0
  436. package/src/util/verticalize_punctuation.js +114 -0
  437. package/src/util/web_worker.js +91 -0
  438. package/src/util/web_worker_transfer.js +266 -0
  439. package/src/util/webp_supported.js +69 -0
  440. package/src/util/window.js +102 -0
  441. package/src/util/worker_pool.js +47 -0
  442. package/postcss.config.js +0 -16
@@ -0,0 +1,1152 @@
1
+ // @flow
2
+
3
+ import {
4
+ bindAll,
5
+ extend,
6
+ warnOnce,
7
+ clamp,
8
+ wrap,
9
+ ease as defaultEasing,
10
+ pick
11
+ } from '../util/util';
12
+ import {number as interpolate} from '../style-spec/util/interpolate';
13
+ import browser from '../util/browser';
14
+ import LngLat from '../geo/lng_lat';
15
+ import LngLatBounds from '../geo/lng_lat_bounds';
16
+ import Point from '@mapbox/point-geometry';
17
+ import {Event, Evented} from '../util/evented';
18
+
19
+ import type Transform from '../geo/transform';
20
+ import type {LngLatLike} from '../geo/lng_lat';
21
+ import type {LngLatBoundsLike} from '../geo/lng_lat_bounds';
22
+ import type {TaskID} from '../util/task_queue';
23
+ import type {PointLike} from '@mapbox/point-geometry';
24
+ import type {PaddingOptions} from '../geo/edge_insets';
25
+
26
+ /**
27
+ * Options common to {@link Map#jumpTo}, {@link Map#easeTo}, and {@link Map#flyTo}, controlling the desired location,
28
+ * zoom, bearing, and pitch of the camera. All properties are optional, and when a property is omitted, the current
29
+ * camera value for that property will remain unchanged.
30
+ *
31
+ * @typedef {Object} CameraOptions
32
+ * @property {LngLatLike} center The desired center.
33
+ * @property {number} zoom The desired zoom level.
34
+ * @property {number} bearing The desired bearing, in degrees. The bearing is the compass direction that
35
+ * is "up"; for example, a bearing of 90° orients the map so that east is up.
36
+ * @property {number} pitch The desired pitch, in degrees.
37
+ * @property {LngLatLike} around If `zoom` is specified, `around` determines the point around which the zoom is centered.
38
+ * @property {PaddingOptions} padding Dimensions in pixels applied on eachs side of the viewport for shifting the vanishing point.
39
+ */
40
+ export type CameraOptions = {
41
+ center?: LngLatLike,
42
+ zoom?: number,
43
+ bearing?: number,
44
+ pitch?: number,
45
+ around?: LngLatLike,
46
+ padding?: PaddingOptions
47
+ };
48
+
49
+ /**
50
+ * Options common to map movement methods that involve animation, such as {@link Map#panBy} and
51
+ * {@link Map#easeTo}, controlling the duration and easing function of the animation. All properties
52
+ * are optional.
53
+ *
54
+ * @typedef {Object} AnimationOptions
55
+ * @property {number} duration The animation's duration, measured in milliseconds.
56
+ * @property {Function} easing A function taking a time in the range 0..1 and returning a number where 0 is
57
+ * the initial state and 1 is the final state.
58
+ * @property {PointLike} offset of the target center relative to real map container center at the end of animation.
59
+ * @property {boolean} animate If `false`, no animation will occur.
60
+ * @property {boolean} essential If `true`, then the animation is considered essential and will not be affected by
61
+ * [`prefers-reduced-motion`](https://developer.mozilla.org/en-US/docs/Web/CSS/@media/prefers-reduced-motion).
62
+ */
63
+ export type AnimationOptions = {
64
+ duration?: number,
65
+ easing?: (_: number) => number,
66
+ offset?: PointLike,
67
+ animate?: boolean,
68
+ essential?: boolean
69
+ };
70
+
71
+ /**
72
+ * Options for setting padding on a call to {@link Map#fitBounds}. All properties of this object must be
73
+ * non-negative integers.
74
+ *
75
+ * @typedef {Object} PaddingOptions
76
+ * @property {number} top Padding in pixels from the top of the map canvas.
77
+ * @property {number} bottom Padding in pixels from the bottom of the map canvas.
78
+ * @property {number} left Padding in pixels from the left of the map canvas.
79
+ * @property {number} right Padding in pixels from the right of the map canvas.
80
+ */
81
+
82
+ class Camera extends Evented {
83
+ transform: Transform;
84
+ _moving: boolean;
85
+ _zooming: boolean;
86
+ _rotating: boolean;
87
+ _pitching: boolean;
88
+ _padding: boolean;
89
+
90
+ _bearingSnap: number;
91
+ _easeEndTimeoutID: TimeoutID;
92
+ _easeStart: number;
93
+ _easeOptions: {duration: number, easing: (_: number) => number};
94
+
95
+ _onEaseFrame: (_: number) => void;
96
+ _onEaseEnd: () => void;
97
+ _easeFrameId: ?TaskID;
98
+
99
+ +_requestRenderFrame: (() => void) => TaskID;
100
+ +_cancelRenderFrame: (_: TaskID) => void;
101
+
102
+ constructor(transform: Transform, options: {bearingSnap: number}) {
103
+ super();
104
+ this._moving = false;
105
+ this._zooming = false;
106
+ this.transform = transform;
107
+ this._bearingSnap = options.bearingSnap;
108
+
109
+ bindAll(['_renderFrameCallback'], this);
110
+ }
111
+
112
+ /**
113
+ * Returns the map's geographical centerpoint.
114
+ *
115
+ * @memberof Map#
116
+ * @returns The map's geographical centerpoint.
117
+ */
118
+ getCenter(): LngLat { return new LngLat(this.transform.center.lng, this.transform.center.lat); }
119
+
120
+ /**
121
+ * Sets the map's geographical centerpoint. Equivalent to `jumpTo({center: center})`.
122
+ *
123
+ * @memberof Map#
124
+ * @param center The centerpoint to set.
125
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
126
+ * @fires movestart
127
+ * @fires moveend
128
+ * @returns {Map} `this`
129
+ * @example
130
+ * map.setCenter([-74, 38]);
131
+ */
132
+ setCenter(center: LngLatLike, eventData?: Object) {
133
+ return this.jumpTo({center}, eventData);
134
+ }
135
+
136
+ /**
137
+ * Pans the map by the specified offset.
138
+ *
139
+ * @memberof Map#
140
+ * @param offset `x` and `y` coordinates by which to pan the map.
141
+ * @param options Options object
142
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
143
+ * @fires movestart
144
+ * @fires moveend
145
+ * @returns {Map} `this`
146
+ * @see [Navigate the map with game-like controls](https://www.mapbox.com/mapbox-gl-js/example/game-controls/)
147
+ */
148
+ panBy(offset: PointLike, options?: AnimationOptions, eventData?: Object) {
149
+ offset = Point.convert(offset).mult(-1);
150
+ return this.panTo(this.transform.center, extend({offset}, options), eventData);
151
+ }
152
+
153
+ /**
154
+ * Pans the map to the specified location, with an animated transition.
155
+ *
156
+ * @memberof Map#
157
+ * @param lnglat The location to pan the map to.
158
+ * @param options Options object
159
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
160
+ * @fires movestart
161
+ * @fires moveend
162
+ * @returns {Map} `this`
163
+ */
164
+ panTo(lnglat: LngLatLike, options?: AnimationOptions, eventData?: Object) {
165
+ return this.easeTo(extend({
166
+ center: lnglat
167
+ }, options), eventData);
168
+ }
169
+
170
+ /**
171
+ * Returns the map's current zoom level.
172
+ *
173
+ * @memberof Map#
174
+ * @returns The map's current zoom level.
175
+ */
176
+ getZoom(): number { return this.transform.zoom; }
177
+
178
+ /**
179
+ * Sets the map's zoom level. Equivalent to `jumpTo({zoom: zoom})`.
180
+ *
181
+ * @memberof Map#
182
+ * @param zoom The zoom level to set (0-20).
183
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
184
+ * @fires movestart
185
+ * @fires zoomstart
186
+ * @fires move
187
+ * @fires zoom
188
+ * @fires moveend
189
+ * @fires zoomend
190
+ * @returns {Map} `this`
191
+ * @example
192
+ * // zoom the map to 5
193
+ * map.setZoom(5);
194
+ */
195
+ setZoom(zoom: number, eventData?: Object) {
196
+ this.jumpTo({zoom}, eventData);
197
+ return this;
198
+ }
199
+
200
+ /**
201
+ * Zooms the map to the specified zoom level, with an animated transition.
202
+ *
203
+ * @memberof Map#
204
+ * @param zoom The zoom level to transition to.
205
+ * @param options Options object
206
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
207
+ * @fires movestart
208
+ * @fires zoomstart
209
+ * @fires move
210
+ * @fires zoom
211
+ * @fires moveend
212
+ * @fires zoomend
213
+ * @returns {Map} `this`
214
+ */
215
+ zoomTo(zoom: number, options: ? AnimationOptions, eventData?: Object) {
216
+ return this.easeTo(extend({
217
+ zoom
218
+ }, options), eventData);
219
+ }
220
+
221
+ /**
222
+ * Increases the map's zoom level by 1.
223
+ *
224
+ * @memberof Map#
225
+ * @param options Options object
226
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
227
+ * @fires movestart
228
+ * @fires zoomstart
229
+ * @fires move
230
+ * @fires zoom
231
+ * @fires moveend
232
+ * @fires zoomend
233
+ * @returns {Map} `this`
234
+ */
235
+ zoomIn(options?: AnimationOptions, eventData?: Object) {
236
+ this.zoomTo(this.getZoom() + 1, options, eventData);
237
+ return this;
238
+ }
239
+
240
+ /**
241
+ * Decreases the map's zoom level by 1.
242
+ *
243
+ * @memberof Map#
244
+ * @param options Options object
245
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
246
+ * @fires movestart
247
+ * @fires zoomstart
248
+ * @fires move
249
+ * @fires zoom
250
+ * @fires moveend
251
+ * @fires zoomend
252
+ * @returns {Map} `this`
253
+ */
254
+ zoomOut(options?: AnimationOptions, eventData?: Object) {
255
+ this.zoomTo(this.getZoom() - 1, options, eventData);
256
+ return this;
257
+ }
258
+
259
+ /**
260
+ * Returns the map's current bearing. The bearing is the compass direction that is \"up\"; for example, a bearing
261
+ * of 90° orients the map so that east is up.
262
+ *
263
+ * @memberof Map#
264
+ * @returns The map's current bearing.
265
+ * @see [Navigate the map with game-like controls](https://www.mapbox.com/mapbox-gl-js/example/game-controls/)
266
+ */
267
+ getBearing(): number { return this.transform.bearing; }
268
+
269
+ /**
270
+ * Sets the map's bearing (rotation). The bearing is the compass direction that is \"up\"; for example, a bearing
271
+ * of 90° orients the map so that east is up.
272
+ *
273
+ * Equivalent to `jumpTo({bearing: bearing})`.
274
+ *
275
+ * @memberof Map#
276
+ * @param bearing The desired bearing.
277
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
278
+ * @fires movestart
279
+ * @fires moveend
280
+ * @returns {Map} `this`
281
+ * @example
282
+ * // rotate the map to 90 degrees
283
+ * map.setBearing(90);
284
+ */
285
+ setBearing(bearing: number, eventData?: Object) {
286
+ this.jumpTo({bearing}, eventData);
287
+ return this;
288
+ }
289
+
290
+ /**
291
+ * Returns the current padding applied around the map viewport.
292
+ *
293
+ * @memberof Map#
294
+ * @returns The current padding around the map viewport.
295
+ */
296
+ getPadding(): PaddingOptions { return this.transform.padding; }
297
+
298
+ /**
299
+ * Sets the padding in pixels around the viewport.
300
+ *
301
+ * Equivalent to `jumpTo({padding: padding})`.
302
+ *
303
+ * @memberof Map#
304
+ * @param padding The desired padding. Format: { left: number, right: number, top: number, bottom: number }
305
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
306
+ * @fires movestart
307
+ * @fires moveend
308
+ * @returns {Map} `this`
309
+ * @example
310
+ * // Sets a left padding of 300px, and a top padding of 50px
311
+ * map.setPadding({ left: 300, top: 50 });
312
+ */
313
+ setPadding(padding: PaddingOptions, eventData?: Object) {
314
+ this.jumpTo({padding}, eventData);
315
+ return this;
316
+ }
317
+
318
+ /**
319
+ * Rotates the map to the specified bearing, with an animated transition. The bearing is the compass direction
320
+ * that is \"up\"; for example, a bearing of 90° orients the map so that east is up.
321
+ *
322
+ * @memberof Map#
323
+ * @param bearing The desired bearing.
324
+ * @param options Options object
325
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
326
+ * @fires movestart
327
+ * @fires moveend
328
+ * @returns {Map} `this`
329
+ */
330
+ rotateTo(bearing: number, options?: AnimationOptions, eventData?: Object) {
331
+ return this.easeTo(extend({
332
+ bearing
333
+ }, options), eventData);
334
+ }
335
+
336
+ /**
337
+ * Rotates the map so that north is up (0° bearing), with an animated transition.
338
+ *
339
+ * @memberof Map#
340
+ * @param options Options object
341
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
342
+ * @fires movestart
343
+ * @fires moveend
344
+ * @returns {Map} `this`
345
+ */
346
+ resetNorth(options?: AnimationOptions, eventData?: Object) {
347
+ this.rotateTo(0, extend({duration: 1000}, options), eventData);
348
+ return this;
349
+ }
350
+
351
+ /**
352
+ * Rotates and pitches the map so that north is up (0° bearing) and pitch is 0°, with an animated transition.
353
+ *
354
+ * @memberof Map#
355
+ * @param options Options object
356
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
357
+ * @fires movestart
358
+ * @fires moveend
359
+ * @returns {Map} `this`
360
+ */
361
+ resetNorthPitch(options?: AnimationOptions, eventData?: Object) {
362
+ this.easeTo(extend({
363
+ bearing: 0,
364
+ pitch: 0,
365
+ duration: 1000
366
+ }, options), eventData);
367
+ return this;
368
+ }
369
+
370
+ /**
371
+ * Snaps the map so that north is up (0° bearing), if the current bearing is close enough to it (i.e. within the
372
+ * `bearingSnap` threshold).
373
+ *
374
+ * @memberof Map#
375
+ * @param options Options object
376
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
377
+ * @fires movestart
378
+ * @fires moveend
379
+ * @returns {Map} `this`
380
+ */
381
+ snapToNorth(options?: AnimationOptions, eventData?: Object) {
382
+ if (Math.abs(this.getBearing()) < this._bearingSnap) {
383
+ return this.resetNorth(options, eventData);
384
+ }
385
+ return this;
386
+ }
387
+
388
+ /**
389
+ * Returns the map's current pitch (tilt).
390
+ *
391
+ * @memberof Map#
392
+ * @returns The map's current pitch, measured in degrees away from the plane of the screen.
393
+ */
394
+ getPitch(): number { return this.transform.pitch; }
395
+
396
+ /**
397
+ * Sets the map's pitch (tilt). Equivalent to `jumpTo({pitch: pitch})`.
398
+ *
399
+ * @memberof Map#
400
+ * @param pitch The pitch to set, measured in degrees away from the plane of the screen (0-60).
401
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
402
+ * @fires pitchstart
403
+ * @fires movestart
404
+ * @fires moveend
405
+ * @returns {Map} `this`
406
+ */
407
+ setPitch(pitch: number, eventData?: Object) {
408
+ this.jumpTo({pitch}, eventData);
409
+ return this;
410
+ }
411
+
412
+ /**
413
+ * @memberof Map#
414
+ * @param {LngLatBoundsLike} bounds Calculate the center for these bounds in the viewport and use
415
+ * the highest zoom level up to and including `Map#getMaxZoom()` that fits
416
+ * in the viewport. LatLngBounds represent a box that is always axis-aligned with bearing 0.
417
+ * @param options Options object
418
+ * @param {number | PaddingOptions} [options.padding] The amount of padding in pixels to add to the given bounds.
419
+ * @param {PointLike} [options.offset=[0, 0]] The center of the given bounds relative to the map's center, measured in pixels.
420
+ * @param {number} [options.maxZoom] The maximum zoom level to allow when the camera would transition to the specified bounds.
421
+ * @returns {CameraOptions | void} If map is able to fit to provided bounds, returns `CameraOptions` with
422
+ * `center`, `zoom`, and `bearing`. If map is unable to fit, method will warn and return undefined.
423
+ * @example
424
+ * var bbox = [[-79, 43], [-73, 45]];
425
+ * var newCameraTransform = map.cameraForBounds(bbox, {
426
+ * padding: {top: 10, bottom:25, left: 15, right: 5}
427
+ * });
428
+ */
429
+ cameraForBounds(bounds: LngLatBoundsLike, options?: CameraOptions): void | CameraOptions & AnimationOptions {
430
+ bounds = LngLatBounds.convert(bounds);
431
+ return this._cameraForBoxAndBearing(bounds.getNorthWest(), bounds.getSouthEast(), 0, options);
432
+ }
433
+
434
+ /**
435
+ * Calculate the center of these two points in the viewport and use
436
+ * the highest zoom level up to and including `Map#getMaxZoom()` that fits
437
+ * the points in the viewport at the specified bearing.
438
+ * @memberof Map#
439
+ * @param {LngLatLike} p0 First point
440
+ * @param {LngLatLike} p1 Second point
441
+ * @param bearing Desired map bearing at end of animation, in degrees
442
+ * @param options
443
+ * @param {number | PaddingOptions} [options.padding] The amount of padding in pixels to add to the given bounds.
444
+ * @param {PointLike} [options.offset=[0, 0]] The center of the given bounds relative to the map's center, measured in pixels.
445
+ * @param {number} [options.maxZoom] The maximum zoom level to allow when the camera would transition to the specified bounds.
446
+ * @returns {CameraOptions | void} If map is able to fit to provided bounds, returns `CameraOptions` with
447
+ * `center`, `zoom`, and `bearing`. If map is unable to fit, method will warn and return undefined.
448
+ * @private
449
+ * @example
450
+ * var p0 = [-79, 43];
451
+ * var p1 = [-73, 45];
452
+ * var bearing = 90;
453
+ * var newCameraTransform = map._cameraForBoxAndBearing(p0, p1, bearing, {
454
+ * padding: {top: 10, bottom:25, left: 15, right: 5}
455
+ * });
456
+ */
457
+ _cameraForBoxAndBearing(p0: LngLatLike, p1: LngLatLike, bearing: number, options?: CameraOptions): void | CameraOptions & AnimationOptions {
458
+ const defaultPadding = {
459
+ top: 0,
460
+ bottom: 0,
461
+ right: 0,
462
+ left: 0
463
+ };
464
+ options = extend({
465
+ padding: defaultPadding,
466
+ offset: [0, 0],
467
+ maxZoom: this.transform.maxZoom
468
+ }, options);
469
+
470
+ if (typeof options.padding === 'number') {
471
+ const p = options.padding;
472
+ options.padding = {
473
+ top: p,
474
+ bottom: p,
475
+ right: p,
476
+ left: p
477
+ };
478
+ }
479
+
480
+ options.padding = extend(defaultPadding, options.padding);
481
+ const tr = this.transform;
482
+ const edgePadding = tr.padding;
483
+
484
+ // We want to calculate the upper right and lower left of the box defined by p0 and p1
485
+ // in a coordinate system rotate to match the destination bearing.
486
+ const p0world = tr.project(LngLat.convert(p0));
487
+ const p1world = tr.project(LngLat.convert(p1));
488
+ const p0rotated = p0world.rotate(-bearing * Math.PI / 180);
489
+ const p1rotated = p1world.rotate(-bearing * Math.PI / 180);
490
+
491
+ const upperRight = new Point(Math.max(p0rotated.x, p1rotated.x), Math.max(p0rotated.y, p1rotated.y));
492
+ const lowerLeft = new Point(Math.min(p0rotated.x, p1rotated.x), Math.min(p0rotated.y, p1rotated.y));
493
+
494
+ // Calculate zoom: consider the original bbox and padding.
495
+ const size = upperRight.sub(lowerLeft);
496
+ const scaleX = (tr.width - (edgePadding.left + edgePadding.right + options.padding.left + options.padding.right)) / size.x;
497
+ const scaleY = (tr.height - (edgePadding.top + edgePadding.bottom + options.padding.top + options.padding.bottom)) / size.y;
498
+
499
+ if (scaleY < 0 || scaleX < 0) {
500
+ warnOnce(
501
+ 'Map cannot fit within canvas with the given bounds, padding, and/or offset.'
502
+ );
503
+ return;
504
+ }
505
+
506
+ const zoom = Math.min(tr.scaleZoom(tr.scale * Math.min(scaleX, scaleY)), options.maxZoom);
507
+
508
+ // Calculate center: apply the zoom, the configured offset, as well as offset that exists as a result of padding.
509
+ const offset = Point.convert(options.offset);
510
+ const paddingOffsetX = (options.padding.left - options.padding.right) / 2;
511
+ const paddingOffsetY = (options.padding.top - options.padding.bottom) / 2;
512
+ const offsetAtInitialZoom = new Point(offset.x + paddingOffsetX, offset.y + paddingOffsetY);
513
+ const offsetAtFinalZoom = offsetAtInitialZoom.mult(tr.scale / tr.zoomScale(zoom));
514
+
515
+ const center = tr.unproject(p0world.add(p1world).div(2).sub(offsetAtFinalZoom));
516
+
517
+ return {
518
+ center,
519
+ zoom,
520
+ bearing
521
+ };
522
+ }
523
+
524
+ /**
525
+ * Pans and zooms the map to contain its visible area within the specified geographical bounds.
526
+ * This function will also reset the map's bearing to 0 if bearing is nonzero.
527
+ *
528
+ * @memberof Map#
529
+ * @param bounds Center these bounds in the viewport and use the highest
530
+ * zoom level up to and including `Map#getMaxZoom()` that fits them in the viewport.
531
+ * @param {Object} [options] Options supports all properties from {@link AnimationOptions} and {@link CameraOptions} in addition to the fields below.
532
+ * @param {number | PaddingOptions} [options.padding] The amount of padding in pixels to add to the given bounds.
533
+ * @param {boolean} [options.linear=false] If `true`, the map transitions using
534
+ * {@link Map#easeTo}. If `false`, the map transitions using {@link Map#flyTo}. See
535
+ * those functions and {@link AnimationOptions} for information about options available.
536
+ * @param {Function} [options.easing] An easing function for the animated transition. See {@link AnimationOptions}.
537
+ * @param {PointLike} [options.offset=[0, 0]] The center of the given bounds relative to the map's center, measured in pixels.
538
+ * @param {number} [options.maxZoom] The maximum zoom level to allow when the map view transitions to the specified bounds.
539
+ * @param {Object} [eventData] Additional properties to be added to event objects of events triggered by this method.
540
+ * @fires movestart
541
+ * @fires moveend
542
+ * @returns {Map} `this`
543
+ * @example
544
+ * var bbox = [[-79, 43], [-73, 45]];
545
+ * map.fitBounds(bbox, {
546
+ * padding: {top: 10, bottom:25, left: 15, right: 5}
547
+ * });
548
+ * @see [Fit a map to a bounding box](https://www.mapbox.com/mapbox-gl-js/example/fitbounds/)
549
+ */
550
+ fitBounds(bounds: LngLatBoundsLike, options?: AnimationOptions & CameraOptions, eventData?: Object) {
551
+ return this._fitInternal(
552
+ this.cameraForBounds(bounds, options),
553
+ options,
554
+ eventData);
555
+ }
556
+
557
+ /**
558
+ * Pans, rotates and zooms the map to to fit the box made by points p0 and p1
559
+ * once the map is rotated to the specified bearing. To zoom without rotating,
560
+ * pass in the current map bearing.
561
+ *
562
+ * @memberof Map#
563
+ * @param p0 First point on screen, in pixel coordinates
564
+ * @param p1 Second point on screen, in pixel coordinates
565
+ * @param bearing Desired map bearing at end of animation, in degrees
566
+ * @param options Options object
567
+ * @param {number | PaddingOptions} [options.padding] The amount of padding in pixels to add to the given bounds.
568
+ * @param {boolean} [options.linear=false] If `true`, the map transitions using
569
+ * {@link Map#easeTo}. If `false`, the map transitions using {@link Map#flyTo}. See
570
+ * those functions and {@link AnimationOptions} for information about options available.
571
+ * @param {Function} [options.easing] An easing function for the animated transition. See {@link AnimationOptions}.
572
+ * @param {PointLike} [options.offset=[0, 0]] The center of the given bounds relative to the map's center, measured in pixels.
573
+ * @param {number} [options.maxZoom] The maximum zoom level to allow when the map view transitions to the specified bounds.
574
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
575
+ * @fires movestart
576
+ * @fires moveend
577
+ * @returns {Map} `this`
578
+ * @example
579
+ * var p0 = [220, 400];
580
+ * var p1 = [500, 900];
581
+ * map.fitScreenCoordinates(p0, p1, map.getBearing(), {
582
+ * padding: {top: 10, bottom:25, left: 15, right: 5}
583
+ * });
584
+ * @see [Used by BoxZoomHandler](https://www.mapbox.com/mapbox-gl-js/api/#boxzoomhandler)
585
+ */
586
+ fitScreenCoordinates(p0: PointLike, p1: PointLike, bearing: number, options?: AnimationOptions & CameraOptions, eventData?: Object) {
587
+ return this._fitInternal(
588
+ this._cameraForBoxAndBearing(
589
+ this.transform.pointLocation(Point.convert(p0)),
590
+ this.transform.pointLocation(Point.convert(p1)),
591
+ bearing,
592
+ options),
593
+ options,
594
+ eventData);
595
+ }
596
+
597
+ _fitInternal(calculatedOptions?: CameraOptions & AnimationOptions, options?: AnimationOptions & CameraOptions, eventData?: Object) {
598
+ // cameraForBounds warns + returns undefined if unable to fit:
599
+ if (!calculatedOptions) return this;
600
+
601
+ options = extend(calculatedOptions, options);
602
+
603
+ return options.linear ?
604
+ this.easeTo(options, eventData) :
605
+ this.flyTo(options, eventData);
606
+ }
607
+
608
+ /**
609
+ * Changes any combination of center, zoom, bearing, and pitch, without
610
+ * an animated transition. The map will retain its current values for any
611
+ * details not specified in `options`.
612
+ *
613
+ * @memberof Map#
614
+ * @param options Options object
615
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
616
+ * @fires movestart
617
+ * @fires zoomstart
618
+ * @fires pitchstart
619
+ * @fires rotate
620
+ * @fires move
621
+ * @fires zoom
622
+ * @fires pitch
623
+ * @fires moveend
624
+ * @fires zoomend
625
+ * @fires pitchend
626
+ * @returns {Map} `this`
627
+ */
628
+ jumpTo(options: CameraOptions, eventData?: Object) {
629
+ this.stop();
630
+
631
+ const tr = this.transform;
632
+ let zoomChanged = false,
633
+ bearingChanged = false,
634
+ pitchChanged = false;
635
+
636
+ if ('zoom' in options && tr.zoom !== +options.zoom) {
637
+ zoomChanged = true;
638
+ tr.zoom = +options.zoom;
639
+ }
640
+
641
+ if (options.center !== undefined) {
642
+ tr.center = LngLat.convert(options.center);
643
+ }
644
+
645
+ if ('bearing' in options && tr.bearing !== +options.bearing) {
646
+ bearingChanged = true;
647
+ tr.bearing = +options.bearing;
648
+ }
649
+
650
+ if ('pitch' in options && tr.pitch !== +options.pitch) {
651
+ pitchChanged = true;
652
+ tr.pitch = +options.pitch;
653
+ }
654
+
655
+ if (options.padding != null && !tr.isPaddingEqual(options.padding)) {
656
+ tr.padding = options.padding;
657
+ }
658
+
659
+ this.fire(new Event('movestart', eventData))
660
+ .fire(new Event('move', eventData));
661
+
662
+ if (zoomChanged) {
663
+ this.fire(new Event('zoomstart', eventData))
664
+ .fire(new Event('zoom', eventData))
665
+ .fire(new Event('zoomend', eventData));
666
+ }
667
+
668
+ if (bearingChanged) {
669
+ this.fire(new Event('rotatestart', eventData))
670
+ .fire(new Event('rotate', eventData))
671
+ .fire(new Event('rotateend', eventData));
672
+ }
673
+
674
+ if (pitchChanged) {
675
+ this.fire(new Event('pitchstart', eventData))
676
+ .fire(new Event('pitch', eventData))
677
+ .fire(new Event('pitchend', eventData));
678
+ }
679
+
680
+ return this.fire(new Event('moveend', eventData));
681
+ }
682
+
683
+ /**
684
+ * Changes any combination of center, zoom, bearing, pitch, and padding with an animated transition
685
+ * between old and new values. The map will retain its current values for any
686
+ * details not specified in `options`.
687
+ *
688
+ * Note: The transition will happen instantly if the user has enabled
689
+ * the `reduced motion` accesibility feature enabled in their operating system,
690
+ * unless 'options' includes `essential: true`.
691
+ *
692
+ * @memberof Map#
693
+ * @param options Options describing the destination and animation of the transition.
694
+ * Accepts {@link CameraOptions} and {@link AnimationOptions}.
695
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
696
+ * @fires movestart
697
+ * @fires zoomstart
698
+ * @fires pitchstart
699
+ * @fires rotate
700
+ * @fires move
701
+ * @fires zoom
702
+ * @fires pitch
703
+ * @fires moveend
704
+ * @fires zoomend
705
+ * @fires pitchend
706
+ * @returns {Map} `this`
707
+ * @see [Navigate the map with game-like controls](https://www.mapbox.com/mapbox-gl-js/example/game-controls/)
708
+ */
709
+ easeTo(options: CameraOptions & AnimationOptions & {delayEndEvents?: number}, eventData?: Object) {
710
+ this.stop();
711
+
712
+ options = extend({
713
+ offset: [0, 0],
714
+ duration: 500,
715
+ easing: defaultEasing
716
+ }, options);
717
+
718
+ if (options.animate === false || (!options.essential && browser.prefersReducedMotion)) options.duration = 0;
719
+
720
+ const tr = this.transform,
721
+ startZoom = this.getZoom(),
722
+ startBearing = this.getBearing(),
723
+ startPitch = this.getPitch(),
724
+ startPadding = this.getPadding(),
725
+
726
+ zoom = 'zoom' in options ? +options.zoom : startZoom,
727
+ bearing = 'bearing' in options ? this._normalizeBearing(options.bearing, startBearing) : startBearing,
728
+ pitch = 'pitch' in options ? +options.pitch : startPitch,
729
+ padding = 'padding' in options ? options.padding : tr.padding;
730
+
731
+ const offsetAsPoint = Point.convert(options.offset);
732
+ let pointAtOffset = tr.centerPoint.add(offsetAsPoint);
733
+ const locationAtOffset = tr.pointLocation(pointAtOffset);
734
+ const center = LngLat.convert(options.center || locationAtOffset);
735
+ this._normalizeCenter(center);
736
+
737
+ const from = tr.project(locationAtOffset);
738
+ const delta = tr.project(center).sub(from);
739
+ const finalScale = tr.zoomScale(zoom - startZoom);
740
+
741
+ let around, aroundPoint;
742
+
743
+ if (options.around) {
744
+ around = LngLat.convert(options.around);
745
+ aroundPoint = tr.locationPoint(around);
746
+ }
747
+
748
+ this._zooming = (zoom !== startZoom);
749
+ this._rotating = (startBearing !== bearing);
750
+ this._pitching = (pitch !== startPitch);
751
+ this._padding = !tr.isPaddingEqual(padding);
752
+
753
+ this._prepareEase(eventData, options.noMoveStart);
754
+
755
+ clearTimeout(this._easeEndTimeoutID);
756
+
757
+ this._ease((k) => {
758
+ if (this._zooming) {
759
+ tr.zoom = interpolate(startZoom, zoom, k);
760
+ }
761
+ if (this._rotating) {
762
+ tr.bearing = interpolate(startBearing, bearing, k);
763
+ }
764
+ if (this._pitching) {
765
+ tr.pitch = interpolate(startPitch, pitch, k);
766
+ }
767
+ if (this._padding) {
768
+ tr.interpolatePadding(startPadding, padding, k);
769
+ // When padding is being applied, Transform#centerPoint is changing continously,
770
+ // thus we need to recalculate offsetPoint every fra,e
771
+ pointAtOffset = tr.centerPoint.add(offsetAsPoint);
772
+ }
773
+
774
+ if (around) {
775
+ tr.setLocationAtPoint(around, aroundPoint);
776
+ } else {
777
+ const scale = tr.zoomScale(tr.zoom - startZoom);
778
+ const base = zoom > startZoom ?
779
+ Math.min(2, finalScale) :
780
+ Math.max(0.5, finalScale);
781
+ const speedup = Math.pow(base, 1 - k);
782
+ const newCenter = tr.unproject(from.add(delta.mult(k * speedup)).mult(scale));
783
+ tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
784
+ }
785
+
786
+ this._fireMoveEvents(eventData);
787
+
788
+ }, () => {
789
+ if (options.delayEndEvents) {
790
+ this._easeEndTimeoutID = setTimeout(() => this._afterEase(eventData), options.delayEndEvents);
791
+ } else {
792
+ this._afterEase(eventData);
793
+ }
794
+ }, options);
795
+
796
+ return this;
797
+ }
798
+
799
+ _prepareEase(eventData?: Object, noMoveStart: boolean) {
800
+ this._moving = true;
801
+
802
+ if (!noMoveStart) {
803
+ this.fire(new Event('movestart', eventData));
804
+ }
805
+ if (this._zooming) {
806
+ this.fire(new Event('zoomstart', eventData));
807
+ }
808
+ if (this._rotating) {
809
+ this.fire(new Event('rotatestart', eventData));
810
+ }
811
+ if (this._pitching) {
812
+ this.fire(new Event('pitchstart', eventData));
813
+ }
814
+ }
815
+
816
+ _fireMoveEvents(eventData?: Object) {
817
+ this.fire(new Event('move', eventData));
818
+ if (this._zooming) {
819
+ this.fire(new Event('zoom', eventData));
820
+ }
821
+ if (this._rotating) {
822
+ this.fire(new Event('rotate', eventData));
823
+ }
824
+ if (this._pitching) {
825
+ this.fire(new Event('pitch', eventData));
826
+ }
827
+ }
828
+
829
+ _afterEase(eventData?: Object) {
830
+ const wasZooming = this._zooming;
831
+ const wasRotating = this._rotating;
832
+ const wasPitching = this._pitching;
833
+ this._moving = false;
834
+ this._zooming = false;
835
+ this._rotating = false;
836
+ this._pitching = false;
837
+ this._padding = false;
838
+
839
+ if (wasZooming) {
840
+ this.fire(new Event('zoomend', eventData));
841
+ }
842
+ if (wasRotating) {
843
+ this.fire(new Event('rotateend', eventData));
844
+ }
845
+ if (wasPitching) {
846
+ this.fire(new Event('pitchend', eventData));
847
+ }
848
+ this.fire(new Event('moveend', eventData));
849
+ }
850
+
851
+ /**
852
+ * Changes any combination of center, zoom, bearing, and pitch, animating the transition along a curve that
853
+ * evokes flight. The animation seamlessly incorporates zooming and panning to help
854
+ * the user maintain her bearings even after traversing a great distance.
855
+ *
856
+ * Note: The animation will be skipped, and this will behave equivalently to `jumpTo`
857
+ * if the user has the `reduced motion` accesibility feature enabled in their operating system,
858
+ * unless 'options' includes `essential: true`.
859
+ *
860
+ * @memberof Map#
861
+ * @param {Object} options Options describing the destination and animation of the transition.
862
+ * Accepts {@link CameraOptions}, {@link AnimationOptions},
863
+ * and the following additional options.
864
+ * @param {number} [options.curve=1.42] The zooming "curve" that will occur along the
865
+ * flight path. A high value maximizes zooming for an exaggerated animation, while a low
866
+ * value minimizes zooming for an effect closer to {@link Map#easeTo}. 1.42 is the average
867
+ * value selected by participants in the user study discussed in
868
+ * [van Wijk (2003)](https://www.win.tue.nl/~vanwijk/zoompan.pdf). A value of
869
+ * `Math.pow(6, 0.25)` would be equivalent to the root mean squared average velocity. A
870
+ * value of 1 would produce a circular motion.
871
+ * @param {number} [options.minZoom] The zero-based zoom level at the peak of the flight path. If
872
+ * `options.curve` is specified, this option is ignored.
873
+ * @param {number} [options.speed=1.2] The average speed of the animation defined in relation to
874
+ * `options.curve`. A speed of 1.2 means that the map appears to move along the flight path
875
+ * by 1.2 times `options.curve` screenfuls every second. A _screenful_ is the map's visible span.
876
+ * It does not correspond to a fixed physical distance, but varies by zoom level.
877
+ * @param {number} [options.screenSpeed] The average speed of the animation measured in screenfuls
878
+ * per second, assuming a linear timing curve. If `options.speed` is specified, this option is ignored.
879
+ * @param {number} [options.maxDuration] The animation's maximum duration, measured in milliseconds.
880
+ * If duration exceeds maximum duration, it resets to 0.
881
+ * @param eventData Additional properties to be added to event objects of events triggered by this method.
882
+ * @fires movestart
883
+ * @fires zoomstart
884
+ * @fires pitchstart
885
+ * @fires move
886
+ * @fires zoom
887
+ * @fires rotate
888
+ * @fires pitch
889
+ * @fires moveend
890
+ * @fires zoomend
891
+ * @fires pitchend
892
+ * @returns {Map} `this`
893
+ * @example
894
+ * // fly with default options to null island
895
+ * map.flyTo({center: [0, 0], zoom: 9});
896
+ * // using flyTo options
897
+ * map.flyTo({
898
+ * center: [0, 0],
899
+ * zoom: 9,
900
+ * speed: 0.2,
901
+ * curve: 1,
902
+ * easing(t) {
903
+ * return t;
904
+ * }
905
+ * });
906
+ * @see [Fly to a location](https://www.mapbox.com/mapbox-gl-js/example/flyto/)
907
+ * @see [Slowly fly to a location](https://www.mapbox.com/mapbox-gl-js/example/flyto-options/)
908
+ * @see [Fly to a location based on scroll position](https://www.mapbox.com/mapbox-gl-js/example/scroll-fly-to/)
909
+ */
910
+ flyTo(options: Object, eventData?: Object) {
911
+ // Fall through to jumpTo if user has set prefers-reduced-motion
912
+ if (!options.essential && browser.prefersReducedMotion) {
913
+ const coercedOptions = (pick(options, ['center', 'zoom', 'bearing', 'pitch', 'around']): CameraOptions);
914
+ return this.jumpTo(coercedOptions, eventData);
915
+ }
916
+
917
+ // This method implements an “optimal path” animation, as detailed in:
918
+ //
919
+ // Van Wijk, Jarke J.; Nuij, Wim A. A. “Smooth and efficient zooming and panning.” INFOVIS
920
+ // ’03. pp. 15–22. <https://www.win.tue.nl/~vanwijk/zoompan.pdf#page=5>.
921
+ //
922
+ // Where applicable, local variable documentation begins with the associated variable or
923
+ // function in van Wijk (2003).
924
+
925
+ this.stop();
926
+
927
+ options = extend({
928
+ offset: [0, 0],
929
+ speed: 1.2,
930
+ curve: 1.42,
931
+ easing: defaultEasing
932
+ }, options);
933
+
934
+ const tr = this.transform,
935
+ startZoom = this.getZoom(),
936
+ startBearing = this.getBearing(),
937
+ startPitch = this.getPitch(),
938
+ startPadding = this.getPadding();
939
+
940
+ const zoom = 'zoom' in options ? clamp(+options.zoom, tr.minZoom, tr.maxZoom) : startZoom;
941
+ const bearing = 'bearing' in options ? this._normalizeBearing(options.bearing, startBearing) : startBearing;
942
+ const pitch = 'pitch' in options ? +options.pitch : startPitch;
943
+ const padding = 'padding' in options ? options.padding : tr.padding;
944
+
945
+ const scale = tr.zoomScale(zoom - startZoom);
946
+ const offsetAsPoint = Point.convert(options.offset);
947
+ let pointAtOffset = tr.centerPoint.add(offsetAsPoint);
948
+ const locationAtOffset = tr.pointLocation(pointAtOffset);
949
+ if (options.center && options.center.length >= 2) {
950
+ if (options.center[0] == 0) {
951
+ options.center[0] = 0.000001;
952
+ }
953
+ if (options.center[1] == 0) {
954
+ options.center[1] = 0.000001;
955
+ }
956
+ }
957
+ const center = LngLat.convert(options.center || locationAtOffset);
958
+ this._normalizeCenter(center);
959
+
960
+ const from = tr.project(locationAtOffset);
961
+ const delta = tr.project(center).sub(from);
962
+
963
+ let rho = options.curve;
964
+
965
+ // w₀: Initial visible span, measured in pixels at the initial scale.
966
+ const w0 = Math.max(tr.width, tr.height),
967
+ // w₁: Final visible span, measured in pixels with respect to the initial scale.
968
+ w1 = w0 / scale,
969
+ // Length of the flight path as projected onto the ground plane, measured in pixels from
970
+ // the world image origin at the initial scale.
971
+ u1 = delta.mag();
972
+
973
+ if ('minZoom' in options) {
974
+ const minZoom = clamp(Math.min(options.minZoom, startZoom, zoom), tr.minZoom, tr.maxZoom);
975
+ // w<sub>m</sub>: Maximum visible span, measured in pixels with respect to the initial
976
+ // scale.
977
+ const wMax = w0 / tr.zoomScale(minZoom - startZoom);
978
+ rho = Math.sqrt(wMax / u1 * 2);
979
+ }
980
+
981
+ // ρ²
982
+ const rho2 = rho * rho;
983
+
984
+ /**
985
+ * rᵢ: Returns the zoom-out factor at one end of the animation.
986
+ *
987
+ * @param i 0 for the ascent or 1 for the descent.
988
+ * @private
989
+ */
990
+ function r(i) {
991
+ const b = (w1 * w1 - w0 * w0 + (i ? -1 : 1) * rho2 * rho2 * u1 * u1) / (2 * (i ? w1 : w0) * rho2 * u1);
992
+ return Math.log(Math.sqrt(b * b + 1) - b);
993
+ }
994
+
995
+ function sinh(n) { return (Math.exp(n) - Math.exp(-n)) / 2; }
996
+ function cosh(n) { return (Math.exp(n) + Math.exp(-n)) / 2; }
997
+ function tanh(n) { return sinh(n) / cosh(n); }
998
+
999
+ // r₀: Zoom-out factor during ascent.
1000
+ const r0 = r(0);
1001
+
1002
+ // w(s): Returns the visible span on the ground, measured in pixels with respect to the
1003
+ // initial scale. Assumes an angular field of view of 2 arctan ½ ≈ 53°.
1004
+ let w: (_: number) => number = function (s) {
1005
+ return (cosh(r0) / cosh(r0 + rho * s));
1006
+ };
1007
+
1008
+ // u(s): Returns the distance along the flight path as projected onto the ground plane,
1009
+ // measured in pixels from the world image origin at the initial scale.
1010
+ let u: (_: number) => number = function (s) {
1011
+ return w0 * ((cosh(r0) * tanh(r0 + rho * s) - sinh(r0)) / rho2) / u1;
1012
+ };
1013
+
1014
+ // S: Total length of the flight path, measured in ρ-screenfuls.
1015
+ let S = (r(1) - r0) / rho;
1016
+
1017
+ // When u₀ = u₁, the optimal path doesn’t require both ascent and descent.
1018
+ if (Math.abs(u1) < 0.000001 || !isFinite(S)) {
1019
+ // Perform a more or less instantaneous transition if the path is too short.
1020
+ if (Math.abs(w0 - w1) < 0.000001) return this.easeTo(options, eventData);
1021
+
1022
+ const k = w1 < w0 ? -1 : 1;
1023
+ S = Math.abs(Math.log(w1 / w0)) / rho;
1024
+
1025
+ u = function() { return 0; };
1026
+ w = function(s) { return Math.exp(k * rho * s); };
1027
+ }
1028
+
1029
+ if ('duration' in options) {
1030
+ options.duration = +options.duration;
1031
+ } else {
1032
+ const V = 'screenSpeed' in options ? +options.screenSpeed / rho : +options.speed;
1033
+ options.duration = 1000 * S / V;
1034
+ }
1035
+
1036
+ if (options.maxDuration && options.duration > options.maxDuration) {
1037
+ options.duration = 0;
1038
+ }
1039
+
1040
+ this._zooming = true;
1041
+ this._rotating = (startBearing !== bearing);
1042
+ this._pitching = (pitch !== startPitch);
1043
+ this._padding = !tr.isPaddingEqual(padding);
1044
+
1045
+ this._prepareEase(eventData, false);
1046
+
1047
+ this._ease((k) => {
1048
+ // s: The distance traveled along the flight path, measured in ρ-screenfuls.
1049
+ const s = k * S;
1050
+ const scale = 1 / w(s);
1051
+ tr.zoom = k === 1 ? zoom : startZoom + tr.scaleZoom(scale);
1052
+
1053
+ if (this._rotating) {
1054
+ tr.bearing = interpolate(startBearing, bearing, k);
1055
+ }
1056
+ if (this._pitching) {
1057
+ tr.pitch = interpolate(startPitch, pitch, k);
1058
+ }
1059
+ if (this._padding) {
1060
+ tr.interpolatePadding(startPadding, padding, k);
1061
+ // When padding is being applied, Transform#centerPoint is changing continously,
1062
+ // thus we need to recalculate offsetPoint every frame
1063
+ pointAtOffset = tr.centerPoint.add(offsetAsPoint);
1064
+ }
1065
+
1066
+ const newCenter = k === 1 ? center : tr.unproject(from.add(delta.mult(u(s))).mult(scale));
1067
+ tr.setLocationAtPoint(tr.renderWorldCopies ? newCenter.wrap() : newCenter, pointAtOffset);
1068
+
1069
+ this._fireMoveEvents(eventData);
1070
+
1071
+ }, () => this._afterEase(eventData), options);
1072
+
1073
+ return this;
1074
+ }
1075
+
1076
+ isEasing() {
1077
+ return !!this._easeFrameId;
1078
+ }
1079
+
1080
+ /**
1081
+ * Stops any animated transition underway.
1082
+ *
1083
+ * @memberof Map#
1084
+ * @returns {Map} `this`
1085
+ */
1086
+ stop(): this {
1087
+ if (this._easeFrameId) {
1088
+ this._cancelRenderFrame(this._easeFrameId);
1089
+ delete this._easeFrameId;
1090
+ delete this._onEaseFrame;
1091
+ }
1092
+
1093
+ if (this._onEaseEnd) {
1094
+ // The _onEaseEnd function might emit events which trigger new
1095
+ // animation, which sets a new _onEaseEnd. Ensure we don't delete
1096
+ // it unintentionally.
1097
+ const onEaseEnd = this._onEaseEnd;
1098
+ delete this._onEaseEnd;
1099
+ onEaseEnd.call(this);
1100
+ }
1101
+ return this;
1102
+ }
1103
+
1104
+ _ease(frame: (_: number) => void,
1105
+ finish: () => void,
1106
+ options: {animate: boolean, duration: number, easing: (_: number) => number}) {
1107
+ if (options.animate === false || options.duration === 0) {
1108
+ frame(1);
1109
+ finish();
1110
+ } else {
1111
+ this._easeStart = browser.now();
1112
+ this._easeOptions = options;
1113
+ this._onEaseFrame = frame;
1114
+ this._onEaseEnd = finish;
1115
+ this._easeFrameId = this._requestRenderFrame(this._renderFrameCallback);
1116
+ }
1117
+ }
1118
+
1119
+ // Callback for map._requestRenderFrame
1120
+ _renderFrameCallback() {
1121
+ const t = Math.min((browser.now() - this._easeStart) / this._easeOptions.duration, 1);
1122
+ this._onEaseFrame(this._easeOptions.easing(t));
1123
+ if (t < 1) {
1124
+ this._easeFrameId = this._requestRenderFrame(this._renderFrameCallback);
1125
+ } else {
1126
+ this.stop();
1127
+ }
1128
+ }
1129
+
1130
+ // convert bearing so that it's numerically close to the current one so that it interpolates properly
1131
+ _normalizeBearing(bearing: number, currentBearing: number) {
1132
+ bearing = wrap(bearing, -180, 180);
1133
+ const diff = Math.abs(bearing - currentBearing);
1134
+ if (Math.abs(bearing - 360 - currentBearing) < diff) bearing -= 360;
1135
+ if (Math.abs(bearing + 360 - currentBearing) < diff) bearing += 360;
1136
+ return bearing;
1137
+ }
1138
+
1139
+ // If a path crossing the antimeridian would be shorter, extend the final coordinate so that
1140
+ // interpolating between the two endpoints will cross it.
1141
+ _normalizeCenter(center: LngLat) {
1142
+ const tr = this.transform;
1143
+ if (!tr.renderWorldCopies || tr.lngRange) return;
1144
+
1145
+ const delta = center.lng - tr.center.lng;
1146
+ center.lng +=
1147
+ delta > 180 ? -360 :
1148
+ delta < -180 ? 360 : 0;
1149
+ }
1150
+ }
1151
+
1152
+ export default Camera;