maplibre-gl 2.0.4 → 2.1.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 (319) hide show
  1. package/build/{banner.js → banner.ts} +1 -1
  2. package/build/generate-query-test-fixtures.ts +123 -0
  3. package/build/generate-shaders.ts +35 -0
  4. package/build/generate-struct-arrays.ts +7 -7
  5. package/build/generate-style-code.ts +8 -8
  6. package/build/generate-style-spec.ts +5 -4
  7. package/build/generate-typings.ts +16 -0
  8. package/build/readme.md +8 -18
  9. package/build/release-notes.js +9 -13
  10. package/build/{rollup_plugin_minify_style_spec.js → rollup_plugin_minify_style_spec.ts} +4 -3
  11. package/build/{rollup_plugins.js → rollup_plugins.ts} +12 -26
  12. package/dist/maplibre-gl-dev.js +54885 -0
  13. package/dist/maplibre-gl.css +1 -1
  14. package/dist/maplibre-gl.d.ts +1583 -1023
  15. package/dist/maplibre-gl.js +3 -3
  16. package/dist/maplibre-gl.js.map +1 -1
  17. package/package.json +99 -141
  18. package/src/css/maplibre-gl.css +36 -36
  19. package/src/data/{array_types.ts → array_types.g.ts} +0 -0
  20. package/src/data/bucket/circle_bucket.ts +1 -1
  21. package/src/data/bucket/fill_bucket.test.ts +1 -1
  22. package/src/data/bucket/fill_bucket.ts +4 -4
  23. package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
  24. package/src/data/bucket/line_bucket.test.ts +1 -1
  25. package/src/data/bucket/line_bucket.ts +6 -6
  26. package/src/data/bucket/symbol_bucket.test.ts +16 -16
  27. package/src/data/bucket/symbol_bucket.ts +56 -56
  28. package/src/data/bucket.ts +43 -43
  29. package/src/data/dem_data.ts +12 -12
  30. package/src/data/evaluation_feature.ts +10 -10
  31. package/src/data/feature_index.ts +37 -37
  32. package/src/data/feature_position_map.ts +5 -5
  33. package/src/data/index_array_type.ts +1 -1
  34. package/src/data/load_geometry.test.ts +1 -1
  35. package/src/data/program_configuration.ts +47 -47
  36. package/src/data/segment.ts +14 -14
  37. package/src/geo/edge_insets.ts +2 -2
  38. package/src/geo/lng_lat.ts +4 -4
  39. package/src/geo/lng_lat_bounds.ts +35 -35
  40. package/src/geo/mercator_coordinate.ts +5 -5
  41. package/src/geo/transform.test.ts +1 -1
  42. package/src/geo/transform.ts +14 -14
  43. package/src/gl/context.ts +3 -3
  44. package/src/gl/types.ts +19 -19
  45. package/src/gl/value.ts +6 -6
  46. package/src/gl/vertex_buffer.test.ts +1 -1
  47. package/src/index.ts +24 -9
  48. package/src/render/draw_circle.ts +8 -8
  49. package/src/render/draw_collision_debug.ts +5 -5
  50. package/src/render/draw_debug.ts +1 -1
  51. package/src/render/draw_line.ts +4 -4
  52. package/src/render/draw_symbol.ts +21 -21
  53. package/src/render/glyph_atlas.ts +12 -12
  54. package/src/render/glyph_manager.test.ts +10 -21
  55. package/src/render/glyph_manager.ts +34 -33
  56. package/src/render/image_manager.ts +4 -4
  57. package/src/render/painter.ts +16 -14
  58. package/src/render/program/background_program.ts +29 -29
  59. package/src/render/program/circle_program.ts +11 -11
  60. package/src/render/program/clipping_mask_program.ts +1 -1
  61. package/src/render/program/collision_program.ts +9 -9
  62. package/src/render/program/debug_program.ts +4 -4
  63. package/src/render/program/fill_extrusion_program.ts +31 -31
  64. package/src/render/program/fill_program.ts +29 -29
  65. package/src/render/program/heatmap_program.ts +12 -12
  66. package/src/render/program/hillshade_program.ts +12 -12
  67. package/src/render/program/line_program.ts +41 -41
  68. package/src/render/program/pattern.ts +28 -28
  69. package/src/render/program/raster_program.ts +21 -21
  70. package/src/render/program/symbol_program.ts +97 -97
  71. package/src/render/program.ts +25 -25
  72. package/src/render/texture.ts +9 -9
  73. package/src/render/uniform_binding.ts +1 -1
  74. package/src/render/vertex_array_object.ts +13 -13
  75. package/src/shaders/_prelude.fragment.glsl.g.ts +2 -0
  76. package/src/shaders/_prelude.vertex.glsl.g.ts +2 -0
  77. package/src/shaders/background.fragment.glsl.g.ts +2 -0
  78. package/src/shaders/background.vertex.glsl.g.ts +2 -0
  79. package/src/shaders/background_pattern.fragment.glsl.g.ts +2 -0
  80. package/src/shaders/background_pattern.vertex.glsl.g.ts +2 -0
  81. package/src/shaders/circle.fragment.glsl.g.ts +2 -0
  82. package/src/shaders/circle.vertex.glsl.g.ts +2 -0
  83. package/src/shaders/clipping_mask.fragment.glsl.g.ts +2 -0
  84. package/src/shaders/clipping_mask.vertex.glsl.g.ts +2 -0
  85. package/src/shaders/collision_box.fragment.glsl.g.ts +2 -0
  86. package/src/shaders/collision_box.vertex.glsl.g.ts +2 -0
  87. package/src/shaders/collision_circle.fragment.glsl.g.ts +2 -0
  88. package/src/shaders/collision_circle.vertex.glsl.g.ts +2 -0
  89. package/src/shaders/debug.fragment.glsl.g.ts +2 -0
  90. package/src/shaders/debug.vertex.glsl.g.ts +2 -0
  91. package/src/shaders/fill.fragment.glsl.g.ts +2 -0
  92. package/src/shaders/fill.vertex.glsl.g.ts +2 -0
  93. package/src/shaders/fill_extrusion.fragment.glsl.g.ts +2 -0
  94. package/src/shaders/fill_extrusion.vertex.glsl.g.ts +2 -0
  95. package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +2 -0
  96. package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +2 -0
  97. package/src/shaders/fill_outline.fragment.glsl.g.ts +2 -0
  98. package/src/shaders/fill_outline.vertex.glsl.g.ts +2 -0
  99. package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +2 -0
  100. package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +2 -0
  101. package/src/shaders/fill_pattern.fragment.glsl.g.ts +2 -0
  102. package/src/shaders/fill_pattern.vertex.glsl.g.ts +2 -0
  103. package/src/shaders/heatmap.fragment.glsl.g.ts +2 -0
  104. package/src/shaders/heatmap.vertex.glsl.g.ts +2 -0
  105. package/src/shaders/heatmap_texture.fragment.glsl.g.ts +2 -0
  106. package/src/shaders/heatmap_texture.vertex.glsl.g.ts +2 -0
  107. package/src/shaders/hillshade.fragment.glsl.g.ts +2 -0
  108. package/src/shaders/hillshade.vertex.glsl.g.ts +2 -0
  109. package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +2 -0
  110. package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +2 -0
  111. package/src/shaders/line.fragment.glsl.g.ts +2 -0
  112. package/src/shaders/line.vertex.glsl.g.ts +2 -0
  113. package/src/shaders/line_gradient.fragment.glsl.g.ts +2 -0
  114. package/src/shaders/line_gradient.vertex.glsl.g.ts +2 -0
  115. package/src/shaders/line_pattern.fragment.glsl.g.ts +2 -0
  116. package/src/shaders/line_pattern.vertex.glsl.g.ts +2 -0
  117. package/src/shaders/line_sdf.fragment.glsl.g.ts +2 -0
  118. package/src/shaders/line_sdf.vertex.glsl.g.ts +2 -0
  119. package/src/shaders/raster.fragment.glsl.g.ts +2 -0
  120. package/src/shaders/raster.vertex.glsl.g.ts +2 -0
  121. package/src/shaders/shaders.ts +52 -55
  122. package/src/shaders/symbol_icon.fragment.glsl.g.ts +2 -0
  123. package/src/shaders/symbol_icon.vertex.glsl.g.ts +2 -0
  124. package/src/shaders/symbol_sdf.fragment.glsl.g.ts +2 -0
  125. package/src/shaders/symbol_sdf.vertex.glsl.g.ts +2 -0
  126. package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +2 -0
  127. package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +2 -0
  128. package/src/source/canvas_source.test.ts +11 -12
  129. package/src/source/canvas_source.ts +4 -4
  130. package/src/source/geojson_source.test.ts +2 -1
  131. package/src/source/geojson_source.ts +1 -1
  132. package/src/source/geojson_worker_source.ts +23 -23
  133. package/src/source/geojson_wrapper.ts +8 -8
  134. package/src/source/image_source.test.ts +153 -0
  135. package/src/source/image_source.ts +6 -6
  136. package/src/source/pixels_to_tile_units.ts +6 -6
  137. package/src/source/query_features.ts +20 -20
  138. package/src/source/raster_dem_tile_source.test.ts +4 -3
  139. package/src/source/raster_dem_tile_source.ts +1 -1
  140. package/src/source/raster_tile_source.test.ts +4 -3
  141. package/src/source/raster_tile_source.ts +1 -1
  142. package/src/source/rtl_text_plugin.ts +10 -10
  143. package/src/source/source.ts +29 -29
  144. package/src/source/source_cache.test.ts +33 -1
  145. package/src/source/source_cache.ts +7 -5
  146. package/src/source/source_state.ts +1 -1
  147. package/src/source/tile.test.ts +3 -3
  148. package/src/source/tile.ts +15 -15
  149. package/src/source/tile_cache.test.ts +6 -4
  150. package/src/source/tile_cache.ts +6 -6
  151. package/src/source/tile_id.test.ts +10 -13
  152. package/src/source/tile_id.ts +2 -2
  153. package/src/source/vector_tile_source.test.ts +17 -5
  154. package/src/source/vector_tile_source.ts +4 -5
  155. package/src/source/vector_tile_worker_source.test.ts +4 -4
  156. package/src/source/vector_tile_worker_source.ts +5 -5
  157. package/src/source/worker.test.ts +1 -1
  158. package/src/source/worker.ts +22 -22
  159. package/src/source/worker_source.ts +56 -56
  160. package/src/source/worker_tile.ts +4 -4
  161. package/src/style/evaluation_parameters.ts +3 -3
  162. package/src/style/format_section_override.test.ts +1 -1
  163. package/src/style/light.ts +10 -10
  164. package/src/style/load_glyph_range.test.ts +3 -5
  165. package/src/style/load_glyph_range.ts +6 -6
  166. package/src/style/load_sprite.ts +5 -4
  167. package/src/style/pauseable_placement.ts +1 -1
  168. package/src/style/properties.ts +70 -70
  169. package/src/style/query_utils.ts +7 -7
  170. package/src/style/style.test.ts +26 -15
  171. package/src/style/style.ts +30 -30
  172. package/src/style/style_glyph.ts +8 -8
  173. package/src/style/style_image.ts +58 -58
  174. package/src/style/style_layer/background_style_layer.ts +2 -2
  175. package/src/style/style_layer/{background_style_layer_properties.ts → background_style_layer_properties.g.ts} +0 -0
  176. package/src/style/style_layer/circle_style_layer.ts +10 -10
  177. package/src/style/style_layer/{circle_style_layer_properties.ts → circle_style_layer_properties.g.ts} +0 -0
  178. package/src/style/style_layer/custom_style_layer.ts +19 -19
  179. package/src/style/style_layer/fill_extrusion_style_layer.ts +11 -11
  180. package/src/style/style_layer/{fill_extrusion_style_layer_properties.ts → fill_extrusion_style_layer_properties.g.ts} +0 -0
  181. package/src/style/style_layer/fill_style_layer.ts +9 -9
  182. package/src/style/style_layer/{fill_style_layer_properties.ts → fill_style_layer_properties.g.ts} +0 -0
  183. package/src/style/style_layer/heatmap_style_layer.ts +2 -2
  184. package/src/style/style_layer/{heatmap_style_layer_properties.ts → heatmap_style_layer_properties.g.ts} +0 -0
  185. package/src/style/style_layer/hillshade_style_layer.ts +2 -2
  186. package/src/style/style_layer/{hillshade_style_layer_properties.ts → hillshade_style_layer_properties.g.ts} +0 -0
  187. package/src/style/style_layer/line_style_layer.ts +9 -9
  188. package/src/style/style_layer/{line_style_layer_properties.ts → line_style_layer_properties.g.ts} +0 -0
  189. package/src/style/style_layer/raster_style_layer.ts +2 -2
  190. package/src/style/style_layer/{raster_style_layer_properties.ts → raster_style_layer_properties.g.ts} +0 -0
  191. package/src/style/style_layer/symbol_style_layer.ts +26 -7
  192. package/src/style/style_layer/{symbol_style_layer_properties.ts → symbol_style_layer_properties.g.ts} +6 -0
  193. package/src/style/style_layer.ts +10 -10
  194. package/src/style/style_layer_index.ts +3 -3
  195. package/src/style/validate_style.ts +15 -15
  196. package/src/style-spec/CHANGELOG.md +6 -0
  197. package/src/style-spec/error/validation_error.ts +1 -1
  198. package/src/style-spec/expression/compound_expression.ts +3 -3
  199. package/src/style-spec/expression/definitions/format.ts +11 -11
  200. package/src/style-spec/expression/definitions/interpolate.ts +5 -5
  201. package/src/style-spec/expression/definitions/match.ts +2 -2
  202. package/src/style-spec/expression/definitions/number_format.ts +11 -11
  203. package/src/style-spec/expression/expression.ts +8 -8
  204. package/src/style-spec/expression/index.ts +97 -97
  205. package/src/style-spec/expression/parsing_context.ts +11 -11
  206. package/src/style-spec/expression/types/collator.ts +9 -9
  207. package/src/style-spec/expression/types/resolved_image.ts +2 -2
  208. package/src/style-spec/expression/types.ts +14 -14
  209. package/src/style-spec/expression/values.ts +1 -1
  210. package/src/style-spec/feature_filter/index.ts +66 -66
  211. package/src/style-spec/function/convert.ts +3 -3
  212. package/src/style-spec/package.json +1 -1
  213. package/src/style-spec/reference/v8.json +68 -2
  214. package/src/style-spec/style-spec.ts +44 -44
  215. package/src/style-spec/types.ts +2 -0
  216. package/src/style-spec/util/color_spaces.ts +8 -8
  217. package/src/style-spec/util/result.ts +4 -4
  218. package/src/style-spec/validate/validate_filter.ts +58 -58
  219. package/src/style-spec/validate/validate_source.ts +63 -63
  220. package/src/style-spec/visit.ts +11 -11
  221. package/src/symbol/collision_feature.test.ts +1 -1
  222. package/src/symbol/collision_feature.ts +10 -10
  223. package/src/symbol/collision_index.ts +43 -43
  224. package/src/symbol/cross_tile_symbol_index.ts +17 -17
  225. package/src/symbol/get_anchors.ts +16 -16
  226. package/src/symbol/grid_index.test.ts +42 -19
  227. package/src/symbol/grid_index.ts +69 -40
  228. package/src/symbol/placement.ts +124 -95
  229. package/src/symbol/projection.ts +30 -30
  230. package/src/symbol/quads.ts +30 -30
  231. package/src/symbol/shaping.ts +160 -160
  232. package/src/symbol/symbol_layout.ts +119 -119
  233. package/src/symbol/symbol_size.ts +29 -29
  234. package/src/symbol/symbol_style_layer.test.ts +49 -2
  235. package/src/types/cancelable.ts +1 -1
  236. package/src/types/tilejson.ts +13 -13
  237. package/src/ui/anchor.ts +1 -1
  238. package/src/ui/camera.test.ts +9 -9
  239. package/src/ui/camera.ts +26 -18
  240. package/src/ui/control/attribution_control.test.ts +51 -16
  241. package/src/ui/control/attribution_control.ts +35 -16
  242. package/src/ui/control/control.ts +40 -40
  243. package/src/ui/control/fullscreen_control.ts +1 -1
  244. package/src/ui/control/geolocate_control.test.ts +1 -1
  245. package/src/ui/control/geolocate_control.ts +102 -102
  246. package/src/ui/control/logo_control.test.ts +5 -4
  247. package/src/ui/control/navigation_control.ts +3 -3
  248. package/src/ui/control/scale_control.test.ts +2 -2
  249. package/src/ui/control/scale_control.ts +5 -5
  250. package/src/ui/events.ts +289 -200
  251. package/src/ui/handler/box_zoom.test.ts +1 -1
  252. package/src/ui/handler/box_zoom.ts +1 -1
  253. package/src/ui/handler/dblclick_zoom.test.ts +1 -1
  254. package/src/ui/handler/drag_pan.test.ts +1 -1
  255. package/src/ui/handler/drag_rotate.test.ts +1 -1
  256. package/src/ui/handler/keyboard.test.ts +1 -1
  257. package/src/ui/handler/keyboard.ts +51 -51
  258. package/src/ui/handler/map_event.test.ts +1 -1
  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 +1 -1
  262. package/src/ui/handler/scroll_zoom.test.ts +3 -2
  263. package/src/ui/handler/scroll_zoom.ts +9 -9
  264. package/src/ui/handler/shim/drag_pan.ts +4 -4
  265. package/src/ui/handler/shim/drag_rotate.ts +1 -1
  266. package/src/ui/handler/shim/touch_zoom_rotate.ts +1 -1
  267. package/src/ui/handler/tap_recognizer.ts +4 -4
  268. package/src/ui/handler/touch_pan.ts +2 -2
  269. package/src/ui/handler/touch_zoom_rotate.test.ts +1 -1
  270. package/src/ui/handler/touch_zoom_rotate.ts +1 -1
  271. package/src/ui/handler_inertia.ts +6 -6
  272. package/src/ui/handler_manager.ts +44 -44
  273. package/src/ui/map/isMoving.test.ts +1 -1
  274. package/src/ui/map/isRotating.test.ts +1 -1
  275. package/src/ui/map/isZooming.test.ts +1 -1
  276. package/src/ui/map.test.ts +87 -14
  277. package/src/ui/map.ts +138 -108
  278. package/src/ui/map_events.test.ts +1 -1
  279. package/src/ui/marker.test.ts +12 -12
  280. package/src/ui/marker.ts +37 -37
  281. package/src/ui/popup.test.ts +7 -7
  282. package/src/ui/popup.ts +9 -9
  283. package/src/util/actor.test.ts +41 -10
  284. package/src/util/actor.ts +8 -8
  285. package/src/util/ajax.test.ts +214 -0
  286. package/src/util/ajax.ts +51 -30
  287. package/src/util/browser.ts +1 -1
  288. package/src/util/classify_rings.test.ts +1 -1
  289. package/src/util/color_ramp.ts +5 -5
  290. package/src/util/config.ts +2 -2
  291. package/src/util/dispatcher.ts +1 -1
  292. package/src/util/dom.ts +2 -2
  293. package/src/util/evented.ts +1 -1
  294. package/src/util/find_pole_of_inaccessibility.ts +3 -3
  295. package/src/util/image.ts +5 -5
  296. package/src/util/performance.ts +7 -7
  297. package/src/util/request_manager.ts +4 -4
  298. package/src/util/resolve_tokens.ts +4 -4
  299. package/src/util/struct_array.test.ts +1 -1
  300. package/src/util/struct_array.ts +15 -15
  301. package/src/util/task_queue.ts +3 -3
  302. package/src/util/test/util.ts +14 -0
  303. package/src/util/tile_request_cache.ts +3 -3
  304. package/src/util/transferable_grid_index.ts +4 -4
  305. package/src/util/util.ts +8 -8
  306. package/src/util/web_worker.ts +4 -68
  307. package/src/util/web_worker_transfer.test.ts +3 -0
  308. package/src/util/web_worker_transfer.ts +21 -17
  309. package/src/util/worker_pool.ts +1 -1
  310. package/build/.eslintrc +0 -21
  311. package/build/glsl_to_js.js +0 -12
  312. package/build/post-ts-build.js +0 -43
  313. package/build/release-notes.md.ejs +0 -8
  314. package/build/test/build-tape.js +0 -17
  315. package/build/web_worker_replacement.js +0 -5
  316. package/dist/package.json +0 -1
  317. package/src/style-spec/validate_spec.test.ts +0 -29
  318. package/src/symbol/shaping.test.ts +0 -392
  319. package/src/types/glsl.d.ts +0 -4
