maplibre-gl 2.1.1 → 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 (305) 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} +11 -26
  12. package/dist/maplibre-gl-dev.js +522 -226
  13. package/dist/maplibre-gl.css +1 -1
  14. package/dist/maplibre-gl.d.ts +1536 -1010
  15. package/dist/maplibre-gl.js +3 -3
  16. package/dist/maplibre-gl.js.map +1 -1
  17. package/package.json +40 -61
  18. package/src/data/{array_types.ts → array_types.g.ts} +0 -0
  19. package/src/data/bucket/circle_bucket.ts +1 -1
  20. package/src/data/bucket/fill_bucket.test.ts +1 -1
  21. package/src/data/bucket/fill_bucket.ts +4 -4
  22. package/src/data/bucket/fill_extrusion_bucket.ts +1 -1
  23. package/src/data/bucket/line_bucket.test.ts +1 -1
  24. package/src/data/bucket/line_bucket.ts +6 -6
  25. package/src/data/bucket/symbol_bucket.test.ts +16 -16
  26. package/src/data/bucket/symbol_bucket.ts +53 -53
  27. package/src/data/bucket.ts +43 -43
  28. package/src/data/dem_data.ts +12 -12
  29. package/src/data/evaluation_feature.ts +10 -10
  30. package/src/data/feature_index.ts +37 -37
  31. package/src/data/feature_position_map.ts +5 -5
  32. package/src/data/index_array_type.ts +1 -1
  33. package/src/data/load_geometry.test.ts +1 -1
  34. package/src/data/program_configuration.ts +46 -46
  35. package/src/data/segment.ts +14 -14
  36. package/src/geo/edge_insets.ts +2 -2
  37. package/src/geo/lng_lat.ts +4 -4
  38. package/src/geo/lng_lat_bounds.ts +35 -35
  39. package/src/geo/mercator_coordinate.ts +5 -5
  40. package/src/geo/transform.test.ts +1 -1
  41. package/src/geo/transform.ts +14 -14
  42. package/src/gl/context.ts +3 -3
  43. package/src/gl/types.ts +19 -19
  44. package/src/gl/value.ts +6 -6
  45. package/src/gl/vertex_buffer.test.ts +1 -1
  46. package/src/index.ts +24 -9
  47. package/src/render/draw_circle.ts +8 -8
  48. package/src/render/draw_collision_debug.ts +5 -5
  49. package/src/render/draw_line.ts +4 -4
  50. package/src/render/draw_symbol.ts +21 -21
  51. package/src/render/glyph_atlas.ts +12 -12
  52. package/src/render/glyph_manager.test.ts +10 -21
  53. package/src/render/glyph_manager.ts +33 -32
  54. package/src/render/image_manager.ts +4 -4
  55. package/src/render/painter.ts +11 -11
  56. package/src/render/program/background_program.ts +29 -29
  57. package/src/render/program/circle_program.ts +10 -10
  58. package/src/render/program/clipping_mask_program.ts +1 -1
  59. package/src/render/program/collision_program.ts +9 -9
  60. package/src/render/program/debug_program.ts +4 -4
  61. package/src/render/program/fill_extrusion_program.ts +31 -31
  62. package/src/render/program/fill_program.ts +29 -29
  63. package/src/render/program/heatmap_program.ts +12 -12
  64. package/src/render/program/hillshade_program.ts +12 -12
  65. package/src/render/program/line_program.ts +38 -38
  66. package/src/render/program/pattern.ts +28 -28
  67. package/src/render/program/raster_program.ts +21 -21
  68. package/src/render/program/symbol_program.ts +96 -96
  69. package/src/render/program.ts +25 -25
  70. package/src/render/texture.ts +9 -9
  71. package/src/render/uniform_binding.ts +1 -1
  72. package/src/render/vertex_array_object.ts +13 -13
  73. package/src/shaders/_prelude.fragment.glsl.g.ts +2 -0
  74. package/src/shaders/_prelude.vertex.glsl.g.ts +2 -0
  75. package/src/shaders/background.fragment.glsl.g.ts +2 -0
  76. package/src/shaders/background.vertex.glsl.g.ts +2 -0
  77. package/src/shaders/background_pattern.fragment.glsl.g.ts +2 -0
  78. package/src/shaders/background_pattern.vertex.glsl.g.ts +2 -0
  79. package/src/shaders/circle.fragment.glsl.g.ts +2 -0
  80. package/src/shaders/circle.vertex.glsl.g.ts +2 -0
  81. package/src/shaders/clipping_mask.fragment.glsl.g.ts +2 -0
  82. package/src/shaders/clipping_mask.vertex.glsl.g.ts +2 -0
  83. package/src/shaders/collision_box.fragment.glsl.g.ts +2 -0
  84. package/src/shaders/collision_box.vertex.glsl.g.ts +2 -0
  85. package/src/shaders/collision_circle.fragment.glsl.g.ts +2 -0
  86. package/src/shaders/collision_circle.vertex.glsl.g.ts +2 -0
  87. package/src/shaders/debug.fragment.glsl.g.ts +2 -0
  88. package/src/shaders/debug.vertex.glsl.g.ts +2 -0
  89. package/src/shaders/fill.fragment.glsl.g.ts +2 -0
  90. package/src/shaders/fill.vertex.glsl.g.ts +2 -0
  91. package/src/shaders/fill_extrusion.fragment.glsl.g.ts +2 -0
  92. package/src/shaders/fill_extrusion.vertex.glsl.g.ts +2 -0
  93. package/src/shaders/fill_extrusion_pattern.fragment.glsl.g.ts +2 -0
  94. package/src/shaders/fill_extrusion_pattern.vertex.glsl.g.ts +2 -0
  95. package/src/shaders/fill_outline.fragment.glsl.g.ts +2 -0
  96. package/src/shaders/fill_outline.vertex.glsl.g.ts +2 -0
  97. package/src/shaders/fill_outline_pattern.fragment.glsl.g.ts +2 -0
  98. package/src/shaders/fill_outline_pattern.vertex.glsl.g.ts +2 -0
  99. package/src/shaders/fill_pattern.fragment.glsl.g.ts +2 -0
  100. package/src/shaders/fill_pattern.vertex.glsl.g.ts +2 -0
  101. package/src/shaders/heatmap.fragment.glsl.g.ts +2 -0
  102. package/src/shaders/heatmap.vertex.glsl.g.ts +2 -0
  103. package/src/shaders/heatmap_texture.fragment.glsl.g.ts +2 -0
  104. package/src/shaders/heatmap_texture.vertex.glsl.g.ts +2 -0
  105. package/src/shaders/hillshade.fragment.glsl.g.ts +2 -0
  106. package/src/shaders/hillshade.vertex.glsl.g.ts +2 -0
  107. package/src/shaders/hillshade_prepare.fragment.glsl.g.ts +2 -0
  108. package/src/shaders/hillshade_prepare.vertex.glsl.g.ts +2 -0
  109. package/src/shaders/line.fragment.glsl.g.ts +2 -0
  110. package/src/shaders/line.vertex.glsl.g.ts +2 -0
  111. package/src/shaders/line_gradient.fragment.glsl.g.ts +2 -0
  112. package/src/shaders/line_gradient.vertex.glsl.g.ts +2 -0
  113. package/src/shaders/line_pattern.fragment.glsl.g.ts +2 -0
  114. package/src/shaders/line_pattern.vertex.glsl.g.ts +2 -0
  115. package/src/shaders/line_sdf.fragment.glsl.g.ts +2 -0
  116. package/src/shaders/line_sdf.vertex.glsl.g.ts +2 -0
  117. package/src/shaders/raster.fragment.glsl.g.ts +2 -0
  118. package/src/shaders/raster.vertex.glsl.g.ts +2 -0
  119. package/src/shaders/shaders.ts +52 -55
  120. package/src/shaders/symbol_icon.fragment.glsl.g.ts +2 -0
  121. package/src/shaders/symbol_icon.vertex.glsl.g.ts +2 -0
  122. package/src/shaders/symbol_sdf.fragment.glsl.g.ts +2 -0
  123. package/src/shaders/symbol_sdf.vertex.glsl.g.ts +2 -0
  124. package/src/shaders/symbol_text_and_icon.fragment.glsl.g.ts +2 -0
  125. package/src/shaders/symbol_text_and_icon.vertex.glsl.g.ts +2 -0
  126. package/src/source/canvas_source.test.ts +11 -12
  127. package/src/source/canvas_source.ts +4 -4
  128. package/src/source/geojson_worker_source.ts +23 -23
  129. package/src/source/geojson_wrapper.ts +8 -8
  130. package/src/source/image_source.test.ts +2 -2
  131. package/src/source/image_source.ts +6 -6
  132. package/src/source/pixels_to_tile_units.ts +6 -6
  133. package/src/source/query_features.ts +20 -20
  134. package/src/source/raster_dem_tile_source.test.ts +2 -2
  135. package/src/source/raster_tile_source.test.ts +2 -2
  136. package/src/source/rtl_text_plugin.ts +10 -10
  137. package/src/source/source.ts +29 -29
  138. package/src/source/source_cache.test.ts +32 -0
  139. package/src/source/source_cache.ts +7 -5
  140. package/src/source/source_state.ts +1 -1
  141. package/src/source/tile.test.ts +3 -3
  142. package/src/source/tile.ts +15 -15
  143. package/src/source/tile_cache.ts +6 -6
  144. package/src/source/tile_id.test.ts +0 -1
  145. package/src/source/vector_tile_source.test.ts +3 -3
  146. package/src/source/vector_tile_source.ts +1 -1
  147. package/src/source/vector_tile_worker_source.test.ts +4 -4
  148. package/src/source/vector_tile_worker_source.ts +5 -5
  149. package/src/source/worker.test.ts +1 -1
  150. package/src/source/worker.ts +22 -22
  151. package/src/source/worker_source.ts +56 -56
  152. package/src/source/worker_tile.ts +4 -4
  153. package/src/style/evaluation_parameters.ts +3 -3
  154. package/src/style/format_section_override.test.ts +1 -1
  155. package/src/style/light.ts +10 -10
  156. package/src/style/load_glyph_range.test.ts +3 -3
  157. package/src/style/load_glyph_range.ts +6 -6
  158. package/src/style/load_sprite.ts +4 -4
  159. package/src/style/pauseable_placement.ts +1 -1
  160. package/src/style/properties.ts +69 -69
  161. package/src/style/query_utils.ts +7 -7
  162. package/src/style/style.test.ts +2 -2
  163. package/src/style/style.ts +29 -29
  164. package/src/style/style_glyph.ts +8 -8
  165. package/src/style/style_image.ts +58 -58
  166. package/src/style/style_layer/background_style_layer.ts +2 -2
  167. package/src/style/style_layer/{background_style_layer_properties.ts → background_style_layer_properties.g.ts} +0 -0
  168. package/src/style/style_layer/circle_style_layer.ts +10 -10
  169. package/src/style/style_layer/{circle_style_layer_properties.ts → circle_style_layer_properties.g.ts} +0 -0
  170. package/src/style/style_layer/custom_style_layer.ts +17 -17
  171. package/src/style/style_layer/fill_extrusion_style_layer.ts +10 -10
  172. package/src/style/style_layer/{fill_extrusion_style_layer_properties.ts → fill_extrusion_style_layer_properties.g.ts} +0 -0
  173. package/src/style/style_layer/fill_style_layer.ts +9 -9
  174. package/src/style/style_layer/{fill_style_layer_properties.ts → fill_style_layer_properties.g.ts} +0 -0
  175. package/src/style/style_layer/heatmap_style_layer.ts +2 -2
  176. package/src/style/style_layer/{heatmap_style_layer_properties.ts → heatmap_style_layer_properties.g.ts} +0 -0
  177. package/src/style/style_layer/hillshade_style_layer.ts +2 -2
  178. package/src/style/style_layer/{hillshade_style_layer_properties.ts → hillshade_style_layer_properties.g.ts} +0 -0
  179. package/src/style/style_layer/line_style_layer.ts +9 -9
  180. package/src/style/style_layer/{line_style_layer_properties.ts → line_style_layer_properties.g.ts} +0 -0
  181. package/src/style/style_layer/raster_style_layer.ts +2 -2
  182. package/src/style/style_layer/{raster_style_layer_properties.ts → raster_style_layer_properties.g.ts} +0 -0
  183. package/src/style/style_layer/symbol_style_layer.ts +7 -7
  184. package/src/style/style_layer/{symbol_style_layer_properties.ts → symbol_style_layer_properties.g.ts} +0 -0
  185. package/src/style/style_layer.ts +10 -10
  186. package/src/style/style_layer_index.ts +3 -3
  187. package/src/style/validate_style.ts +15 -15
  188. package/src/style-spec/error/validation_error.ts +1 -1
  189. package/src/style-spec/expression/compound_expression.ts +3 -3
  190. package/src/style-spec/expression/definitions/format.ts +11 -11
  191. package/src/style-spec/expression/definitions/interpolate.ts +5 -5
  192. package/src/style-spec/expression/definitions/match.ts +2 -2
  193. package/src/style-spec/expression/definitions/number_format.ts +11 -11
  194. package/src/style-spec/expression/expression.ts +8 -8
  195. package/src/style-spec/expression/index.ts +97 -97
  196. package/src/style-spec/expression/parsing_context.ts +11 -11
  197. package/src/style-spec/expression/types/collator.ts +9 -9
  198. package/src/style-spec/expression/types/resolved_image.ts +2 -2
  199. package/src/style-spec/expression/types.ts +14 -14
  200. package/src/style-spec/expression/values.ts +1 -1
  201. package/src/style-spec/feature_filter/index.ts +66 -66
  202. package/src/style-spec/function/convert.ts +3 -3
  203. package/src/style-spec/style-spec.ts +44 -44
  204. package/src/style-spec/util/color_spaces.ts +8 -8
  205. package/src/style-spec/util/result.ts +4 -4
  206. package/src/style-spec/validate/validate_filter.ts +58 -58
  207. package/src/style-spec/validate/validate_source.ts +63 -63
  208. package/src/style-spec/visit.ts +11 -11
  209. package/src/symbol/collision_feature.test.ts +1 -1
  210. package/src/symbol/collision_feature.ts +10 -10
  211. package/src/symbol/collision_index.ts +26 -26
  212. package/src/symbol/cross_tile_symbol_index.ts +17 -17
  213. package/src/symbol/get_anchors.ts +16 -16
  214. package/src/symbol/grid_index.ts +7 -7
  215. package/src/symbol/placement.ts +72 -72
  216. package/src/symbol/projection.ts +30 -30
  217. package/src/symbol/quads.ts +30 -30
  218. package/src/symbol/shaping.ts +160 -160
  219. package/src/symbol/symbol_layout.ts +119 -119
  220. package/src/symbol/symbol_size.ts +29 -29
  221. package/src/symbol/symbol_style_layer.test.ts +1 -1
  222. package/src/types/cancelable.ts +1 -1
  223. package/src/types/tilejson.ts +13 -13
  224. package/src/ui/anchor.ts +1 -1
  225. package/src/ui/camera.test.ts +5 -5
  226. package/src/ui/camera.ts +18 -18
  227. package/src/ui/control/attribution_control.test.ts +51 -16
  228. package/src/ui/control/attribution_control.ts +35 -16
  229. package/src/ui/control/control.ts +40 -40
  230. package/src/ui/control/fullscreen_control.ts +1 -1
  231. package/src/ui/control/geolocate_control.test.ts +1 -1
  232. package/src/ui/control/geolocate_control.ts +102 -102
  233. package/src/ui/control/logo_control.test.ts +4 -4
  234. package/src/ui/control/navigation_control.ts +3 -3
  235. package/src/ui/control/scale_control.test.ts +2 -2
  236. package/src/ui/control/scale_control.ts +5 -5
  237. package/src/ui/events.ts +289 -200
  238. package/src/ui/handler/box_zoom.test.ts +1 -1
  239. package/src/ui/handler/box_zoom.ts +1 -1
  240. package/src/ui/handler/dblclick_zoom.test.ts +1 -1
  241. package/src/ui/handler/drag_pan.test.ts +1 -1
  242. package/src/ui/handler/drag_rotate.test.ts +1 -1
  243. package/src/ui/handler/keyboard.test.ts +1 -1
  244. package/src/ui/handler/keyboard.ts +51 -51
  245. package/src/ui/handler/map_event.test.ts +1 -1
  246. package/src/ui/handler/map_event.ts +1 -1
  247. package/src/ui/handler/mouse.ts +1 -1
  248. package/src/ui/handler/mouse_rotate.test.ts +1 -1
  249. package/src/ui/handler/scroll_zoom.test.ts +1 -1
  250. package/src/ui/handler/scroll_zoom.ts +9 -9
  251. package/src/ui/handler/shim/drag_pan.ts +4 -4
  252. package/src/ui/handler/shim/drag_rotate.ts +1 -1
  253. package/src/ui/handler/shim/touch_zoom_rotate.ts +1 -1
  254. package/src/ui/handler/tap_recognizer.ts +4 -4
  255. package/src/ui/handler/touch_pan.ts +2 -2
  256. package/src/ui/handler/touch_zoom_rotate.test.ts +1 -1
  257. package/src/ui/handler/touch_zoom_rotate.ts +1 -1
  258. package/src/ui/handler_inertia.ts +6 -6
  259. package/src/ui/handler_manager.ts +44 -44
  260. package/src/ui/map/isMoving.test.ts +1 -1
  261. package/src/ui/map/isRotating.test.ts +1 -1
  262. package/src/ui/map/isZooming.test.ts +1 -1
  263. package/src/ui/map.test.ts +10 -4
  264. package/src/ui/map.ts +106 -101
  265. package/src/ui/map_events.test.ts +1 -1
  266. package/src/ui/marker.test.ts +12 -12
  267. package/src/ui/marker.ts +37 -37
  268. package/src/ui/popup.test.ts +7 -7
  269. package/src/ui/popup.ts +9 -9
  270. package/src/util/actor.test.ts +41 -10
  271. package/src/util/actor.ts +8 -8
  272. package/src/util/ajax.test.ts +29 -21
  273. package/src/util/ajax.ts +51 -30
  274. package/src/util/browser.ts +1 -1
  275. package/src/util/classify_rings.test.ts +1 -1
  276. package/src/util/color_ramp.ts +5 -5
  277. package/src/util/config.ts +2 -2
  278. package/src/util/dispatcher.ts +1 -1
  279. package/src/util/dom.ts +2 -2
  280. package/src/util/evented.ts +1 -1
  281. package/src/util/find_pole_of_inaccessibility.ts +3 -3
  282. package/src/util/image.ts +5 -5
  283. package/src/util/performance.ts +7 -7
  284. package/src/util/request_manager.ts +4 -4
  285. package/src/util/resolve_tokens.ts +4 -4
  286. package/src/util/struct_array.test.ts +1 -1
  287. package/src/util/struct_array.ts +15 -15
  288. package/src/util/task_queue.ts +3 -3
  289. package/src/util/tile_request_cache.ts +3 -3
  290. package/src/util/transferable_grid_index.ts +4 -4
  291. package/src/util/util.ts +8 -8
  292. package/src/util/web_worker.ts +4 -68
  293. package/src/util/web_worker_transfer.test.ts +3 -0
  294. package/src/util/web_worker_transfer.ts +21 -17
  295. package/src/util/worker_pool.ts +1 -1
  296. package/build/.eslintrc +0 -21
  297. package/build/glsl_to_js.js +0 -12
  298. package/build/post-ts-build.js +0 -43
  299. package/build/release-notes.md.ejs +0 -8
  300. package/build/test/build-tape.js +0 -17
  301. package/build/web_worker_replacement.js +0 -5
  302. package/dist/package.json +0 -1
  303. package/src/style-spec/validate_spec.test.ts +0 -29
  304. package/src/symbol/shaping.test.ts +0 -392
  305. package/src/types/glsl.d.ts +0 -4
