maplair 4.0.0 → 4.1.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 (270) hide show
  1. package/CHANGELOG.md +118 -0
  2. package/dist/esm/Maplair.js +14 -14
  3. package/dist/esm/control/AttributionControl.js +24 -14
  4. package/dist/esm/control/AttributionControl.js.map +1 -1
  5. package/dist/esm/control/ButtonControl.js +9 -11
  6. package/dist/esm/control/ButtonControl.js.map +1 -1
  7. package/dist/esm/control/ContextMenu.js +1 -3
  8. package/dist/esm/control/ContextMenu.js.map +1 -1
  9. package/dist/esm/control/Control.js +9 -16
  10. package/dist/esm/control/Control.js.map +1 -1
  11. package/dist/esm/control/FullscreenControl.js +5 -7
  12. package/dist/esm/control/FullscreenControl.js.map +1 -1
  13. package/dist/esm/control/LayersControl.js +144 -35
  14. package/dist/esm/control/LayersControl.js.map +1 -1
  15. package/dist/esm/control/LegendControl.js +7 -9
  16. package/dist/esm/control/LegendControl.js.map +1 -1
  17. package/dist/esm/control/MiniMapControl.js +14 -16
  18. package/dist/esm/control/MiniMapControl.js.map +1 -1
  19. package/dist/esm/control/RotateControl.js +1 -3
  20. package/dist/esm/control/RotateControl.js.map +1 -1
  21. package/dist/esm/control/ScaleControl.js +7 -9
  22. package/dist/esm/control/ScaleControl.js.map +1 -1
  23. package/dist/esm/control/SearchControl.js +99 -17
  24. package/dist/esm/control/SearchControl.js.map +1 -1
  25. package/dist/esm/control/SideBySideControl.js +1 -3
  26. package/dist/esm/control/SideBySideControl.js.map +1 -1
  27. package/dist/esm/control/TextControl.js +5 -7
  28. package/dist/esm/control/TextControl.js.map +1 -1
  29. package/dist/esm/control/TimeControl.js +408 -0
  30. package/dist/esm/control/TimeControl.js.map +1 -0
  31. package/dist/esm/control/ZoomControl.js +5 -7
  32. package/dist/esm/control/ZoomControl.js.map +1 -1
  33. package/dist/esm/core/Class.js +28 -37
  34. package/dist/esm/core/Class.js.map +1 -1
  35. package/dist/esm/core/Events.js +21 -8
  36. package/dist/esm/core/Events.js.map +1 -1
  37. package/dist/esm/core/Handler.js +13 -11
  38. package/dist/esm/core/Handler.js.map +1 -1
  39. package/dist/esm/core/Util.js +13 -1
  40. package/dist/esm/core/Util.js.map +1 -1
  41. package/dist/esm/dom/DomEvent.DoubleTap.js +25 -22
  42. package/dist/esm/dom/DomEvent.DoubleTap.js.map +1 -1
  43. package/dist/esm/dom/DomEvent.PointerEvents.js +2 -16
  44. package/dist/esm/dom/DomEvent.PointerEvents.js.map +1 -1
  45. package/dist/esm/dom/DomEvent.js +8 -42
  46. package/dist/esm/dom/DomEvent.js.map +1 -1
  47. package/dist/esm/dom/DomUtil.js +14 -68
  48. package/dist/esm/dom/DomUtil.js.map +1 -1
  49. package/dist/esm/dom/Draggable.js +17 -18
  50. package/dist/esm/dom/Draggable.js.map +1 -1
  51. package/dist/esm/dom/PosAnimation.js +3 -25
  52. package/dist/esm/dom/PosAnimation.js.map +1 -1
  53. package/dist/esm/geo/LatLng.js +15 -5
  54. package/dist/esm/geo/LatLng.js.map +1 -1
  55. package/dist/esm/geo/crs/EPSG3395.js +1 -1
  56. package/dist/esm/geo/crs/EPSG3395.js.map +1 -1
  57. package/dist/esm/geo/crs/EPSG3857.js +1 -1
  58. package/dist/esm/geo/crs/EPSG3857.js.map +1 -1
  59. package/dist/esm/geo/crs/EPSG4326.js +1 -1
  60. package/dist/esm/geo/crs/EPSG4326.js.map +1 -1
  61. package/dist/esm/geo/crs/EarthCRS.js +2 -2
  62. package/dist/esm/geo/crs/EarthCRS.js.map +1 -1
  63. package/dist/esm/geo/crs/SimpleCRS.js +1 -1
  64. package/dist/esm/geo/crs/SimpleCRS.js.map +1 -1
  65. package/dist/esm/geo/projection/Projection.LonLat.js +1 -1
  66. package/dist/esm/geo/projection/Projection.LonLat.js.map +1 -1
  67. package/dist/esm/geo/projection/Projection.Mercator.js +1 -1
  68. package/dist/esm/geo/projection/Projection.Mercator.js.map +1 -1
  69. package/dist/esm/geo/projection/Projection.SphericalMercator.js +1 -1
  70. package/dist/esm/geo/projection/Projection.SphericalMercator.js.map +1 -1
  71. package/dist/esm/geometry/LineUtil.js +36 -30
  72. package/dist/esm/geometry/LineUtil.js.map +1 -1
  73. package/dist/esm/geometry/PolyUtil.js +8 -27
  74. package/dist/esm/geometry/PolyUtil.js.map +1 -1
  75. package/dist/esm/layer/BlanketOverlay.js +6 -8
  76. package/dist/esm/layer/BlanketOverlay.js.map +1 -1
  77. package/dist/esm/layer/DivOverlay.js +15 -20
  78. package/dist/esm/layer/DivOverlay.js.map +1 -1
  79. package/dist/esm/layer/GeoJSON.js +9 -145
  80. package/dist/esm/layer/GeoJSON.js.map +1 -1
  81. package/dist/esm/layer/GeoJSONUtil.js +75 -0
  82. package/dist/esm/layer/GeoJSONUtil.js.map +1 -0
  83. package/dist/esm/layer/HeatLayer.js +15 -17
  84. package/dist/esm/layer/HeatLayer.js.map +1 -1
  85. package/dist/esm/layer/ImageOverlay.js +20 -26
  86. package/dist/esm/layer/ImageOverlay.js.map +1 -1
  87. package/dist/esm/layer/Layer.js +8 -10
  88. package/dist/esm/layer/Layer.js.map +1 -1
  89. package/dist/esm/layer/LayerGroup.js +51 -0
  90. package/dist/esm/layer/LayerGroup.js.map +1 -1
  91. package/dist/esm/layer/Popup.js +26 -42
  92. package/dist/esm/layer/Popup.js.map +1 -1
  93. package/dist/esm/layer/SVGOverlay.js +2 -5
  94. package/dist/esm/layer/SVGOverlay.js.map +1 -1
  95. package/dist/esm/layer/Tooltip.js +15 -17
  96. package/dist/esm/layer/Tooltip.js.map +1 -1
  97. package/dist/esm/layer/VideoOverlay.js +12 -15
  98. package/dist/esm/layer/VideoOverlay.js.map +1 -1
  99. package/dist/esm/layer/marker/DefaultIcon.js +15 -48
  100. package/dist/esm/layer/marker/DefaultIcon.js.map +1 -1
  101. package/dist/esm/layer/marker/DivIcon.js +7 -9
  102. package/dist/esm/layer/marker/DivIcon.js.map +1 -1
  103. package/dist/esm/layer/marker/Icon.js +7 -10
  104. package/dist/esm/layer/marker/Icon.js.map +1 -1
  105. package/dist/esm/layer/marker/Marker.Drag.js +1 -1
  106. package/dist/esm/layer/marker/Marker.Drag.js.map +1 -1
  107. package/dist/esm/layer/marker/Marker.Move.js +1 -2
  108. package/dist/esm/layer/marker/Marker.Move.js.map +1 -1
  109. package/dist/esm/layer/marker/Marker.js +61 -33
  110. package/dist/esm/layer/marker/Marker.js.map +1 -1
  111. package/dist/esm/layer/marker/MarkerClusterGroup.js +302 -0
  112. package/dist/esm/layer/marker/MarkerClusterGroup.js.map +1 -0
  113. package/dist/esm/layer/marker/SvgIcon.js +6 -8
  114. package/dist/esm/layer/marker/SvgIcon.js.map +1 -1
  115. package/dist/esm/layer/tile/GridLayer.js +85 -97
  116. package/dist/esm/layer/tile/GridLayer.js.map +1 -1
  117. package/dist/esm/layer/tile/TileLayer.js +28 -36
  118. package/dist/esm/layer/tile/TileLayer.js.map +1 -1
  119. package/dist/esm/layer/tile/WMSTileLayer.js +28 -23
  120. package/dist/esm/layer/tile/WMSTileLayer.js.map +1 -1
  121. package/dist/esm/layer/vector/Canvas.js +1 -3
  122. package/dist/esm/layer/vector/Canvas.js.map +1 -1
  123. package/dist/esm/layer/vector/Circle.js +2 -2
  124. package/dist/esm/layer/vector/Circle.js.map +1 -1
  125. package/dist/esm/layer/vector/CircleMarker.js +17 -7
  126. package/dist/esm/layer/vector/CircleMarker.js.map +1 -1
  127. package/dist/esm/layer/vector/Path.DashAnimation.js +2 -3
  128. package/dist/esm/layer/vector/Path.DashAnimation.js.map +1 -1
  129. package/dist/esm/layer/vector/Path.js +27 -20
  130. package/dist/esm/layer/vector/Path.js.map +1 -1
  131. package/dist/esm/layer/vector/Polygon.js +20 -4
  132. package/dist/esm/layer/vector/Polygon.js.map +1 -1
  133. package/dist/esm/layer/vector/Polyline.Decorations.js +2 -2
  134. package/dist/esm/layer/vector/Polyline.js +23 -7
  135. package/dist/esm/layer/vector/Polyline.js.map +1 -1
  136. package/dist/esm/layer/vector/Renderer.getRenderer.js +14 -13
  137. package/dist/esm/layer/vector/Renderer.getRenderer.js.map +1 -1
  138. package/dist/esm/layer/vector/SVG.js +5 -5
  139. package/dist/esm/layer/vector/SVG.js.map +1 -1
  140. package/dist/esm/map/Map.Rotation.js +10 -6
  141. package/dist/esm/map/Map.Rotation.js.map +1 -1
  142. package/dist/esm/map/Map.js +116 -110
  143. package/dist/esm/map/Map.js.map +1 -1
  144. package/dist/esm/map/handler/BoxZoomHandler.js +5 -7
  145. package/dist/esm/map/handler/BoxZoomHandler.js.map +1 -1
  146. package/dist/esm/map/handler/DisplaceHandler.js +6 -8
  147. package/dist/esm/map/handler/DisplaceHandler.js.map +1 -1
  148. package/dist/esm/map/handler/DragHandler.js +19 -19
  149. package/dist/esm/map/handler/DragHandler.js.map +1 -1
  150. package/dist/esm/map/handler/KeyboardHandler.js +35 -35
  151. package/dist/esm/map/handler/KeyboardHandler.js.map +1 -1
  152. package/dist/esm/map/handler/PinchZoomHandler.js +12 -3
  153. package/dist/esm/map/handler/PinchZoomHandler.js.map +1 -1
  154. package/dist/esm/map/handler/ScrollWheelZoomHandler.js +3 -4
  155. package/dist/esm/map/handler/ScrollWheelZoomHandler.js.map +1 -1
  156. package/dist/esm/map/handler/TapHoldHandler.js +12 -5
  157. package/dist/esm/map/handler/TapHoldHandler.js.map +1 -1
  158. package/dist/esm/package.js +1 -1
  159. package/dist/maplair-global-src.js +8009 -7369
  160. package/dist/maplair-global-src.js.map +1 -1
  161. package/dist/maplair-global.js +2 -2
  162. package/dist/maplair-global.js.map +1 -1
  163. package/dist/maplair-src.js +10040 -9381
  164. package/dist/maplair-src.js.map +1 -1
  165. package/dist/maplair.css +148 -98
  166. package/dist/maplair.js +2 -2
  167. package/dist/maplair.js.map +1 -1
  168. package/i18n/cs.json +6 -0
  169. package/i18n/de.json +6 -0
  170. package/i18n/en.json +6 -0
  171. package/i18n/es.json +6 -0
  172. package/i18n/fr.json +6 -0
  173. package/i18n/hu.json +6 -0
  174. package/i18n/it.json +6 -0
  175. package/i18n/rm.json +6 -0
  176. package/i18n/sk.json +6 -0
  177. package/i18n/sl.json +6 -0
  178. package/package.json +9 -11
  179. package/src/control/AttributionControl.js +25 -18
  180. package/src/control/ButtonControl.js +9 -11
  181. package/src/control/ContextMenu.js +3 -5
  182. package/src/control/Control.js +9 -19
  183. package/src/control/FullscreenControl.js +5 -7
  184. package/src/control/LayersControl.js +159 -36
  185. package/src/control/LegendControl.js +7 -9
  186. package/src/control/MiniMapControl.js +9 -11
  187. package/src/control/RotateControl.js +3 -5
  188. package/src/control/ScaleControl.js +7 -9
  189. package/src/control/SearchControl.js +102 -19
  190. package/src/control/SideBySideControl.js +3 -5
  191. package/src/control/TextControl.js +5 -7
  192. package/src/control/TimeControl.js +471 -0
  193. package/src/control/ZoomControl.js +5 -7
  194. package/src/control/index.js +1 -0
  195. package/src/core/Class.js +35 -34
  196. package/src/core/Events.js +22 -3
  197. package/src/core/Handler.js +14 -12
  198. package/src/core/Util.js +19 -1
  199. package/src/core/index.js +0 -1
  200. package/src/dom/DomEvent.DoubleTap.js +18 -10
  201. package/src/dom/DomEvent.PointerEvents.js +3 -26
  202. package/src/dom/DomEvent.js +8 -66
  203. package/src/dom/DomUtil.js +22 -78
  204. package/src/dom/Draggable.js +27 -22
  205. package/src/dom/PosAnimation.js +3 -25
  206. package/src/dom/index.js +0 -1
  207. package/src/geo/LatLng.js +20 -3
  208. package/src/geo/crs/EPSG3395.js +1 -1
  209. package/src/geo/crs/EPSG3857.js +1 -1
  210. package/src/geo/crs/EPSG4326.js +1 -1
  211. package/src/geo/crs/EarthCRS.js +2 -8
  212. package/src/geo/crs/SimpleCRS.js +1 -1
  213. package/src/geo/projection/Projection.LonLat.js +1 -1
  214. package/src/geo/projection/Projection.Mercator.js +1 -1
  215. package/src/geo/projection/Projection.SphericalMercator.js +1 -1
  216. package/src/geometry/LineUtil.js +47 -48
  217. package/src/geometry/PolyUtil.js +14 -43
  218. package/src/layer/BlanketOverlay.js +6 -10
  219. package/src/layer/DivOverlay.js +15 -26
  220. package/src/layer/GeoJSON.js +7 -205
  221. package/src/layer/GeoJSONUtil.js +85 -0
  222. package/src/layer/HeatLayer.js +9 -11
  223. package/src/layer/ImageOverlay.js +19 -30
  224. package/src/layer/Layer.js +8 -10
  225. package/src/layer/LayerGroup.js +71 -0
  226. package/src/layer/Popup.js +28 -43
  227. package/src/layer/SVGOverlay.js +1 -5
  228. package/src/layer/Tooltip.js +15 -19
  229. package/src/layer/VideoOverlay.js +12 -15
  230. package/src/layer/marker/DefaultIcon.js +15 -61
  231. package/src/layer/marker/DivIcon.js +9 -11
  232. package/src/layer/marker/Icon.js +7 -10
  233. package/src/layer/marker/Marker.Drag.js +1 -1
  234. package/src/layer/marker/Marker.Move.js +1 -2
  235. package/src/layer/marker/Marker.js +81 -39
  236. package/src/layer/marker/MarkerClusterGroup.js +370 -0
  237. package/src/layer/marker/SvgIcon.js +7 -9
  238. package/src/layer/marker/index.js +1 -0
  239. package/src/layer/tile/GridLayer.js +103 -133
  240. package/src/layer/tile/TileLayer.js +35 -43
  241. package/src/layer/tile/WMSTileLayer.js +26 -24
  242. package/src/layer/vector/Canvas.js +3 -5
  243. package/src/layer/vector/Circle.js +5 -2
  244. package/src/layer/vector/CircleMarker.js +17 -6
  245. package/src/layer/vector/Path.DashAnimation.js +1 -2
  246. package/src/layer/vector/Path.js +30 -21
  247. package/src/layer/vector/Polygon.js +28 -5
  248. package/src/layer/vector/Polyline.js +25 -6
  249. package/src/layer/vector/Renderer.getRenderer.js +17 -17
  250. package/src/layer/vector/SVG.js +5 -5
  251. package/src/map/Map.Rotation.js +12 -4
  252. package/src/map/Map.js +142 -133
  253. package/src/map/handler/BoxZoomHandler.js +9 -8
  254. package/src/map/handler/DisplaceHandler.js +6 -8
  255. package/src/map/handler/DragHandler.js +25 -28
  256. package/src/map/handler/KeyboardHandler.js +42 -48
  257. package/src/map/handler/PinchZoomHandler.js +16 -5
  258. package/src/map/handler/ScrollWheelZoomHandler.js +6 -4
  259. package/src/map/handler/TapHoldHandler.js +15 -4
  260. package/src/map/index.js +1 -1
  261. package/src/maplair.css +148 -98
  262. package/dist/esm/core/Browser.js +0 -100
  263. package/dist/esm/core/Browser.js.map +0 -1
  264. package/dist/images/layers.svg +0 -1
  265. package/dist/images/marker-icon.svg +0 -1
  266. package/dist/images/marker-shadow.svg +0 -1
  267. package/src/core/Browser.js +0 -110
  268. package/src/images/layers.svg +0 -1
  269. package/src/images/marker-icon.svg +0 -1
  270. package/src/images/marker-shadow.svg +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"MiniMapControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/MiniMapControl.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';\nimport {MaplairMap} from '../map/Map.js';\nimport {Polygon} from '../layer/vector/Polygon.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMapOptions} from '../map/Map.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {PathOptions} from '../layer/vector/Path.js' */\n\n/**\n * Options of `MiniMapControl`.\n * @typedef {object} MiniMapControlOptions\n * @property {string} [position='bottomright'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [width=150] The width of the overview map in pixels.\n * @property {number} [height=150] The height of the overview map in pixels.\n * @property {number} [zoomOffset=-5] The zoom level of the overview map relative to the\n * map.\n * @property {boolean} [collapsed=false] Whether the overview map is collapsed initially.\n * @property {PathOptions} [rectangleOptions={color: '#ff7800', weight: 1, fillOpacity: 0.2}]\n * The style of the rectangle showing the view of the map.\n * @property {MaplairMapOptions} [mapOptions={}] Further options of the overview map.\n * @extends ControlOptions\n */\n\n/**\n * An overview map in a corner of the map, showing the view of the map as a\n * rectangle (or rotated rectangle on a rotated map) at a smaller zoom level.\n * Dragging the overview map pans the map, clicking it centers the map there, and\n * a button collapses it.\n *\n * Inspired by the [Leaflet-MiniMap](https://github.com/Norkart/Leaflet-MiniMap) plugin.\n *\n * @example\n * ```js\n * // a layer of its own, a layer can only be on one map\n * const overviewLayer = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png');\n * new MiniMapControl(overviewLayer).addTo(map);\n * ```\n */\nexport class MiniMapControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'bottomright',\n\t\t\twidth: 150,\n\t\t\theight: 150,\n\t\t\tzoomOffset: -5,\n\t\t\tcollapsed: false,\n\t\t\trectangleOptions: {color: '#ff7800', weight: 1, fillOpacity: 0.2},\n\t\t\tmapOptions: {}\n\t\t});\n\t}\n\n\t/**\n\t * Creates an overview map control showing `layer` (which must not be on another map).\n\t * @param {Layer} layer\n\t * @param {MiniMapControlOptions} [options]\n\t */\n\tconstructor(layer, options) {\n\t\tsuper(options);\n\t\tthis._layer = layer;\n\t\tthis.callInitHooks(MiniMapControl);\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// the size of the overview map is known once it is on the page\n\t\tthis._miniMap.invalidateSize({pan: false});\n\t\tthis._update();\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 container = DomUtil.create('div', 'maplair-control-minimap'),\n\t\tmapContainer = DomUtil.create('div', 'maplair-control-minimap-map', container);\n\t\tcontainer.style.width = `${this.options.width}px`;\n\t\tcontainer.style.height = `${this.options.height}px`;\n\n\t\tconst toggle = this._toggle = DomUtil.create('button', 'maplair-control-minimap-toggle', container);\n\t\ttoggle.type = 'button';\n\t\tDomEvent.on(toggle, 'click', DomEvent.stop);\n\t\tDomEvent.on(toggle, 'click', this.toggle, this);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\n\t\tthis._miniMap = new MaplairMap(mapContainer, {\n\t\t\tattributionControl: false,\n\t\t\tzoomControl: false,\n\t\t\tdoubleClickZoom: false,\n\t\t\tscrollWheelZoom: false,\n\t\t\tboxZoom: false,\n\t\t\tkeyboard: false,\n\t\t\tpinchZoom: false,\n\t\t\ttapDragZoom: false,\n\t\t\tariaLabel: I18n.translate('Overview map'),\n\t\t\t...this.options.mapOptions,\n\t\t\tlayers: [this._layer]\n\t\t});\n\t\t// not part of the keyboard navigation, the map has its own\n\t\tmapContainer.tabIndex = -1;\n\n\t\tthis._rectangle = new Polygon([], {interactive: false, ...this.options.rectangleOptions});\n\n\t\tthis._miniMap.on({\n\t\t\tmoveend: this._onMiniMapMoveEnd,\n\t\t\tclick: this._onMiniMapClick\n\t\t}, this);\n\t\tmap.on('move zoom rotate resize', this._update, this);\n\t\tmap.whenReady(this._update, this);\n\n\t\tthis._setCollapsed(this.options.collapsed);\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('move zoom rotate resize', this._update, this);\n\t\tthis._miniMap.remove();\n\t\tthis._miniMap = null;\n\t}\n\n\t/**\n\t * Returns the overview map.\n\t * @returns {MaplairMap}\n\t */\n\tgetMiniMap() {\n\t\treturn this._miniMap;\n\t}\n\n\t/**\n\t * Collapses or expands the overview map.\n\t * @returns {this}\n\t */\n\ttoggle() {\n\t\treturn this._setCollapsed(!this._collapsed);\n\t}\n\n\t_setCollapsed(collapsed) {\n\t\tthis._collapsed = collapsed;\n\t\tconst container = this._container ?? this._toggle.parentNode,\n\t\ttitle = collapsed ? I18n.translate('Show the overview map') : I18n.translate('Hide the overview map');\n\t\tcontainer.classList.toggle('maplair-control-minimap-collapsed', collapsed);\n\t\tthis._toggle.title = title;\n\t\tthis._toggle.setAttribute('aria-label', title);\n\t\tthis._toggle.setAttribute('aria-expanded', !collapsed);\n\t\tif (!collapsed) {\n\t\t\tthis._miniMap.invalidateSize();\n\t\t\tthis._update();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Follows the view of the map\n\t_update() {\n\t\tconst map = this._map, miniMap = this._miniMap;\n\t\tif (!map?._loaded || !miniMap || this._collapsed) { return; }\n\n\t\tconst zoom = Math.max(miniMap.getMinZoom(), Math.min(map.getZoom() + this.options.zoomOffset, miniMap.getMaxZoom()));\n\t\tminiMap.setView(map.getCenter(), zoom, {animate: false});\n\n\t\tconst size = map.getSize();\n\t\tthis._rectangle.setLatLngs([[0, 0], [size.x, 0], size, [0, size.y]].map(p => map.containerPointToLatLng(p)));\n\t\tif (!miniMap.hasLayer(this._rectangle)) {\n\t\t\tthis._rectangle.addTo(miniMap);\n\t\t}\n\t}\n\n\t// Dragging the overview map pans the map (only when moved by the user)\n\t_onMiniMapMoveEnd(e) {\n\t\tif (e.originalEvent) {\n\t\t\tthis._map.panTo(this._miniMap.getCenter());\n\t\t}\n\t}\n\n\t_onMiniMapClick(e) {\n\t\tif (!this._miniMap.dragging?.moved()) {\n\t\t\tthis._map.panTo(e.latlng);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;CAE3C;EACC,KAAK,kBAAkB;GACtB,UAAU;GACV,OAAO;GACP,QAAQ;GACR,YAAY;GACZ,WAAW;GACX,kBAAkB;IAAC,OAAO;IAAW,QAAQ;IAAG,aAAa;GAAG;GAChE,YAAY,CAAC;EACd,CAAC;CACF;;;;;;CAOA,YAAY,OAAO,SAAS;EAC3B,MAAM,OAAO;EACb,KAAK,SAAS;EACd,KAAK,cAAc,cAAc;CAClC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,MAAM,GAAG;EAEf,KAAK,SAAS,eAAe,EAAC,KAAK,MAAK,CAAC;EACzC,KAAK,QAAQ;EACb,OAAO;CACR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AAK,cAAc,KAAK,QAAQ,YAClD,QAAQ,YAAY,KAAK,UAAU,uBAAuB,IAAI,KAAK,UAAU,uBAAuB;EACpG,UAAU,UAAU,OAAO,qCAAqC,SAAS;EACzE,KAAK,QAAQ,QAAQ;EACrB,KAAK,QAAQ,aAAa,cAAc,KAAK;EAC7C,KAAK,QAAQ,aAAa,iBAAiB,CAAC,SAAS;EACrD,IAAI,CAAC,WAAW;GACf,KAAK,SAAS,eAAe;GAC7B,KAAK,QAAQ;EACd;EACA,OAAO;CACR;CAGA,UAAU;EACT,MAAM,MAAM,KAAK,MAAM,UAAU,KAAK;EACtC,IAAI,CAAC,KAAK,WAAW,CAAC,WAAW,KAAK,YAAc;EAEpD,MAAM,OAAO,KAAK,IAAI,QAAQ,WAAW,GAAG,KAAK,IAAI,IAAI,QAAQ,IAAI,KAAK,QAAQ,YAAY,QAAQ,WAAW,CAAC,CAAC;EACnH,QAAQ,QAAQ,IAAI,UAAU,GAAG,MAAM,EAAC,SAAS,MAAK,CAAC;EAEvD,MAAM,OAAO,IAAI,QAAQ;EACzB,KAAK,WAAW,WAAW;GAAC,CAAC,GAAG,CAAC;GAAG,CAAC,KAAK,GAAG,CAAC;GAAG;GAAM,CAAC,GAAG,KAAK,CAAC;EAAC,CAAC,CAAC,KAAI,MAAK,IAAI,uBAAuB,CAAC,CAAC,CAAC;EAC3G,IAAI,CAAC,QAAQ,SAAS,KAAK,UAAU,GACpC,KAAK,WAAW,MAAM,OAAO;CAE/B;CAGA,kBAAkB,GAAG;EACpB,IAAI,EAAE,eACL,KAAK,KAAK,MAAM,KAAK,SAAS,UAAU,CAAC;CAE3C;CAEA,gBAAgB,GAAG;EAClB,IAAI,CAAC,KAAK,SAAS,UAAU,MAAM,GAClC,KAAK,KAAK,MAAM,EAAE,MAAM;CAE1B;AACD"}
