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,640 @@
1
+ // @flow
2
+
3
+ import {extend, bindAll} from '../util/util';
4
+ import {Event, Evented} from '../util/evented';
5
+ import {MapMouseEvent} from '../ui/events';
6
+ import DOM from '../util/dom';
7
+ import LngLat from '../geo/lng_lat';
8
+ import Point from '@mapbox/point-geometry';
9
+ import window from '../util/window';
10
+ import smartWrap from '../util/smart_wrap';
11
+ import {type Anchor, anchorTranslate, applyAnchorClass} from './anchor';
12
+
13
+ import type Map from './map';
14
+ import type {LngLatLike} from '../geo/lng_lat';
15
+ import type {PointLike} from '@mapbox/point-geometry';
16
+
17
+ const defaultOptions = {
18
+ closeButton: true,
19
+ closeOnClick: true,
20
+ focusAfterOpen: true,
21
+ className: '',
22
+ maxWidth: "240px"
23
+ };
24
+
25
+ export type Offset = number | PointLike | {[_: Anchor]: PointLike};
26
+
27
+ export type PopupOptions = {
28
+ closeButton?: boolean,
29
+ closeOnClick?: boolean,
30
+ closeOnMove?: boolean,
31
+ focusAfterOpen?: boolean,
32
+ anchor?: Anchor,
33
+ offset?: Offset,
34
+ className?: string,
35
+ maxWidth?: string
36
+ };
37
+
38
+ const focusQuerySelector = [
39
+ "a[href]",
40
+ "[tabindex]:not([tabindex='-1'])",
41
+ "[contenteditable]:not([contenteditable='false'])",
42
+ "button:not([disabled])",
43
+ "input:not([disabled])",
44
+ "select:not([disabled])",
45
+ "textarea:not([disabled])",
46
+ ].join(", ");
47
+
48
+ /**
49
+ * A popup component.
50
+ *
51
+ * @param {Object} [options]
52
+ * @param {boolean} [options.closeButton=true] If `true`, a close button will appear in the
53
+ * top right corner of the popup.
54
+ * @param {boolean} [options.closeOnClick=true] If `true`, the popup will closed when the
55
+ * map is clicked.
56
+ * @param {boolean} [options.closeOnMove=false] If `true`, the popup will closed when the
57
+ * map moves.
58
+ * @param {boolean} [options.focusAfterOpen=true] If `true`, the popup will try to focus the
59
+ * first focusable element inside the popup.
60
+ * @param {string} [options.anchor] - A string indicating the part of the Popup that should
61
+ * be positioned closest to the coordinate set via {@link Popup#setLngLat}.
62
+ * Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`,
63
+ * `'top-right'`, `'bottom-left'`, and `'bottom-right'`. If unset the anchor will be
64
+ * dynamically set to ensure the popup falls within the map container with a preference
65
+ * for `'bottom'`.
66
+ * @param {number|PointLike|Object} [options.offset] -
67
+ * A pixel offset applied to the popup's location specified as:
68
+ * - a single number specifying a distance from the popup's location
69
+ * - a {@link PointLike} specifying a constant offset
70
+ * - an object of {@link Point}s specifing an offset for each anchor position
71
+ * Negative offsets indicate left and up.
72
+ * @param {string} [options.className] Space-separated CSS class names to add to popup container
73
+ * @param {string} [options.maxWidth='240px'] -
74
+ * A string that sets the CSS property of the popup's maximum width, eg `'300px'`.
75
+ * To ensure the popup resizes to fit its content, set this property to `'none'`.
76
+ * Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
77
+ * @example
78
+ * var markerHeight = 50, markerRadius = 10, linearOffset = 25;
79
+ * var popupOffsets = {
80
+ * 'top': [0, 0],
81
+ * 'top-left': [0,0],
82
+ * 'top-right': [0,0],
83
+ * 'bottom': [0, -markerHeight],
84
+ * 'bottom-left': [linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
85
+ * 'bottom-right': [-linearOffset, (markerHeight - markerRadius + linearOffset) * -1],
86
+ * 'left': [markerRadius, (markerHeight - markerRadius) * -1],
87
+ * 'right': [-markerRadius, (markerHeight - markerRadius) * -1]
88
+ * };
89
+ * var popup = new mapboxgl.Popup({offset: popupOffsets, className: 'my-class'})
90
+ * .setLngLat(e.lngLat)
91
+ * .setHTML("<h1>Hello World!</h1>")
92
+ * .setMaxWidth("300px")
93
+ * .addTo(map);
94
+ * @see [Display a popup](https://www.mapbox.com/mapbox-gl-js/example/popup/)
95
+ * @see [Display a popup on hover](https://www.mapbox.com/mapbox-gl-js/example/popup-on-hover/)
96
+ * @see [Display a popup on click](https://www.mapbox.com/mapbox-gl-js/example/popup-on-click/)
97
+ * @see [Attach a popup to a marker instance](https://www.mapbox.com/mapbox-gl-js/example/set-popup/)
98
+ */
99
+ export default class Popup extends Evented {
100
+ _map: Map;
101
+ options: PopupOptions;
102
+ _content: HTMLElement;
103
+ _container: HTMLElement;
104
+ _closeButton: HTMLElement;
105
+ _tip: HTMLElement;
106
+ _lngLat: LngLat;
107
+ _trackPointer: boolean;
108
+ _pos: ?Point;
109
+
110
+ constructor(options: PopupOptions) {
111
+ super();
112
+ this.options = extend(Object.create(defaultOptions), options);
113
+ bindAll(['_update', '_onClose', 'remove', '_onMouseMove', '_onMouseUp', '_onDrag'], this);
114
+ }
115
+
116
+ /**
117
+ * Adds the popup to a map.
118
+ *
119
+ * @param {Map} map The Mapbox GL JS map to add the popup to.
120
+ * @returns {Popup} `this`
121
+ * @example
122
+ * new mapboxgl.Popup()
123
+ * .setLngLat([0, 0])
124
+ * .setHTML("<h1>Null Island</h1>")
125
+ * .addTo(map);
126
+ * @see [Display a popup](https://docs.mapbox.com/mapbox-gl-js/example/popup/)
127
+ * @see [Display a popup on hover](https://docs.mapbox.com/mapbox-gl-js/example/popup-on-hover/)
128
+ * @see [Display a popup on click](https://docs.mapbox.com/mapbox-gl-js/example/popup-on-click/)
129
+ * @see [Show polygon information on click](https://docs.mapbox.com/mapbox-gl-js/example/polygon-popup-on-click/)
130
+ */
131
+ addTo(map: Map) {
132
+ if (this._map) this.remove();
133
+
134
+ this._map = map;
135
+ if (this.options.closeOnClick) {
136
+ this._map.on('click', this._onClose);
137
+ }
138
+
139
+ if (this.options.closeOnMove) {
140
+ this._map.on('move', this._onClose);
141
+ }
142
+
143
+ this._map.on('remove', this.remove);
144
+ this._update();
145
+ this._focusFirstElement();
146
+
147
+ if (this._trackPointer) {
148
+ this._map.on('mousemove', this._onMouseMove);
149
+ this._map.on('mouseup', this._onMouseUp);
150
+ if (this._container) {
151
+ this._container.classList.add('mapboxgl-popup-track-pointer');
152
+ }
153
+ this._map._canvasContainer.classList.add('mapboxgl-track-pointer');
154
+ } else {
155
+ this._map.on('move', this._update);
156
+ }
157
+
158
+ /**
159
+ * Fired when the popup is opened manually or programatically.
160
+ *
161
+ * @event open
162
+ * @memberof Popup
163
+ * @instance
164
+ * @type {Object}
165
+ * @property {Popup} popup object that was opened
166
+ *
167
+ * @example
168
+ * // Create a popup
169
+ * var popup = new mapboxgl.Popup();
170
+ * // Set an event listener that will fire
171
+ * // any time the popup is opened
172
+ * popup.on('open', function(){
173
+ * console.log('popup was opened');
174
+ * });
175
+ *
176
+ */
177
+ this.fire(new Event('open'));
178
+
179
+ return this;
180
+ }
181
+
182
+ /**
183
+ * @returns {boolean} `true` if the popup is open, `false` if it is closed.
184
+ */
185
+ isOpen() {
186
+ return !!this._map;
187
+ }
188
+
189
+ /**
190
+ * Removes the popup from the map it has been added to.
191
+ *
192
+ * @example
193
+ * var popup = new mapboxgl.Popup().addTo(map);
194
+ * popup.remove();
195
+ * @returns {Popup} `this`
196
+ */
197
+ remove() {
198
+ if (this._content) {
199
+ DOM.remove(this._content);
200
+ }
201
+
202
+ if (this._container) {
203
+ DOM.remove(this._container);
204
+ delete this._container;
205
+ }
206
+
207
+ if (this._map) {
208
+ this._map.off('move', this._update);
209
+ this._map.off('move', this._onClose);
210
+ this._map.off('click', this._onClose);
211
+ this._map.off('remove', this.remove);
212
+ this._map.off('mousemove', this._onMouseMove);
213
+ this._map.off('mouseup', this._onMouseUp);
214
+ this._map.off('drag', this._onDrag);
215
+ delete this._map;
216
+ }
217
+
218
+ /**
219
+ * Fired when the popup is closed manually or programatically.
220
+ *
221
+ * @event close
222
+ * @memberof Popup
223
+ * @instance
224
+ * @type {Object}
225
+ * @property {Popup} popup object that was closed
226
+ *
227
+ * @example
228
+ * // Create a popup
229
+ * var popup = new mapboxgl.Popup();
230
+ * // Set an event listener that will fire
231
+ * // any time the popup is closed
232
+ * popup.on('close', function(){
233
+ * console.log('popup was closed');
234
+ * });
235
+ *
236
+ */
237
+ this.fire(new Event('close'));
238
+
239
+ return this;
240
+ }
241
+
242
+ /**
243
+ * Returns the geographical location of the popup's anchor.
244
+ *
245
+ * The longitude of the result may differ by a multiple of 360 degrees from the longitude previously
246
+ * set by `setLngLat` because `Popup` wraps the anchor longitude across copies of the world to keep
247
+ * the popup on screen.
248
+ *
249
+ * @returns {LngLat} The geographical location of the popup's anchor.
250
+ */
251
+ getLngLat() {
252
+ return this._lngLat;
253
+ }
254
+
255
+ /**
256
+ * Sets the geographical location of the popup's anchor, and moves the popup to it. Replaces trackPointer() behavior.
257
+ *
258
+ * @param lnglat The geographical location to set as the popup's anchor.
259
+ * @returns {Popup} `this`
260
+ */
261
+ setLngLat(lnglat: LngLatLike) {
262
+ this._lngLat = LngLat.convert(lnglat);
263
+ this._pos = null;
264
+
265
+ this._trackPointer = false;
266
+
267
+ this._update();
268
+
269
+ if (this._map) {
270
+ this._map.on('move', this._update);
271
+ this._map.off('mousemove', this._onMouseMove);
272
+ if (this._container) {
273
+ this._container.classList.remove('mapboxgl-popup-track-pointer');
274
+ }
275
+ this._map._canvasContainer.classList.remove('mapboxgl-track-pointer');
276
+ }
277
+
278
+ return this;
279
+ }
280
+
281
+ /**
282
+ * Tracks the popup anchor to the cursor position on screens with a pointer device (it will be hidden on touchscreens). Replaces the `setLngLat` behavior.
283
+ * For most use cases, set `closeOnClick` and `closeButton` to `false`.
284
+ * @example
285
+ * var popup = new mapboxgl.Popup({ closeOnClick: false, closeButton: false })
286
+ * .setHTML("<h1>Hello World!</h1>")
287
+ * .trackPointer()
288
+ * .addTo(map);
289
+ * @returns {Popup} `this`
290
+ */
291
+ trackPointer() {
292
+ this._trackPointer = true;
293
+ this._pos = null;
294
+ this._update();
295
+ if (this._map) {
296
+ this._map.off('move', this._update);
297
+ this._map.on('mousemove', this._onMouseMove);
298
+ this._map.on('drag', this._onDrag);
299
+ if (this._container) {
300
+ this._container.classList.add('mapboxgl-popup-track-pointer');
301
+ }
302
+ this._map._canvasContainer.classList.add('mapboxgl-track-pointer');
303
+ }
304
+
305
+ return this;
306
+
307
+ }
308
+
309
+ /**
310
+ * Returns the `Popup`'s HTML element.
311
+ * @example
312
+ * // Change the `Popup` element's font size
313
+ * var popup = new mapboxgl.Popup()
314
+ * .setLngLat([-96, 37.8])
315
+ * .setHTML("<p>Hello World!</p>")
316
+ * .addTo(map);
317
+ * var popupElem = popup.getElement();
318
+ * popupElem.style.fontSize = "25px";
319
+ * @returns {HTMLElement} element
320
+ */
321
+ getElement() {
322
+ return this._container;
323
+ }
324
+
325
+ /**
326
+ * Sets the popup's content to a string of text.
327
+ *
328
+ * This function creates a [Text](https://developer.mozilla.org/en-US/docs/Web/API/Text) node in the DOM,
329
+ * so it cannot insert raw HTML. Use this method for security against XSS
330
+ * if the popup content is user-provided.
331
+ *
332
+ * @param text Textual content for the popup.
333
+ * @returns {Popup} `this`
334
+ * @example
335
+ * var popup = new mapboxgl.Popup()
336
+ * .setLngLat(e.lngLat)
337
+ * .setText('Hello, world!')
338
+ * .addTo(map);
339
+ */
340
+ setText(text: string) {
341
+ return this.setDOMContent(window.document.createTextNode(text));
342
+ }
343
+
344
+ /**
345
+ * Sets the popup's content to the HTML provided as a string.
346
+ *
347
+ * This method does not perform HTML filtering or sanitization, and must be
348
+ * used only with trusted content. Consider {@link Popup#setText} if
349
+ * the content is an untrusted text string.
350
+ *
351
+ * @param html A string representing HTML content for the popup.
352
+ * @returns {Popup} `this`
353
+ * @example
354
+ * var popup = new mapboxgl.Popup()
355
+ * .setLngLat(e.lngLat)
356
+ * .setHTML("<h1>Hello World!</h1>")
357
+ * .addTo(map);
358
+ * @see [Display a popup](https://docs.mapbox.com/mapbox-gl-js/example/popup/)
359
+ * @see [Display a popup on hover](https://docs.mapbox.com/mapbox-gl-js/example/popup-on-hover/)
360
+ * @see [Display a popup on click](https://docs.mapbox.com/mapbox-gl-js/example/popup-on-click/)
361
+ * @see [Attach a popup to a marker instance](https://docs.mapbox.com/mapbox-gl-js/example/set-popup/)
362
+ */
363
+ setHTML(html: string) {
364
+ const frag = window.document.createDocumentFragment();
365
+ const temp = window.document.createElement('body');
366
+ let child;
367
+ temp.innerHTML = html;
368
+ while (true) {
369
+ child = temp.firstChild;
370
+ if (!child) break;
371
+ frag.appendChild(child);
372
+ }
373
+
374
+ return this.setDOMContent(frag);
375
+ }
376
+
377
+ /**
378
+ * Returns the popup's maximum width.
379
+ *
380
+ * @returns {string} The maximum width of the popup.
381
+ */
382
+ getMaxWidth() {
383
+ return this._container && this._container.style.maxWidth;
384
+ }
385
+
386
+ /**
387
+ * Sets the popup's maximum width. This is setting the CSS property `max-width`.
388
+ * Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
389
+ *
390
+ * @param maxWidth A string representing the value for the maximum width.
391
+ * @returns {Popup} `this`
392
+ */
393
+ setMaxWidth(maxWidth: string) {
394
+ this.options.maxWidth = maxWidth;
395
+ this._update();
396
+ return this;
397
+ }
398
+
399
+ /**
400
+ * Sets the popup's content to the element provided as a DOM node.
401
+ *
402
+ * @param htmlNode A DOM node to be used as content for the popup.
403
+ * @returns {Popup} `this`
404
+ * @example
405
+ * // create an element with the popup content
406
+ * var div = window.document.createElement('div');
407
+ * div.innerHTML = 'Hello, world!';
408
+ * var popup = new mapboxgl.Popup()
409
+ * .setLngLat(e.lngLat)
410
+ * .setDOMContent(div)
411
+ * .addTo(map);
412
+ */
413
+ setDOMContent(htmlNode: Node) {
414
+ if (this._content) {
415
+ // Clear out children first.
416
+ while (this._content.hasChildNodes()) {
417
+ if (this._content.firstChild) {
418
+ this._content.removeChild(this._content.firstChild);
419
+ }
420
+ }
421
+ } else {
422
+ this._content = DOM.create('div', 'mapboxgl-popup-content', this._container);
423
+ }
424
+
425
+ // The close button should be the last tabbable element inside the popup for a good keyboard UX.
426
+ this._content.appendChild(htmlNode);
427
+ this._createCloseButton();
428
+ this._update();
429
+ this._focusFirstElement();
430
+ return this;
431
+ }
432
+
433
+ /**
434
+ * Adds a CSS class to the popup container element.
435
+ *
436
+ * @param {string} className Non-empty string with CSS class name to add to popup container
437
+ *
438
+ * @example
439
+ * let popup = new mapboxgl.Popup()
440
+ * popup.addClassName('some-class')
441
+ */
442
+ addClassName(className: string) {
443
+ if (this._container) {
444
+ this._container.classList.add(className);
445
+ }
446
+ }
447
+
448
+ /**
449
+ * Removes a CSS class from the popup container element.
450
+ *
451
+ * @param {string} className Non-empty string with CSS class name to remove from popup container
452
+ *
453
+ * @example
454
+ * let popup = new mapboxgl.Popup()
455
+ * popup.removeClassName('some-class')
456
+ */
457
+ removeClassName(className: string) {
458
+ if (this._container) {
459
+ this._container.classList.remove(className);
460
+ }
461
+ }
462
+
463
+ /**
464
+ * Sets the popup's offset.
465
+ *
466
+ * @param offset Sets the popup's offset.
467
+ * @returns {Popup} `this`
468
+ */
469
+ setOffset (offset?: Offset) {
470
+ this.options.offset = offset;
471
+ this._update();
472
+ return this;
473
+ }
474
+
475
+ /**
476
+ * Add or remove the given CSS class on the popup container, depending on whether the container currently has that class.
477
+ *
478
+ * @param {string} className Non-empty string with CSS class name to add/remove
479
+ *
480
+ * @returns {boolean} if the class was removed return false, if class was added, then return true
481
+ *
482
+ * @example
483
+ * let popup = new mapboxgl.Popup()
484
+ * popup.toggleClassName('toggleClass')
485
+ */
486
+ toggleClassName(className: string) {
487
+ if (this._container) {
488
+ return this._container.classList.toggle(className);
489
+ }
490
+ }
491
+
492
+ _createCloseButton() {
493
+ if (this.options.closeButton) {
494
+ this._closeButton = DOM.create('button', 'mapboxgl-popup-close-button', this._content);
495
+ this._closeButton.type = 'button';
496
+ this._closeButton.setAttribute('aria-label', 'Close popup');
497
+ this._closeButton.innerHTML = '&#215;';
498
+ this._closeButton.addEventListener('click', this._onClose);
499
+ }
500
+ }
501
+
502
+ _onMouseUp(event: MapMouseEvent) {
503
+ this._update(event.point);
504
+ }
505
+
506
+ _onMouseMove(event: MapMouseEvent) {
507
+ this._update(event.point);
508
+ }
509
+
510
+ _onDrag(event: MapMouseEvent) {
511
+ this._update(event.point);
512
+ }
513
+
514
+ _update(cursor: ?PointLike) {
515
+ const hasPosition = this._lngLat || this._trackPointer;
516
+
517
+ if (!this._map || !hasPosition || !this._content) { return; }
518
+
519
+ if (!this._container) {
520
+ this._container = DOM.create('div', 'mapboxgl-popup', this._map.getContainer());
521
+ this._tip = DOM.create('div', 'mapboxgl-popup-tip', this._container);
522
+ this._container.appendChild(this._content);
523
+ if (this.options.className) {
524
+ this.options.className.split(' ').forEach(name =>
525
+ this._container.classList.add(name));
526
+ }
527
+
528
+ if (this._trackPointer) {
529
+ this._container.classList.add('mapboxgl-popup-track-pointer');
530
+ }
531
+ }
532
+
533
+ if (this.options.maxWidth && this._container.style.maxWidth !== this.options.maxWidth) {
534
+ this._container.style.maxWidth = this.options.maxWidth;
535
+ }
536
+
537
+ if (this._map.transform.renderWorldCopies && !this._trackPointer) {
538
+ this._lngLat = smartWrap(this._lngLat, this._pos, this._map.transform);
539
+ }
540
+
541
+ if (this._trackPointer && !cursor) return;
542
+
543
+ const pos = this._pos = this._trackPointer && cursor ? cursor : this._map.project(this._lngLat);
544
+
545
+ let anchor: ?Anchor = this.options.anchor;
546
+ const offset = normalizeOffset(this.options.offset);
547
+
548
+ if (!anchor) {
549
+ const width = this._container.offsetWidth;
550
+ const height = this._container.offsetHeight;
551
+ let anchorComponents;
552
+
553
+ if (pos.y + offset.bottom.y < height) {
554
+ anchorComponents = ['top'];
555
+ } else if (pos.y > this._map.transform.height - height) {
556
+ anchorComponents = ['bottom'];
557
+ } else {
558
+ anchorComponents = [];
559
+ }
560
+
561
+ if (pos.x < width / 2) {
562
+ anchorComponents.push('left');
563
+ } else if (pos.x > this._map.transform.width - width / 2) {
564
+ anchorComponents.push('right');
565
+ }
566
+
567
+ if (anchorComponents.length === 0) {
568
+ anchor = 'bottom';
569
+ } else {
570
+ anchor = (anchorComponents.join('-'): any);
571
+ }
572
+ }
573
+
574
+ const offsetedPos = pos.add(offset[anchor]).round();
575
+ DOM.setTransform(this._container, `${anchorTranslate[anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`);
576
+ applyAnchorClass(this._container, anchor, 'popup');
577
+ }
578
+
579
+ _focusFirstElement() {
580
+ if (!this.options.focusAfterOpen || !this._container) return;
581
+
582
+ const firstFocusable = this._container.querySelector(focusQuerySelector);
583
+
584
+ if (firstFocusable) firstFocusable.focus();
585
+ }
586
+
587
+ _onClose() {
588
+ this.remove();
589
+ }
590
+ }
591
+
592
+ function normalizeOffset(offset: ?Offset) {
593
+ if (!offset) {
594
+ return normalizeOffset(new Point(0, 0));
595
+
596
+ } else if (typeof offset === 'number') {
597
+ // input specifies a radius from which to calculate offsets at all positions
598
+ const cornerOffset = Math.round(Math.sqrt(0.5 * Math.pow(offset, 2)));
599
+ return {
600
+ 'center': new Point(0, 0),
601
+ 'top': new Point(0, offset),
602
+ 'top-left': new Point(cornerOffset, cornerOffset),
603
+ 'top-right': new Point(-cornerOffset, cornerOffset),
604
+ 'bottom': new Point(0, -offset),
605
+ 'bottom-left': new Point(cornerOffset, -cornerOffset),
606
+ 'bottom-right': new Point(-cornerOffset, -cornerOffset),
607
+ 'left': new Point(offset, 0),
608
+ 'right': new Point(-offset, 0)
609
+ };
610
+
611
+ } else if (offset instanceof Point || Array.isArray(offset)) {
612
+ // input specifies a single offset to be applied to all positions
613
+ const convertedOffset = Point.convert(offset);
614
+ return {
615
+ 'center': convertedOffset,
616
+ 'top': convertedOffset,
617
+ 'top-left': convertedOffset,
618
+ 'top-right': convertedOffset,
619
+ 'bottom': convertedOffset,
620
+ 'bottom-left': convertedOffset,
621
+ 'bottom-right': convertedOffset,
622
+ 'left': convertedOffset,
623
+ 'right': convertedOffset
624
+ };
625
+
626
+ } else {
627
+ // input specifies an offset per position
628
+ return {
629
+ 'center': Point.convert(offset['center'] || [0, 0]),
630
+ 'top': Point.convert(offset['top'] || [0, 0]),
631
+ 'top-left': Point.convert(offset['top-left'] || [0, 0]),
632
+ 'top-right': Point.convert(offset['top-right'] || [0, 0]),
633
+ 'bottom': Point.convert(offset['bottom'] || [0, 0]),
634
+ 'bottom-left': Point.convert(offset['bottom-left'] || [0, 0]),
635
+ 'bottom-right': Point.convert(offset['bottom-right'] || [0, 0]),
636
+ 'left': Point.convert(offset['left'] || [0, 0]),
637
+ 'right': Point.convert(offset['right'] || [0, 0])
638
+ };
639
+ }
640
+ }