@@ -1,6 +1,6 @@
1
1
  import AttributionControl from './attribution_control';
2
2
  import {createMap as globalCreateMap, setWebGlContext, setPerformance, setMatchMedia} from '../../util/test/util';
3
- import simulate from '../../../test/util/simulate_interaction';
3
+ import simulate from '../../../test/unit/lib/simulate_interaction';
4
4
 
5
5
  function createMap() {
6
6
 
@@ -35,7 +35,7 @@ describe('AttributionControl', () => {
35
35
  map.addControl(new AttributionControl());
36
36
 
37
37
  expect(
38
- map.getContainer().querySelectorAll('.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib')
38
+ map.getContainer().querySelectorAll('.maplibregl-ctrl-bottom-right .maplibregl-ctrl-attrib')
39
39
  ).toHaveLength(1);
40
40
  });
41
41
 
@@ -43,7 +43,7 @@ describe('AttributionControl', () => {
43
43
  map.addControl(new AttributionControl(), 'top-left');
44
44
 
45
45
  expect(
46
- map.getContainer().querySelectorAll('.maplibregl-ctrl-top-left .maplibregl-ctrl-attrib')
46
+ map.getContainer().querySelectorAll('.maplibregl-ctrl-top-left .maplibregl-ctrl-attrib')
47
47
  ).toHaveLength(1);
48
48
  });
49
49
 
@@ -51,14 +51,15 @@ describe('AttributionControl', () => {
51
51
  Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 700, configurable: true});
52
52
 
53
53
  let attributionControl = new AttributionControl({
54
- compact: true
54
+ compact: true,
55
+ customAttribution: 'MapLibre'
55
56
  });
56
57
  map.addControl(attributionControl);
57
58
 
58
59
  const container = map.getContainer();
59
60
 
60
61
  expect(
61
- container.querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')
62
+ container.querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')
62
63
  ).toHaveLength(1);
63
64
  map.removeControl(attributionControl);
64
65
 
@@ -69,45 +70,75 @@ describe('AttributionControl', () => {
69
70
 
70
71
  map.addControl(attributionControl);
71
72
  expect(
72
- container.querySelectorAll('.maplibregl-ctrl-attrib:not(.maplibregl-compact)')
73
+ container.querySelectorAll('.maplibregl-ctrl-attrib:not(.maplibregl-compact)')
73
74
  ).toHaveLength(1);
74
75
  });
75
76
 
76
- test('appears in compact mode if container is less then 640 pixel wide', () => {
77
+ test('appears in compact mode if container is less then 640 pixel wide and attributions are not empty', () => {
78
+ Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 700, configurable: true});
79
+ const attributionControl = new AttributionControl({
80
+ customAttribution: 'MapLibre'
81
+ });
82
+ map.addControl(attributionControl);
83
+
84
+ const container = map.getContainer();
85
+
86
+ expect(
87
+ container.querySelectorAll('.maplibregl-ctrl-attrib:not(.maplibregl-compact)')
88
+ ).toHaveLength(1);
89
+
90
+ Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 600, configurable: true});
91
+ map.resize();
92
+
93
+ expect(
94
+ container.querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')
95
+ ).toHaveLength(1);
96
+
97
+ expect(
98
+ container.querySelectorAll('.maplibregl-attrib-empty')
99
+ ).toHaveLength(0);
100
+ });
101
+
102
+ test('does not appear in compact mode if container is less then 640 pixel wide and attributions are empty', () => {
77
103
  Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 700, configurable: true});
