maplibre-gl 3.1.0 → 3.2.0-pre.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 (338) hide show
  1. package/README.md +7 -7
  2. package/build/generate-doc-images.ts +73 -0
  3. package/build/generate-docs.ts +100 -0
  4. package/build/generate-struct-arrays.ts +9 -12
  5. package/dist/maplibre-gl-csp-worker.js +1 -1
  6. package/dist/maplibre-gl-csp-worker.js.map +1 -1
  7. package/dist/maplibre-gl-csp.js +1 -1
  8. package/dist/maplibre-gl-csp.js.map +1 -1
  9. package/dist/maplibre-gl-dev.js +3303 -3398
  10. package/dist/maplibre-gl-dev.js.map +1 -1
  11. package/dist/maplibre-gl.d.ts +3899 -3531
  12. package/dist/maplibre-gl.js +3 -3
  13. package/dist/maplibre-gl.js.map +1 -1
  14. package/package.json +28 -25
  15. package/src/data/array_types.g.ts +14 -48
  16. package/src/data/bucket/circle_bucket.ts +11 -14
  17. package/src/data/bucket/fill_bucket.test.ts +6 -6
  18. package/src/data/bucket/fill_bucket.ts +10 -12
  19. package/src/data/bucket/fill_extrusion_bucket.ts +11 -13
  20. package/src/data/bucket/heatmap_bucket.ts +3 -6
  21. package/src/data/bucket/line_attributes.ts +1 -2
  22. package/src/data/bucket/line_attributes_ext.ts +1 -2
  23. package/src/data/bucket/line_bucket.test.ts +5 -5
  24. package/src/data/bucket/line_bucket.ts +18 -21
  25. package/src/data/bucket/pattern_attributes.ts +1 -3
  26. package/src/data/bucket/pattern_bucket_features.ts +3 -3
  27. package/src/data/bucket/symbol_bucket.test.ts +5 -5
  28. package/src/data/bucket/symbol_bucket.ts +12 -15
  29. package/src/data/bucket.ts +7 -11
  30. package/src/data/dem_data.test.ts +1 -1
  31. package/src/data/dem_data.ts +1 -1
  32. package/src/data/evaluation_feature.ts +4 -5
  33. package/src/data/extent.ts +1 -4
  34. package/src/data/feature_index.ts +14 -13
  35. package/src/data/feature_position_map.test.ts +4 -4
  36. package/src/data/feature_position_map.ts +1 -1
  37. package/src/data/index_array_type.ts +0 -1
  38. package/src/data/load_geometry.test.ts +1 -1
  39. package/src/data/load_geometry.ts +3 -4
  40. package/src/data/program_configuration.ts +6 -11
  41. package/src/data/segment.ts +9 -6
  42. package/src/geo/edge_insets.test.ts +1 -1
  43. package/src/geo/edge_insets.ts +36 -26
  44. package/src/geo/lng_lat.test.ts +1 -1
  45. package/src/geo/lng_lat.ts +61 -44
  46. package/src/geo/lng_lat_bounds.test.ts +2 -2
  47. package/src/geo/lng_lat_bounds.ts +88 -68
  48. package/src/geo/mercator_coordinate.test.ts +2 -2
  49. package/src/geo/mercator_coordinate.ts +34 -27
  50. package/src/geo/transform.test.ts +3 -3
  51. package/src/geo/transform.ts +58 -79
  52. package/src/gl/color_mode.ts +1 -3
  53. package/src/gl/context.ts +12 -11
  54. package/src/gl/cull_face_mode.ts +1 -3
  55. package/src/gl/depth_mode.ts +1 -3
  56. package/src/gl/framebuffer.ts +5 -4
  57. package/src/gl/index_buffer.ts +5 -4
  58. package/src/gl/render_pool.test.ts +2 -2
  59. package/src/gl/render_pool.ts +5 -5
  60. package/src/gl/state.test.ts +1 -1
  61. package/src/gl/stencil_mode.ts +1 -3
  62. package/src/gl/value.ts +1 -1
  63. package/src/gl/vertex_buffer.test.ts +2 -2
  64. package/src/gl/vertex_buffer.ts +8 -14
  65. package/src/index.test.ts +2 -2
  66. package/src/index.ts +121 -113
  67. package/src/render/draw_background.ts +7 -9
  68. package/src/render/draw_circle.ts +13 -15
  69. package/src/render/draw_collision_debug.ts +11 -13
  70. package/src/render/draw_custom.ts +6 -8
  71. package/src/render/draw_debug.test.ts +4 -4
  72. package/src/render/draw_debug.ts +8 -10
  73. package/src/render/draw_fill.test.ts +13 -13
  74. package/src/render/draw_fill.ts +9 -11
  75. package/src/render/draw_fill_extrusion.ts +10 -12
  76. package/src/render/draw_heatmap.ts +12 -14
  77. package/src/render/draw_hillshade.ts +10 -12
  78. package/src/render/draw_line.ts +9 -9
  79. package/src/render/draw_raster.ts +9 -11
  80. package/src/render/draw_symbol.test.ts +16 -16
  81. package/src/render/draw_symbol.ts +15 -16
  82. package/src/render/draw_terrain.ts +11 -11
  83. package/src/render/glyph_atlas.ts +10 -1
  84. package/src/render/glyph_manager.test.ts +3 -3
  85. package/src/render/glyph_manager.ts +7 -7
  86. package/src/render/image_atlas.ts +6 -3
  87. package/src/render/image_manager.ts +3 -5
  88. package/src/render/line_atlas.test.ts +1 -1
  89. package/src/render/line_atlas.ts +19 -14
  90. package/src/render/painter.ts +85 -65
  91. package/src/render/program/background_program.ts +2 -2
  92. package/src/render/program/circle_program.ts +5 -5
  93. package/src/render/program/clipping_mask_program.ts +1 -1
  94. package/src/render/program/collision_program.ts +4 -4
  95. package/src/render/program/debug_program.ts +1 -1
  96. package/src/render/program/fill_extrusion_program.ts +3 -3
  97. package/src/render/program/fill_program.ts +3 -3
  98. package/src/render/program/heatmap_program.ts +5 -5
  99. package/src/render/program/hillshade_program.ts +7 -7
  100. package/src/render/program/line_program.ts +6 -6
  101. package/src/render/program/pattern.ts +3 -3
  102. package/src/render/program/raster_program.ts +2 -2
  103. package/src/render/program/symbol_program.ts +2 -2
  104. package/src/render/program/terrain_program.ts +1 -1
  105. package/src/render/program.ts +18 -16
  106. package/src/render/render_to_texture.test.ts +15 -15
  107. package/src/render/render_to_texture.ts +10 -10
  108. package/src/render/terrain.test.ts +38 -7
  109. package/src/render/terrain.ts +103 -67
  110. package/src/render/texture.ts +5 -4
  111. package/src/render/uniform_binding.test.ts +1 -1
  112. package/src/render/uniform_binding.ts +7 -1
  113. package/src/render/update_pattern_positions_in_program.ts +5 -5
  114. package/src/render/vertex_array_object.ts +9 -8
  115. package/src/shaders/encode_attribute.ts +0 -2
  116. package/src/shaders/shaders.ts +1 -3
  117. package/src/source/canvas_source.test.ts +6 -6
  118. package/src/source/canvas_source.ts +46 -60
  119. package/src/source/geojson_source.test.ts +5 -5
  120. package/src/source/geojson_source.ts +75 -59
  121. package/src/source/geojson_source_diff.ts +39 -2
  122. package/src/source/geojson_worker_source.test.ts +3 -3
  123. package/src/source/geojson_worker_source.ts +20 -26
  124. package/src/source/geojson_wrapper.test.ts +3 -3
  125. package/src/source/geojson_wrapper.ts +2 -4
  126. package/src/source/image_source.test.ts +9 -8
  127. package/src/source/image_source.ts +49 -35
  128. package/src/source/load_tilejson.ts +2 -2
  129. package/src/source/pixels_to_tile_units.ts +2 -3
  130. package/src/source/query_features.test.ts +3 -3
  131. package/src/source/query_features.ts +50 -19
  132. package/src/source/raster_dem_tile_source.test.ts +3 -3
  133. package/src/source/raster_dem_tile_source.ts +23 -10
  134. package/src/source/raster_dem_tile_worker_source.test.ts +2 -2
  135. package/src/source/raster_dem_tile_worker_source.ts +3 -5
  136. package/src/source/raster_tile_source.test.ts +3 -3
  137. package/src/source/raster_tile_source.ts +38 -11
  138. package/src/source/rtl_text_plugin.ts +4 -1
  139. package/src/source/source.ts +67 -59
  140. package/src/source/source_cache.test.ts +7 -7
  141. package/src/source/source_cache.ts +17 -38
  142. package/src/source/source_state.ts +2 -5
  143. package/src/source/terrain_source_cache.test.ts +8 -8
  144. package/src/source/terrain_source_cache.ts +42 -27
  145. package/src/source/tile.test.ts +3 -3
  146. package/src/source/tile.ts +32 -38
  147. package/src/source/tile_bounds.ts +2 -4
  148. package/src/source/tile_cache.test.ts +2 -2
  149. package/src/source/tile_cache.ts +20 -30
  150. package/src/source/tile_id.ts +11 -2
  151. package/src/source/vector_tile_source.test.ts +3 -3
  152. package/src/source/vector_tile_source.ts +34 -24
  153. package/src/source/vector_tile_worker_source.test.ts +4 -4
  154. package/src/source/vector_tile_worker_source.ts +11 -23
  155. package/src/source/video_source.test.ts +5 -5
  156. package/src/source/video_source.ts +21 -28
  157. package/src/source/worker.ts +6 -8
  158. package/src/source/worker_source.ts +6 -8
  159. package/src/source/worker_tile.test.ts +5 -5
  160. package/src/source/worker_tile.ts +13 -16
  161. package/src/style/create_style_layer.ts +31 -26
  162. package/src/style/evaluation_parameters.ts +5 -4
  163. package/src/style/format_section_override.test.ts +2 -2
  164. package/src/style/format_section_override.ts +1 -1
  165. package/src/style/light.test.ts +2 -2
  166. package/src/style/light.ts +3 -5
  167. package/src/style/load_glyph_range.test.ts +1 -1
  168. package/src/style/load_glyph_range.ts +3 -3
  169. package/src/style/load_sprite.test.ts +1 -1
  170. package/src/style/load_sprite.ts +3 -3
  171. package/src/style/parse_glyph_pbf.ts +1 -1
  172. package/src/style/pauseable_placement.ts +7 -9
  173. package/src/style/properties.ts +4 -53
  174. package/src/style/query_utils.ts +3 -3
  175. package/src/style/style.test.ts +22 -19
  176. package/src/style/style.ts +118 -84
  177. package/src/style/style_glyph.ts +6 -0
  178. package/src/style/style_image.ts +39 -33
  179. package/src/style/style_layer/background_style_layer.ts +2 -4
  180. package/src/style/style_layer/circle_style_layer.ts +7 -6
  181. package/src/style/style_layer/custom_style_layer.ts +23 -48
  182. package/src/style/style_layer/fill_extrusion_style_layer.ts +4 -6
  183. package/src/style/style_layer/fill_style_layer.ts +5 -7
  184. package/src/style/style_layer/heatmap_style_layer.ts +8 -7
  185. package/src/style/style_layer/hillshade_style_layer.ts +2 -4
  186. package/src/style/style_layer/line_style_layer.ts +6 -8
  187. package/src/style/style_layer/overlap_mode.test.ts +3 -3
  188. package/src/style/style_layer/overlap_mode.ts +3 -0
  189. package/src/style/style_layer/raster_style_layer.ts +2 -4
  190. package/src/style/style_layer/symbol_style_layer.ts +6 -8
  191. package/src/style/style_layer/typed_style_layer.ts +7 -7
  192. package/src/style/style_layer.test.ts +5 -5
  193. package/src/style/style_layer.ts +7 -6
  194. package/src/style/style_layer_index.test.ts +1 -1
  195. package/src/style/style_layer_index.ts +3 -5
  196. package/src/style/zoom_history.ts +1 -3
  197. package/src/symbol/anchor.test.ts +1 -1
  198. package/src/symbol/anchor.ts +1 -3
  199. package/src/symbol/check_max_angle.test.ts +8 -2
  200. package/src/symbol/check_max_angle.ts +10 -13
  201. package/src/symbol/clip_line.test.ts +1 -1
  202. package/src/symbol/clip_line.ts +6 -9
  203. package/src/symbol/collision_feature.test.ts +2 -2
  204. package/src/symbol/collision_feature.ts +7 -12
  205. package/src/symbol/collision_index.test.ts +2 -2
  206. package/src/symbol/collision_index.ts +5 -11
  207. package/src/symbol/cross_tile_symbol_index.test.ts +2 -2
  208. package/src/symbol/cross_tile_symbol_index.ts +5 -7
  209. package/src/symbol/get_anchors.ts +2 -2
  210. package/src/symbol/grid_index.test.ts +1 -1
  211. package/src/symbol/grid_index.ts +4 -5
  212. package/src/symbol/merge_lines.test.ts +1 -1
  213. package/src/symbol/merge_lines.ts +1 -1
  214. package/src/symbol/opacity_state.ts +1 -3
  215. package/src/symbol/path_interpolator.test.ts +1 -1
  216. package/src/symbol/path_interpolator.ts +1 -3
  217. package/src/symbol/placement.ts +9 -9
  218. package/src/symbol/projection.ts +61 -34
  219. package/src/symbol/quads.ts +7 -11
  220. package/src/symbol/shaping.ts +1 -1
  221. package/src/symbol/symbol_layout.ts +9 -12
  222. package/src/symbol/symbol_size.ts +1 -1
  223. package/src/symbol/symbol_style_layer.test.ts +4 -4
  224. package/src/symbol/transform_text.ts +2 -2
  225. package/src/types/callback.ts +14 -14
  226. package/src/types/cancelable.ts +3 -0
  227. package/src/types/transferable.ts +3 -0
  228. package/src/ui/anchor.ts +4 -0
  229. package/src/ui/camera.test.ts +6 -6
  230. package/src/ui/camera.ts +392 -361
  231. package/src/ui/control/attribution_control.test.ts +1 -1
  232. package/src/ui/control/attribution_control.ts +34 -30
  233. package/src/ui/control/control.ts +14 -20
  234. package/src/ui/control/fullscreen_control.test.ts +1 -1
  235. package/src/ui/control/fullscreen_control.ts +21 -26
  236. package/src/ui/control/geolocate_control.test.ts +5 -5
  237. package/src/ui/control/geolocate_control.ts +181 -194
  238. package/src/ui/control/logo_control.ts +20 -16
  239. package/src/ui/control/navigation_control.test.ts +1 -1
  240. package/src/ui/control/navigation_control.ts +46 -42
  241. package/src/ui/control/scale_control.test.ts +1 -1
  242. package/src/ui/control/scale_control.ts +30 -21
  243. package/src/ui/control/terrain_control.test.ts +1 -1
  244. package/src/ui/control/terrain_control.ts +14 -18
  245. package/src/ui/default_locale.ts +1 -3
  246. package/src/ui/events.ts +570 -1281
  247. package/src/ui/handler/box_zoom.test.ts +2 -2
  248. package/src/ui/handler/box_zoom.ts +16 -11
  249. package/src/ui/handler/click_zoom.ts +11 -3
  250. package/src/ui/handler/cooperative_gestures.test.ts +3 -3
  251. package/src/ui/handler/dblclick_zoom.test.ts +1 -1
  252. package/src/ui/handler/drag_handler.ts +30 -22
  253. package/src/ui/handler/drag_move_state_manager.ts +1 -1
  254. package/src/ui/handler/drag_pan.test.ts +2 -2
  255. package/src/ui/handler/drag_rotate.test.ts +3 -3
  256. package/src/ui/handler/keyboard.test.ts +2 -2
  257. package/src/ui/handler/keyboard.ts +22 -13
  258. package/src/ui/handler/map_event.test.ts +2 -2
  259. package/src/ui/handler/map_event.ts +1 -1
  260. package/src/ui/handler/mouse.ts +1 -1
  261. package/src/ui/handler/mouse_rotate.test.ts +3 -3
  262. package/src/ui/handler/scroll_zoom.test.ts +3 -3
  263. package/src/ui/handler/scroll_zoom.ts +45 -52
  264. package/src/ui/handler/shim/dblclick_zoom.ts +12 -6
  265. package/src/ui/handler/shim/drag_pan.ts +34 -14
  266. package/src/ui/handler/shim/drag_rotate.ts +20 -12
  267. package/src/ui/handler/shim/two_fingers_touch.ts +24 -18
  268. package/src/ui/handler/tap_drag_zoom.test.ts +113 -0
  269. package/src/ui/handler/tap_drag_zoom.ts +18 -10
  270. package/src/ui/handler/tap_recognizer.ts +1 -1
  271. package/src/ui/handler/tap_zoom.ts +4 -3
  272. package/src/ui/handler/touch_pan.ts +3 -2
  273. package/src/ui/handler/transform-provider.ts +4 -6
  274. package/src/ui/handler/two_fingers_touch.test.ts +3 -3
  275. package/src/ui/handler/two_fingers_touch.ts +64 -47
  276. package/src/ui/handler_inertia.ts +4 -4
  277. package/src/ui/handler_manager.ts +86 -52
  278. package/src/ui/hash.test.ts +1 -1
  279. package/src/ui/hash.ts +21 -28
  280. package/src/ui/map/isMoving.test.ts +3 -3
  281. package/src/ui/map/isRotating.test.ts +3 -3
  282. package/src/ui/map/isZooming.test.ts +3 -3
  283. package/src/ui/map.test.ts +97 -8
  284. package/src/ui/map.ts +856 -702
  285. package/src/ui/map_events.test.ts +1 -1
  286. package/src/ui/marker.test.ts +35 -15
  287. package/src/ui/marker.ts +220 -141
  288. package/src/ui/popup.test.ts +2 -2
  289. package/src/ui/popup.ts +179 -147
  290. package/src/util/actor.test.ts +7 -7
  291. package/src/util/actor.ts +25 -22
  292. package/src/util/ajax.ts +37 -17
  293. package/src/util/browser.test.ts +1 -1
  294. package/src/util/browser.ts +2 -6
  295. package/src/util/classify_rings.test.ts +1 -1
  296. package/src/util/classify_rings.ts +1 -1
  297. package/src/util/color_ramp.ts +0 -2
  298. package/src/util/config.ts +6 -3
  299. package/src/util/debug.ts +0 -2
  300. package/src/util/dictionary_coder.ts +1 -4
  301. package/src/util/dispatcher.test.ts +3 -3
  302. package/src/util/dispatcher.ts +4 -9
  303. package/src/util/dom.ts +1 -1
  304. package/src/util/evented.ts +23 -18
  305. package/src/util/find_pole_of_inaccessibility.test.ts +1 -1
  306. package/src/util/find_pole_of_inaccessibility.ts +4 -5
  307. package/src/util/global_worker_pool.ts +2 -3
  308. package/src/util/image.ts +10 -4
  309. package/src/util/image_request.test.ts +3 -3
  310. package/src/util/image_request.ts +15 -14
  311. package/src/util/is_char_in_unicode_block.ts +1 -3
  312. package/src/util/offscreen_canvas_supported.ts +1 -1
  313. package/src/util/performance.ts +1 -2
  314. package/src/util/request_manager.ts +4 -0
  315. package/src/util/resolve_tokens.test.ts +1 -1
  316. package/src/util/resolve_tokens.ts +3 -6
  317. package/src/util/script_detection.ts +1 -4
  318. package/src/util/smart_wrap.ts +3 -5
  319. package/src/util/struct_array.ts +18 -14
  320. package/src/util/style.ts +2 -2
  321. package/src/util/task_queue.test.ts +1 -1
  322. package/src/util/task_queue.ts +1 -3
  323. package/src/util/test/mock_webgl.ts +6 -0
  324. package/src/util/test/util.ts +2 -2
  325. package/src/util/throttle.test.ts +1 -1
  326. package/src/util/throttle.ts +1 -2
  327. package/src/util/throttled_invoker.ts +1 -5
  328. package/src/util/transferable_grid_index.test.ts +1 -1
  329. package/src/util/transferable_grid_index.ts +1 -3
  330. package/src/util/util.test.ts +1 -14
  331. package/src/util/util.ts +44 -107
  332. package/src/util/vectortile_to_geojson.ts +13 -3
  333. package/src/util/verticalize_punctuation.ts +1 -1
  334. package/src/util/web_worker.ts +2 -2
  335. package/src/util/web_worker_transfer.ts +11 -8
  336. package/src/util/webp_supported.ts +2 -4
  337. package/src/util/worker_pool.test.ts +1 -1
  338. package/src/util/worker_pool.ts +4 -5
