maplair 4.3.0 → 4.5.0

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 (191) hide show
  1. package/CHANGELOG.md +151 -8
  2. package/dist/esm/control/AttributionControl.js +30 -13
  3. package/dist/esm/control/AttributionControl.js.map +1 -1
  4. package/dist/esm/control/ButtonControl.js +0 -1
  5. package/dist/esm/control/ButtonControl.js.map +1 -1
  6. package/dist/esm/control/ContextMenu.js +1 -1
  7. package/dist/esm/control/ContextMenu.js.map +1 -1
  8. package/dist/esm/control/Control.js +16 -11
  9. package/dist/esm/control/Control.js.map +1 -1
  10. package/dist/esm/control/FullscreenControl.js +0 -1
  11. package/dist/esm/control/FullscreenControl.js.map +1 -1
  12. package/dist/esm/control/LayersControl.js +46 -27
  13. package/dist/esm/control/LayersControl.js.map +1 -1
  14. package/dist/esm/control/RotateControl.js +0 -1
  15. package/dist/esm/control/RotateControl.js.map +1 -1
  16. package/dist/esm/control/ScaleControl.js +7 -8
  17. package/dist/esm/control/ScaleControl.js.map +1 -1
  18. package/dist/esm/control/SideBySideControl.js +3 -2
  19. package/dist/esm/control/SideBySideControl.js.map +1 -1
  20. package/dist/esm/control/ZoomControl.js +14 -13
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Events.js +3 -2
  23. package/dist/esm/core/Events.js.map +1 -1
  24. package/dist/esm/core/Util.js +17 -5
  25. package/dist/esm/core/Util.js.map +1 -1
  26. package/dist/esm/dom/DomEvent.PointerEvents.js +72 -2
  27. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  28. package/dist/esm/dom/DomEvent.js +4 -7
  29. package/dist/esm/dom/DomEvent.js.map +1 -1
  30. package/dist/esm/dom/DomUtil.js +5 -5
  31. package/dist/esm/dom/DomUtil.js.map +1 -1
  32. package/dist/esm/dom/Draggable.js +10 -8
  33. package/dist/esm/dom/Draggable.js.map +1 -1
  34. package/dist/esm/geo/LatLng.js +24 -35
  35. package/dist/esm/geo/LatLng.js.map +1 -1
  36. package/dist/esm/geo/LatLngBounds.js +6 -3
  37. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  38. package/dist/esm/geometry/Bounds.js +2 -2
  39. package/dist/esm/geometry/Bounds.js.map +1 -1
  40. package/dist/esm/geometry/Point.js +16 -19
  41. package/dist/esm/geometry/Point.js.map +1 -1
  42. package/dist/esm/geometry/PolyUtil.js +10 -3
  43. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  44. package/dist/esm/geometry/Transformation.js +1 -7
  45. package/dist/esm/geometry/Transformation.js.map +1 -1
  46. package/dist/esm/layer/BlanketOverlay.js +3 -2
  47. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  48. package/dist/esm/layer/DivOverlay.js +25 -25
  49. package/dist/esm/layer/DivOverlay.js.map +1 -1
  50. package/dist/esm/layer/ImageOverlay.js +8 -5
  51. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  52. package/dist/esm/layer/Layer.js +12 -7
  53. package/dist/esm/layer/Layer.js.map +1 -1
  54. package/dist/esm/layer/Popup.js +33 -15
  55. package/dist/esm/layer/Popup.js.map +1 -1
  56. package/dist/esm/layer/Tooltip.js +48 -56
  57. package/dist/esm/layer/Tooltip.js.map +1 -1
  58. package/dist/esm/layer/VideoOverlay.js +2 -2
  59. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  60. package/dist/esm/layer/marker/DivIcon.js +4 -8
  61. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  62. package/dist/esm/layer/marker/Icon.js +37 -17
  63. package/dist/esm/layer/marker/Icon.js.map +1 -1
  64. package/dist/esm/layer/marker/Marker.Drag.js +11 -12
  65. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  66. package/dist/esm/layer/marker/Marker.js +54 -53
  67. package/dist/esm/layer/marker/Marker.js.map +1 -1
  68. package/dist/esm/layer/marker/SvgIcon.js +1 -1
  69. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  70. package/dist/esm/layer/tile/GridLayer.js +29 -21
  71. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  72. package/dist/esm/layer/tile/TileLayer.js +19 -15
  73. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  74. package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
  75. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  76. package/dist/esm/layer/vector/Canvas.js +45 -94
  77. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  78. package/dist/esm/layer/vector/Circle.js +8 -9
  79. package/dist/esm/layer/vector/Circle.js.map +1 -1
  80. package/dist/esm/layer/vector/CircleMarker.js +15 -4
  81. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  82. package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
  83. package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
  84. package/dist/esm/layer/vector/Path.js +10 -5
  85. package/dist/esm/layer/vector/Path.js.map +1 -1
  86. package/dist/esm/layer/vector/Polygon.js +10 -11
  87. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  88. package/dist/esm/layer/vector/Polyline.js +19 -26
  89. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  90. package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
  91. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  92. package/dist/esm/layer/vector/Renderer.js +16 -0
  93. package/dist/esm/layer/vector/Renderer.js.map +1 -1
  94. package/dist/esm/layer/vector/SVG.js +3 -3
  95. package/dist/esm/layer/vector/SVG.js.map +1 -1
  96. package/dist/esm/map/Map.Rotation.js +9 -11
  97. package/dist/esm/map/Map.Rotation.js.map +1 -1
  98. package/dist/esm/map/Map.js +158 -71
  99. package/dist/esm/map/Map.js.map +1 -1
  100. package/dist/esm/map/MapSync.js +2 -5
  101. package/dist/esm/map/MapSync.js.map +1 -1
  102. package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
  103. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  104. package/dist/esm/map/handler/DisplaceHandler.js +68 -30
  105. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  106. package/dist/esm/map/handler/DragHandler.js +7 -2
  107. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  108. package/dist/esm/map/handler/KeyboardHandler.js +3 -5
  109. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  110. package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
  111. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  112. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
  113. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  114. package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
  115. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  116. package/dist/esm/map/handler/TapHoldHandler.js +8 -20
  117. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  118. package/dist/esm/package.js +1 -1
  119. package/dist/maplair-global-src.js +970 -810
  120. package/dist/maplair-global-src.js.map +1 -1
  121. package/dist/maplair-global.js +2 -2
  122. package/dist/maplair-global.js.map +1 -1
  123. package/dist/maplair-src.js +970 -810
  124. package/dist/maplair-src.js.map +1 -1
  125. package/dist/maplair.css +1 -1
  126. package/dist/maplair.js +2 -2
  127. package/dist/maplair.js.map +1 -1
  128. package/i18n/en.json +1 -0
  129. package/package.json +1 -1
  130. package/src/control/AttributionControl.js +37 -11
  131. package/src/control/ButtonControl.js +0 -1
  132. package/src/control/ContextMenu.js +1 -1
  133. package/src/control/Control.js +13 -16
  134. package/src/control/FullscreenControl.js +0 -1
  135. package/src/control/LayersControl.js +61 -37
  136. package/src/control/RotateControl.js +0 -1
  137. package/src/control/ScaleControl.js +10 -8
  138. package/src/control/SideBySideControl.js +4 -2
  139. package/src/control/ZoomControl.js +11 -13
  140. package/src/core/Events.js +6 -2
  141. package/src/core/Util.js +17 -4
  142. package/src/dom/DomEvent.PointerEvents.js +68 -2
  143. package/src/dom/DomEvent.js +5 -17
  144. package/src/dom/DomUtil.js +5 -5
  145. package/src/dom/Draggable.js +11 -8
  146. package/src/geo/LatLng.js +24 -37
  147. package/src/geo/LatLngBounds.js +10 -4
  148. package/src/geometry/Bounds.js +3 -3
  149. package/src/geometry/Point.js +22 -28
  150. package/src/geometry/PolyUtil.js +12 -3
  151. package/src/geometry/Transformation.js +1 -8
  152. package/src/layer/BlanketOverlay.js +6 -3
  153. package/src/layer/DivOverlay.js +30 -32
  154. package/src/layer/ImageOverlay.js +12 -9
  155. package/src/layer/Layer.js +19 -7
  156. package/src/layer/Popup.js +41 -21
  157. package/src/layer/Tooltip.js +50 -70
  158. package/src/layer/VideoOverlay.js +2 -2
  159. package/src/layer/marker/DivIcon.js +3 -6
  160. package/src/layer/marker/Icon.js +41 -20
  161. package/src/layer/marker/Marker.Drag.js +22 -24
  162. package/src/layer/marker/Marker.js +71 -64
  163. package/src/layer/marker/SvgIcon.js +1 -1
  164. package/src/layer/tile/GridLayer.js +41 -30
  165. package/src/layer/tile/TileLayer.js +31 -21
  166. package/src/layer/tile/WMSTileLayer.js +4 -2
  167. package/src/layer/vector/Canvas.js +53 -149
  168. package/src/layer/vector/Circle.js +13 -13
  169. package/src/layer/vector/CircleMarker.js +16 -3
  170. package/src/layer/vector/Path.ZoomStyles.js +5 -3
  171. package/src/layer/vector/Path.js +11 -5
  172. package/src/layer/vector/Polygon.js +11 -10
  173. package/src/layer/vector/Polyline.js +20 -21
  174. package/src/layer/vector/Renderer.getRenderer.js +2 -1
  175. package/src/layer/vector/Renderer.js +21 -3
  176. package/src/layer/vector/SVG.js +3 -3
  177. package/src/map/Map.Rotation.js +13 -9
  178. package/src/map/Map.js +195 -83
  179. package/src/map/MapSync.js +2 -2
  180. package/src/map/handler/BoxZoomHandler.js +5 -0
  181. package/src/map/handler/DisplaceHandler.js +53 -7
  182. package/src/map/handler/DragHandler.js +5 -5
  183. package/src/map/handler/KeyboardHandler.js +5 -10
  184. package/src/map/handler/PinchZoomHandler.js +4 -4
  185. package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
  186. package/src/map/handler/TapDragZoomHandler.js +2 -2
  187. package/src/map/handler/TapHoldHandler.js +13 -25
  188. package/src/maplair.css +50 -10
  189. package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
  190. package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
  191. package/src/dom/DomEvent.DoubleTap.js +0 -143
package/CHANGELOG.md CHANGED
@@ -3,6 +3,149 @@ Maplair Changelog
3
3
 