78
104
  map.addControl(new AttributionControl());
79
105
 
80
106
  const container = map.getContainer();
81
107
 
82
108
  expect(
83
- container.querySelectorAll('.maplibregl-ctrl-attrib:not(.maplibregl-compact)')
109
+ container.querySelectorAll('.maplibregl-ctrl-attrib:not(.maplibregl-compact)')
84
110
  ).toHaveLength(1);
85
111
 
86
112
  Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 600, configurable: true});
87
113
  map.resize();
88
114
 
89
115
  expect(
90
- container.querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')
116
+ container.querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')
117
+ ).toHaveLength(0);
118
+
119
+ expect(
120
+ container.querySelectorAll('.maplibregl-attrib-empty')
91
121
  ).toHaveLength(1);
92
122
  });
93
123
 
94
124
  test('compact mode control toggles attribution', () => {
95
125
  map.addControl(new AttributionControl({
96
- compact: true
126
+ compact: true,
127
+ customAttribution: 'MapLibre'
97
128
  }));
98
129
 
99
130
  const container = map.getContainer();
100
131
  const toggle = container.querySelector('.maplibregl-ctrl-attrib-button');
101
132
 
102
- expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(0);
133
+ expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(1);
103
134
 
104
135
  simulate.click(toggle);
105
136
 
106
- expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(1);
137
+ expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(0);
107
138
 
108
139
  simulate.click(toggle);
109
140
 
110
- expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(0);
141
+ expect(container.querySelectorAll('.maplibregl-compact-show')).toHaveLength(1);
111
142
  });
