maplair 4.4.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 (121) hide show
  1. package/CHANGELOG.md +62 -0
  2. package/dist/esm/control/AttributionControl.js +20 -3
  3. package/dist/esm/control/AttributionControl.js.map +1 -1
  4. package/dist/esm/control/LayersControl.js +35 -20
  5. package/dist/esm/control/LayersControl.js.map +1 -1
  6. package/dist/esm/control/ScaleControl.js +3 -3
  7. package/dist/esm/control/ScaleControl.js.map +1 -1
  8. package/dist/esm/control/ZoomControl.js +1 -0
  9. package/dist/esm/control/ZoomControl.js.map +1 -1
  10. package/dist/esm/core/Util.js +1 -1
  11. package/dist/esm/core/Util.js.map +1 -1
  12. package/dist/esm/dom/DomEvent.PointerEvents.js +19 -2
  13. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  14. package/dist/esm/dom/Draggable.js +6 -2
  15. package/dist/esm/dom/Draggable.js.map +1 -1
  16. package/dist/esm/geo/LatLng.js +1 -1
  17. package/dist/esm/geo/LatLng.js.map +1 -1
  18. package/dist/esm/geo/LatLngBounds.js +1 -1
  19. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  20. package/dist/esm/geometry/Bounds.js +1 -1
  21. package/dist/esm/geometry/Bounds.js.map +1 -1
  22. package/dist/esm/geometry/Point.js +4 -2
  23. package/dist/esm/geometry/Point.js.map +1 -1
  24. package/dist/esm/geometry/PolyUtil.js +10 -3
  25. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  26. package/dist/esm/layer/BlanketOverlay.js +2 -1
  27. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  28. package/dist/esm/layer/DivOverlay.js +3 -3
  29. package/dist/esm/layer/DivOverlay.js.map +1 -1
  30. package/dist/esm/layer/ImageOverlay.js +1 -1
  31. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  32. package/dist/esm/layer/Layer.js +1 -1
  33. package/dist/esm/layer/Layer.js.map +1 -1
  34. package/dist/esm/layer/Popup.js +3 -4
  35. package/dist/esm/layer/Popup.js.map +1 -1
  36. package/dist/esm/layer/Tooltip.js +31 -22
  37. package/dist/esm/layer/Tooltip.js.map +1 -1
  38. package/dist/esm/layer/marker/Icon.js +25 -6
  39. package/dist/esm/layer/marker/Icon.js.map +1 -1
  40. package/dist/esm/layer/marker/Marker.Drag.js +5 -5
  41. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  42. package/dist/esm/layer/marker/Marker.js +5 -5
  43. package/dist/esm/layer/marker/Marker.js.map +1 -1
  44. package/dist/esm/layer/tile/GridLayer.js +11 -5
  45. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  46. package/dist/esm/layer/tile/TileLayer.js +10 -6
  47. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  48. package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
  49. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  50. package/dist/esm/layer/vector/Canvas.js +2 -2
  51. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  52. package/dist/esm/layer/vector/Circle.js +2 -3
  53. package/dist/esm/layer/vector/Circle.js.map +1 -1
  54. package/dist/esm/layer/vector/CircleMarker.js +6 -3
  55. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  56. package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
  57. package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
  58. package/dist/esm/map/Map.Rotation.js +3 -2
  59. package/dist/esm/map/Map.Rotation.js.map +1 -1
  60. package/dist/esm/map/Map.js +58 -26
  61. package/dist/esm/map/Map.js.map +1 -1
  62. package/dist/esm/map/MapSync.js +1 -1
  63. package/dist/esm/map/MapSync.js.map +1 -1
  64. package/dist/esm/map/handler/BoxZoomHandler.js +2 -0
  65. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  66. package/dist/esm/map/handler/DragHandler.js +7 -2
  67. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  68. package/dist/esm/map/handler/PinchZoomHandler.js +1 -1
  69. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  70. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +1 -1
  71. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  72. package/dist/esm/map/handler/TapDragZoomHandler.js +1 -1
  73. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  74. package/dist/esm/package.js +1 -1
  75. package/dist/maplair-global-src.js +289 -140
  76. package/dist/maplair-global-src.js.map +1 -1
  77. package/dist/maplair-global.js +2 -2
  78. package/dist/maplair-global.js.map +1 -1
  79. package/dist/maplair-src.js +289 -140
  80. package/dist/maplair-src.js.map +1 -1
  81. package/dist/maplair.css +1 -1
  82. package/dist/maplair.js +2 -2
  83. package/dist/maplair.js.map +1 -1
  84. package/package.json +1 -1
  85. package/src/control/AttributionControl.js +29 -3
  86. package/src/control/LayersControl.js +47 -27
  87. package/src/control/ScaleControl.js +6 -3
  88. package/src/control/ZoomControl.js +1 -0
  89. package/src/core/Util.js +1 -1
  90. package/src/dom/DomEvent.PointerEvents.js +22 -2
  91. package/src/dom/Draggable.js +6 -2
  92. package/src/geo/LatLng.js +2 -1
  93. package/src/geo/LatLngBounds.js +1 -1
  94. package/src/geometry/Bounds.js +1 -1
  95. package/src/geometry/Point.js +4 -2
  96. package/src/geometry/PolyUtil.js +12 -3
  97. package/src/layer/BlanketOverlay.js +5 -2
  98. package/src/layer/DivOverlay.js +3 -3
  99. package/src/layer/ImageOverlay.js +3 -2
  100. package/src/layer/Layer.js +1 -1
  101. package/src/layer/Popup.js +3 -4
  102. package/src/layer/Tooltip.js +34 -27
  103. package/src/layer/marker/Icon.js +25 -5
  104. package/src/layer/marker/Marker.Drag.js +6 -6
  105. package/src/layer/marker/Marker.js +5 -5
  106. package/src/layer/tile/GridLayer.js +20 -7
  107. package/src/layer/tile/TileLayer.js +14 -7
  108. package/src/layer/tile/WMSTileLayer.js +4 -2
  109. package/src/layer/vector/Canvas.js +2 -2
  110. package/src/layer/vector/Circle.js +3 -5
  111. package/src/layer/vector/CircleMarker.js +5 -2
  112. package/src/layer/vector/Path.ZoomStyles.js +5 -3
  113. package/src/map/Map.Rotation.js +6 -3
  114. package/src/map/Map.js +63 -32
  115. package/src/map/MapSync.js +1 -1
  116. package/src/map/handler/BoxZoomHandler.js +3 -0
  117. package/src/map/handler/DragHandler.js +5 -5
  118. package/src/map/handler/PinchZoomHandler.js +1 -1
  119. package/src/map/handler/ScrollWheelZoomHandler.js +1 -1
  120. package/src/map/handler/TapDragZoomHandler.js +1 -1
  121. package/src/maplair.css +12 -1
package/CHANGELOG.md CHANGED
@@ -3,6 +3,68 @@ 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
+
6
68
  ## 4.4.0 (2026-11-09)
7
69
 
8
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.
@@ -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
  /**
@@ -78,7 +79,8 @@ var AttributionControl = class AttributionControl extends Control {
78
79
  getEvents() {
79
80
  return {
80
81
  layeradd: this._addLayer,
81
- layerremove: this._removeLayer
82
+ layerremove: this._removeLayer,
83
+ zoomend: this._onZoomEnd
82
84
  };
83
85
  }
84
86
  /**
@@ -91,12 +93,27 @@ var AttributionControl = class AttributionControl extends Control {
91
93
  const text = layer.getAttribution?.();
92
94
  if (!text || this._layerAttributions.has(layer)) return;
93
95
  this._layerAttributions.set(layer, text);
94
- this.addAttribution(text, layer.options?.attributionOrder);
96
+ this._updateLayer(layer);
95
97
  }
96
98
  _removeLayer({ layer }) {
97
- this.removeAttribution(this._layerAttributions.get(layer));
99
+ if (this._shownLayers.delete(layer)) this.removeAttribution(this._layerAttributions.get(layer));
98
100
  this._layerAttributions.delete(layer);
99
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
+ }
100
117
  /**
101
118
  * The HTML text shown before the attributions. Pass `false` to disable.
102
119
  * @param {string|false} prefix
@@ -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\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};\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.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\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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K,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"}
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;E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._lastZIndex = 0;
154
154
  this._handlingClick = false;
155
155
  this._preventClick = false;
156
+ this._needsUpdate = false;
156
157
  for (const [name, layer] of Object.entries(baseLayers ?? {})) this._addLayer(layer, name);
157
158
  for (const [name, layer] of Object.entries(overlays ?? {})) this._addLayer(layer, name, true);
158
159
  this.callInitHooks(LayersControl);
@@ -238,6 +239,7 @@ var LayersControl = class LayersControl extends Control {
238
239
  * @returns {this}
239
240
  */