package/src/ui/popup.ts CHANGED
@@ -1,14 +1,14 @@
1
- import {extend, bindAll} from '../util/util';
1
+ import {extend} from '../util/util';
2
2
  import {Event, Evented} from '../util/evented';
3
3
  import {MapMouseEvent} from '../ui/events';
4
- import DOM from '../util/dom';
5
- import LngLat from '../geo/lng_lat';
4
+ import {DOM} from '../util/dom';
5
+ import {LngLat} from '../geo/lng_lat';
6
6
  import Point from '@mapbox/point-geometry';
7
- import smartWrap from '../util/smart_wrap';
7
+ import {smartWrap} from '../util/smart_wrap';
8
8
  import {anchorTranslate, applyAnchorClass} from './anchor';
9
9
 
10
10
  import type {PositionAnchor} from './anchor';
11
- import type Map from './map';
11
+ import type {Map} from './map';
12
12
  import type {LngLatLike} from '../geo/lng_lat';
13
13
  import type {PointLike} from './camera';
14
14
 
@@ -20,18 +20,61 @@ const defaultOptions = {
20
20
  maxWidth: '240px'
21
21
  };
22
22
 
23
+ /**
24
+ * A pixel offset specified as:
25
+ * - a single number specifying a distance from the location
26
+ * - a {@link PointLike} specifying a constant offset
27
+ * - an object of {@link Point}s specifying an offset for each anchor position
28
+ * Negative offsets indicate left and up.
29
+ */
23
30
  export type Offset = number | PointLike | {
24
31
  [_ in PositionAnchor]: PointLike;
25
32
  };