112
143
 
113
144
  test('dedupes attributions that are substrings of others', done => {
@@ -325,23 +356,27 @@ describe('AttributionControl test regarding the HTML elements details and summar
325
356
  expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBe('');
326
357
  });
327
358
 
328
- test('The attribute open="" SHOULD change on resize from size > 640 to <= 640 and and vice versa.', () => {
359
+ test('The attribute open="" SHOULD exist after resize from size > 640 to <= 640 and and vice versa.', () => {
329
360
  Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 640, configurable: true});
330
361
  const attributionControl = new AttributionControl({
362
+ customAttribution: 'MapLibre'
331
363
  });
332
364
  map.addControl(attributionControl);
333
365
 
334
- expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBeNull();
366
+ expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')).toHaveLength(1);
367
+ expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBe('');
335
368
 
336
369
  Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 641, configurable: true});
337
370
  map.resize();
338
371
 
372
+ expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib:not(.maplibregl-compact)')).toHaveLength(1);
339
373
  expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBe('');
340
374
 
341
375
  Object.defineProperty(map.getCanvasContainer(), 'offsetWidth', {value: 640, configurable: true});
342
376
  map.resize();
343
377
 
344
- expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBeNull();
378
+ expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib.maplibregl-compact')).toHaveLength(1);
379
+ expect(map.getContainer().querySelectorAll('.maplibregl-ctrl-attrib')[0].getAttribute('open')).toBe('');
345
380
  });
