maplair 4.3.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (191) hide show
  1. package/CHANGELOG.md +151 -8
  2. package/dist/esm/control/AttributionControl.js +30 -13
  3. package/dist/esm/control/AttributionControl.js.map +1 -1
  4. package/dist/esm/control/ButtonControl.js +0 -1
  5. package/dist/esm/control/ButtonControl.js.map +1 -1
  6. package/dist/esm/control/ContextMenu.js +1 -1
  7. package/dist/esm/control/ContextMenu.js.map +1 -1
  8. package/dist/esm/control/Control.js +16 -11
  9. package/dist/esm/control/Control.js.map +1 -1
  10. package/dist/esm/control/FullscreenControl.js +0 -1
  11. package/dist/esm/control/FullscreenControl.js.map +1 -1
  12. package/dist/esm/control/LayersControl.js +46 -27
  13. package/dist/esm/control/LayersControl.js.map +1 -1
  14. package/dist/esm/control/RotateControl.js +0 -1
  15. package/dist/esm/control/RotateControl.js.map +1 -1
  16. package/dist/esm/control/ScaleControl.js +7 -8
  17. package/dist/esm/control/ScaleControl.js.map +1 -1
  18. package/dist/esm/control/SideBySideControl.js +3 -2
  19. package/dist/esm/control/SideBySideControl.js.map +1 -1
  20. package/dist/esm/control/ZoomControl.js +14 -13
  21. package/dist/esm/control/ZoomControl.js.map +1 -1
  22. package/dist/esm/core/Events.js +3 -2
  23. package/dist/esm/core/Events.js.map +1 -1
  24. package/dist/esm/core/Util.js +17 -5
  25. package/dist/esm/core/Util.js.map +1 -1
  26. package/dist/esm/dom/DomEvent.PointerEvents.js +72 -2
  27. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  28. package/dist/esm/dom/DomEvent.js +4 -7
  29. package/dist/esm/dom/DomEvent.js.map +1 -1
  30. package/dist/esm/dom/DomUtil.js +5 -5
  31. package/dist/esm/dom/DomUtil.js.map +1 -1
  32. package/dist/esm/dom/Draggable.js +10 -8
  33. package/dist/esm/dom/Draggable.js.map +1 -1
  34. package/dist/esm/geo/LatLng.js +24 -35
  35. package/dist/esm/geo/LatLng.js.map +1 -1
  36. package/dist/esm/geo/LatLngBounds.js +6 -3
  37. package/dist/esm/geo/LatLngBounds.js.map +1 -1
  38. package/dist/esm/geometry/Bounds.js +2 -2
  39. package/dist/esm/geometry/Bounds.js.map +1 -1
  40. package/dist/esm/geometry/Point.js +16 -19
  41. package/dist/esm/geometry/Point.js.map +1 -1
  42. package/dist/esm/geometry/PolyUtil.js +10 -3
  43. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  44. package/dist/esm/geometry/Transformation.js +1 -7
  45. package/dist/esm/geometry/Transformation.js.map +1 -1
  46. package/dist/esm/layer/BlanketOverlay.js +3 -2
  47. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  48. package/dist/esm/layer/DivOverlay.js +25 -25
  49. package/dist/esm/layer/DivOverlay.js.map +1 -1
  50. package/dist/esm/layer/ImageOverlay.js +8 -5
  51. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  52. package/dist/esm/layer/Layer.js +12 -7
  53. package/dist/esm/layer/Layer.js.map +1 -1
  54. package/dist/esm/layer/Popup.js +33 -15
  55. package/dist/esm/layer/Popup.js.map +1 -1
  56. package/dist/esm/layer/Tooltip.js +48 -56
  57. package/dist/esm/layer/Tooltip.js.map +1 -1
  58. package/dist/esm/layer/VideoOverlay.js +2 -2
  59. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  60. package/dist/esm/layer/marker/DivIcon.js +4 -8
  61. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  62. package/dist/esm/layer/marker/Icon.js +37 -17
  63. package/dist/esm/layer/marker/Icon.js.map +1 -1
  64. package/dist/esm/layer/marker/Marker.Drag.js +11 -12
  65. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  66. package/dist/esm/layer/marker/Marker.js +54 -53
  67. package/dist/esm/layer/marker/Marker.js.map +1 -1
  68. package/dist/esm/layer/marker/SvgIcon.js +1 -1
  69. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  70. package/dist/esm/layer/tile/GridLayer.js +29 -21
  71. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  72. package/dist/esm/layer/tile/TileLayer.js +19 -15
  73. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  74. package/dist/esm/layer/tile/WMSTileLayer.js +7 -3
  75. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  76. package/dist/esm/layer/vector/Canvas.js +45 -94
  77. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  78. package/dist/esm/layer/vector/Circle.js +8 -9
  79. package/dist/esm/layer/vector/Circle.js.map +1 -1
  80. package/dist/esm/layer/vector/CircleMarker.js +15 -4
  81. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  82. package/dist/esm/layer/vector/Path.ZoomStyles.js +4 -1
  83. package/dist/esm/layer/vector/Path.ZoomStyles.js.map +1 -1
  84. package/dist/esm/layer/vector/Path.js +10 -5
  85. package/dist/esm/layer/vector/Path.js.map +1 -1
  86. package/dist/esm/layer/vector/Polygon.js +10 -11
  87. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  88. package/dist/esm/layer/vector/Polyline.js +19 -26
  89. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  90. package/dist/esm/layer/vector/Renderer.getRenderer.js +2 -1
  91. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  92. package/dist/esm/layer/vector/Renderer.js +16 -0
  93. package/dist/esm/layer/vector/Renderer.js.map +1 -1
  94. package/dist/esm/layer/vector/SVG.js +3 -3
  95. package/dist/esm/layer/vector/SVG.js.map +1 -1
  96. package/dist/esm/map/Map.Rotation.js +9 -11
  97. package/dist/esm/map/Map.Rotation.js.map +1 -1
  98. package/dist/esm/map/Map.js +158 -71
  99. package/dist/esm/map/Map.js.map +1 -1
  100. package/dist/esm/map/MapSync.js +2 -5
  101. package/dist/esm/map/MapSync.js.map +1 -1
  102. package/dist/esm/map/handler/BoxZoomHandler.js +4 -0
  103. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  104. package/dist/esm/map/handler/DisplaceHandler.js +68 -30
  105. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  106. package/dist/esm/map/handler/DragHandler.js +7 -2
  107. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  108. package/dist/esm/map/handler/KeyboardHandler.js +3 -5
  109. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  110. package/dist/esm/map/handler/PinchZoomHandler.js +4 -7
  111. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  112. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +4 -7
  113. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  114. package/dist/esm/map/handler/TapDragZoomHandler.js +2 -5
  115. package/dist/esm/map/handler/TapDragZoomHandler.js.map +1 -1
  116. package/dist/esm/map/handler/TapHoldHandler.js +8 -20
  117. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  118. package/dist/esm/package.js +1 -1
  119. package/dist/maplair-global-src.js +970 -810
  120. package/dist/maplair-global-src.js.map +1 -1
  121. package/dist/maplair-global.js +2 -2
  122. package/dist/maplair-global.js.map +1 -1
  123. package/dist/maplair-src.js +970 -810
  124. package/dist/maplair-src.js.map +1 -1
  125. package/dist/maplair.css +1 -1
  126. package/dist/maplair.js +2 -2
  127. package/dist/maplair.js.map +1 -1
  128. package/i18n/en.json +1 -0
  129. package/package.json +1 -1
  130. package/src/control/AttributionControl.js +37 -11
  131. package/src/control/ButtonControl.js +0 -1
  132. package/src/control/ContextMenu.js +1 -1
  133. package/src/control/Control.js +13 -16
  134. package/src/control/FullscreenControl.js +0 -1
  135. package/src/control/LayersControl.js +61 -37
  136. package/src/control/RotateControl.js +0 -1
  137. package/src/control/ScaleControl.js +10 -8
  138. package/src/control/SideBySideControl.js +4 -2
  139. package/src/control/ZoomControl.js +11 -13
  140. package/src/core/Events.js +6 -2
  141. package/src/core/Util.js +17 -4
  142. package/src/dom/DomEvent.PointerEvents.js +68 -2
  143. package/src/dom/DomEvent.js +5 -17
  144. package/src/dom/DomUtil.js +5 -5
  145. package/src/dom/Draggable.js +11 -8
  146. package/src/geo/LatLng.js +24 -37
  147. package/src/geo/LatLngBounds.js +10 -4
  148. package/src/geometry/Bounds.js +3 -3
  149. package/src/geometry/Point.js +22 -28
  150. package/src/geometry/PolyUtil.js +12 -3
  151. package/src/geometry/Transformation.js +1 -8
  152. package/src/layer/BlanketOverlay.js +6 -3
  153. package/src/layer/DivOverlay.js +30 -32
  154. package/src/layer/ImageOverlay.js +12 -9
  155. package/src/layer/Layer.js +19 -7
  156. package/src/layer/Popup.js +41 -21
  157. package/src/layer/Tooltip.js +50 -70
  158. package/src/layer/VideoOverlay.js +2 -2
  159. package/src/layer/marker/DivIcon.js +3 -6
  160. package/src/layer/marker/Icon.js +41 -20
  161. package/src/layer/marker/Marker.Drag.js +22 -24
  162. package/src/layer/marker/Marker.js +71 -64
  163. package/src/layer/marker/SvgIcon.js +1 -1
  164. package/src/layer/tile/GridLayer.js +41 -30
  165. package/src/layer/tile/TileLayer.js +31 -21
  166. package/src/layer/tile/WMSTileLayer.js +4 -2
  167. package/src/layer/vector/Canvas.js +53 -149
  168. package/src/layer/vector/Circle.js +13 -13
  169. package/src/layer/vector/CircleMarker.js +16 -3
  170. package/src/layer/vector/Path.ZoomStyles.js +5 -3
  171. package/src/layer/vector/Path.js +11 -5
  172. package/src/layer/vector/Polygon.js +11 -10
  173. package/src/layer/vector/Polyline.js +20 -21
  174. package/src/layer/vector/Renderer.getRenderer.js +2 -1
  175. package/src/layer/vector/Renderer.js +21 -3
  176. package/src/layer/vector/SVG.js +3 -3
  177. package/src/map/Map.Rotation.js +13 -9
  178. package/src/map/Map.js +195 -83
  179. package/src/map/MapSync.js +2 -2
  180. package/src/map/handler/BoxZoomHandler.js +5 -0
  181. package/src/map/handler/DisplaceHandler.js +53 -7
  182. package/src/map/handler/DragHandler.js +5 -5
  183. package/src/map/handler/KeyboardHandler.js +5 -10
  184. package/src/map/handler/PinchZoomHandler.js +4 -4
  185. package/src/map/handler/ScrollWheelZoomHandler.js +4 -4
  186. package/src/map/handler/TapDragZoomHandler.js +2 -2
  187. package/src/map/handler/TapHoldHandler.js +13 -25
  188. package/src/maplair.css +50 -10
  189. package/dist/esm/dom/DomEvent.DoubleTap.js +0 -90
  190. package/dist/esm/dom/DomEvent.DoubleTap.js.map +0 -1
  191. package/src/dom/DomEvent.DoubleTap.js +0 -143