26
33
 
27
34
  export type PopupOptions = {
35
+ /**
36
+ * If `true`, a close button will appear in the top right corner of the popup.
37
+ * @defaultValue true
38
+ */
28
39
  closeButton?: boolean;
40
+ /**
41
+ * If `true`, the popup will closed when the map is clicked.
42
+ * @defaultValue true
43
+ */
29
44
  closeOnClick?: boolean;
45
+ /**
46
+ * If `true`, the popup will closed when the map moves.
47
+ * @defaultValue false
48
+ */
30
49
  closeOnMove?: boolean;
50
+ /**
51
+ * If `true`, the popup will try to focus the first focusable element inside the popup.
52
+ * @defaultValue true
53
+ */
31
54
  focusAfterOpen?: boolean;
55
+ /**
56
+ * A string indicating the part of the Popup that should
57
+ * be positioned closest to the coordinate set via {@link Popup#setLngLat}.
58
+ * Options are `'center'`, `'top'`, `'bottom'`, `'left'`, `'right'`, `'top-left'`,
59
+ * `'top-right'`, `'bottom-left'`, and `'bottom-right'`. If unset the anchor will be
60
+ * dynamically set to ensure the popup falls within the map container with a preference
61
+ * for `'bottom'`.
62
+ */
32
63
  anchor?: PositionAnchor;
64
+ /**
65
+ * A pixel offset applied to the popup's location
66
+ */
33
67
  offset?: Offset;
68
+ /**
69
+ * Space-separated CSS class names to add to popup container
70
+ */
34
71
  className?: string;
72
+ /**
73
+ * A string that sets the CSS property of the popup's maximum width, eg `'300px'`.
74
+ * To ensure the popup resizes to fit its content, set this property to `'none'`.
75
+ * Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
76
+ * @defaultValue '240px'
77
+ */
35
78
  maxWidth?: string;
36
79
  };