346
381
 
347
382
  test('The attribute open="" should NOT change on resize from > 640 to another > 640.', () => {
@@ -5,8 +5,8 @@ import type Map from '../map';
5
5
  import type {ControlPosition, IControl} from './control';
6
6
 
7
7
  type AttributionOptions = {
8
- compact?: boolean;
9
- customAttribution?: string | Array<string>;
8
+ compact?: boolean;
9
+ customAttribution?: string | Array<string>;
10
10
  };
11
11
 
12
12
  /**
@@ -25,6 +25,7 @@ type AttributionOptions = {
25
25
  class AttributionControl implements IControl {
26
26
  options: AttributionOptions;
27
27
  _map: Map;
28
+ _compact: boolean;
28
29
  _container: HTMLElement;
29
30
  _innerContainer: HTMLElement;
30
31
  _compactButton: HTMLElement;
@@ -39,7 +40,8 @@ class AttributionControl implements IControl {
39
40
  bindAll([
40
41
  '_toggleAttribution',
41
42
  '_updateData',
42
- '_updateCompact'
43
+ '_updateCompact',
44
+ '_updateCompactMinimize'
43
45
  ], this);
44
46
  }
45
47
 
@@ -49,18 +51,20 @@ class AttributionControl implements IControl {
49
51
 
50
52
  onAdd(map: Map) {
51
53
  this._map = map;
54
+ this._compact = this.options && this.options.compact;
52
55
  this._container = DOM.create('details', 'maplibregl-ctrl maplibregl-ctrl-attrib mapboxgl-ctrl mapboxgl-ctrl-attrib');
53
56
  this._compactButton = DOM.create('summary', 'maplibregl-ctrl-attrib-button mapboxgl-ctrl-attrib-button', this._container);
54
57
  this._compactButton.addEventListener('click', this._toggleAttribution);
55
58
  this._setElementTitle(this._compactButton, 'ToggleAttribution');
56
59
  this._innerContainer = DOM.create('div', 'maplibregl-ctrl-attrib-inner mapboxgl-ctrl-attrib-inner', this._container);
57
60
 
58
- this._updateCompact();
59
61
  this._updateAttributions();
62
+ this._updateCompact();
60
63
 
61
64
  this._map.on('styledata', this._updateData);
62
65
  this._map.on('sourcedata', this._updateData);
63
66
  this._map.on('resize', this._updateCompact);
67
+ this._map.on('drag', this._updateCompactMinimize);
64
68
 
65
69
  return this._container;
66
70
  }
@@ -71,8 +75,10 @@ class AttributionControl implements IControl {
71
75
  this._map.off('styledata', this._updateData);
72
76
  this._map.off('sourcedata', this._updateData);
73
77
  this._map.off('resize', this._updateCompact);
78
+ this._map.off('drag', this._updateCompactMinimize);
74
79
 
75
80
  this._map = undefined;
81
+ this._compact = undefined;
76
82
  this._attribHTML = undefined;
77
83
  }
78
84
 
@@ -83,10 +89,14 @@ class AttributionControl implements IControl {
83
89
  }
84
90
 
85
91
  _toggleAttribution() {
86
- if (this._container.classList.contains('maplibregl-compact-show') || this._container.classList.contains('mapboxgl-compact-show')) {
87
- this._container.classList.remove('maplibregl-compact-show', 'mapboxgl-compact-show');
88
- } else {
89
- this._container.classList.add('maplibregl-compact-show', 'mapboxgl-compact-show');
92
+ if (this._container.classList.contains('maplibregl-compact')) {
93
+ if (this._container.classList.contains('maplibregl-compact-show')) {
94
+ this._container.setAttribute('open', '');
95
+ this._container.classList.remove('maplibregl-compact-show', 'mapboxgl-compact-show');
96
+ } else {
97
+ this._container.classList.add('maplibregl-compact-show', 'mapboxgl-compact-show');
98
+ this._container.removeAttribute('open');
99
+ }
90
100
  }
91
101
  }
92
102
 
@@ -129,6 +139,9 @@ class AttributionControl implements IControl {
129
139
  }
130
140
  }
131
141
 
142
+ // remove any entries that are whitespace
143
+ attributions = attributions.filter(e => String(e).trim());
144
+
132
145
  // remove any entries that are substrings of another entry.
133
146
  // first sort by length so that substrings come first
134
147
  attributions.sort((a, b) => a.length - b.length);
@@ -151,20 +164,18 @@ class AttributionControl implements IControl {
151
164
  } else {
152
165
  this._container.classList.add('maplibregl-attrib-empty', 'mapboxgl-attrib-empty');
153
166
  }
167
+ this._updateCompact();
154
168
  // remove old DOM node from _editLink
155
169
  this._editLink = null;
156
170
  }
157
171
 
158
172
  _updateCompact() {
159
- const compact = this.options && this.options.compact;
160
- if (this._map.getCanvasContainer().offsetWidth <= 640 || compact) {
161
- if (compact === false) {
173
+ if (this._map.getCanvasContainer().offsetWidth <= 640 || this._compact) {
174
+ if (this._compact === false) {
162
175
  this._container.setAttribute('open', '');
163
- } else {
164
- if (!this._container.classList.contains('maplibregl-compact')) {
165
- this._container.removeAttribute('open');
166
- this._container.classList.add('maplibregl-compact', 'mapboxgl-compact');
167
- }
176
+ } else if (!this._container.classList.contains('maplibregl-compact') && !this._container.classList.contains('maplibregl-attrib-empty')) {
177
+ this._container.setAttribute('open', '');
178
+ this._container.classList.add('maplibregl-compact', 'mapboxgl-compact', 'maplibregl-compact-show', 'mapboxgl-compact-show');
168
179
  }
169
180
  } else {
170
181
  this._container.setAttribute('open', '');
@@ -174,6 +185,14 @@ class AttributionControl implements IControl {
174
185
  }
175
186
  }
176
187
 
188
+ _updateCompactMinimize() {
189
+ if (this._container.classList.contains('maplibregl-compact')) {
190
+ if (this._container.classList.contains('maplibregl-compact-show')) {
191
+ this._container.classList.remove('maplibregl-compact-show', 'mapboxgl-compact-show');
192
+ }
193
+ }
194
+ }
195
+
177
196
  }
178
197
 
179
198
  export default AttributionControl;
@@ -45,46 +45,46 @@ import type Map from '../map';
45
45
  * };
46
46
  */
47
47
  export interface IControl {
48
- /**
49
- * Register a control on the map and give it a chance to register event listeners
50
- * and resources. This method is called by {@link Map#addControl}
51
- * internally.
52
- *
53
- * @function
54
- * @memberof IControl
55
- * @instance
56
- * @name onAdd
57
- * @param {Map} map the Map this control will be added to
58
- * @returns {HTMLElement} The control's container element. This should
59
- * be created by the control and returned by onAdd without being attached
60
- * to the DOM: the map will insert the control's element into the DOM
61
- * as necessary.
62
- */
48
+ /**
49
+ * Register a control on the map and give it a chance to register event listeners
50
+ * and resources. This method is called by {@link Map#addControl}
51
+ * internally.
52
+ *
53
+ * @function
54
+ * @memberof IControl
55
+ * @instance
56
+ * @name onAdd
57
+ * @param {Map} map the Map this control will be added to
58
+ * @returns {HTMLElement} The control's container element. This should
59
+ * be created by the control and returned by onAdd without being attached
60
+ * to the DOM: the map will insert the control's element into the DOM
61
+ * as necessary.
62
+ */
63
63
  onAdd(map: Map): HTMLElement;
64
- /**
65
- * Unregister a control on the map and give it a chance to detach event listeners
66
- * and resources. This method is called by {@link Map#removeControl}
67
- * internally.
68
- *
69
- * @function
70
- * @memberof IControl
71
- * @instance
72
- * @name onRemove
73
- * @param {Map} map the Map this control will be removed from
74
- * @returns {undefined} there is no required return value for this method
75
- */
64
+ /**
65
+ * Unregister a control on the map and give it a chance to detach event listeners
66
+ * and resources. This method is called by {@link Map#removeControl}
67
+ * internally.
68
+ *
69
+ * @function
70
+ * @memberof IControl
71
+ * @instance
72
+ * @name onRemove
73
+ * @param {Map} map the Map this control will be removed from
74
+ * @returns {undefined} there is no required return value for this method
75
+ */
76
76
  onRemove(map: Map): void;
77
- /**
78
- * Optionally provide a default position for this control. If this method
79
- * is implemented and {@link Map#addControl} is called without the `position`
80
- * parameter, the value returned by getDefaultPosition will be used as the
81
- * control's position.
82
- *
83
- * @function
84
- * @memberof IControl
85
- * @instance
86
- * @name getDefaultPosition
87
- * @returns {ControlPosition} a control position, one of the values valid in addControl.
88
- */
89
- readonly getDefaultPosition?: () => ControlPosition;
77
+ /**
78
+ * Optionally provide a default position for this control. If this method
79
+ * is implemented and {@link Map#addControl} is called without the `position`
80
+ * parameter, the value returned by getDefaultPosition will be used as the
81
+ * control's position.
82
+ *
83
+ * @function
84
+ * @memberof IControl
85
+ * @instance
86
+ * @name getDefaultPosition
87
+ * @returns {ControlPosition} a control position, one of the values valid in addControl.
88
+ */
89
+ readonly getDefaultPosition?: () => ControlPosition;
90
90
  }
@@ -6,7 +6,7 @@ import type Map from '../map';
6
6
  import type {IControl} from './control';
7
7
 
8
8
  type FullscreenOptions = {
9
- container?: HTMLElement;
9
+ container?: HTMLElement;
10
10
  };
11
11
 
12
12
  /**
@@ -222,7 +222,7 @@ describe('GeolocateControl with no options', () => {
222
222
  expect(lngLatAsFixed(map.getCenter(), 4)).toEqual({'lat': '10.0000', 'lng': '20.0000'});
223
223
  expect(geolocate._userLocationDotMarker._map).toBeTruthy();
224
224
  expect(
225
- geolocate._userLocationDotMarker._element.classList.contains('maplibregl-user-location-dot-stale')
225
+ geolocate._userLocationDotMarker._element.classList.contains('maplibregl-user-location-dot-stale')
226
226
  ).toBeFalsy();
227
227
  map.once('moveend', () => {
228
228
  expect(lngLatAsFixed(map.getCenter(), 4)).toEqual({'lat': '40.0000', 'lng': '50.0000'});
@@ -10,11 +10,11 @@ import type {FitBoundsOptions} from '../camera';
10
10
  import type {IControl} from './control';
11
11
 
12
12
  type GeolocateOptions = {
13
- positionOptions?: PositionOptions;
14
- fitBoundsOptions?: FitBoundsOptions;
15
- trackUserLocation?: boolean;
16
- showAccuracyCircle?: boolean;
17
- showUserLocation?: boolean;
13
+ positionOptions?: PositionOptions;
14
+ fitBoundsOptions?: FitBoundsOptions;
15
+ trackUserLocation?: boolean;
16
+ showAccuracyCircle?: boolean;
17
+ showUserLocation?: boolean;
18
18
  };
19
19
 
20
20
  const defaultOptions: GeolocateOptions = {
@@ -173,29 +173,29 @@ class GeolocateControl extends Evented implements IControl {
173
173
 
174
174
  _setErrorState() {
175
175
  switch (this._watchState) {
176
- case 'WAITING_ACTIVE':
177
- this._watchState = 'ACTIVE_ERROR';
178
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
179
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active-error', 'mapboxgl-ctrl-geolocate-active-error');
180
- break;
181
- case 'ACTIVE_LOCK':
182
- this._watchState = 'ACTIVE_ERROR';
183
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
184
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active-error', 'mapboxgl-ctrl-geolocate-active-error');
185
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
186
- // turn marker grey
187
- break;
188
- case 'BACKGROUND':
189
- this._watchState = 'BACKGROUND_ERROR';
190
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background', 'mapboxgl-ctrl-geolocate-background');
191
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-background-error', 'mapboxgl-ctrl-geolocate-background-error');
192
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
193
- // turn marker grey
194
- break;
195
- case 'ACTIVE_ERROR':
196
- break;
197
- default:
198
- assert(false, `Unexpected watchState ${this._watchState}`);
176
+ case 'WAITING_ACTIVE':
177
+ this._watchState = 'ACTIVE_ERROR';
178
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
179
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active-error', 'mapboxgl-ctrl-geolocate-active-error');
180
+ break;
181
+ case 'ACTIVE_LOCK':
182
+ this._watchState = 'ACTIVE_ERROR';
183
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
184
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active-error', 'mapboxgl-ctrl-geolocate-active-error');
185
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
186
+ // turn marker grey
187
+ break;
188
+ case 'BACKGROUND':
189
+ this._watchState = 'BACKGROUND_ERROR';
190
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background', 'mapboxgl-ctrl-geolocate-background');
191
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-background-error', 'mapboxgl-ctrl-geolocate-background-error');
192
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
193
+ // turn marker grey
194
+ break;
195
+ case 'ACTIVE_ERROR':
196
+ break;
197
+ default:
198
+ assert(false, `Unexpected watchState ${this._watchState}`);
199
199
  }
200
200
  }
201
201
 
@@ -228,23 +228,23 @@ class GeolocateControl extends Evented implements IControl {
228
228
  this._lastKnownPosition = position;
229
229
 
230
230
  switch (this._watchState) {
231
- case 'WAITING_ACTIVE':
232
- case 'ACTIVE_LOCK':
233
- case 'ACTIVE_ERROR':
234
- this._watchState = 'ACTIVE_LOCK';
235
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
236
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active-error', 'mapboxgl-ctrl-geolocate-active-error');
237
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
238
- break;
239
- case 'BACKGROUND':
240
- case 'BACKGROUND_ERROR':
241
- this._watchState = 'BACKGROUND';
242
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
243
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background-error', 'mapboxgl-ctrl-geolocate-background-error');
244
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-background', 'mapboxgl-ctrl-geolocate-background');
245
- break;
246
- default:
247
- assert(false, `Unexpected watchState ${this._watchState}`);
231
+ case 'WAITING_ACTIVE':
232
+ case 'ACTIVE_LOCK':
233
+ case 'ACTIVE_ERROR':
234
+ this._watchState = 'ACTIVE_LOCK';
235
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
236
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active-error', 'mapboxgl-ctrl-geolocate-active-error');
237
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
238
+ break;
239
+ case 'BACKGROUND':
240
+ case 'BACKGROUND_ERROR':
241
+ this._watchState = 'BACKGROUND';
242
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
243
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background-error', 'mapboxgl-ctrl-geolocate-background-error');
244
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-background', 'mapboxgl-ctrl-geolocate-background');
245
+ break;
246
+ default:
247
+ assert(false, `Unexpected watchState ${this._watchState}`);
248
248
  }
249
249
  }
250
250
 
@@ -429,23 +429,23 @@ class GeolocateControl extends Evented implements IControl {
429
429
  }
430
430
 
431
431
  /**
432
- * Programmatically request and move the map to the user's location.
433
- *
434
- * @returns {boolean} Returns `false` if called before control was added to a map, otherwise returns `true`.
435
- * @example
436
- * // Initialize the geolocate control.
437
- * var geolocate = new maplibregl.GeolocateControl({
438
- * positionOptions: {
439
- * enableHighAccuracy: true
440
- * },
441
- * trackUserLocation: true
442
- * });
443
- * // Add the control to the map.
444
- * map.addControl(geolocate);
445
- * map.on('load', function() {
446
- * geolocate.trigger();
447
- * });
448
- */
432
+ * Programmatically request and move the map to the user's location.
433
+ *
434
+ * @returns {boolean} Returns `false` if called before control was added to a map, otherwise returns `true`.
435
+ * @example
436
+ * // Initialize the geolocate control.
437
+ * var geolocate = new maplibregl.GeolocateControl({
438
+ * positionOptions: {
439
+ * enableHighAccuracy: true
440
+ * },
441
+ * trackUserLocation: true
442
+ * });
443
+ * // Add the control to the map.
444
+ * map.addControl(geolocate);
445
+ * map.on('load', function() {
446
+ * geolocate.trigger();
447
+ * });
448
+ */
449
449
  trigger() {
450
450
  if (!this._setup) {
451
451
  warnOnce('Geolocate control triggered before added to a map');
@@ -454,53 +454,53 @@ class GeolocateControl extends Evented implements IControl {
454
454
  if (this.options.trackUserLocation) {
455
455
  // update watchState and do any outgoing state cleanup
456
456
  switch (this._watchState) {
457
- case 'OFF':
457
+ case 'OFF':
458
458
  // turn on the Geolocate Control
459
- this._watchState = 'WAITING_ACTIVE';
460
-
461
- this.fire(new Event('trackuserlocationstart'));
462
- break;
463
- case 'WAITING_ACTIVE':
464
- case 'ACTIVE_LOCK':
465
- case 'ACTIVE_ERROR':
466
- case 'BACKGROUND_ERROR':
459
+ this._watchState = 'WAITING_ACTIVE';
460
+
461
+ this.fire(new Event('trackuserlocationstart'));
462
+ break;
463
+ case 'WAITING_ACTIVE':
464
+ case 'ACTIVE_LOCK':
465
+ case 'ACTIVE_ERROR':
466
+ case 'BACKGROUND_ERROR':
467
467
  // turn off the Geolocate Control
468
- numberOfWatches--;
469
- noTimeout = false;
470
- this._watchState = 'OFF';
471
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
472
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
473
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active-error', 'mapboxgl-ctrl-geolocate-active-error');
474
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background', 'mapboxgl-ctrl-geolocate-background');
475
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background-error', 'mapboxgl-ctrl-geolocate-background-error');
476
-
477
- this.fire(new Event('trackuserlocationend'));
478
- break;
479
- case 'BACKGROUND':
480
- this._watchState = 'ACTIVE_LOCK';
481
- this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background', 'mapboxgl-ctrl-geolocate-background');
482
- // set camera to last known location
483
- if (this._lastKnownPosition) this._updateCamera(this._lastKnownPosition);
468
+ numberOfWatches--;
469
+ noTimeout = false;
470
+ this._watchState = 'OFF';
471
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
472
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
473
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-active-error', 'mapboxgl-ctrl-geolocate-active-error');
474
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background', 'mapboxgl-ctrl-geolocate-background');
475
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background-error', 'mapboxgl-ctrl-geolocate-background-error');
484
476
 
485
- this.fire(new Event('trackuserlocationstart'));
486
- break;
487
- default:
488
- assert(false, `Unexpected watchState ${this._watchState}`);
477
+ this.fire(new Event('trackuserlocationend'));
478
+ break;
479
+ case 'BACKGROUND':
480
+ this._watchState = 'ACTIVE_LOCK';
481
+ this._geolocateButton.classList.remove('maplibregl-ctrl-geolocate-background', 'mapboxgl-ctrl-geolocate-background');
482
+ // set camera to last known location
483
+ if (this._lastKnownPosition) this._updateCamera(this._lastKnownPosition);
484
+
485
+ this.fire(new Event('trackuserlocationstart'));
486
+ break;
487
+ default:
488
+ assert(false, `Unexpected watchState ${this._watchState}`);
489
489
  }
490
490
 
491
491
  // incoming state setup
492
492
  switch (this._watchState) {
493
- case 'WAITING_ACTIVE':
494
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
495
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
496
- break;
497
- case 'ACTIVE_LOCK':
498
- this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
499
- break;
500
- case 'OFF':
501
- break;
502
- default:
503
- assert(false, `Unexpected watchState ${this._watchState}`);
493
+ case 'WAITING_ACTIVE':
494
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-waiting', 'mapboxgl-ctrl-geolocate-waiting');
495
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
496
+ break;
497
+ case 'ACTIVE_LOCK':
498
+ this._geolocateButton.classList.add('maplibregl-ctrl-geolocate-active', 'mapboxgl-ctrl-geolocate-active');
499
+ break;
500
+ case 'OFF':
501
+ break;
502
+ default:
503
+ assert(false, `Unexpected watchState ${this._watchState}`);
504
504
  }
505
505
 
506
506
  // manage geolocation.watchPosition / geolocation.clearWatch