4
4
  (all changes of Leaflet without author notice are by [@mourner](https://github.com/mourner))
5
5
 
6
+ ## 4.5.0 (2026-11-16)
7
+
8
+ ⚠️ Despite the minor version, this release contains breaking changes ported from Leaflet, see the refactorings below; e.g. the list of a collapsed layers control is only built when it expands, and circle markers throw on a radius that is not a number.
9
+
10
+ ### Leaflet, since 4.4.0
11
+
12
+ Ported from Leaflet (changes without author notice are by [@mourner](https://github.com/mourner))
13
+
14
+ #### ❇️ New Features
15
+
16
+ * Marker: `originalEvent` in the `dragstart` and `movestart` events, also for keyboard drags, by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10574
17
+ * `Point#scaleBy()` and `#unscaleBy()` accept arrays and plain objects by [@Kernel-Hunter](https://github.com/Kernel-Hunter) in https://github.com/Leaflet/Leaflet/pull/10573
18
+ * WMSTileLayer: params set to `undefined` or `null` are left out of the requests, so `setParams()` can clear them, by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10590
19
+
20
+ #### ✨ Refactorings (⚠️ Breaking Changes)
21
+
22
+ * LayersControl: the list of a collapsed control is only rebuilt when it expands (or by `selectLayer()`), which made adding n layers O(n²); code reading the inputs of a collapsed control should call `expand()` first, by [@TheNetherWatcher](https://github.com/TheNetherWatcher) in https://github.com/Leaflet/Leaflet/pull/10585
23
+ * `CircleMarker` and `Circle` convert a numeric string radius and throw on a radius that is not a number, also in `setRadius()` and `setStyle()`, in https://github.com/Leaflet/Leaflet/commit/25f1739cbff60934e6e5786a9d34fc40958e8a6a
24
+ * TileLayer: `detectRetina` only requests retina tiles from a device pixel ratio of 1.5, as half-size tiles made labels too small to read at 125% scaling (with [@vpithart](https://github.com/vpithart)) in https://github.com/Leaflet/Leaflet/commit/91854082d36c4d7863ec4a2855fff87a329eb3a2
25
+ * The attribution of a layer with `minZoom` or `maxZoom` is only shown within that zoom range, in https://github.com/Leaflet/Leaflet/commit/77b4e97e695a76335ab4c1c1b17a7651f64851d1
26
+ * Pointers pressed in controls and popups are no longer captured by the map nor listed by `DomEvent.PointerEvents.getPointers()`, by [@Misyuk-T](https://github.com/Misyuk-T) in https://github.com/Leaflet/Leaflet/pull/10567
27
+ * Tile layers zoom their container as a whole during zoom animations, and the private `_animateZoom()` of the map lost its `startAnim` argument, in https://github.com/Leaflet/Leaflet/commit/2ec3814a5e80fd5422a4b75ac2652c61cc083222 and https://github.com/Leaflet/Leaflet/commit/dcd87ddd37c10d1921c9b460f7d8e29df810067f
28
+
29
+ #### ✨ Improvements
30
+
31
+ * Fix the jitter of tiles, markers and overlays during `flyTo()` in https://github.com/Leaflet/Leaflet/commit/40f80ef8250de07d4c96915ca704fc2d0940c7d7
32
+ * Fix zoom animations getting cut short and stuttering on pages with many markers in https://github.com/Leaflet/Leaflet/commit/2ec3814a5e80fd5422a4b75ac2652c61cc083222 and https://github.com/Leaflet/Leaflet/commit/dcd87ddd37c10d1921c9b460f7d8e29df810067f
33
+ * Fix slow `flyTo()` with many image or round markers in https://github.com/Leaflet/Leaflet/commit/582b88c96567d46333500340848945f5201327f0
34
+ * Attach marker tooltips per direction: to the top or bottom of the icon, and `center` ones at the height of `tooltipAnchor`, in https://github.com/Leaflet/Leaflet/commit/fcfca4a1675f29cdc7ebd47107ddc6c0fa0d662a
35
+ * Disable the fading of tiles when printing in https://github.com/Leaflet/Leaflet/commit/42ad4bf593d18776267155a36d135564623e75ec
36
+
37
+ #### ♿️ Accessibility
38
+
39
+ * LayersControl: Enter or Space on the toggle moves the focus into the list, and Escape collapses it and returns the focus to the toggle, by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10560
40
+ * Tooltip: remove it from `aria-describedby` when it closes by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10578
41
+
42
+ #### 🐞 Bugfixes
43
+
44
+ * Fix circle radii and `getBoundsZoom()` for projections that rotate the axes in https://github.com/Leaflet/Leaflet/commit/0d82a025285fc154d7728a0262192768007799ae
45
+ * Use all four corners of `maxBounds` when the projection rotates the axes by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10584
46
+ * Use the middle of a zero-area polygon as its center by [@kevin9327](https://github.com/kevin9327) in https://github.com/Leaflet/Leaflet/pull/10555 and https://github.com/Leaflet/Leaflet/commit/3d14b24bb19abdb406029e22cbc072cbd2a1afc9
47
+ * Fix the NaN distance between antipodal points by [@SwastikTripathi](https://github.com/SwastikTripathi) in https://github.com/Leaflet/Leaflet/pull/10561
48
+ * Ignore a space before the closing brace in template placeholders by [@Kernel-Hunter](https://github.com/Kernel-Hunter) in https://github.com/Leaflet/Leaflet/pull/10562
49
+ * Ignore empty arrays when extending bounds by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10569
50
+ * Don't capture pointers on form controls inside the map, which broke native widgets like the clear button of a search input, by [@Misyuk-T](https://github.com/Misyuk-T) in https://github.com/Leaflet/Leaflet/pull/10567
51
+ * Hit-test canvas renderers at the same z-index topmost first by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10570
52
+ * Only click a canvas layer that the press started on by [@b84330808](https://github.com/b84330808) in https://github.com/Leaflet/Leaflet/pull/10588
53
+ * Apply `setMinZoom()` and `setMaxZoom()` to the zoom the map is heading to by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10571
54
+ * Zoom out to a layer maximum zoom of 0 by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10572
55
+ * Skip the canvas stroke for a string `weight` of 0 by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10581
56
+ * Don't throw when disabling a zoom control that isn't on a map by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10582
57
+ * ScaleControl: round distances under 1 m down instead of up to 1 m by [@SwastikTripathi](https://github.com/SwastikTripathi) in https://github.com/Leaflet/Leaflet/pull/10583
58
+ * Cancel a box zoom in progress when box zoom is disabled by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10587
59
+ * Protect the SVG renderers of custom panes and all overlays from host `max-width` resets by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10589
60
+
61
+ #### 📝 Docs
62
+
63
+ * Explain stopping control events from reaching the map in https://github.com/Leaflet/Leaflet/commit/99e4fa4f937c6a10faf27221da7eed3fa391f355
64
+ * Drop DOMPurify from the security notes in https://github.com/Leaflet/Leaflet/commit/f5bc2297333c83f7c8018039112a05a087b25e4d
65
+ * Assert the GeoJSON coordinate conversions in the specs, and fix nine swapped expectations, by [@dylanpulver](https://github.com/dylanpulver) in https://github.com/Leaflet/Leaflet/pull/10564
66
+ * Fix a debug page broken by the v2 API changes by [@ogchicken](https://github.com/ogchicken) in https://github.com/Leaflet/Leaflet/pull/10586
67
+
68
+ ## 4.4.0 (2026-11-09)
69
+
70
+ ⚠️ Despite the minor version, this release contains breaking changes ported from Leaflet, see the refactorings below; e.g. canvas renderers no longer receive pointer events, `panBy()` is limited by `maxBounds`, and `Point` and `LatLng` throw on coordinates that are not numbers.
71
+
72
+ ### Leaflet, since 4.3.0
73
+
74
+ Ported from Leaflet (changes without author notice are by [@mourner](https://github.com/mourner))
75
+
76
+ #### ❇️ New Features
77
+
78
+ * LayersControl: the option `title` for the toggle button and the label of the list in https://github.com/Leaflet/Leaflet/commit/77387ed1483b5628603b823acd89dc8ec3956403
79
+ * Popups and tooltips accept a `DocumentFragment` as content, which no longer disappears on reopen, by [@A350xt](https://github.com/A350xt) in https://github.com/Leaflet/Leaflet/pull/10540
80
+ * Control: `getEvents()` for map listeners added and removed with the control in https://github.com/Leaflet/Leaflet/commit/80618956304ce64674e585025d4f1143fd62f664
81
+
82
+ #### ✨ Refactorings (⚠️ Breaking Changes)
83
+
84
+ * The `<canvas>` element of a canvas renderer no longer receives pointer events, so DOM listeners added to it don't fire; listen on the layers or the map instead. The private `Canvas` methods `_onClick()`, `_onPointerMove()`, `_handlePointerOut()` and `_fireEvent()` are gone; the map calls `_layerAt()`, in https://github.com/Leaflet/Leaflet/pull/10523
85
+ * `panBy()` goes through `setView()`: it is limited by `maxBounds`, stops running animations and is applied after a running zoom animation; the pan animation itself is the private `_panBy()`, in https://github.com/Leaflet/Leaflet/pull/10549
86
+ * `Point` and `LatLng` convert numeric strings and throw on coordinates that are not numbers, e.g. `new LatLng(50, '')` or `new Point(5, 'auto')`, which became `0` or a string before; `validate()` matches the constructors, in https://github.com/Leaflet/Leaflet/pull/10550
87
+ * `DomEvent.on(el, 'dblclick', …)` no longer simulates double taps on iOS for elements outside a map, in https://github.com/Leaflet/Leaflet/pull/10524
88
+ * The Marker option `alt` defaults to `undefined`, which is the translation of `'Marker'`, in https://github.com/Leaflet/Leaflet/pull/10542
89
+ * Controls no longer refocus the map after a click, and the private `Control._refocusOnMap()` is gone, in https://github.com/Leaflet/Leaflet/commit/92e961262393a1acb697de148d43278a9e505a1b
90
+
91
+ #### ✨ Improvements
92
+
93
+ * Make the canvas renderer transparent to pointer events, so that SVG paths, markers, overlays and other canvas renderers below it get clicks and hovers, in https://github.com/Leaflet/Leaflet/pull/10523
94
+ * Stop throttling the hover events of canvas paths in https://github.com/Leaflet/Leaflet/commit/e9bdd59480901136caa1fde3fbbf6f8049eb47a0
95
+ * Draw the plus and minus signs of the zoom control in SVG, crisp and centered with any font, in https://github.com/Leaflet/Leaflet/commit/a203b006477cf9545aa723130a1e6a83f3a58f95
96
+ * Simplify the double tap simulation on iOS, which fires a single `dblclick` on a canvas renderer, in https://github.com/Leaflet/Leaflet/pull/10524
97
+ * Let Shift-drag pan the map when box zoom is disabled in https://github.com/Leaflet/Leaflet/commit/79c68c6429c232fe0a1b19a5061dec9d28b7ef57
98
+ * Use modern DOM APIs, small and mechanical code cleanups in https://github.com/Leaflet/Leaflet/commit/91633ca7a85ad7ab051d57cd8c3006c9a9295d68, https://github.com/Leaflet/Leaflet/commit/77e5f691e6746e7f11cbccadd223851254e4cd42, https://github.com/Leaflet/Leaflet/commit/99d8006ce0ae57ce5d2dfa9c009f23ceffa2e38a and https://github.com/Leaflet/Leaflet/commit/f1b911917ab0b23895883f22a62f7a0395451fe6
99
+ * Allow dragging the map during a zoom animation in https://github.com/Leaflet/Leaflet/commit/01eb901fd8c8b2c371ddb60e544f5cf11f5225e2
100
+ * Make view changes compose regardless of call order: `setView()` then `setZoom()`, repeated `zoomIn()` and `panTo()` then `panBy()` build on where an animation is heading, in https://github.com/Leaflet/Leaflet/pull/10549
101
+
102
+ #### ♿️ Accessibility
103
+
104
+ * Markers acting as buttons get `aria-expanded` and `aria-controls` for their popup, closing a popup returns the focus however it is closed, markers rise above others while focused, and increased contrast gets an opaque attribution and scale with underlined links, in https://github.com/Leaflet/Leaflet/pull/10536
105
+ * Improve the contrast of the attribution and the scale for WCAG AA in https://github.com/Leaflet/Leaflet/commit/17729390c752bf0d2bc960836653d4e937af9fcf
106
+ * Rise markers with `riseOnHover` on keyboard focus too in https://github.com/Leaflet/Leaflet/commit/2c28c1a22cf355e663738d8f08e03b2577f1fae4
107
+ * Open tooltips on keyboard focus only, not when the focus comes back to an element clicked with the mouse, in https://github.com/Leaflet/Leaflet/commit/f1fb25604d52afe5c2c433b11ae401fa27b9c140
108
+ * Set `aria-describedby` on a layer whenever its tooltip opens, however it was opened, in https://github.com/Leaflet/Leaflet/commit/dfab29d671bc2135cb3ac761e554d50856020fae
109
+ * Translate the default `alt` text of marker icons by [@nfreear](https://github.com/nfreear) in https://github.com/Leaflet/Leaflet/pull/10542
110
+ * Fix keyboard clicks on markers being ignored after a drag by [@Enfiladeguide](https://github.com/Enfiladeguide) in https://github.com/Leaflet/Leaflet/pull/10529
111
+ * Fix Escape being swallowed by the map after a popup was closed in https://github.com/Leaflet/Leaflet/commit/ee23ede2df59ac0d70007f4eea0e52d896ce817f
112
+ * Stop refocusing the map after clicks on controls in https://github.com/Leaflet/Leaflet/commit/92e961262393a1acb697de148d43278a9e505a1b
113
+ * Keep the focus on a marker clicked by a screen reader in https://github.com/Leaflet/Leaflet/commit/68c14509db2d12c2a2cec6df5705ae1ac6f7b464
114
+
115
+ #### 🐞 Bugfixes
116
+
117
+ * Fix paths jumping when they are changed or added during a zoom animation or pinch in https://github.com/Leaflet/Leaflet/commit/ff13df6ae03ff54126fa5126525d50d15c7ddf6f
118
+ * Fix view changes being lost during a zoom animation, they now apply once it ends (with [@yellowman](https://github.com/yellowman)) in https://github.com/Leaflet/Leaflet/commit/e61b254f4e6c29d8a185f3cdc6182887d8e37acc
119
+ * Fix `minNativeZoom` and `maxNativeZoom` with `detectRetina` and `zoomReverse` in https://github.com/Leaflet/Leaflet/commit/10388a5176ab998b2b22f8ddb3fd34b6715552c3
120
+ * Honor `coords.z` in TileLayer `getTileUrl()` (with [@yohanboniface](https://github.com/yohanboniface)) in https://github.com/Leaflet/Leaflet/commit/8f0fe7bfde0e9c6a948d2131e66619f5882c1111
121
+ * Fix `closestLayerPoint()` of polygons missing the segment closing the ring in https://github.com/Leaflet/Leaflet/commit/3c202e89f5cb74bd4e090b4a1a7c2cd97792c0fd
122
+ * Fix a repeated click on image, SVG and video overlays closing their popup instead of moving it in https://github.com/Leaflet/Leaflet/commit/1c7d70533414a4802455723fbe248b12000bd5cb
123
+ * Apply `zIndex` and `opacity` consistently on image, video and SVG overlays, also `zIndex: 0` and `opacity: 0`, by [@b84330808](https://github.com/b84330808) in https://github.com/Leaflet/Leaflet/pull/10533
124
+ * Reset the styles of the previous icon when a marker reuses its element by [@b84330808](https://github.com/b84330808) in https://github.com/Leaflet/Leaflet/pull/10538
125
+ * Fix `setContent('')` leaving the old content in a popup or tooltip by [@Don-Yin](https://github.com/Don-Yin) in https://github.com/Leaflet/Leaflet/pull/10532
126
+ * Fix markers losing their altitude after a drag in https://github.com/Leaflet/Leaflet/commit/310749e71daff3eec62774abe90839c81417719a
127
+ * Fix the autoPan of a dragged marker panning past `maxBounds` by [@A350xt](https://github.com/A350xt) in https://github.com/Leaflet/Leaflet/pull/10539
128
+ * Fix a click firing after a long-press `contextmenu` on iOS in https://github.com/Leaflet/Leaflet/commit/aff4916e019d03f3fa91a81e8da6b38d91f6c12b
129
+ * Fix the expanded list of the layers control hidden under other controls in https://github.com/Leaflet/Leaflet/commit/f4e449b61ba356ab83f712f167477daeec434c09
130
+ * Return the min zoom from `getBoundsZoom()` when the padding is larger than the map by [@jayhemnani9910](https://github.com/jayhemnani9910) in https://github.com/Leaflet/Leaflet/pull/10544
131
+ * Fix `overlaps()` for bounds with zero area by [@xunguangzlj-cloud](https://github.com/xunguangzlj-cloud) in https://github.com/Leaflet/Leaflet/pull/10547
132
+ * Ignore NaN when combining the zoom limits of the layers of a map by [@xunguangzlj-cloud](https://github.com/xunguangzlj-cloud) in https://github.com/Leaflet/Leaflet/pull/10548
133
+ * Don't call event listeners added during a fire of their event until the next fire, found with the specs of https://github.com/Leaflet/Leaflet/pull/10537
134
+ * Tooltip: replace the `center` direction class when the direction changes in https://github.com/Leaflet/Leaflet/commit/8ad17baed7639eea6b515b5f474d87d63325f48f
135
+ * Small fixes from the core `FullscreenControl` of Leaflet: the pseudo-fullscreen map ignores the margins of its container, `aria-keyshortcuts` is set as an attribute, in https://github.com/Leaflet/Leaflet/pull/10531
136
+ * Fix the position of tooltips in right-to-left containers in https://github.com/Leaflet/Leaflet/commit/a3f5687828c83a5fe9c446f8dfe827c725c0b34d
137
+ * Fix tiles flickering at fractional zoom past `maxZoom` (with [@sbquinlan](https://github.com/sbquinlan)) in https://github.com/Leaflet/Leaflet/commit/32d950de72dc508789509423d165e6eb0242e8dd
138
+ * Fix polygons disappearing with a string `weight` (with [@Falke-Design](https://github.com/Falke-Design)) in https://github.com/Leaflet/Leaflet/commit/08d2dd24157201b6706d9df40a0cc1e96c6cccf0
139
+ * Don't throw when toggling a popup or tooltip of a layer that isn't on the map by [@Enesuygurs](https://github.com/Enesuygurs) in https://github.com/Leaflet/Leaflet/pull/10551
140
+ * Validate `Point` and `LatLng` coordinates: numeric strings are converted, anything else that is not a number throws, in https://github.com/Leaflet/Leaflet/pull/10550
141
+ * Keep the exact center for `invalidateSize()` without a size change, handle a missing `weight` of polygons, in https://github.com/Leaflet/Leaflet/commit/f998a71de529184495bc42ff82767a2f6ce5b7dc
142
+
143
+ #### 📝 Docs
144
+
145
+ * Document the `animate` option of `setView()` and `invalidateSize()`, interactive targets, the renderers of custom panes, the `flyTo` and `pinch` flags of move and zoom events, and point from the base classes to the classes to use, in https://github.com/Leaflet/Leaflet/commit/ad3f0dd0cc0e4fcc77c713ba6b30c61f89438f50, https://github.com/Leaflet/Leaflet/commit/0b1c64a7395f105210e334d145ed51a9f78d9b9d, https://github.com/Leaflet/Leaflet/commit/cd0dbf0ded365094072bf6a55c9aac7de9f67ee7 and https://github.com/Leaflet/Leaflet/commit/b7f53cecf296338ee528ee0fc603ed65981dbc48
146
+ * Rewrite the plugin guide, with a section on a script build for the global `L`, in https://github.com/Leaflet/Leaflet/commit/c2ba3ff6fddb7b83e2e0333526cbe3df1624736d
147
+ * Fix a typo in the ImageOverlay spec by [@ninglinLiu](https://github.com/ninglinLiu) in https://github.com/Leaflet/Leaflet/pull/10543
148
+
6
149
  ## 4.3.0 (2026-11-02)
7
150
 
8
151
  ### Leaflet, since 4.2.0
@@ -42,7 +185,7 @@ Ported from Leaflet (changes without author notice are by [@mourner](https://git
42
185
  * Marker: the option `rotation` (in degrees, `null` for none) with `setRotation()` and `getRotation()` rotates the icon around its anchor, rotates the popup and tooltip anchors and hides the shadow; it replaces the optional module `maplair/marker-rotation` with `rotationAngle`, `rotationOrigin`, `setRotationAngle()` and `setRotationOrigin()`, `rotateWithView` is part of `maplair/map-rotation`, in https://github.com/Leaflet/Leaflet/pull/10489
43
186
  * `latLngToLayerPoint()` and `latLngToContainerPoint()` keep subpixel precision instead of rounding, so polylines and polygons don't zigzag along whole pixels, in https://github.com/Leaflet/Leaflet/pull/10494
44
187
  * Various small cleanups, e.g. KeyboardHandler reads `keyboardPanDelta` and `zoomDelta` on each key, Canvas draws ellipses with `ellipse()`, in https://github.com/Leaflet/Leaflet/pull/10490
45
- * Only stop the propagation of clicks opening a popup in https://github.com/Leaflet/Leaflet/commit/{prop}
188
+ * Only stop the propagation of clicks opening a popup in https://github.com/Leaflet/Leaflet/commit/d10454a56bab4b6df1f8eba729c4d818a71c118f
46
189
 
47
190
  #### 🐞 Bugfixes
48
191
 
@@ -53,11 +196,11 @@ Ported from Leaflet (changes without author notice are by [@mourner](https://git
53
196
  * Fix Circle `getBounds()` throwing when not added to a map (with [@Schleuse](https://github.com/Schleuse)) in https://github.com/Leaflet/Leaflet/commit/4c7958990cfe586dfc05eede518694b81fe9f32c
54
197
  * Fix FeatureGroup `getBounds()` throwing for layers without a position, include nested layer groups (with [@rafaelgallani](https://github.com/rafaelgallani)) in https://github.com/Leaflet/Leaflet/commit/ee37d374222822139af43580906a966186bccebf
55
198
  * Fix an error when removing the map or a GridLayer on tile load (with [@pierreeurope](https://github.com/pierreeurope)) in https://github.com/Leaflet/Leaflet/commit/62c5f52791c5055ef4c94e508525b554ab158d15
56
- * Fix an error with empty `subdomains` in https://github.com/Leaflet/Leaflet/commit/{sub}
199
+ * Fix an error with empty `subdomains` in https://github.com/Leaflet/Leaflet/commit/8861b5e4faac7243590017a7248f34f2c3d7762c
57
200
  * Switch the tooltip handlers when rebinding a tooltip with different options, open it on focus after the layer is added again, don't fire `tileerror` for tiles pruned with `errorTileUrl` in https://github.com/Leaflet/Leaflet/pull/10490
58
- * Fix the map drifting under the cursor on zoom in https://github.com/Leaflet/Leaflet/commit/{drift}
59
- * Close popups on Escape more reliably, e.g. with the focus on a marker in https://github.com/Leaflet/Leaflet/commit/{esc}
60
- * Isolate the stacking context of the map container in https://github.com/Leaflet/Leaflet/commit/{iso}
201
+ * Fix the map drifting under the cursor on zoom in https://github.com/Leaflet/Leaflet/commit/de0be695f714e3c0cef3097b27761a16283c3de7
202
+ * Close popups on Escape more reliably, e.g. with the focus on a marker in https://github.com/Leaflet/Leaflet/commit/aee4d5c907ae57ea83c3b2e9d6ed9f170c6fe174
203
+ * Isolate the stacking context of the map container in https://github.com/Leaflet/Leaflet/commit/611c300542de053bd9335204a4357677cbd76250
61
204
  * Accept marker icons without `createShadow()` in https://github.com/Leaflet/Leaflet/pull/10489
62
205
  * Make Draggable work outside a map in https://github.com/Leaflet/Leaflet/commit/2e770eb84bafca2368eef611922497cd0b3a81de
63
206
  * LayersControl stops listening to map clicks when removed, TileLayer halves a `Point` tileSize with `detectRetina`, `isLoading()` returns a boolean in https://github.com/Leaflet/Leaflet/commit/1dc1b4ea0ffd779e15f8a5aeeb27dd15e597cd1f
@@ -69,16 +212,16 @@ Ported from Leaflet (changes without author notice are by [@mourner](https://git
69
212
 
70
213
  * Fix doc typos and outdated links (with [@Kumar007-7](https://github.com/Kumar007-7)) in https://github.com/Leaflet/Leaflet/commit/ff2715f95cd8542eaf8706b9459620bedb3baec7
71
214
  * Use viewport units in the mobile example by [@pierreeurope](https://github.com/pierreeurope) in https://github.com/Leaflet/Leaflet/pull/10120
72
- * Fix a few stale things in the plugin guide in https://github.com/Leaflet/Leaflet/commit/{guide}
215
+ * Fix a few stale things in the plugin guide in https://github.com/Leaflet/Leaflet/commit/2869685c537efcaebad72723a907d7c01c226f56
73
216
 
74
217
  #### 🔧 Workflow
75
218
 
76
219
  * Minify `maplair.css` with lightningcss in https://github.com/Leaflet/Leaflet/pull/10493
77
- * Reduce Dependabot noise with a better config in https://github.com/Leaflet/Leaflet/commit/{dep}
220
+ * Reduce Dependabot noise with a better config in https://github.com/Leaflet/Leaflet/commit/8dc45a82932d8c5682ee1a00a62ed54eb6533b50
78
221
 
79
222
  #### 🧪 Tests
80
223
 
81
- * Fix test flakiness on slow runners in https://github.com/Leaflet/Leaflet/commit/{flaky}
224
+ * Fix test flakiness on slow runners in https://github.com/Leaflet/Leaflet/commit/d958d3ced7208e4e8bfa3ad80e2b7432317a0e84
82
225
 
83
226
  ## 4.1.0 (2026-10-28)
84
227
 
@@ -56,6 +56,7 @@ var AttributionControl = class AttributionControl extends Control {
56
56
  this._attributions = {};
57
57
  this._orders = {};
58
58
  this._layerAttributions = /* @__PURE__ */ new Map();
59
+ this._shownLayers = /* @__PURE__ */ new Set();
59
60
  this.callInitHooks(AttributionControl);
60
61
  }
61
62
  /**
@@ -69,33 +70,50 @@ var AttributionControl = class AttributionControl extends Control {
69
70
  disableClickPropagation(this._container);
70
71
  if (map._loaded) map.eachLayer((layer) => this._addLayer({ layer }));
71
72
  this._update();
72
- map.on({
73
- layeradd: this._addLayer,
74
- layerremove: this._removeLayer
75
- }, this);
76
73
  return this._container;
77
74
  }
78
75
  /**
79
76
  * @internal
80
- * @param {MaplairMap} map
77
+ * @returns {Record<string, Function>}
81
78
  */
82
- onRemove(map) {
83
- map.off({
79
+ getEvents() {
80
+ return {
84
81
  layeradd: this._addLayer,
85
- layerremove: this._removeLayer
86
- }, this);
82
+ layerremove: this._removeLayer,
83
+ zoomend: this._onZoomEnd
84
+ };
85
+ }
86
+ /**
87
+ * @internal
88
+ */
89
+ onRemove() {
87
90
  for (const layer of this._layerAttributions.keys()) this._removeLayer({ layer });
88
91
  }
89
92
  _addLayer({ layer }) {
90
93
  const text = layer.getAttribution?.();
91
94
  if (!text || this._layerAttributions.has(layer)) return;
92
95
  this._layerAttributions.set(layer, text);
93
- this.addAttribution(text, layer.options?.attributionOrder);
96
+ this._updateLayer(layer);
94
97
  }
95
98
  _removeLayer({ layer }) {
96
- this.removeAttribution(this._layerAttributions.get(layer));
99
+ if (this._shownLayers.delete(layer)) this.removeAttribution(this._layerAttributions.get(layer));
97
100
  this._layerAttributions.delete(layer);
98
101
  }
102
+ _onZoomEnd() {
103
+ for (const layer of this._layerAttributions.keys()) this._updateLayer(layer);
104
+ }
105
+ _updateLayer(layer) {
106
+ const { minZoom = -Infinity, maxZoom = Infinity } = layer.options ?? {}, zoom = this._map.getZoom(), show = zoom >= minZoom && zoom <= maxZoom;
107
+ if (show === this._shownLayers.has(layer)) return;
108
+ const text = this._layerAttributions.get(layer);
109
+ if (show) {
110
+ this._shownLayers.add(layer);
111
+ this.addAttribution(text, layer.options?.attributionOrder);
112
+ } else {
113
+ this._shownLayers.delete(layer);
114
+ this.removeAttribution(text);
115
+ }
116
+ }
99
117
  /**
100
118
  * The HTML text shown before the attributions. Pass `false` to disable.
101
119
  * @param {string|false} prefix
@@ -117,8 +135,7 @@ var AttributionControl = class AttributionControl extends Control {
117
135
  addAttribution(text, order = 0) {
118
136
  if (!text) return this;
119
137
  this._orders[text] = order;
120
- if (!this._attributions[text]) this._attributions[text] = 0;
121
- this._attributions[text]++;
138
+ this._attributions[text] = (this._attributions[text] || 0) + 1;
122
139
  this._update();
123
140
  return this;
124
141
  }
@@ -1 +1 @@
1
- {"version":3,"file":"AttributionControl.js","names":["DomUtil.create"],"sources":["../../../src/control/AttributionControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\nconst mapleLeaf = '<span aria-hidden=\"true\" class=\"maplair-attribution-leaf\">&#x1F341;</span>';\n\n/**\n * Options of `AttributionControl`.\n * @typedef {object} AttributionControlOptions\n * @property {string} [position='bottomright'] The position of the control (one of the\n * map corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string|false|null} [prefix=null] The HTML text shown before the\n * attributions. Pass `false` to disable. By default (`null`), a link to Maplair.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `AttributionControl`.\n * @typedef {object} AttributionControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [attributionControl=true] Whether a\n * [attribution control](#control-attribution) is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `AttributionControl`.\n * @typedef {object} AttributionControlMapProperties\n * @lends MaplairMap\n * @property {AttributionControl} attributionControl The attribution control of the map,\n * the default one (if the [`attributionControl` option](#map-attributioncontrol) was\n * `true` when creating the map) or the one added last.\n */\n\n/**\n * The attribution control allows you to display attribution data in a small text box\n * on a map. It is put on the map by default unless you set its\n * [`attributionControl` option](#map-attributioncontrol) to `false`, and it fetches\n * attribution texts from layers with the [`getAttribution` method](#layer-getattribution)\n * automatically.\n */\nexport class AttributionControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomright',\n\t\tprefix: null\n\t};\n\n\t/**\n\t * Creates an attribution control.\n\t * @param {AttributionControlOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper(options);\n\t\tif (this.options.prefix === null) {\n\t\t\tconst title = I18n.translate('A JavaScript library for interactive maps');\n\t\t\tthis.options.prefix = `<a target=\"_blank\" href=\"https://maplair.org\" title=\"${title}\">${mapleLeaf}Maplair</a>`;\n\t\t}\n\n\t\tthis._attributions = {};\n\t\tthis._orders = {};\n\t\tthis._layerAttributions = new Map();\n\n\t\tthis.callInitHooks(AttributionControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tmap.attributionControl = this;\n\t\tthis._container = DomUtil.create('div', 'maplair-control-attribution');\n\t\tDomEvent.disableClickPropagation(this._container);\n\n\t\t// before the map is loaded, layers already added to it will still fire layeradd once it loads\n\t\tif (map._loaded) {\n\t\t\tmap.eachLayer(layer => this._addLayer({layer}));\n\t\t}\n\n\t\tthis._update();\n\n\t\tmap.on({layeradd: this._addLayer, layerremove: this._removeLayer}, this);\n\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off({layeradd: this._addLayer, layerremove: this._removeLayer}, this);\n\n\t\tfor (const layer of this._layerAttributions.keys()) {\n\t\t\tthis._removeLayer({layer});\n\t\t}\n\t}\n\n\t_addLayer({layer}) {\n\t\tconst text = layer.getAttribution?.();\n\t\tif (!text || this._layerAttributions.has(layer)) { return; }\n\n\t\tthis._layerAttributions.set(layer, text);\n\t\tthis.addAttribution(text, layer.options?.attributionOrder);\n\t}\n\n\t_removeLayer({layer}) {\n\t\tthis.removeAttribution(this._layerAttributions.get(layer));\n\t\tthis._layerAttributions.delete(layer);\n\t}\n\n\t/**\n\t * The HTML text shown before the attributions. Pass `false` to disable.\n\t * @param {string|false} prefix\n\t * @returns {this}\n\t */\n\tsetPrefix(prefix) {\n\t\tthis.options.prefix = prefix;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an attribution text (e.g. `'© OpenStreetMap contributors'`). Attributions\n\t * are sorted by `order` (see the layer option `attributionOrder`), then by the order\n\t * of adding.\n\t * @param {string} text\n\t * @param {number} [order=0]\n\t * @returns {this}\n\t */\n\taddAttribution(text, order = 0) {\n\t\tif (!text) { return this; }\n\n\t\tthis._orders[text] = order;\n\t\tif (!this._attributions[text]) {\n\t\t\tthis._attributions[text] = 0;\n\t\t}\n\t\tthis._attributions[text]++;\n\n\t\tthis._update();\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes an attribution text.\n\t * @param {string} text\n\t * @returns {this}\n\t */\n\tremoveAttribution(text) {\n\t\tif (!text) { return this; }\n\n\t\tif (this._attributions[text]) {\n\t\t\tthis._attributions[text]--;\n\t\t\tthis._update();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t_update() {\n\t\tif (!this._map) { return; }\n\n\t\tconst attribs = Object.keys(this._attributions).filter(i => this._attributions[i])\n\t\t\t.sort((a, b) => this._orders[a] - this._orders[b]);\n\n\t\tconst prefixAndAttribs = [];\n\n\t\tif (this.options.prefix) {\n\t\t\tprefixAndAttribs.push(this.options.prefix);\n\t\t}\n\t\tif (attribs.length) {\n\t\t\tprefixAndAttribs.push(attribs.join(', '));\n\t\t}\n\n\t\tthis._container.innerHTML = prefixAndAttribs.join(' <span aria-hidden=\"true\">|</span> ');\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tattributionControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.attributionControl) {\n\t\t\t\tnew AttributionControl().addTo(this);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;AAQA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqClB,IAAa,qBAAb,MAAa,2BAA2B,QAAQ;CAE/C,OAAO,iBAAiB;EACvB,UAAU;EACV,QAAQ;CACT;;;;;CAMA,YAAY,SAAS;EACpB,MAAM,OAAO;EACb,IAAI,KAAK,QAAQ,WAAW,MAAM;GACjC,MAAM,QAAQ,KAAK,UAAU,2CAA2C;GACxE,KAAK,QAAQ,SAAS,wDAAwD,MAAM,IAAI,UAAU;EACnG;EAEA,KAAK,gBAAgB,CAAC;EACtB,KAAK,UAAU,CAAC;EAChB,KAAK,qCAAqB,IAAI,IAAI;EAElC,KAAK,cAAc,kBAAkB;CACtC;;;;;;CAOA,MAAM,KAAK;EACV,IAAI,qBAAqB;EACzB,KAAK,aAAaA,OAAe,OAAO,6BAA6B;EACrE,wBAAiC,KAAK,UAAU;EAGhD,IAAI,IAAI,SACP,IAAI,WAAU,UAAS,KAAK,UAAU,EAAC,MAAK,CAAC,CAAC;EAG/C,KAAK,QAAQ;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AK,KAAK,QAAQ,EAAE;EAElD,MAAM,mBAAmB,CAAC;EAE1B,IAAI,KAAK,QAAQ,QAChB,iBAAiB,KAAK,KAAK,QAAQ,MAAM;EAE1C,IAAI,QAAQ,QACX,iBAAiB,KAAK,QAAQ,KAAK,IAAI,CAAC;EAGzC,KAAK,WAAW,YAAY,iBAAiB,KAAK,uCAAqC;CACxF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,oBAAoB,KACrB,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,oBAChB,IAAI,mBAAmB,CAAC,CAAC,MAAM,IAAI;EAErC,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"AttributionControl.js","names":["DomUtil.create"],"sources":["../../../src/control/AttributionControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\nconst mapleLeaf = '<span aria-hidden=\"true\" class=\"maplair-attribution-leaf\">&#x1F341;</span>';\n\n/**\n * Options of `AttributionControl`.\n * @typedef {object} AttributionControlOptions\n * @property {string} [position='bottomright'] The position of the control (one of the\n * map corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string|false|null} [prefix=null] The HTML text shown before the\n * attributions. Pass `false` to disable. By default (`null`), a link to Maplair.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `AttributionControl`.\n * @typedef {object} AttributionControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [attributionControl=true] Whether a\n * [attribution control](#control-attribution) is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `AttributionControl`.\n * @typedef {object} AttributionControlMapProperties\n * @lends MaplairMap\n * @property {AttributionControl} attributionControl The attribution control of the map,\n * the default one (if the [`attributionControl` option](#map-attributioncontrol) was\n * `true` when creating the map) or the one added last.\n */\n\n/**\n * The attribution control allows you to display attribution data in a small text box\n * on a map. It is put on the map by default unless you set its\n * [`attributionControl` option](#map-attributioncontrol) to `false`, and it fetches\n * attribution texts from layers with the [`getAttribution` method](#layer-getattribution)\n * automatically.\n */\nexport class AttributionControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomright',\n\t\tprefix: null\n\t};\n\n\t/**\n\t * Creates an attribution control.\n\t * @param {AttributionControlOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper(options);\n\t\tif (this.options.prefix === null) {\n\t\t\tconst title = I18n.translate('A JavaScript library for interactive maps');\n\t\t\tthis.options.prefix = `<a target=\"_blank\" href=\"https://maplair.org\" title=\"${title}\">${mapleLeaf}Maplair</a>`;\n\t\t}\n\n\t\tthis._attributions = {};\n\t\tthis._orders = {};\n\t\tthis._layerAttributions = new Map();\n\t\tthis._shownLayers = new Set();\n\n\t\tthis.callInitHooks(AttributionControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tmap.attributionControl = this;\n\t\tthis._container = DomUtil.create('div', 'maplair-control-attribution');\n\t\tDomEvent.disableClickPropagation(this._container);\n\n\t\t// before the map is loaded, layers already added to it will still fire layeradd once it loads\n\t\tif (map._loaded) {\n\t\t\tmap.eachLayer(layer => this._addLayer({layer}));\n\t\t}\n\n\t\tthis._update();\n\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\treturn {layeradd: this._addLayer, layerremove: this._removeLayer, zoomend: this._onZoomEnd};\n\t}\n\n\t/**\n\t * @internal\n\t */\n\tonRemove() {\n\t\tfor (const layer of this._layerAttributions.keys()) {\n\t\t\tthis._removeLayer({layer});\n\t\t}\n\t}\n\n\t_addLayer({layer}) {\n\t\tconst text = layer.getAttribution?.();\n\t\tif (!text || this._layerAttributions.has(layer)) { return; }\n\n\t\tthis._layerAttributions.set(layer, text);\n\t\tthis._updateLayer(layer);\n\t}\n\n\t_removeLayer({layer}) {\n\t\tif (this._shownLayers.delete(layer)) {\n\t\t\tthis.removeAttribution(this._layerAttributions.get(layer));\n\t\t}\n\t\tthis._layerAttributions.delete(layer);\n\t}\n\n\t_onZoomEnd() {\n\t\tfor (const layer of this._layerAttributions.keys()) {\n\t\t\tthis._updateLayer(layer);\n\t\t}\n\t}\n\n\t// Layers with `minZoom`/`maxZoom` options (e.g. tile layers) aren't displayed outside that range.\n\t_updateLayer(layer) {\n\t\tconst {minZoom = -Infinity, maxZoom = Infinity} = layer.options ?? {},\n\t\tzoom = this._map.getZoom(),\n\t\tshow = zoom >= minZoom && zoom <= maxZoom;\n\t\tif (show === this._shownLayers.has(layer)) { return; }\n\n\t\tconst text = this._layerAttributions.get(layer);\n\t\tif (show) {\n\t\t\tthis._shownLayers.add(layer);\n\t\t\tthis.addAttribution(text, layer.options?.attributionOrder);\n\t\t} else {\n\t\t\tthis._shownLayers.delete(layer);\n\t\t\tthis.removeAttribution(text);\n\t\t}\n\t}\n\n\t/**\n\t * The HTML text shown before the attributions. Pass `false` to disable.\n\t * @param {string|false} prefix\n\t * @returns {this}\n\t */\n\tsetPrefix(prefix) {\n\t\tthis.options.prefix = prefix;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Adds an attribution text (e.g. `'© OpenStreetMap contributors'`). Attributions\n\t * are sorted by `order` (see the layer option `attributionOrder`), then by the order\n\t * of adding.\n\t * @param {string} text\n\t * @param {number} [order=0]\n\t * @returns {this}\n\t */\n\taddAttribution(text, order = 0) {\n\t\tif (!text) { return this; }\n\n\t\tthis._orders[text] = order;\n\t\tthis._attributions[text] = (this._attributions[text] || 0) + 1;\n\n\t\tthis._update();\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes an attribution text.\n\t * @param {string} text\n\t * @returns {this}\n\t */\n\tremoveAttribution(text) {\n\t\tif (!text) { return this; }\n\n\t\tif (this._attributions[text]) {\n\t\t\tthis._attributions[text]--;\n\t\t\tthis._update();\n\t\t}\n\n\t\treturn this;\n\t}\n\n\t_update() {\n\t\tif (!this._map) { return; }\n\n\t\tconst attribs = Object.keys(this._attributions).filter(i => this._attributions[i])\n\t\t\t.sort((a, b) => this._orders[a] - this._orders[b]);\n\n\t\tconst prefixAndAttribs = [];\n\n\t\tif (this.options.prefix) {\n\t\t\tprefixAndAttribs.push(this.options.prefix);\n\t\t}\n\t\tif (attribs.length) {\n\t\t\tprefixAndAttribs.push(attribs.join(', '));\n\t\t}\n\n\t\tthis._container.innerHTML = prefixAndAttribs.join(' <span aria-hidden=\"true\">|</span> ');\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.mergeOptions({\n\t\t\tattributionControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.attributionControl) {\n\t\t\t\tnew AttributionControl().addTo(this);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;AAQA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqClB,IAAa,qBAAb,MAAa,2BAA2B,QAAQ;CAE/C,OAAO,iBAAiB;EACvB,UAAU;EACV,QAAQ;CACT;;;;;CAMA,YAAY,SAAS;EACpB,MAAM,OAAO;EACb,IAAI,KAAK,QAAQ,WAAW,MAAM;GACjC,MAAM,QAAQ,KAAK,UAAU,2CAA2C;GACxE,KAAK,QAAQ,SAAS,wDAAwD,MAAM,IAAI,UAAU;EACnG;EAEA,KAAK,gBAAgB,CAAC;EACtB,KAAK,UAAU,CAAC;EAChB,KAAK,qCAAqB,IAAI,IAAI;EAClC,KAAK,+BAAe,IAAI,IAAI;EAE5B,KAAK,cAAc,kBAAkB;CACtC;;;;;;CAOA,MAAM,K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AI;EAC5B;CACD;;;;;;CAOA,UAAU,QAAQ;EACjB,KAAK,QAAQ,SAAS;EACtB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;;;;;CAUA,eAAe,MAAM,QAAQ,GAAG;EAC/B,IAAI,CAAC,MAAQ,OAAO;EAEpB,KAAK,QAAQ,QAAQ;EACrB,KAAK,cAAc,SAAS,KAAK,cAAc,SAAS,KAAK;EAE7D,KAAK,QAAQ;EAEb,OAAO;CACR;;;;;;CAOA,kBAAkB,MAAM;EACvB,IAAI,CAAC,MAAQ,OAAO;EAEpB,IAAI,KAAK,cAAc,OAAO;GAC7B,KAAK,cAAc,KAAK;GACxB,KAAK,QAAQ;EACd;EAEA,OAAO;CACR;CAEA,UAAU;EACT,IAAI,CAAC,KAAK,MAAQ;EAElB,MAAM,UAAU,OAAO,KAAK,KAAK,aAAa,CAAC,CAAC,QAAO,MAAK,KAAK,cAAc,EAAE,CAAC,CAChF,MAAM,GAAG,MAAM,KAAK,QAAQ,KAAK,KAAK,QAAQ,EAAE;EAElD,MAAM,mBAAmB,CAAC;EAE1B,IAAI,KAAK,QAAQ,QAChB,iBAAiB,KAAK,KAAK,QAAQ,MAAM;EAE1C,IAAI,QAAQ,QACX,iBAAiB,KAAK,QAAQ,KAAK,IAAI,CAAC;EAGzC,KAAK,WAAW,YAAY,iBAAiB,KAAK,uCAAqC;CACxF;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,oBAAoB,KACrB,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,oBAChB,IAAI,mBAAmB,CAAC,CAAC,MAAM,IAAI;EAErC,CAAC;CACF;AACD"}
@@ -99,7 +99,6 @@ var ButtonControl = class ButtonControl extends Control {
99
99
  disableClickPropagation(button);
100
100
  on(button, "click", stop);
101
101
  on(button, "click", this._onClick, this);
102
- on(button, "click", this._refocusOnMap, this);
103
102
  this._update();
104
103
  return button;
105
104
  }
@@ -1 +1 @@
1
- {"version":3,"file":"ButtonControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ButtonControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * A state of a `ButtonControl`, see its `states` option.\n * @typedef {object} ButtonControlState\n * @property {string} name The name of the state, see `setState()`.\n * @property {string|HTMLElement} [content] The content of the button in this state.\n * @property {string} [title] The title of the button in this state.\n * @property {(this: ButtonControl, e: MouseEvent, button: ButtonControl, map: MaplairMap) => void} [onClick]\n * Called when clicking the button in this state.\n */\n\n/**\n * Options of `ButtonControl`.\n * @typedef {object} ButtonControlOptions\n * @property {string} [position='topleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string|HTMLElement} [content=''] The content of the button: HTML (e.g. an\n * icon or a character) or an element. String content is rendered as HTML; do not pass\n * untrusted input.\n * @property {string} [title=''] The title (tooltip) and accessible name of the button.\n * @property {(this: ButtonControl, e: MouseEvent, button: ButtonControl, map: MaplairMap) => void} [onClick]\n * Called with the click event, the `ButtonControl` and the map when clicking the button.\n * @property {ButtonControlState[]} [states] Alternative states of the button, each an\n * object with `name` and with `content`, `title` and `onClick` like the options. The\n * first state is the initial one, `setState()` switches them.\n * @property {string} [className=''] A custom CSS class name to assign to the button.\n * @property {string} [accessKey=''] A key to activate the button with the browser's\n * [access key](https://developer.mozilla.org/docs/Web/HTML/Reference/Global_attributes/accesskey)\n * modifiers (e.g. Alt+Shift+K), shown in the title.\n * @extends ControlOptions\n */\n\n/**\n * A control with a button, styled like the zoom control, calling a function when\n * clicked. It can have several states with their own content, title and function,\n * e.g. to toggle something. Several buttons can be grouped with `ButtonBarControl`.\n *\n * Inspired by the [Leaflet.EasyButton](https://github.com/CliffCloud/Leaflet.EasyButton) plugin.\n *\n * @example\n * ```js\n * new ButtonControl({\n * \tcontent: '⌂',\n * \ttitle: 'Home',\n * \tonClick: (e, button, map) => map.setView([47.27, 11.40], 13)\n * }).addTo(map);\n *\n * new ButtonControl({\n * \tstates: [{\n * \t\tname: 'show',\n * \t\tcontent: '👁',\n * \t\ttitle: 'Show the markers',\n * \t\tonClick(e, button, map) { markers.addTo(map); button.setState('hide'); }\n * \t}, {\n * \t\tname: 'hide',\n * \t\tcontent: '🙈',\n * \t\ttitle: 'Hide the markers',\n * \t\tonClick(e, button) { markers.remove(); button.setState('show'); }\n * \t}]\n * }).addTo(map);\n * ```\n */\nexport class ButtonControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tcontent: '',\n\t\ttitle: '',\n\t\tonClick: undefined,\n\t\tstates: undefined,\n\t\tclassName: '',\n\t\taccessKey: ''\n\t};\n\n\t/**\n\t * Creates a button control.\n\t * @param {...ButtonControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis._state = this.options.states?.[0];\n\t\tthis.callInitHooks(ButtonControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {HTMLElement}\n\t */\n\tonAdd() {\n\t\tconst container = DomUtil.create('div', 'maplair-bar maplair-control-button');\n\t\tthis._createButton(container);\n\t\treturn container;\n\t}\n\n\t// Creates the button element in `container`, see `ButtonBarControl`\n\t_createButton(container) {\n\t\tconst button = this._button = DomUtil.create('button', `maplair-control-button-button ${this.options.className}`, container);\n\t\tbutton.type = 'button';\n\t\tbutton.accessKey = this.options.accessKey;\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._onClick, this);\n\t\tDomEvent.on(button, 'click', this._refocusOnMap, this);\n\n\t\tthis._update();\n\t\treturn button;\n\t}\n\n\t_onClick(e) {\n\t\tif (this._disabled) { return; }\n\t\t(this._state ?? this.options).onClick?.call(this, e, this, this._map);\n\t}\n\n\t_update() {\n\t\tif (!this._button) { return; }\n\t\tconst {content, title} = this._state ?? this.options,\n\t\tbutton = this._button;\n\n\t\tif (typeof content === 'string') {\n\t\t\tbutton.innerHTML = content;\n\t\t} else {\n\t\t\tbutton.replaceChildren(content);\n\t\t}\n\t\tconst key = button.accessKeyLabel || this.options.accessKey.toUpperCase();\n\t\tbutton.title = [title, key && `[${key}]`].filter(Boolean).join(' ');\n\t\tbutton.setAttribute('aria-label', title ?? '');\n\t\tif (this._state) {\n\t\t\tbutton.dataset.state = this._state.name;\n\t\t}\n\t\tbutton.classList.toggle('maplair-disabled', !!this._disabled);\n\t\tbutton.setAttribute('aria-disabled', !!this._disabled);\n\t}\n\n\t/**\n\t * Switches to the state with the given `name`, see the `states` option.\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\tsetState(name) {\n\t\tconst state = this.options.states?.find(s => s.name === name);\n\t\tif (!state) {\n\t\t\tthrow new Error(`Unknown button state \"${name}\".`);\n\t\t}\n\t\tthis._state = state;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the name of the current state, see the `states` option.\n\t * @returns {string|undefined}\n\t */\n\tgetState() {\n\t\treturn this._state?.name;\n\t}\n\n\t/**\n\t * Disables the button, so that clicking it does nothing.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the button again.\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the button element.\n\t * @returns {HTMLElement}\n\t */\n\tgetButton() {\n\t\treturn this._button;\n\t}\n}\n\n/**\n * Groups several `ButtonControl`s in one bar, like the buttons of the zoom control.\n *\n * Inspired by the [Leaflet.EasyButton](https://github.com/CliffCloud/Leaflet.EasyButton) plugin.\n *\n * @example\n * ```js\n * new ButtonBarControl([\n * \tnew ButtonControl({content: 'A', title: 'First', onClick: () => {}}),\n * \tnew ButtonControl({content: 'B', title: 'Second', onClick: () => {}})\n * ]).addTo(map);\n * ```\n */\nexport class ButtonBarControl extends Control {\n\t/**\n\t * Creates a bar with the given buttons.\n\t * @param {ButtonControl[]} buttons\n\t * @param {ControlOptions} [options]\n\t */\n\tconstructor(buttons, options) {\n\t\tsuper(options);\n\t\tthis._buttons = buttons;\n\t\tthis.callInitHooks(ButtonBarControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst container = DomUtil.create('div', 'maplair-bar maplair-control-button-bar');\n\t\tfor (const button of this._buttons) {\n\t\t\tbutton._map = map;\n\t\t\tbutton._createButton(container);\n\t\t}\n\t\treturn container;\n\t}\n\n\t/** @internal */\n\tonRemove() {\n\t\tfor (const button of this._buttons) {\n\t\t\tbutton._map = null;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the buttons of the bar.\n\t * @returns {ButtonControl[]}\n\t */\n\tgetButtons() {\n\t\treturn this._buttons;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB;EACvB,UAAU;EACV,SAAS;EACT,OAAO;EACP,SAAS,KAAA;EACT,QAAQ,KAAA;EACR,WAAW;EACX,WAAW;CACZ;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,SAAS,KAAK,QAAQ,SAAS;EACpC,KAAK,cAAc,aAAa;CACjC;;;;;CAMA,QAAQ;EACP,MAAM,YAAYA,OAAe,OAAO,oCAAoC;EAC5E,KAAK,cAAc,SAAS;EAC5B,OAAO;CACR;CAGA,cAAc,WAAW;EACxB,MAAM,SAAS,KAAK,UAAUA,OAAe,UAAU,iCAAiC,KAAK,QAAQ,aAAa,SAAS;EAC3H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,SAAS;EACR,KAAK,YAAY;EACjB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,YAAY;EACX,OAAO,KAAK;CACb;AACD;;;;;;;;;;;;;;AAeA,IAAa,mBAAb,MAAa,yBAAyB,QAAQ;;;;;;CAM7C,YAAY,SAAS,SAAS;EAC7B,MAAM,OAAO;EACb,KAAK,WAAW;EAChB,KAAK,cAAc,gBAAgB;CACpC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYD,OAAe,OAAO,wCAAwC;EAChF,KAAK,MAAM,UAAU,KAAK,UAAU;GACnC,OAAO,OAAO;GACd,OAAO,cAAc,SAAS;EAC/B;EACA,OAAO;CACR;;CAGA,WAAW;EACV,KAAK,MAAM,UAAU,KAAK,UACzB,OAAO,OAAO;CAEhB;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;AACD"}
1
+ {"version":3,"file":"ButtonControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ButtonControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * A state of a `ButtonControl`, see its `states` option.\n * @typedef {object} ButtonControlState\n * @property {string} name The name of the state, see `setState()`.\n * @property {string|HTMLElement} [content] The content of the button in this state.\n * @property {string} [title] The title of the button in this state.\n * @property {(this: ButtonControl, e: MouseEvent, button: ButtonControl, map: MaplairMap) => void} [onClick]\n * Called when clicking the button in this state.\n */\n\n/**\n * Options of `ButtonControl`.\n * @typedef {object} ButtonControlOptions\n * @property {string} [position='topleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {string|HTMLElement} [content=''] The content of the button: HTML (e.g. an\n * icon or a character) or an element. String content is rendered as HTML; do not pass\n * untrusted input.\n * @property {string} [title=''] The title (tooltip) and accessible name of the button.\n * @property {(this: ButtonControl, e: MouseEvent, button: ButtonControl, map: MaplairMap) => void} [onClick]\n * Called with the click event, the `ButtonControl` and the map when clicking the button.\n * @property {ButtonControlState[]} [states] Alternative states of the button, each an\n * object with `name` and with `content`, `title` and `onClick` like the options. The\n * first state is the initial one, `setState()` switches them.\n * @property {string} [className=''] A custom CSS class name to assign to the button.\n * @property {string} [accessKey=''] A key to activate the button with the browser's\n * [access key](https://developer.mozilla.org/docs/Web/HTML/Reference/Global_attributes/accesskey)\n * modifiers (e.g. Alt+Shift+K), shown in the title.\n * @extends ControlOptions\n */\n\n/**\n * A control with a button, styled like the zoom control, calling a function when\n * clicked. It can have several states with their own content, title and function,\n * e.g. to toggle something. Several buttons can be grouped with `ButtonBarControl`.\n *\n * Inspired by the [Leaflet.EasyButton](https://github.com/CliffCloud/Leaflet.EasyButton) plugin.\n *\n * @example\n * ```js\n * new ButtonControl({\n * \tcontent: '⌂',\n * \ttitle: 'Home',\n * \tonClick: (e, button, map) => map.setView([47.27, 11.40], 13)\n * }).addTo(map);\n *\n * new ButtonControl({\n * \tstates: [{\n * \t\tname: 'show',\n * \t\tcontent: '👁',\n * \t\ttitle: 'Show the markers',\n * \t\tonClick(e, button, map) { markers.addTo(map); button.setState('hide'); }\n * \t}, {\n * \t\tname: 'hide',\n * \t\tcontent: '🙈',\n * \t\ttitle: 'Hide the markers',\n * \t\tonClick(e, button) { markers.remove(); button.setState('show'); }\n * \t}]\n * }).addTo(map);\n * ```\n */\nexport class ButtonControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tcontent: '',\n\t\ttitle: '',\n\t\tonClick: undefined,\n\t\tstates: undefined,\n\t\tclassName: '',\n\t\taccessKey: ''\n\t};\n\n\t/**\n\t * Creates a button control.\n\t * @param {...ButtonControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis._state = this.options.states?.[0];\n\t\tthis.callInitHooks(ButtonControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {HTMLElement}\n\t */\n\tonAdd() {\n\t\tconst container = DomUtil.create('div', 'maplair-bar maplair-control-button');\n\t\tthis._createButton(container);\n\t\treturn container;\n\t}\n\n\t// Creates the button element in `container`, see `ButtonBarControl`\n\t_createButton(container) {\n\t\tconst button = this._button = DomUtil.create('button', `maplair-control-button-button ${this.options.className}`, container);\n\t\tbutton.type = 'button';\n\t\tbutton.accessKey = this.options.accessKey;\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._onClick, this);\n\n\t\tthis._update();\n\t\treturn button;\n\t}\n\n\t_onClick(e) {\n\t\tif (this._disabled) { return; }\n\t\t(this._state ?? this.options).onClick?.call(this, e, this, this._map);\n\t}\n\n\t_update() {\n\t\tif (!this._button) { return; }\n\t\tconst {content, title} = this._state ?? this.options,\n\t\tbutton = this._button;\n\n\t\tif (typeof content === 'string') {\n\t\t\tbutton.innerHTML = content;\n\t\t} else {\n\t\t\tbutton.replaceChildren(content);\n\t\t}\n\t\tconst key = button.accessKeyLabel || this.options.accessKey.toUpperCase();\n\t\tbutton.title = [title, key && `[${key}]`].filter(Boolean).join(' ');\n\t\tbutton.setAttribute('aria-label', title ?? '');\n\t\tif (this._state) {\n\t\t\tbutton.dataset.state = this._state.name;\n\t\t}\n\t\tbutton.classList.toggle('maplair-disabled', !!this._disabled);\n\t\tbutton.setAttribute('aria-disabled', !!this._disabled);\n\t}\n\n\t/**\n\t * Switches to the state with the given `name`, see the `states` option.\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\tsetState(name) {\n\t\tconst state = this.options.states?.find(s => s.name === name);\n\t\tif (!state) {\n\t\t\tthrow new Error(`Unknown button state \"${name}\".`);\n\t\t}\n\t\tthis._state = state;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the name of the current state, see the `states` option.\n\t * @returns {string|undefined}\n\t */\n\tgetState() {\n\t\treturn this._state?.name;\n\t}\n\n\t/**\n\t * Disables the button, so that clicking it does nothing.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the button again.\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the button element.\n\t * @returns {HTMLElement}\n\t */\n\tgetButton() {\n\t\treturn this._button;\n\t}\n}\n\n/**\n * Groups several `ButtonControl`s in one bar, like the buttons of the zoom control.\n *\n * Inspired by the [Leaflet.EasyButton](https://github.com/CliffCloud/Leaflet.EasyButton) plugin.\n *\n * @example\n * ```js\n * new ButtonBarControl([\n * \tnew ButtonControl({content: 'A', title: 'First', onClick: () => {}}),\n * \tnew ButtonControl({content: 'B', title: 'Second', onClick: () => {}})\n * ]).addTo(map);\n * ```\n */\nexport class ButtonBarControl extends Control {\n\t/**\n\t * Creates a bar with the given buttons.\n\t * @param {ButtonControl[]} buttons\n\t * @param {ControlOptions} [options]\n\t */\n\tconstructor(buttons, options) {\n\t\tsuper(options);\n\t\tthis._buttons = buttons;\n\t\tthis.callInitHooks(ButtonBarControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst container = DomUtil.create('div', 'maplair-bar maplair-control-button-bar');\n\t\tfor (const button of this._buttons) {\n\t\t\tbutton._map = map;\n\t\t\tbutton._createButton(container);\n\t\t}\n\t\treturn container;\n\t}\n\n\t/** @internal */\n\tonRemove() {\n\t\tfor (const button of this._buttons) {\n\t\t\tbutton._map = null;\n\t\t}\n\t}\n\n\t/**\n\t * Returns the buttons of the bar.\n\t * @returns {ButtonControl[]}\n\t */\n\tgetButtons() {\n\t\treturn this._buttons;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,KAAK,OAAO;EAEpC,OAAO,UAAU,OAAO,oBAAoB,CAAC,CAAC,KAAK,SAAS;EAC5D,OAAO,aAAa,iBAAiB,CAAC,CAAC,KAAK,SAAS;CACtD;;;;;;CAOA,SAAS,MAAM;EACd,MAAM,QAAQ,KAAK,QAAQ,QAAQ,MAAK,MAAK,EAAE,SAAS,IAAI;EAC5D,IAAI,CAAC,OACJ,MAAM,IAAI,MAAM,yBAAyB,KAAK,GAAG;EAElD,KAAK,SAAS;EACd,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,WAAW;EACV,OAAO,KAAK,QAAQ;CACrB;;;;;CAMA,UAAU;EACT,KAAK,YAAY;EACjB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,SAAS;EACR,KAAK,YAAY;EACjB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,YAAY;EACX,OAAO,KAAK;CACb;AACD;;;;;;;;;;;;;;AAeA,IAAa,mBAAb,MAAa,yBAAyB,QAAQ;;;;;;CAM7C,YAAY,SAAS,SAAS;EAC7B,MAAM,OAAO;EACb,KAAK,WAAW;EAChB,KAAK,cAAc,gBAAgB;CACpC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYD,OAAe,OAAO,wCAAwC;EAChF,KAAK,MAAM,UAAU,KAAK,UAAU;GACnC,OAAO,OAAO;GACd,OAAO,cAAc,SAAS;EAC/B;EACA,OAAO;CACR;;CAGA,WAAW;EACV,KAAK,MAAM,UAAU,KAAK,UACzB,OAAO,OAAO;CAEhB;;;;;CAMA,aAAa;EACZ,OAAO,KAAK;CACb;AACD"}
@@ -127,7 +127,7 @@ var ContextMenu = class ContextMenu extends Class {
127
127
  }
128
128
  _createMenu(parent) {
129
129
  const container = this._container ??= create("div", `maplair-contextmenu ${this.options.className}`);
130
- if (container.parentNode !== parent) parent.appendChild(container);
130
+ if (container.parentNode !== parent) parent.append(container);
131
131
  container.popover = "auto";
132
132
  container.setAttribute("role", "menu");
133
133
  container.replaceChildren();
@@ -1 +1 @@
1
- {"version":3,"file":"ContextMenu.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ContextMenu.js"],"sourcesContent":["import {Class} from '../core/Class.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Layer} from '../layer/Layer.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {Point} from '../geometry/Point.js' */\n\n/**\n * Options of `ContextMenu`.\n * @typedef {object} ContextMenuOptions\n * @property {string} [className=''] A custom CSS class name to assign to the menu.\n */\n\n/**\n * The argument of the `callback` of a `ContextMenu` item, with the location of the\n * `contextmenu` event.\n * @typedef {object} ContextMenuEvent\n * @property {LatLng} latlng The geographical point of the event.\n * @property {Point} containerPoint Pixel coordinates of the event relative to the map\n * container.\n * @property {Point} layerPoint Pixel coordinates of the event relative to the map layer.\n * @property {MouseEvent|PointerEvent} originalEvent The original DOM event.\n * @property {Layer} [relatedTarget] The layer, for menus of layers.\n */\n\n/**\n * An item of a `ContextMenu`.\n * @typedef {object} ContextMenuItem\n * @property {string} text The text of the item.\n * @property {(this: ContextMenu, event: ContextMenuEvent) => void} [callback] Called\n * when the item is chosen.\n * @property {boolean} [disabled] Whether the item is disabled.\n */\n\n/**\n * A menu opened with the `contextmenu` event (right click, or long tap on touch\n * screens) on the map or on a layer. Each item calls a function with the location\n * of the event. The menu is a [popover](https://developer.mozilla.org/docs/Web/API/Popover_API),\n * closed by clicking outside of it or pressing Escape, and can be used with the\n * keyboard (arrow keys, Enter).\n *\n * Inspired by the [Leaflet.contextmenu](https://github.com/aratcliffe/Leaflet.contextmenu) plugin.\n *\n * @example\n * ```js\n * new ContextMenu([\n * \t{text: 'Center the map here', callback: e => map.panTo(e.latlng)},\n * \t'-',\n * \t{text: 'Zoom in', callback: () => map.zoomIn()}\n * ]).addTo(map);\n *\n * new ContextMenu([\n * \t{text: 'Remove', callback: e => e.relatedTarget.remove()}\n * ]).addTo(marker);\n * ```\n */\nexport class ContextMenu extends Class {\n\n\tstatic defaultOptions = {\n\t\tclassName: ''\n\t};\n\n\t/**\n\t * Creates a context menu. Each item is an object with `text`, `callback` and the\n\t * optional `disabled`, or `'-'` for a separator. The `callback` gets an event with\n\t * `latlng`, `containerPoint`, `layerPoint`, `originalEvent` and `relatedTarget`\n\t * (the layer, for menus of layers).\n\t * @param {(ContextMenuItem|'-')[]} items\n\t * @param {ContextMenuOptions} [options]\n\t */\n\tconstructor(items, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._items = items;\n\t\tthis.callInitHooks(ContextMenu);\n\t}\n\n\t/**\n\t * Opens the menu on `contextmenu` events of the map or the layer.\n\t * @param {MaplairMap|Layer} target\n\t * @returns {this}\n\t */\n\taddTo(target) {\n\t\tthis.remove();\n\t\tthis._target = target;\n\t\ttarget.on('contextmenu', this._open, this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the menu from its map or layer.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\tthis.close();\n\t\tthis._target?.off('contextmenu', this._open, this);\n\t\tthis._target = null;\n\t\tthis._container?.remove();\n\t\tthis._container = null;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the menu.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tif (this._container?.matches(':popover-open')) {\n\t\t\tthis._container.hidePopover();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if the menu is open.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._container?.matches(':popover-open');\n\t}\n\n\t_open(e) {\n\t\t// a menu of a layer replaces the one of the map\n\t\tDomEvent.stop(e);\n\t\tconst map = this._target instanceof Layer ? this._target._map : this._target;\n\t\tif (!map) { return; }\n\n\t\tthis._map = map;\n\t\tthis._event = {\n\t\t\tlatlng: e.latlng,\n\t\t\tcontainerPoint: e.containerPoint,\n\t\t\tlayerPoint: e.layerPoint,\n\t\t\toriginalEvent: e.originalEvent,\n\t\t\trelatedTarget: this._target instanceof Layer ? this._target : undefined\n\t\t};\n\n\t\tconst container = this._createMenu(map._container);\n\t\tif (!container.matches(':popover-open')) {\n\t\t\tcontainer.showPopover();\n\t\t}\n\t\tthis._position(e.originalEvent);\n\t\tcontainer.querySelector('button:not([disabled])')?.focus({preventScroll: true});\n\t\tmap.once('movestart', this.close, this);\n\t}\n\n\t_createMenu(parent) {\n\t\tconst container = this._container ??= DomUtil.create('div', `maplair-contextmenu ${this.options.className}`);\n\t\tif (container.parentNode !== parent) {\n\t\t\tparent.appendChild(container);\n\t\t}\n\t\tcontainer.popover = 'auto';\n\t\tcontainer.setAttribute('role', 'menu');\n\t\tcontainer.replaceChildren();\n\n\t\tfor (const item of this._items) {\n\t\t\tif (item === '-') {\n\t\t\t\tDomUtil.create('div', 'maplair-contextmenu-separator', container).setAttribute('role', 'separator');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst button = DomUtil.create('button', 'maplair-contextmenu-item', container);\n\t\t\tbutton.type = 'button';\n\t\t\tbutton.setAttribute('role', 'menuitem');\n\t\t\tbutton.textContent = item.text;\n\t\t\tbutton.disabled = !!item.disabled;\n\t\t\tDomEvent.on(button, 'click', (ev) => {\n\t\t\t\tDomEvent.stop(ev);\n\t\t\t\tthis.close();\n\t\t\t\titem.callback?.call(this, this._event);\n\t\t\t});\n\t\t}\n\n\t\tDomEvent.on(container, 'keydown', this._onKeyDown, this);\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tDomEvent.on(container, 'contextmenu', DomEvent.stop);\n\t\treturn container;\n\t}\n\n\t// At the pointer, within the viewport\n\t_position(e) {\n\t\tconst container = this._container,\n\t\tviewport = document.documentElement,\n\t\tx = Math.min(e.clientX, viewport.clientWidth - container.offsetWidth),\n\t\ty = Math.min(e.clientY, viewport.clientHeight - container.offsetHeight);\n\t\tcontainer.style.left = `${Math.max(0, x)}px`;\n\t\tcontainer.style.top = `${Math.max(0, y)}px`;\n\t}\n\n\t_onKeyDown(e) {\n\t\tif (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') { return; }\n\t\tDomEvent.stop(e);\n\t\tconst buttons = [...this._container.querySelectorAll('button:not([disabled])')],\n\t\tindex = buttons.indexOf(document.activeElement),\n\t\tnext = e.key === 'ArrowDown' ? index + 1 : index - 1;\n\t\tbuttons.at(next % buttons.length)?.focus();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,cAAb,MAAa,oBAAoB,MAAM;CAEtC,OAAO,iBAAiB,EACvB,WAAW,GACZ;;;;;;;;;CAUA,YAAY,OAAO,SAAS;EAC3B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,SAAS;EACd,KAAK,cAAc,WAAW;CAC/B;;;;;;CAOA,MAAM,QAAQ;EACb,KAAK,OAAO;EACZ,KAAK,UAAU;EACf,OAAO,GAAG,eAAe,KAAK,OAAO,IAAI;EACzC,OAAO;CACR;;;;;CAMA,SAAS;EACR,KAAK,MAAM;EACX,KAAK,SAAS,IAAI,eAAe,KAAK,OAAO,IAAI;EACjD,KAAK,UAAU;EACf,KAAK,YAAY,OAAO;EACxB,KAAK,aAAa;EAClB,OAAO;CACR;;;;;CAMA,QAAQ;EACP,IAAI,KAAK,YAAY,QAAQ,eAAe,GAC3C,KAAK,WAAW,YAAY;EAE7B,OAAO;CACR;;;;;CAMA,SAAS;EACR,OAAO,CAAC,CAAC,KAAK,YAAY,QAAQ,eAAe;CAClD;CAEA,MAAM,GAAG;EAER,KAAc,CAAC;EACf,MAAM,MAAM,KAAK,mBAAmB,QAAQ,KAAK,QAAQ,OAAO,KAAK;EACrE,IAAI,CAAC,KAAO;EAEZ,KAAK,OAAO;EACZ,KAAK,SAAS;GACb,QAAQ,EAAE;GACV,gBAAgB,EAAE;GAClB,YAAY,EA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AAI,EAAE,SAAS,SAAS,eAAe,UAAU,YAAY;EACtE,UAAU,MAAM,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,EAAE;EACzC,UAAU,MAAM,MAAM,GAAG,KAAK,IAAI,GAAG,CAAC,EAAE;CACzC;CAEA,WAAW,GAAG;EACb,IAAI,EAAE,QAAQ,eAAe,EAAE,QAAQ,WAAa;EACpD,KAAc,CAAC;EACf,MAAM,UAAU,CAAC,GAAG,KAAK,WAAW,iBAAiB,wBAAwB,CAAC,GAC9E,QAAQ,QAAQ,QAAQ,SAAS,aAAa,GAC9C,OAAO,EAAE,QAAQ,cAAc,QAAQ,IAAI,QAAQ;EACnD,QAAQ,GAAG,OAAO,QAAQ,MAAM,CAAC,EAAE,MAAM;CAC1C;AACD"}
1
+ {"version":3,"file":"ContextMenu.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/ContextMenu.js"],"sourcesContent":["import {Class} from '../core/Class.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {Layer} from '../layer/Layer.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {LatLng} from '../geo/LatLng.js' */\n/** @import {Point} from '../geometry/Point.js' */\n\n/**\n * Options of `ContextMenu`.\n * @typedef {object} ContextMenuOptions\n * @property {string} [className=''] A custom CSS class name to assign to the menu.\n */\n\n/**\n * The argument of the `callback` of a `ContextMenu` item, with the location of the\n * `contextmenu` event.\n * @typedef {object} ContextMenuEvent\n * @property {LatLng} latlng The geographical point of the event.\n * @property {Point} containerPoint Pixel coordinates of the event relative to the map\n * container.\n * @property {Point} layerPoint Pixel coordinates of the event relative to the map layer.\n * @property {MouseEvent|PointerEvent} originalEvent The original DOM event.\n * @property {Layer} [relatedTarget] The layer, for menus of layers.\n */\n\n/**\n * An item of a `ContextMenu`.\n * @typedef {object} ContextMenuItem\n * @property {string} text The text of the item.\n * @property {(this: ContextMenu, event: ContextMenuEvent) => void} [callback] Called\n * when the item is chosen.\n * @property {boolean} [disabled] Whether the item is disabled.\n */\n\n/**\n * A menu opened with the `contextmenu` event (right click, or long tap on touch\n * screens) on the map or on a layer. Each item calls a function with the location\n * of the event. The menu is a [popover](https://developer.mozilla.org/docs/Web/API/Popover_API),\n * closed by clicking outside of it or pressing Escape, and can be used with the\n * keyboard (arrow keys, Enter).\n *\n * Inspired by the [Leaflet.contextmenu](https://github.com/aratcliffe/Leaflet.contextmenu) plugin.\n *\n * @example\n * ```js\n * new ContextMenu([\n * \t{text: 'Center the map here', callback: e => map.panTo(e.latlng)},\n * \t'-',\n * \t{text: 'Zoom in', callback: () => map.zoomIn()}\n * ]).addTo(map);\n *\n * new ContextMenu([\n * \t{text: 'Remove', callback: e => e.relatedTarget.remove()}\n * ]).addTo(marker);\n * ```\n */\nexport class ContextMenu extends Class {\n\n\tstatic defaultOptions = {\n\t\tclassName: ''\n\t};\n\n\t/**\n\t * Creates a context menu. Each item is an object with `text`, `callback` and the\n\t * optional `disabled`, or `'-'` for a separator. The `callback` gets an event with\n\t * `latlng`, `containerPoint`, `layerPoint`, `originalEvent` and `relatedTarget`\n\t * (the layer, for menus of layers).\n\t * @param {(ContextMenuItem|'-')[]} items\n\t * @param {ContextMenuOptions} [options]\n\t */\n\tconstructor(items, options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\t\tthis._items = items;\n\t\tthis.callInitHooks(ContextMenu);\n\t}\n\n\t/**\n\t * Opens the menu on `contextmenu` events of the map or the layer.\n\t * @param {MaplairMap|Layer} target\n\t * @returns {this}\n\t */\n\taddTo(target) {\n\t\tthis.remove();\n\t\tthis._target = target;\n\t\ttarget.on('contextmenu', this._open, this);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the menu from its map or layer.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\tthis.close();\n\t\tthis._target?.off('contextmenu', this._open, this);\n\t\tthis._target = null;\n\t\tthis._container?.remove();\n\t\tthis._container = null;\n\t\treturn this;\n\t}\n\n\t/**\n\t * Closes the menu.\n\t * @returns {this}\n\t */\n\tclose() {\n\t\tif (this._container?.matches(':popover-open')) {\n\t\t\tthis._container.hidePopover();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns `true` if the menu is open.\n\t * @returns {boolean}\n\t */\n\tisOpen() {\n\t\treturn !!this._container?.matches(':popover-open');\n\t}\n\n\t_open(e) {\n\t\t// a menu of a layer replaces the one of the map\n\t\tDomEvent.stop(e);\n\t\tconst map = this._target instanceof Layer ? this._target._map : this._target;\n\t\tif (!map) { return; }\n\n\t\tthis._map = map;\n\t\tthis._event = {\n\t\t\tlatlng: e.latlng,\n\t\t\tcontainerPoint: e.containerPoint,\n\t\t\tlayerPoint: e.layerPoint,\n\t\t\toriginalEvent: e.originalEvent,\n\t\t\trelatedTarget: this._target instanceof Layer ? this._target : undefined\n\t\t};\n\n\t\tconst container = this._createMenu(map._container);\n\t\tif (!container.matches(':popover-open')) {\n\t\t\tcontainer.showPopover();\n\t\t}\n\t\tthis._position(e.originalEvent);\n\t\tcontainer.querySelector('button:not([disabled])')?.focus({preventScroll: true});\n\t\tmap.once('movestart', this.close, this);\n\t}\n\n\t_createMenu(parent) {\n\t\tconst container = this._container ??= DomUtil.create('div', `maplair-contextmenu ${this.options.className}`);\n\t\tif (container.parentNode !== parent) {\n\t\t\tparent.append(container);\n\t\t}\n\t\tcontainer.popover = 'auto';\n\t\tcontainer.setAttribute('role', 'menu');\n\t\tcontainer.replaceChildren();\n\n\t\tfor (const item of this._items) {\n\t\t\tif (item === '-') {\n\t\t\t\tDomUtil.create('div', 'maplair-contextmenu-separator', container).setAttribute('role', 'separator');\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tconst button = DomUtil.create('button', 'maplair-contextmenu-item', container);\n\t\t\tbutton.type = 'button';\n\t\t\tbutton.setAttribute('role', 'menuitem');\n\t\t\tbutton.textContent = item.text;\n\t\t\tbutton.disabled = !!item.disabled;\n\t\t\tDomEvent.on(button, 'click', (ev) => {\n\t\t\t\tDomEvent.stop(ev);\n\t\t\t\tthis.close();\n\t\t\t\titem.callback?.call(this, this._event);\n\t\t\t});\n\t\t}\n\n\t\tDomEvent.on(container, 'keydown', this._onKeyDown, this);\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tDomEvent.on(container, 'contextmenu', DomEvent.stop);\n\t\treturn container;\n\t}\n\n\t// At the pointer, within the viewport\n\t_position(e) {\n\t\tconst container = this._container,\n\t\tviewport = document.documentElement,\n\t\tx = Math.min(e.clientX, viewport.clientWidth - container.offsetWidth),\n\t\ty = Math.min(e.clientY, viewport.clientHeight - container.offsetHeight);\n\t\tcontainer.style.left = `${Math.max(0, x)}px`;\n\t\tcontainer.style.top = `${Math.max(0, y)}px`;\n\t}\n\n\t_onKeyDown(e) {\n\t\tif (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') { return; }\n\t\tDomEvent.stop(e);\n\t\tconst buttons = [...this._container.querySelectorAll('button:not([disabled])')],\n\t\tindex = buttons.indexOf(document.activeElement),\n\t\tnext = e.key === 'ArrowDown' ? index + 1 : index - 1;\n\t\tbuttons.at(next % buttons.length)?.focus();\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA0DA,IAAa,cAAb,MAAa,oBAAoB,MAAM;CAEtC,OAAO,iBAAiB,EACvB,WAAW,GACZ;;;;;;;;;CAUA,YAAY,OAAO,SAAS;EAC3B,MAAM;EACN,WAAgB,MAAM,OAAO;EAC7B,KAAK,SAAS;EACd,KAAK,cAAc,WAAW;CAC/B;;;;;;CAOA,MAAM,QAAQ;EACb,KAAK,OAAO;EACZ,KAAK,UAAU;EACf,OAAO,GAAG,eAAe,KAAK,OAAO,IAAI;EACzC,OAAO;CACR;;;;;CAMA,SAAS;EACR,KAAK,MAAM;EACX,KAAK,SAAS,IAAI,eAAe,KAAK,OAAO,IAAI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,OAAO,cAAc,KAAK;GAC1B,OAAO,WAAW,CAAC,CAAC,KAAK;GACzB,GAAY,QAAQ,UAAU,OAAO;IACpC,KAAc,EAAE;IAChB,KAAK,MAAM;IACX,KAAK,UAAU,KAAK,MAAM,KAAK,MAAM;GACtC,CAAC;EACF;EAEA,GAAY,WAAW,WAAW,KAAK,YAAY,IAAI;EACvD,wBAAiC,SAAS;EAC1C,yBAAkC,SAAS;EAC3C,GAAY,WAAW,eAAeC,IAAa;EACnD,OAAO;CACR;CAGA,UAAU,GAAG;EACZ,MAAM,YAAY,KAAK,YACvB,WAAW,SAAS,iBACpB,IAAI,KAAK,IAAI,EAAE,SAAS,SAAS,cAAc,UAAU,WAAW,GACpE,IAAI,KAAK,IAAI,EAAE,SAAS,SAAS,eAAe,UAAU,YAAY;EACtE,UAAU,MAAM,OAAO,GAAG,KAAK,IAAI,GAAG,CAAC,EAAE;EACzC,UAAU,MAAM,MAAM,GAAG,KAAK,IAAI,GAAG,CAAC,EAAE;CACzC;CAEA,WAAW,GAAG;EACb,IAAI,EAAE,QAAQ,eAAe,EAAE,QAAQ,WAAa;EACpD,KAAc,CAAC;EACf,MAAM,UAAU,CAAC,GAAG,KAAK,WAAW,iBAAiB,wBAAwB,CAAC,GAC9E,QAAQ,QAAQ,QAAQ,SAAS,aAAa,GAC9C,OAAO,EAAE,QAAQ,cAAc,QAAQ,IAAI,QAAQ;EACnD,QAAQ,GAAG,OAAO,QAAQ,MAAM,CAAC,EAAE,MAAM;CAC1C;AACD"}
@@ -58,12 +58,16 @@ const mapControlMethods = {
58
58
  * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that
59
59
  * removes the listeners previously added in `onAdd`. Called on
60
60
  * [`control.remove()`](#control-remove).
61
+ * @property {() => Record<string, Function>} [getEvents] Should return an object like
62
+ * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this object
63
+ * will be automatically added and removed from the map with your control.
61
64
  * @lends Control
62
65
  */
63
66
  const controlOrders = /* @__PURE__ */ new WeakMap();
64
67
  /**
65
- * Control is a base class for implementing map controls. Handles positioning.
66
- * All other controls extend from this class.
68
+ * Base class for map controls such as `ZoomControl`, `AttributionControl`,
69
+ * `LayersControl` and `ScaleControl`, which handles positioning them. Extend it to
70
+ * create your own controls.
67
71
  *
68
72
  * Every control should extend from `Control` and (re-)implement the following methods:
69
73
  *
@@ -73,6 +77,9 @@ const controlOrders = /* @__PURE__ */ new WeakMap();
73
77
  * * `onRemove(map: MaplairMap)` (optional) should contain all clean up code that removes
74
78
  * the listeners previously added in [`onAdd`](#control-onadd). Called on
75
79
  * [`control.remove()`](#control-remove).
80
+ * * `getEvents(): Object` (optional) should return an object like
81
+ * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this
82
+ * object will be automatically added and removed from the map with your control.
76
83
  */
77
84
  var Control = class Control extends Class {
78
85
  static defaultOptions = {
@@ -126,7 +133,11 @@ var Control = class Control extends Class {
126
133
  const order = this.options.order ?? 0, bottom = pos.includes("bottom"), children = [...corner.children];
127
134
  controlOrders.set(container, order);
128
135
  corner.insertBefore(container, children.find((el) => bottom ? (controlOrders.get(el) ?? 0) <= order : (controlOrders.get(el) ?? 0) > order) ?? null);
129
- this._map.on("unload", this.remove, this);
136
+ this._mapEvents = {
137
+ ...this.getEvents?.(),
138
+ unload: this.remove
139
+ };
140
+ map.on(this._mapEvents, this);
130
141
  return this;
131
142
  }
132
143
  /**
@@ -136,17 +147,11 @@ var Control = class Control extends Class {
136
147
  remove() {
137
148
  if (!this._map) return this;
138
149
  this._container.remove();
139
- if (this.onRemove) this.onRemove(this._map);
140
- this._map.off("unload", this.remove, this);
150
+ this._map.off(this._mapEvents, this);
151
+ this.onRemove?.(this._map);
141
152
  this._map = null;
142
153
  return this;
143
154
  }
144
- _refocusOnMap(e) {
145
- if (this._map && e && !(e.screenX === 0 && e.screenY === 0)) this._map.getContainer().focus({
146
- preventScroll: true,
147
- focusVisible: false
148
- });
149
- }
150
155
  /**
151
156
  * Registers this default feature on the map class, called by `MaplairMap` itself.
152
157
  * @internal
@@ -1 +1 @@
1
- {"version":3,"file":"Control.js","names":["DomUtil.create"],"sources":["../../../src/control/Control.js"],"sourcesContent":["import {Class} from '../core/Class.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `Control`, inherited by all controls.\n * @typedef {object} ControlOptions\n * @property {string} [position='topright'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [order=0] The position of the control within its corner: controls\n * with a lower order are closer to the corner of the map, those with the same order in\n * the order of adding.\n */\n\n/**\n * Methods of `MaplairMap` for controls.\n * @lends MaplairMap.prototype\n */\nconst mapControlMethods = {\n\t/**\n\t * Adds the given control to the map.\n\t * @group Methods for layers and controls\n\t * @param {Control} control\n\t * @returns {this}\n\t */\n\taddControl(control) {\n\t\tcontrol.addTo(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given control from the map.\n\t * @group Methods for layers and controls\n\t * @param {Control} control\n\t * @returns {this}\n\t */\n\tremoveControl(control) {\n\t\tcontrol.remove();\n\t\treturn this;\n\t},\n\n\t_initControlPos() {\n\t\tconst corners = this._controlCorners = {},\n\t\tl = 'maplair-',\n\t\tcontainer = this._controlContainer = DomUtil.create('div', `${l}control-container`, this._container);\n\n\t\tfor (const v of ['top', 'bottom']) {\n\t\t\tfor (const h of ['left', 'right']) {\n\t\t\t\tcorners[v + h] = DomUtil.create('div', `${l + v} ${l}${h}`, container);\n\t\t\t}\n\t\t}\n\t},\n\n\t_clearControlPos() {\n\t\tthis._controlContainer.remove();\n\t\tdelete this._controlCorners;\n\t\tdelete this._controlContainer;\n\t}\n};\n/** @typedef {typeof mapControlMethods} MapControlMethods */\n\n/**\n * The methods which controls implement, see `Control`.\n * @typedef {object} ControlExtensionMethods\n * @property {(map: MaplairMap) => HTMLElement} [onAdd] Should return the container DOM\n * element for the control and add listeners on relevant map events. Called on\n * [`control.addTo(map)`](#control-addto).\n * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that\n * removes the listeners previously added in `onAdd`. Called on\n * [`control.remove()`](#control-remove).\n * @lends Control\n */\n\n// The `order` option of the containers of added controls\nconst controlOrders = new WeakMap();\n\n/**\n * Control is a base class for implementing map controls. Handles positioning.\n * All other controls extend from this class.\n *\n * Every control should extend from `Control` and (re-)implement the following methods:\n *\n * * `onAdd(map: MaplairMap): HTMLElement` should return the container DOM element for\n * the control and add listeners on relevant map events. Called on\n * [`control.addTo(map)`](#control-addTo).\n * * `onRemove(map: MaplairMap)` (optional) should contain all clean up code that removes\n * the listeners previously added in [`onAdd`](#control-onadd). Called on\n * [`control.remove()`](#control-remove).\n */\nexport class Control extends Class {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topright',\n\t\torder: 0\n\t};\n\n\t/**\n\t * @param {ControlOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(Control);\n\t}\n\n\t/**\n\t * Returns the position of the control.\n\t * @returns {string}\n\t */\n\tgetPosition() {\n\t\treturn this.options.position;\n\t}\n\n\t/**\n\t * Sets the position of the control.\n\t * @param {string} position\n\t * @returns {this}\n\t */\n\tsetPosition(position) {\n\t\tconst map = this._map;\n\n\t\tmap?.removeControl(this);\n\n\t\tthis.options.position = position;\n\n\t\tmap?.addControl(this);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTMLElement that contains the control.\n\t * @returns {HTMLElement}\n\t */\n\tgetContainer() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Adds the control to the given map.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tthis.remove();\n\t\tthis._map = map;\n\n\t\tconst container = this._container = this.onAdd(map),\n\t\tpos = this.getPosition(),\n\t\tcorner = map._controlCorners[pos];\n\n\t\tcontainer.classList.add('maplair-control');\n\n\t\t// sorted by order from the corner of the map (bottom corners are filled upwards),\n\t\t// farther than the controls with the same order\n\t\tconst order = this.options.order ?? 0,\n\t\tbottom = pos.includes('bottom'),\n\t\tchildren = [...corner.children];\n\t\tcontrolOrders.set(container, order);\n\t\tcorner.insertBefore(container, children.find(el => bottom ?\n\t\t\t(controlOrders.get(el) ?? 0) <= order :\n\t\t\t(controlOrders.get(el) ?? 0) > order) ?? null);\n\n\t\tthis._map.on('unload', this.remove, this);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the control from the map it is currently active on.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\tif (!this._map) {\n\t\t\treturn this;\n\t\t}\n\n\t\tthis._container.remove();\n\n\t\tif (this.onRemove) {\n\t\t\tthis.onRemove(this._map);\n\t\t}\n\n\t\tthis._map.off('unload', this.remove, this);\n\t\tthis._map = null;\n\n\t\treturn this;\n\t}\n\n\t_refocusOnMap(e) {\n\t\t// We exclude keyboard-click event to keep the focus on the control for accessibility.\n\t\t// The position of keyboard-click events are x=0 and y=0.\n\t\tif (this._map && e && !(e.screenX === 0 && e.screenY === 0)) {\n\t\t\tthis._map.getContainer().focus({preventScroll: true, focusVisible: false});\n\t\t}\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapControlMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;;;;;;;CAOzB,WAAW,SAAS;EACnB,QAAQ,MAAM,IAAI;EAClB,OAAO;CACR;;;;;;;CAQA,cAAc,SAAS;EACtB,QAAQ,OAAO;EACf,OAAO;CACR;CAEA,kBAAkB;EACjB,MAAM,UAAU,KAAK,kBAAkB,CAAC,GACxC,IAAI,YACJ,YAAY,KAAK,oBAAoBA,OAAe,OAAO,GAAG,EAAE,oBAAoB,KAAK,UAAU;EAE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AK,QAAQ,IAAI;EAExC,OAAO;CACR;;;;;CAMA,SAAS;EACR,IAAI,CAAC,KAAK,MACT,OAAO;EAGR,KAAK,WAAW,OAAO;EAEvB,IAAI,KAAK,UACR,KAAK,SAAS,KAAK,IAAI;EAGxB,KAAK,KAAK,IAAI,UAAU,KAAK,QAAQ,IAAI;EACzC,KAAK,OAAO;EAEZ,OAAO;CACR;CAEA,cAAc,GAAG;EAGhB,IAAI,KAAK,QAAQ,KAAK,EAAE,EAAE,YAAY,KAAK,EAAE,YAAY,IACxD,KAAK,KAAK,aAAa,CAAC,CAAC,MAAM;GAAC,eAAe;GAAM,cAAc;EAAK,CAAC;CAE3E;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,iBAAiB;CACrC;AACD"}
1
+ {"version":3,"file":"Control.js","names":["DomUtil.create"],"sources":["../../../src/control/Control.js"],"sourcesContent":["import {Class} from '../core/Class.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `Control`, inherited by all controls.\n * @typedef {object} ControlOptions\n * @property {string} [position='topright'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [order=0] The position of the control within its corner: controls\n * with a lower order are closer to the corner of the map, those with the same order in\n * the order of adding.\n */\n\n/**\n * Methods of `MaplairMap` for controls.\n * @lends MaplairMap.prototype\n */\nconst mapControlMethods = {\n\t/**\n\t * Adds the given control to the map.\n\t * @group Methods for layers and controls\n\t * @param {Control} control\n\t * @returns {this}\n\t */\n\taddControl(control) {\n\t\tcontrol.addTo(this);\n\t\treturn this;\n\t},\n\n\t/**\n\t * Removes the given control from the map.\n\t * @group Methods for layers and controls\n\t * @param {Control} control\n\t * @returns {this}\n\t */\n\tremoveControl(control) {\n\t\tcontrol.remove();\n\t\treturn this;\n\t},\n\n\t_initControlPos() {\n\t\tconst corners = this._controlCorners = {},\n\t\tl = 'maplair-',\n\t\tcontainer = this._controlContainer = DomUtil.create('div', `${l}control-container`, this._container);\n\n\t\tfor (const v of ['top', 'bottom']) {\n\t\t\tfor (const h of ['left', 'right']) {\n\t\t\t\tcorners[v + h] = DomUtil.create('div', `${l + v} ${l}${h}`, container);\n\t\t\t}\n\t\t}\n\t},\n\n\t_clearControlPos() {\n\t\tthis._controlContainer.remove();\n\t\tdelete this._controlCorners;\n\t\tdelete this._controlContainer;\n\t}\n};\n/** @typedef {typeof mapControlMethods} MapControlMethods */\n\n/**\n * The methods which controls implement, see `Control`.\n * @typedef {object} ControlExtensionMethods\n * @property {(map: MaplairMap) => HTMLElement} [onAdd] Should return the container DOM\n * element for the control and add listeners on relevant map events. Called on\n * [`control.addTo(map)`](#control-addto).\n * @property {(map: MaplairMap) => void} [onRemove] Should contain all clean up code that\n * removes the listeners previously added in `onAdd`. Called on\n * [`control.remove()`](#control-remove).\n * @property {() => Record<string, Function>} [getEvents] Should return an object like\n * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this object\n * will be automatically added and removed from the map with your control.\n * @lends Control\n */\n\n// The `order` option of the containers of added controls\nconst controlOrders = new WeakMap();\n\n/**\n * Base class for map controls such as `ZoomControl`, `AttributionControl`,\n * `LayersControl` and `ScaleControl`, which handles positioning them. Extend it to\n * create your own controls.\n *\n * Every control should extend from `Control` and (re-)implement the following methods:\n *\n * * `onAdd(map: MaplairMap): HTMLElement` should return the container DOM element for\n * the control and add listeners on relevant map events. Called on\n * [`control.addTo(map)`](#control-addTo).\n * * `onRemove(map: MaplairMap)` (optional) should contain all clean up code that removes\n * the listeners previously added in [`onAdd`](#control-onadd). Called on\n * [`control.remove()`](#control-remove).\n * * `getEvents(): Object` (optional) should return an object like\n * `{zoomend: this._update}` for [`on`](#evented-on). The event handlers in this\n * object will be automatically added and removed from the map with your control.\n */\nexport class Control extends Class {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topright',\n\t\torder: 0\n\t};\n\n\t/**\n\t * @param {ControlOptions} [options]\n\t */\n\tconstructor(options) {\n\t\tsuper();\n\t\tUtil.setOptions(this, options);\n\n\t\tthis.callInitHooks(Control);\n\t}\n\n\t/**\n\t * Returns the position of the control.\n\t * @returns {string}\n\t */\n\tgetPosition() {\n\t\treturn this.options.position;\n\t}\n\n\t/**\n\t * Sets the position of the control.\n\t * @param {string} position\n\t * @returns {this}\n\t */\n\tsetPosition(position) {\n\t\tconst map = this._map;\n\n\t\tmap?.removeControl(this);\n\n\t\tthis.options.position = position;\n\n\t\tmap?.addControl(this);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the HTMLElement that contains the control.\n\t * @returns {HTMLElement}\n\t */\n\tgetContainer() {\n\t\treturn this._container;\n\t}\n\n\t/**\n\t * Adds the control to the given map.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tthis.remove();\n\t\tthis._map = map;\n\n\t\tconst container = this._container = this.onAdd(map),\n\t\tpos = this.getPosition(),\n\t\tcorner = map._controlCorners[pos];\n\n\t\tcontainer.classList.add('maplair-control');\n\n\t\t// sorted by order from the corner of the map (bottom corners are filled upwards),\n\t\t// farther than the controls with the same order\n\t\tconst order = this.options.order ?? 0,\n\t\tbottom = pos.includes('bottom'),\n\t\tchildren = [...corner.children];\n\t\tcontrolOrders.set(container, order);\n\t\tcorner.insertBefore(container, children.find(el => bottom ?\n\t\t\t(controlOrders.get(el) ?? 0) <= order :\n\t\t\t(controlOrders.get(el) ?? 0) > order) ?? null);\n\n\t\tthis._mapEvents = {...this.getEvents?.(), unload: this.remove};\n\t\tmap.on(this._mapEvents, this);\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Removes the control from the map it is currently active on.\n\t * @returns {this}\n\t */\n\tremove() {\n\t\tif (!this._map) {\n\t\t\treturn this;\n\t\t}\n\n\t\tthis._container.remove();\n\t\tthis._map.off(this._mapEvents, this);\n\t\tthis.onRemove?.(this._map);\n\n\t\tthis._map = null;\n\n\t\treturn this;\n\t}\n\n\t/**\n\t * Registers this default feature on the map class, called by `MaplairMap` itself.\n\t * @internal\n\t * @param {typeof MaplairMap} MaplairMap\n\t */\n\tstatic register(MaplairMap) {\n\t\tMaplairMap.include(mapControlMethods);\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAoBA,MAAM,oBAAoB;;;;;;;CAOzB,WAAW,SAAS;EACnB,QAAQ,MAAM,IAAI;EAClB,OAAO;CACR;;;;;;;CAQA,cAAc,SAAS;EACtB,QAAQ,OAAO;EACf,OAAO;CACR;CAEA,kBAAkB;EACjB,MAAM,UAAU,KAAK,kBAAkB,CAAC,GACxC,IAAI,YACJ,YAAY,KAAK,oBAAoBA,OAAe,OAAO,GAAG,EAAE,oBAAoB,KAAK,UAAU;EAEnG,KAAK,MAAM,KAAK,CAAC,OAAO,QAAQ,GAC/B,KAAK,MAAM,KAAK,CAAC,QAAQ,OAAO,GAC/B,QAAQ,IAAI,KAAKA,OAAe,OAAO,GAAG,IAAI,EAAE,GAAG,IAAI,KAAK,SAAS;CAGxE;CAEA,mBAAmB;EAClB,KAAK,kBAAkB,OAAO;EAC9B,OAAO,KAAK;EACZ,OAAO,KAAK;CACb;AACD;;;;;;;;;;;;;;;;AAmBA,MAAM,gCAAgB,IAAI,QAAQ;;;;;;;;;;;;;;;;;;AAmBlC,IAAa,UAAb,MAAa,gBAAgB,MAAM;CAElC,OAAO,iBAAiB;EACvB,UAAU;EACV,OAAO;CACR;;;;CAKA,YAAY,SAAS;EACpB,MAAM;EACN,WAAgB,MAAM,OAAO;EAE7B,KAAK,cAAc,OAAO;CAC3B;;;;;CAMA,cAAc;EACb,OAAO,KAAK,QAAQ;CACrB;;;;;;CAOA,YAAY,UAAU;EACrB,MAAM,MAAM,KAAK;EAEjB,KAAK,cAAc,IAAI;EAEvB,KAAK,QAAQ,WAAW;EAExB,KAAK,WAAW,IAAI;EAEpB,OAAO;CACR;;;;;CAMA,eAAe;EACd,OAAO,KAAK;CACb;;;;;;CAOA,MAAM,KAAK;EACV,KAAK,OAAO;EACZ,KAAK,OAAO;EAEZ,MAAM,YAAY,KAAK,aAAa,KAAK,MAAM,GAAG,GAClD,MAAM,KAAK,YAAY,GACvB,SAAS,IAAI,gBAAgB;EAE7B,UAAU,UAAU,IAAI,iBAAiB;EAIzC,MAAM,QAAQ,KAAK,QAAQ,SAAS,GACpC,SAAS,IAAI,SAAS,QAAQ,GAC9B,WAAW,CAAC,GAAG,OAAO,QAAQ;EAC9B,cAAc,IAAI,WAAW,KAAK;EAClC,OAAO,aAAa,WAAW,SAAS,MAAK,OAAM,UACjD,cAAc,IAAI,EAAE,KAAK,MAAM,SAC/B,cAAc,IAAI,EAAE,KAAK,KAAK,KAAK,KAAK,IAAI;EAE9C,KAAK,aAAa;GAAC,GAAG,KAAK,YAAY;GAAG,QAAQ,KAAK;EAAM;EAC7D,IAAI,GAAG,KAAK,YAAY,IAAI;EAE5B,OAAO;CACR;;;;;CAMA,SAAS;EACR,IAAI,CAAC,KAAK,MACT,OAAO;EAGR,KAAK,WAAW,OAAO;EACvB,KAAK,KAAK,IAAI,KAAK,YAAY,IAAI;EACnC,KAAK,WAAW,KAAK,IAAI;EAEzB,KAAK,OAAO;EAEZ,OAAO;CACR;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,QAAQ,iBAAiB;CACrC;AACD"}
@@ -131,7 +131,6 @@ var FullscreenControl = class FullscreenControl extends Control {
131
131
  disableClickPropagation(button);
132
132
  on(button, "click", stop);
133
133
  on(button, "click", this._toggleFullscreen, this);
134
- on(button, "click", this._refocusOnMap, this);
135
134
  this._update();
136
135
  map.on("fullscreenchange", this._update, this);
137
136
  return container;