37
80
 
@@ -48,35 +91,35 @@ const focusQuerySelector = [
48
91
  /**
49
92
  * A popup component.
50
93
  *
51
- * @param {PopupOptions} [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 {PositionAnchor} [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 specifying 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
94
+ * @group Markers and Controls
95
+ *
96
+ *
97
+ * @example
98
+ * Create a popup
99
+ * ```ts
100
+ * let popup = new maplibregl.Popup();
101
+ * // Set an event listener that will fire
102
+ * // any time the popup is opened
103
+ * popup.on('open', function(){
104
+ * console.log('popup was opened');
105
+ * });
106
+ * ```
107
+ *
77
108
  * @example
78
- * var markerHeight = 50, markerRadius = 10, linearOffset = 25;
79
- * var popupOffsets = {
109
+ * Create a popup
110
+ * ```ts
111
+ * let popup = new maplibregl.Popup();
112
+ * // Set an event listener that will fire
113
+ * // any time the popup is closed
114
+ * popup.on('close', function(){
115
+ * console.log('popup was closed');
116
+ * });
117
+ * ```
118
+ *
119
+ * @example
120
+ * ```ts
121
+ * let markerHeight = 50, markerRadius = 10, linearOffset = 25;
122
+ * let popupOffsets = {
80
123
  * 'top': [0, 0],
81
124
  * 'top-left': [0,0],
82
125
  * 'top-right': [0,0],
@@ -86,17 +129,24 @@ const focusQuerySelector = [
86
129
  * 'left': [markerRadius, (markerHeight - markerRadius) * -1],
87
130
  * 'right': [-markerRadius, (markerHeight - markerRadius) * -1]
88
131
  * };
89
- * var popup = new maplibregl.Popup({offset: popupOffsets, className: 'my-class'})
132
+ * let popup = new maplibregl.Popup({offset: popupOffsets, className: 'my-class'})
90
133
  * .setLngLat(e.lngLat)
91
134
  * .setHTML("<h1>Hello World!</h1>")
92
135
  * .setMaxWidth("300px")
93
136
  * .addTo(map);
94
- * @see [Display a popup](https://maplibre.org/maplibre-gl-js-docs/example/popup/)
95
- * @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js-docs/example/popup-on-hover/)
96
- * @see [Display a popup on click](https://maplibre.org/maplibre-gl-js-docs/example/popup-on-click/)
97
- * @see [Attach a popup to a marker instance](https://maplibre.org/maplibre-gl-js-docs/example/set-popup/)
137
+ * ```
138
+ * @see [Display a popup](https://maplibre.org/maplibre-gl-js/docs/examples/popup/)
139
+ * @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
140
+ * @see [Display a popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
141
+ * @see [Attach a popup to a marker instance](https://maplibre.org/maplibre-gl-js/docs/examples/set-popup/)
142
+ *
143
+ * ### Events
144
+ *
145
+ * @event `open` Fired when the popup is opened manually or programmatically. `popup` object that was opened
146
+ *
147
+ * @event `close` Fired when the popup is closed manually or programmatically. `popup` object that was closed
98
148
  */
99
- export default class Popup extends Evented {
149
+ export class Popup extends Evented {
100
150
  _map: Map;
101
151
  options: PopupOptions;
102
152
  _content: HTMLElement;
@@ -110,25 +160,26 @@ export default class Popup extends Evented {
110
160
  constructor(options?: PopupOptions) {
111
161
  super();
112
162
  this.options = extend(Object.create(defaultOptions), options);
113
- bindAll(['_update', '_onClose', 'remove', '_onMouseMove', '_onMouseUp', '_onDrag'], this);
114
163
  }
115
164
 
116
165
  /**
117
166
  * Adds the popup to a map.
118
167
  *
119
- * @param {Map} map The MapLibre GL JS map to add the popup to.
120
- * @returns {Popup} `this`
168
+ * @param map - The MapLibre GL JS map to add the popup to.
169
+ * @returns `this`
121
170
  * @example
171
+ * ```ts
122
172
  * new maplibregl.Popup()
123
173
  * .setLngLat([0, 0])
124
174
  * .setHTML("<h1>Null Island</h1>")
125
175
  * .addTo(map);
126
- * @see [Display a popup](https://maplibre.org/maplibre-gl-js-docs/example/popup/)
127
- * @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js-docs/example/popup-on-hover/)
128
- * @see [Display a popup on click](https://maplibre.org/maplibre-gl-js-docs/example/popup-on-click/)
129
- * @see [Show polygon information on click](https://maplibre.org/maplibre-gl-js-docs/example/polygon-popup-on-click/)
176
+ * ```
177
+ * @see [Display a popup](https://maplibre.org/maplibre-gl-js/docs/examples/popup/)
178
+ * @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
179
+ * @see [Display a popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
180
+ * @see [Show polygon information on click](https://maplibre.org/maplibre-gl-js/docs/examples/polygon-popup-on-click/)
130
181
  */
131
- addTo(map: Map) {
182
+ addTo(map: Map): this {
132
183
  if (this._map) this.remove();
133
184
 
134
185
  this._map = map;
@@ -155,32 +206,13 @@ export default class Popup extends Evented {
155
206
  this._map.on('move', this._update);
156
207
  }
157
208
 
158
- /**
159
- * Fired when the popup is opened manually or programmatically.
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 maplibregl.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
209
  this.fire(new Event('open'));
178
210
 
179
211
  return this;
180
212
  }
181
213
 
182
214
  /**
183
- * @returns {boolean} `true` if the popup is open, `false` if it is closed.
215
+ * @returns `true` if the popup is open, `false` if it is closed.
184
216
  */
185
217
  isOpen() {
186
218
  return !!this._map;
@@ -190,11 +222,13 @@ export default class Popup extends Evented {
190
222
  * Removes the popup from the map it has been added to.
191
223
  *
192
224
  * @example
193
- * var popup = new maplibregl.Popup().addTo(map);
225
+ * ```ts
226
+ * let popup = new maplibregl.Popup().addTo(map);
194
227
  * popup.remove();
195
- * @returns {Popup} `this`
228
+ * ```
229
+ * @returns `this`
196
230
  */
197
- remove() {
231
+ remove = (): this => {
198
232
  if (this._content) {
199
233
  DOM.remove(this._content);
200
234
  }
@@ -215,29 +249,10 @@ export default class Popup extends Evented {
215
249
  delete this._map;
216
250
  }
217
251
 
218
- /**
219
- * Fired when the popup is closed manually or programmatically.
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 maplibregl.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
252
  this.fire(new Event('close'));
238
253
 
239
254
  return this;
240
- }
255
+ };
241
256
 
242
257
  /**
243
258
  * Returns the geographical location of the popup's anchor.
@@ -246,19 +261,19 @@ export default class Popup extends Evented {
246
261
  * set by `setLngLat` because `Popup` wraps the anchor longitude across copies of the world to keep
247
262
  * the popup on screen.
248
263
  *
249
- * @returns {LngLat} The geographical location of the popup's anchor.
264
+ * @returns The geographical location of the popup's anchor.
250
265
  */
251
- getLngLat() {
266
+ getLngLat(): LngLat {
252
267
  return this._lngLat;
253
268
  }
254
269
 
255
270
  /**
256
271
  * Sets the geographical location of the popup's anchor, and moves the popup to it. Replaces trackPointer() behavior.
257
272
  *
258
- * @param lnglat The geographical location to set as the popup's anchor.
259
- * @returns {Popup} `this`
273
+ * @param lnglat - The geographical location to set as the popup's anchor.
274
+ * @returns `this`
260
275
  */
261
- setLngLat(lnglat: LngLatLike) {
276
+ setLngLat(lnglat: LngLatLike): this {
262
277
  this._lngLat = LngLat.convert(lnglat);
263
278
  this._pos = null;
264
279
 
@@ -282,13 +297,15 @@ export default class Popup extends Evented {
282
297
  * 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
298
  * For most use cases, set `closeOnClick` and `closeButton` to `false`.
284
299
  * @example
285
- * var popup = new maplibregl.Popup({ closeOnClick: false, closeButton: false })
300
+ * ```ts
301
+ * let popup = new maplibregl.Popup({ closeOnClick: false, closeButton: false })
286
302
  * .setHTML("<h1>Hello World!</h1>")
287
303
  * .trackPointer()
288
304
  * .addTo(map);
289
- * @returns {Popup} `this`
305
+ * ```
306
+ * @returns `this`
290
307
  */
291
- trackPointer() {
308
+ trackPointer(): this {
292
309
  this._trackPointer = true;
293
310
  this._pos = null;
294
311
  this._update();
@@ -309,16 +326,18 @@ export default class Popup extends Evented {
309
326
  /**
310
327
  * Returns the `Popup`'s HTML element.
311
328
  * @example
312
- * // Change the `Popup` element's font size
313
- * var popup = new maplibregl.Popup()
329
+ * Change the `Popup` element's font size
330
+ * ```ts
331
+ * let popup = new maplibregl.Popup()
314
332
  * .setLngLat([-96, 37.8])
315
333
  * .setHTML("<p>Hello World!</p>")
316
334
  * .addTo(map);
317
- * var popupElem = popup.getElement();
335
+ * let popupElem = popup.getElement();
318
336
  * popupElem.style.fontSize = "25px";
319
- * @returns {HTMLElement} element
337
+ * ```
338
+ * @returns element
320
339
  */
321
- getElement() {
340
+ getElement(): HTMLElement {
322
341
  return this._container;
323
342
  }
324
343
 
@@ -329,15 +348,17 @@ export default class Popup extends Evented {
329
348
  * so it cannot insert raw HTML. Use this method for security against XSS
330
349
  * if the popup content is user-provided.
331
350
  *
332
- * @param text Textual content for the popup.
333
- * @returns {Popup} `this`
351
+ * @param text - Textual content for the popup.
352
+ * @returns `this`
334
353
  * @example
335
- * var popup = new maplibregl.Popup()
354
+ * ```ts
355
+ * let popup = new maplibregl.Popup()
336
356
  * .setLngLat(e.lngLat)
337
357
  * .setText('Hello, world!')
338
358
  * .addTo(map);
359
+ * ```
339
360
  */
340
- setText(text: string) {
361
+ setText(text: string): this {
341
362
  return this.setDOMContent(document.createTextNode(text));
342
363
  }
343
364
 
@@ -348,19 +369,21 @@ export default class Popup extends Evented {
348
369
  * used only with trusted content. Consider {@link Popup#setText} if
349
370
  * the content is an untrusted text string.
350
371
  *
351
- * @param html A string representing HTML content for the popup.
352
- * @returns {Popup} `this`
372
+ * @param html - A string representing HTML content for the popup.
373
+ * @returns `this`
353
374
  * @example
354
- * var popup = new maplibregl.Popup()
375
+ * ```ts
376
+ * let popup = new maplibregl.Popup()
355
377
  * .setLngLat(e.lngLat)
356
378
  * .setHTML("<h1>Hello World!</h1>")
357
379
  * .addTo(map);
358
- * @see [Display a popup](https://maplibre.org/maplibre-gl-js-docs/example/popup/)
359
- * @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js-docs/example/popup-on-hover/)
360
- * @see [Display a popup on click](https://maplibre.org/maplibre-gl-js-docs/example/popup-on-click/)
361
- * @see [Attach a popup to a marker instance](https://maplibre.org/maplibre-gl-js-docs/example/set-popup/)
380
+ * ```
381
+ * @see [Display a popup](https://maplibre.org/maplibre-gl-js/docs/examples/popup/)
382
+ * @see [Display a popup on hover](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-hover/)
383
+ * @see [Display a popup on click](https://maplibre.org/maplibre-gl-js/docs/examples/popup-on-click/)
384
+ * @see [Attach a popup to a marker instance](https://maplibre.org/maplibre-gl-js/docs/examples/set-popup/)
362
385
  */
363
- setHTML(html: string) {
386
+ setHTML(html: string): this {
364
387
  const frag = document.createDocumentFragment();
365
388
  const temp = document.createElement('body');
366
389
  let child;
@@ -377,20 +400,20 @@ export default class Popup extends Evented {
377
400
  /**
378
401
  * Returns the popup's maximum width.
379
402
  *
380
- * @returns {string} The maximum width of the popup.
403
+ * @returns The maximum width of the popup.
381
404
  */
382
- getMaxWidth() {
383
- return this._container && this._container.style.maxWidth;
405
+ getMaxWidth(): string {
406
+ return this._container?.style.maxWidth;
384
407
  }
385
408
 
386
409
  /**
387
410
  * Sets the popup's maximum width. This is setting the CSS property `max-width`.
388
411
  * Available values can be found here: https://developer.mozilla.org/en-US/docs/Web/CSS/max-width
389
412
  *
390
- * @param maxWidth A string representing the value for the maximum width.
391
- * @returns {Popup} `this`
413
+ * @param maxWidth - A string representing the value for the maximum width.
414
+ * @returns `this`
392
415
  */
393
- setMaxWidth(maxWidth: string) {
416
+ setMaxWidth(maxWidth: string): this {
394
417
  this.options.maxWidth = maxWidth;
395
418
  this._update();
396
419
  return this;
@@ -399,18 +422,20 @@ export default class Popup extends Evented {
399
422
  /**
400
423
  * Sets the popup's content to the element provided as a DOM node.
401
424
  *
402
- * @param htmlNode A DOM node to be used as content for the popup.
403
- * @returns {Popup} `this`
425
+ * @param htmlNode - A DOM node to be used as content for the popup.
426
+ * @returns `this`
404
427
  * @example
405
- * // create an element with the popup content
406
- * var div = document.createElement('div');
428
+ * Create an element with the popup content
429
+ * ```ts
430
+ * let div = document.createElement('div');
407
431
  * div.innerHTML = 'Hello, world!';
408
- * var popup = new maplibregl.Popup()
432
+ * let popup = new maplibregl.Popup()
409
433
  * .setLngLat(e.lngLat)
410
434
  * .setDOMContent(div)
411
435
  * .addTo(map);
436
+ * ```
412
437
  */
413
- setDOMContent(htmlNode: Node) {
438
+ setDOMContent(htmlNode: Node): this {
414
439
  if (this._content) {
415
440
  // Clear out children first.
416
441
  while (this._content.hasChildNodes()) {
@@ -433,11 +458,13 @@ export default class Popup extends Evented {
433
458
  /**
434
459
  * Adds a CSS class to the popup container element.
435
460
  *
436
- * @param {string} className Non-empty string with CSS class name to add to popup container
461
+ * @param className - Non-empty string with CSS class name to add to popup container
437
462
  *
438
463
  * @example
464
+ * ```ts
439
465
  * let popup = new maplibregl.Popup()
440
466
  * popup.addClassName('some-class')
467
+ * ```
441
468
  */
442
469
  addClassName(className: string) {
443
470
  if (this._container) {
@@ -448,11 +475,13 @@ export default class Popup extends Evented {
448
475
  /**
449
476
  * Removes a CSS class from the popup container element.
450
477
  *
451
- * @param {string} className Non-empty string with CSS class name to remove from popup container
478
+ * @param className - Non-empty string with CSS class name to remove from popup container
452
479
  *
453
480
  * @example
481
+ * ```ts
454
482
  * let popup = new maplibregl.Popup()
455
483
  * popup.removeClassName('some-class')
484
+ * ```
456
485
  */
457
486
  removeClassName(className: string) {
458
487
  if (this._container) {
@@ -463,10 +492,10 @@ export default class Popup extends Evented {
463
492
  /**
464
493
  * Sets the popup's offset.
465
494
  *
466
- * @param offset Sets the popup's offset.
467
- * @returns {Popup} `this`
495
+ * @param offset - Sets the popup's offset.
496
+ * @returns `this`
468
497
  */
469
- setOffset (offset?: Offset) {
498
+ setOffset (offset?: Offset): this {
470
499
  this.options.offset = offset;
471
500
  this._update();
472
501
  return this;
@@ -475,15 +504,17 @@ export default class Popup extends Evented {
475
504
  /**
476
505
  * Add or remove the given CSS class on the popup container, depending on whether the container currently has that class.
477
506
  *
478
- * @param {string} className Non-empty string with CSS class name to add/remove
507
+ * @param className - Non-empty string with CSS class name to add/remove
479
508
  *
480
- * @returns {boolean} if the class was removed return false, if class was added, then return true
509
+ * @returns if the class was removed return false, if class was added, then return true, undefined if there is no container
481
510
  *
482
511
  * @example
512
+ * ```ts
483
513
  * let popup = new maplibregl.Popup()
484
514
  * popup.toggleClassName('toggleClass')
515
+ * ```
485
516
  */
486
- toggleClassName(className: string) {
517
+ toggleClassName(className: string): boolean | undefined {
487
518
  if (this._container) {
488
519
  return this._container.classList.toggle(className);
489
520
  }
@@ -499,19 +530,19 @@ export default class Popup extends Evented {
499
530
  }
500
531
  }
501
532
 
502
- _onMouseUp(event: MapMouseEvent) {
533
+ _onMouseUp = (event: MapMouseEvent) => {
503
534
  this._update(event.point);
504
- }
535
+ };
505
536
 
506
- _onMouseMove(event: MapMouseEvent) {
537
+ _onMouseMove = (event: MapMouseEvent) => {
507
538
  this._update(event.point);
508
- }
539
+ };
509
540
 
510
- _onDrag(event: MapMouseEvent) {
541
+ _onDrag = (event: MapMouseEvent) => {
511
542
  this._update(event.point);
512
- }
543
+ };
513
544
 
514
- _update(cursor?: Point) {
545
+ _update = (cursor?: Point) => {
515
546
  const hasPosition = this._lngLat || this._trackPointer;
516
547
 
517
548
  if (!this._map || !hasPosition || !this._content) { return; }
@@ -521,8 +552,9 @@ export default class Popup extends Evented {
521
552
  this._tip = DOM.create('div', 'maplibregl-popup-tip', this._container);
522
553
  this._container.appendChild(this._content);
523
554
  if (this.options.className) {
524
- this.options.className.split(' ').forEach(name =>
525
- this._container.classList.add(name));
555
+ for (const name of this.options.className.split(' ')) {
556
+ this._container.classList.add(name);
557
+ }
526
558
  }
527
559
 
528
560
  if (this._trackPointer) {
@@ -574,7 +606,7 @@ export default class Popup extends Evented {
574
606
  const offsetedPos = pos.add(offset[anchor]).round();
575
607
  DOM.setTransform(this._container, `${anchorTranslate[anchor]} translate(${offsetedPos.x}px,${offsetedPos.y}px)`);
576
608
  applyAnchorClass(this._container, anchor, 'popup');
577
- }
609
+ };
578
610
 
579
611
  _focusFirstElement() {
580
612
  if (!this.options.focusAfterOpen || !this._container) return;
@@ -584,9 +616,9 @@ export default class Popup extends Evented {
584
616
  if (firstFocusable) firstFocusable.focus();
585
617
  }
586
618
 
587
- _onClose() {
619
+ _onClose = () => {
588
620
  this.remove();
589
- }
621
+ };
590
622
  }
591
623
 
592
624
  function normalizeOffset(offset?: Offset | null) {
@@ -1,5 +1,5 @@
1
- import Actor from './actor';
2
- import workerFactory from './web_worker';
1
+ import {Actor} from './actor';
2
+ import {workerFactory} from './web_worker';
3
3
  import {MessageBus} from '../../test/unit/lib/web_worker_mock';
4
4
 
5
5
  const originalWorker = global.Worker;
@@ -40,8 +40,8 @@ describe('Actor', () => {
40
40
 
41
41
  const worker = workerFactory();
42
42
 
43
- const m1 = new Actor(worker, {}, 1);
44
- const m2 = new Actor(worker, {}, 2);
43
+ const m1 = new Actor(worker, {}, '1');
44
+ const m2 = new Actor(worker, {}, '2');
45
45
 
46
46
  let callbackCount = 0;
47
47
  m1.send('test', {value: 1729}, (err, response) => {
@@ -78,14 +78,14 @@ describe('Actor', () => {
78
78
 
79
79
  new Actor(worker, {
80
80
  test () { done(); }
81
- }, 1);
81
+ }, '1');
82
82
  new Actor(worker, {
83
83
  test () {
84
84
  done('test failed');
85
85
  }
86
- }, 2);
86
+ }, '2');
87
87
 
88
- workerActor.send('test', {}, () => {}, 1);
88
+ workerActor.send('test', {}, () => {}, '1');
89
89
  });
90
90
 
91
91
  test('#remove unbinds event listener', done => {