@@ -1 +1 @@
1
- {"version":3,"file":"FullscreenControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/FullscreenControl.js"],"sourcesContent":["import {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/** @import {MaplairEvent} from '../core/Events.js' */\n\nconst enterIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"currentColor\"><path d=\"M2 2h5v2H4v3H2zm7 0h5v5h-2V4H9zM2 9h2v3h3v2H2zm10 0h2v5H9v-2h3z\"/></svg>';\nconst exitIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"currentColor\"><path d=\"M5 2h2v5H2V5h3zm4 0h2v3h3v2H9zM2 9h5v5H5v-3H2zm7 0h5v2h-3v3H9z\"/></svg>';\n\n/**\n * Options of `FullscreenControl`.\n * @typedef {object} FullscreenControlOptions\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} [enterText] The HTML content of the button while the map is not in\n * fullscreen, by default an expand icon.\n * @property {string} [exitText] The HTML content of the button while the map is in\n * fullscreen, by default a collapse icon.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `FullscreenControl`.\n * @typedef {object} FullscreenControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [fullscreenControl=false] Whether a\n * [fullscreen control](#fullscreencontrol) is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `FullscreenControl`.\n * @typedef {object} FullscreenControlMapProperties\n * @lends MaplairMap\n * @property {FullscreenControl} fullscreenControl The default fullscreen control (only\n * available if the [`fullscreenControl` option](#map-fullscreencontrol) was `true` when\n * creating the map).\n */\n\n/**\n * Methods of `MaplairMap` for the fullscreen view.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#enterfullscreen {MaplairEvent} Fired when the map enters fullscreen.\n * @fires MaplairMap#exitfullscreen {MaplairEvent} Fired when the map exits fullscreen.\n * @fires MaplairMap#fullscreenchange {MaplairEvent} Fired when the map enters or exits\n * fullscreen.\n */\nconst mapFullscreenMethods = {\n\t/**\n\t * Enters or exits the fullscreen view of the map, see `FullscreenControl`.\n\t * Browsers allow entering fullscreen only in response to a user interaction,\n\t * e.g. a click.\n\t * @group Methods for modifying map state\n\t * @returns {this}\n\t */\n\ttoggleFullscreen() {\n\t\tconst container = this._container;\n\n\t\tif (this._fullscreen === 'pseudo') {\n\t\t\tthis._setFullscreen(false);\n\t\t} else if (this._fullscreen) {\n\t\t\tdocument.exitFullscreen();\n\t\t} else if (document.fullscreenEnabled && container.requestFullscreen) {\n\t\t\tDomEvent.on(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\tcontainer.requestFullscreen().catch(() => {\n\t\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\t\tthis._setFullscreen('pseudo');\n\t\t\t});\n\t\t} else {\n\t\t\tthis._setFullscreen('pseudo');\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the map is viewed in fullscreen.\n\t * @group Other methods\n\t * @returns {boolean}\n\t */\n\tisFullscreen() {\n\t\treturn !!this._fullscreen;\n\t},\n\n\t_onFullscreenChange() {\n\t\tconst fullscreen = document.fullscreenElement === this._container;\n\t\tif (!fullscreen) {\n\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t}\n\t\tif (fullscreen !== this.isFullscreen()) {\n\t\t\tthis._setFullscreen(fullscreen && 'native');\n\t\t}\n\t},\n\n\t_onFullscreenKeyDown(e) {\n\t\tif (e.key === 'Escape') {\n\t\t\tthis._setFullscreen(false);\n\t\t}\n\t},\n\n\t// `mode` is `'native'` (Fullscreen API), `'pseudo'` (CSS) or `false`\n\t_setFullscreen(mode) {\n\t\tconst container = this._container;\n\t\tthis._fullscreen = mode;\n\n\t\tcontainer.classList.toggle('maplair-fullscreen', !!mode);\n\t\tcontainer.classList.toggle('maplair-pseudo-fullscreen', mode === 'pseudo');\n\t\tif (mode === 'pseudo') {\n\t\t\tDomEvent.on(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t} else {\n\t\t\tDomEvent.off(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t}\n\n\t\tthis.invalidateSize();\n\n\t\tthis.fire(mode ? 'enterfullscreen' : 'exitfullscreen');\n\t\tthis.fire('fullscreenchange');\n\t}\n};\n/** @typedef {typeof mapFullscreenMethods} MapFullscreenMethods */\n\n/**\n * A control with a button to view the map in fullscreen and to exit it again. It is\n * put on the map if you set its [`fullscreenControl` option](#map-fullscreencontrol)\n * to `true`. Where the browser does not support the\n * [Fullscreen API](https://developer.mozilla.org/docs/Web/API/Fullscreen_API)\n * (e.g. Safari on iPhone) or refuses fullscreen (e.g. in an iframe without\n * `allow=\"fullscreen\"`), the map is enlarged to the size of the window instead.\n *\n * @example\n * ```js\n * new FullscreenControl({position: 'topright'}).addTo(map);\n * ```\n */\nexport class FullscreenControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tenterText: enterIcon,\n\t\texitText: exitIcon\n\t};\n\n\t/**\n\t * Creates a fullscreen control.\n\t * @param {...FullscreenControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(FullscreenControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst container = DomUtil.create('div', 'maplair-control-fullscreen maplair-bar'),\n\t\tbutton = this._button = DomUtil.create('button', 'maplair-control-fullscreen-button', container);\n\t\tbutton.type = 'button';\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._toggleFullscreen, this);\n\t\tDomEvent.on(button, 'click', this._refocusOnMap, this);\n\n\t\tthis._update();\n\t\tmap.on('fullscreenchange', this._update, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('fullscreenchange', this._update, this);\n\t}\n\n\t_toggleFullscreen() {\n\t\tthis._map.toggleFullscreen();\n\t}\n\n\t_update() {\n\t\tconst fullscreen = this._map.isFullscreen(),\n\t\ttitle = fullscreen ? I18n.translate('Exit fullscreen') : I18n.translate('View fullscreen');\n\n\t\tthis._button.innerHTML = fullscreen ? this.options.exitText : this.options.enterText;\n\t\tthis._button.title = title;\n\t\tthis._button.setAttribute('aria-label', title);\n\t\tthis._button.setAttribute('aria-pressed', fullscreen);\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\tfullscreenControl: false\n\t\t});\n\n\t\tMaplairMap.include(mapFullscreenMethods);\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tthis.on('unload', function () {\n\t\t\t\tif (this._fullscreen === 'native') {\n\t\t\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\t\t\tdocument.exitFullscreen();\n\t\t\t\t}\n\t\t\t\tthis._container.classList.remove('maplair-fullscreen', 'maplair-pseudo-fullscreen');\n\t\t\t\tDomEvent.off(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t\t\tthis._fullscreen = false;\n\t\t\t});\n\n\t\t\tif (this.options.fullscreenControl) {\n\t\t\t\tthis.fullscreenControl = new FullscreenControl();\n\t\t\t\tthis.addControl(this.fullscreenControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,YAAY;AAClB,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCjB,MAAM,uBAAuB;;;;;;;;CAQ5B,mBAAmB;EAClB,MAAM,YAAY,KAAK;EAEvB,IAAI,KAAK,gBAAgB,UACxB,KAAK,eAAe,KAAK;OACnB,IAAI,KAAK,aACf,SAAS,eAAe;OAClB,IAAI,SAAS,qBAAqB,UAAU,mBAAmB;GACrE,GAAY,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;GACxE,UAAU,kBAAkB,CAAC,CAAC,YAAY;IACzC,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;IACzE,KAAK,eAAe,QAAQ;GAC7B,CAAC;EACF,OACC,KAAK,eAAe,QAAQ;EAE7B,OAAO;CACR;;;;;;CAOA,eAAe;EACd,OAAO,CAAC,CAAC,KAAK;CACf;CAEA,sBAAsB;EACrB,MAAM,aAAa,SAAS,sBAAsB,KAAK;EACvD,IAAI,CAAC,YACJ,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;EAE1E,IAAI,eAAe,KAAK,aAAa,GACpC,KAAK,eAAe,cAAc,QAAQ;CAE5C;CAEA,qBAAqB,GAAG;EACvB,IAAI,EAAE,QAAQ,UACb,KAAK,eAAe,KAAK;CAE3B;CAGA,eAAe,MAAM;EACpB,MAAM,YAAY,KAAK;EACvB,KAAK,cAAc;EAEnB,UAAU,UAAU,OAAO,sBAAsB,CAAC,CAAC,IAAI;EACvD,UAAU,UAAU,OAAO,6BAA6B,SAAS,QAAQ;EACzE,IAAI,SAAS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,CAAC;EAED,WAAW,QAAQ,oBAAoB;EAEvC,WAAW,YAAY,WAAY;GAClC,KAAK,GAAG,UAAU,WAAY;IAC7B,IAAI,KAAK,gBAAgB,UAAU;KAClC,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;KACzE,SAAS,eAAe;IACzB;IACA,KAAK,WAAW,UAAU,OAAO,sBAAsB,2BAA2B;IAClF,IAAa,UAAU,WAAW,KAAK,sBAAsB,IAAI;IACjE,KAAK,cAAc;GACpB,CAAC;GAED,IAAI,KAAK,QAAQ,mBAAmB;IACnC,KAAK,oBAAoB,IAAI,kBAAkB;IAC/C,KAAK,WAAW,KAAK,iBAAiB;GACvC;EACD,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"FullscreenControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/FullscreenControl.js"],"sourcesContent":["import {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/** @import {MaplairEvent} from '../core/Events.js' */\n\nconst enterIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"currentColor\"><path d=\"M2 2h5v2H4v3H2zm7 0h5v5h-2V4H9zM2 9h2v3h3v2H2zm10 0h2v5H9v-2h3z\"/></svg>';\nconst exitIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"currentColor\"><path d=\"M5 2h2v5H2V5h3zm4 0h2v3h3v2H9zM2 9h5v5H5v-3H2zm7 0h5v2h-3v3H9z\"/></svg>';\n\n/**\n * Options of `FullscreenControl`.\n * @typedef {object} FullscreenControlOptions\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} [enterText] The HTML content of the button while the map is not in\n * fullscreen, by default an expand icon.\n * @property {string} [exitText] The HTML content of the button while the map is in\n * fullscreen, by default a collapse icon.\n * @extends ControlOptions\n */\n\n/**\n * Map options of `FullscreenControl`.\n * @typedef {object} FullscreenControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [fullscreenControl=false] Whether a\n * [fullscreen control](#fullscreencontrol) is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `FullscreenControl`.\n * @typedef {object} FullscreenControlMapProperties\n * @lends MaplairMap\n * @property {FullscreenControl} fullscreenControl The default fullscreen control (only\n * available if the [`fullscreenControl` option](#map-fullscreencontrol) was `true` when\n * creating the map).\n */\n\n/**\n * Methods of `MaplairMap` for the fullscreen view.\n * @lends MaplairMap.prototype\n * @fires MaplairMap#enterfullscreen {MaplairEvent} Fired when the map enters fullscreen.\n * @fires MaplairMap#exitfullscreen {MaplairEvent} Fired when the map exits fullscreen.\n * @fires MaplairMap#fullscreenchange {MaplairEvent} Fired when the map enters or exits\n * fullscreen.\n */\nconst mapFullscreenMethods = {\n\t/**\n\t * Enters or exits the fullscreen view of the map, see `FullscreenControl`.\n\t * Browsers allow entering fullscreen only in response to a user interaction,\n\t * e.g. a click.\n\t * @group Methods for modifying map state\n\t * @returns {this}\n\t */\n\ttoggleFullscreen() {\n\t\tconst container = this._container;\n\n\t\tif (this._fullscreen === 'pseudo') {\n\t\t\tthis._setFullscreen(false);\n\t\t} else if (this._fullscreen) {\n\t\t\tdocument.exitFullscreen();\n\t\t} else if (document.fullscreenEnabled && container.requestFullscreen) {\n\t\t\tDomEvent.on(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\tcontainer.requestFullscreen().catch(() => {\n\t\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\t\tthis._setFullscreen('pseudo');\n\t\t\t});\n\t\t} else {\n\t\t\tthis._setFullscreen('pseudo');\n\t\t}\n\t\treturn this;\n\t},\n\n\t/**\n\t * Returns `true` if the map is viewed in fullscreen.\n\t * @group Other methods\n\t * @returns {boolean}\n\t */\n\tisFullscreen() {\n\t\treturn !!this._fullscreen;\n\t},\n\n\t_onFullscreenChange() {\n\t\tconst fullscreen = document.fullscreenElement === this._container;\n\t\tif (!fullscreen) {\n\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t}\n\t\tif (fullscreen !== this.isFullscreen()) {\n\t\t\tthis._setFullscreen(fullscreen && 'native');\n\t\t}\n\t},\n\n\t_onFullscreenKeyDown(e) {\n\t\tif (e.key === 'Escape') {\n\t\t\tthis._setFullscreen(false);\n\t\t}\n\t},\n\n\t// `mode` is `'native'` (Fullscreen API), `'pseudo'` (CSS) or `false`\n\t_setFullscreen(mode) {\n\t\tconst container = this._container;\n\t\tthis._fullscreen = mode;\n\n\t\tcontainer.classList.toggle('maplair-fullscreen', !!mode);\n\t\tcontainer.classList.toggle('maplair-pseudo-fullscreen', mode === 'pseudo');\n\t\tif (mode === 'pseudo') {\n\t\t\tDomEvent.on(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t} else {\n\t\t\tDomEvent.off(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t}\n\n\t\tthis.invalidateSize();\n\n\t\tthis.fire(mode ? 'enterfullscreen' : 'exitfullscreen');\n\t\tthis.fire('fullscreenchange');\n\t}\n};\n/** @typedef {typeof mapFullscreenMethods} MapFullscreenMethods */\n\n/**\n * A control with a button to view the map in fullscreen and to exit it again. It is\n * put on the map if you set its [`fullscreenControl` option](#map-fullscreencontrol)\n * to `true`. Where the browser does not support the\n * [Fullscreen API](https://developer.mozilla.org/docs/Web/API/Fullscreen_API)\n * (e.g. Safari on iPhone) or refuses fullscreen (e.g. in an iframe without\n * `allow=\"fullscreen\"`), the map is enlarged to the size of the window instead.\n *\n * @example\n * ```js\n * new FullscreenControl({position: 'topright'}).addTo(map);\n * ```\n */\nexport class FullscreenControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tenterText: enterIcon,\n\t\texitText: exitIcon\n\t};\n\n\t/**\n\t * Creates a fullscreen control.\n\t * @param {...FullscreenControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(FullscreenControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst container = DomUtil.create('div', 'maplair-control-fullscreen maplair-bar'),\n\t\tbutton = this._button = DomUtil.create('button', 'maplair-control-fullscreen-button', container);\n\t\tbutton.type = 'button';\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._toggleFullscreen, this);\n\n\t\tthis._update();\n\t\tmap.on('fullscreenchange', this._update, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('fullscreenchange', this._update, this);\n\t}\n\n\t_toggleFullscreen() {\n\t\tthis._map.toggleFullscreen();\n\t}\n\n\t_update() {\n\t\tconst fullscreen = this._map.isFullscreen(),\n\t\ttitle = fullscreen ? I18n.translate('Exit fullscreen') : I18n.translate('View fullscreen');\n\n\t\tthis._button.innerHTML = fullscreen ? this.options.exitText : this.options.enterText;\n\t\tthis._button.title = title;\n\t\tthis._button.setAttribute('aria-label', title);\n\t\tthis._button.setAttribute('aria-pressed', fullscreen);\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\tfullscreenControl: false\n\t\t});\n\n\t\tMaplairMap.include(mapFullscreenMethods);\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tthis.on('unload', function () {\n\t\t\t\tif (this._fullscreen === 'native') {\n\t\t\t\t\tDomEvent.off(document, 'fullscreenchange', this._onFullscreenChange, this);\n\t\t\t\t\tdocument.exitFullscreen();\n\t\t\t\t}\n\t\t\t\tthis._container.classList.remove('maplair-fullscreen', 'maplair-pseudo-fullscreen');\n\t\t\t\tDomEvent.off(document, 'keydown', this._onFullscreenKeyDown, this);\n\t\t\t\tthis._fullscreen = false;\n\t\t\t});\n\n\t\t\tif (this.options.fullscreenControl) {\n\t\t\t\tthis.fullscreenControl = new FullscreenControl();\n\t\t\t\tthis.addControl(this.fullscreenControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;;AAQA,MAAM,YAAY;AAClB,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAwCjB,MAAM,uBAAuB;;;;;;;;CAQ5B,mBAAmB;EAClB,MAAM,YAAY,KAAK;EAEvB,IAAI,KAAK,gBAAgB,UACxB,KAAK,eAAe,KAAK;OACnB,IAAI,KAAK,aACf,SAAS,eAAe;OAClB,IAAI,SAAS,qBAAqB,UAAU,mBAAmB;GACrE,GAAY,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;GACxE,UAAU,kBAAkB,CAAC,CAAC,YAAY;IACzC,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;IACzE,KAAK,eAAe,QAAQ;GAC7B,CAAC;EACF,OACC,KAAK,eAAe,QAAQ;EAE7B,OAAO;CACR;;;;;;CAOA,eAAe;EACd,OAAO,CAAC,CAAC,KAAK;CACf;CAEA,sBAAsB;EACrB,MAAM,aAAa,SAAS,sBAAsB,KAAK;EACvD,IAAI,CAAC,YACJ,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;EAE1E,IAAI,eAAe,KAAK,aAAa,GACpC,KAAK,eAAe,cAAc,QAAQ;CAE5C;CAEA,qBAAqB,GAAG;EACvB,IAAI,EAAE,QAAQ,UACb,KAAK,eAAe,KAAK;CAE3B;CAGA,eAAe,MAAM;EACpB,MAAM,YAAY,KAAK;EACvB,KAAK,cAAc;EA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;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,mBAAmB,MACpB,CAAC;EAED,WAAW,QAAQ,oBAAoB;EAEvC,WAAW,YAAY,WAAY;GAClC,KAAK,GAAG,UAAU,WAAY;IAC7B,IAAI,KAAK,gBAAgB,UAAU;KAClC,IAAa,UAAU,oBAAoB,KAAK,qBAAqB,IAAI;KACzE,SAAS,eAAe;IACzB;IACA,KAAK,WAAW,UAAU,OAAO,sBAAsB,2BAA2B;IAClF,IAAa,UAAU,WAAW,KAAK,sBAAsB,IAAI;IACjE,KAAK,cAAc;GACpB,CAAC;GAED,IAAI,KAAK,QAAQ,mBAAmB;IACnC,KAAK,oBAAoB,IAAI,kBAAkB;IAC/C,KAAK,WAAW,KAAK,iBAAiB;GACvC;EACD,CAAC;CACF;AACD"}
@@ -40,6 +40,8 @@ import { I18n } from "../core/I18n.js";
40
40
  * `maplair-control-layers-group-name` element, and each entry shows only its label.
41
41
  * Events like `baselayerchange` still carry the full `name`. When combined with
42
42
  * `sortLayers`, the entries are sorted first and grouped afterwards.
43
+ * @property {string} [title] The title of the toggle button and the accessible label
44
+ * of the layers list, the translation of `'Layers'` by default.
43
45
  * @property {string|HTMLElement} [toggleContent] The content of the toggle button of a
44
46
  * collapsed control instead of the layers icon: HTML (e.g. an icon or a character) or an
45
47
  * element. String content is rendered as HTML; do not pass untrusted input.
@@ -124,6 +126,7 @@ var LayersControl = class LayersControl extends Control {
124
126
  collapsed: true,
125
127
  inline: false,
126
128
  groupBy: void 0,
129
+ title: void 0,
127
130
  toggleContent: void 0,
128
131
  collapseDelay: 0,
129
132
  position: "topright",
@@ -150,6 +153,7 @@ var LayersControl = class LayersControl extends Control {
150
153
  this._lastZIndex = 0;
151
154
  this._handlingClick = false;
152
155
  this._preventClick = false;
156
+ this._needsUpdate = false;
153
157
  for (const [name, layer] of Object.entries(baseLayers ?? {})) this._addLayer(layer, name);
154
158
  for (const [name, layer] of Object.entries(overlays ?? {})) this._addLayer(layer, name, true);
155
159
  this.callInitHooks(LayersControl);
@@ -235,6 +239,7 @@ var LayersControl = class LayersControl extends Control {
235
239
  * @returns {this}
236
240
  */
237
241
  selectLayer(layer) {
242
+ if (this._needsUpdate) this._update(true);
238
243
  const input = this._layerControlInputs.find((input) => input._layer === layer);
239
244
  if (input && !input.checked) {
240
245
  input.checked = true;
@@ -249,6 +254,7 @@ var LayersControl = class LayersControl extends Control {
249
254
  expand() {
250
255
  clearTimeout(this._collapseDelayTimeout);
251
256
  this._container.classList.add("maplair-control-layers-expanded");
257
+ if (this._needsUpdate) this._update();
252
258
  this._section.style.height = "";
253
259
  const acceptableHeight = this._map.getSize().y - (this._container.offsetTop + 50);
254
260
  if (acceptableHeight < this._section.clientHeight) {
@@ -264,19 +270,40 @@ var LayersControl = class LayersControl extends Control {
264
270
  */
265
271
  collapse() {
266
272
  if (this.options.inline) return this;
273
+ clearTimeout(this._collapseDelayTimeout);
267
274
  if (this.options.collapseDelay > 0) this._collapseDelayTimeout = setTimeout(() => {
268
275
  this._container.classList.remove("maplair-control-layers-expanded");
269
276
  }, this.options.collapseDelay);
270
277
  else this._container.classList.remove("maplair-control-layers-expanded");
271
278
  return this;
272
279
  }
280
+ _getTitle() {
281
+ return this.options.title ?? I18n.translate("Layers");
282
+ }
273
283
  _initLayout() {
274
284
  const className = "maplair-control-layers", container = this._container = create("div", className), collapsed = this._isCollapsible();
275
285
  if (this.options.inline) container.classList.add(`${className}-inline`);
276
286
  disableClickPropagation(container);
277
287
  disableScrollPropagation(container);
278
288
  const section = this._section = create("fieldset", `${className}-list`);
279
- section.setAttribute("aria-label", I18n.translate("Layers"));
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
+ }
280
307
  if (collapsed) {
281
308
  this._map.on("click", this.collapse, this);
282
309
  on(container, {
@@ -285,30 +312,19 @@ var LayersControl = class LayersControl extends Control {
285
312
  if (e.pointerType !== "touch") this.collapse();
286
313
  }
287
314
  }, this);
288
- }
289
- if (!this.options.inline) {
290
- const link = this._layersLink = create("button", `${className}-toggle`, container);
291
- link.type = "button";
292
- link.title = I18n.translate("Layers");
293
- link.setAttribute("aria-label", I18n.translate("Layers"));
294
- const { toggleContent } = this.options;
295
- if (typeof toggleContent === "string") link.innerHTML = toggleContent;
296
- else if (toggleContent) link.replaceChildren(toggleContent);
297
- on(link, {
298
- keydown(e) {
299
- if (e.code === "Enter") this._expandSafely();
300
- },
301
- 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();
302
320
  e.preventDefault();
303
- this._expandSafely();
304
321
  }
305
- }, this);
306
- }
307
- if (!collapsed) this.expand();
322
+ });
323
+ } else this.expand();
308
324
  this._baseLayersList = create("div", `${className}-base`, section);
309
325
  this._separator = create("div", `${className}-separator`, section);
310
326
  this._overlaysList = create("div", `${className}-overlays`, section);
311
- container.appendChild(section);
327
+ container.append(section);
312
328
  }
313
329
  _addLayer(layer, name, overlay) {
314
330
  if (this._map) layer.on("add remove", this._onLayerChange, this);
@@ -324,8 +340,13 @@ var LayersControl = class LayersControl extends Control {
324
340
  }
325
341
  this._expandIfNotCollapsed();
326
342
  }
327
- _update() {
343
+ _update(force) {
328
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;
329
350
  this._baseLayersList.replaceChildren();
330
351
  this._overlaysList.replaceChildren();
331
352
  this._layerControlInputs = [];
@@ -342,6 +363,7 @@ var LayersControl = class LayersControl extends Control {
342
363
  this._baseLayersList.style.display = baseLayersPresent ? "" : "none";
343
364
  }
344
365
  this._separator.style.display = overlaysPresent && baseLayersPresent ? "" : "none";
366
+ this._checkDisabledLayers();
345
367
  return this;
346
368
  }
347
369
  _onLayerChange(e) {
@@ -367,12 +389,10 @@ var LayersControl = class LayersControl extends Control {
367
389
  const name = document.createElement("span");
368
390
  name.innerHTML = ` ${group ? group.label : obj.name}`;
369
391
  const holder = document.createElement("span");
370
- label.appendChild(holder);
371
- holder.appendChild(input);
372
- holder.appendChild(name);
392
+ label.append(holder);
393
+ holder.append(input, name);
373
394
  const list = obj.overlay ? this._overlaysList : this._baseLayersList;
374
- (group ? this._getGroupContainer(list, group.group) : list).appendChild(label);
375
- this._checkDisabledLayers();
395
+ (group ? this._getGroupContainer(list, group.group) : list).append(label);
376
396
  return label;
377
397
  }
378
398
  /**
@@ -412,7 +432,6 @@ var LayersControl = class LayersControl extends Control {
412
432
  this._update();
413
433
  break;
414
434
  }
415
- this._refocusOnMap(e);
416
435
  }
417
436
  _checkDisabledLayers() {
418
437
  const inputs = this._layerControlInputs, zoom = this._map.getZoom();
@@ -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|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\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_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', I18n.translate('Layers'));\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 = I18n.translate('Layers');\n\t\t\tlink.setAttribute('aria-label', I18n.translate('Layers'));\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.appendChild(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.appendChild(holder);\n\t\tholder.appendChild(input);\n\t\tholder.appendChild(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.appendChild(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\n\t\tthis._refocusOnMap(e);\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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;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"}
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,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;EAEb,KAAK,sBAAsB,CAAC;EAC5B,KAAK,UAAU,CAAC;EAChB,KAAK,cAAc;EACnB,KAAK,iBAAiB;EACtB,KAAK,gBAAgB;EACrB,KAAK,eAAe;EAEpB,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,cAAc,CAAC,CAAC,GAC1D,KAAK,UAAU,OAAO,IAAI;EAG3B,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,YAAY,CAAC,CAAC,GACxD,KAAK,UAAU,OAAO,MAAM,IAAI;EAGjC,KAAK,cAAc,aAAa;CACjC;;;;;;CAOA,MAAM,KAAK;EACV,KAAK,YAAY;EACjB,KAAK,QAAQ;EAEb,KAAK,OAAO;EACZ,IAAI,GAAG,WAAW,KAAK,sBAAsB,IAAI;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62,7 +62,6 @@ var RotateControl = class RotateControl extends Control {
62
62
  disableClickPropagation(button);
63
63
  on(button, "click", stop);
64
64
  on(button, "click", this._resetNorth, this);
65
- on(button, "click", this._refocusOnMap, this);
66
65
  this._update();
67
66
  map.on("rotate", this._update, this);
68
67
  return container;
@@ -1 +1 @@
1
- {"version":3,"file":"RotateControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/RotateControl.js"],"sourcesContent":["import {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\nconst compass = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path d=\"M8 1 11 8H5z\" fill=\"#d22\"/><path d=\"M8 15 5 8h6z\" fill=\"#999\"/></svg>';\n\n/**\n * Options of `RotateControl`.\n * @typedef {object} RotateControlOptions\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 * @extends ControlOptions\n */\n\n/**\n * Map options of `RotateControl`.\n * @typedef {object} RotateControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [rotateControl=false] Whether a [rotate control](#rotatecontrol)\n * is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `RotateControl`.\n * @typedef {object} RotateControlMapProperties\n * @lends MaplairMap\n * @property {RotateControl} rotateControl The default rotate control (only available if\n * the [`rotateControl` option](#map-rotatecontrol) was `true` when creating the map).\n */\n\n/**\n * A compass showing the rotation of the map (see `MaplairMap.setBearing()`); clicking it\n * rotates the map back to north up. It is put on the map if you set its\n * [`rotateControl` option](#map-rotatecontrol) to `true`.\n *\n * @example\n * ```js\n * new RotateControl({position: 'topright'}).addTo(map);\n * ```\n */\nexport class RotateControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft'\n\t};\n\n\t/**\n\t * Creates a rotate control.\n\t * @param {...RotateControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(RotateControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst container = DomUtil.create('div', 'maplair-control-rotate maplair-bar'),\n\t\tbutton = this._button = DomUtil.create('button', 'maplair-control-rotate-button', container),\n\t\ttitle = I18n.translate('Reset north');\n\t\tbutton.type = 'button';\n\t\tbutton.title = title;\n\t\tbutton.setAttribute('aria-label', title);\n\t\tbutton.innerHTML = compass;\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._resetNorth, this);\n\t\tDomEvent.on(button, 'click', this._refocusOnMap, this);\n\n\t\tthis._update();\n\t\tmap.on('rotate', this._update, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('rotate', this._update, this);\n\t}\n\n\t_resetNorth(e) {\n\t\tthis._map._setUserEvent(e);\n\t\tthis._map.setBearing(0, {animate: true});\n\t}\n\n\t_update() {\n\t\t// the needle points north\n\t\tthis._button.firstChild.style.transform = `rotate(${-this._map.getBearing()}deg)`;\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\trotateControl: false\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.rotateControl) {\n\t\t\t\tthis.rotateControl = new RotateControl();\n\t\t\t\tthis.addControl(this.rotateControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;AAOA,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqChB,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB,EACvB,UAAU,UACX;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,aAAa;CACjC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYA,OAAe,OAAO,oCAAoC,GAC5E,SAAS,KAAK,UAAUA,OAAe,UAAU,iCAAiC,SAAS,GAC3F,QAAQ,KAAK,UAAU,aAAa;EACpC,OAAO,OAAO;EACd,OAAO,QAAQ;EACf,OAAO,aAAa,cAAc,KAAK;EACvC,OAAO,YAAY;EAEnB,wBAAiC,MAAM;EACvC,GAAY,QAAQ,SAASC,IAAa;EAC1C,GAAY,QAAQ,SAAS,KAAK,aAAa,IAAI;EACnD,GAAY,QAAQ,SAAS,KAAK,eAAe,IAAI;EAErD,KAAK,QAAQ;EACb,IAAI,GAAG,UAAU,KAAK,SAAS,IAAI;EAEnC,OAAO;CACR;;;;;CAMA,SAAS,KAAK;EACb,IAAI,IAAI,UAAU,KAAK,SAAS,IAAI;CACrC;CAEA,YAAY,GAAG;EACd,KAAK,KAAK,cAAc,CAAC;EACzB,KAAK,KAAK,WAAW,GAAG,EAAC,SAAS,KAAI,CAAC;CACxC;CAEA,UAAU;EAET,KAAK,QAAQ,WAAW,MAAM,YAAY,UAAU,CAAC,KAAK,KAAK,WAAW,EAAE;CAC7E;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,eAAe,MAChB,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,eAAe;IAC/B,KAAK,gBAAgB,IAAI,cAAc;IACvC,KAAK,WAAW,KAAK,aAAa;GACnC;EACD,CAAC;CACF;AACD"}
1
+ {"version":3,"file":"RotateControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/RotateControl.js"],"sourcesContent":["import {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\nconst compass = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\"><path d=\"M8 1 11 8H5z\" fill=\"#d22\"/><path d=\"M8 15 5 8h6z\" fill=\"#999\"/></svg>';\n\n/**\n * Options of `RotateControl`.\n * @typedef {object} RotateControlOptions\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 * @extends ControlOptions\n */\n\n/**\n * Map options of `RotateControl`.\n * @typedef {object} RotateControlMapOptions\n * @lends MaplairMapOptions\n * @property {boolean} [rotateControl=false] Whether a [rotate control](#rotatecontrol)\n * is added to the map by default.\n */\n\n/**\n * Properties of `MaplairMap` set by `RotateControl`.\n * @typedef {object} RotateControlMapProperties\n * @lends MaplairMap\n * @property {RotateControl} rotateControl The default rotate control (only available if\n * the [`rotateControl` option](#map-rotatecontrol) was `true` when creating the map).\n */\n\n/**\n * A compass showing the rotation of the map (see `MaplairMap.setBearing()`); clicking it\n * rotates the map back to north up. It is put on the map if you set its\n * [`rotateControl` option](#map-rotatecontrol) to `true`.\n *\n * @example\n * ```js\n * new RotateControl({position: 'topright'}).addTo(map);\n * ```\n */\nexport class RotateControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft'\n\t};\n\n\t/**\n\t * Creates a rotate control.\n\t * @param {...RotateControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(RotateControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t * @returns {HTMLElement}\n\t */\n\tonAdd(map) {\n\t\tconst container = DomUtil.create('div', 'maplair-control-rotate maplair-bar'),\n\t\tbutton = this._button = DomUtil.create('button', 'maplair-control-rotate-button', container),\n\t\ttitle = I18n.translate('Reset north');\n\t\tbutton.type = 'button';\n\t\tbutton.title = title;\n\t\tbutton.setAttribute('aria-label', title);\n\t\tbutton.innerHTML = compass;\n\n\t\tDomEvent.disableClickPropagation(button);\n\t\tDomEvent.on(button, 'click', DomEvent.stop);\n\t\tDomEvent.on(button, 'click', this._resetNorth, this);\n\n\t\tthis._update();\n\t\tmap.on('rotate', this._update, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off('rotate', this._update, this);\n\t}\n\n\t_resetNorth(e) {\n\t\tthis._map._setUserEvent(e);\n\t\tthis._map.setBearing(0, {animate: true});\n\t}\n\n\t_update() {\n\t\t// the needle points north\n\t\tthis._button.firstChild.style.transform = `rotate(${-this._map.getBearing()}deg)`;\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\trotateControl: false\n\t\t});\n\n\t\tMaplairMap.addInitHook(function () {\n\t\t\tif (this.options.rotateControl) {\n\t\t\t\tthis.rotateControl = new RotateControl();\n\t\t\t\tthis.addControl(this.rotateControl);\n\t\t\t}\n\t\t});\n\t}\n}\n"],"mappings":";;;;;;;AAOA,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqChB,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB,EACvB,UAAU,UACX;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,aAAa;CACjC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYA,OAAe,OAAO,oCAAoC,GAC5E,SAAS,KAAK,UAAUA,OAAe,UAAU,iCAAiC,SAAS,GAC3F,QAAQ,KAAK,UAAU,aAAa;EACpC,OAAO,OAAO;EACd,OAAO,QAAQ;EACf,OAAO,aAAa,cAAc,KAAK;EACvC,OAAO,YAAY;EAEnB,wBAAiC,MAAM;EACvC,GAAY,QAAQ,SAASC,IAAa;EAC1C,GAAY,QAAQ,SAAS,KAAK,aAAa,IAAI;EAEnD,KAAK,QAAQ;EACb,IAAI,GAAG,UAAU,KAAK,SAAS,IAAI;EAEnC,OAAO;CACR;;;;;CAMA,SAAS,KAAK;EACb,IAAI,IAAI,UAAU,KAAK,SAAS,IAAI;CACrC;CAEA,YAAY,GAAG;EACd,KAAK,KAAK,cAAc,CAAC;EACzB,KAAK,KAAK,WAAW,GAAG,EAAC,SAAS,KAAI,CAAC;CACxC;CAEA,UAAU;EAET,KAAK,QAAQ,WAAW,MAAM,YAAY,UAAU,CAAC,KAAK,KAAK,WAAW,EAAE;CAC7E;;;;;;CAOA,OAAO,SAAS,YAAY;EAC3B,WAAW,aAAa,EACvB,eAAe,MAChB,CAAC;EAED,WAAW,YAAY,WAAY;GAClC,IAAI,KAAK,QAAQ,eAAe;IAC/B,KAAK,gBAAgB,IAAI,cAAc;IACvC,KAAK,WAAW,KAAK,aAAa;GACnC;EACD,CAAC;CACF;AACD"}
@@ -53,16 +53,15 @@ var ScaleControl = class ScaleControl extends Control {
53
53
  onAdd(map) {
54
54
  const className = "maplair-control-scale", container = create("div", className), options = this.options;
55
55
  this._addScales(options, `${className}-line`, container);
56
- map.on(options.updateWhenIdle ? "moveend" : "move", this._update, this);
57
56
  map.whenReady(this._update, this);
58
57
  return container;
59
58
  }
60
59
  /**
61
60
  * @internal
62
- * @param {MaplairMap} map
61
+ * @returns {Record<string, Function>}
63
62
  */
64
- onRemove(map) {
65
- map.off(this.options.updateWhenIdle ? "moveend" : "move", this._update, this);
63
+ getEvents() {
64
+ return { [this.options.updateWhenIdle ? "moveend" : "move"]: this._update };
66
65
  }
67
66
  _addScales(options, className, container) {
68
67
  if (options.metric) this._mScale = create("div", className, container);
@@ -95,13 +94,13 @@ var ScaleControl = class ScaleControl extends Control {
95
94
  }
96
95
  _updateScale(scale, text, ratio) {
97
96
  scale.style.width = `${Math.round(this.options.maxWidth * ratio)}px`;
98
- scale.innerHTML = text;
97
+ scale.textContent = text;
99
98
  }
100
99
  _getRoundNum(num) {
101
- const pow10 = 10 ** (`${Math.floor(num)}`.length - 1);
102
- 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;
103
102
  d = d >= 10 ? 10 : d >= 5 ? 5 : d >= 3 ? 3 : d >= 2 ? 2 : 1;
104
- return pow10 * d;
103
+ return exponent < 0 ? d / 10 ** -exponent : d * 10 ** exponent;
105
104
  }
106
105
  };
107
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.on(options.updateWhenIdle ? 'moveend' : 'move', this._update, this);\n\t\tmap.whenReady(this._update, this);\n\n\t\treturn container;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tmap.off(this.options.updateWhenIdle ? 'moveend' : 'move', this._update, this);\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.innerHTML = text;\n\t}\n\n\t_getRoundNum(num) {\n\t\tconst pow10 = 10 ** ((`${Math.floor(num)}`).length - 1);\n\t\tlet d = num / pow10;\n\n\t\td = d >= 10 ? 10 :\n\t\t\td >= 5 ? 5 :\n\t\t\td >= 3 ? 3 :\n\t\t\td >= 2 ? 2 : 1;\n\n\t\treturn pow10 * d;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,eAAb,MAAa,qBAAqB,QAAQ;CAEzC,OAAO,iBAAiB;EACvB,UAAU;EACV,UAAU;EACV,QAAQ;EACR,UAAU;EACV,gBAAgB;CACjB;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,YAAY;CAChC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAY,yBAClB,YAAYA,OAAe,OAAO,SAAS,GAC3C,UAAU,KAAK;EAEf,KAAK,WAAW,SAAS,GAAG,UAAU,QAAQ,SAAS;EAEvD,IAAI,GAAG,QAAQ,iBAAiB,YAAY,QAAQ,KAAK,SAAS,IAAI;EACtE,IAAI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AU,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,YAAY;CACnB;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\t\t\td >= 2 ? 2 : 1;\n\n\t\t// dividing by a power of ten keeps 0.3 exact, where 3 * 0.1 gives 0.30000000000000004\n\t\treturn exponent < 0 ? d / 10 ** -exponent : d * 10 ** exponent;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAiCA,IAAa,eAAb,MAAa,qBAAqB,QAAQ;CAEzC,OAAO,iBAAiB;EACvB,UAAU;EACV,UAAU;EACV,QAAQ;EACR,UAAU;EACV,gBAAgB;CACjB;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,YAAY;CAChC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAY,yBAClB,YAAYA,OAAe,OAAO,SAAS,GAC3C,UAAU,KAAK;EAEf,KAAK,WAAW,SAAS,GAAG,UAAU,QAAQ,SAAS;EAEvD,IAAI,UAAU,KA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AC,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"}
@@ -65,8 +65,9 @@ var SideBySideControl = class SideBySideControl extends Control {
65
65
  this.remove();
66
66
  this._map = map;
67
67
  this._container = this.onAdd(map);
68
- map._container.appendChild(this._container);
69
- map.on("unload", this.remove, this);
68
+ map._container.append(this._container);
69
+ this._mapEvents = { unload: this.remove };
70
+ map.on(this._mapEvents, this);
70
71
  return this;
71
72
  }
72
73
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"SideBySideControl.js","names":["DomUtil.create","DomUtil.getPosition"],"sources":["../../../src/control/SideBySideControl.js"],"sourcesContent":["import {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/** @import {Layer} from '../layer/Layer.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `SideBySideControl`.\n * @typedef {object} SideBySideControlOptions\n * @property {number} [ratio=0.5] The initial position of the divider, from `0` (left) to\n * `1` (right).\n * @extends ControlOptions\n */\n\n/**\n * The event object of `dividermove`.\n * @typedef {object} DividerMoveEvent\n * @property {number} ratio The position of the divider, from `0` (left) to `1` (right).\n * @property {number} x The position of the divider in container pixels.\n * @extends MaplairEvent\n */\n\n/**\n * Compares layers side by side: a vertical divider across the map shows the\n * \"left\" layers on its left and the \"right\" layers on its right side. The divider\n * can be dragged, or moved with the arrow keys. Works with layers having a\n * container or element of their own, e.g. tile layers and image overlays.\n *\n * Inspired by the [leaflet-side-by-side](https://github.com/digidem/leaflet-side-by-side) plugin.\n *\n * @example\n * ```js\n * const before = new TileLayer('https://…/2020/{z}/{x}/{y}.png').addTo(map);\n * const after = new TileLayer('https://…/2025/{z}/{x}/{y}.png').addTo(map);\n * new SideBySideControl(before, after).addTo(map);\n * ```\n *\n * @fires MaplairMap#dividermove {DividerMoveEvent} Fired when the divider of a\n * `SideBySideControl` moves.\n */\nexport class SideBySideControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tratio: 0.5\n\t};\n\n\t/**\n\t * Creates a side-by-side control for the given layers (which have to be added to the\n\t * map separately).\n\t * @param {Layer|Layer[]} [leftLayers]\n\t * @param {Layer|Layer[]} [rightLayers]\n\t * @param {SideBySideControlOptions} [options]\n\t */\n\tconstructor(leftLayers, rightLayers, options) {\n\t\tsuper(options);\n\t\tthis._leftLayers = [leftLayers ?? []].flat();\n\t\tthis._rightLayers = [rightLayers ?? []].flat();\n\t\tthis._ratio = this.options.ratio;\n\t\tthis.callInitHooks(SideBySideControl);\n\t}\n\n\t/**\n\t * Adds the control to the given map. The divider spans the map instead of being in\n\t * a corner.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tthis.remove();\n\t\tthis._map = map;\n\t\tthis._container = this.onAdd(map);\n\t\tmap._container.appendChild(this._container);\n\t\tmap.on('unload', this.remove, this);\n\t\treturn this;\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 divider = DomUtil.create('div', 'maplair-sidebyside-divider'),\n\t\tlabel = I18n.translate('Divider between the compared layers');\n\t\tdivider.tabIndex = 0;\n\t\tdivider.setAttribute('role', 'slider');\n\t\tdivider.setAttribute('aria-label', label);\n\t\tdivider.setAttribute('aria-valuemin', 0);\n\t\tdivider.setAttribute('aria-valuemax', 100);\n\n\t\tDomEvent.disableClickPropagation(divider);\n\t\tDomEvent.on(divider, 'pointerdown', this._onPointerDown, this);\n\t\tDomEvent.on(divider, 'keydown', this._onKeyDown, this);\n\n\t\tmap.on('move zoom viewreset resize rotate layeradd', this._update, this);\n\t\tthis._container = divider;\n\t\tthis._update();\n\t\treturn divider;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tthis._onPointerUp();\n\t\tmap.off('move zoom viewreset resize rotate layeradd', this._update, this);\n\t\tfor (const layer of [...this._leftLayers, ...this._rightLayers]) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (el) {\n\t\t\t\tel.style.clipPath = '';\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets the layers shown on the left side of the divider.\n\t * @param {Layer|Layer[]} layers\n\t * @returns {this}\n\t */\n\tsetLeftLayers(layers) {\n\t\tthis._clear(this._leftLayers);\n\t\tthis._leftLayers = [layers].flat();\n\t\treturn this._update();\n\t}\n\n\t/**\n\t * Sets the layers shown on the right side of the divider.\n\t * @param {Layer|Layer[]} layers\n\t * @returns {this}\n\t */\n\tsetRightLayers(layers) {\n\t\tthis._clear(this._rightLayers);\n\t\tthis._rightLayers = [layers].flat();\n\t\treturn this._update();\n\t}\n\n\t/**\n\t * Returns the position of the divider, from `0` (left) to `1` (right).\n\t * @returns {number}\n\t */\n\tgetRatio() {\n\t\treturn this._ratio;\n\t}\n\n\t/**\n\t * Moves the divider, from `0` (left) to `1` (right).\n\t * @param {number} ratio\n\t * @returns {this}\n\t */\n\tsetRatio(ratio) {\n\t\tthis._ratio = Math.min(1, Math.max(0, ratio));\n\t\tthis._update();\n\t\tthis._map?.fire('dividermove', {ratio: this._ratio, x: this._x});\n\t\treturn this;\n\t}\n\n\t_clear(layers) {\n\t\tfor (const layer of layers) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (el) {\n\t\t\t\tel.style.clipPath = '';\n\t\t\t}\n\t\t}\n\t}\n\n\t_update() {\n\t\tconst map = this._map;\n\t\tif (!map?._loaded || !this._container) { return this; }\n\n\t\tconst size = map.getSize(),\n\t\tx = this._x = Math.round(size.x * this._ratio);\n\t\tthis._container.style.left = `${x}px`;\n\t\tthis._container.setAttribute('aria-valuenow', Math.round(this._ratio * 100));\n\n\t\tthis._clip(this._leftLayers, 0, x, size.y);\n\t\tthis._clip(this._rightLayers, x, size.x, size.y);\n\t\treturn this;\n\t}\n\n\t// Clips the layers to the area from `x1` to `x2` (in container pixels)\n\t_clip(layers, x1, x2, height) {\n\t\tconst map = this._map;\n\t\tfor (const layer of layers) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (!el || !map.hasLayer(layer)) { continue; }\n\t\t\t// relative to the element, which is positioned in layer pixels\n\t\t\tconst offset = DomUtil.getPosition(el),\n\t\t\tcorners = [[x1, 0], [x2, 0], [x2, height], [x1, height]].map((p) => {\n\t\t\t\tconst point = map.containerPointToLayerPoint(p).subtract(offset);\n\t\t\t\treturn `${point.x}px ${point.y}px`;\n\t\t\t});\n\t\t\tel.style.clipPath = `polygon(${corners.join(', ')})`;\n\t\t}\n\t}\n\n\t_onPointerDown(e) {\n\t\tDomEvent.stop(e);\n\t\tthis._container.focus({preventScroll: true});\n\t\t// on the document, to follow the pointer outside of the divider\n\t\tDomEvent.on(document, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(document, 'pointerup pointercancel', this._onPointerUp, this);\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst rect = this._map._container.getBoundingClientRect();\n\t\tthis.setRatio((e.clientX - rect.left) / rect.width);\n\t}\n\n\t_onPointerUp() {\n\t\tDomEvent.off(document, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(document, 'pointerup pointercancel', this._onPointerUp, this);\n\t}\n\n\t_onKeyDown(e) {\n\t\tconst step = e.shiftKey ? 0.01 : 0.05;\n\t\tif (e.key === 'ArrowLeft') {\n\t\t\tthis.setRatio(this._ratio - step);\n\t\t} else if (e.key === 'ArrowRight') {\n\t\t\tthis.setRatio(this._ratio + step);\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\t\t// not panning the map\n\t\tDomEvent.stop(e);\n\t}\n}\n\nfunction getElement(layer) {\n\treturn layer.getContainer?.() ?? layer.getElement?.();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,oBAAb,MAAa,0BAA0B,QAAQ;CAE9C,OAAO,iBAAiB,EACvB,OAAO,GACR;;;;;;;;CASA,YAAY,YAAY,aAAa,SAAS;EAC7C,MAAM,OAAO;EACb,KAAK,cAAc,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,KAAK;EAC3C,KAAK,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,KAAK;EAC7C,KAAK,SAAS,KAAK,QAAQ;EAC3B,KAAK,cAAc,iBAAiB;CACrC;;;;;;;CAQA,MAAM,KAAK;EACV,KAAK,OAAO;EACZ,KAAK,OAAO;EACZ,KAAK,aAAa,KAAK,MAAM,GAAG;EAChC,IAAI,WAAW,YAAY,KAAK,UAAU;EAC1C,IAAI,GAAG,UAAU,KAAK,QAAQ,IAAI;EAClC,OAAO;CACR;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,UAAUA,OAAe,OAAO,4BAA4B,GAClE,QAAQ,KAAK,UAAU,qCAAqC;EAC5D,QAAQ,WAAW;EACnB,QAAQ,aAAa,QAAQ,QAAQ;EACrC,QAAQ,aAAa,cAAc,KAAK;EACxC,QAAQ,aAAa,iBAAiB,CAAC;EACvC,QAAQ,aAAa,iBAAiB,GAAG;EAEzC,wBAAiC,OAAO;EACxC,GAAY,SAAS,eAAe,KAAK,gBAAgB,IAAI;EAC7D,GAAY,SAAS,WAAW,KAA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AAS,KAAK,SAAS,IAAI;OAC1B,IAAI,EAAE,QAAQ,cACpB,KAAK,SAAS,KAAK,SAAS,IAAI;OAEhC;EAGD,KAAc,CAAC;CAChB;AACD;AAEA,SAAS,WAAW,OAAO;CAC1B,OAAO,MAAM,eAAe,KAAK,MAAM,aAAa;AACrD"}
1
+ {"version":3,"file":"SideBySideControl.js","names":["DomUtil.create","DomUtil.getPosition"],"sources":["../../../src/control/SideBySideControl.js"],"sourcesContent":["import {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/** @import {Layer} from '../layer/Layer.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n\n/**\n * Options of `SideBySideControl`.\n * @typedef {object} SideBySideControlOptions\n * @property {number} [ratio=0.5] The initial position of the divider, from `0` (left) to\n * `1` (right).\n * @extends ControlOptions\n */\n\n/**\n * The event object of `dividermove`.\n * @typedef {object} DividerMoveEvent\n * @property {number} ratio The position of the divider, from `0` (left) to `1` (right).\n * @property {number} x The position of the divider in container pixels.\n * @extends MaplairEvent\n */\n\n/**\n * Compares layers side by side: a vertical divider across the map shows the\n * \"left\" layers on its left and the \"right\" layers on its right side. The divider\n * can be dragged, or moved with the arrow keys. Works with layers having a\n * container or element of their own, e.g. tile layers and image overlays.\n *\n * Inspired by the [leaflet-side-by-side](https://github.com/digidem/leaflet-side-by-side) plugin.\n *\n * @example\n * ```js\n * const before = new TileLayer('https://…/2020/{z}/{x}/{y}.png').addTo(map);\n * const after = new TileLayer('https://…/2025/{z}/{x}/{y}.png').addTo(map);\n * new SideBySideControl(before, after).addTo(map);\n * ```\n *\n * @fires MaplairMap#dividermove {DividerMoveEvent} Fired when the divider of a\n * `SideBySideControl` moves.\n */\nexport class SideBySideControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tratio: 0.5\n\t};\n\n\t/**\n\t * Creates a side-by-side control for the given layers (which have to be added to the\n\t * map separately).\n\t * @param {Layer|Layer[]} [leftLayers]\n\t * @param {Layer|Layer[]} [rightLayers]\n\t * @param {SideBySideControlOptions} [options]\n\t */\n\tconstructor(leftLayers, rightLayers, options) {\n\t\tsuper(options);\n\t\tthis._leftLayers = [leftLayers ?? []].flat();\n\t\tthis._rightLayers = [rightLayers ?? []].flat();\n\t\tthis._ratio = this.options.ratio;\n\t\tthis.callInitHooks(SideBySideControl);\n\t}\n\n\t/**\n\t * Adds the control to the given map. The divider spans the map instead of being in\n\t * a corner.\n\t * @param {MaplairMap} map\n\t * @returns {this}\n\t */\n\taddTo(map) {\n\t\tthis.remove();\n\t\tthis._map = map;\n\t\tthis._container = this.onAdd(map);\n\t\tmap._container.append(this._container);\n\t\t// removed by `remove()` of `Control`\n\t\tthis._mapEvents = {unload: this.remove};\n\t\tmap.on(this._mapEvents, this);\n\t\treturn this;\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 divider = DomUtil.create('div', 'maplair-sidebyside-divider'),\n\t\tlabel = I18n.translate('Divider between the compared layers');\n\t\tdivider.tabIndex = 0;\n\t\tdivider.setAttribute('role', 'slider');\n\t\tdivider.setAttribute('aria-label', label);\n\t\tdivider.setAttribute('aria-valuemin', 0);\n\t\tdivider.setAttribute('aria-valuemax', 100);\n\n\t\tDomEvent.disableClickPropagation(divider);\n\t\tDomEvent.on(divider, 'pointerdown', this._onPointerDown, this);\n\t\tDomEvent.on(divider, 'keydown', this._onKeyDown, this);\n\n\t\tmap.on('move zoom viewreset resize rotate layeradd', this._update, this);\n\t\tthis._container = divider;\n\t\tthis._update();\n\t\treturn divider;\n\t}\n\n\t/**\n\t * @internal\n\t * @param {MaplairMap} map\n\t */\n\tonRemove(map) {\n\t\tthis._onPointerUp();\n\t\tmap.off('move zoom viewreset resize rotate layeradd', this._update, this);\n\t\tfor (const layer of [...this._leftLayers, ...this._rightLayers]) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (el) {\n\t\t\t\tel.style.clipPath = '';\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Sets the layers shown on the left side of the divider.\n\t * @param {Layer|Layer[]} layers\n\t * @returns {this}\n\t */\n\tsetLeftLayers(layers) {\n\t\tthis._clear(this._leftLayers);\n\t\tthis._leftLayers = [layers].flat();\n\t\treturn this._update();\n\t}\n\n\t/**\n\t * Sets the layers shown on the right side of the divider.\n\t * @param {Layer|Layer[]} layers\n\t * @returns {this}\n\t */\n\tsetRightLayers(layers) {\n\t\tthis._clear(this._rightLayers);\n\t\tthis._rightLayers = [layers].flat();\n\t\treturn this._update();\n\t}\n\n\t/**\n\t * Returns the position of the divider, from `0` (left) to `1` (right).\n\t * @returns {number}\n\t */\n\tgetRatio() {\n\t\treturn this._ratio;\n\t}\n\n\t/**\n\t * Moves the divider, from `0` (left) to `1` (right).\n\t * @param {number} ratio\n\t * @returns {this}\n\t */\n\tsetRatio(ratio) {\n\t\tthis._ratio = Math.min(1, Math.max(0, ratio));\n\t\tthis._update();\n\t\tthis._map?.fire('dividermove', {ratio: this._ratio, x: this._x});\n\t\treturn this;\n\t}\n\n\t_clear(layers) {\n\t\tfor (const layer of layers) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (el) {\n\t\t\t\tel.style.clipPath = '';\n\t\t\t}\n\t\t}\n\t}\n\n\t_update() {\n\t\tconst map = this._map;\n\t\tif (!map?._loaded || !this._container) { return this; }\n\n\t\tconst size = map.getSize(),\n\t\tx = this._x = Math.round(size.x * this._ratio);\n\t\tthis._container.style.left = `${x}px`;\n\t\tthis._container.setAttribute('aria-valuenow', Math.round(this._ratio * 100));\n\n\t\tthis._clip(this._leftLayers, 0, x, size.y);\n\t\tthis._clip(this._rightLayers, x, size.x, size.y);\n\t\treturn this;\n\t}\n\n\t// Clips the layers to the area from `x1` to `x2` (in container pixels)\n\t_clip(layers, x1, x2, height) {\n\t\tconst map = this._map;\n\t\tfor (const layer of layers) {\n\t\t\tconst el = getElement(layer);\n\t\t\tif (!el || !map.hasLayer(layer)) { continue; }\n\t\t\t// relative to the element, which is positioned in layer pixels\n\t\t\tconst offset = DomUtil.getPosition(el),\n\t\t\tcorners = [[x1, 0], [x2, 0], [x2, height], [x1, height]].map((p) => {\n\t\t\t\tconst point = map.containerPointToLayerPoint(p).subtract(offset);\n\t\t\t\treturn `${point.x}px ${point.y}px`;\n\t\t\t});\n\t\t\tel.style.clipPath = `polygon(${corners.join(', ')})`;\n\t\t}\n\t}\n\n\t_onPointerDown(e) {\n\t\tDomEvent.stop(e);\n\t\tthis._container.focus({preventScroll: true});\n\t\t// on the document, to follow the pointer outside of the divider\n\t\tDomEvent.on(document, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.on(document, 'pointerup pointercancel', this._onPointerUp, this);\n\t}\n\n\t_onPointerMove(e) {\n\t\tconst rect = this._map._container.getBoundingClientRect();\n\t\tthis.setRatio((e.clientX - rect.left) / rect.width);\n\t}\n\n\t_onPointerUp() {\n\t\tDomEvent.off(document, 'pointermove', this._onPointerMove, this);\n\t\tDomEvent.off(document, 'pointerup pointercancel', this._onPointerUp, this);\n\t}\n\n\t_onKeyDown(e) {\n\t\tconst step = e.shiftKey ? 0.01 : 0.05;\n\t\tif (e.key === 'ArrowLeft') {\n\t\t\tthis.setRatio(this._ratio - step);\n\t\t} else if (e.key === 'ArrowRight') {\n\t\t\tthis.setRatio(this._ratio + step);\n\t\t} else {\n\t\t\treturn;\n\t\t}\n\t\t// not panning the map\n\t\tDomEvent.stop(e);\n\t}\n}\n\nfunction getElement(layer) {\n\treturn layer.getContainer?.() ?? layer.getElement?.();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,oBAAb,MAAa,0BAA0B,QAAQ;CAE9C,OAAO,iBAAiB,EACvB,OAAO,GACR;;;;;;;;CASA,YAAY,YAAY,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G,CAAC,IAAI,CAAC;IAAG,CAAC,IAAI,MAAM;IAAG,CAAC,IAAI,MAAM;GAAC,CAAC,CAAC,KAAK,MAAM;IACnE,MAAM,QAAQ,IAAI,2BAA2B,CAAC,CAAC,CAAC,SAAS,MAAM;IAC/D,OAAO,GAAG,MAAM,EAAE,KAAK,MAAM,EAAE;GAChC,CAAC;GACD,GAAG,MAAM,WAAW,WAAW,QAAQ,KAAK,IAAI,EAAE;EACnD;CACD;CAEA,eAAe,GAAG;EACjB,KAAc,CAAC;EACf,KAAK,WAAW,MAAM,EAAC,eAAe,KAAI,CAAC;EAE3C,GAAY,UAAU,eAAe,KAAK,gBAAgB,IAAI;EAC9D,GAAY,UAAU,2BAA2B,KAAK,cAAc,IAAI;CACzE;CAEA,eAAe,GAAG;EACjB,MAAM,OAAO,KAAK,KAAK,WAAW,sBAAsB;EACxD,KAAK,UAAU,EAAE,UAAU,KAAK,QAAQ,KAAK,KAAK;CACnD;CAEA,eAAe;EACd,IAAa,UAAU,eAAe,KAAK,gBAAgB,IAAI;EAC/D,IAAa,UAAU,2BAA2B,KAAK,cAAc,IAAI;CAC1E;CAEA,WAAW,GAAG;EACb,MAAM,OAAO,EAAE,WAAW,MAAO;EACjC,IAAI,EAAE,QAAQ,aACb,KAAK,SAAS,KAAK,SAAS,IAAI;OAC1B,IAAI,EAAE,QAAQ,cACpB,KAAK,SAAS,KAAK,SAAS,IAAI;OAEhC;EAGD,KAAc,CAAC;CAChB;AACD;AAEA,SAAS,WAAW,OAAO;CAC1B,OAAO,MAAM,eAAe,KAAK,MAAM,aAAa;AACrD"}
@@ -11,10 +11,10 @@ import { I18n } from "../core/I18n.js";
11
11
  * @property {string} [position='topleft'] The position of the control (one of the map
12
12
  * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or
13
13
  * `'bottomright'`.
14
- * @property {string} [zoomInText='<span aria-hidden="true">+</span>'] The text set on
15
- * the 'zoom in' button.
16
- * @property {string} [zoomOutText='<span aria-hidden="true">&#x2212;</span>'] The text
17
- * set on the 'zoom out' button.
14
+ * @property {string} [zoomInText] The HTML of the 'zoom in' button, a plus sign drawn
15
+ * in SVG by default.
16
+ * @property {string} [zoomOutText] The HTML of the 'zoom out' button, a minus sign
17
+ * drawn in SVG by default.
18
18
  * @extends ControlOptions
19
19
  */
20
20
  /**
@@ -38,8 +38,8 @@ import { I18n } from "../core/I18n.js";
38
38
  var ZoomControl = class ZoomControl extends Control {
39
39
  static defaultOptions = {
40
40
  position: "topleft",
41
- zoomInText: "<span aria-hidden=\"true\">+</span>",
42
- zoomOutText: "<span aria-hidden=\"true\">&#x2212;</span>"
41
+ zoomInText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12M6 0v12\"/></svg>",
42
+ zoomOutText: "<svg width=\"12\" height=\"12\" stroke=\"currentColor\" stroke-width=\"2\" aria-hidden=\"true\"><path d=\"M0 6h12\"/></svg>"
43
43
  };
44
44
  /**
45
45
  * Creates a zoom control.
@@ -51,23 +51,24 @@ var ZoomControl = class ZoomControl extends Control {
51
51
  }
52
52
  /**
53
53
  * @internal
54
- * @param {MaplairMap} map
55
54
  * @returns {HTMLElement}
56
55
  */
57
- onAdd(map) {
56
+ onAdd() {
58
57
  const zoomName = "maplair-control-zoom", container = create("div", `${zoomName} maplair-bar`), options = this.options;
59
58
  this._zoomInButton = this._createButton(options.zoomInText, I18n.translate("Zoom in"), `${zoomName}-in`, container, (e) => this._zoom(e, 1));
60
59
  this._zoomOutButton = this._createButton(options.zoomOutText, I18n.translate("Zoom out"), `${zoomName}-out`, container, (e) => this._zoom(e, -1));
61
60
  this._updateDisabled();
62
- map.on("zoomend zoomlevelschange", this._updateDisabled, this);
63
61
  return container;
64
62
  }
65
63
  /**
66
64
  * @internal
67
- * @param {MaplairMap} map
65
+ * @returns {Record<string, Function>}
68
66
  */
69
- onRemove(map) {
70
- map.off("zoomend zoomlevelschange", this._updateDisabled, this);
67
+ getEvents() {
68
+ return {
69
+ zoomend: this._updateDisabled,
70
+ zoomlevelschange: this._updateDisabled
71
+ };
71
72
  }
72
73
  /**
73
74
  * Disables the zoom buttons.
@@ -104,12 +105,12 @@ var ZoomControl = class ZoomControl extends Control {
104
105
  on(link, "click", (e) => {
105
106
  stop(e);
106
107
  fn.call(this, e);
107
- this._refocusOnMap(e);
108
108
  });
109
109
  return link;
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);