mapbox-gl 1.13.2

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