@@ -4,15 +4,15 @@ import LngLat from '../geo/lng_lat';
4
4
  import Tile from '../source/tile';
5
5
  import {OverscaledTileID} from '../source/tile_id';
6
6
  import {Event, ErrorEvent} from '../util/evented';
7
- import simulate from '../../test/util/simulate_interaction';
8
- import {fixedLngLat, fixedNum} from '../../test/util/fixed';
7
+ import simulate from '../../test/unit/lib/simulate_interaction';
8
+ import {fixedLngLat, fixedNum} from '../../test/unit/lib/fixed';
9
9
  import {LayerSpecification, SourceSpecification, StyleSpecification} from '../style-spec/types';
10
10
  import {RequestTransformFunction} from '../util/request_manager';
11
11
  import {extend} from '../util/util';
12
12
  import {LngLatBoundsLike} from '../geo/lng_lat_bounds';
13
13
  import {IControl} from './control/control';
14
14
  import EvaluationParameters from '../style/evaluation_parameters';
15
- import {fakeServer, SinonFakeServer} from 'sinon';
15
+ import {fakeServer, FakeServer} from 'nise';
16
16
 
17
17
  function createStyleSource() {
18
18
  return {
@@ -24,7 +24,7 @@ function createStyleSource() {
24
24
  } as SourceSpecification;
25
25
  }
26
26
 
27
- let server: SinonFakeServer;
27
+ let server: FakeServer;
28
28
 
29
29
  beforeEach(() => {
30
30
  setPerformance();
@@ -134,15 +134,17 @@ describe('Map', () => {
134
134
  test('emits load event after a style is set', done => {
135
135
  const map = new Map({container: window.document.createElement('div')} as any as MapOptions);
136
136
 
137
- map.on('load', done.fail);
137
+ const fail = () => done('test failed');
138
+ const pass = () => done();
139
+
140
+ map.on('load', fail);
138
141
 
139
142
  setTimeout(() => {
140
- map.off('load', done.fail);
141
- map.on('load', () => {
142
- done();
143
- });
143
+ map.off('load', fail);
144
+ map.on('load', pass);
144
145
  map.setStyle(createStyle());
145
146
  }, 1);
147
+
146
148
  });
147
149
 
148
150
  describe('#setStyle', () => {
@@ -918,7 +920,7 @@ describe('Map', () => {
918
920
  test('does not fire "webglcontextlost" after #remove has been called', done => {
919
921
  const map = createMap();
920
922
  const canvas = map.getCanvas();
921
- map.once('webglcontextlost', () => done.fail('"webglcontextlost" fired after #remove has been called'));
923
+ map.once('webglcontextlost', () => done('"webglcontextlost" fired after #remove has been called'));
922
924
  map.remove();
923
925
  // Dispatch the event manually because at the time of this writing, gl does not support
924
926
  // the WEBGL_lose_context extension.
@@ -931,7 +933,7 @@ describe('Map', () => {
931
933
  const canvas = map.getCanvas();
932
934
 
933
935
  map.once('webglcontextlost', () => {
934
- map.once('webglcontextrestored', () => done.fail('"webglcontextrestored" fired after #remove has been called'));
936
+ map.once('webglcontextrestored', () => done('"webglcontextrestored" fired after #remove has been called'));
935
937
  map.remove();
936
938
  canvas.dispatchEvent(new window.Event('webglcontextrestored'));
937
939
  done();
@@ -1885,7 +1887,9 @@ describe('Map', () => {
1885
1887
  if (timer) clearTimeout(timer);
1886
1888
  timer = setTimeout(() => {
1887
1889
  map.off('render', undefined);
1888
- map.on('render', done.fail);
1890
+ map.on('render', () => {
1891
+ done('test failed');
1892
+ });
1889
1893
  expect((map as any)._frameId).toBeFalsy();
1890
1894
  done();
1891
1895
  }, 100);
@@ -1896,7 +1900,9 @@ describe('Map', () => {
1896
1900
  const style = createStyle();
1897
1901
  const map = createMap({style});
1898
1902
  map.on('idle', () => {
1899
- map.on('render', done.fail);
1903
+ map.on('render', () => {
1904
+ done('test failed');
1905
+ });
1900
1906
  setTimeout(() => {
1901
1907
  done();
1902
1908
  }, 100);
@@ -2043,11 +2049,78 @@ describe('Map', () => {
2043
2049
  });
2044
2050
 
2045
2051
  map.on('styleimagemissing', ({id}) => {
2046
- done.fail(`styleimagemissing fired for value ${id}`);
2052
+ done(`styleimagemissing fired for value ${id}`);
2047
2053
  });
2048
2054
  });
2049
2055
  });
2050
2056
 
2057
+ describe('setPixelRatio', () => {
2058
+ test('resizes canvas', () => {
2059
+ const container = window.document.createElement('div');
2060
+ Object.defineProperty(container, 'clientWidth', {value: 512});
2061
+ Object.defineProperty(container, 'clientHeight', {value: 512});
2062
+ const map = createMap({container, pixelRatio: 1});
2063
+ expect(map.getCanvas().width).toBe(512);
2064
+ expect(map.getCanvas().height).toBe(512);
2065
+ map.setPixelRatio(2);
2066
+ expect(map.getCanvas().width).toBe(1024);
2067
+ expect(map.getCanvas().height).toBe(1024);
2068
+ });
2069
+
2070
+ test('resizes painter', () => {
2071
+ const container = window.document.createElement('div');
2072
+ Object.defineProperty(container, 'clientWidth', {value: 512});
2073
+ Object.defineProperty(container, 'clientHeight', {value: 512});
2074
+ const map = createMap({container, pixelRatio: 1});
2075
+ expect(map.painter.pixelRatio).toBe(1);
2076
+ expect(map.painter.width).toBe(512);
2077
+ expect(map.painter.height).toBe(512);
2078
+ map.setPixelRatio(2);
2079
+ expect(map.painter.pixelRatio).toBe(2);
2080
+ expect(map.painter.width).toBe(1024);
2081
+ expect(map.painter.height).toBe(1024);
2082
+ });
2083
+ });
2084
+
2085
+ describe('getPixelRatio', () => {
2086
+ test('returns the pixel ratio', () => {
2087
+ const map = createMap({pixelRatio: 1});
2088
+ expect(map.getPixelRatio()).toBe(1);
2089
+ map.setPixelRatio(2);
2090
+ expect(map.getPixelRatio()).toBe(2);
2091
+ });
2092
+ });
2093
+
2094
+ test('pixel ratio defaults to devicePixelRatio', () => {
2095
+ const map = createMap();
2096
+ expect(map.getPixelRatio()).toBe(devicePixelRatio);
2097
+ });
2098
+
2099
+ test('canvas has the expected size', () => {
2100
+ const container = window.document.createElement('div');
2101
+ Object.defineProperty(container, 'clientWidth', {value: 512});
2102
+ Object.defineProperty(container, 'clientHeight', {value: 512});
2103
+ const map = createMap({container, pixelRatio: 2});
2104
+ expect(map.getCanvas().width).toBe(1024);
2105
+ expect(map.getCanvas().height).toBe(1024);
2106
+ });
2107
+
2108
+ test('painter has the expected size and pixel ratio', () => {
2109
+ const container = window.document.createElement('div');
2110
+ Object.defineProperty(container, 'clientWidth', {value: 512});
2111
+ Object.defineProperty(container, 'clientHeight', {value: 512});
2112
+ const map = createMap({container, pixelRatio: 2});
2113
+ expect(map.painter.pixelRatio).toBe(2);
2114
+ expect(map.painter.width).toBe(1024);
2115
+ expect(map.painter.height).toBe(1024);
2116
+ });
2117
+
2118
+ test('fires sourcedataabort event on dataabort event', done => {
2119
+ const map = createMap();
2120
+ map.once('sourcedataabort', () => done());
2121
+ map.fire(new Event('dataabort'));
2122
+ });
2123
+
2051
2124
  });
2052
2125
 
2053
2126
  function createStyle() {
package/src/ui/map.ts CHANGED
@@ -59,48 +59,49 @@ import type {ControlPosition, IControl} from './control/control';
59
59
  /* eslint-enable no-use-before-define */
60
60
 
61
61
  export type MapOptions = {
62
- hash?: boolean | string;
63
- interactive?: boolean;
64
- container: HTMLElement | string;
65
- bearingSnap?: number;
66
- attributionControl?: boolean;
67
- customAttribution?: string | Array<string>;
68
- logoPosition?: ControlPosition;
69
- failIfMajorPerformanceCaveat?: boolean;
70
- preserveDrawingBuffer?: boolean;
71
- antialias?: boolean;
72
- refreshExpiredTiles?: boolean;
73
- maxBounds?: LngLatBoundsLike;
74
- scrollZoom?: boolean;
75
- minZoom?: number | null;
76
- maxZoom?: number | null;
77
- minPitch?: number | null;
78
- maxPitch?: number | null;
79
- boxZoom?: boolean;
80
- dragRotate?: boolean;
81
- dragPan?: DragPanOptions | boolean;
82
- keyboard?: boolean;
83
- doubleClickZoom?: boolean;
84
- touchZoomRotate?: boolean;
85
- touchPitch?: boolean;
86
- trackResize?: boolean;
87
- center?: LngLatLike;
88
- zoom?: number;
89
- bearing?: number;
90
- pitch?: number;
91
- renderWorldCopies?: boolean;
92
- maxTileCacheSize?: number;
93
- transformRequest?: RequestTransformFunction;
94
- locale?: any;
95
- fadeDuration?: number;
96
- crossSourceCollisions?: boolean;
97
- collectResourceTiming?: boolean;
98
- clickTolerance?: number;
99
- bounds?: LngLatBoundsLike;
100
- fitBoundsOptions?: Object;
101
- localIdeographFontFamily?: string;
102
- style: StyleSpecification | string;
103
- pitchWithRotate?: boolean;
62
+ hash?: boolean | string;
63
+ interactive?: boolean;
64
+ container: HTMLElement | string;
65
+ bearingSnap?: number;
66
+ attributionControl?: boolean;
67
+ customAttribution?: string | Array<string>;
68
+ logoPosition?: ControlPosition;
69
+ failIfMajorPerformanceCaveat?: boolean;
70
+ preserveDrawingBuffer?: boolean;
71
+ antialias?: boolean;
72
+ refreshExpiredTiles?: boolean;
73
+ maxBounds?: LngLatBoundsLike;
74
+ scrollZoom?: boolean;
75
+ minZoom?: number | null;
76
+ maxZoom?: number | null;
77
+ minPitch?: number | null;
78
+ maxPitch?: number | null;
79
+ boxZoom?: boolean;
80
+ dragRotate?: boolean;
81
+ dragPan?: DragPanOptions | boolean;
82
+ keyboard?: boolean;
83
+ doubleClickZoom?: boolean;
84
+ touchZoomRotate?: boolean;
85
+ touchPitch?: boolean;
86
+ trackResize?: boolean;
87
+ center?: LngLatLike;
88
+ zoom?: number;
89
+ bearing?: number;
90
+ pitch?: number;
91
+ renderWorldCopies?: boolean;
92
+ maxTileCacheSize?: number;
93
+ transformRequest?: RequestTransformFunction;
94
+ locale?: any;
95
+ fadeDuration?: number;
96
+ crossSourceCollisions?: boolean;
97
+ collectResourceTiming?: boolean;
98
+ clickTolerance?: number;
99
+ bounds?: LngLatBoundsLike;
100
+ fitBoundsOptions?: Object;
101
+ localIdeographFontFamily?: string;
102
+ style: StyleSpecification | string;
103
+ pitchWithRotate?: boolean;
104
+ pixelRatio?: number;
104
105
  };
105
106
 
106
107
  // See article here: https://medium.com/terria/typescript-transforming-optional-properties-to-required-properties-that-may-be-undefined-7482cb4e1585
@@ -211,19 +212,19 @@ const defaultOptions = {
211
212
  * @param {boolean} [options.doubleClickZoom=true] If `true`, the "double click to zoom" interaction is enabled (see {@link DoubleClickZoomHandler}).
212
213
  * @param {boolean|Object} [options.touchZoomRotate=true] If `true`, the "pinch to rotate and zoom" interaction is enabled. An `Object` value is passed as options to {@link TouchZoomRotateHandler#enable}.
213
214
  * @param {boolean|Object} [options.touchPitch=true] If `true`, the "drag to pitch" interaction is enabled. An `Object` value is passed as options to {@link TouchPitchHandler#enable}.
214
- * @param {boolean} [options.trackResize=true] If `true`, the map will automatically resize when the browser window resizes.
215
+ * @param {boolean} [options.trackResize=true] If `true`, the map will automatically resize when the browser window resizes.
215
216
  * @param {LngLatLike} [options.center=[0, 0]] The initial geographical centerpoint of the map. If `center` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `[0, 0]` Note: MapLibre GL uses longitude, latitude coordinate order (as opposed to latitude, longitude) to match GeoJSON.
216
217
  * @param {number} [options.zoom=0] The initial zoom level of the map. If `zoom` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
217
218
  * @param {number} [options.bearing=0] The initial bearing (rotation) of the map, measured in degrees counter-clockwise from north. If `bearing` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`.
218
219
  * @param {number} [options.pitch=0] The initial pitch (tilt) of the map, measured in degrees away from the plane of the screen (0-85). If `pitch` is not specified in the constructor options, MapLibre GL JS will look for it in the map's style object. If it is not specified in the style, either, it will default to `0`. Values greater than 60 degrees are experimental and may result in rendering issues. If you encounter any, please raise an issue with details in the MapLibre project.
219
220
  * @param {LngLatBoundsLike} [options.bounds] The initial bounds of the map. If `bounds` is specified, it overrides `center` and `zoom` constructor options.
220
221
  * @param {Object} [options.fitBoundsOptions] A {@link Map#fitBounds} options object to use _only_ when fitting the initial `bounds` provided above.
221
- * @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to `false`:
222
+ * @param {boolean} [options.renderWorldCopies=true] If `true`, multiple copies of the world will be rendered side by side beyond -180 and 180 degrees longitude. If set to `false`:
222
223
  * - When the map is zoomed out far enough that a single representation of the world does not fill the map's entire
223
224
  * container, there will be blank space beyond 180 and -180 degrees longitude.
224
225
  * - Features that cross 180 and -180 degrees longitude will be cut in two (with one portion on the right edge of the
225
226
  * map and the other on the left edge of the map) at every zoom level.
226
- * @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
227
+ * @param {number} [options.maxTileCacheSize=null] The maximum number of tiles stored in the tile cache for a given source. If omitted, the cache will be dynamically sized based on the current viewport.
227
228
  * @param {string} [options.localIdeographFontFamily='sans-serif'] Defines a CSS
228
229
  * font-family for locally overriding generation of glyphs in the 'CJK Unified Ideographs', 'Hiragana', 'Katakana' and 'Hangul Syllables' ranges.
229
230
  * In these ranges, font settings from the map's style will be ignored, except for font-weight keywords (light/regular/medium/bold).
@@ -235,6 +236,7 @@ const defaultOptions = {
235
236
  * @param {number} [options.fadeDuration=300] Controls the duration of the fade-in/fade-out animation for label collisions, in milliseconds. This setting affects all symbol layers. This setting does not affect the duration of runtime styling transitions or raster tile cross-fading.
236
237
  * @param {boolean} [options.crossSourceCollisions=true] If `true`, symbols from multiple sources can collide with each other during collision detection. If `false`, collision detection is run separately for the symbols in each source.
237
238
  * @param {Object} [options.locale=null] A patch to apply to the default localization table for UI strings, e.g. control tooltips. The `locale` object maps namespaced UI string IDs to translated strings in the target language; see `src/ui/default_locale.js` for an example with all supported string IDs. The object may specify all UI strings (thereby adding support for a new translation) or only a subset of strings (thereby patching the default translation table).
239
+ * @param {number} [options.pixelRatio] The pixel ratio. The canvas' `width` attribute will be `container.clientWidth * pixelRatio` and its `height` attribute will be `container.clientHeight * pixelRatio`. Defaults to `devicePixelRatio` if not specified.
238
240
  * @example
239
241
  * var map = new maplibregl.Map({
240
242
  * container: 'map',
@@ -298,6 +300,7 @@ class Map extends Camera {
298
300
  _locale: any;
299
301
  _removed: boolean;
300
302
  _clickTolerance: number;
303
+ _pixelRatio: number;
301
304
 
302
305
  /**
303
306
  * The map's {@link ScrollZoomHandler}, which implements zooming in and out with a scroll wheel or trackpad.
@@ -389,6 +392,7 @@ class Map extends Camera {
389
392
  this._mapId = uniqueId();
390
393
  this._locale = extend({}, defaultLocale, options.locale);
391
394
  this._clickTolerance = options.clickTolerance;
395
+ this._pixelRatio = options.pixelRatio ?? devicePixelRatio;
392
396
 
393
397
  this._requestManager = new RequestManager(options.transformRequest);
394
398
 
@@ -472,6 +476,9 @@ class Map extends Camera {
472
476
  this.on('dataloading', (event: MapDataEvent) => {
473
477
  this.fire(new Event(`${event.dataType}dataloading`, event));
474
478
  });
479
+ this.on('dataabort', (event: MapDataEvent) => {
480
+ this.fire(new Event('sourcedataabort', event));
481
+ });
475
482
  }
476
483
 
477
484
  /*
@@ -584,9 +591,9 @@ class Map extends Camera {
584
591
  const width = dimensions[0];
585
592
  const height = dimensions[1];
586
593
 
587
- this._resizeCanvas(width, height);
594
+ this._resizeCanvas(width, height, this.getPixelRatio());
588
595
  this.transform.resize(width, height);
589
- this.painter.resize(width, height);
596
+ this.painter.resize(width, height, this.getPixelRatio());
590
597
 
591
598
  const fireMoving = !this._moving;
592
599
  if (fireMoving) {
@@ -602,6 +609,29 @@ class Map extends Camera {
602
609
  return this;
603
610
  }
604
611
 
612
+ /**
613
+ * Returns the map's pixel ratio.
614
+ * @returns {number} The pixel ratio.
615
+ */
616
+ getPixelRatio() {
617
+ return this._pixelRatio;
618
+ }
619
+
620
+ /**
621
+ * Sets the map's pixel ratio. This allows to override `devicePixelRatio`.
622
+ * After this call, the canvas' `width` attribute will be `container.clientWidth * pixelRatio`
623
+ * and its height attribute will be `container.clientHeight * pixelRatio`.
624
+ * @param {number} pixelRatio The pixel ratio.
625
+ */
626
+ setPixelRatio(pixelRatio: number) {
627
+ const [width, height] = this._containerDimensions();
628
+
629
+ this._pixelRatio = pixelRatio;
630
+
631
+ this._resizeCanvas(width, height, pixelRatio);
632
+ this.painter.resize(width, height, pixelRatio);
633
+ }
634
+
605
635
  /**
606
636
  * Returns the map's geographical bounds. When the bearing or pitch is non-zero, the visible region is not
607
637
  * an axis-aligned rectangle, and the result is the smallest bounds that encompasses the visible region.
@@ -828,11 +858,11 @@ class Map extends Camera {
828
858
  }
829
859
 
830
860
  /**
831
- * Returns a {@link Point} representing pixel coordinates, relative to the map's `container`,
861
+ * Returns a [Point](https://github.com/mapbox/point-geometry) representing pixel coordinates, relative to the map's `container`,
832
862
  * that correspond to the specified geographical location.
833
863
  *
834
864
  * @param {LngLatLike} lnglat The geographical location to project.
835
- * @returns {Point} The {@link Point} corresponding to `lnglat`, relative to the map's `container`.
865
+ * @returns {Point} The [Point](https://github.com/mapbox/point-geometry) corresponding to `lnglat`, relative to the map's `container`.
836
866
  * @example
837
867
  * var coordinate = [-122.420679, 37.772537];
838
868
  * var point = map.project(coordinate);
@@ -991,6 +1021,8 @@ class Map extends Camera {
991
1021
  * | [`styledataloading`](#map.event:styledataloading) | |
992
1022
  * | [`sourcedataloading`](#map.event:sourcedataloading) | |
993
1023
  * | [`styleimagemissing`](#map.event:styleimagemissing) | |
1024
+ * | [`dataabort`](#map.event:dataabort) | |
1025
+ * | [`sourcedataabort`](#map.event:sourcedataabort) | |
994
1026
  *
995
1027
  * @param {string | Listener} layerIdOrListener The ID of a style layer or a listener if no ID is provided. Event will only be triggered if its location
996
1028
  * is within a visible feature in this layer. The event will have a `features` property containing
@@ -1311,9 +1343,9 @@ class Map extends Camera {
1311
1343
  *
1312
1344
  */
1313
1345
  querySourceFeatures(sourceId: string, parameters?: {
1314
- sourceLayer: string;
1315
- filter: Array<any>;
1316
- validate?: boolean;
1346
+ sourceLayer: string;
1347
+ filter: Array<any>;
1348
+ validate?: boolean;
1317
1349
  } | null) {
1318
1350
  return this.style.querySourceFeatures(sourceId, parameters);
1319
1351
  }
@@ -1345,7 +1377,7 @@ class Map extends Camera {
1345
1377
  *
1346
1378
  */
1347
1379
  setStyle(style: StyleSpecification | string | null, options?: {
1348
- diff?: boolean;
1380
+ diff?: boolean;
1349
1381
  } & StyleOptions) {
1350
1382
  options = extend({}, {localIdeographFontFamily: this._localIdeographFontFamily}, options);
1351
1383
 
@@ -1361,10 +1393,10 @@ class Map extends Camera {
1361
1393
  /**
1362
1394
  * Updates the requestManager's transform request with a new function
1363
1395
  *
1364
- * @param transformRequest A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests.
1396
+ * @param transformRequest A callback run before the Map makes a request for an external URL. The callback can be used to modify the url, set headers, or set the credentials property for cross-origin requests.
1365
1397
  * Expected to return an object with a `url` property and optionally `headers` and `credentials` properties
1366
1398
  *
1367
- * @returns {Map} `this`
1399
+ * @returns {Map} `this`
1368
1400
  *
1369
1401
  * @example
1370
1402
  * map.setTransformRequest((url: string, resourceType: string) => {});
@@ -1384,7 +1416,7 @@ class Map extends Camera {
1384
1416
  }
1385
1417
 
1386
1418
  _updateStyle(style: StyleSpecification | string | null, options?: {
1387
- diff?: boolean;
1419
+ diff?: boolean;
1388
1420
  } & StyleOptions) {
1389
1421
  if (this.style) {
1390
1422
  this.style.setEventedParent(null);
@@ -1418,7 +1450,7 @@ class Map extends Camera {
1418
1450
  }
1419
1451
 
1420
1452
  _diffStyle(style: StyleSpecification | string, options?: {
1421
- diff?: boolean;
1453
+ diff?: boolean;
1422
1454
  } & StyleOptions) {
1423
1455
  if (typeof style === 'string') {
1424
1456
  const url = style;
@@ -1436,7 +1468,7 @@ class Map extends Camera {
1436
1468
  }
1437
1469
 
1438
1470
  _updateDiff(style: StyleSpecification, options?: {
1439
- diff?: boolean;
1471
+ diff?: boolean;
1440
1472
  } & StyleOptions) {
1441
1473
  try {
1442
1474
  if (this.style.setState(style)) {
@@ -1621,9 +1653,9 @@ class Map extends Camera {
1621
1653
  * @param options Options object.
1622
1654
  * @param options.pixelRatio The ratio of pixels in the image to physical pixels on the screen
1623
1655
  * @param options.sdf Whether the image should be interpreted as an SDF image
1624
- * @param options.content `[x1, y1, x2, y2]` If `icon-text-fit` is used in a layer with this image, this option defines the part of the image that can be covered by the content in `text-field`.
1625
- * @param options.stretchX `[[x1, x2], ...]` If `icon-text-fit` is used in a layer with this image, this option defines the part(s) of the image that can be stretched horizontally.
1626
- * @param options.stretchY `[[y1, y2], ...]` If `icon-text-fit` is used in a layer with this image, this option defines the part(s) of the image that can be stretched vertically.
1656
+ * @param options.content `[x1, y1, x2, y2]` If `icon-text-fit` is used in a layer with this image, this option defines the part of the image that can be covered by the content in `text-field`.
1657
+ * @param options.stretchX `[[x1, x2], ...]` If `icon-text-fit` is used in a layer with this image, this option defines the part(s) of the image that can be stretched horizontally.
1658
+ * @param options.stretchY `[[y1, y2], ...]` If `icon-text-fit` is used in a layer with this image, this option defines the part(s) of the image that can be stretched vertically.
1627
1659
  *
1628
1660
  * @example
1629
1661
  * // If the style's sprite does not already contain an image with ID 'cat',
@@ -1652,18 +1684,18 @@ class Map extends Camera {
1652
1684
  * @see Use `ImageData`: [Add a generated icon to the map](https://maplibre.org/maplibre-gl-js-docs/example/add-image-generated/)
1653
1685
  */
1654
1686
  addImage(id: string,
1655
- image: HTMLImageElement | ImageBitmap | ImageData | {
1656
- width: number;
1657
- height: number;
1658
- data: Uint8Array | Uint8ClampedArray;
1659
- } | StyleImageInterface,
1660
- {
1661
- pixelRatio = 1,
1662
- sdf = false,
1663
- stretchX,
1664
- stretchY,
1665
- content
1666
- }: Partial<StyleImageMetadata> = {}) {
1687
+ image: HTMLImageElement | ImageBitmap | ImageData | {
1688
+ width: number;
1689
+ height: number;
1690
+ data: Uint8Array | Uint8ClampedArray;
1691
+ } | StyleImageInterface,
1692
+ {
1693
+ pixelRatio = 1,
1694
+ sdf = false,
1695
+ stretchX,
1696
+ stretchY,
1697
+ content
1698
+ }: Partial<StyleImageMetadata> = {}) {
1667
1699
  this._lazyInitEmptyStyle();
1668
1700
  const version = 0;
1669
1701
 
@@ -1715,9 +1747,9 @@ class Map extends Camera {
1715
1747
  */
1716
1748
  updateImage(id: string,
1717
1749
  image: HTMLImageElement | ImageBitmap | ImageData | {
1718
- width: number;
1719
- height: number;
1720
- data: Uint8Array | Uint8ClampedArray;
1750
+ width: number;
1751
+ height: number;
1752
+ data: Uint8Array | Uint8ClampedArray;
1721
1753
  } | StyleImageInterface) {
1722
1754
 
1723
1755
  const existingImage = this.style.getImage(id);
@@ -1754,7 +1786,7 @@ class Map extends Camera {
1754
1786
  *
1755
1787
  * @param id The ID of the image.
1756
1788
  *
1757
- * @returns {boolean} A Boolean indicating whether the image exists.
1789
+ * @returns {boolean} A Boolean indicating whether the image exists.
1758
1790
  * @example
1759
1791
  * // Check if an image with the ID 'cat' exists in
1760
1792
  * // the style's sprite.
@@ -1807,16 +1839,16 @@ class Map extends Camera {
1807
1839
  }
1808
1840
 
1809
1841
  /**
1810
- * Returns an Array of strings containing the IDs of all images currently available in the map.
1811
- * This includes both images from the style's original sprite
1812
- * and any images that have been added at runtime using {@link Map#addImage}.
1813
- *
1814
- * @returns {Array<string>} An Array of strings containing the names of all sprites/images currently available in the map.
1815
- *
1816
- * @example
1817
- * var allImages = map.listImages();
1818
- *
1819
- */
1842
+ * Returns an Array of strings containing the IDs of all images currently available in the map.
1843
+ * This includes both images from the style's original sprite
1844
+ * and any images that have been added at runtime using {@link Map#addImage}.
1845
+ *
1846
+ * @returns {Array<string>} An Array of strings containing the names of all sprites/images currently available in the map.
1847
+ *
1848
+ * @example
1849
+ * var allImages = map.listImages();
1850
+ *
1851
+ */
1820
1852
  listImages() {
1821
1853
  return this.style.listImages();
1822
1854
  }
@@ -2180,9 +2212,9 @@ class Map extends Camera {
2180
2212
  * @see [Create a hover effect](https://maplibre.org/maplibre-gl-js-docs/example/hover-styles/)
2181
2213
  */
2182
2214
  setFeatureState(feature: {
2183
- source: string;
2184
- sourceLayer?: string;
2185
- id: string | number;
2215
+ source: string;
2216
+ sourceLayer?: string;
2217
+ id: string | number;
2186
2218
  }, state: any) {
2187
2219
  this.style.setFeatureState(feature, state);
2188
2220
  return this._update();
@@ -2234,11 +2266,11 @@ class Map extends Camera {
2234
2266
  * }, 'hover');
2235
2267
  * });
2236
2268
  *
2237
- */
2269
+ */
2238
2270
  removeFeatureState(target: {
2239
- source: string;
2240
- sourceLayer?: string;
2241
- id?: string | number;
2271
+ source: string;
2272
+ sourceLayer?: string;
2273
+ id?: string | number;
2242
2274
  }, key?: string) {
2243
2275
  this.style.removeFeatureState(target, key);
2244
2276
  return this._update();
@@ -2274,11 +2306,11 @@ class Map extends Camera {
2274
2306
  *
2275
2307
  */
2276
2308
  getFeatureState(
2277
- feature: {
2278
- source: string;
2279
- sourceLayer?: string;
2280
- id: string | number;
2281
- }
2309
+ feature: {
2310
+ source: string;
2311
+ sourceLayer?: string;
2312
+ id: string | number;
2313
+ }
2282
2314
  ): any {
2283
2315
  return this.style.getFeatureState(feature);
2284
2316
  }
@@ -2349,7 +2381,7 @@ class Map extends Camera {
2349
2381
  this._canvas.setAttribute('role', 'region');
2350
2382
 
2351
2383
  const dimensions = this._containerDimensions();
2352
- this._resizeCanvas(dimensions[0], dimensions[1]);
2384
+ this._resizeCanvas(dimensions[0], dimensions[1], this.getPixelRatio());
2353
2385
 
2354
2386
  const controlContainer = this._controlContainer = DOM.create('div', 'maplibregl-control-container mapboxgl-control-container', container);
2355
2387
  const positions = this._controlPositions = {};
@@ -2360,9 +2392,7 @@ class Map extends Camera {
2360
2392
  this._container.addEventListener('scroll', this._onMapScroll, false);
2361
2393
  }
2362
2394
 
2363
- _resizeCanvas(width: number, height: number) {
2364
- const pixelRatio = devicePixelRatio || 1;
2365
-
2395
+ _resizeCanvas(width: number, height: number, pixelRatio: number) {
2366
2396
  // Request the required canvas size taking the pixelratio into account.
2367
2397
  this._canvas.width = pixelRatio * width;
2368
2398
  this._canvas.height = pixelRatio * height;
@@ -2609,11 +2639,11 @@ class Map extends Camera {
2609
2639
  }
2610
2640
 
2611
2641
  /**
2612
- * Force a synchronous redraw of the map.
2613
- * @example
2614
- * map.redraw();
2615
- * @returns {Map} `this`
2616
- */
2642
+ * Force a synchronous redraw of the map.
2643
+ * @example
2644
+ * map.redraw();
2645
+ * @returns {Map} `this`
2646
+ */
2617
2647
  redraw(): Map {
2618
2648
  if (this.style) {
2619
2649
  // cancel the scheduled update
@@ -1,4 +1,4 @@
1
- import simulate, {window} from '../../test/util/simulate_interaction';
1
+ import simulate, {window} from '../../test/unit/lib/simulate_interaction';
2
2
  import StyleLayer from '../style/style_layer';
3
3
  import {createMap, setPerformance, setWebGlContext} from '../util/test/util';
4
4
  import {MapLayerEventType} from './events';