240
241
  selectLayer(layer) {
242
+ if (this._needsUpdate) this._update(true);
241
243
  const input = this._layerControlInputs.find((input) => input._layer === layer);
242
244
  if (input && !input.checked) {
243
245
  input.checked = true;
@@ -252,6 +254,7 @@ var LayersControl = class LayersControl extends Control {
252
254
  expand() {
253
255
  clearTimeout(this._collapseDelayTimeout);
254
256
  this._container.classList.add("maplair-control-layers-expanded");
257
+ if (this._needsUpdate) this._update();
255
258
  this._section.style.height = "";
256
259
  const acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);
257
260
  if (acceptableHeight < this._section.clientHeight) {
@@ -267,6 +270,7 @@ var LayersControl = class LayersControl extends Control {
267
270
  */
268
271
  collapse() {
269
272
  if (this.options.inline) return this;
273
+ clearTimeout(this._collapseDelayTimeout);
270
274
  if (this.options.collapseDelay > 0) this._collapseDelayTimeout = setTimeout(() => {
271
275
  this._container.classList.remove("maplair-control-layers-expanded");
272
276
  }, this.options.collapseDelay);
@@ -283,6 +287,23 @@ var LayersControl = class LayersControl extends Control {
283
287
  disableScrollPropagation(container);
284
288
  const section = this._section = create("fieldset", `${className}-list`);
285
289
  section.setAttribute("aria-label", this._getTitle());
290
+ section.tabIndex = -1;
291
+ let link;
292
+ if (!this.options.inline) {
293
+ link = this._layersLink = create("button", `${className}-toggle`, container);
294
+ link.type = "button";
295
+ link.title = this._getTitle();
296
+ link.setAttribute("aria-label", link.title);
297
+ const { toggleContent } = this.options;
298
+ if (typeof toggleContent === "string") link.innerHTML = toggleContent;
299
+ else if (toggleContent) link.replaceChildren(toggleContent);
300
+ on(link, "click", (e) => {
301
+ e.preventDefault();
302
+ const focused = document.activeElement === link;
303
+ this._expandSafely();
304
+ if (focused) section.focus();
305
+ });
306
+ }
286
307
  if (collapsed) {
287
308
  this._map.on("click", this.collapse, this);
288
309
  on(container, {
@@ -291,26 +312,15 @@ var LayersControl = class LayersControl extends Control {
291
312
  if (e.pointerType !== "touch") this.collapse();
292
313
  }
293
314
  }, this);
294
- }
295
- if (!this.options.inline) {
296
- const link = this._layersLink = create("button", `${className}-toggle`, container);
297
- link.type = "button";
298
- link.title = this._getTitle();
299
- link.setAttribute("aria-label", link.title);
300
- const { toggleContent } = this.options;
301
- if (typeof toggleContent === "string") link.innerHTML = toggleContent;
302
- else if (toggleContent) link.replaceChildren(toggleContent);
303
- on(link, {
304
- keydown(e) {
305
- if (e.code === "Enter") this._expandSafely();
306
- },
307
- click(e) {
315
+ on(section, "keydown", (e) => {
316
+ if (e.key === "Escape") {
317
+ clearTimeout(this._collapseDelayTimeout);
318
+ container.classList.remove(`${className}-expanded`);
319
+ link.focus();
308
320
  e.preventDefault();
309
- this._expandSafely();
310
321
  }
311
- }, this);
312
- }
313
- if (!collapsed) this.expand();
322
+ });
323
+ } else this.expand();
314
324
  this._baseLayersList = create("div", `${className}-base`, section);
315
325
  this._separator = create("div", `${className}-separator`, section);
316
326
  this._overlaysList = create("div", `${className}-overlays`, section);
@@ -330,8 +340,13 @@ var LayersControl = class LayersControl extends Control {
330
340
  }
331
341
  this._expandIfNotCollapsed();
332
342
  }
333
- _update() {
343
+ _update(force) {
334
344
  if (!this._container) return this;
345
+ if (!force && !this._container.classList.contains("maplair-control-layers-expanded")) {
346
+ this._needsUpdate = true;
347
+ return this;
348
+ }
349
+ this._needsUpdate = false;
335
350
  this._baseLayersList.replaceChildren();
336
351
  this._overlaysList.replaceChildren();
337
352
  this._layerControlInputs = [];
@@ -348,6 +363,7 @@ var LayersControl = class LayersControl extends Control {
348
363
  this._baseLayersList.style.display = baseLayersPresent ? "" : "none";
349
364
  }
350
365
  this._separator.style.display = overlaysPresent && baseLayersPresent ? "" : "none";
366
+ this._checkDisabledLayers();
351
367
  return this;
352
368
  }
353
369
  _onLayerChange(e) {
@@ -377,7 +393,6 @@ var LayersControl = class LayersControl extends Control {
377
393
  holder.append(input, name);
378
394
  const list = obj.overlay ? this._overlaysList : this._baseLayersList;
379
395
  (group ? this._getGroupContainer(list, group.group) : list).append(label);
380
- this._checkDisabledLayers();
381
396
  return label;
382
397
  }
383
398
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"LayersControl.js","names":["DomUtil.create","Util.stamp","DomEvent.preventDefault"],"sources":["../../../src/control/LayersControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as Util from '../core/Util.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/** @import {Layer} from '../layer/Layer.js' */\n/** @import {LayersControlEvent} from '../core/Events.js' */\n\n/**\n * An entry of `LayersControl`, as returned by `getLayers()`.\n * @typedef {object} LayersControlEntry\n * @property {Layer} layer The layer.\n * @property {string} name The name of the layer, as given to the control.\n * @property {boolean} overlay Whether the layer is an overlay (checkbox) or a base layer\n * (radio button).\n */\n\n/**\n * The group of an entry of `LayersControl`, as returned by the option `groupBy`.\n * @typedef {object} LayersControlGroup\n * @property {string} group The name of the group, rendered as text.\n * @property {string} label The label of the entry within the group, may contain HTML\n * (like layer names).\n */\n\n/**\n * Options of `LayersControl`.\n * @typedef {object} LayersControlOptions\n * @property {boolean} [collapsed=true] If `true`, the control will be collapsed into an\n * icon and expanded on pointer hover, touch, or keyboard activation. Ignored if `inline`\n * is `true`.\n * @property {boolean} [inline=false] If `true`, the control is laid out like the\n * attribution control: it is always expanded (without toggle button) and all entries are\n * placed next to each other, wrapping onto multiple lines if necessary.\n * @property {(name: string, layer: Layer, overlay: boolean) => LayersControlGroup | undefined} [groupBy]\n * A function to group the entries. For each entry, it returns the name of its group and\n * its label within the group, or `undefined` for an ungrouped entry. Consecutive entries\n * of the same group (base layers and overlays separately) are rendered within one\n * `maplair-control-layers-group` container, starting with the group name in a\n * `maplair-control-layers-group-name` element, and each entry shows only its label.\n * Events like `baselayerchange` still carry the full `name`. When combined with\n * `sortLayers`, the entries are sorted first and grouped afterwards.\n * @property {string} [title] The title of the toggle button and the accessible label\n * of the layers list, the translation of `'Layers'` by default.\n * @property {string|HTMLElement} [toggleContent] The content of the toggle button of a\n * collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an\n * element. String content is rendered as HTML; do not pass untrusted input.\n * @property {number} [collapseDelay=0] Collapse delay in milliseconds. If greater than 0,\n * the control will remain open longer, making it easier to scroll through long layer\n * lists.\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 {boolean} [autoZIndex=true] If `true`, the control will assign zIndexes in\n * increasing order to all of its layers so that the order is preserved when switching\n * them on/off.\n * @property {boolean} [hideSingleBase=false] If `true`, the base layers in the control\n * will be hidden when there is only one.\n * @property {boolean} [sortLayers=false] Whether to sort the layers. When `false`, layers\n * will keep the order in which they were added to the control.\n * @property {(layerA: Layer, layerB: Layer, nameA: string, nameB: string) => number} [sortFunction]\n * A [compare function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\n * that will be used for sorting the layers, when `sortLayers` is `true`. The function\n * receives both the `Layer` instances and their names, as in\n * `sortFunction(layerA, layerB, nameA, nameB)`. By default, it sorts layers\n * alphabetically by their name.\n * @extends ControlOptions\n */\n\n/**\n * The layers control gives users the ability to switch between different base layers\n * and switch overlays on/off (check out the\n * [detailed example](https://maplair.org/examples/layers-control/)).\n *\n * @example\n * ```js\n * const baseLayers = {\n * \t\"Mapbox\": mapbox,\n * \t\"OpenStreetMap\": osm\n * };\n *\n * const overlays = {\n * \t\"Marker\": marker,\n * \t\"Roads\": roadsLayer\n * };\n *\n * new LayersControl(baseLayers, overlays).addTo(map);\n * ```\n *\n * The `baseLayers` and `overlays` parameters are object literals with layer names as keys and `Layer` objects as values:\n *\n * ```js\n * {\n * \"<someName1>\": layer1,\n * \"<someName2>\": layer2\n * }\n * ```\n *\n * The layer names can contain HTML, which allows you to add additional styling to the items:\n *\n * ```js\n * {\"<img src='my-layer-icon' /> <span class='my-layer-item'>My Layer</span>\": myLayer}\n * ```\n *\n * Layers can be grouped using the option `groupBy`, for example layer names of the form\n * `\"Group (label)\"`:\n *\n * ```js\n * new LayersControl(baseLayers, overlays, {\n * \tinline: true,\n * \tgroupBy(name) {\n * \t\tconst [, group, label] = /^([^<>()]+) \\((.+)\\)$/.exec(name) ?? [];\n * \t\treturn group ? {group: `${group}:`, label} : undefined;\n * \t}\n * }).addTo(map);\n * ```\n *\n * @fires MaplairMap#baselayerchange {LayersControlEvent} Fired when the base layer is\n * changed through the [layers control](#control-layers).\n * @fires MaplairMap#overlayadd {LayersControlEvent} Fired when an overlay is selected\n * through the [layers control](#control-layers).\n * @fires MaplairMap#overlayremove {LayersControlEvent} Fired when an overlay is\n * deselected through the [layers control](#control-layers).\n */\nexport class LayersControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tcollapsed: true,\n\t\tinline: false,\n\t\tgroupBy: undefined,\n\t\ttitle: undefined,\n\t\ttoggleContent: undefined,\n\t\tcollapseDelay: 0,\n\t\tposition: 'topright',\n\t\tautoZIndex: true,\n\t\thideSingleBase: false,\n\t\tsortLayers: false,\n\t\tsortFunction(layerA, layerB, nameA, nameB) {\n\t\t\treturn nameA < nameB ? -1 : (nameB < nameA ? 1 : 0);\n\t\t}\n\t};\n\n\t/**\n\t * Creates a layers control with the given layers. Base layers will be switched with\n\t * radio buttons, while overlays will be switched with checkboxes. Note that all base\n\t * layers should be passed in the base layers object, but only one should be added to\n\t * the map during map instantiation.\n\t * @param {Record<string, Layer>} [baseLayers]\n\t * @param {Record<string, Layer>} [overlays]\n\t * @param {LayersControlOptions} [options]\n\t */\n\tconstructor(baseLayers, overlays, options) {\n\t\tsuper(options);\n\n\t\tthis._layerControlInputs = [];\n\t\tthis._layers = [];\n\t\tthis._lastZIndex = 0;\n\t\tthis._handlingClick = false;\n\t\tthis._preventClick = false;\n\n\t\tfor (const [name, layer] of Object.entries(baseLayers ?? {})) {\n\t\t\tthis._addLayer(layer, name);\n\t\t}\n\n\t\tfor (const [name, layer] of Object.entries(overlays ?? {})) {\n\t\t\tthis._addLayer(layer, name, true);\n\t\t}\n\n\t\tthis.callInitHooks(LayersControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tthis._initLayout();\n\t\tthis._update();\n\n\t\tthis._map = map;\n\t\tmap.on('zoomend', this._checkDisabledLayers, this);\n\n\t\tfor (const layer of this._layers) {\n\t\t\tlayer.layer.on('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tif (!this._isCollapsible()) {\n\t\t\t// update the height of the container after resizing the window\n\t\t\tmap.on('resize', this._expandIfNotCollapsed, this);\n\t\t}\n\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\tsuper.addTo(map);\n\t\t// Trigger expand after Layers Control has been inserted into DOM so that is now has an actual height.\n\t\treturn this._expandIfNotCollapsed();\n\t}\n\n\t/** @internal */\n\tonRemove() {\n\t\tthis._map.off('zoomend', this._checkDisabledLayers, this);\n\n\t\tfor (const layer of this._layers) {\n\t\t\tlayer.layer.off('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tthis._map.off('resize', this._expandIfNotCollapsed, this);\n\t\tthis._map.off('click', this.collapse, this);\n\t}\n\n\t/**\n\t * Adds a base layer (radio button entry) with the given name to the control.\n\t * @param {Layer} layer\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\taddBaseLayer(layer, name) {\n\t\tthis._addLayer(layer, name);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Adds an overlay (checkbox entry) with the given name to the control.\n\t * @param {Layer} layer\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\taddOverlay(layer, name) {\n\t\tthis._addLayer(layer, name, true);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Remove the given layer from the control.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tlayer.off('add remove', this._onLayerChange, this);\n\n\t\tthis._layers = this._layers.filter(o => o.layer !== layer);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Returns the entries of the control in the order they are displayed.\n\t * @returns {LayersControlEntry[]}\n\t */\n\tgetLayers() {\n\t\treturn this._layers.map(({layer, name, overlay}) => ({layer, name, overlay}));\n\t}\n\n\t/**\n\t * Selects the given layer of the control like a click on its entry: a base layer\n\t * replaces the current base layer, an overlay is added to the map. The events\n\t * `baselayerchange` and `overlayadd` are fired as for a click, but without\n\t * `originalEvent`. Has no effect if the control is not on a map or does not contain\n\t * the layer.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tselectLayer(layer) {\n\t\tconst input = this._layerControlInputs.find(input => input._layer === layer);\n\t\tif (input && !input.checked) {\n\t\t\tinput.checked = true;\n\t\t\tthis._onInputClick();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Expand the control container if collapsed.\n\t * @returns {this}\n\t */\n\texpand() {\n\t\tclearTimeout(this._collapseDelayTimeout);\n\n\t\tthis._container.classList.add('maplair-control-layers-expanded');\n\t\tthis._section.style.height = '';\n\t\tconst acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);\n\t\tif (acceptableHeight < this._section.clientHeight) {\n\t\t\tthis._section.classList.add('maplair-control-layers-scrollbar');\n\t\t\tthis._section.style.height = `${acceptableHeight}px`;\n\t\t} else {\n\t\t\tthis._section.classList.remove('maplair-control-layers-scrollbar');\n\t\t}\n\t\tthis._checkDisabledLayers();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Collapse the control container if expanded.\n\t * @returns {this}\n\t */\n\tcollapse() {\n\t\tif (this.options.inline) {\n\t\t\treturn this;\n\t\t}\n\t\tif (this.options.collapseDelay > 0) {\n\t\t\tthis._collapseDelayTimeout = setTimeout(() => {\n\t\t\t\tthis._container.classList.remove('maplair-control-layers-expanded');\n\t\t\t}, this.options.collapseDelay);\n\t\t} else {\n\t\t\tthis._container.classList.remove('maplair-control-layers-expanded');\n\t\t}\n\t\treturn this;\n\t}\n\n\t_getTitle() {\n\t\treturn this.options.title ?? I18n.translate('Layers');\n\t}\n\n\t_initLayout() {\n\t\tconst className = 'maplair-control-layers',\n\t\tcontainer = this._container = DomUtil.create('div', className),\n\t\tcollapsed = this._isCollapsible();\n\n\t\tif (this.options.inline) {\n\t\t\tcontainer.classList.add(`${className}-inline`);\n\t\t}\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\n\t\tconst section = this._section = DomUtil.create('fieldset', `${className}-list`);\n\t\tsection.setAttribute('aria-label', this._getTitle());\n\n\t\tif (collapsed) {\n\t\t\tthis._map.on('click', this.collapse, this);\n\n\t\t\tDomEvent.on(container, {\n\t\t\t\tpointerenter: this._expandSafely,\n\t\t\t\t// on touch devices, pointerleave fires while clicking a checkbox, which shouldn't collapse the control\n\t\t\t\tpointerleave(e) {\n\t\t\t\t\tif (e.pointerType !== 'touch') { this.collapse(); }\n\t\t\t\t}\n\t\t\t}, this);\n\t\t}\n\n\t\tif (!this.options.inline) {\n\t\t\tconst link = this._layersLink = DomUtil.create('button', `${className}-toggle`, container);\n\t\t\tlink.type = 'button';\n\t\t\tlink.title = this._getTitle();\n\t\t\tlink.setAttribute('aria-label', link.title);\n\n\t\t\tconst {toggleContent} = this.options;\n\t\t\tif (typeof toggleContent === 'string') {\n\t\t\t\tlink.innerHTML = toggleContent;\n\t\t\t} else if (toggleContent) {\n\t\t\t\tlink.replaceChildren(toggleContent);\n\t\t\t}\n\n\t\t\tDomEvent.on(link, {\n\t\t\t\tkeydown(e) {\n\t\t\t\t\tif (e.code === 'Enter') {\n\t\t\t\t\t\tthis._expandSafely();\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t\t// Certain screen readers intercept the key event and instead send a click event\n\t\t\t\tclick(e) {\n\t\t\t\t\te.preventDefault();\n\t\t\t\t\tthis._expandSafely();\n\t\t\t\t}\n\t\t\t}, this);\n\t\t}\n\n\t\tif (!collapsed) {\n\t\t\tthis.expand();\n\t\t}\n\n\t\tthis._baseLayersList = DomUtil.create('div', `${className}-base`, section);\n\t\tthis._separator = DomUtil.create('div', `${className}-separator`, section);\n\t\tthis._overlaysList = DomUtil.create('div', `${className}-overlays`, section);\n\n\t\tcontainer.append(section);\n\t}\n\n\t_addLayer(layer, name, overlay) {\n\t\tif (this._map) {\n\t\t\tlayer.on('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tthis._layers.push({\n\t\t\tlayer,\n\t\t\tname,\n\t\t\toverlay: !!overlay\n\t\t});\n\n\t\tif (this.options.sortLayers) {\n\t\t\tthis._layers.sort(((a, b) => this.options.sortFunction(a.layer, b.layer, a.name, b.name)));\n\t\t}\n\n\t\tif (this.options.autoZIndex && layer.setZIndex) {\n\t\t\tthis._lastZIndex++;\n\t\t\tlayer.setZIndex(this._lastZIndex);\n\t\t}\n\n\t\tthis._expandIfNotCollapsed();\n\t}\n\n\t_update() {\n\t\tif (!this._container) { return this; }\n\n\t\tthis._baseLayersList.replaceChildren();\n\t\tthis._overlaysList.replaceChildren();\n\n\t\tthis._layerControlInputs = [];\n\t\tthis._groupCount = 0;\n\t\tlet baseLayersPresent, overlaysPresent, baseLayersCount = 0;\n\n\t\tfor (const obj of this._layers) {\n\t\t\tthis._addItem(obj);\n\t\t\toverlaysPresent ||= obj.overlay;\n\t\t\tbaseLayersPresent ||= !obj.overlay;\n\t\t\tbaseLayersCount += !obj.overlay ? 1 : 0;\n\t\t}\n\n\t\t// Hide base layers section if there's only one layer.\n\t\tif (this.options.hideSingleBase) {\n\t\t\tbaseLayersPresent = baseLayersPresent && baseLayersCount > 1;\n\t\t\tthis._baseLayersList.style.display = baseLayersPresent ? '' : 'none';\n\t\t}\n\n\t\tthis._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';\n\n\t\treturn this;\n\t}\n\n\t_onLayerChange(e) {\n\t\tif (!this._handlingClick) {\n\t\t\tthis._update();\n\t\t}\n\n\t\tconst obj = this._layers.find(o => o.layer === e.target);\n\n\t\tconst type = obj.overlay ?\n\t\t\t(e.type === 'add' ? 'overlayadd' : 'overlayremove') :\n\t\t\t(e.type === 'add' ? 'baselayerchange' : null);\n\n\t\tif (type) {\n\t\t\tthis._map.fire(type, this._clickEvent ? {...obj, originalEvent: this._clickEvent} : obj);\n\t\t}\n\t}\n\n\t_addItem(obj) {\n\t\tconst label = document.createElement('label'),\n\t\tchecked = this._map.hasLayer(obj.layer);\n\n\t\tconst input = document.createElement('input');\n\t\tinput.type = obj.overlay ? 'checkbox' : 'radio';\n\t\tinput.className = 'maplair-control-layers-selector';\n\t\tinput.defaultChecked = checked;\n\t\tif (!obj.overlay) {\n\t\t\tinput.name = `maplair-base-layers_${Util.stamp(this)}`;\n\t\t}\n\n\t\tthis._layerControlInputs.push(input);\n\t\tinput._layer = obj.layer;\n\n\t\tDomEvent.on(input, 'click', this._onInputClick, this);\n\n\t\tconst group = this.options.groupBy?.(obj.name, obj.layer, obj.overlay);\n\n\t\tconst name = document.createElement('span');\n\t\tname.innerHTML = ` ${group ? group.label : obj.name}`;\n\n\t\t// Helps from preventing layer control flicker when checkboxes are disabled\n\t\t// https://github.com/Leaflet/Leaflet/issues/2771\n\t\tconst holder = document.createElement('span');\n\n\t\tlabel.append(holder);\n\t\tholder.append(input, name);\n\n\t\tconst list = obj.overlay ? this._overlaysList : this._baseLayersList;\n\t\tconst container = group ? this._getGroupContainer(list, group.group) : list;\n\t\tcontainer.append(label);\n\n\t\tthis._checkDisabledLayers();\n\t\treturn label;\n\t}\n\n\t/**\n\t * Returns the container of the given group if it is the last element in `list`\n\t * (continuing the group), otherwise appends a new group container to `list`.\n\t * @param {HTMLElement} list\n\t * @param {string} group\n\t * @returns {HTMLElement}\n\t */\n\t_getGroupContainer(list, group) {\n\t\tconst last = list.lastElementChild;\n\t\tif (last?._maplairGroup === group) {\n\t\t\treturn last;\n\t\t}\n\n\t\tconst className = 'maplair-control-layers-group',\n\t\tcontainer = DomUtil.create('div', className, list),\n\t\tname = DomUtil.create('span', `${className}-name`, container);\n\t\tname.id = `${className}_${Util.stamp(this)}_${++this._groupCount}`;\n\t\tname.textContent = group;\n\t\tcontainer.setAttribute('role', 'group');\n\t\tcontainer.setAttribute('aria-labelledby', name.id);\n\t\tcontainer._maplairGroup = group;\n\t\treturn container;\n\t}\n\n\t_onInputClick(e) {\n\t\t// expanding the control on mobile with a click can cause adding a layer - we don't want this\n\t\tif (this._preventClick) {\n\t\t\treturn;\n\t\t}\n\n\t\t// a layer can be listed under several inputs, so it should be on the map if any of them is checked\n\t\tconst checked = new Map();\n\t\tfor (const input of this._layerControlInputs) {\n\t\t\tconst layer = input._layer;\n\t\t\tchecked.set(layer, checked.get(layer) || input.checked);\n\t\t}\n\n\t\t// diff against the map upfront, so layers that event handlers add or remove below keep their state\n\t\tconst addedLayers = [], removedLayers = [];\n\t\tfor (const [layer, on] of checked) {\n\t\t\tif (on !== this._map.hasLayer(layer)) {\n\t\t\t\t(on ? addedLayers : removedLayers).push(layer);\n\t\t\t}\n\t\t}\n\n\t\tthis._handlingClick = true;\n\t\tthis._clickEvent = e;\n\n\t\t// Bugfix issue 2318: Should remove all old layers before readding new ones\n\t\tfor (const layer of removedLayers) {\n\t\t\tthis._map.removeLayer(layer);\n\t\t}\n\t\tfor (const layer of addedLayers) {\n\t\t\tthis._map.addLayer(layer);\n\t\t}\n\n\t\tthis._handlingClick = false;\n\t\tthis._clickEvent = undefined;\n\n\t\tfor (const [layer, on] of checked) {\n\t\t\tif (on !== this._map.hasLayer(layer)) {\n\t\t\t\tthis._update();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t_checkDisabledLayers() {\n\t\tconst inputs = this._layerControlInputs,\n\t\tzoom = this._map.getZoom();\n\n\t\tfor (const input of inputs) {\n\t\t\tconst layer = input._layer;\n\t\t\tinput.disabled = (layer.options.minZoom !== undefined && zoom < layer.options.minZoom) ||\n\t\t\t (layer.options.maxZoom !== undefined && zoom > layer.options.maxZoom);\n\n\t\t}\n\t}\n\n\t_isCollapsible() {\n\t\treturn this.options.collapsed && !this.options.inline;\n\t}\n\n\t_expandIfNotCollapsed() {\n\t\tif (this._map && !this._isCollapsible()) {\n\t\t\tthis.expand();\n\t\t}\n\t\treturn this;\n\t}\n\n\t_expandSafely() {\n\t\tconst section = this._section;\n\t\tthis._preventClick = true;\n\t\tDomEvent.on(section, 'click', DomEvent.preventDefault);\n\t\tthis.expand();\n\t\tsetTimeout(() => {\n\t\t\tDomEvent.off(section, 'click', DomEvent.preventDefault);\n\t\t\tthis._preventClick = false;\n\t\t});\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+HA,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB;EACvB,WAAW;EACX,QAAQ;EACR,SAAS,KAAA;EACT,OAAO,KAAA;EACP,eAAe,KAAA;EACf,eAAe;EACf,UAAU;EACV,YAAY;EACZ,gBAAgB;EAChB,YAAY;EACZ,aAAa,QAAQ,QAAQ,OAAO,OAAO;GAC1C,OAAO,QAAQ,QAAQ,KAAM,QAAQ,QAAQ,IAAI;EAClD;CACD;;;;;;;;;;CAWA,YAAY,YAAY,UAAU,SAAS;EAC1C,MAAM,OAAO;EAE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uB;GACtD,KAAK,gBAAgB;EACtB,CAAC;CACF;AAED"}
1
+ {"version":3,"file":"LayersControl.js","names":["DomUtil.create","Util.stamp","DomEvent.preventDefault"],"sources":["../../../src/control/LayersControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as Util from '../core/Util.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/** @import {Layer} from '../layer/Layer.js' */\n/** @import {LayersControlEvent} from '../core/Events.js' */\n\n/**\n * An entry of `LayersControl`, as returned by `getLayers()`.\n * @typedef {object} LayersControlEntry\n * @property {Layer} layer The layer.\n * @property {string} name The name of the layer, as given to the control.\n * @property {boolean} overlay Whether the layer is an overlay (checkbox) or a base layer\n * (radio button).\n */\n\n/**\n * The group of an entry of `LayersControl`, as returned by the option `groupBy`.\n * @typedef {object} LayersControlGroup\n * @property {string} group The name of the group, rendered as text.\n * @property {string} label The label of the entry within the group, may contain HTML\n * (like layer names).\n */\n\n/**\n * Options of `LayersControl`.\n * @typedef {object} LayersControlOptions\n * @property {boolean} [collapsed=true] If `true`, the control will be collapsed into an\n * icon and expanded on pointer hover, touch, or keyboard activation. Ignored if `inline`\n * is `true`.\n * @property {boolean} [inline=false] If `true`, the control is laid out like the\n * attribution control: it is always expanded (without toggle button) and all entries are\n * placed next to each other, wrapping onto multiple lines if necessary.\n * @property {(name: string, layer: Layer, overlay: boolean) => LayersControlGroup | undefined} [groupBy]\n * A function to group the entries. For each entry, it returns the name of its group and\n * its label within the group, or `undefined` for an ungrouped entry. Consecutive entries\n * of the same group (base layers and overlays separately) are rendered within one\n * `maplair-control-layers-group` container, starting with the group name in a\n * `maplair-control-layers-group-name` element, and each entry shows only its label.\n * Events like `baselayerchange` still carry the full `name`. When combined with\n * `sortLayers`, the entries are sorted first and grouped afterwards.\n * @property {string} [title] The title of the toggle button and the accessible label\n * of the layers list, the translation of `'Layers'` by default.\n * @property {string|HTMLElement} [toggleContent] The content of the toggle button of a\n * collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an\n * element. String content is rendered as HTML; do not pass untrusted input.\n * @property {number} [collapseDelay=0] Collapse delay in milliseconds. If greater than 0,\n * the control will remain open longer, making it easier to scroll through long layer\n * lists.\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 {boolean} [autoZIndex=true] If `true`, the control will assign zIndexes in\n * increasing order to all of its layers so that the order is preserved when switching\n * them on/off.\n * @property {boolean} [hideSingleBase=false] If `true`, the base layers in the control\n * will be hidden when there is only one.\n * @property {boolean} [sortLayers=false] Whether to sort the layers. When `false`, layers\n * will keep the order in which they were added to the control.\n * @property {(layerA: Layer, layerB: Layer, nameA: string, nameB: string) => number} [sortFunction]\n * A [compare function](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/sort)\n * that will be used for sorting the layers, when `sortLayers` is `true`. The function\n * receives both the `Layer` instances and their names, as in\n * `sortFunction(layerA, layerB, nameA, nameB)`. By default, it sorts layers\n * alphabetically by their name.\n * @extends ControlOptions\n */\n\n/**\n * The layers control gives users the ability to switch between different base layers\n * and switch overlays on/off (check out the\n * [detailed example](https://maplair.org/examples/layers-control/)).\n *\n * @example\n * ```js\n * const baseLayers = {\n * \t\"Mapbox\": mapbox,\n * \t\"OpenStreetMap\": osm\n * };\n *\n * const overlays = {\n * \t\"Marker\": marker,\n * \t\"Roads\": roadsLayer\n * };\n *\n * new LayersControl(baseLayers, overlays).addTo(map);\n * ```\n *\n * The `baseLayers` and `overlays` parameters are object literals with layer names as keys and `Layer` objects as values:\n *\n * ```js\n * {\n * \"<someName1>\": layer1,\n * \"<someName2>\": layer2\n * }\n * ```\n *\n * The layer names can contain HTML, which allows you to add additional styling to the items:\n *\n * ```js\n * {\"<img src='my-layer-icon' /> <span class='my-layer-item'>My Layer</span>\": myLayer}\n * ```\n *\n * Layers can be grouped using the option `groupBy`, for example layer names of the form\n * `\"Group (label)\"`:\n *\n * ```js\n * new LayersControl(baseLayers, overlays, {\n * \tinline: true,\n * \tgroupBy(name) {\n * \t\tconst [, group, label] = /^([^<>()]+) \\((.+)\\)$/.exec(name) ?? [];\n * \t\treturn group ? {group: `${group}:`, label} : undefined;\n * \t}\n * }).addTo(map);\n * ```\n *\n * @fires MaplairMap#baselayerchange {LayersControlEvent} Fired when the base layer is\n * changed through the [layers control](#control-layers).\n * @fires MaplairMap#overlayadd {LayersControlEvent} Fired when an overlay is selected\n * through the [layers control](#control-layers).\n * @fires MaplairMap#overlayremove {LayersControlEvent} Fired when an overlay is\n * deselected through the [layers control](#control-layers).\n */\nexport class LayersControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tcollapsed: true,\n\t\tinline: false,\n\t\tgroupBy: undefined,\n\t\ttitle: undefined,\n\t\ttoggleContent: undefined,\n\t\tcollapseDelay: 0,\n\t\tposition: 'topright',\n\t\tautoZIndex: true,\n\t\thideSingleBase: false,\n\t\tsortLayers: false,\n\t\tsortFunction(layerA, layerB, nameA, nameB) {\n\t\t\treturn nameA < nameB ? -1 : (nameB < nameA ? 1 : 0);\n\t\t}\n\t};\n\n\t/**\n\t * Creates a layers control with the given layers. Base layers will be switched with\n\t * radio buttons, while overlays will be switched with checkboxes. Note that all base\n\t * layers should be passed in the base layers object, but only one should be added to\n\t * the map during map instantiation.\n\t * @param {Record<string, Layer>} [baseLayers]\n\t * @param {Record<string, Layer>} [overlays]\n\t * @param {LayersControlOptions} [options]\n\t */\n\tconstructor(baseLayers, overlays, options) {\n\t\tsuper(options);\n\n\t\tthis._layerControlInputs = [];\n\t\tthis._layers = [];\n\t\tthis._lastZIndex = 0;\n\t\tthis._handlingClick = false;\n\t\tthis._preventClick = false;\n\t\tthis._needsUpdate = false;\n\n\t\tfor (const [name, layer] of Object.entries(baseLayers ?? {})) {\n\t\t\tthis._addLayer(layer, name);\n\t\t}\n\n\t\tfor (const [name, layer] of Object.entries(overlays ?? {})) {\n\t\t\tthis._addLayer(layer, name, true);\n\t\t}\n\n\t\tthis.callInitHooks(LayersControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tthis._initLayout();\n\t\tthis._update();\n\n\t\tthis._map = map;\n\t\tmap.on('zoomend', this._checkDisabledLayers, this);\n\n\t\tfor (const layer of this._layers) {\n\t\t\tlayer.layer.on('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tif (!this._isCollapsible()) {\n\t\t\t// update the height of the container after resizing the window\n\t\t\tmap.on('resize', this._expandIfNotCollapsed, this);\n\t\t}\n\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\tsuper.addTo(map);\n\t\t// Trigger expand after Layers Control has been inserted into DOM so that is now has an actual height.\n\t\treturn this._expandIfNotCollapsed();\n\t}\n\n\t/** @internal */\n\tonRemove() {\n\t\tthis._map.off('zoomend', this._checkDisabledLayers, this);\n\n\t\tfor (const layer of this._layers) {\n\t\t\tlayer.layer.off('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tthis._map.off('resize', this._expandIfNotCollapsed, this);\n\t\tthis._map.off('click', this.collapse, this);\n\t}\n\n\t/**\n\t * Adds a base layer (radio button entry) with the given name to the control.\n\t * @param {Layer} layer\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\taddBaseLayer(layer, name) {\n\t\tthis._addLayer(layer, name);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Adds an overlay (checkbox entry) with the given name to the control.\n\t * @param {Layer} layer\n\t * @param {string} name\n\t * @returns {this}\n\t */\n\taddOverlay(layer, name) {\n\t\tthis._addLayer(layer, name, true);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Remove the given layer from the control.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tremoveLayer(layer) {\n\t\tlayer.off('add remove', this._onLayerChange, this);\n\n\t\tthis._layers = this._layers.filter(o => o.layer !== layer);\n\t\treturn (this._map) ? this._update() : this;\n\t}\n\n\t/**\n\t * Returns the entries of the control in the order they are displayed.\n\t * @returns {LayersControlEntry[]}\n\t */\n\tgetLayers() {\n\t\treturn this._layers.map(({layer, name, overlay}) => ({layer, name, overlay}));\n\t}\n\n\t/**\n\t * Selects the given layer of the control like a click on its entry: a base layer\n\t * replaces the current base layer, an overlay is added to the map. The events\n\t * `baselayerchange` and `overlayadd` are fired as for a click, but without\n\t * `originalEvent`. Has no effect if the control is not on a map or does not contain\n\t * the layer.\n\t * @param {Layer} layer\n\t * @returns {this}\n\t */\n\tselectLayer(layer) {\n\t\t// the list isn't rebuilt while collapsed\n\t\tif (this._needsUpdate) { this._update(true); }\n\t\tconst input = this._layerControlInputs.find(input => input._layer === layer);\n\t\tif (input && !input.checked) {\n\t\t\tinput.checked = true;\n\t\t\tthis._onInputClick();\n\t\t}\n\t\treturn this;\n\t}\n\n\t/**\n\t * Expand the control container if collapsed.\n\t * @returns {this}\n\t */\n\texpand() {\n\t\tclearTimeout(this._collapseDelayTimeout);\n\n\t\tthis._container.classList.add('maplair-control-layers-expanded');\n\t\tif (this._needsUpdate) { this._update(); }\n\t\tthis._section.style.height = '';\n\t\tconst acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);\n\t\tif (acceptableHeight < this._section.clientHeight) {\n\t\t\tthis._section.classList.add('maplair-control-layers-scrollbar');\n\t\t\tthis._section.style.height = `${acceptableHeight}px`;\n\t\t} else {\n\t\t\tthis._section.classList.remove('maplair-control-layers-scrollbar');\n\t\t}\n\t\tthis._checkDisabledLayers();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Collapse the control container if expanded.\n\t * @returns {this}\n\t */\n\tcollapse() {\n\t\tif (this.options.inline) {\n\t\t\treturn this;\n\t\t}\n\t\tclearTimeout(this._collapseDelayTimeout);\n\t\tif (this.options.collapseDelay > 0) {\n\t\t\tthis._collapseDelayTimeout = setTimeout(() => {\n\t\t\t\tthis._container.classList.remove('maplair-control-layers-expanded');\n\t\t\t}, this.options.collapseDelay);\n\t\t} else {\n\t\t\tthis._container.classList.remove('maplair-control-layers-expanded');\n\t\t}\n\t\treturn this;\n\t}\n\n\t_getTitle() {\n\t\treturn this.options.title ?? I18n.translate('Layers');\n\t}\n\n\t_initLayout() {\n\t\tconst className = 'maplair-control-layers',\n\t\tcontainer = this._container = DomUtil.create('div', className),\n\t\tcollapsed = this._isCollapsible();\n\n\t\tif (this.options.inline) {\n\t\t\tcontainer.classList.add(`${className}-inline`);\n\t\t}\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\n\t\tconst section = this._section = DomUtil.create('fieldset', `${className}-list`);\n\t\tsection.setAttribute('aria-label', this._getTitle());\n\t\tsection.tabIndex = -1;\n\n\t\tlet link;\n\t\tif (!this.options.inline) {\n\t\t\tlink = this._layersLink = DomUtil.create('button', `${className}-toggle`, container);\n\t\t\tlink.type = 'button';\n\t\t\tlink.title = this._getTitle();\n\t\t\tlink.setAttribute('aria-label', link.title);\n\n\t\t\tconst {toggleContent} = this.options;\n\t\t\tif (typeof toggleContent === 'string') {\n\t\t\t\tlink.innerHTML = toggleContent;\n\t\t\t} else if (toggleContent) {\n\t\t\t\tlink.replaceChildren(toggleContent);\n\t\t\t}\n\n\t\t\t// also for Enter and Space, and for screen readers that send a click instead of the key event\n\t\t\tDomEvent.on(link, 'click', (e) => {\n\t\t\t\te.preventDefault();\n\t\t\t\tconst focused = document.activeElement === link;\n\t\t\t\tthis._expandSafely();\n\t\t\t\tif (focused) { section.focus(); }\n\t\t\t});\n\t\t}\n\n\t\tif (collapsed) {\n\t\t\tthis._map.on('click', this.collapse, this);\n\n\t\t\tDomEvent.on(container, {\n\t\t\t\tpointerenter: this._expandSafely,\n\t\t\t\t// on touch devices, pointerleave fires while clicking a checkbox, which shouldn't collapse the control\n\t\t\t\tpointerleave(e) {\n\t\t\t\t\tif (e.pointerType !== 'touch') { this.collapse(); }\n\t\t\t\t}\n\t\t\t}, this);\n\n\t\t\t// the list only takes focus while expanded; skip `collapseDelay`, as the toggle is hidden until then\n\t\t\tDomEvent.on(section, 'keydown', (e) => {\n\t\t\t\tif (e.key === 'Escape') {\n\t\t\t\t\tclearTimeout(this._collapseDelayTimeout);\n\t\t\t\t\tcontainer.classList.remove(`${className}-expanded`);\n\t\t\t\t\tlink.focus();\n\t\t\t\t\te.preventDefault();\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tthis.expand();\n\t\t}\n\n\t\tthis._baseLayersList = DomUtil.create('div', `${className}-base`, section);\n\t\tthis._separator = DomUtil.create('div', `${className}-separator`, section);\n\t\tthis._overlaysList = DomUtil.create('div', `${className}-overlays`, section);\n\n\t\tcontainer.append(section);\n\t}\n\n\t_addLayer(layer, name, overlay) {\n\t\tif (this._map) {\n\t\t\tlayer.on('add remove', this._onLayerChange, this);\n\t\t}\n\n\t\tthis._layers.push({\n\t\t\tlayer,\n\t\t\tname,\n\t\t\toverlay: !!overlay\n\t\t});\n\n\t\tif (this.options.sortLayers) {\n\t\t\tthis._layers.sort(((a, b) => this.options.sortFunction(a.layer, b.layer, a.name, b.name)));\n\t\t}\n\n\t\tif (this.options.autoZIndex && layer.setZIndex) {\n\t\t\tthis._lastZIndex++;\n\t\t\tlayer.setZIndex(this._lastZIndex);\n\t\t}\n\n\t\tthis._expandIfNotCollapsed();\n\t}\n\n\t_update(force) {\n\t\tif (!this._container) { return this; }\n\n\t\t// Rebuilding on every layer change makes adding n layers O(n²). The list is hidden\n\t\t// while collapsed, so leave it until `expand()` shows it.\n\t\tif (!force && !this._container.classList.contains('maplair-control-layers-expanded')) {\n\t\t\tthis._needsUpdate = true;\n\t\t\treturn this;\n\t\t}\n\t\tthis._needsUpdate = false;\n\n\t\tthis._baseLayersList.replaceChildren();\n\t\tthis._overlaysList.replaceChildren();\n\n\t\tthis._layerControlInputs = [];\n\t\tthis._groupCount = 0;\n\t\tlet baseLayersPresent, overlaysPresent, baseLayersCount = 0;\n\n\t\tfor (const obj of this._layers) {\n\t\t\tthis._addItem(obj);\n\t\t\toverlaysPresent ||= obj.overlay;\n\t\t\tbaseLayersPresent ||= !obj.overlay;\n\t\t\tbaseLayersCount += !obj.overlay ? 1 : 0;\n\t\t}\n\n\t\t// Hide base layers section if there's only one layer.\n\t\tif (this.options.hideSingleBase) {\n\t\t\tbaseLayersPresent = baseLayersPresent && baseLayersCount > 1;\n\t\t\tthis._baseLayersList.style.display = baseLayersPresent ? '' : 'none';\n\t\t}\n\n\t\tthis._separator.style.display = overlaysPresent && baseLayersPresent ? '' : 'none';\n\n\t\t// once for the whole list, as it loops over every input\n\t\tthis._checkDisabledLayers();\n\n\t\treturn this;\n\t}\n\n\t_onLayerChange(e) {\n\t\tif (!this._handlingClick) {\n\t\t\tthis._update();\n\t\t}\n\n\t\tconst obj = this._layers.find(o => o.layer === e.target);\n\n\t\tconst type = obj.overlay ?\n\t\t\t(e.type === 'add' ? 'overlayadd' : 'overlayremove') :\n\t\t\t(e.type === 'add' ? 'baselayerchange' : null);\n\n\t\tif (type) {\n\t\t\tthis._map.fire(type, this._clickEvent ? {...obj, originalEvent: this._clickEvent} : obj);\n\t\t}\n\t}\n\n\t_addItem(obj) {\n\t\tconst label = document.createElement('label'),\n\t\tchecked = this._map.hasLayer(obj.layer);\n\n\t\tconst input = document.createElement('input');\n\t\tinput.type = obj.overlay ? 'checkbox' : 'radio';\n\t\tinput.className = 'maplair-control-layers-selector';\n\t\tinput.defaultChecked = checked;\n\t\tif (!obj.overlay) {\n\t\t\tinput.name = `maplair-base-layers_${Util.stamp(this)}`;\n\t\t}\n\n\t\tthis._layerControlInputs.push(input);\n\t\tinput._layer = obj.layer;\n\n\t\tDomEvent.on(input, 'click', this._onInputClick, this);\n\n\t\tconst group = this.options.groupBy?.(obj.name, obj.layer, obj.overlay);\n\n\t\tconst name = document.createElement('span');\n\t\tname.innerHTML = ` ${group ? group.label : obj.name}`;\n\n\t\t// Helps from preventing layer control flicker when checkboxes are disabled\n\t\t// https://github.com/Leaflet/Leaflet/issues/2771\n\t\tconst holder = document.createElement('span');\n\n\t\tlabel.append(holder);\n\t\tholder.append(input, name);\n\n\t\tconst list = obj.overlay ? this._overlaysList : this._baseLayersList;\n\t\tconst container = group ? this._getGroupContainer(list, group.group) : list;\n\t\tcontainer.append(label);\n\n\t\treturn label;\n\t}\n\n\t/**\n\t * Returns the container of the given group if it is the last element in `list`\n\t * (continuing the group), otherwise appends a new group container to `list`.\n\t * @param {HTMLElement} list\n\t * @param {string} group\n\t * @returns {HTMLElement}\n\t */\n\t_getGroupContainer(list, group) {\n\t\tconst last = list.lastElementChild;\n\t\tif (last?._maplairGroup === group) {\n\t\t\treturn last;\n\t\t}\n\n\t\tconst className = 'maplair-control-layers-group',\n\t\tcontainer = DomUtil.create('div', className, list),\n\t\tname = DomUtil.create('span', `${className}-name`, container);\n\t\tname.id = `${className}_${Util.stamp(this)}_${++this._groupCount}`;\n\t\tname.textContent = group;\n\t\tcontainer.setAttribute('role', 'group');\n\t\tcontainer.setAttribute('aria-labelledby', name.id);\n\t\tcontainer._maplairGroup = group;\n\t\treturn container;\n\t}\n\n\t_onInputClick(e) {\n\t\t// expanding the control on mobile with a click can cause adding a layer - we don't want this\n\t\tif (this._preventClick) {\n\t\t\treturn;\n\t\t}\n\n\t\t// a layer can be listed under several inputs, so it should be on the map if any of them is checked\n\t\tconst checked = new Map();\n\t\tfor (const input of this._layerControlInputs) {\n\t\t\tconst layer = input._layer;\n\t\t\tchecked.set(layer, checked.get(layer) || input.checked);\n\t\t}\n\n\t\t// diff against the map upfront, so layers that event handlers add or remove below keep their state\n\t\tconst addedLayers = [], removedLayers = [];\n\t\tfor (const [layer, on] of checked) {\n\t\t\tif (on !== this._map.hasLayer(layer)) {\n\t\t\t\t(on ? addedLayers : removedLayers).push(layer);\n\t\t\t}\n\t\t}\n\n\t\tthis._handlingClick = true;\n\t\tthis._clickEvent = e;\n\n\t\t// Bugfix issue 2318: Should remove all old layers before readding new ones\n\t\tfor (const layer of removedLayers) {\n\t\t\tthis._map.removeLayer(layer);\n\t\t}\n\t\tfor (const layer of addedLayers) {\n\t\t\tthis._map.addLayer(layer);\n\t\t}\n\n\t\tthis._handlingClick = false;\n\t\tthis._clickEvent = undefined;\n\n\t\tfor (const [layer, on] of checked) {\n\t\t\tif (on !== this._map.hasLayer(layer)) {\n\t\t\t\tthis._update();\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t}\n\n\t_checkDisabledLayers() {\n\t\tconst inputs = this._layerControlInputs,\n\t\tzoom = this._map.getZoom();\n\n\t\tfor (const input of inputs) {\n\t\t\tconst layer = input._layer;\n\t\t\tinput.disabled = (layer.options.minZoom !== undefined && zoom < layer.options.minZoom) ||\n\t\t\t (layer.options.maxZoom !== undefined && zoom > layer.options.maxZoom);\n\n\t\t}\n\t}\n\n\t_isCollapsible() {\n\t\treturn this.options.collapsed && !this.options.inline;\n\t}\n\n\t_expandIfNotCollapsed() {\n\t\tif (this._map && !this._isCollapsible()) {\n\t\t\tthis.expand();\n\t\t}\n\t\treturn this;\n\t}\n\n\t_expandSafely() {\n\t\tconst section = this._section;\n\t\tthis._preventClick = true;\n\t\tDomEvent.on(section, 'click', DomEvent.preventDefault);\n\t\tthis.expand();\n\t\tsetTimeout(() => {\n\t\t\tDomEvent.off(section, 'click', DomEvent.preventDefault);\n\t\t\tthis._preventClick = false;\n\t\t});\n\t}\n\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA+HA,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB;EACvB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;EACtB,KAAK,cAAc,KAAA;EAEnB,KAAK,MAAM,CAAC,OAAO,OAAO,SACzB,IAAI,OAAO,KAAK,KAAK,SAAS,KAAK,GAAG;GACrC,KAAK,QAAQ;GACb;EACD;CAEF;CAEA,uBAAuB;EACtB,MAAM,SAAS,KAAK,qBACpB,OAAO,KAAK,KAAK,QAAQ;EAEzB,KAAK,MAAM,SAAS,QAAQ;GAC3B,MAAM,QAAQ,MAAM;GACpB,MAAM,WAAY,MAAM,QAAQ,YAAY,KAAA,KAAa,OAAO,MAAM,QAAQ,WAC5D,MAAM,QAAQ,YAAY,KAAA,KAAa,OAAO,MAAM,QAAQ;EAE/E;CACD;CAEA,iBAAiB;EAChB,OAAO,KAAK,QAAQ,aAAa,CAAC,KAAK,QAAQ;CAChD;CAEA,wBAAwB;EACvB,IAAI,KAAK,QAAQ,CAAC,KAAK,eAAe,GACrC,KAAK,OAAO;EAEb,OAAO;CACR;CAEA,gBAAgB;EACf,MAAM,UAAU,KAAK;EACrB,KAAK,gBAAgB;EACrB,GAAY,SAAS,SAASC,cAAuB;EACrD,KAAK,OAAO;EACZ,iBAAiB;GAChB,IAAa,SAAS,SAASA,cAAuB;GACtD,KAAK,gBAAgB;EACtB,CAAC;CACF;AAED"}
@@ -97,10 +97,10 @@ var ScaleControl = class ScaleControl extends Control {
97
97
  scale.textContent = text;
98
98
  }
99
99
  _getRoundNum(num) {
100
- const pow10 = 10 ** (`${Math.floor(num)}`.length - 1);
101
- let d = num / pow10;
100
+ const exponent = num < 1 ? Math.floor(Math.log10(num)) : `${Math.floor(num)}`.length - 1;
101
+ let d = num / 10 ** exponent;
102
102
  d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
103
- return pow10 * d;
103
+ return exponent < 0 ? d / 10 ** -exponent : d * 10 ** exponent;
104
104
  }
105
105
  };
106
106
  export { ScaleControl };
@@ -1 +1 @@
1
- {"version":3,"file":"ScaleControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ScaleControl.js"],"sourcesContent":["\nimport {Control} from './Control.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\n/**\n * Options of `ScaleControl`.\n * @typedef {object} ScaleControlOptions\n * @property {string} [position='bottomleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [maxWidth=100] Maximum width of the control in pixels. The width is\n * set dynamically to show round values (e.g. 100, 200, 500).\n * @property {boolean} [metric=true] Whether to show the metric scale line (m/km).\n * @property {boolean} [imperial=true] Whether to show the imperial scale line (mi/ft).\n * @property {boolean} [updateWhenIdle=false] If `true`, the control is updated on\n * [`moveend`](#map-moveend), otherwise it's always up-to-date (updated on\n * [`move`](#map-move)).\n * @extends ControlOptions\n */\n\n/**\n * A simple scale control that shows the scale of the current center of screen in metric\n * (m/km) and imperial (mi/ft) systems.\n *\n * @example\n *\n * ```js\n * new ScaleControl().addTo(map);\n * ```\n */\nexport class ScaleControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomleft',\n\t\tmaxWidth: 100,\n\t\tmetric: true,\n\t\timperial: true,\n\t\tupdateWhenIdle: false\n\t};\n\n\t/**\n\t * Creates a scale control with the given options.\n\t * @param {...ScaleControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ScaleControl);\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 className = 'maplair-control-scale',\n\t\tcontainer = DomUtil.create('div', className),\n\t\toptions = this.options;\n\n\t\tthis._addScales(options, `${className}-line`, container);\n\n\t\tmap.whenReady(this._update, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\treturn {[this.options.updateWhenIdle ? 'moveend' : 'move']: this._update};\n\t}\n\n\t_addScales(options, className, container) {\n\t\tif (options.metric) {\n\t\t\tthis._mScale = DomUtil.create('div', className, container);\n\t\t}\n\t\tif (options.imperial) {\n\t\t\tthis._iScale = DomUtil.create('div', className, container);\n\t\t}\n\t}\n\n\t_update() {\n\t\tconst map = this._map,\n\t\ty = map.getSize().y / 2;\n\n\t\tconst maxMeters = map.distance(\n\t\t\tmap.containerPointToLatLng([0, y]),\n\t\t\tmap.containerPointToLatLng([this.options.maxWidth, y]));\n\n\t\tthis._updateScales(maxMeters);\n\t}\n\n\t_updateScales(maxMeters) {\n\t\tif (this.options.metric && maxMeters) {\n\t\t\tthis._updateMetric(maxMeters);\n\t\t}\n\t\tif (this.options.imperial && maxMeters) {\n\t\t\tthis._updateImperial(maxMeters);\n\t\t}\n\t}\n\n\t_updateMetric(maxMeters) {\n\t\tconst meters = this._getRoundNum(maxMeters),\n\t\tlabel = meters < 1000 ?\n\t\t\tI18n.translate('{meters} m', {meters}) :\n\t\t\tI18n.translate('{kilometers} km', {kilometers: meters / 1000});\n\n\t\tthis._updateScale(this._mScale, label, meters / maxMeters);\n\t}\n\n\t_updateImperial(maxMeters) {\n\t\tconst maxFeet = maxMeters * 3.2808399;\n\t\tlet maxMiles, miles, feet;\n\n\t\tif (maxFeet > 5280) {\n\t\t\tmaxMiles = maxFeet / 5280;\n\t\t\tmiles = this._getRoundNum(maxMiles);\n\t\t\tthis._updateScale(this._iScale, I18n.translate('{miles} mi', {miles}), miles / maxMiles);\n\n\t\t} else {\n\t\t\tfeet = this._getRoundNum(maxFeet);\n\t\t\tthis._updateScale(this._iScale, I18n.translate('{feet} ft', {feet}), feet / maxFeet);\n\t\t}\n\t}\n\n\t_updateScale(scale, text, ratio) {\n\t\tscale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;\n\t\tscale.textContent = text;\n\t}\n\n\t_getRoundNum(num) {\n\t\tconst pow10 = 10 ** ((`${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gBAAgB,SAAS;CAEhC;CAEA,cAAc,WAAW;EACxB,MAAM,SAAS,KAAK,aAAa,SAAS,GAC1C,QAAQ,SAAS,MAChB,KAAK,UAAU,cAAc,EAAC,OAAM,CAAC,IACrC,KAAK,UAAU,mBAAmB,EAAC,YAAY,SAAS,IAAI,CAAC;EAE9D,KAAK,aAAa,KAAK,SAAS,OAAO,SAAS,SAAS;CAC1D;CAEA,gBAAgB,WAAW;EAC1B,MAAM,UAAU,YAAY;EAC5B,IAAI,UAAU,OAAO;EAErB,IAAI,UAAU,MAAM;GACnB,WAAW,UAAU;GACrB,QAAQ,KAAK,aAAa,QAAQ;GAClC,KAAK,aAAa,KAAK,SAAS,KAAK,UAAU,cAAc,EAAC,MAAK,CAAC,GAAG,QAAQ,QAAQ;EAExF,OAAO;GACN,OAAO,KAAK,aAAa,OAAO;GAChC,KAAK,aAAa,KAAK,SAAS,KAAK,UAAU,aAAa,EAAC,KAAI,CAAC,GAAG,OAAO,OAAO;EACpF;CACD;CAEA,aAAa,OAAO,MAAM,OAAO;EAChC,MAAM,MAAM,QAAQ,GAAG,KAAK,MAAM,KAAK,QAAQ,WAAW,KAAK,EAAE;EACjE,MAAM,cAAc;CACrB;CAEA,aAAa,KAAK;EACjB,MAAM,QAAQ,OAAQ,GAAG,KAAK,MAAM,GAAG,IAAK,SAAS;EACrD,IAAI,IAAI,MAAM;EAEd,IAAI,KAAK,KAAK,KACb,KAAK,IAAI,IACT,KAAK,IAAI,IACT,KAAK,IAAI,IAAI;EAEd,OAAO,QAAQ;CAChB;AACD"}
1
+ {"version":3,"file":"ScaleControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ScaleControl.js"],"sourcesContent":["\nimport {Control} from './Control.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\n/**\n * Options of `ScaleControl`.\n * @typedef {object} ScaleControlOptions\n * @property {string} [position='bottomleft'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [maxWidth=100] Maximum width of the control in pixels. The width is\n * set dynamically to show round values (e.g. 100, 200, 500).\n * @property {boolean} [metric=true] Whether to show the metric scale line (m/km).\n * @property {boolean} [imperial=true] Whether to show the imperial scale line (mi/ft).\n * @property {boolean} [updateWhenIdle=false] If `true`, the control is updated on\n * [`moveend`](#map-moveend), otherwise it's always up-to-date (updated on\n * [`move`](#map-move)).\n * @extends ControlOptions\n */\n\n/**\n * A simple scale control that shows the scale of the current center of screen in metric\n * (m/km) and imperial (mi/ft) systems.\n *\n * @example\n *\n * ```js\n * new ScaleControl().addTo(map);\n * ```\n */\nexport class ScaleControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomleft',\n\t\tmaxWidth: 100,\n\t\tmetric: true,\n\t\timperial: true,\n\t\tupdateWhenIdle: false\n\t};\n\n\t/**\n\t * Creates a scale control with the given options.\n\t * @param {...ScaleControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ScaleControl);\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 className = 'maplair-control-scale',\n\t\tcontainer = DomUtil.create('div', className),\n\t\toptions = this.options;\n\n\t\tthis._addScales(options, `${className}-line`, container);\n\n\t\tmap.whenReady(this._update, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\treturn {[this.options.updateWhenIdle ? 'moveend' : 'move']: this._update};\n\t}\n\n\t_addScales(options, className, container) {\n\t\tif (options.metric) {\n\t\t\tthis._mScale = DomUtil.create('div', className, container);\n\t\t}\n\t\tif (options.imperial) {\n\t\t\tthis._iScale = DomUtil.create('div', className, container);\n\t\t}\n\t}\n\n\t_update() {\n\t\tconst map = this._map,\n\t\ty = map.getSize().y / 2;\n\n\t\tconst maxMeters = map.distance(\n\t\t\tmap.containerPointToLatLng([0, y]),\n\t\t\tmap.containerPointToLatLng([this.options.maxWidth, y]));\n\n\t\tthis._updateScales(maxMeters);\n\t}\n\n\t_updateScales(maxMeters) {\n\t\tif (this.options.metric && maxMeters) {\n\t\t\tthis._updateMetric(maxMeters);\n\t\t}\n\t\tif (this.options.imperial && maxMeters) {\n\t\t\tthis._updateImperial(maxMeters);\n\t\t}\n\t}\n\n\t_updateMetric(maxMeters) {\n\t\tconst meters = this._getRoundNum(maxMeters),\n\t\tlabel = meters < 1000 ?\n\t\t\tI18n.translate('{meters} m', {meters}) :\n\t\t\tI18n.translate('{kilometers} km', {kilometers: meters / 1000});\n\n\t\tthis._updateScale(this._mScale, label, meters / maxMeters);\n\t}\n\n\t_updateImperial(maxMeters) {\n\t\tconst maxFeet = maxMeters * 3.2808399;\n\t\tlet maxMiles, miles, feet;\n\n\t\tif (maxFeet > 5280) {\n\t\t\tmaxMiles = maxFeet / 5280;\n\t\t\tmiles = this._getRoundNum(maxMiles);\n\t\t\tthis._updateScale(this._iScale, I18n.translate('{miles} mi', {miles}), miles / maxMiles);\n\n\t\t} else {\n\t\t\tfeet = this._getRoundNum(maxFeet);\n\t\t\tthis._updateScale(this._iScale, I18n.translate('{feet} ft', {feet}), feet / maxFeet);\n\t\t}\n\t}\n\n\t_updateScale(scale, text, ratio) {\n\t\tscale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;\n\t\tscale.textContent = text;\n\t}\n\n\t_getRoundNum(num) {\n\t\t// Below 1, count the zeros after the decimal point instead, so that 0.35 gives 0.3 rather than 1\n\t\t// (which would draw the scale wider than maxWidth)\n\t\tconst exponent = num < 1 ? Math.floor(Math.log10(num)) : (`${Math.floor(num)}`).length - 1;\n\t\tlet d = num / 10 ** exponent;\n\n\t\td = d >= 10 ? 10 :\n\t\t\td >= 5 ? 5 :\n\t\t\td >= 3 ? 3 :\n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EA,cAAc,WAAW;EACxB,MAAM,SAAS,KAAK,aAAa,SAAS,GAC1C,QAAQ,SAAS,MAChB,KAAK,UAAU,cAAc,EAAC,OAAM,CAAC,IACrC,KAAK,UAAU,mBAAmB,EAAC,YAAY,SAAS,IAAI,CAAC;EAE9D,KAAK,aAAa,KAAK,SAAS,OAAO,SAAS,SAAS;CAC1D;CAEA,gBAAgB,WAAW;EAC1B,MAAM,UAAU,YAAY;EAC5B,IAAI,UAAU,OAAO;EAErB,IAAI,UAAU,MAAM;GACnB,WAAW,UAAU;GACrB,QAAQ,KAAK,aAAa,QAAQ;GAClC,KAAK,aAAa,KAAK,SAAS,KAAK,UAAU,cAAc,EAAC,MAAK,CAAC,GAAG,QAAQ,QAAQ;EAExF,OAAO;GACN,OAAO,KAAK,aAAa,OAAO;GAChC,KAAK,aAAa,KAAK,SAAS,KAAK,UAAU,aAAa,EAAC,KAAI,CAAC,GAAG,OAAO,OAAO;EACpF;CACD;CAEA,aAAa,OAAO,MAAM,OAAO;EAChC,MAAM,MAAM,QAAQ,GAAG,KAAK,MAAM,KAAK,QAAQ,WAAW,KAAK,EAAE;EACjE,MAAM,cAAc;CACrB;CAEA,aAAa,KAAK;EAGjB,MAAM,WAAW,MAAM,IAAI,KAAK,MAAM,KAAK,MAAM,GAAG,CAAC,IAAK,GAAG,KAAK,MAAM,GAAG,IAAK,SAAS;EACzF,IAAI,IAAI,MAAM,MAAM;EAEpB,IAAI,KAAK,KAAK,KACb,KAAK,IAAI,IACT,KAAK,IAAI,IACT,KAAK,IAAI,IAAI;EAGd,OAAO,WAAW,IAAI,IAAI,MAAM,CAAC,WAAW,IAAI,MAAM;CACvD;AACD"}
@@ -110,6 +110,7 @@ var ZoomControl = class ZoomControl extends Control {
110
110
  }
111
111
  _updateDisabled() {
112
112
  const map = this._map;
113
+ if (!map) return;
113
114
  for (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {
114
115
  const disabled = this._disabled || map._zoom === limit;
115
116
  button.classList.toggle("maplair-disabled", disabled);
@@ -1 +1 @@
1
- {"version":3,"file":"ZoomControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ZoomControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `ZoomControl`.\n * @typedef {object} ZoomControlOptions\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} [zoomInText] The HTML of the 'zoom in' button, a plus sign drawn\n * in SVG by default.\n * @property {string} [zoomOutText] The HTML of the 'zoom out' button, a minus sign\n * drawn in SVG by default.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `ZoomControl`.\n * @typedef {object} ZoomControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [zoomControl=true] Whether a [zoom control](#control-zoom) is\n * added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `ZoomControl`.\n * @typedef {object} ZoomControlMapProperties\n * @lends MaplairMap\n * @property {ZoomControl} zoomControl The default zoom control (only available if the\n * [`zoomControl` option](#map-zoomcontrol) was `true` when creating the map).\n */\n\n/**\n * A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by\n * default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`.\n */\nexport class ZoomControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tzoomInText: '<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12M6 0v12\"/></svg>',\n\t\tzoomOutText: '<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12\"/></svg>',\n\t};\n\n\t/**\n\t * Creates a zoom control.\n\t * @param {...ZoomControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ZoomControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {HTMLElement}\n\t */\n\tonAdd() {\n\t\tconst zoomName = 'maplair-control-zoom',\n\t\tcontainer = DomUtil.create('div', `${zoomName} maplair-bar`),\n\t\toptions = this.options;\n\n\t\tthis._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),\n\t\t\t`${zoomName}-in`, container, e => this._zoom(e, 1));\n\t\tthis._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),\n\t\t\t`${zoomName}-out`, container, e => this._zoom(e, -1));\n\n\t\tthis._updateDisabled();\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\treturn {zoomend: this._updateDisabled, zoomlevelschange: this._updateDisabled};\n\t}\n\n\t/**\n\t * Disables the zoom buttons.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the zoom buttons (if the zoom level allows).\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t_zoom(e, dir) {\n\t\tconst map = this._map;\n\t\tif (!this._disabled && (dir > 0 ? map._zoom < map.getMaxZoom() : map._zoom > map.getMinZoom())) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.zoomIn(dir * map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_createButton(html, title, className, container, fn) {\n\t\tconst link = DomUtil.create('button', className, container);\n\t\tlink.type = 'button';\n\t\tlink.innerHTML = html;\n\t\tlink.title = title;\n\t\tlink.setAttribute('aria-label', title);\n\n\t\tDomEvent.disableClickPropagation(link);\n\t\tDomEvent.on(link, 'click', (e) => {\n\t\t\tDomEvent.stop(e);\n\t\t\tfn.call(this, e);\n\t\t});\n\n\t\treturn link;\n\t}\n\n\t_updateDisabled() {\n\t\tconst map = this._map;\n\t\tfor (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {\n\t\t\tconst disabled = this._disabled || map._zoom === limit;\n\t\t\tbutton.classList.toggle('maplair-disabled', disabled);\n\t\t\tbutton.setAttribute('aria-disabled', `${disabled}`);\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.mergeOptions({\n\t\t\tzoomControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.zoomControl) {\n\t\t\t\tthis.zoomControl = new ZoomControl();\n\t\t\t\tthis.addControl(this.zoomControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC,OAAO,iBAAiB;EACvB,UAAU;EACV,YAAY;EACZ,aAAa;CACd;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;;CAMA,QAAQ;EACP,MAAM,WAAW,wBACjB,YAAYA,OAAe,OAAO,GAAG,SAAS,aAAa,GAC3D,UAAU,KAAK;EAEf,KAAK,gBAAiB,KAAK,cAAc,QAAQ,YAAY,KAAK,UAAU,SAAS,GACpF,GAAG,SAAS,MAAO,YAAW,MAAK,KAAK,MAAM,GAAG,CAAC,CAAC;EACpD,KAAK,iBAAiB,KAAK,cAAc,QAAQ,aAAa,KAAK,UAAU,UAAU,GACtF,GAAG,SAAS,OAAO,YAAW,MAAK,KAAK,MAAM,GAAG,EAAE,CAA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,QAAQ,aAAa;IAC7B,KAAK,cAAc,IAAI,YAAY;IACnC,KAAK,WAAW,KAAK,WAAW;GACjC;EACD,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"ZoomControl.js","names":["DomUtil.create"],"sources":["../../../src/control/ZoomControl.js"],"sourcesContent":["\nimport {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n\n/**\n * Options of `ZoomControl`.\n * @typedef {object} ZoomControlOptions\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} [zoomInText] The HTML of the 'zoom in' button, a plus sign drawn\n * in SVG by default.\n * @property {string} [zoomOutText] The HTML of the 'zoom out' button, a minus sign\n * drawn in SVG by default.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `ZoomControl`.\n * @typedef {object} ZoomControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [zoomControl=true] Whether a [zoom control](#control-zoom) is\n * added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `ZoomControl`.\n * @typedef {object} ZoomControlMapProperties\n * @lends MaplairMap\n * @property {ZoomControl} zoomControl The default zoom control (only available if the\n * [`zoomControl` option](#map-zoomcontrol) was `true` when creating the map).\n */\n\n/**\n * A basic zoom control with two buttons (zoom in and zoom out). It is put on the map by\n * default unless you set its [`zoomControl` option](#map-zoomcontrol) to `false`.\n */\nexport class ZoomControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tzoomInText: '<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12M6 0v12\"/></svg>',\n\t\tzoomOutText: '<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12\"/></svg>',\n\t};\n\n\t/**\n\t * Creates a zoom control.\n\t * @param {...ZoomControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(ZoomControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {HTMLElement}\n\t */\n\tonAdd() {\n\t\tconst zoomName = 'maplair-control-zoom',\n\t\tcontainer = DomUtil.create('div', `${zoomName} maplair-bar`),\n\t\toptions = this.options;\n\n\t\tthis._zoomInButton = this._createButton(options.zoomInText, I18n.translate('Zoom in'),\n\t\t\t`${zoomName}-in`, container, e => this._zoom(e, 1));\n\t\tthis._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate('Zoom out'),\n\t\t\t`${zoomName}-out`, container, e => this._zoom(e, -1));\n\n\t\tthis._updateDisabled();\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {Record<string, Function>}\n\t */\n\tgetEvents() {\n\t\treturn {zoomend: this._updateDisabled, zoomlevelschange: this._updateDisabled};\n\t}\n\n\t/**\n\t * Disables the zoom buttons.\n\t * @returns {this}\n\t */\n\tdisable() {\n\t\tthis._disabled = true;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Enables the zoom buttons (if the zoom level allows).\n\t * @returns {this}\n\t */\n\tenable() {\n\t\tthis._disabled = false;\n\t\tthis._updateDisabled();\n\t\treturn this;\n\t}\n\n\t_zoom(e, dir) {\n\t\tconst map = this._map;\n\t\tif (!this._disabled && (dir > 0 ? map._zoom < map.getMaxZoom() : map._zoom > map.getMinZoom())) {\n\t\t\tmap._setUserEvent(e);\n\t\t\tmap.zoomIn(dir * map.options.zoomDelta * (e.shiftKey ? 3 : 1));\n\t\t}\n\t}\n\n\t_createButton(html, title, className, container, fn) {\n\t\tconst link = DomUtil.create('button', className, container);\n\t\tlink.type = 'button';\n\t\tlink.innerHTML = html;\n\t\tlink.title = title;\n\t\tlink.setAttribute('aria-label', title);\n\n\t\tDomEvent.disableClickPropagation(link);\n\t\tDomEvent.on(link, 'click', (e) => {\n\t\t\tDomEvent.stop(e);\n\t\t\tfn.call(this, e);\n\t\t});\n\n\t\treturn link;\n\t}\n\n\t_updateDisabled() {\n\t\tconst map = this._map;\n\t\tif (!map) { return; } // `onAdd` applies the state\n\t\tfor (const [button, limit] of [[this._zoomInButton, map.getMaxZoom()], [this._zoomOutButton, map.getMinZoom()]]) {\n\t\t\tconst disabled = this._disabled || map._zoom === limit;\n\t\t\tbutton.classList.toggle('maplair-disabled', disabled);\n\t\t\tbutton.setAttribute('aria-disabled', `${disabled}`);\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.mergeOptions({\n\t\t\tzoomControl: true\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.zoomControl) {\n\t\t\t\tthis.zoomControl = new ZoomControl();\n\t\t\t\tthis.addControl(this.zoomControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAyCA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC,OAAO,iBAAiB;EACvB,UAAU;EACV,YAAY;EACZ,aAAa;CACd;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;;CAMA,QAAQ;EACP,MAAM,WAAW,wBACjB,YAAYA,OAAe,OAAO,GAAG,SAAS,aAAa,GAC3D,UAAU,KAAK;EAEf,KAAK,gBAAiB,KAAK,cAAc,QAAQ,YAAY,KAAK,UAAU,SAAS,GACpF,GAAG,SAAS,MAAO,YAAW,MAAK,KAAK,MAAM,GAAG,CAAC,CAAC;EACpD,KAAK,iBAAiB,KAAK,cAAc,QAAQ,aAAa,KAA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A,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,aAAa,KACd,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,aAAa;IAC7B,KAAK,cAAc,IAAI,YAAY;IACnC,KAAK,WAAW,KAAK,WAAW;GACjC;EACD,CAAC;CACF;AACD"}
@@ -133,7 +133,7 @@ function getDefaultOptions(cls) {
133
133
  }
134
134
  return defaults;
135
135
  }
136
- const templateRe = /\{ *([\w_ -]+) *\}/g;
136
+ const templateRe = /\{ *([\w_ -]+?) *\}/g;
137
137
  /**
138
138
  * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`
139
139
  * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string
@@ -1 +1 @@
1
- {"version":3,"file":"Util.js","names":[],"sources":["../../../src/core/Util.js"],"sourcesContent":["// Util: various utility functions, used by Maplair internally.\n\n/**\n * Last unique ID used by [`stamp()`](#util-stamp).\n * @type {number}\n */\nexport let lastId = 0;\n\n/**\n * Returns the unique ID of an object, assigning it one if it doesn't have it.\n * @param {object} obj\n * @returns {number}\n */\nexport function stamp(obj) {\n\tif (!('_maplair_id' in obj)) {\n\t\tobj['_maplair_id'] = ++lastId;\n\t}\n\treturn obj._maplair_id;\n}\n\n/**\n * Returns a function which executes function `fn` with the given scope `context`\n * (so that the `this` keyword refers to `context` inside `fn`'s code). The function\n * `fn` will be called no more than one time per given amount of `time`. The arguments\n * received by the bound function will be any arguments passed when binding the\n * function, followed by any arguments passed when invoking the bound function.\n * @param {(...args: any[]) => void} fn\n * @param {number} time In milliseconds.\n * @param {object} [context]\n * @returns {(...args: any[]) => void}\n */\nexport function throttle(fn, time, context) {\n\tlet lock, queuedArgs;\n\n\tfunction later() {\n\t\t// reset lock and call if queued\n\t\tlock = false;\n\t\tif (queuedArgs) {\n\t\t\twrapperFn.apply(context, queuedArgs);\n\t\t\tqueuedArgs = false;\n\t\t}\n\t}\n\n\tfunction wrapperFn(...args) {\n\t\tif (lock) {\n\t\t\t// called too soon, queue to call later\n\t\t\tqueuedArgs = args;\n\n\t\t} else {\n\t\t\t// call and lock until later\n\t\t\tfn.apply(context, args);\n\t\t\tsetTimeout(later, time);\n\t\t\tlock = true;\n\t\t}\n\t}\n\n\treturn wrapperFn;\n}\n\n/**\n * Returns the number `x` modulo `range` in such a way so it lies within\n * `range[0]` and `range[1]`. The returned value will always be smaller than\n * `range[1]` unless `includeMax` is set to `true`.\n * @param {number} x\n * @param {[number, number]} range\n * @param {boolean} [includeMax]\n * @returns {number}\n */\nexport function wrapNum(x, range, includeMax) {\n\tconst max = range[1],\n\tmin = range[0],\n\td = max - min;\n\treturn x === max && includeMax ? x : ((x - min) % d + d) % d + min;\n}\n\n/**\n * A function which always returns `false`.\n * @returns {false}\n */\nexport function falseFn() { return false; }\n\n/**\n * Returns the number `num` rounded with specified `precision`.\n * The default `precision` value is 6 decimal places.\n * `false` can be passed to skip any processing (can be useful to avoid round-off errors).\n * @param {number} num\n * @param {number|false} [precision]\n * @returns {number}\n */\nexport function formatNum(num, precision = 6) {\n\tif (precision === false) { return num; }\n\tconst pow = 10 ** precision;\n\treturn Math.round(num * pow) / pow;\n}\n\n/**\n * Returns `value` if it's a number (including `Infinity`), converts it if it's a\n * numeric string, and returns `NaN` for anything else, unlike `Number()`, which turns\n * `''`, `null` and booleans into `0` or `1`.\n * @param {unknown} value\n * @returns {number}\n */\nexport function toNumber(value) {\n\treturn typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? +value : NaN;\n}\n\nconst WHITESPACE_RE = /\\s+/;\n\n/**\n * Trims and splits the string on whitespace and returns the array of parts.\n * @param {string} str\n * @returns {string[]}\n */\nexport function splitWords(str) {\n\t// a single word is the common case, and splitting allocates a lot more than the array\n\tconst trimmed = str.trim();\n\treturn WHITESPACE_RE.test(trimmed) ? trimmed.split(WHITESPACE_RE) : [trimmed];\n}\n\n/**\n * Merges the given properties to the `options` of the `obj` object, returning the\n * resulting options. See `Class options`.\n * @param {object} obj\n * @param {object} [options]\n * @returns {object}\n */\nexport function setOptions(obj, options) {\n\tif (!Object.hasOwn(obj, 'options')) {\n\t\tconst defaults = getDefaultOptions(obj.constructor) ?? obj.options;\n\t\tobj.options = defaults ? Object.create(defaults) : {};\n\t}\n\tfor (const i in options) {\n\t\tif (Object.hasOwn(options, i)) {\n\t\t\tobj.options[i] = options[i];\n\t\t}\n\t}\n\treturn obj.options;\n}\n\nconst chainedDefaults = new WeakMap(); // class -> the defaultOptions object it was chained with\n\n// Links the `defaultOptions` of each class in the chain to its parent's, so defaults are inherited and stay live.\n// Done on first use because a static field can't do it in its initializer and stay tree-shakeable.\nfunction getDefaultOptions(cls) {\n\tconst defaults = cls?.defaultOptions;\n\tif (defaults && chainedDefaults.get(cls) !== defaults) {\n\t\tfor (let c = cls; c.defaultOptions; c = Object.getPrototypeOf(c)) {\n\t\t\tif (Object.hasOwn(c, 'defaultOptions')) {\n\t\t\t\tObject.setPrototypeOf(c.defaultOptions, Object.getPrototypeOf(c).defaultOptions ?? Object.prototype);\n\t\t\t}\n\t\t}\n\t\tchainedDefaults.set(cls, defaults);\n\t}\n\treturn defaults;\n}\n\nconst templateRe = /\\{ *([\\w_ -]+) *\\}/g;\n\n/**\n * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`\n * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string\n * `('Hello foo, bar')`. You can also specify functions instead of strings for\n * data values — they will be evaluated passing `data` as an argument.\n * @param {string} str\n * @param {Record<string, any>} data\n * @returns {string}\n */\nexport function template(str, data) {\n\treturn str.replace(templateRe, (str, key) => {\n\t\tlet value = data[key];\n\n\t\tif (value === undefined) {\n\t\t\tthrow new Error(`No value provided for variable ${str}`);\n\n\t\t} else if (typeof value === 'function') {\n\t\t\tvalue = value(data);\n\t\t}\n\t\treturn value;\n\t});\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAMA,IAAW,SAAS;;;;;;AAOpB,SAAgB,MAAM,KAAK;CAC1B,IAA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OAAO,QAAQ,IAAI,CAAC;CACrD;CACA,KAAK,MAAM,KAAK,SACf,IAAI,OAAO,OAAO,SAAS,CAAC,GAC3B,IAAI,QAAQ,KAAK,QAAQ;CAG3B,OAAO,IAAI;AACZ;AAEA,MAAM,kCAAkB,IAAI,QAAQ;AAIpC,SAAS,kBAAkB,KAAK;CAC/B,MAAM,WAAW,KAAK;CACtB,IAAI,YAAY,gBAAgB,IAAI,GAAG,MAAM,UAAU;EACtD,KAAK,IAAI,IAAI,KAAK,EAAE,gBAAgB,IAAI,OAAO,eAAe,CAAC,GAC9D,IAAI,OAAO,OAAO,GAAG,gBAAgB,GACpC,OAAO,eAAe,EAAE,gBAAgB,OAAO,eAAe,CAAC,CAAC,CAAC,kBAAkB,OAAO,SAAS;EAGrG,gBAAgB,IAAI,KAAK,QAAQ;CAClC;CACA,OAAO;AACR;AAEA,MAAM,aAAa;;;;;;;;;;AAWnB,SAAgB,SAAS,KAAK,MAAM;CACnC,OAAO,IAAI,QAAQ,aAAa,KAAK,QAAQ;EAC5C,IAAI,QAAQ,KAAK;EAEjB,IAAI,UAAU,KAAA,GACb,MAAM,IAAI,MAAM,kCAAkC,KAAK;OAEjD,IAAI,OAAO,UAAU,YAC3B,QAAQ,MAAM,IAAI;EAEnB,OAAO;CACR,CAAC;AACF"}
1
+ {"version":3,"file":"Util.js","names":[],"sources":["../../../src/core/Util.js"],"sourcesContent":["// Util: various utility functions, used by Maplair internally.\n\n/**\n * Last unique ID used by [`stamp()`](#util-stamp).\n * @type {number}\n */\nexport let lastId = 0;\n\n/**\n * Returns the unique ID of an object, assigning it one if it doesn't have it.\n * @param {object} obj\n * @returns {number}\n */\nexport function stamp(obj) {\n\tif (!('_maplair_id' in obj)) {\n\t\tobj['_maplair_id'] = ++lastId;\n\t}\n\treturn obj._maplair_id;\n}\n\n/**\n * Returns a function which executes function `fn` with the given scope `context`\n * (so that the `this` keyword refers to `context` inside `fn`'s code). The function\n * `fn` will be called no more than one time per given amount of `time`. The arguments\n * received by the bound function will be any arguments passed when binding the\n * function, followed by any arguments passed when invoking the bound function.\n * @param {(...args: any[]) => void} fn\n * @param {number} time In milliseconds.\n * @param {object} [context]\n * @returns {(...args: any[]) => void}\n */\nexport function throttle(fn, time, context) {\n\tlet lock, queuedArgs;\n\n\tfunction later() {\n\t\t// reset lock and call if queued\n\t\tlock = false;\n\t\tif (queuedArgs) {\n\t\t\twrapperFn.apply(context, queuedArgs);\n\t\t\tqueuedArgs = false;\n\t\t}\n\t}\n\n\tfunction wrapperFn(...args) {\n\t\tif (lock) {\n\t\t\t// called too soon, queue to call later\n\t\t\tqueuedArgs = args;\n\n\t\t} else {\n\t\t\t// call and lock until later\n\t\t\tfn.apply(context, args);\n\t\t\tsetTimeout(later, time);\n\t\t\tlock = true;\n\t\t}\n\t}\n\n\treturn wrapperFn;\n}\n\n/**\n * Returns the number `x` modulo `range` in such a way so it lies within\n * `range[0]` and `range[1]`. The returned value will always be smaller than\n * `range[1]` unless `includeMax` is set to `true`.\n * @param {number} x\n * @param {[number, number]} range\n * @param {boolean} [includeMax]\n * @returns {number}\n */\nexport function wrapNum(x, range, includeMax) {\n\tconst max = range[1],\n\tmin = range[0],\n\td = max - min;\n\treturn x === max && includeMax ? x : ((x - min) % d + d) % d + min;\n}\n\n/**\n * A function which always returns `false`.\n * @returns {false}\n */\nexport function falseFn() { return false; }\n\n/**\n * Returns the number `num` rounded with specified `precision`.\n * The default `precision` value is 6 decimal places.\n * `false` can be passed to skip any processing (can be useful to avoid round-off errors).\n * @param {number} num\n * @param {number|false} [precision]\n * @returns {number}\n */\nexport function formatNum(num, precision = 6) {\n\tif (precision === false) { return num; }\n\tconst pow = 10 ** precision;\n\treturn Math.round(num * pow) / pow;\n}\n\n/**\n * Returns `value` if it's a number (including `Infinity`), converts it if it's a\n * numeric string, and returns `NaN` for anything else, unlike `Number()`, which turns\n * `''`, `null` and booleans into `0` or `1`.\n * @param {unknown} value\n * @returns {number}\n */\nexport function toNumber(value) {\n\treturn typeof value === 'number' ? value : typeof value === 'string' && value.trim() !== '' ? +value : NaN;\n}\n\nconst WHITESPACE_RE = /\\s+/;\n\n/**\n * Trims and splits the string on whitespace and returns the array of parts.\n * @param {string} str\n * @returns {string[]}\n */\nexport function splitWords(str) {\n\t// a single word is the common case, and splitting allocates a lot more than the array\n\tconst trimmed = str.trim();\n\treturn WHITESPACE_RE.test(trimmed) ? trimmed.split(WHITESPACE_RE) : [trimmed];\n}\n\n/**\n * Merges the given properties to the `options` of the `obj` object, returning the\n * resulting options. See `Class options`.\n * @param {object} obj\n * @param {object} [options]\n * @returns {object}\n */\nexport function setOptions(obj, options) {\n\tif (!Object.hasOwn(obj, 'options')) {\n\t\tconst defaults = getDefaultOptions(obj.constructor) ?? obj.options;\n\t\tobj.options = defaults ? Object.create(defaults) : {};\n\t}\n\tfor (const i in options) {\n\t\tif (Object.hasOwn(options, i)) {\n\t\t\tobj.options[i] = options[i];\n\t\t}\n\t}\n\treturn obj.options;\n}\n\nconst chainedDefaults = new WeakMap(); // class -> the defaultOptions object it was chained with\n\n// Links the `defaultOptions` of each class in the chain to its parent's, so defaults are inherited and stay live.\n// Done on first use because a static field can't do it in its initializer and stay tree-shakeable.\nfunction getDefaultOptions(cls) {\n\tconst defaults = cls?.defaultOptions;\n\tif (defaults && chainedDefaults.get(cls) !== defaults) {\n\t\tfor (let c = cls; c.defaultOptions; c = Object.getPrototypeOf(c)) {\n\t\t\tif (Object.hasOwn(c, 'defaultOptions')) {\n\t\t\t\tObject.setPrototypeOf(c.defaultOptions, Object.getPrototypeOf(c).defaultOptions ?? Object.prototype);\n\t\t\t}\n\t\t}\n\t\tchainedDefaults.set(cls, defaults);\n\t}\n\treturn defaults;\n}\n\nconst templateRe = /\\{ *([\\w_ -]+?) *\\}/g;\n\n/**\n * Simple templating facility, accepts a template string of the form `'Hello {a}, {b}'`\n * and a data object like `{a: 'foo', b: 'bar'}`, returns evaluated string\n * `('Hello foo, bar')`. You can also specify functions instead of strings for\n * data values — they will be evaluated passing `data` as an argument.\n * @param {string} str\n * @param {Record<string, any>} data\n * @returns {string}\n */\nexport function template(str, data) {\n\treturn str.replace(templateRe, (str, key) => {\n\t\tlet value = data[key];\n\n\t\tif (value === undefined) {\n\t\t\tthrow new Error(`No value provided for variable ${str}`);\n\n\t\t} else if (typeof value === 'function') {\n\t\t\tvalue = value(data);\n\t\t}\n\t\treturn value;\n\t});\n}\n\n\n"],"mappings":";;;;;;;;;;;;;;;;;;AAMA,IAAW,SAAS;;;;;;AAOpB,SAAgB,MAAM,KAAK;CAC1B,IAAI,EAAE,iBAAiB,MACtB,IAAI,iBAAiB,EAAE;CAExB,OAAO,IAAI;AACZ;;;;;;;;;;;;AAaA,SAAgB,SAAS,IAAI,MAAM,SAAS;CAC3C,IAAI,MAAM;CAEV,SAAS,QAAQ;EAEhB,OAAO;EACP,IAAI,YAAY;GACf,UAAU,MAAM,SAAS,UAAU;GACnC,aAAa;EACd;CACD;CAEA,SAAS,UAAU,GAAG,MAAM;EAC3B,IAAI,MAEH,aAAa;OAEP;GAEN,GAAG,MAAM,SAAS,IAAI;GACtB,WAAW,OAAO,IAAI;GACtB,OAAO;EACR;CACD;CAEA,OAAO;AACR;;;;;;;;;;AAWA,SAAgB,QAAQ,GAAG,OAAO,YAAY;CAC7C,MAAM,MAAM,MAAM,IAClB,MAAM,MAAM,IACZ,IAAI,MAAM;CACV,OAAO,MAAM,OAAO,aAAa,MAAM,IAAI,OAAO,IAAI,KAAK,IAAI;AAChE;;;;;AAMA,SAAgB,UAAU;CAAE,OAAO;AAAO;;;;;;;;;AAU1C,SAAgB,UAAU,KAAK,YAAY,GAAG;CAC7C,IAAI,cAAc,OAAS,OAAO;CAClC,MAAM,MAAM,MAAM;CAClB,OAAO,KAAK,MAAM,MAAM,GAAG,IAAI;AAChC;;;;;;;;AASA,SAAgB,SAAS,OAAO;CAC/B,OAAO,OAAO,UAAU,WAAW,QAAQ,OAAO,UAAU,YAAY,MAAM,KAAK,MAAM,KAAK,CAA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erDetection: () => disablePointerDetection,
5
5
  enablePointerDetection: () => enablePointerDetection,
6
6
  getPointers: () => getPointers,
7
+ isClickDisabled: () => isClickDisabled,
7
8
  simulateDblclick: () => simulateDblclick
8
9
  });
9
10
  const activePointers = /* @__PURE__ */ new Map();
@@ -33,10 +34,26 @@ function disablePointerDetection(el) {
33
34
  el.removeEventListener("pointerup", _onDelete, { capture: true });
34
35
  el.removeEventListener("pointercancel", _onDelete, { capture: true });
35
36
  }
37
+ /**
38
+ * Whether `el` is inside an element that `DomEvent.disableClickPropagation` was called
39
+ * on (before reaching `container`), or detached from the DOM.
40
+ * @internal
41
+ * @param {Node|null} el
42
+ * @param {EventTarget|null} container
43
+ * @returns {boolean}
44
+ */
45
+ function isClickDisabled(el, container) {
46
+ while (el && el !== container) {
47
+ if (el["_maplair_disable_click"] || !el.parentNode) return true;
48
+ el = el.parentNode;
49
+ }
50
+ return false;
51
+ }
36
52
  function _onSet(e) {
53
+ lastPointerType = e.pointerType;
54
+ if (isClickDisabled(e.target, e.currentTarget)) return;
37
55
  if (e.isTrusted) e.target.setPointerCapture(e.pointerId);
38
56
  activePointers.set(e.pointerId, e);
39
- lastPointerType = e.pointerType;
40
57
  }
41
58
  function _onUpdate(e) {
42
59
  if (activePointers.has(e.pointerId)) activePointers.set(e.pointerId, e);
@@ -103,6 +120,6 @@ function simulateDblclick(e, mapContainer) {
103
120
  target.dispatchEvent(new MouseEvent("dblclick", init));
104
121
  }
105
122
  }
106
- export { DomEvent_PointerEvents_exports, disablePointerDetection, enablePointerDetection, getPointers, simulateDblclick };
123
+ export { DomEvent_PointerEvents_exports, disablePointerDetection, enablePointerDetection, getPointers, isClickDisabled, simulateDblclick };
107
124
 
108
125
  //# sourceMappingURL=DomEvent.PointerEvents.js.map