1
+ {"version":3,"file":"MiniMapControl.js","names":["DomUtil.create","DomEvent.stop"],"sources":["../../../src/control/MiniMapControl.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';\nimport {MaplairMap} from '../map/Map.js';\nimport {Polygon} from '../layer/vector/Polygon.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMapOptions} from '../map/Map.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {PathOptions} from '../layer/vector/Path.js' */\n\n/**\n * Options of `MiniMapControl`.\n * @typedef {object} MiniMapControlOptions\n * @property {string} [position='bottomright'] The position of the control (one of the map\n * corners). Possible values are `'topleft'`, `'topright'`, `'bottomleft'` or\n * `'bottomright'`.\n * @property {number} [width=150] The width of the overview map in pixels.\n * @property {number} [height=150] The height of the overview map in pixels.\n * @property {number} [zoomOffset=-5] The zoom level of the overview map relative to the\n * map.\n * @property {boolean} [collapsed=false] Whether the overview map is collapsed initially.\n * @property {PathOptions} [rectangleOptions={color: '#ff7800', weight: 1, fillOpacity: 0.2}]\n * The style of the rectangle showing the view of the map.\n * @property {MaplairMapOptions} [mapOptions={}] Further options of the overview map.\n * @extends ControlOptions\n */\n\n/**\n * An overview map in a corner of the map, showing the view of the map as a\n * rectangle (or rotated rectangle on a rotated map) at a smaller zoom level.\n * Dragging the overview map pans the map, clicking it centers the map there, and\n * a button collapses it.\n *\n * Inspired by the [Leaflet-MiniMap](https://github.com/Norkart/Leaflet-MiniMap) plugin.\n *\n * @example\n * ```js\n * // a layer of its own, a layer can only be on one map\n * const overviewLayer = new TileLayer('https://tile.openstreetmap.org/{z}/{x}/{y}.png');\n * new MiniMapControl(overviewLayer).addTo(map);\n * ```\n */\nexport class MiniMapControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'bottomright',\n\t\twidth: 150,\n\t\theight: 150,\n\t\tzoomOffset: -5,\n\t\tcollapsed: false,\n\t\trectangleOptions: {color: '#ff7800', weight: 1, fillOpacity: 0.2},\n\t\tmapOptions: {}\n\t};\n\n\t/**\n\t * Creates an overview map control showing `layer` (which must not be on another map).\n\t * @param {Layer} layer\n\t * @param {MiniMapControlOptions} [options]\n\t */\n\tconstructor(layer, options) {\n\t\tsuper(options);\n\t\tthis._layer = layer;\n\t\tthis.callInitHooks(MiniMapControl);\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// the size of the overview map is known once it is on the page\n\t\tthis._miniMap.invalidateSize({pan: false});\n\t\tthis._update();\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 container = DomUtil.create('div', 'maplair-control-minimap'),\n\t\tmapContainer = DomUtil.create('div', 'maplair-control-minimap-map', container);\n\t\tcontainer.style.width = `${this.options.width}px`;\n\t\tcontainer.style.height = `${this.options.height}px`;\n\n\t\tconst toggle = this._toggle = DomUtil.create('button', 'maplair-control-minimap-toggle', container);\n\t\ttoggle.type = 'button';\n\t\tDomEvent.on(toggle, 'click', DomEvent.stop);\n\t\tDomEvent.on(toggle, 'click', this.toggle, this);\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\n\t\tthis._miniMap = new MaplairMap(mapContainer, {\n\t\t\tattributionControl: false,\n\t\t\tzoomControl: false,\n\t\t\tdoubleClickZoom: false,\n\t\t\tscrollWheelZoom: false,\n\t\t\tboxZoom: false,\n\t\t\tkeyboard: false,\n\t\t\tpinchZoom: false,\n\t\t\ttapDragZoom: false,\n\t\t\tariaLabel: I18n.translate('Overview map'),\n\t\t\t...this.options.mapOptions,\n\t\t\tlayers: [this._layer]\n\t\t});\n\t\t// not part of the keyboard navigation, the map has its own\n\t\tmapContainer.tabIndex = -1;\n\n\t\tthis._rectangle = new Polygon([], {interactive: false, ...this.options.rectangleOptions});\n\n\t\tthis._miniMap.on({\n\t\t\tmoveend: this._onMiniMapMoveEnd,\n\t\t\tclick: this._onMiniMapClick\n\t\t}, this);\n\t\tmap.on('move zoom rotate resize', this._update, this);\n\t\tmap.whenReady(this._update, this);\n\n\t\tthis._setCollapsed(this.options.collapsed);\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('move zoom rotate resize', this._update, this);\n\t\tthis._miniMap.remove();\n\t\tthis._miniMap = null;\n\t}\n\n\t/**\n\t * Returns the overview map.\n\t * @returns {MaplairMap}\n\t */\n\tgetMiniMap() {\n\t\treturn this._miniMap;\n\t}\n\n\t/**\n\t * Collapses or expands the overview map.\n\t * @returns {this}\n\t */\n\ttoggle() {\n\t\treturn this._setCollapsed(!this._collapsed);\n\t}\n\n\t_setCollapsed(collapsed) {\n\t\tthis._collapsed = collapsed;\n\t\tconst container = this._container ?? this._toggle.parentNode,\n\t\ttitle = collapsed ? I18n.translate('Show the overview map') : I18n.translate('Hide the overview map');\n\t\tcontainer.classList.toggle('maplair-control-minimap-collapsed', collapsed);\n\t\tthis._toggle.title = title;\n\t\tthis._toggle.setAttribute('aria-label', title);\n\t\tthis._toggle.setAttribute('aria-expanded', !collapsed);\n\t\tif (!collapsed) {\n\t\t\tthis._miniMap.invalidateSize();\n\t\t\tthis._update();\n\t\t}\n\t\treturn this;\n\t}\n\n\t// Follows the view of the map\n\t_update() {\n\t\tconst map = this._map, miniMap = this._miniMap;\n\t\tif (!map?._loaded || !miniMap || this._collapsed) { return; }\n\n\t\tconst zoom = Math.max(miniMap.getMinZoom(), Math.min(map.getZoom() + this.options.zoomOffset, miniMap.getMaxZoom()));\n\t\tminiMap.setView(map.getCenter(), zoom, {animate: false});\n\n\t\tconst size = map.getSize();\n\t\tthis._rectangle.setLatLngs([[0, 0], [size.x, 0], size, [0, size.y]].map(p => map.containerPointToLatLng(p)));\n\t\tif (!miniMap.hasLayer(this._rectangle)) {\n\t\t\tthis._rectangle.addTo(miniMap);\n\t\t}\n\t}\n\n\t// Dragging the overview map pans the map (only when moved by the user)\n\t_onMiniMapMoveEnd(e) {\n\t\tif (e.originalEvent) {\n\t\t\tthis._map.panTo(this._miniMap.getCenter());\n\t\t}\n\t}\n\n\t_onMiniMapClick(e) {\n\t\tif (!this._miniMap.dragging?.moved()) {\n\t\t\tthis._map.panTo(e.latlng);\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CA,IAAa,iBAAb,MAAa,uBAAuB,QAAQ;CAE3C,OAAO,iBAAiB;EACvB,UAAU;EACV,OAAO;EACP,QAAQ;EACR,YAAY;EACZ,WAAW;EACX,kBAAkB;GAAC,OAAO;GAAW,QAAQ;GAAG,aAAa;EAAG;EAChE,YAAY,CAAC;CACd;;;;;;CAOA,YAAY,OAAO,SAAS;EAC3B,MAAM,OAAO;EACb,KAAK,SAAS;EACd,KAAK,cAAc,cAAc;CAClC;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,MAAM,GAAG;EAEf,KAAK,SAAS,eAAe,EAAC,KAAK,MAAK,CAAC;EACzC,KAAK,QAAQ;EACb,OAAO;CACR;;;;;;CAOA,MAAM,KAAK;EACV,MAAM,YAAYA,OAAe,OAAO,yBAAyB,GACjE,eAAeA,OAAe,OAAO,+BAA+B,SAAS;EAC7E,UAAU,MAAM,QAAQ,GAAG,KAAK,QAAQ,MAAM;EAC9C,UAAU,MAAM,SAAS,GAAG,KAAK,QAAQ,OAAO;EAEhD,MAAM,SAAS,KAAK,UAAUA,OAAe,UAAU,kCAAkC,SAAS;EAClG,OAAO,OAAO;EACd,GAAY,QAAQ,SAASC,IAAa;EAC1C,GAAY,QAAQ,SAAS,KAAK,QAAQ,IAAI;EAE9C,wBAAiC,SAAS;EAC1C,yBAAkC,SAAS;EAE3C,KAAK,WAAW,IAAI,WAAW,cAAc;GAC5C,oBAAoB;GACpB,aAAa;GACb,iBAAiB;GACjB,iBAAiB;GACjB,SAAS;GACT,UAAU;GACV,W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AAQ,YAAY,QAAQ,WAAW,CAAC,CAAC;EACnH,QAAQ,QAAQ,IAAI,UAAU,GAAG,MAAM,EAAC,SAAS,MAAK,CAAC;EAEvD,MAAM,OAAO,IAAI,QAAQ;EACzB,KAAK,WAAW,WAAW;GAAC,CAAC,GAAG,CAAC;GAAG,CAAC,KAAK,GAAG,CAAC;GAAG;GAAM,CAAC,GAAG,KAAK,CAAC;EAAC,CAAC,CAAC,KAAI,MAAK,IAAI,uBAAuB,CAAC,CAAC,CAAC;EAC3G,IAAI,CAAC,QAAQ,SAAS,KAAK,UAAU,GACpC,KAAK,WAAW,MAAM,OAAO;CAE/B;CAGA,kBAAkB,GAAG;EACpB,IAAI,EAAE,eACL,KAAK,KAAK,MAAM,KAAK,SAAS,UAAU,CAAC;CAE3C;CAEA,gBAAgB,GAAG;EAClB,IAAI,CAAC,KAAK,SAAS,UAAU,MAAM,GAClC,KAAK,KAAK,MAAM,EAAE,MAAM;CAE1B;AACD"}
@@ -39,9 +39,7 @@ const compass = "<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"
39
39
  * ```
40
40
  */
41
41
  var RotateControl = class RotateControl extends Control {
42
- static {
43
- this.setDefaultOptions({ position: "topleft" });
44
- }
42
+ static defaultOptions = { position: "topleft" };
45
43
  /**
46
44
  * Creates a rotate control.
47
45
  * @param {...RotateControlOptions} args The options.
@@ -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 {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'topleft'\n\t\t});\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;EACC,KAAK,kBAAkB,EACtB,UAAU,UACX,CAAC;CACF;;;;;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\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"}
@@ -30,15 +30,13 @@ import { I18n } from "../core/I18n.js";
30
30
  * ```
31
31
  */
32
32
  var ScaleControl = class ScaleControl extends Control {
33
- static {
34
- this.setDefaultOptions({
35
- position: "bottomleft",
36
- maxWidth: 100,
37
- metric: true,
38
- imperial: true,
39
- updateWhenIdle: false
40
- });
41
- }
33
+ static defaultOptions = {
34
+ position: "bottomleft",
35
+ maxWidth: 100,
36
+ metric: true,
37
+ imperial: true,
38
+ updateWhenIdle: false
39
+ };
42
40
  /**
43
41
  * Creates a scale control with the given options.
44
42
  * @param {...ScaleControlOptions} args The options.
@@ -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 {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'bottomleft',\n\t\t\tmaxWidth: 100,\n\t\t\tmetric: true,\n\t\t\timperial: true,\n\t\t\tupdateWhenIdle: false\n\t\t});\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;EACC,KAAK,kBAAkB;GACtB,UAAU;GACV,UAAU;GACV,QAAQ;GACR,UAAU;GACV,gBAAgB;EACjB,CAAC;CACF;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAA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AErB,IAAI,UAAU,MAAM;GACnB,WAAW,UAAU;GACrB,QAAQ,KAAK,aAAa,QAAQ;GAClC,KAAK,aAAa,KAAK,SAAS,KAAK,UAAU,cAAc,EAAC,MAAK,CAAC,GAAG,QAAQ,QAAQ;EAExF,OAAO;GACN,OAAO,KAAK,aAAa,OAAO;GAChC,KAAK,aAAa,KAAK,SAAS,KAAK,UAAU,aAAa,EAAC,KAAI,CAAC,GAAG,OAAO,OAAO;EACpF;CACD;CAEA,aAAa,OAAO,MAAM,OAAO;EAChC,MAAM,MAAM,QAAQ,GAAG,KAAK,MAAM,KAAK,QAAQ,WAAW,KAAK,EAAE;EACjE,MAAM,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.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,S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a,KAAK,SAAS,KAAK,UAAU,cAAc,EAAC,MAAK,CAAC,GAAG,QAAQ,QAAQ;EAExF,OAAO;GACN,OAAO,KAAK,aAAa,OAAO;GAChC,KAAK,aAAa,KAAK,SAAS,KAAK,UAAU,aAAa,EAAC,KAAI,CAAC,GAAG,OAAO,OAAO;EACpF;CACD;CAEA,aAAa,OAAO,MAAM,OAAO;EAChC,MAAM,MAAM,QAAQ,GAAG,KAAK,MAAM,KAAK,QAAQ,WAAW,KAAK,EAAE;EACjE,MAAM,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"}
@@ -12,6 +12,8 @@ import { Marker } from "../layer/marker/Marker.js";
12
12
  /** @import {MaplairEvent} from '../core/Events.js' */
13
13
  /** @import {LatLngExpression} from '../geo/LatLng.js' */
14
14
  /** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */
15
+ /** @import {Layer} from '../layer/Layer.js' */
16
+ /** @import {LayerGroup} from '../layer/LayerGroup.js' */
15
17
  const searchIcon = "<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><circle cx=\"6.5\" cy=\"6.5\" r=\"4.5\"/><path d=\"M10 10l4.5 4.5\"/></svg>";
16
18
  const nextRequests = /* @__PURE__ */ new Map();
17
19
  function delay(ms, signal) {
@@ -31,6 +33,8 @@ function delay(ms, signal) {
31
33
  * @property {LatLngBoundsExpression} [bounds] The extent of the result, e.g. of a city,
32
34
  * which the map fits to instead of zooming to the position.
33
35
  * @property {any} [raw] The original result of the service, for use in event listeners.
36
+ * @property {Layer} [layer] The found layer, by [`SearchControl.layers()`](#searchcontrol-layers),
37
+ * e.g. to open its tooltip in a `searchresult` listener.
34
38
  */
35
39
  /**
36
40
  * A function searching places for a query, see the [`geocoder`](#searchcontrol-geocoder)
@@ -62,9 +66,17 @@ function delay(ms, signal) {
62
66
  * [`autoComplete`](#searchcontrol-autocomplete).
63
67
  * @property {number} [zoom=16] The zoom level for results without bounds, and the
64
68
  * maximum zoom level for fitting the bounds of results.
65
- * @property {boolean} [marker=true] Whether to show a marker at the selected result.
69
+ * @property {boolean|((result: SearchResult) => Layer|null|undefined)} [marker=true] Whether
70
+ * to show a marker at the selected result, or a function returning the layer to show
71
+ * instead, e.g. a `CircleMarker` highlighting the result (or nothing for none). The
72
+ * layer is removed when the search is cleared or another result is selected.
73
+ * @property {boolean} [clearOnMapClick=false] If `true`, a click on the map clears the
74
+ * search (the field, the results and the marker) and collapses the control. By
75
+ * default, the click only hides the results and the marker stays.
66
76
  * @property {string} [placeholder] The placeholder of the search field, by default
67
77
  * the translation of "Search".
78
+ * @property {string} [noResultsText] The message shown if nothing is found, by
79
+ * default the translation of "No results".
68
80
  * @extends ControlOptions
69
81
  */
70
82
  /**
@@ -116,19 +128,19 @@ function delay(ms, signal) {
116
128
  * [search control](#searchcontrol) is selected.
117
129
  */
118
130
  var SearchControl = class SearchControl extends Control {
119
- static {
120
- this.setDefaultOptions({
121
- position: "topleft",
122
- geocoder: void 0,
123
- collapsed: true,
124
- autoComplete: false,
125
- autoCompleteDelay: 250,
126
- minLength: 3,
127
- zoom: 16,
128
- marker: true,
129
- placeholder: void 0
130
- });
131
- }
131
+ static defaultOptions = {
132
+ position: "topleft",
133
+ geocoder: void 0,
134
+ collapsed: true,
135
+ autoComplete: false,
136
+ autoCompleteDelay: 250,
137
+ minLength: 3,
138
+ zoom: 16,
139
+ marker: true,
140
+ clearOnMapClick: false,
141
+ placeholder: void 0,
142
+ noResultsText: void 0
143
+ };
132
144
  /**
133
145
  * Returns a [geocoder](#searchcontrol-geocoder) searching with
134
146
  * [Nominatim](https://nominatim.org/release-docs/latest/api/Search/), by default the
@@ -192,6 +204,72 @@ var SearchControl = class SearchControl extends Control {
192
204
  });
193
205
  }
194
206
  /**
207
+ * Returns a [geocoder](#searchcontrol-geocoder) searching the layers of a layer group,
208
+ * e.g. the markers of a `FeatureGroup` or the features of a `GeoJSON` layer, by their
209
+ * label: a property of their GeoJSON feature (`layer.feature.properties`) or the
210
+ * result of a function. The group is searched at the time of the search, so layers
211
+ * added later are found as well, and nested groups without a label are searched
212
+ * recursively. The search ignores the case and finds the query anywhere in the
213
+ * label; labels starting with it come first, then in alphabetical order. The results
214
+ * contain the found `layer` and its GeoJSON feature as `raw`; layers without a
215
+ * single position (e.g. polygons) have the `bounds` and their center as `latlng`.
216
+ * Combine it with [`autoComplete`](#searchcontrol-autocomplete) to search while
217
+ * typing, and with [`marker`](#searchcontrol-marker) `false` or a function to not
218
+ * cover the found marker with another one.
219
+ *
220
+ * @example
221
+ * ```js
222
+ * const stations = new GeoJSON(data, {
223
+ * onEachFeature: (feature, layer) => layer.bindTooltip(feature.properties.name)
224
+ * }).addTo(map);
225
+ * new SearchControl({
226
+ * geocoder: SearchControl.layers(stations, {property: 'name'}),
227
+ * autoComplete: true,
228
+ * minLength: 1,
229
+ * marker: false
230
+ * }).addTo(map);
231
+ * map.on('searchresult', ({result}) => result.layer.openTooltip());
232
+ * ```
233
+ * @param {LayerGroup} group The layer group to search.
234
+ * @param {object} [options]
235
+ * @param {string} [options.property='name'] The property of the GeoJSON features to
236
+ * search.
237
+ * @param {(layer: Layer) => string|number|null|undefined} [options.label] A function
238
+ * returning the label of a layer instead of the `property`, nothing to skip the
239
+ * layer (or to search its layers, if it is a group).
240
+ * @param {number} [options.limit=10] The maximum number of results.
241
+ * @returns {Geocoder}
242
+ */
243
+ static layers(group, { property = "name", label = (layer) => layer.feature?.properties?.[property], limit = 10 } = {}) {
244
+ return (query) => {
245
+ query = query.toLocaleLowerCase();
246
+ const found = [];
247
+ group.eachLayer(function search(layer) {
248
+ const text = label(layer);
249
+ if (text === void 0 || text === null || text === "") {
250
+ layer.eachLayer?.(search);
251
+ return;
252
+ }
253
+ const result = {
254
+ label: String(text),
255
+ layer,
256
+ raw: layer.feature
257
+ }, index = result.label.toLocaleLowerCase().indexOf(query);
258
+ if (index < 0) return;
259
+ if (layer.getLatLng) result.latlng = layer.getLatLng();
260
+ else if (layer.getBounds?.().isValid()) {
261
+ result.bounds = layer.getBounds();
262
+ result.latlng = result.bounds.getCenter();
263
+ } else return;
264
+ found.push({
265
+ result,
266
+ prefix: index === 0
267
+ });
268
+ });
269
+ return Promise.resolve(found.sort((a, b) => b.prefix - a.prefix || a.result.label.localeCompare(b.result.label)).slice(0, limit).map(({ result }) => result));
270
+ };
271
+ }
272
+ /**
195
273
  * Creates a search control.
196
274
  * @param {...SearchControlOptions} args The options.
197
275
  */
@@ -300,7 +378,7 @@ var SearchControl = class SearchControl extends Control {
300
378
  this._container.classList.add("maplair-control-search-loading");
301
379
  try {
302
380
  const results = await this.options.geocoder(query, { signal: controller.signal });
303
- if (!controller.signal.aborted) this._showResults(results, I18n.translate("No results"));
381
+ if (!controller.signal.aborted) this._showResults(results, this.options.noResultsText ?? I18n.translate("No results"));
304
382
  return results;
305
383
  } catch (error) {
306
384
  if (controller.signal.aborted) return [];
@@ -326,7 +404,8 @@ var SearchControl = class SearchControl extends Control {
326
404
  if (bounds?.isValid() && !bounds.getNorthWest().equals(bounds.getSouthEast())) map.fitBounds(bounds, { maxZoom: this.options.zoom });
327
405
  else map.setView(latlng, this.options.zoom);
328
406
  this._marker?.remove();
329
- if (this.options.marker) this._marker = new Marker(latlng, { title: result.label }).addTo(map);
407
+ const { marker } = this.options;
408
+ this._marker = typeof marker === "function" ? marker(result)?.addTo(map) ?? null : marker ? new Marker(latlng, { title: result.label }).addTo(map) : null;
330
409
  map.fire("searchresult", {
331
410
  result,
332
411
  latlng,
@@ -432,7 +511,10 @@ var SearchControl = class SearchControl extends Control {
432
511
  if (index >= 0) this.select(this._results[index]);
433
512
  }
434
513
  _onMapClick() {
435
- if (this._input.value) this._showResults([]);
514
+ if (this.options.clearOnMapClick) {
515
+ this.clear();
516
+ this.collapse();
517
+ } else if (this._input.value) this._showResults([]);
436
518
  else this.collapse();
437
519
  }
438
520
  };
@@ -1 +1 @@
1
- {"version":3,"file":"SearchControl.js","names":["DomUtil.create","Util.stamp","Util.falseFn"],"sources":["../../../src/control/SearchControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Marker} from '../layer/marker/Marker.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n\nconst searchIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><circle cx=\"6.5\" cy=\"6.5\" r=\"4.5\"/><path d=\"M10 10l4.5 4.5\"/></svg>';\n\n// the time of the next allowed request to each Nominatim server, shared by all geocoders\nconst nextRequests = new Map();\n\n// Resolves after `ms` milliseconds, rejects when the signal aborts\nfunction delay(ms, signal) {\n\treturn new Promise((resolve, reject) => {\n\t\tconst timeout = setTimeout(resolve, ms);\n\t\tsignal.addEventListener('abort', () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(signal.reason);\n\t\t}, {once: true});\n\t});\n}\n\n/**\n * A result of a search, returned by a [geocoder](#searchcontrol-geocoder).\n * @typedef {object} SearchResult\n * @property {string} label The text shown in the list of results, e.g. an address.\n * @property {LatLngExpression} latlng The position of the result.\n * @property {LatLngBoundsExpression} [bounds] The extent of the result, e.g. of a city,\n * which the map fits to instead of zooming to the position.\n * @property {any} [raw] The original result of the service, for use in event listeners.\n */\n\n/**\n * A function searching places for a query, see the [`geocoder`](#searchcontrol-geocoder)\n * option. It should pass the `signal` to `fetch()`: searches are aborted when the user\n * starts another one. Optional properties of the function: `attribution`, an attribution\n * text which the control adds to the map, and `autoComplete: false` if the service\n * forbids searching while typing (overriding the\n * [`autoComplete`](#searchcontrol-autocomplete) option).\n * @typedef {((query: string, options: {signal: AbortSignal}) => Promise<SearchResult[]>) & {attribution?: string, autoComplete?: boolean}} Geocoder\n */\n\n/**\n * Options of `SearchControl`.\n * @typedef {object} SearchControlOptions\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 {Geocoder} geocoder The function searching places (required), e.g.\n * [Nominatim](#searchcontrol-nominatim). Coordinates (see\n * [`LatLng.parse()`](#latlng-parse)) are found without it.\n * @property {boolean} [collapsed=true] If `true`, the control is collapsed into a button\n * and expanded on click.\n * @property {boolean} [autoComplete=false] Whether to search while typing instead of\n * on <kbd>Enter</kbd>. Not with the public Nominatim service, its\n * [usage policy](https://operations.osmfoundation.org/policies/nominatim/) forbids\n * auto-complete.\n * @property {number} [autoCompleteDelay=250] The delay in milliseconds after typing\n * before searching with [`autoComplete`](#searchcontrol-autocomplete).\n * @property {number} [minLength=3] The minimum length of queries searched with\n * [`autoComplete`](#searchcontrol-autocomplete).\n * @property {number} [zoom=16] The zoom level for results without bounds, and the\n * maximum zoom level for fitting the bounds of results.\n * @property {boolean} [marker=true] Whether to show a marker at the selected result.\n * @property {string} [placeholder] The placeholder of the search field, by default\n * the translation of \"Search\".\n * @extends ControlOptions\n */\n\n/**\n * The event object of `searchresult`.\n * @typedef {object} SearchResultEvent\n * @property {SearchResult} result The selected result.\n * @property {LatLng} latlng The position of the result.\n * @property {LatLngBounds|undefined} bounds The extent of the result, if any.\n * @extends MaplairEvent\n */\n\n/**\n * A control with a search field for places, showing the results in a list to select\n * one with the pointer or the keyboard. The selected result is shown on the map with a\n * marker. It searches with a [`geocoder`](#searchcontrol-geocoder), e.g.\n * [Nominatim](#searchcontrol-nominatim) of OpenStreetMap or any other service.\n * Coordinates like `47.27, 11.4` or `geo:47.27,11.4` are found without a service.\n *\n * The public Nominatim service is free, but limited by its\n * [usage policy](https://operations.osmfoundation.org/policies/nominatim/): it is for\n * occasional searches of users, not for heavy use (an absolute maximum of one request\n * per second for all users of an app), and forbids auto-complete. The\n * [Nominatim geocoder](#searchcontrol-nominatim) follows the technical requirements,\n * but you are responsible for your use of the service, which you confirm with the\n * `acceptUsagePolicy` option: for more traffic, use your own Nominatim server or a\n * commercial provider.\n *\n * @example\n * ```js\n * new SearchControl({\n * geocoder: SearchControl.nominatim({acceptUsagePolicy: true})\n * }).addTo(map);\n *\n * // Photon of Komoot, which allows auto-complete\n * new SearchControl({\n * autoComplete: true,\n * async geocoder(query, {signal}) {\n * const response = await fetch(`https://photon.komoot.io/api/?q=${encodeURIComponent(query)}`, {signal});\n * const {features} = await response.json();\n * return features.map(({geometry, properties}) => ({\n * label: [properties.name, properties.city, properties.country].filter(Boolean).join(', '),\n * latlng: [geometry.coordinates[1], geometry.coordinates[0]],\n * raw: properties\n * }));\n * }\n * }).addTo(map);\n * ```\n *\n * @fires MaplairMap#searchresult {SearchResultEvent} Fired when a result of the\n * [search control](#searchcontrol) is selected.\n */\nexport class SearchControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'topleft',\n\t\t\tgeocoder: undefined,\n\t\t\tcollapsed: true,\n\t\t\tautoComplete: false,\n\t\t\tautoCompleteDelay: 250,\n\t\t\tminLength: 3,\n\t\t\tzoom: 16,\n\t\t\tmarker: true,\n\t\t\tplaceholder: undefined\n\t\t});\n\t}\n\n\t/**\n\t * Returns a [geocoder](#searchcontrol-geocoder) searching with\n\t * [Nominatim](https://nominatim.org/release-docs/latest/api/Search/), by default the\n\t * public service of OpenStreetMap. Using it requires that you read and accept its\n\t * [usage policy](https://operations.osmfoundation.org/policies/nominatim/) with the\n\t * `acceptUsagePolicy` option, otherwise this throws an error. The geocoder sends at most one request per second, caches the results of the last 100\n\t * queries, adds the OpenStreetMap attribution to the map and does not search while\n\t * typing with the public service. For more traffic, use your own Nominatim server or a\n\t * commercial provider.\n\t *\n\t * @example\n\t * ```js\n\t * new SearchControl({\n\t * geocoder: SearchControl.nominatim({acceptUsagePolicy: true, params: {countrycodes: 'at,de'}})\n\t * }).addTo(map);\n\t * ```\n\t * @param {object} [options]\n\t * @param {string} [options.url='https://nominatim.openstreetmap.org/search'] The URL\n\t * of the search endpoint.\n\t * @param {Record<string, string>} [options.params] Further query parameters, e.g.\n\t * `countrycodes`, `viewbox` or `limit` (5 by default).\n\t * @param {boolean} [options.acceptUsagePolicy=false] Confirms that your use of the\n\t * public service complies with its\n\t * [usage policy](https://operations.osmfoundation.org/policies/nominatim/), required\n\t * for the public service.\n\t * @returns {Geocoder}\n\t */\n\tstatic nominatim({url = 'https://nominatim.openstreetmap.org/search', params = {}, acceptUsagePolicy = false} = {}) {\n\t\tconst {host} = new URL(url),\n\t\tpublicService = host === 'nominatim.openstreetmap.org';\n\t\tif (publicService && !acceptUsagePolicy) {\n\t\t\tthrow new Error('Using the public Nominatim service requires that you read and accept its usage policy (https://operations.osmfoundation.org/policies/nominatim/) with the acceptUsagePolicy option.');\n\t\t}\n\t\t// the results of recent queries\n\t\tconst cache = new Map();\n\n\t\tasync function geocoder(query, {signal}) {\n\t\t\tconst search = new URLSearchParams({q: query, format: 'jsonv2', limit: '5', ...params}),\n\t\t\trequestUrl = `${url}?${search}`;\n\t\t\tif (cache.has(requestUrl)) {\n\t\t\t\treturn cache.get(requestUrl);\n\t\t\t}\n\n\t\t\t// at most one request per second\n\t\t\tconst now = Date.now(), next = nextRequests.get(host) ?? 0, wait = next - now;\n\t\t\tnextRequests.set(host, Math.max(now, next) + 1000);\n\t\t\tif (wait > 0) {\n\t\t\t\tawait delay(wait, signal);\n\t\t\t}\n\n\t\t\tconst response = await fetch(requestUrl, {signal});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Nominatim: ${response.status} ${response.statusText}`);\n\t\t\t}\n\t\t\tconst results = (await response.json()).map((place) => {\n\t\t\t\t// [south, north, west, east]\n\t\t\t\tconst [s, n, w, e] = place.boundingbox.map(Number);\n\t\t\t\treturn {\n\t\t\t\t\tlabel: place.display_name,\n\t\t\t\t\tlatlng: [Number(place.lat), Number(place.lon)],\n\t\t\t\t\tbounds: [[s, w], [n, e]],\n\t\t\t\t\traw: place\n\t\t\t\t};\n\t\t\t});\n\t\t\tcache.set(requestUrl, results);\n\t\t\tif (cache.size > 100) {\n\t\t\t\tcache.delete(cache.keys().next().value);\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n\n\t\treturn Object.defineProperties(geocoder, {\n\t\t\t// the same as of OpenStreetMap tiles, translated when added\n\t\t\tattribution: {get: () => `&copy; <a href=\"https://www.openstreetmap.org/copyright\">${I18n.translate('OpenStreetMap contributors')}</a>`},\n\t\t\tautoComplete: {value: !publicService}\n\t\t});\n\t}\n\n\t/**\n\t * Creates a search control.\n\t * @param {...SearchControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tif (!this.options.geocoder) {\n\t\t\tthrow new Error('SearchControl: the geocoder option is required, e.g. SearchControl.nominatim().');\n\t\t}\n\t\tthis.callInitHooks(SearchControl);\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-search',\n\t\tcontainer = this._container = DomUtil.create('div', `${className} maplair-bar`),\n\t\tform = DomUtil.create('form', `${className}-form`, container),\n\t\ttoggle = this._toggle = DomUtil.create('button', `${className}-toggle`, form),\n\t\tinput = this._input = DomUtil.create('input', `${className}-input`, form),\n\t\treset = DomUtil.create('button', `${className}-reset`, form),\n\t\tlist = this._list = DomUtil.create('ul', `${className}-results`, container),\n\t\tlistId = `${className}-results-${Util.stamp(this)}`,\n\t\ttitle = I18n.translate('Search');\n\n\t\tform.role = 'search';\n\t\ttoggle.type = 'button';\n\t\ttoggle.innerHTML = searchIcon;\n\t\ttoggle.title = title;\n\t\ttoggle.setAttribute('aria-label', title);\n\n\t\tinput.type = 'search';\n\t\tinput.placeholder = this.options.placeholder ?? title;\n\t\tinput.autocomplete = 'off';\n\t\tinput.enterKeyHint = 'search';\n\t\tinput.role = 'combobox';\n\t\tinput.setAttribute('aria-label', title);\n\t\tinput.setAttribute('aria-autocomplete', 'list');\n\t\tinput.setAttribute('aria-controls', listId);\n\n\t\treset.type = 'reset';\n\t\treset.innerHTML = '<span aria-hidden=\"true\">&times;</span>';\n\t\treset.title = I18n.translate('Clear the search');\n\t\treset.setAttribute('aria-label', reset.title);\n\n\t\tlist.id = listId;\n\t\tlist.role = 'listbox';\n\t\tlist.setAttribute('aria-label', I18n.translate('Search results'));\n\n\t\tthis._message = DomUtil.create('div', `${className}-message`, container);\n\t\tthis._message.role = 'status';\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tDomEvent.on(toggle, 'click', this._onToggle, this);\n\t\tDomEvent.on(form, 'submit', this._onSubmit, this);\n\t\tDomEvent.on(form, 'reset', this._onReset, this);\n\t\tDomEvent.on(input, 'input', this._onInput, this);\n\t\tDomEvent.on(input, 'keydown', this._onKeyDown, this);\n\t\tDomEvent.on(list, 'click', this._onListClick, this);\n\t\tmap.on('click', this._onMapClick, this);\n\t\tthis._attribution = this.options.geocoder.attribution;\n\t\tmap.attributionControl?.addAttribution(this._attribution);\n\n\t\tthis._showResults([]);\n\t\tthis._setExpanded(!this.options.collapsed);\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('click', this._onMapClick, this);\n\t\tmap.attributionControl?.removeAttribution(this._attribution);\n\t\tthis._abort();\n\t\tthis._marker?.remove();\n\t}\n\n\t/**\n\t * Expands the search field of a [collapsed](#searchcontrol-collapsed) control and\n\t * focuses it.\n\t * @returns {this}\n\t */\n\texpand() {\n\t\tthis._setExpanded(true);\n\t\tthis._input.focus();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Collapses the control into its button, if [collapsed](#searchcontrol-collapsed),\n\t * and hides the results.\n\t * @returns {this}\n\t */\n\tcollapse() {\n\t\tthis._showResults([]);\n\t\tthis._setExpanded(!this.options.collapsed);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Searches the given text and shows the results in the list. Resolves to the results.\n\t * @param {string} query\n\t * @returns {Promise<SearchResult[]>}\n\t */\n\tasync search(query) {\n\t\tthis._abort();\n\t\tthis._input.value = query;\n\t\tquery = query.trim();\n\t\tif (!query) {\n\t\t\tthis._showResults([]);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst latlng = LatLng.parse(query);\n\t\tif (latlng) {\n\t\t\tconst results = [{label: query, latlng}];\n\t\t\tthis._showResults(results);\n\t\t\treturn results;\n\t\t}\n\n\t\tconst controller = this._controller = new AbortController();\n\t\tthis._container.classList.add('maplair-control-search-loading');\n\t\ttry {\n\t\t\tconst results = await this.options.geocoder(query, {signal: controller.signal});\n\t\t\tif (!controller.signal.aborted) {\n\t\t\t\tthis._showResults(results, I18n.translate('No results'));\n\t\t\t}\n\t\t\treturn results;\n\t\t} catch (error) {\n\t\t\tif (controller.signal.aborted) { return []; }\n\t\t\tthis._showResults([], I18n.translate('The search failed'));\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tif (this._controller === controller) {\n\t\t\t\tthis._controller = null;\n\t\t\t\tthis._container.classList.remove('maplair-control-search-loading');\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Shows the given result on the map: zooms to it, shows a\n\t * [marker](#searchcontrol-marker) and fires `searchresult` on the map.\n\t * @param {SearchResult} result\n\t * @returns {this}\n\t */\n\tselect(result) {\n\t\tconst map = this._map,\n\t\tlatlng = LatLng.from(result.latlng),\n\t\tbounds = result.bounds ? LatLngBounds.from(result.bounds) : undefined;\n\n\t\tthis._input.value = result.label;\n\t\tthis._showResults([]);\n\n\t\tif (bounds?.isValid() && !bounds.getNorthWest().equals(bounds.getSouthEast())) {\n\t\t\tmap.fitBounds(bounds, {maxZoom: this.options.zoom});\n\t\t} else {\n\t\t\tmap.setView(latlng, this.options.zoom);\n\t\t}\n\n\t\tthis._marker?.remove();\n\t\tif (this.options.marker) {\n\t\t\tthis._marker = new Marker(latlng, {title: result.label}).addTo(map);\n\t\t}\n\n\t\tmap.fire('searchresult', {result, latlng, bounds});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Clears the search field, the results and the marker.\n\t * @returns {this}\n\t */\n\tclear() {\n\t\tthis._abort();\n\t\tthis._input.value = '';\n\t\tthis._showResults([]);\n\t\tthis._marker?.remove();\n\t\tthis._marker = null;\n\t\treturn this;\n\t}\n\n\t_setExpanded(expanded) {\n\t\tthis._container.classList.toggle('maplair-control-search-expanded', expanded);\n\t\tthis._toggle.setAttribute('aria-expanded', expanded);\n\t}\n\n\t_abort() {\n\t\tclearTimeout(this._autoCompleteTimeout);\n\t\tthis._controller?.abort();\n\t\tthis._controller = null;\n\t\tthis._container?.classList.remove('maplair-control-search-loading');\n\t}\n\n\t// Shows the results, or the message if there are none\n\t_showResults(results, message = '') {\n\t\tthis._results = results;\n\t\tthis._list.replaceChildren(...results.map((result, i) => {\n\t\t\tconst item = DomUtil.create('li', 'maplair-control-search-result');\n\t\t\titem.id = `${this._list.id}-${i}`;\n\t\t\titem.role = 'option';\n\t\t\titem.textContent = result.label;\n\t\t\treturn item;\n\t\t}));\n\t\tthis._list.hidden = !results.length;\n\t\tthis._message.textContent = results.length ? '' : message;\n\t\tthis._message.hidden = !this._message.textContent;\n\t\tthis._input.setAttribute('aria-expanded', !!results.length);\n\t\tthis._setActive(-1);\n\t}\n\n\t_setActive(index) {\n\t\tthis._active = index;\n\t\tfor (const [i, item] of [...this._list.children].entries()) {\n\t\t\titem.setAttribute('aria-selected', i === index);\n\t\t}\n\t\tif (index < 0) {\n\t\t\tthis._input.removeAttribute('aria-activedescendant');\n\t\t} else {\n\t\t\tconst item = this._list.children[index];\n\t\t\tthis._input.setAttribute('aria-activedescendant', item.id);\n\t\t\titem.scrollIntoView({block: 'nearest'});\n\t\t}\n\t}\n\n\t_onToggle() {\n\t\tif (this.options.collapsed && !this._container.classList.contains('maplair-control-search-expanded')) {\n\t\t\tthis.expand();\n\t\t} else {\n\t\t\tthis._onSubmit();\n\t\t}\n\t}\n\n\t_onSubmit(e) {\n\t\tif (e) { DomEvent.preventDefault(e); }\n\t\tconst query = this._input.value,\n\t\tresult = this._results[this._active],\n\t\tlatlng = LatLng.parse(query);\n\t\tif (result) {\n\t\t\tthis.select(result);\n\t\t} else if (latlng) {\n\t\t\tthis.select({label: query.trim(), latlng});\n\t\t} else {\n\t\t\t// errors are shown in the control\n\t\t\tthis.search(query).catch(Util.falseFn);\n\t\t}\n\t}\n\n\t_onReset() {\n\t\tthis.clear();\n\t\tthis._input.focus();\n\t}\n\n\t_onInput() {\n\t\tclearTimeout(this._autoCompleteTimeout);\n\t\tconst query = this._input.value.trim();\n\t\tif (!this.options.autoComplete || this.options.geocoder.autoComplete === false) {\n\t\t\tthis._showResults([]);\n\t\t} else if (query.length >= this.options.minLength || LatLng.parse(query)) {\n\t\t\tthis._autoCompleteTimeout = setTimeout(() => {\n\t\t\t\tthis.search(this._input.value).catch(Util.falseFn);\n\t\t\t}, this.options.autoCompleteDelay);\n\t\t} else {\n\t\t\tthis._abort();\n\t\t\tthis._showResults([]);\n\t\t}\n\t}\n\n\t_onKeyDown(e) {\n\t\tconst n = this._results.length;\n\t\tif ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && n) {\n\t\t\tDomEvent.preventDefault(e);\n\t\t\tconst step = e.key === 'ArrowDown' ? 1 : -1;\n\t\t\t// from no active result, the first or the last one\n\t\t\tthis._setActive(((this._active < 0 && step < 0 ? n : this._active) + step + n) % n);\n\t\t} else if (e.key === 'Escape') {\n\t\t\tDomEvent.preventDefault(e);\n\t\t\tif (n || !this._message.hidden) {\n\t\t\t\tthis._showResults([]);\n\t\t\t} else if (this._input.value) {\n\t\t\t\tthis.clear();\n\t\t\t} else if (this.options.collapsed) {\n\t\t\t\tthis.collapse();\n\t\t\t\tthis._map.getContainer().focus();\n\t\t\t}\n\t\t}\n\t}\n\n\t_onListClick(e) {\n\t\tconst item = e.target.closest('.maplair-control-search-result'),\n\t\tindex = [...this._list.children].indexOf(item);\n\t\tif (index >= 0) {\n\t\t\tthis.select(this._results[index]);\n\t\t}\n\t}\n\n\t_onMapClick() {\n\t\tif (this._input.value) {\n\t\t\tthis._showResults([]);\n\t\t} else {\n\t\t\tthis.collapse();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;AAcA,MAAM,aAAa;AAGnB,MAAM,+BAAe,IAAI,IAAI;AAG7B,SAAS,MAAM,IAAI,QAAQ;CAC1B,OAAO,IAAI,SAAS,SAAS,WAAW;EACvC,MAAM,UAAU,WAAW,SAAS,EAAE;EACtC,OAAO,iBAAiB,eAAe;GACtC,aAAa,OAAO;GACpB,OAAO,OAAO,MAAM;EACrB,GAAG,EAAC,MAAM,KAAI,CAAC;CAChB,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAkGA,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C;EACC,KAAK,kBAAkB;GACtB,UAAU;GACV,UAAU,KAAA;GACV,WAAW;GACX,cAAc;GACd,mBAAmB;GACnB,WAAW;GACX,MAAM;GACN,QAAQ;GACR,aAAa,KAAA;EACd,CAAC;CACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BA,OAAO,UAAU,EAAC,MAAM,8CAA8C,SAAS,CAAC,GAAG,oBAAoB,UAAS,CAAC,GA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Q,WAAW;IAClC,KAAK,SAAS;IACd,KAAK,KAAK,aAAa,CAAC,CAAC,MAAM;GAChC;EACD;CACD;CAEA,aAAa,GAAG;EACf,MAAM,OAAO,EAAE,OAAO,QAAQ,gCAAgC,GAC9D,QAAQ,CAAC,GAAG,KAAK,MAAM,QAAQ,CAAC,CAAC,QAAQ,IAAI;EAC7C,IAAI,SAAS,GACZ,KAAK,OAAO,KAAK,SAAS,MAAM;CAElC;CAEA,cAAc;EACb,IAAI,KAAK,OAAO,OACf,KAAK,aAAa,CAAC,CAAC;OAEpB,KAAK,SAAS;CAEhB;AACD"}
1
+ {"version":3,"file":"SearchControl.js","names":["DomUtil.create","Util.stamp","Util.falseFn"],"sources":["../../../src/control/SearchControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as Util from '../core/Util.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\nimport {I18n} from '../core/I18n.js';\nimport {LatLng} from '../geo/LatLng.js';\nimport {LatLngBounds} from '../geo/LatLngBounds.js';\nimport {Marker} from '../layer/marker/Marker.js';\n/** @import {ControlOptions} from './Control.js' */\n/** @import {MaplairMap} from '../map/Map.js' */\n/** @import {MaplairEvent} from '../core/Events.js' */\n/** @import {LatLngExpression} from '../geo/LatLng.js' */\n/** @import {LatLngBoundsExpression} from '../geo/LatLngBounds.js' */\n/** @import {Layer} from '../layer/Layer.js' */\n/** @import {LayerGroup} from '../layer/LayerGroup.js' */\n\nconst searchIcon = '<svg aria-hidden=\"true\" width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"><circle cx=\"6.5\" cy=\"6.5\" r=\"4.5\"/><path d=\"M10 10l4.5 4.5\"/></svg>';\n\n// the time of the next allowed request to each Nominatim server, shared by all geocoders\nconst nextRequests = new Map();\n\n// Resolves after `ms` milliseconds, rejects when the signal aborts\nfunction delay(ms, signal) {\n\treturn new Promise((resolve, reject) => {\n\t\tconst timeout = setTimeout(resolve, ms);\n\t\tsignal.addEventListener('abort', () => {\n\t\t\tclearTimeout(timeout);\n\t\t\treject(signal.reason);\n\t\t}, {once: true});\n\t});\n}\n\n/**\n * A result of a search, returned by a [geocoder](#searchcontrol-geocoder).\n * @typedef {object} SearchResult\n * @property {string} label The text shown in the list of results, e.g. an address.\n * @property {LatLngExpression} latlng The position of the result.\n * @property {LatLngBoundsExpression} [bounds] The extent of the result, e.g. of a city,\n * which the map fits to instead of zooming to the position.\n * @property {any} [raw] The original result of the service, for use in event listeners.\n * @property {Layer} [layer] The found layer, by [`SearchControl.layers()`](#searchcontrol-layers),\n * e.g. to open its tooltip in a `searchresult` listener.\n */\n\n/**\n * A function searching places for a query, see the [`geocoder`](#searchcontrol-geocoder)\n * option. It should pass the `signal` to `fetch()`: searches are aborted when the user\n * starts another one. Optional properties of the function: `attribution`, an attribution\n * text which the control adds to the map, and `autoComplete: false` if the service\n * forbids searching while typing (overriding the\n * [`autoComplete`](#searchcontrol-autocomplete) option).\n * @typedef {((query: string, options: {signal: AbortSignal}) => Promise<SearchResult[]>) & {attribution?: string, autoComplete?: boolean}} Geocoder\n */\n\n/**\n * Options of `SearchControl`.\n * @typedef {object} SearchControlOptions\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 {Geocoder} geocoder The function searching places (required), e.g.\n * [Nominatim](#searchcontrol-nominatim). Coordinates (see\n * [`LatLng.parse()`](#latlng-parse)) are found without it.\n * @property {boolean} [collapsed=true] If `true`, the control is collapsed into a button\n * and expanded on click.\n * @property {boolean} [autoComplete=false] Whether to search while typing instead of\n * on <kbd>Enter</kbd>. Not with the public Nominatim service, its\n * [usage policy](https://operations.osmfoundation.org/policies/nominatim/) forbids\n * auto-complete.\n * @property {number} [autoCompleteDelay=250] The delay in milliseconds after typing\n * before searching with [`autoComplete`](#searchcontrol-autocomplete).\n * @property {number} [minLength=3] The minimum length of queries searched with\n * [`autoComplete`](#searchcontrol-autocomplete).\n * @property {number} [zoom=16] The zoom level for results without bounds, and the\n * maximum zoom level for fitting the bounds of results.\n * @property {boolean|((result: SearchResult) => Layer|null|undefined)} [marker=true] Whether\n * to show a marker at the selected result, or a function returning the layer to show\n * instead, e.g. a `CircleMarker` highlighting the result (or nothing for none). The\n * layer is removed when the search is cleared or another result is selected.\n * @property {boolean} [clearOnMapClick=false] If `true`, a click on the map clears the\n * search (the field, the results and the marker) and collapses the control. By\n * default, the click only hides the results and the marker stays.\n * @property {string} [placeholder] The placeholder of the search field, by default\n * the translation of \"Search\".\n * @property {string} [noResultsText] The message shown if nothing is found, by\n * default the translation of \"No results\".\n * @extends ControlOptions\n */\n\n/**\n * The event object of `searchresult`.\n * @typedef {object} SearchResultEvent\n * @property {SearchResult} result The selected result.\n * @property {LatLng} latlng The position of the result.\n * @property {LatLngBounds|undefined} bounds The extent of the result, if any.\n * @extends MaplairEvent\n */\n\n/**\n * A control with a search field for places, showing the results in a list to select\n * one with the pointer or the keyboard. The selected result is shown on the map with a\n * marker. It searches with a [`geocoder`](#searchcontrol-geocoder), e.g.\n * [Nominatim](#searchcontrol-nominatim) of OpenStreetMap or any other service.\n * Coordinates like `47.27, 11.4` or `geo:47.27,11.4` are found without a service.\n *\n * The public Nominatim service is free, but limited by its\n * [usage policy](https://operations.osmfoundation.org/policies/nominatim/): it is for\n * occasional searches of users, not for heavy use (an absolute maximum of one request\n * per second for all users of an app), and forbids auto-complete. The\n * [Nominatim geocoder](#searchcontrol-nominatim) follows the technical requirements,\n * but you are responsible for your use of the service, which you confirm with the\n * `acceptUsagePolicy` option: for more traffic, use your own Nominatim server or a\n * commercial provider.\n *\n * @example\n * ```js\n * new SearchControl({\n * geocoder: SearchControl.nominatim({acceptUsagePolicy: true})\n * }).addTo(map);\n *\n * // Photon of Komoot, which allows auto-complete\n * new SearchControl({\n * autoComplete: true,\n * async geocoder(query, {signal}) {\n * const response = await fetch(`https://photon.komoot.io/api/?q=${encodeURIComponent(query)}`, {signal});\n * const {features} = await response.json();\n * return features.map(({geometry, properties}) => ({\n * label: [properties.name, properties.city, properties.country].filter(Boolean).join(', '),\n * latlng: [geometry.coordinates[1], geometry.coordinates[0]],\n * raw: properties\n * }));\n * }\n * }).addTo(map);\n * ```\n *\n * @fires MaplairMap#searchresult {SearchResultEvent} Fired when a result of the\n * [search control](#searchcontrol) is selected.\n */\nexport class SearchControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topleft',\n\t\tgeocoder: undefined,\n\t\tcollapsed: true,\n\t\tautoComplete: false,\n\t\tautoCompleteDelay: 250,\n\t\tminLength: 3,\n\t\tzoom: 16,\n\t\tmarker: true,\n\t\tclearOnMapClick: false,\n\t\tplaceholder: undefined,\n\t\tnoResultsText: undefined\n\t};\n\n\t/**\n\t * Returns a [geocoder](#searchcontrol-geocoder) searching with\n\t * [Nominatim](https://nominatim.org/release-docs/latest/api/Search/), by default the\n\t * public service of OpenStreetMap. Using it requires that you read and accept its\n\t * [usage policy](https://operations.osmfoundation.org/policies/nominatim/) with the\n\t * `acceptUsagePolicy` option, otherwise this throws an error. The geocoder sends at most one request per second, caches the results of the last 100\n\t * queries, adds the OpenStreetMap attribution to the map and does not search while\n\t * typing with the public service. For more traffic, use your own Nominatim server or a\n\t * commercial provider.\n\t *\n\t * @example\n\t * ```js\n\t * new SearchControl({\n\t * geocoder: SearchControl.nominatim({acceptUsagePolicy: true, params: {countrycodes: 'at,de'}})\n\t * }).addTo(map);\n\t * ```\n\t * @param {object} [options]\n\t * @param {string} [options.url='https://nominatim.openstreetmap.org/search'] The URL\n\t * of the search endpoint.\n\t * @param {Record<string, string>} [options.params] Further query parameters, e.g.\n\t * `countrycodes`, `viewbox` or `limit` (5 by default).\n\t * @param {boolean} [options.acceptUsagePolicy=false] Confirms that your use of the\n\t * public service complies with its\n\t * [usage policy](https://operations.osmfoundation.org/policies/nominatim/), required\n\t * for the public service.\n\t * @returns {Geocoder}\n\t */\n\tstatic nominatim({url = 'https://nominatim.openstreetmap.org/search', params = {}, acceptUsagePolicy = false} = {}) {\n\t\tconst {host} = new URL(url),\n\t\tpublicService = host === 'nominatim.openstreetmap.org';\n\t\tif (publicService && !acceptUsagePolicy) {\n\t\t\tthrow new Error('Using the public Nominatim service requires that you read and accept its usage policy (https://operations.osmfoundation.org/policies/nominatim/) with the acceptUsagePolicy option.');\n\t\t}\n\t\t// the results of recent queries\n\t\tconst cache = new Map();\n\n\t\tasync function geocoder(query, {signal}) {\n\t\t\tconst search = new URLSearchParams({q: query, format: 'jsonv2', limit: '5', ...params}),\n\t\t\trequestUrl = `${url}?${search}`;\n\t\t\tif (cache.has(requestUrl)) {\n\t\t\t\treturn cache.get(requestUrl);\n\t\t\t}\n\n\t\t\t// at most one request per second\n\t\t\tconst now = Date.now(), next = nextRequests.get(host) ?? 0, wait = next - now;\n\t\t\tnextRequests.set(host, Math.max(now, next) + 1000);\n\t\t\tif (wait > 0) {\n\t\t\t\tawait delay(wait, signal);\n\t\t\t}\n\n\t\t\tconst response = await fetch(requestUrl, {signal});\n\t\t\tif (!response.ok) {\n\t\t\t\tthrow new Error(`Nominatim: ${response.status} ${response.statusText}`);\n\t\t\t}\n\t\t\tconst results = (await response.json()).map((place) => {\n\t\t\t\t// [south, north, west, east]\n\t\t\t\tconst [s, n, w, e] = place.boundingbox.map(Number);\n\t\t\t\treturn {\n\t\t\t\t\tlabel: place.display_name,\n\t\t\t\t\tlatlng: [Number(place.lat), Number(place.lon)],\n\t\t\t\t\tbounds: [[s, w], [n, e]],\n\t\t\t\t\traw: place\n\t\t\t\t};\n\t\t\t});\n\t\t\tcache.set(requestUrl, results);\n\t\t\tif (cache.size > 100) {\n\t\t\t\tcache.delete(cache.keys().next().value);\n\t\t\t}\n\t\t\treturn results;\n\t\t}\n\n\t\treturn Object.defineProperties(geocoder, {\n\t\t\t// the same as of OpenStreetMap tiles, translated when added\n\t\t\tattribution: {get: () => `&copy; <a href=\"https://www.openstreetmap.org/copyright\">${I18n.translate('OpenStreetMap contributors')}</a>`},\n\t\t\tautoComplete: {value: !publicService}\n\t\t});\n\t}\n\n\t/**\n\t * Returns a [geocoder](#searchcontrol-geocoder) searching the layers of a layer group,\n\t * e.g. the markers of a `FeatureGroup` or the features of a `GeoJSON` layer, by their\n\t * label: a property of their GeoJSON feature (`layer.feature.properties`) or the\n\t * result of a function. The group is searched at the time of the search, so layers\n\t * added later are found as well, and nested groups without a label are searched\n\t * recursively. The search ignores the case and finds the query anywhere in the\n\t * label; labels starting with it come first, then in alphabetical order. The results\n\t * contain the found `layer` and its GeoJSON feature as `raw`; layers without a\n\t * single position (e.g. polygons) have the `bounds` and their center as `latlng`.\n\t * Combine it with [`autoComplete`](#searchcontrol-autocomplete) to search while\n\t * typing, and with [`marker`](#searchcontrol-marker) `false` or a function to not\n\t * cover the found marker with another one.\n\t *\n\t * @example\n\t * ```js\n\t * const stations = new GeoJSON(data, {\n\t * onEachFeature: (feature, layer) => layer.bindTooltip(feature.properties.name)\n\t * }).addTo(map);\n\t * new SearchControl({\n\t * geocoder: SearchControl.layers(stations, {property: 'name'}),\n\t * autoComplete: true,\n\t * minLength: 1,\n\t * marker: false\n\t * }).addTo(map);\n\t * map.on('searchresult', ({result}) => result.layer.openTooltip());\n\t * ```\n\t * @param {LayerGroup} group The layer group to search.\n\t * @param {object} [options]\n\t * @param {string} [options.property='name'] The property of the GeoJSON features to\n\t * search.\n\t * @param {(layer: Layer) => string|number|null|undefined} [options.label] A function\n\t * returning the label of a layer instead of the `property`, nothing to skip the\n\t * layer (or to search its layers, if it is a group).\n\t * @param {number} [options.limit=10] The maximum number of results.\n\t * @returns {Geocoder}\n\t */\n\tstatic layers(group, {property = 'name', label = layer => layer.feature?.properties?.[property], limit = 10} = {}) {\n\t\treturn (query) => {\n\t\t\tquery = query.toLocaleLowerCase();\n\t\t\tconst found = [];\n\t\t\tgroup.eachLayer(function search(layer) {\n\t\t\t\tconst text = label(layer);\n\t\t\t\tif (text === undefined || text === null || text === '') {\n\t\t\t\t\tlayer.eachLayer?.(search);\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tconst result = {label: String(text), layer, raw: layer.feature},\n\t\t\t\tindex = result.label.toLocaleLowerCase().indexOf(query);\n\t\t\t\tif (index < 0) { return; }\n\t\t\t\tif (layer.getLatLng) {\n\t\t\t\t\tresult.latlng = layer.getLatLng();\n\t\t\t\t} else if (layer.getBounds?.().isValid()) {\n\t\t\t\t\tresult.bounds = layer.getBounds();\n\t\t\t\t\tresult.latlng = result.bounds.getCenter();\n\t\t\t\t} else {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\tfound.push({result, prefix: index === 0});\n\t\t\t});\n\t\t\treturn Promise.resolve(found\n\t\t\t\t.sort((a, b) => b.prefix - a.prefix || a.result.label.localeCompare(b.result.label))\n\t\t\t\t.slice(0, limit)\n\t\t\t\t.map(({result}) => result));\n\t\t};\n\t}\n\n\t/**\n\t * Creates a search control.\n\t * @param {...SearchControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tif (!this.options.geocoder) {\n\t\t\tthrow new Error('SearchControl: the geocoder option is required, e.g. SearchControl.nominatim().');\n\t\t}\n\t\tthis.callInitHooks(SearchControl);\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-search',\n\t\tcontainer = this._container = DomUtil.create('div', `${className} maplair-bar`),\n\t\tform = DomUtil.create('form', `${className}-form`, container),\n\t\ttoggle = this._toggle = DomUtil.create('button', `${className}-toggle`, form),\n\t\tinput = this._input = DomUtil.create('input', `${className}-input`, form),\n\t\treset = DomUtil.create('button', `${className}-reset`, form),\n\t\tlist = this._list = DomUtil.create('ul', `${className}-results`, container),\n\t\tlistId = `${className}-results-${Util.stamp(this)}`,\n\t\ttitle = I18n.translate('Search');\n\n\t\tform.role = 'search';\n\t\ttoggle.type = 'button';\n\t\ttoggle.innerHTML = searchIcon;\n\t\ttoggle.title = title;\n\t\ttoggle.setAttribute('aria-label', title);\n\n\t\tinput.type = 'search';\n\t\tinput.placeholder = this.options.placeholder ?? title;\n\t\tinput.autocomplete = 'off';\n\t\tinput.enterKeyHint = 'search';\n\t\tinput.role = 'combobox';\n\t\tinput.setAttribute('aria-label', title);\n\t\tinput.setAttribute('aria-autocomplete', 'list');\n\t\tinput.setAttribute('aria-controls', listId);\n\n\t\treset.type = 'reset';\n\t\treset.innerHTML = '<span aria-hidden=\"true\">&times;</span>';\n\t\treset.title = I18n.translate('Clear the search');\n\t\treset.setAttribute('aria-label', reset.title);\n\n\t\tlist.id = listId;\n\t\tlist.role = 'listbox';\n\t\tlist.setAttribute('aria-label', I18n.translate('Search results'));\n\n\t\tthis._message = DomUtil.create('div', `${className}-message`, container);\n\t\tthis._message.role = 'status';\n\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tDomEvent.on(toggle, 'click', this._onToggle, this);\n\t\tDomEvent.on(form, 'submit', this._onSubmit, this);\n\t\tDomEvent.on(form, 'reset', this._onReset, this);\n\t\tDomEvent.on(input, 'input', this._onInput, this);\n\t\tDomEvent.on(input, 'keydown', this._onKeyDown, this);\n\t\tDomEvent.on(list, 'click', this._onListClick, this);\n\t\tmap.on('click', this._onMapClick, this);\n\t\tthis._attribution = this.options.geocoder.attribution;\n\t\tmap.attributionControl?.addAttribution(this._attribution);\n\n\t\tthis._showResults([]);\n\t\tthis._setExpanded(!this.options.collapsed);\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('click', this._onMapClick, this);\n\t\tmap.attributionControl?.removeAttribution(this._attribution);\n\t\tthis._abort();\n\t\tthis._marker?.remove();\n\t}\n\n\t/**\n\t * Expands the search field of a [collapsed](#searchcontrol-collapsed) control and\n\t * focuses it.\n\t * @returns {this}\n\t */\n\texpand() {\n\t\tthis._setExpanded(true);\n\t\tthis._input.focus();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Collapses the control into its button, if [collapsed](#searchcontrol-collapsed),\n\t * and hides the results.\n\t * @returns {this}\n\t */\n\tcollapse() {\n\t\tthis._showResults([]);\n\t\tthis._setExpanded(!this.options.collapsed);\n\t\treturn this;\n\t}\n\n\t/**\n\t * Searches the given text and shows the results in the list. Resolves to the results.\n\t * @param {string} query\n\t * @returns {Promise<SearchResult[]>}\n\t */\n\tasync search(query) {\n\t\tthis._abort();\n\t\tthis._input.value = query;\n\t\tquery = query.trim();\n\t\tif (!query) {\n\t\t\tthis._showResults([]);\n\t\t\treturn [];\n\t\t}\n\n\t\tconst latlng = LatLng.parse(query);\n\t\tif (latlng) {\n\t\t\tconst results = [{label: query, latlng}];\n\t\t\tthis._showResults(results);\n\t\t\treturn results;\n\t\t}\n\n\t\tconst controller = this._controller = new AbortController();\n\t\tthis._container.classList.add('maplair-control-search-loading');\n\t\ttry {\n\t\t\tconst results = await this.options.geocoder(query, {signal: controller.signal});\n\t\t\tif (!controller.signal.aborted) {\n\t\t\t\tthis._showResults(results, this.options.noResultsText ?? I18n.translate('No results'));\n\t\t\t}\n\t\t\treturn results;\n\t\t} catch (error) {\n\t\t\tif (controller.signal.aborted) { return []; }\n\t\t\tthis._showResults([], I18n.translate('The search failed'));\n\t\t\tthrow error;\n\t\t} finally {\n\t\t\tif (this._controller === controller) {\n\t\t\t\tthis._controller = null;\n\t\t\t\tthis._container.classList.remove('maplair-control-search-loading');\n\t\t\t}\n\t\t}\n\t}\n\n\t/**\n\t * Shows the given result on the map: zooms to it, shows a\n\t * [marker](#searchcontrol-marker) and fires `searchresult` on the map.\n\t * @param {SearchResult} result\n\t * @returns {this}\n\t */\n\tselect(result) {\n\t\tconst map = this._map,\n\t\tlatlng = LatLng.from(result.latlng),\n\t\tbounds = result.bounds ? LatLngBounds.from(result.bounds) : undefined;\n\n\t\tthis._input.value = result.label;\n\t\tthis._showResults([]);\n\n\t\tif (bounds?.isValid() && !bounds.getNorthWest().equals(bounds.getSouthEast())) {\n\t\t\tmap.fitBounds(bounds, {maxZoom: this.options.zoom});\n\t\t} else {\n\t\t\tmap.setView(latlng, this.options.zoom);\n\t\t}\n\n\t\tthis._marker?.remove();\n\t\tconst {marker} = this.options;\n\t\tthis._marker = typeof marker === 'function' ?\n\t\t\tmarker(result)?.addTo(map) ?? null :\n\t\t\tmarker ? new Marker(latlng, {title: result.label}).addTo(map) : null;\n\n\t\tmap.fire('searchresult', {result, latlng, bounds});\n\t\treturn this;\n\t}\n\n\t/**\n\t * Clears the search field, the results and the marker.\n\t * @returns {this}\n\t */\n\tclear() {\n\t\tthis._abort();\n\t\tthis._input.value = '';\n\t\tthis._showResults([]);\n\t\tthis._marker?.remove();\n\t\tthis._marker = null;\n\t\treturn this;\n\t}\n\n\t_setExpanded(expanded) {\n\t\tthis._container.classList.toggle('maplair-control-search-expanded', expanded);\n\t\tthis._toggle.setAttribute('aria-expanded', expanded);\n\t}\n\n\t_abort() {\n\t\tclearTimeout(this._autoCompleteTimeout);\n\t\tthis._controller?.abort();\n\t\tthis._controller = null;\n\t\tthis._container?.classList.remove('maplair-control-search-loading');\n\t}\n\n\t// Shows the results, or the message if there are none\n\t_showResults(results, message = '') {\n\t\tthis._results = results;\n\t\tthis._list.replaceChildren(...results.map((result, i) => {\n\t\t\tconst item = DomUtil.create('li', 'maplair-control-search-result');\n\t\t\titem.id = `${this._list.id}-${i}`;\n\t\t\titem.role = 'option';\n\t\t\titem.textContent = result.label;\n\t\t\treturn item;\n\t\t}));\n\t\tthis._list.hidden = !results.length;\n\t\tthis._message.textContent = results.length ? '' : message;\n\t\tthis._message.hidden = !this._message.textContent;\n\t\tthis._input.setAttribute('aria-expanded', !!results.length);\n\t\tthis._setActive(-1);\n\t}\n\n\t_setActive(index) {\n\t\tthis._active = index;\n\t\tfor (const [i, item] of [...this._list.children].entries()) {\n\t\t\titem.setAttribute('aria-selected', i === index);\n\t\t}\n\t\tif (index < 0) {\n\t\t\tthis._input.removeAttribute('aria-activedescendant');\n\t\t} else {\n\t\t\tconst item = this._list.children[index];\n\t\t\tthis._input.setAttribute('aria-activedescendant', item.id);\n\t\t\titem.scrollIntoView({block: 'nearest'});\n\t\t}\n\t}\n\n\t_onToggle() {\n\t\tif (this.options.collapsed && !this._container.classList.contains('maplair-control-search-expanded')) {\n\t\t\tthis.expand();\n\t\t} else {\n\t\t\tthis._onSubmit();\n\t\t}\n\t}\n\n\t_onSubmit(e) {\n\t\tif (e) { DomEvent.preventDefault(e); }\n\t\tconst query = this._input.value,\n\t\tresult = this._results[this._active],\n\t\tlatlng = LatLng.parse(query);\n\t\tif (result) {\n\t\t\tthis.select(result);\n\t\t} else if (latlng) {\n\t\t\tthis.select({label: query.trim(), latlng});\n\t\t} else {\n\t\t\t// errors are shown in the control\n\t\t\tthis.search(query).catch(Util.falseFn);\n\t\t}\n\t}\n\n\t_onReset() {\n\t\tthis.clear();\n\t\tthis._input.focus();\n\t}\n\n\t_onInput() {\n\t\tclearTimeout(this._autoCompleteTimeout);\n\t\tconst query = this._input.value.trim();\n\t\tif (!this.options.autoComplete || this.options.geocoder.autoComplete === false) {\n\t\t\tthis._showResults([]);\n\t\t} else if (query.length >= this.options.minLength || LatLng.parse(query)) {\n\t\t\tthis._autoCompleteTimeout = setTimeout(() => {\n\t\t\t\tthis.search(this._input.value).catch(Util.falseFn);\n\t\t\t}, this.options.autoCompleteDelay);\n\t\t} else {\n\t\t\tthis._abort();\n\t\t\tthis._showResults([]);\n\t\t}\n\t}\n\n\t_onKeyDown(e) {\n\t\tconst n = this._results.length;\n\t\tif ((e.key === 'ArrowDown' || e.key === 'ArrowUp') && n) {\n\t\t\tDomEvent.preventDefault(e);\n\t\t\tconst step = e.key === 'ArrowDown' ? 1 : -1;\n\t\t\t// from no active result, the first or the last one\n\t\t\tthis._setActive(((this._active < 0 && step < 0 ? n : this._active) + step + n) % n);\n\t\t} else if (e.key === 'Escape') {\n\t\t\tDomEvent.preventDefault(e);\n\t\t\tif (n || !this._message.hidden) {\n\t\t\t\tthis._showResults([]);\n\t\t\t} else if (this._input.value) {\n\t\t\t\tthis.clear();\n\t\t\t} else if (this.options.collapsed) {\n\t\t\t\tthis.collapse();\n\t\t\t\tthis._map.getContainer().focus();\n\t\t\t}\n\t\t}\n\t}\n\n\t_onListClick(e) {\n\t\tconst item = e.target.closest('.maplair-control-search-result'),\n\t\tindex = [...this._list.children].indexOf(item);\n\t\tif (index >= 0) {\n\t\t\tthis.select(this._results[index]);\n\t\t}\n\t}\n\n\t_onMapClick() {\n\t\tif (this.options.clearOnMapClick) {\n\t\t\tthis.clear();\n\t\t\tthis.collapse();\n\t\t} else if (this._input.value) {\n\t\t\tthis._showResults([]);\n\t\t} else {\n\t\t\tthis.collapse();\n\t\t}\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgBA,MAAM,aAAa;AAGnB,MAAM,+BAAe,IAAI,IAAI;AAG7B,SAAS,MAAM,IAAI,QAAQ;CAC1B,OAAO,IAAI,SAAS,SAAS,WAAW;EACvC,MAAM,UAAU,WAAW,SAAS,EAAE;EACtC,OAAO,iBAAiB,eAAe;GACtC,aAAa,OAAO;GACpB,OAAO,OAAO,MAAM;EACrB,GAAG,EAAC,MAAM,KAAI,CAAC;CAChB,CAAC;AACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4GA,IAAa,gBAAb,MAAa,sBAAsB,QAAQ;CAE1C,OAAO,iBAAiB;EACvB,UAAU;EACV,UAAU,KAAA;EACV,WAAW;EACX,cAAc;EACd,mBAAmB;EACnB,WAAW;EACX,MAAM;EACN,QAAQ;EACR,iBAAiB;EACjB,aAAa,KAAA;EACb,eAAe,KAAA;CAChB;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA6BA,OAAO,UAAU,EAAC,MAAM,8CA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AAG;EACf,MAAM,OAAO,EAAE,OAAO,QAAQ,gCAAgC,GAC9D,QAAQ,CAAC,GAAG,KAAK,MAAM,QAAQ,CAAC,CAAC,QAAQ,IAAI;EAC7C,IAAI,SAAS,GACZ,KAAK,OAAO,KAAK,SAAS,MAAM;CAElC;CAEA,cAAc;EACb,IAAI,KAAK,QAAQ,iBAAiB;GACjC,KAAK,MAAM;GACX,KAAK,SAAS;EACf,OAAO,IAAI,KAAK,OAAO,OACtB,KAAK,aAAa,CAAC,CAAC;OAEpB,KAAK,SAAS;CAEhB;AACD"}
@@ -40,9 +40,7 @@ import { I18n } from "../core/I18n.js";
40
40
  * `SideBySideControl` moves.
41
41
  */
42
42
  var SideBySideControl = class SideBySideControl extends Control {
43
- static {
44
- this.setDefaultOptions({ ratio: .5 });
45
- }
43
+ static defaultOptions = { ratio: .5 };
46
44
  /**
47
45
  * Creates a side-by-side control for the given layers (which have to be added to the
48
46
  * map separately).
@@ -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 {\n\t\tthis.setDefaultOptions({\n\t\t\tratio: 0.5\n\t\t});\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;EACC,KAAK,kBAAkB,EACtB,OAAO,GACR,CAAC;CACF;;;;;;;;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,KAAK,YAAY,IAAI;EAErD,IAAI,GAAG,8CAA8C,KAAK,SAAS,IAAI;EACvE,KAAK,aAAa;EAClB,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I;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.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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,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"}
@@ -25,13 +25,11 @@ import { Control } from "./Control.js";
25
25
  * ```
26
26
  */
27
27
  var TextControl = class TextControl extends Control {
28
- static {
29
- this.setDefaultOptions({
30
- position: "topright",
31
- content: "",
32
- className: ""
33
- });
34
- }
28
+ static defaultOptions = {
29
+ position: "topright",
30
+ content: "",
31
+ className: ""
32
+ };
35
33
  /**
36
34
  * Creates a text control.
37
35
  * @param {...TextControlOptions} args The options.
@@ -1 +1 @@
1
- {"version":3,"file":"TextControl.js","names":["DomUtil.create"],"sources":["../../../src/control/TextControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\n/** @import {ControlOptions} from './Control.js' */\n\n/**\n * Options of `TextControl`.\n * @typedef {object} TextControlOptions\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 {string|HTMLElement} [content=''] The content of the control: HTML or an\n * element. String content is rendered as HTML; do not pass untrusted input.\n * @property {string} [className=''] A custom CSS class name to assign to the control.\n * @extends ControlOptions\n */\n\n/**\n * A control showing a text or any content in a box, e.g. a title, a note on the\n * data or a status. It is hidden while its content is empty.\n *\n * @example\n * ```js\n * const status = new TextControl({position: 'topright', content: 'Loading…'}).addTo(map);\n * status.setContent(`Updated at ${new Date().toLocaleTimeString()}`);\n * ```\n */\nexport class TextControl extends Control {\n\n\tstatic {\n\t\tthis.setDefaultOptions({\n\t\t\tposition: 'topright',\n\t\t\tcontent: '',\n\t\t\tclassName: ''\n\t\t});\n\t}\n\n\t/**\n\t * Creates a text control.\n\t * @param {...TextControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(TextControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {HTMLElement}\n\t */\n\tonAdd() {\n\t\tconst container = DomUtil.create('div', `maplair-control-text ${this.options.className}`);\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tthis._container = container;\n\t\tthis._update();\n\t\treturn container;\n\t}\n\n\t/**\n\t * Changes the [content](#textcontrol-content) of the control.\n\t * @param {string|HTMLElement} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis.options.content = content;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the control.\n\t * @returns {string|HTMLElement}\n\t */\n\tgetContent() {\n\t\treturn this.options.content;\n\t}\n\n\t_update() {\n\t\tconst container = this._container,\n\t\t{content} = this.options;\n\t\tif (!container) { return; }\n\n\t\tif (typeof content === 'string') {\n\t\t\tcontainer.innerHTML = content;\n\t\t} else {\n\t\t\tcontainer.replaceChildren(content ?? '');\n\t\t}\n\t\tcontainer.hidden = !content;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC;EACC,KAAK,kBAAkB;GACtB,UAAU;GACV,SAAS;GACT,WAAW;EACZ,CAAC;CACF;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;;CAMA,QAAQ;EACP,MAAM,YAAYA,OAAe,OAAO,wBAAwB,KAAK,QAAQ,WAAW;EACxF,wBAAiC,SAAS;EAC1C,yBAAkC,SAAS;EAC3C,KAAK,aAAa;EAClB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,QAAQ,UAAU;EACvB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,aAAa;EACZ,OAAO,KAAK,QAAQ;CACrB;CAEA,UAAU;EACT,MAAM,YAAY,KAAK,YACvB,EAAC,YAAW,KAAK;EACjB,IAAI,CAAC,WAAa;EAElB,IAAI,OAAO,YAAY,UACtB,UAAU,YAAY;OAEtB,UAAU,gBAAgB,WAAW,EAAE;EAExC,UAAU,SAAS,CAAC;CACrB;AACD"}
1
+ {"version":3,"file":"TextControl.js","names":["DomUtil.create"],"sources":["../../../src/control/TextControl.js"],"sourcesContent":["import {Control} from './Control.js';\nimport * as DomUtil from '../dom/DomUtil.js';\nimport * as DomEvent from '../dom/DomEvent.js';\n/** @import {ControlOptions} from './Control.js' */\n\n/**\n * Options of `TextControl`.\n * @typedef {object} TextControlOptions\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 {string|HTMLElement} [content=''] The content of the control: HTML or an\n * element. String content is rendered as HTML; do not pass untrusted input.\n * @property {string} [className=''] A custom CSS class name to assign to the control.\n * @extends ControlOptions\n */\n\n/**\n * A control showing a text or any content in a box, e.g. a title, a note on the\n * data or a status. It is hidden while its content is empty.\n *\n * @example\n * ```js\n * const status = new TextControl({position: 'topright', content: 'Loading…'}).addTo(map);\n * status.setContent(`Updated at ${new Date().toLocaleTimeString()}`);\n * ```\n */\nexport class TextControl extends Control {\n\n\tstatic defaultOptions = {\n\t\tposition: 'topright',\n\t\tcontent: '',\n\t\tclassName: ''\n\t};\n\n\t/**\n\t * Creates a text control.\n\t * @param {...TextControlOptions} args The options.\n\t */\n\tconstructor(...args) {\n\t\tsuper(...args);\n\t\tthis.callInitHooks(TextControl);\n\t}\n\n\t/**\n\t * @internal\n\t * @returns {HTMLElement}\n\t */\n\tonAdd() {\n\t\tconst container = DomUtil.create('div', `maplair-control-text ${this.options.className}`);\n\t\tDomEvent.disableClickPropagation(container);\n\t\tDomEvent.disableScrollPropagation(container);\n\t\tthis._container = container;\n\t\tthis._update();\n\t\treturn container;\n\t}\n\n\t/**\n\t * Changes the [content](#textcontrol-content) of the control.\n\t * @param {string|HTMLElement} content\n\t * @returns {this}\n\t */\n\tsetContent(content) {\n\t\tthis.options.content = content;\n\t\tthis._update();\n\t\treturn this;\n\t}\n\n\t/**\n\t * Returns the content of the control.\n\t * @returns {string|HTMLElement}\n\t */\n\tgetContent() {\n\t\treturn this.options.content;\n\t}\n\n\t_update() {\n\t\tconst container = this._container,\n\t\t{content} = this.options;\n\t\tif (!container) { return; }\n\n\t\tif (typeof content === 'string') {\n\t\t\tcontainer.innerHTML = content;\n\t\t} else {\n\t\t\tcontainer.replaceChildren(content ?? '');\n\t\t}\n\t\tcontainer.hidden = !content;\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,IAAa,cAAb,MAAa,oBAAoB,QAAQ;CAExC,OAAO,iBAAiB;EACvB,UAAU;EACV,SAAS;EACT,WAAW;CACZ;;;;;CAMA,YAAY,GAAG,MAAM;EACpB,MAAM,GAAG,IAAI;EACb,KAAK,cAAc,WAAW;CAC/B;;;;;CAMA,QAAQ;EACP,MAAM,YAAYA,OAAe,OAAO,wBAAwB,KAAK,QAAQ,WAAW;EACxF,wBAAiC,SAAS;EAC1C,yBAAkC,SAAS;EAC3C,KAAK,aAAa;EAClB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;;CAOA,WAAW,SAAS;EACnB,KAAK,QAAQ,UAAU;EACvB,KAAK,QAAQ;EACb,OAAO;CACR;;;;;CAMA,aAAa;EACZ,OAAO,KAAK,QAAQ;CACrB;CAEA,UAAU;EACT,MAAM,YAAY,KAAK,YACvB,EAAC,YAAW,KAAK;EACjB,IAAI,CAAC,WAAa;EAElB,IAAI,OAAO,YAAY,UACtB,UAAU,YAAY;OAEtB,UAAU,gBAAgB,WAAW,EAAE;EAExC,UAAU,SAAS,CAAC;CACrB;AACD"}